Python xml.etree.cElementTree.XMLParser() Examples
The following are 6
code examples of xml.etree.cElementTree.XMLParser().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
xml.etree.cElementTree
, or try the search function
.
Example #1
Source File: random_manifest.py From Obfuscapk with MIT License | 6 votes |
def obfuscate(self, obfuscation_info: Obfuscation): self.logger.info('Running "{0}" obfuscator'.format(self.__class__.__name__)) try: # Change default namespace. Xml.register_namespace('obfuscation', 'http://schemas.android.com/apk/res/android') xml_parser = Xml.XMLParser(encoding='utf-8') manifest_tree = Xml.parse(obfuscation_info.get_manifest_file(), parser=xml_parser) manifest_root = manifest_tree.getroot() self.remove_xml_duplicates(manifest_root) self.scramble_xml_element(manifest_root) self.indent_xml(manifest_root) # Write the changes into the manifest file. manifest_tree.write(obfuscation_info.get_manifest_file(), encoding='utf-8') except Exception as e: self.logger.error('Error during execution of "{0}" obfuscator: {1}'.format(self.__class__.__name__, e)) raise finally: obfuscation_info.used_obfuscators.append(self.__class__.__name__)
Example #2
Source File: res_string_encryption.py From Obfuscapk with MIT License | 5 votes |
def encrypt_string_resources(self, string_resources_xml_file: str, string_names_to_encrypt: Set[str]): xml_parser = Xml.XMLParser(encoding='utf-8') xml_tree = Xml.parse(string_resources_xml_file, parser=xml_parser) for xml_string in xml_tree.iter('string'): string_name = xml_string.get('name', None) string_value = xml_string.text if string_name and string_value and string_name in string_names_to_encrypt: encrypted_string_value = self.encrypt_string(string_value) xml_string.text = encrypted_string_value xml_tree.write(string_resources_xml_file, encoding='utf-8')
Example #3
Source File: res_string_encryption.py From Obfuscapk with MIT License | 5 votes |
def encrypt_string_array_resources(self, string_array_resources_xml_file: str, string_array_names_to_encrypt: Set[str]): xml_parser = Xml.XMLParser(encoding='utf-8') xml_tree = Xml.parse(string_array_resources_xml_file, parser=xml_parser) for xml_string_array in xml_tree.iter('string-array'): string_array_name = xml_string_array.get('name', None) if string_array_name and string_array_name in string_array_names_to_encrypt: for item in xml_string_array.iter('item'): if item.text: encrypted_string_value = self.encrypt_string(item.text) item.text = encrypted_string_value xml_tree.write(string_array_resources_xml_file, encoding='utf-8')
Example #4
Source File: DoxygenDB.py From CodeAtlasSublime with Eclipse Public License 1.0 | 5 votes |
def _getXmlDocumentItem(self, fileName): filePath = '%s/%s.xml' % (self._dbFolder, fileName) xmlDoc = self.xmlCache.get(filePath) if xmlDoc: return xmlDoc doc = None # try different encoding and configurations encodingArray = ['utf-8', 'iso-8859-5'] for docEncoding in encodingArray: try: doc = ET.parse(filePath, parser=ET.XMLParser(encoding=docEncoding)) if doc is not None: print('parse %s success. encoding = %s' % (fileName, docEncoding)) break except: print('parse %s failed. encoding = %s'% (fileName, docEncoding)) # traceback.print_exc() continue if doc is None: print('parse %s failed'% (fileName, )) return XmlDocItem(None) xmlDoc = XmlDocItem(doc) self.xmlCache[filePath] = xmlDoc return xmlDoc
Example #5
Source File: __init__.py From zim-desktop-wiki with GNU General Public License v2.0 | 5 votes |
def fromstring(self, string): '''Set the contents of this tree from XML representation.''' parser = ElementTreeModule.XMLParser() parser.feed(string) root = parser.close() self._etree._setroot(root) return self # allow ParseTree().fromstring(..)
Example #6
Source File: main.py From aws-extender with MIT License | 4 votes |
def check_loading_issues(self): """Check for any loading issues.""" missing_libs = [] tips = [] label = """<html> <body style='margin: 10px'> <b>The following dependencies could not be loaded successfully:</b><br> <ul><li>%s</li></ul><br> <b>Tips:</b><br> <ul><li>%s</li><br></ul> <b>For detailed information on how to load the plugin, see:</b><br> <ul> <li> <a href='#'>https://github.com/VirtueSecurity/aws-extender#getting-started</a> </li> </ul> </body> </html>""" if not RUN_TESTS: missing_libs.append('boto/boto3') tips.append('Make sure that the boto/boto3 library is installed properly, and\ the right path is specified in the "Folder for loading modules" setting.') try: CET.fromstring('<test></test>') except SAXException: # a workaround for "http://bugs.jython.org/issue1127" try: def xml_parser(**_): class Parser(object): def feed(*_): raise XMLParseError @staticmethod def close(*_): return None return Parser() CET.XMLParser = xml_parser except TypeError: missing_libs.append('SAXParser') tips.append("""Run Burp Suite using the following command: <br><code style='background: #f7f7f9; color: red'>$ java -classpath xercesImpl.jar;burpsuite_pro.jar burp.StartBurp</code>""") if not missing_libs: return label %= ('</li><li>'.join(missing_libs), '</li><li>'.join(tips)) self.show_errors(label)