forked from androbugs2/androbugs2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
37 lines (26 loc) · 965 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import re
def is_success_base64_decoded_string(base64_string):
# Punct: \:;/-.,?=<>+_()[]{}|"'~`*
return re.match('^[A-Za-z0-9\\\:\;\/\-\.\,\?\=\<\>\+\_\(\)\[\]\{\}\|\"\'\~\`\*\ ]+$', base64_string)
def is_null_or_empty_string(input_string, strip_whitespaces=False):
if input_string is None:
return True
if strip_whitespaces:
if input_string.strip() == "":
return True
else:
if input_string == "":
return True
return False
def is_base64(base64_string):
return re.match('^[A-Za-z0-9+/]+[=]{0,2}$', base64_string)
def get_elements_by_tagname(xml, tagname):
results = []
get_elements_by_tagname_sub(xml, tagname, results)
return results
def get_elements_by_tagname_sub(xml, tagname, results):
children = xml.getchildren()
for child in children:
get_elements_by_tagname_sub(child, tagname, results)
if xml.tag == tagname:
results.append(xml)