本文整理汇总了Python中xml.sax.parse方法的典型用法代码示例。如果您正苦于以下问题:Python sax.parse方法的具体用法?Python sax.parse怎么用?Python sax.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml.sax
的用法示例。
在下文中一共展示了sax.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getAutoDirectories
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import parse [as 别名]
def getAutoDirectories():
retVal = set()
if kb.absFilePaths:
infoMsg = "retrieved web server absolute paths: "
infoMsg += "'%s'" % ", ".join(ntToPosixSlashes(path) for path in kb.absFilePaths)
logger.info(infoMsg)
for absFilePath in kb.absFilePaths:
if absFilePath:
directory = directoryPath(absFilePath)
directory = ntToPosixSlashes(directory)
retVal.add(directory)
else:
warnMsg = "unable to automatically parse any web server path"
logger.warn(warnMsg)
_ = extractRegexResult(r"//[^/]+?(?P<result>/.*)/", conf.url) # web directory
if _:
retVal.add(_)
return list(retVal)
示例2: extractErrorMessage
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import parse [as 别名]
def extractErrorMessage(page):
"""
Returns reported error message from page if it founds one
>>> extractErrorMessage(u'<html><title>Test</title>\\n<b>Warning</b>: oci_parse() [function.oci-parse]: ORA-01756: quoted string not properly terminated<br><p>Only a test page</p></html>')
u'oci_parse() [function.oci-parse]: ORA-01756: quoted string not properly terminated'
"""
retVal = None
if isinstance(page, basestring):
for regex in ERROR_PARSING_REGEXES:
match = re.search(regex, page, re.DOTALL | re.IGNORECASE)
if match:
retVal = htmlunescape(match.group("result")).replace("<br>", "\n").strip()
break
return retVal
示例3: main
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import parse [as 别名]
def main():
xmlString = "<note>\n<to>Tove</to>\n<from>Jani</from>\n<heading>Reminder</heading>\n<body>Don't forget me this weekend!</body>\n</note>"
# bad
xml.sax.parseString(xmlString, ExampleContentHandler())
xml.sax.parse('notaxmlfilethatexists.xml', ExampleContentHandler())
sax.parseString(xmlString, ExampleContentHandler())
sax.parse('notaxmlfilethatexists.xml', ExampleContentHandler)
# good
defusedxml.sax.parseString(xmlString, ExampleContentHandler())
# bad
xml.sax.make_parser()
sax.make_parser()
print('nothing')
# good
defusedxml.sax.make_parser()
示例4: htmlParser
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import parse [as 别名]
def htmlParser(page):
"""
This function calls a class that parses the input HTML page to
fingerprint the back-end database management system
"""
xmlfile = paths.ERRORS_XML
checkFile(xmlfile)
page = sanitizeStr(page)
handler = htmlHandler(page)
parse(xmlfile, handler)
if handler.dbms and handler.dbms not in kb.htmlFp:
kb.htmlFp.append(handler.dbms)
return handler.dbms
示例5: getAutoDirectories
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import parse [as 别名]
def getAutoDirectories():
retVal = set()
if kb.absFilePaths:
infoMsg = "retrieved web server absolute paths: "
infoMsg += "'%s'" % ", ".join(ntToPosixSlashes(path) for path in kb.absFilePaths)
logger.info(infoMsg)
for absFilePath in kb.absFilePaths:
if absFilePath:
directory = directoryPath(absFilePath)
directory = ntToPosixSlashes(directory)
retVal.add(directory)
else:
warnMsg = "unable to automatically parse any web server path"
logger.warn(warnMsg)
return list(retVal)
示例6: __call__
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import parse [as 别名]
def __call__(self,fav=1):
hwnds = Handle()
if len(hwnds) > 0:
ScreamerPath = self.plugin.ScreamerPath
xmltoparse = ScreamerPath+'\\favorites.xml'
self.dh2 = my_xml_handler2()
sax.parse(xmltoparse.encode(eg.systemEncoding), self.dh2)
if fav <= len(self.plugin.favList):
self.plugin.fav_num=fav-1
PostMessage(hwnds[0], WM_COMMAND, 9216+fav, 0)
return str(fav)+": "+self.plugin.favList[self.plugin.fav_num]
else:
self.PrintError(
self.text.over % (str(fav),str(len(self.plugin.favList))))
return self.text.over % (str(fav),str(len(self.plugin.favList)))
else:
self.PrintError(self.plugin.text.text1)
return self.plugin.text.text1
示例7: main
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import parse [as 别名]
def main():
file = raw_input( "Enter a file to parse: " )
tagName = raw_input( "Enter tag to search for: " )
try:
parse( file, TagInfoHandler( tagName ) )
# handle exception if unable to open file
except IOError, message:
print "Error reading file:", message
# handle exception parsing file
示例8: parseXmlFile
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import parse [as 别名]
def parseXmlFile(xmlFile, handler):
"""
Parses XML file by a given handler
"""
try:
with contextlib.closing(StringIO(readCachedFileContent(xmlFile))) as stream:
parse(stream, handler)
except (SAXParseException, UnicodeError), ex:
errMsg = "something seems to be wrong with "
errMsg += "the file '%s' ('%s'). Please make " % (xmlFile, ex)
errMsg += "sure that you haven't made any changes to it"
raise SqlmapInstallationException, errMsg
示例9: readXmlFile
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import parse [as 别名]
def readXmlFile(xmlFile):
"""
Reads XML file content and returns its DOM representation
"""
checkFile(xmlFile)
retVal = minidom.parse(xmlFile).documentElement
return retVal
示例10: terna_file_to_initial_dataframe
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import parse [as 别名]
def terna_file_to_initial_dataframe(filepath):
'''
Parse the xml or read excel directly,
returning the data from the file in a simple-index dataframe.
Some files are formated as xml, some are pure excel files.
This function handles both cases.
Parameters:
----------
filepath: str
The path of the file to process
Returns:
----------
df: pandas.DataFrame
A pandas dataframe containing the data from the specified file.
'''
# First, we'll try to parse the file as if it is xml.
try:
excelHandler = ExcelHandler()
parse(filepath, excelHandler)
# Create the dataframe from the parsed data
df = pd.DataFrame(excelHandler.tables[0][2:],
columns=excelHandler.tables[0][1])
# Convert the "Generation [MWh]"-column to numeric
df['Generation [MWh]'] = pd.to_numeric(df['Generation [MWh]'])
except:
# In the case of an exception, treat the file as excel.
try:
df = pd.read_excel(filepath, header=1)
except xlrd.XLRDError:
df = pd.DataFrame()
return df
示例11: headersParser
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import parse [as 别名]
def headersParser(headers):
"""
This function calls a class that parses the input HTTP headers to
fingerprint the back-end database management system operating system
and the web application technology
"""
# It is enough to parse the headers on first four HTTP responses
if kb.headersCount > 3:
return
kb.headersCount += 1
topHeaders = {
"cookie": "%s/cookie.xml" % paths.SQLMAP_XML_BANNER_PATH,
"microsoftsharepointteamservices": "%s/sharepoint.xml" % paths.SQLMAP_XML_BANNER_PATH,
"server": "%s/server.xml" % paths.SQLMAP_XML_BANNER_PATH,
"servlet-engine": "%s/servlet.xml" % paths.SQLMAP_XML_BANNER_PATH,
"set-cookie": "%s/cookie.xml" % paths.SQLMAP_XML_BANNER_PATH,
"x-aspnet-version": "%s/x-aspnet-version.xml" % paths.SQLMAP_XML_BANNER_PATH,
"x-powered-by": "%s/x-powered-by.xml" % paths.SQLMAP_XML_BANNER_PATH,
}
for header in headers:
if header in topHeaders.keys():
value = headers[header]
xmlfile = topHeaders[header]
checkFile(xmlfile)
handler = FingerprintHandler(value, kb.headersFp)
parse(xmlfile, handler)
parse(paths.GENERIC_XML, handler)
示例12: bannerParser
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import parse [as 别名]
def bannerParser(banner):
"""
This function calls a class to extract information from the given
DBMS banner based upon the data in XML file
"""
if kb.dbms == "Microsoft SQL Server":
xmlfile = paths.MSSQL_XML
elif kb.dbms == "MySQL":
xmlfile = paths.MYSQL_XML
elif kb.dbms == "Oracle":
xmlfile = paths.ORACLE_XML
elif kb.dbms == "PostgreSQL":
xmlfile = paths.PGSQL_XML
checkFile(xmlfile)
if kb.dbms == "Microsoft SQL Server":
handler = MSSQLBannerHandler(banner)
parse(xmlfile, handler)
handler = FingerprintHandler(banner, kb.bannerFp)
parse(paths.GENERIC_XML, handler)
else:
handler = FingerprintHandler(banner, kb.bannerFp)
parse(xmlfile, handler)
parse(paths.GENERIC_XML, handler)
示例13: queriesParser
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import parse [as 别名]
def queriesParser():
"""
This function calls a class to parse the default DBMS queries
from an XML file
"""
debugMsg = "parsing XML queries file"
logger.debug(debugMsg)
xmlfile = paths.QUERIES_XML
checkFile(xmlfile)
handler = queriesHandler()
parse(xmlfile, handler)
示例14: parseXmlFile
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import parse [as 别名]
def parseXmlFile(xmlFile, handler):
"""
Parses XML file by a given handler
"""
try:
with contextlib.closing(StringIO(readCachedFileContent(xmlFile))) as stream:
parse(stream, handler)
except (SAXParseException, UnicodeError), ex:
errMsg = "something appears to be wrong with "
errMsg += "the file '%s' ('%s'). Please make " % (xmlFile, getSafeExString(ex))
errMsg += "sure that you haven't made any changes to it"
raise SqlmapInstallationException(errMsg)
示例15: __start__
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import parse [as 别名]
def __start__(self, ScreamerPath, path2 = None):
self.ScreamerPath = ScreamerPath
self.path2 = path2
xmltoparse = ScreamerPath+'\\screamer.xml'
self.dh = my_xml_handler1()
sax.parse(xmltoparse.encode(eg.systemEncoding), self.dh)
xmltoparse = self.dh.document['LanguageFile']
sax.parse(xmltoparse.encode(eg.systemEncoding), self.dh)