Best Python code snippet using autotest_python
xml_output.py
Source:xml_output.py
...48#49def showIndent(outfile, level):50 for idx in range(level):51 outfile.write(' ')52def quote_xml(inStr):53 s1 = (isinstance(inStr, basestring) and inStr or54 '%s' % inStr)55 s1 = s1.replace('&', '&')56 s1 = s1.replace('<', '<')57 s1 = s1.replace('>', '>')58 return s159def quote_attrib(inStr):60 s1 = (isinstance(inStr, basestring) and inStr or61 '%s' % inStr)62 s1 = s1.replace('&', '&')63 s1 = s1.replace('<', '<')64 s1 = s1.replace('>', '>')65 if '"' in s1:66 if "'" in s1:67 s1 = '"%s"' % s1.replace('"', """)68 else:69 s1 = "'%s'" % s170 else:71 s1 = '"%s"' % s172 return s173def quote_python(inStr):74 s1 = inStr75 if s1.find("'") == -1:76 if s1.find('\n') == -1:77 return "'%s'" % s178 else:79 return "'''%s'''" % s180 else:81 if s1.find('"') != -1:82 s1 = s1.replace('"', '\\"')83 if s1.find('\n') == -1:84 return '"%s"' % s185 else:86 return '"""%s"""' % s187class MixedContainer:88 # Constants for category:89 CategoryNone = 090 CategoryText = 191 CategorySimple = 292 CategoryComplex = 393 # Constants for content_type:94 TypeNone = 095 TypeText = 196 TypeString = 297 TypeInteger = 398 TypeFloat = 499 TypeDecimal = 5100 TypeDouble = 6101 TypeBoolean = 7102 def __init__(self, category, content_type, name, value):103 self.category = category104 self.content_type = content_type105 self.name = name106 self.value = value107 def getCategory(self):108 return self.category109 def getContenttype(self, content_type):110 return self.content_type111 def getValue(self):112 return self.value113 def getName(self):114 return self.name115 def export(self, outfile, level, name, namespace):116 if self.category == MixedContainer.CategoryText:117 outfile.write(self.value)118 elif self.category == MixedContainer.CategorySimple:119 self.exportSimple(outfile, level, name)120 else: # category == MixedContainer.CategoryComplex121 self.value.export(outfile, level, namespace,name)122 def exportSimple(self, outfile, level, name):123 if self.content_type == MixedContainer.TypeString:124 outfile.write('<%s>%s</%s>' % (self.name, self.value, self.name))125 elif self.content_type == MixedContainer.TypeInteger or \126 self.content_type == MixedContainer.TypeBoolean:127 outfile.write('<%s>%d</%s>' % (self.name, self.value, self.name))128 elif self.content_type == MixedContainer.TypeFloat or \129 self.content_type == MixedContainer.TypeDecimal:130 outfile.write('<%s>%f</%s>' % (self.name, self.value, self.name))131 elif self.content_type == MixedContainer.TypeDouble:132 outfile.write('<%s>%g</%s>' % (self.name, self.value, self.name))133 def exportLiteral(self, outfile, level, name):134 if self.category == MixedContainer.CategoryText:135 showIndent(outfile, level)136 outfile.write('model_.MixedContainer(%d, %d, "%s", "%s"),\n' % \137 (self.category, self.content_type, self.name, self.value))138 elif self.category == MixedContainer.CategorySimple:139 showIndent(outfile, level)140 outfile.write('model_.MixedContainer(%d, %d, "%s", "%s"),\n' % \141 (self.category, self.content_type, self.name, self.value))142 else: # category == MixedContainer.CategoryComplex143 showIndent(outfile, level)144 outfile.write('model_.MixedContainer(%d, %d, "%s",\n' % \145 (self.category, self.content_type, self.name,))146 self.value.exportLiteral(outfile, level + 1)147 showIndent(outfile, level)148 outfile.write(')\n')149class MemberSpec_(object):150 def __init__(self, name='', data_type='', container=0):151 self.name = name152 self.data_type = data_type153 self.container = container154 def set_name(self, name): self.name = name155 def get_name(self): return self.name156 def set_data_type(self, data_type): self.data_type = data_type157 def get_data_type_chain(self): return self.data_type158 def get_data_type(self):159 if isinstance(self.data_type, list):160 if len(self.data_type) > 0:161 return self.data_type[-1]162 else:163 return 'xs:string'164 else:165 return self.data_type166 def set_container(self, container): self.container = container167 def get_container(self): return self.container168def _cast(typ, value):169 if typ is None or value is None:170 return value171 return typ(value)172#173# Data representation classes.174#175class urls(GeneratedsSuper):176 subclass = None177 superclass = None178 def __init__(self, clientInfo=None, url=None):179 if clientInfo is None:180 self.clientInfo = []181 else:182 self.clientInfo = clientInfo183 if url is None:184 self.url = []185 else:186 self.url = url187 def factory(*args_, **kwargs_):188 if urls.subclass:189 return urls.subclass(*args_, **kwargs_)190 else:191 return urls(*args_, **kwargs_)192 factory = staticmethod(factory)193 def get_clientInfo(self): return self.clientInfo194 def set_clientInfo(self, clientInfo): self.clientInfo = clientInfo195 def add_clientInfo(self, value): self.clientInfo.append(value)196 def insert_clientInfo(self, index, value): self.clientInfo[index] = value197 def get_url(self): return self.url198 def set_url(self, url): self.url = url199 def add_url(self, value): self.url.append(value)200 def insert_url(self, index, value): self.url[index] = value201 def export(self, outfile, level, namespace_='', name_='urls', namespacedef_=''):202 showIndent(outfile, level)203 outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))204 self.exportAttributes(outfile, level, namespace_, name_='urls')205 if self.hasContent_():206 outfile.write('>\n')207 self.exportChildren(outfile, level + 1, namespace_, name_)208 showIndent(outfile, level)209 outfile.write('</%s%s>\n' % (namespace_, name_))210 else:211 outfile.write('/>\n')212 def exportAttributes(self, outfile, level, namespace_='', name_='urls'):213 pass214 def exportChildren(self, outfile, level, namespace_='', name_='urls'):215 for clientInfo_ in self.clientInfo:216 clientInfo_.export(outfile, level, namespace_, name_='clientInfo')217 for url_ in self.url:218 url_.export(outfile, level, namespace_, name_='url')219 def hasContent_(self):220 if (221 self.clientInfo or222 self.url223 ):224 return True225 else:226 return False227 def exportLiteral(self, outfile, level, name_='urls'):228 level += 1229 self.exportLiteralAttributes(outfile, level, name_)230 if self.hasContent_():231 self.exportLiteralChildren(outfile, level, name_)232 def exportLiteralAttributes(self, outfile, level, name_):233 pass234 def exportLiteralChildren(self, outfile, level, name_):235 showIndent(outfile, level)236 outfile.write('clientInfo=[\n')237 level += 1238 for clientInfo_ in self.clientInfo:239 showIndent(outfile, level)240 outfile.write('model_.clientInfo(\n')241 clientInfo_.exportLiteral(outfile, level)242 showIndent(outfile, level)243 outfile.write('),\n')244 level -= 1245 showIndent(outfile, level)246 outfile.write('],\n')247 showIndent(outfile, level)248 outfile.write('url=[\n')249 level += 1250 for url_ in self.url:251 showIndent(outfile, level)252 outfile.write('model_.url(\n')253 url_.exportLiteral(outfile, level)254 showIndent(outfile, level)255 outfile.write('),\n')256 level -= 1257 showIndent(outfile, level)258 outfile.write('],\n')259 def build(self, node_):260 attrs = node_.attributes261 self.buildAttributes(attrs)262 for child_ in node_.childNodes:263 nodeName_ = child_.nodeName.split(':')[-1]264 self.buildChildren(child_, nodeName_)265 def buildAttributes(self, attrs):266 pass267 def buildChildren(self, child_, nodeName_):268 if child_.nodeType == Node.ELEMENT_NODE and \269 nodeName_ == 'clientInfo':270 obj_ = clientInfo.factory()271 obj_.build(child_)272 self.clientInfo.append(obj_)273 elif child_.nodeType == Node.ELEMENT_NODE and \274 nodeName_ == 'url':275 obj_ = url.factory()276 obj_.build(child_)277 self.url.append(obj_)278# end class urls279class clientInfo(GeneratedsSuper):280 subclass = None281 superclass = None282 def __init__(self, version=None, ipAddress=None, commandLine=None, startTime=None, endTime=None):283 if version is None:284 self.version = []285 else:286 self.version = version287 if ipAddress is None:288 self.ipAddress = []289 else:290 self.ipAddress = ipAddress291 if commandLine is None:292 self.commandLine = []293 else:294 self.commandLine = commandLine295 if startTime is None:296 self.startTime = []297 else:298 self.startTime = startTime299 if endTime is None:300 self.endTime = []301 else:302 self.endTime = endTime303 def factory(*args_, **kwargs_):304 if clientInfo.subclass:305 return clientInfo.subclass(*args_, **kwargs_)306 else:307 return clientInfo(*args_, **kwargs_)308 factory = staticmethod(factory)309 def get_version(self): return self.version310 def set_version(self, version): self.version = version311 def add_version(self, value): self.version.append(value)312 def insert_version(self, index, value): self.version[index] = value313 def get_ipAddress(self): return self.ipAddress314 def set_ipAddress(self, ipAddress): self.ipAddress = ipAddress315 def add_ipAddress(self, value): self.ipAddress.append(value)316 def insert_ipAddress(self, index, value): self.ipAddress[index] = value317 def get_commandLine(self): return self.commandLine318 def set_commandLine(self, commandLine): self.commandLine = commandLine319 def add_commandLine(self, value): self.commandLine.append(value)320 def insert_commandLine(self, index, value): self.commandLine[index] = value321 def get_startTime(self): return self.startTime322 def set_startTime(self, startTime): self.startTime = startTime323 def add_startTime(self, value): self.startTime.append(value)324 def insert_startTime(self, index, value): self.startTime[index] = value325 def get_endTime(self): return self.endTime326 def set_endTime(self, endTime): self.endTime = endTime327 def add_endTime(self, value): self.endTime.append(value)328 def insert_endTime(self, index, value): self.endTime[index] = value329 def export(self, outfile, level, namespace_='', name_='clientInfo', namespacedef_=''):330 showIndent(outfile, level)331 outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))332 self.exportAttributes(outfile, level, namespace_, name_='clientInfo')333 if self.hasContent_():334 outfile.write('>\n')335 self.exportChildren(outfile, level + 1, namespace_, name_)336 showIndent(outfile, level)337 outfile.write('</%s%s>\n' % (namespace_, name_))338 else:339 outfile.write('/>\n')340 def exportAttributes(self, outfile, level, namespace_='', name_='clientInfo'):341 pass342 def exportChildren(self, outfile, level, namespace_='', name_='clientInfo'):343 for version_ in self.version:344 showIndent(outfile, level)345 outfile.write('<%sversion>%s</%sversion>\n' % (namespace_, self.format_string(quote_xml(version_).encode(ExternalEncoding), input_name='version'), namespace_))346 for ipAddress_ in self.ipAddress:347 showIndent(outfile, level)348 outfile.write('<%sipAddress>%s</%sipAddress>\n' % (namespace_, self.format_string(quote_xml(ipAddress_).encode(ExternalEncoding), input_name='ipAddress'), namespace_))349 for commandLine_ in self.commandLine:350 showIndent(outfile, level)351 outfile.write('<%scommandLine>%s</%scommandLine>\n' % (namespace_, self.format_string(quote_xml(commandLine_).encode(ExternalEncoding), input_name='commandLine'), namespace_))352 for startTime_ in self.startTime:353 showIndent(outfile, level)354 outfile.write('<%sstartTime>%s</%sstartTime>\n' % (namespace_, self.format_string(quote_xml(startTime_).encode(ExternalEncoding), input_name='startTime'), namespace_))355 for endTime_ in self.endTime:356 showIndent(outfile, level)357 outfile.write('<%sendTime>%s</%sendTime>\n' % (namespace_, self.format_string(quote_xml(endTime_).encode(ExternalEncoding), input_name='endTime'), namespace_))358 def hasContent_(self):359 if (360 self.version or361 self.ipAddress or362 self.commandLine or363 self.startTime or364 self.endTime365 ):366 return True367 else:368 return False369 def exportLiteral(self, outfile, level, name_='clientInfo'):370 level += 1371 self.exportLiteralAttributes(outfile, level, name_)372 if self.hasContent_():373 self.exportLiteralChildren(outfile, level, name_)374 def exportLiteralAttributes(self, outfile, level, name_):375 pass376 def exportLiteralChildren(self, outfile, level, name_):377 showIndent(outfile, level)378 outfile.write('version=[\n')379 level += 1380 for version_ in self.version:381 showIndent(outfile, level)382 outfile.write('%s,\n' % quote_python(version_).encode(ExternalEncoding))383 level -= 1384 showIndent(outfile, level)385 outfile.write('],\n')386 showIndent(outfile, level)387 outfile.write('ipAddress=[\n')388 level += 1389 for ipAddress_ in self.ipAddress:390 showIndent(outfile, level)391 outfile.write('model_.xs_string(\n')392 ipAddress_.exportLiteral(outfile, level, name_='xs:string')393 showIndent(outfile, level)394 outfile.write('),\n')395 level -= 1396 showIndent(outfile, level)397 outfile.write('],\n')398 showIndent(outfile, level)399 outfile.write('commandLine=[\n')400 level += 1401 for commandLine_ in self.commandLine:402 showIndent(outfile, level)403 outfile.write('%s,\n' % quote_python(commandLine_).encode(ExternalEncoding))404 level -= 1405 showIndent(outfile, level)406 outfile.write('],\n')407 showIndent(outfile, level)408 outfile.write('startTime=[\n')409 level += 1410 for startTime_ in self.startTime:411 showIndent(outfile, level)412 outfile.write('%s,\n' % quote_python(startTime_).encode(ExternalEncoding))413 level -= 1414 showIndent(outfile, level)415 outfile.write('],\n')416 showIndent(outfile, level)417 outfile.write('endTime=[\n')418 level += 1419 for endTime_ in self.endTime:420 showIndent(outfile, level)421 outfile.write('%s,\n' % quote_python(endTime_).encode(ExternalEncoding))422 level -= 1423 showIndent(outfile, level)424 outfile.write('],\n')425 def build(self, node_):426 attrs = node_.attributes427 self.buildAttributes(attrs)428 for child_ in node_.childNodes:429 nodeName_ = child_.nodeName.split(':')[-1]430 self.buildChildren(child_, nodeName_)431 def buildAttributes(self, attrs):432 pass433 def buildChildren(self, child_, nodeName_):434 if child_.nodeType == Node.ELEMENT_NODE and \435 nodeName_ == 'version':436 version_ = ''437 for text__content_ in child_.childNodes:438 version_ += text__content_.nodeValue439 self.version.append(version_)440 elif child_.nodeType == Node.ELEMENT_NODE and \441 nodeName_ == 'ipAddress':442 ipAddress_ = ''443 for text__content_ in child_.childNodes:444 ipAddress_ += text__content_.nodeValue445 self.ipAddress.append(ipAddress_)446 elif child_.nodeType == Node.ELEMENT_NODE and \447 nodeName_ == 'commandLine':448 commandLine_ = ''449 for text__content_ in child_.childNodes:450 commandLine_ += text__content_.nodeValue451 self.commandLine.append(commandLine_)452 elif child_.nodeType == Node.ELEMENT_NODE and \453 nodeName_ == 'startTime':454 startTime_ = ''455 for text__content_ in child_.childNodes:456 startTime_ += text__content_.nodeValue457 self.startTime.append(startTime_)458 elif child_.nodeType == Node.ELEMENT_NODE and \459 nodeName_ == 'endTime':460 endTime_ = ''461 for text__content_ in child_.childNodes:462 endTime_ += text__content_.nodeValue463 self.endTime.append(endTime_)464# end class clientInfo465class url(GeneratedsSuper):466 subclass = None467 superclass = None468 def __init__(self, id=None, urlString=None, referrer=None, httpStatus=None, httpRedirectedTo=None, serverHeaders=None, requestHeaders=None, error=None, disposition=None, output=None, dnsResolution=None, contents=None, outgoingLinks=None, kit=None, exploits=None, classifications=None):469 self.id = _cast(None, id)470 if urlString is None:471 self.urlString = []472 else:473 self.urlString = urlString474 if referrer is None:475 self.referrer = []476 else:477 self.referrer = referrer478 if httpStatus is None:479 self.httpStatus = []480 else:481 self.httpStatus = httpStatus482 if httpRedirectedTo is None:483 self.httpRedirectedTo = []484 else:485 self.httpRedirectedTo = httpRedirectedTo486 if serverHeaders is None:487 self.serverHeaders = []488 else:489 self.serverHeaders = serverHeaders490 if requestHeaders is None:491 self.requestHeaders = []492 else:493 self.requestHeaders = requestHeaders494 if error is None:495 self.error = []496 else:497 self.error = error498 if disposition is None:499 self.disposition = []500 else:501 self.disposition = disposition502 if output is None:503 self.output = []504 else:505 self.output = output506 if dnsResolution is None:507 self.dnsResolution = []508 else:509 self.dnsResolution = dnsResolution510 if contents is None:511 self.contents = []512 else:513 self.contents = contents514 if outgoingLinks is None:515 self.outgoingLinks = []516 else:517 self.outgoingLinks = outgoingLinks518 if kit is None:519 self.kit = []520 else:521 self.kit = kit522 if exploits is None:523 self.exploits = []524 else:525 self.exploits = exploits526 if classifications is None:527 self.classifications = []528 else:529 self.classifications = classifications530 def factory(*args_, **kwargs_):531 if url.subclass:532 return url.subclass(*args_, **kwargs_)533 else:534 return url(*args_, **kwargs_)535 factory = staticmethod(factory)536 def get_urlString(self): return self.urlString537 def set_urlString(self, urlString): self.urlString = urlString538 def add_urlString(self, value): self.urlString.append(value)539 def insert_urlString(self, index, value): self.urlString[index] = value540 def get_referrer(self): return self.referrer541 def set_referrer(self, referrer): self.referrer = referrer542 def add_referrer(self, value): self.referrer.append(value)543 def insert_referrer(self, index, value): self.referrer[index] = value544 def get_httpStatus(self): return self.httpStatus545 def set_httpStatus(self, httpStatus): self.httpStatus = httpStatus546 def add_httpStatus(self, value): self.httpStatus.append(value)547 def insert_httpStatus(self, index, value): self.httpStatus[index] = value548 def get_httpRedirectedTo(self): return self.httpRedirectedTo549 def set_httpRedirectedTo(self, httpRedirectedTo): self.httpRedirectedTo = httpRedirectedTo550 def add_httpRedirectedTo(self, value): self.httpRedirectedTo.append(value)551 def insert_httpRedirectedTo(self, index, value): self.httpRedirectedTo[index] = value552 def get_serverHeaders(self): return self.serverHeaders553 def set_serverHeaders(self, serverHeaders): self.serverHeaders = serverHeaders554 def add_serverHeaders(self, value): self.serverHeaders.append(value)555 def insert_serverHeaders(self, index, value): self.serverHeaders[index] = value556 def get_requestHeaders(self): return self.requestHeaders557 def set_requestHeaders(self, requestHeaders): self.requestHeaders = requestHeaders558 def add_requestHeaders(self, value): self.requestHeaders.append(value)559 def insert_requestHeaders(self, index, value): self.requestHeaders[index] = value560 def get_error(self): return self.error561 def set_error(self, error): self.error = error562 def add_error(self, value): self.error.append(value)563 def insert_error(self, index, value): self.error[index] = value564 def get_disposition(self): return self.disposition565 def set_disposition(self, disposition): self.disposition = disposition566 def add_disposition(self, value): self.disposition.append(value)567 def insert_disposition(self, index, value): self.disposition[index] = value568 def validate_disposition(self, value):569 # validate type disposition570 pass571 def get_output(self): return self.output572 def set_output(self, output): self.output = output573 def add_output(self, value): self.output.append(value)574 def insert_output(self, index, value): self.output[index] = value575 def get_dnsResolution(self): return self.dnsResolution576 def set_dnsResolution(self, dnsResolution): self.dnsResolution = dnsResolution577 def add_dnsResolution(self, value): self.dnsResolution.append(value)578 def insert_dnsResolution(self, index, value): self.dnsResolution[index] = value579 def get_contents(self): return self.contents580 def set_contents(self, contents): self.contents = contents581 def add_contents(self, value): self.contents.append(value)582 def insert_contents(self, index, value): self.contents[index] = value583 def get_outgoingLinks(self): return self.outgoingLinks584 def set_outgoingLinks(self, outgoingLinks): self.outgoingLinks = outgoingLinks585 def add_outgoingLinks(self, value): self.outgoingLinks.append(value)586 def insert_outgoingLinks(self, index, value): self.outgoingLinks[index] = value587 def get_kit(self): return self.kit588 def set_kit(self, kit): self.kit = kit589 def add_kit(self, value): self.kit.append(value)590 def insert_kit(self, index, value): self.kit[index] = value591 def get_exploits(self): return self.exploits592 def set_exploits(self, exploits): self.exploits = exploits593 def add_exploits(self, value): self.exploits.append(value)594 def insert_exploits(self, index, value): self.exploits[index] = value595 def get_classifications(self): return self.classifications596 def set_classifications(self, classifications): self.classifications = classifications597 def add_classifications(self, value): self.classifications.append(value)598 def insert_classifications(self, index, value): self.classifications[index] = value599 def get_id(self): return self.id600 def set_id(self, id): self.id = id601 def export(self, outfile, level, namespace_='', name_='url', namespacedef_=''):602 showIndent(outfile, level)603 outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))604 self.exportAttributes(outfile, level, namespace_, name_='url')605 if self.hasContent_():606 outfile.write('>\n')607 self.exportChildren(outfile, level + 1, namespace_, name_)608 showIndent(outfile, level)609 outfile.write('</%s%s>\n' % (namespace_, name_))610 else:611 outfile.write('/>\n')612 def exportAttributes(self, outfile, level, namespace_='', name_='url'):613 if self.id is not None:614 outfile.write(' id=%s' % (self.format_string(quote_attrib(self.id).encode(ExternalEncoding), input_name='id'), ))615 def exportChildren(self, outfile, level, namespace_='', name_='url'):616 for urlString_ in self.urlString:617 showIndent(outfile, level)618 outfile.write('<%surlString>%s</%surlString>\n' % (namespace_, self.format_string(quote_xml(urlString_).encode(ExternalEncoding), input_name='urlString'), namespace_))619 for referrer_ in self.referrer:620 showIndent(outfile, level)621 outfile.write('<%sreferrer>%s</%sreferrer>\n' % (namespace_, self.format_string(quote_xml(referrer_).encode(ExternalEncoding), input_name='referrer'), namespace_))622 for httpStatus_ in self.httpStatus:623 showIndent(outfile, level)624 outfile.write('<%shttpStatus>%s</%shttpStatus>\n' % (namespace_, self.format_float(httpStatus_, input_name='httpStatus'), namespace_))625 for httpRedirectedTo_ in self.httpRedirectedTo:626 showIndent(outfile, level)627 outfile.write('<%shttpRedirectedTo>%s</%shttpRedirectedTo>\n' % (namespace_, self.format_string(quote_xml(httpRedirectedTo_).encode(ExternalEncoding), input_name='httpRedirectedTo'), namespace_))628 for serverHeaders_ in self.serverHeaders:629 showIndent(outfile, level)630 outfile.write('<%sserverHeaders>%s</%sserverHeaders>\n' % (namespace_, self.format_string(quote_xml(serverHeaders_).encode(ExternalEncoding), input_name='serverHeaders'), namespace_))631 for requestHeaders_ in self.requestHeaders:632 showIndent(outfile, level)633 outfile.write('<%srequestHeaders>%s</%srequestHeaders>\n' % (namespace_, self.format_string(quote_xml(requestHeaders_).encode(ExternalEncoding), input_name='requestHeaders'), namespace_))634 for error_ in self.error:635 showIndent(outfile, level)636 outfile.write('<%serror>%s</%serror>\n' % (namespace_, self.format_string(quote_xml(error_).encode(ExternalEncoding), input_name='error'), namespace_))637 for disposition_ in self.disposition:638 showIndent(outfile, level)639 outfile.write('<%sdisposition>%s</%sdisposition>\n' % (namespace_, self.format_string(quote_xml(disposition_).encode(ExternalEncoding), input_name='disposition'), namespace_))640 for output_ in self.output:641 showIndent(outfile, level)642 outfile.write('<%soutput>%s</%soutput>\n' % (namespace_, self.format_string(quote_xml(output_).encode(ExternalEncoding), input_name='output'), namespace_))643 for dnsResolution_ in self.dnsResolution:644 dnsResolution_.export(outfile, level, namespace_, name_='dnsResolution')645 for contents_ in self.contents:646 contents_.export(outfile, level, namespace_, name_='contents')647 for outgoingLinks_ in self.outgoingLinks:648 outgoingLinks_.export(outfile, level, namespace_, name_='outgoingLinks')649 for kit_ in self.kit:650 kit_.export(outfile, level, namespace_, name_='kit')651 for exploits_ in self.exploits:652 exploits_.export(outfile, level, namespace_, name_='exploits')653 for classifications_ in self.classifications:654 classifications_.export(outfile, level, namespace_, name_='classifications')655 def hasContent_(self):656 if (657 self.urlString or658 self.referrer or659 self.httpStatus or660 self.httpRedirectedTo or661 self.serverHeaders or662 self.requestHeaders or663 self.error or664 self.disposition or665 self.output or666 self.dnsResolution or667 self.contents or668 self.outgoingLinks or669 self.kit or670 self.exploits or671 self.classifications672 ):673 return True674 else:675 return False676 def exportLiteral(self, outfile, level, name_='url'):677 level += 1678 self.exportLiteralAttributes(outfile, level, name_)679 if self.hasContent_():680 self.exportLiteralChildren(outfile, level, name_)681 def exportLiteralAttributes(self, outfile, level, name_):682 if self.id is not None:683 showIndent(outfile, level)684 outfile.write('id = "%s",\n' % (self.id,))685 def exportLiteralChildren(self, outfile, level, name_):686 showIndent(outfile, level)687 outfile.write('urlString=[\n')688 level += 1689 for urlString_ in self.urlString:690 showIndent(outfile, level)691 outfile.write('%s,\n' % quote_python(urlString_).encode(ExternalEncoding))692 level -= 1693 showIndent(outfile, level)694 outfile.write('],\n')695 showIndent(outfile, level)696 outfile.write('referrer=[\n')697 level += 1698 for referrer_ in self.referrer:699 showIndent(outfile, level)700 outfile.write('%s,\n' % quote_python(referrer_).encode(ExternalEncoding))701 level -= 1702 showIndent(outfile, level)703 outfile.write('],\n')704 showIndent(outfile, level)705 outfile.write('httpStatus=[\n')706 level += 1707 for httpStatus_ in self.httpStatus:708 showIndent(outfile, level)709 outfile.write('%f,\n' % httpStatus)710 level -= 1711 showIndent(outfile, level)712 outfile.write('],\n')713 showIndent(outfile, level)714 outfile.write('httpRedirectedTo=[\n')715 level += 1716 for httpRedirectedTo_ in self.httpRedirectedTo:717 showIndent(outfile, level)718 outfile.write('%s,\n' % quote_python(httpRedirectedTo_).encode(ExternalEncoding))719 level -= 1720 showIndent(outfile, level)721 outfile.write('],\n')722 showIndent(outfile, level)723 outfile.write('serverHeaders=[\n')724 level += 1725 for serverHeaders_ in self.serverHeaders:726 showIndent(outfile, level)727 outfile.write('%s,\n' % quote_python(serverHeaders_).encode(ExternalEncoding))728 level -= 1729 showIndent(outfile, level)730 outfile.write('],\n')731 showIndent(outfile, level)732 outfile.write('requestHeaders=[\n')733 level += 1734 for requestHeaders_ in self.requestHeaders:735 showIndent(outfile, level)736 outfile.write('%s,\n' % quote_python(requestHeaders_).encode(ExternalEncoding))737 level -= 1738 showIndent(outfile, level)739 outfile.write('],\n')740 showIndent(outfile, level)741 outfile.write('error=[\n')742 level += 1743 for error_ in self.error:744 showIndent(outfile, level)745 outfile.write('%s,\n' % quote_python(error_).encode(ExternalEncoding))746 level -= 1747 showIndent(outfile, level)748 outfile.write('],\n')749 showIndent(outfile, level)750 outfile.write('disposition=[\n')751 level += 1752 for disposition_ in self.disposition:753 showIndent(outfile, level)754 outfile.write('%s,\n' % quote_python(disposition_).encode(ExternalEncoding))755 level -= 1756 showIndent(outfile, level)757 outfile.write('],\n')758 showIndent(outfile, level)759 outfile.write('output=[\n')760 level += 1761 for output_ in self.output:762 showIndent(outfile, level)763 outfile.write('%s,\n' % quote_python(output_).encode(ExternalEncoding))764 level -= 1765 showIndent(outfile, level)766 outfile.write('],\n')767 showIndent(outfile, level)768 outfile.write('dnsResolution=[\n')769 level += 1770 for dnsResolution_ in self.dnsResolution:771 showIndent(outfile, level)772 outfile.write('model_.dnsResolution(\n')773 dnsResolution_.exportLiteral(outfile, level)774 showIndent(outfile, level)775 outfile.write('),\n')776 level -= 1777 showIndent(outfile, level)778 outfile.write('],\n')779 showIndent(outfile, level)780 outfile.write('contents=[\n')781 level += 1782 for contents_ in self.contents:783 showIndent(outfile, level)784 outfile.write('model_.contents(\n')785 contents_.exportLiteral(outfile, level)786 showIndent(outfile, level)787 outfile.write('),\n')788 level -= 1789 showIndent(outfile, level)790 outfile.write('],\n')791 showIndent(outfile, level)792 outfile.write('outgoingLinks=[\n')793 level += 1794 for outgoingLinks_ in self.outgoingLinks:795 showIndent(outfile, level)796 outfile.write('model_.outgoingLinks(\n')797 outgoingLinks_.exportLiteral(outfile, level)798 showIndent(outfile, level)799 outfile.write('),\n')800 level -= 1801 showIndent(outfile, level)802 outfile.write('],\n')803 showIndent(outfile, level)804 outfile.write('kit=[\n')805 level += 1806 for kit_ in self.kit:807 showIndent(outfile, level)808 outfile.write('model_.kit(\n')809 kit_.exportLiteral(outfile, level)810 showIndent(outfile, level)811 outfile.write('),\n')812 level -= 1813 showIndent(outfile, level)814 outfile.write('],\n')815 showIndent(outfile, level)816 outfile.write('exploits=[\n')817 level += 1818 for exploits_ in self.exploits:819 showIndent(outfile, level)820 outfile.write('model_.exploits(\n')821 exploits_.exportLiteral(outfile, level)822 showIndent(outfile, level)823 outfile.write('),\n')824 level -= 1825 showIndent(outfile, level)826 outfile.write('],\n')827 showIndent(outfile, level)828 outfile.write('classifications=[\n')829 level += 1830 for classifications_ in self.classifications:831 showIndent(outfile, level)832 outfile.write('model_.classifications(\n')833 classifications_.exportLiteral(outfile, level)834 showIndent(outfile, level)835 outfile.write('),\n')836 level -= 1837 showIndent(outfile, level)838 outfile.write('],\n')839 def build(self, node_):840 attrs = node_.attributes841 self.buildAttributes(attrs)842 for child_ in node_.childNodes:843 nodeName_ = child_.nodeName.split(':')[-1]844 self.buildChildren(child_, nodeName_)845 def buildAttributes(self, attrs):846 if attrs.get('id'):847 self.id = attrs.get('id').value848 def buildChildren(self, child_, nodeName_):849 if child_.nodeType == Node.ELEMENT_NODE and \850 nodeName_ == 'urlString':851 urlString_ = ''852 for text__content_ in child_.childNodes:853 urlString_ += text__content_.nodeValue854 self.urlString.append(urlString_)855 elif child_.nodeType == Node.ELEMENT_NODE and \856 nodeName_ == 'referrer':857 referrer_ = ''858 for text__content_ in child_.childNodes:859 referrer_ += text__content_.nodeValue860 self.referrer.append(referrer_)861 elif child_.nodeType == Node.ELEMENT_NODE and \862 nodeName_ == 'httpStatus':863 if child_.firstChild:864 sval_ = child_.firstChild.nodeValue865 try:866 fval_ = float(sval_)867 except ValueError, exp:868 raise ValueError('requires float or double (httpStatus): %s' %exp)869 self.httpStatus.append(fval_)870 elif child_.nodeType == Node.ELEMENT_NODE and \871 nodeName_ == 'httpRedirectedTo':872 httpRedirectedTo_ = ''873 for text__content_ in child_.childNodes:874 httpRedirectedTo_ += text__content_.nodeValue875 self.httpRedirectedTo.append(httpRedirectedTo_)876 elif child_.nodeType == Node.ELEMENT_NODE and \877 nodeName_ == 'serverHeaders':878 serverHeaders_ = ''879 for text__content_ in child_.childNodes:880 serverHeaders_ += text__content_.nodeValue881 self.serverHeaders.append(serverHeaders_)882 elif child_.nodeType == Node.ELEMENT_NODE and \883 nodeName_ == 'requestHeaders':884 requestHeaders_ = ''885 for text__content_ in child_.childNodes:886 requestHeaders_ += text__content_.nodeValue887 self.requestHeaders.append(requestHeaders_)888 elif child_.nodeType == Node.ELEMENT_NODE and \889 nodeName_ == 'error':890 error_ = ''891 for text__content_ in child_.childNodes:892 error_ += text__content_.nodeValue893 self.error.append(error_)894 elif child_.nodeType == Node.ELEMENT_NODE and \895 nodeName_ == 'disposition':896 disposition_ = ''897 for text__content_ in child_.childNodes:898 disposition_ += text__content_.nodeValue899 self.disposition.append(disposition_)900 self.validate_disposition(self.disposition) # validate type disposition901 elif child_.nodeType == Node.ELEMENT_NODE and \902 nodeName_ == 'output':903 output_ = ''904 for text__content_ in child_.childNodes:905 output_ += text__content_.nodeValue906 self.output.append(output_)907 elif child_.nodeType == Node.ELEMENT_NODE and \908 nodeName_ == 'dnsResolution':909 obj_ = dnsResolution.factory()910 obj_.build(child_)911 self.dnsResolution.append(obj_)912 elif child_.nodeType == Node.ELEMENT_NODE and \913 nodeName_ == 'contents':914 obj_ = contents.factory()915 obj_.build(child_)916 self.contents.append(obj_)917 elif child_.nodeType == Node.ELEMENT_NODE and \918 nodeName_ == 'outgoingLinks':919 obj_ = outgoingLinks.factory()920 obj_.build(child_)921 self.outgoingLinks.append(obj_)922 elif child_.nodeType == Node.ELEMENT_NODE and \923 nodeName_ == 'kit':924 obj_ = kit.factory()925 obj_.build(child_)926 self.kit.append(obj_)927 elif child_.nodeType == Node.ELEMENT_NODE and \928 nodeName_ == 'exploits':929 obj_ = exploits.factory()930 obj_.build(child_)931 self.exploits.append(obj_)932 elif child_.nodeType == Node.ELEMENT_NODE and \933 nodeName_ == 'classifications':934 obj_ = classifications.factory()935 obj_.build(child_)936 self.classifications.append(obj_)937# end class url938class disposition(GeneratedsSuper):939 subclass = None940 superclass = None941 def __init__(self, valueOf_=''):942 self.valueOf_ = valueOf_943 def factory(*args_, **kwargs_):944 if disposition.subclass:945 return disposition.subclass(*args_, **kwargs_)946 else:947 return disposition(*args_, **kwargs_)948 factory = staticmethod(factory)949 def getValueOf_(self): return self.valueOf_950 def setValueOf_(self, valueOf_): self.valueOf_ = valueOf_951 def export(self, outfile, level, namespace_='', name_='disposition', namespacedef_=''):952 showIndent(outfile, level)953 outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))954 self.exportAttributes(outfile, level, namespace_, name_='disposition')955 if self.hasContent_():956 outfile.write('>')957 self.exportChildren(outfile, level + 1, namespace_, name_)958 outfile.write('</%s%s>\n' % (namespace_, name_))959 else:960 outfile.write('/>\n')961 def exportAttributes(self, outfile, level, namespace_='', name_='disposition'):962 pass963 def exportChildren(self, outfile, level, namespace_='', name_='disposition'):964 if self.valueOf_.find('![CDATA') > -1:965 value=quote_xml('%s' % self.valueOf_)966 value=value.replace('![CDATA','<![CDATA')967 value=value.replace(']]',']]>')968 outfile.write(value)969 else:970 outfile.write(quote_xml('%s' % self.valueOf_))971 def hasContent_(self):972 if (973 self.valueOf_974 ):975 return True976 else:977 return False978 def exportLiteral(self, outfile, level, name_='disposition'):979 level += 1980 self.exportLiteralAttributes(outfile, level, name_)981 if self.hasContent_():982 self.exportLiteralChildren(outfile, level, name_)983 def exportLiteralAttributes(self, outfile, level, name_):984 pass985 def exportLiteralChildren(self, outfile, level, name_):986 showIndent(outfile, level)987 outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))988 def build(self, node_):989 attrs = node_.attributes990 self.buildAttributes(attrs)991 self.valueOf_ = ''992 for child_ in node_.childNodes:993 nodeName_ = child_.nodeName.split(':')[-1]994 self.buildChildren(child_, nodeName_)995 def buildAttributes(self, attrs):996 pass997 def buildChildren(self, child_, nodeName_):998 if child_.nodeType == Node.TEXT_NODE:999 self.valueOf_ += child_.nodeValue1000 elif child_.nodeType == Node.CDATA_SECTION_NODE:1001 self.valueOf_ += '![CDATA['+child_.nodeValue+']]'1002# end class disposition1003class dnsResolution(GeneratedsSuper):1004 subclass = None1005 superclass = None1006 def __init__(self, hostname=None, resolvesTo=None):1007 if hostname is None:1008 self.hostname = []1009 else:1010 self.hostname = hostname1011 if resolvesTo is None:1012 self.resolvesTo = []1013 else:1014 self.resolvesTo = resolvesTo1015 def factory(*args_, **kwargs_):1016 if dnsResolution.subclass:1017 return dnsResolution.subclass(*args_, **kwargs_)1018 else:1019 return dnsResolution(*args_, **kwargs_)1020 factory = staticmethod(factory)1021 def get_hostname(self): return self.hostname1022 def set_hostname(self, hostname): self.hostname = hostname1023 def add_hostname(self, value): self.hostname.append(value)1024 def insert_hostname(self, index, value): self.hostname[index] = value1025 def get_resolvesTo(self): return self.resolvesTo1026 def set_resolvesTo(self, resolvesTo): self.resolvesTo = resolvesTo1027 def add_resolvesTo(self, value): self.resolvesTo.append(value)1028 def insert_resolvesTo(self, index, value): self.resolvesTo[index] = value1029 def export(self, outfile, level, namespace_='', name_='dnsResolution', namespacedef_=''):1030 showIndent(outfile, level)1031 outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))1032 self.exportAttributes(outfile, level, namespace_, name_='dnsResolution')1033 if self.hasContent_():1034 outfile.write('>\n')1035 self.exportChildren(outfile, level + 1, namespace_, name_)1036 showIndent(outfile, level)1037 outfile.write('</%s%s>\n' % (namespace_, name_))1038 else:1039 outfile.write('/>\n')1040 def exportAttributes(self, outfile, level, namespace_='', name_='dnsResolution'):1041 pass1042 def exportChildren(self, outfile, level, namespace_='', name_='dnsResolution'):1043 for hostname_ in self.hostname:1044 showIndent(outfile, level)1045 outfile.write('<%shostname>%s</%shostname>\n' % (namespace_, self.format_string(quote_xml(hostname_).encode(ExternalEncoding), input_name='hostname'), namespace_))1046 for resolvesTo_ in self.resolvesTo:1047 resolvesTo_.export(outfile, level, namespace_, name_='resolvesTo')1048 def hasContent_(self):1049 if (1050 self.hostname or1051 self.resolvesTo1052 ):1053 return True1054 else:1055 return False1056 def exportLiteral(self, outfile, level, name_='dnsResolution'):1057 level += 11058 self.exportLiteralAttributes(outfile, level, name_)1059 if self.hasContent_():1060 self.exportLiteralChildren(outfile, level, name_)1061 def exportLiteralAttributes(self, outfile, level, name_):1062 pass1063 def exportLiteralChildren(self, outfile, level, name_):1064 showIndent(outfile, level)1065 outfile.write('hostname=[\n')1066 level += 11067 for hostname_ in self.hostname:1068 showIndent(outfile, level)1069 outfile.write('%s,\n' % quote_python(hostname_).encode(ExternalEncoding))1070 level -= 11071 showIndent(outfile, level)1072 outfile.write('],\n')1073 showIndent(outfile, level)1074 outfile.write('resolvesTo=[\n')1075 level += 11076 for resolvesTo_ in self.resolvesTo:1077 showIndent(outfile, level)1078 outfile.write('model_.resolvesTo(\n')1079 resolvesTo_.exportLiteral(outfile, level)1080 showIndent(outfile, level)1081 outfile.write('),\n')1082 level -= 11083 showIndent(outfile, level)1084 outfile.write('],\n')1085 def build(self, node_):1086 attrs = node_.attributes1087 self.buildAttributes(attrs)1088 for child_ in node_.childNodes:1089 nodeName_ = child_.nodeName.split(':')[-1]1090 self.buildChildren(child_, nodeName_)1091 def buildAttributes(self, attrs):1092 pass1093 def buildChildren(self, child_, nodeName_):1094 if child_.nodeType == Node.ELEMENT_NODE and \1095 nodeName_ == 'hostname':1096 hostname_ = ''1097 for text__content_ in child_.childNodes:1098 hostname_ += text__content_.nodeValue1099 self.hostname.append(hostname_)1100 elif child_.nodeType == Node.ELEMENT_NODE and \1101 nodeName_ == 'resolvesTo':1102 obj_ = resolvesTo.factory()1103 obj_.build(child_)1104 self.resolvesTo.append(obj_)1105# end class dnsResolution1106class resolvesTo(GeneratedsSuper):1107 subclass = None1108 superclass = None1109 def __init__(self, ipAddress=None, cname=None):1110 if ipAddress is None:1111 self.ipAddress = []1112 else:1113 self.ipAddress = ipAddress1114 if cname is None:1115 self.cname = []1116 else:1117 self.cname = cname1118 def factory(*args_, **kwargs_):1119 if resolvesTo.subclass:1120 return resolvesTo.subclass(*args_, **kwargs_)1121 else:1122 return resolvesTo(*args_, **kwargs_)1123 factory = staticmethod(factory)1124 def get_ipAddress(self): return self.ipAddress1125 def set_ipAddress(self, ipAddress): self.ipAddress = ipAddress1126 def add_ipAddress(self, value): self.ipAddress.append(value)1127 def insert_ipAddress(self, index, value): self.ipAddress[index] = value1128 def get_cname(self): return self.cname1129 def set_cname(self, cname): self.cname = cname1130 def add_cname(self, value): self.cname.append(value)1131 def insert_cname(self, index, value): self.cname[index] = value1132 def export(self, outfile, level, namespace_='', name_='resolvesTo', namespacedef_=''):1133 showIndent(outfile, level)1134 outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))1135 self.exportAttributes(outfile, level, namespace_, name_='resolvesTo')1136 if self.hasContent_():1137 outfile.write('>\n')1138 self.exportChildren(outfile, level + 1, namespace_, name_)1139 showIndent(outfile, level)1140 outfile.write('</%s%s>\n' % (namespace_, name_))1141 else:1142 outfile.write('/>\n')1143 def exportAttributes(self, outfile, level, namespace_='', name_='resolvesTo'):1144 pass1145 def exportChildren(self, outfile, level, namespace_='', name_='resolvesTo'):1146 for ipAddress_ in self.ipAddress:1147 ipAddress_.export(outfile, level, namespace_, name_='ipAddress')1148 for cname_ in self.cname:1149 cname_.export(outfile, level, namespace_, name_='cname')1150 def hasContent_(self):1151 if (1152 self.ipAddress or1153 self.cname1154 ):1155 return True1156 else:1157 return False1158 def exportLiteral(self, outfile, level, name_='resolvesTo'):1159 level += 11160 self.exportLiteralAttributes(outfile, level, name_)1161 if self.hasContent_():1162 self.exportLiteralChildren(outfile, level, name_)1163 def exportLiteralAttributes(self, outfile, level, name_):1164 pass1165 def exportLiteralChildren(self, outfile, level, name_):1166 showIndent(outfile, level)1167 outfile.write('ipAddress=[\n')1168 level += 11169 for ipAddress_ in self.ipAddress:1170 showIndent(outfile, level)1171 outfile.write('model_.ipAddress(\n')1172 ipAddress_.exportLiteral(outfile, level)1173 showIndent(outfile, level)1174 outfile.write('),\n')1175 level -= 11176 showIndent(outfile, level)1177 outfile.write('],\n')1178 showIndent(outfile, level)1179 outfile.write('cname=[\n')1180 level += 11181 for cname_ in self.cname:1182 showIndent(outfile, level)1183 outfile.write('model_.cname(\n')1184 cname_.exportLiteral(outfile, level)1185 showIndent(outfile, level)1186 outfile.write('),\n')1187 level -= 11188 showIndent(outfile, level)1189 outfile.write('],\n')1190 def build(self, node_):1191 attrs = node_.attributes1192 self.buildAttributes(attrs)1193 for child_ in node_.childNodes:1194 nodeName_ = child_.nodeName.split(':')[-1]1195 self.buildChildren(child_, nodeName_)1196 def buildAttributes(self, attrs):1197 pass1198 def buildChildren(self, child_, nodeName_):1199 if child_.nodeType == Node.ELEMENT_NODE and \1200 nodeName_ == 'ipAddress':1201 obj_ = ipAddress.factory()1202 obj_.build(child_)1203 self.ipAddress.append(obj_)1204 elif child_.nodeType == Node.ELEMENT_NODE and \1205 nodeName_ == 'cname':1206 obj_ = cname.factory()1207 obj_.build(child_)1208 self.cname.append(obj_)1209# end class resolvesTo1210class ipAddress(GeneratedsSuper):1211 subclass = None1212 superclass = None1213 def __init__(self, timestamp=None, family=None, valueOf_=''):1214 self.timestamp = _cast(None, timestamp)1215 self.family = _cast(None, family)1216 self.valueOf_ = valueOf_1217 def factory(*args_, **kwargs_):1218 if ipAddress.subclass:1219 return ipAddress.subclass(*args_, **kwargs_)1220 else:1221 return ipAddress(*args_, **kwargs_)1222 factory = staticmethod(factory)1223 def get_timestamp(self): return self.timestamp1224 def set_timestamp(self, timestamp): self.timestamp = timestamp1225 def get_family(self): return self.family1226 def set_family(self, family): self.family = family1227 def getValueOf_(self): return self.valueOf_1228 def setValueOf_(self, valueOf_): self.valueOf_ = valueOf_1229 def export(self, outfile, level, namespace_='', name_='ipAddress', namespacedef_=''):1230 showIndent(outfile, level)1231 outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))1232 self.exportAttributes(outfile, level, namespace_, name_='ipAddress')1233 if self.hasContent_():1234 outfile.write('>')1235 self.exportChildren(outfile, level + 1, namespace_, name_)1236 outfile.write('</%s%s>\n' % (namespace_, name_))1237 else:1238 outfile.write('/>\n')1239 def exportAttributes(self, outfile, level, namespace_='', name_='ipAddress'):1240 if self.timestamp is not None:1241 outfile.write(' timestamp=%s' % (self.format_string(quote_attrib(self.timestamp).encode(ExternalEncoding), input_name='timestamp'), ))1242 if self.family is not None:1243 outfile.write(' family=%s' % (self.format_string(quote_attrib(self.family).encode(ExternalEncoding), input_name='family'), ))1244 def exportChildren(self, outfile, level, namespace_='', name_='ipAddress'):1245 if self.valueOf_.find('![CDATA') > -1:1246 value=quote_xml('%s' % self.valueOf_)1247 value=value.replace('![CDATA','<![CDATA')1248 value=value.replace(']]',']]>')1249 outfile.write(value)1250 else:1251 outfile.write(quote_xml('%s' % self.valueOf_))1252 def hasContent_(self):1253 if (1254 self.valueOf_1255 ):1256 return True1257 else:1258 return False1259 def exportLiteral(self, outfile, level, name_='ipAddress'):1260 level += 11261 self.exportLiteralAttributes(outfile, level, name_)1262 if self.hasContent_():1263 self.exportLiteralChildren(outfile, level, name_)1264 def exportLiteralAttributes(self, outfile, level, name_):1265 if self.timestamp is not None:1266 showIndent(outfile, level)1267 outfile.write('timestamp = "%s",\n' % (self.timestamp,))1268 if self.family is not None:1269 showIndent(outfile, level)1270 outfile.write('family = "%s",\n' % (self.family,))1271 def exportLiteralChildren(self, outfile, level, name_):1272 showIndent(outfile, level)1273 outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))1274 def build(self, node_):1275 attrs = node_.attributes1276 self.buildAttributes(attrs)1277 self.valueOf_ = ''1278 for child_ in node_.childNodes:1279 nodeName_ = child_.nodeName.split(':')[-1]1280 self.buildChildren(child_, nodeName_)1281 def buildAttributes(self, attrs):1282 if attrs.get('timestamp'):1283 self.timestamp = attrs.get('timestamp').value1284 if attrs.get('family'):1285 self.family = attrs.get('family').value1286 def buildChildren(self, child_, nodeName_):1287 if child_.nodeType == Node.TEXT_NODE:1288 self.valueOf_ += child_.nodeValue1289 elif child_.nodeType == Node.CDATA_SECTION_NODE:1290 self.valueOf_ += '![CDATA['+child_.nodeValue+']]'1291# end class ipAddress1292class cname(GeneratedsSuper):1293 subclass = None1294 superclass = None1295 def __init__(self, timestamp=None, valueOf_=''):1296 self.timestamp = _cast(None, timestamp)1297 self.valueOf_ = valueOf_1298 def factory(*args_, **kwargs_):1299 if cname.subclass:1300 return cname.subclass(*args_, **kwargs_)1301 else:1302 return cname(*args_, **kwargs_)1303 factory = staticmethod(factory)1304 def get_timestamp(self): return self.timestamp1305 def set_timestamp(self, timestamp): self.timestamp = timestamp1306 def getValueOf_(self): return self.valueOf_1307 def setValueOf_(self, valueOf_): self.valueOf_ = valueOf_1308 def export(self, outfile, level, namespace_='', name_='cname', namespacedef_=''):1309 showIndent(outfile, level)1310 outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))1311 self.exportAttributes(outfile, level, namespace_, name_='cname')1312 if self.hasContent_():1313 outfile.write('>')1314 self.exportChildren(outfile, level + 1, namespace_, name_)1315 outfile.write('</%s%s>\n' % (namespace_, name_))1316 else:1317 outfile.write('/>\n')1318 def exportAttributes(self, outfile, level, namespace_='', name_='cname'):1319 if self.timestamp is not None:1320 outfile.write(' timestamp=%s' % (self.format_string(quote_attrib(self.timestamp).encode(ExternalEncoding), input_name='timestamp'), ))1321 def exportChildren(self, outfile, level, namespace_='', name_='cname'):1322 if self.valueOf_.find('![CDATA') > -1:1323 value=quote_xml('%s' % self.valueOf_)1324 value=value.replace('![CDATA','<![CDATA')1325 value=value.replace(']]',']]>')1326 outfile.write(value)1327 else:1328 outfile.write(quote_xml('%s' % self.valueOf_))1329 def hasContent_(self):1330 if (1331 self.valueOf_1332 ):1333 return True1334 else:1335 return False1336 def exportLiteral(self, outfile, level, name_='cname'):1337 level += 11338 self.exportLiteralAttributes(outfile, level, name_)1339 if self.hasContent_():1340 self.exportLiteralChildren(outfile, level, name_)1341 def exportLiteralAttributes(self, outfile, level, name_):1342 if self.timestamp is not None:1343 showIndent(outfile, level)1344 outfile.write('timestamp = "%s",\n' % (self.timestamp,))1345 def exportLiteralChildren(self, outfile, level, name_):1346 showIndent(outfile, level)1347 outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))1348 def build(self, node_):1349 attrs = node_.attributes1350 self.buildAttributes(attrs)1351 self.valueOf_ = ''1352 for child_ in node_.childNodes:1353 nodeName_ = child_.nodeName.split(':')[-1]1354 self.buildChildren(child_, nodeName_)1355 def buildAttributes(self, attrs):1356 if attrs.get('timestamp'):1357 self.timestamp = attrs.get('timestamp').value1358 def buildChildren(self, child_, nodeName_):1359 if child_.nodeType == Node.TEXT_NODE:1360 self.valueOf_ += child_.nodeValue1361 elif child_.nodeType == Node.CDATA_SECTION_NODE:1362 self.valueOf_ += '![CDATA['+child_.nodeValue+']]'1363# end class cname1364class contents(GeneratedsSuper):1365 subclass = None1366 superclass = None1367 def __init__(self, content=None, content_type=None, content_length=None, hashes=None):1368 if content is None:1369 self.content = []1370 else:1371 self.content = content1372 if content_type is None:1373 self.content_type = []1374 else:1375 self.content_type = content_type1376 if content_length is None:1377 self.content_length = []1378 else:1379 self.content_length = content_length1380 if hashes is None:1381 self.hashes = []1382 else:1383 self.hashes = hashes1384 def factory(*args_, **kwargs_):1385 if contents.subclass:1386 return contents.subclass(*args_, **kwargs_)1387 else:1388 return contents(*args_, **kwargs_)1389 factory = staticmethod(factory)1390 def get_content(self): return self.content1391 def set_content(self, content): self.content = content1392 def add_content(self, value): self.content.append(value)1393 def insert_content(self, index, value): self.content[index] = value1394 def get_content_type(self): return self.content_type1395 def set_content_type(self, content_type): self.content_type = content_type1396 def add_content_type(self, value): self.content_type.append(value)1397 def insert_content_type(self, index, value): self.content_type[index] = value1398 def get_content_length(self): return self.content_length1399 def set_content_length(self, content_length): self.content_length = content_length1400 def add_content_length(self, value): self.content_length.append(value)1401 def insert_content_length(self, index, value): self.content_length[index] = value1402 def get_hashes(self): return self.hashes1403 def set_hashes(self, hashes): self.hashes = hashes1404 def add_hashes(self, value): self.hashes.append(value)1405 def insert_hashes(self, index, value): self.hashes[index] = value1406 def export(self, outfile, level, namespace_='', name_='contents', namespacedef_=''):1407 showIndent(outfile, level)1408 outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))1409 self.exportAttributes(outfile, level, namespace_, name_='contents')1410 if self.hasContent_():1411 outfile.write('>\n')1412 self.exportChildren(outfile, level + 1, namespace_, name_)1413 showIndent(outfile, level)1414 outfile.write('</%s%s>\n' % (namespace_, name_))1415 else:1416 outfile.write('/>\n')1417 def exportAttributes(self, outfile, level, namespace_='', name_='contents'):1418 pass1419 def exportChildren(self, outfile, level, namespace_='', name_='contents'):1420 for content_ in self.content:1421 showIndent(outfile, level)1422 outfile.write('<%scontent>%s</%scontent>\n' % (namespace_, self.format_string(quote_xml(content_).encode(ExternalEncoding), input_name='content'), namespace_))1423 for content_type_ in self.content_type:1424 showIndent(outfile, level)1425 outfile.write('<%scontent_type>%s</%scontent_type>\n' % (namespace_, self.format_string(quote_xml(content_type_).encode(ExternalEncoding), input_name='content_type'), namespace_))1426 for content_length_ in self.content_length:1427 content_length_.export(outfile, level, namespace_, name_='content_length')1428 for hashes_ in self.hashes:1429 hashes_.export(outfile, level, namespace_, name_='hashes')1430 def hasContent_(self):1431 if (1432 self.content or1433 self.content_type or1434 self.content_length or1435 self.hashes1436 ):1437 return True1438 else:1439 return False1440 def exportLiteral(self, outfile, level, name_='contents'):1441 level += 11442 self.exportLiteralAttributes(outfile, level, name_)1443 if self.hasContent_():1444 self.exportLiteralChildren(outfile, level, name_)1445 def exportLiteralAttributes(self, outfile, level, name_):1446 pass1447 def exportLiteralChildren(self, outfile, level, name_):1448 showIndent(outfile, level)1449 outfile.write('content=[\n')1450 level += 11451 for content_ in self.content:1452 showIndent(outfile, level)1453 outfile.write('%s,\n' % quote_python(content_).encode(ExternalEncoding))1454 level -= 11455 showIndent(outfile, level)1456 outfile.write('],\n')1457 showIndent(outfile, level)1458 outfile.write('content_type=[\n')1459 level += 11460 for content_type_ in self.content_type:1461 showIndent(outfile, level)1462 outfile.write('%s,\n' % quote_python(content_type_).encode(ExternalEncoding))1463 level -= 11464 showIndent(outfile, level)1465 outfile.write('],\n')1466 showIndent(outfile, level)1467 outfile.write('content_length=[\n')1468 level += 11469 for content_length_ in self.content_length:1470 showIndent(outfile, level)1471 outfile.write('model_.content_length(\n')1472 content_length_.exportLiteral(outfile, level, name_='content-length')1473 showIndent(outfile, level)1474 outfile.write('),\n')1475 level -= 11476 showIndent(outfile, level)1477 outfile.write('],\n')1478 showIndent(outfile, level)1479 outfile.write('hashes=[\n')1480 level += 11481 for hashes_ in self.hashes:1482 showIndent(outfile, level)1483 outfile.write('model_.hashes(\n')1484 hashes_.exportLiteral(outfile, level)1485 showIndent(outfile, level)1486 outfile.write('),\n')1487 level -= 11488 showIndent(outfile, level)1489 outfile.write('],\n')1490 def build(self, node_):1491 attrs = node_.attributes1492 self.buildAttributes(attrs)1493 for child_ in node_.childNodes:1494 nodeName_ = child_.nodeName.split(':')[-1]1495 self.buildChildren(child_, nodeName_)1496 def buildAttributes(self, attrs):1497 pass1498 def buildChildren(self, child_, nodeName_):1499 if child_.nodeType == Node.ELEMENT_NODE and \1500 nodeName_ == 'content':1501 content_ = ''1502 for text__content_ in child_.childNodes:1503 content_ += text__content_.nodeValue1504 self.content.append(content_)1505 elif child_.nodeType == Node.ELEMENT_NODE and \1506 nodeName_ == 'content-type':1507 content_type_ = ''1508 for text__content_ in child_.childNodes:1509 content_type_ += text__content_.nodeValue1510 self.content_type.append(content_type_)1511 elif child_.nodeType == Node.ELEMENT_NODE and \1512 nodeName_ == 'content-length':1513 obj_ = content_length.factory()1514 obj_.build(child_)1515 self.content_length.append(obj_)1516 elif child_.nodeType == Node.ELEMENT_NODE and \1517 nodeName_ == 'hashes':1518 obj_ = hashes.factory()1519 obj_.build(child_)1520 self.hashes.append(obj_)1521# end class contents1522class content_length(GeneratedsSuper):1523 subclass = None1524 superclass = None1525 def __init__(self, units=None, valueOf_=''):1526 self.units = _cast(None, units)1527 self.valueOf_ = valueOf_1528 def factory(*args_, **kwargs_):1529 if content_length.subclass:1530 return content_length.subclass(*args_, **kwargs_)1531 else:1532 return content_length(*args_, **kwargs_)1533 factory = staticmethod(factory)1534 def get_units(self): return self.units1535 def set_units(self, units): self.units = units1536 def getValueOf_(self): return self.valueOf_1537 def setValueOf_(self, valueOf_): self.valueOf_ = valueOf_1538 def export(self, outfile, level, namespace_='', name_='content-length', namespacedef_=''):1539 showIndent(outfile, level)1540 outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))1541 self.exportAttributes(outfile, level, namespace_, name_='content-length')1542 if self.hasContent_():1543 outfile.write('>')1544 self.exportChildren(outfile, level + 1, namespace_, name_)1545 outfile.write('</%s%s>\n' % (namespace_, name_))1546 else:1547 outfile.write('/>\n')1548 def exportAttributes(self, outfile, level, namespace_='', name_='content-length'):1549 if self.units is not None:1550 outfile.write(' units=%s' % (self.format_string(quote_attrib(self.units).encode(ExternalEncoding), input_name='units'), ))1551 def exportChildren(self, outfile, level, namespace_='', name_='content-length'):1552 if self.valueOf_.find('![CDATA') > -1:1553 value=quote_xml('%s' % self.valueOf_)1554 value=value.replace('![CDATA','<![CDATA')1555 value=value.replace(']]',']]>')1556 outfile.write(value)1557 else:1558 outfile.write(quote_xml('%s' % self.valueOf_))1559 def hasContent_(self):1560 if (1561 self.valueOf_1562 ):1563 return True1564 else:1565 return False1566 def exportLiteral(self, outfile, level, name_='content-length'):1567 level += 11568 self.exportLiteralAttributes(outfile, level, name_)1569 if self.hasContent_():1570 self.exportLiteralChildren(outfile, level, name_)1571 def exportLiteralAttributes(self, outfile, level, name_):1572 if self.units is not None:1573 showIndent(outfile, level)1574 outfile.write('units = "%s",\n' % (self.units,))1575 def exportLiteralChildren(self, outfile, level, name_):1576 showIndent(outfile, level)1577 outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))1578 def build(self, node_):1579 attrs = node_.attributes1580 self.buildAttributes(attrs)1581 self.valueOf_ = ''1582 for child_ in node_.childNodes:1583 nodeName_ = child_.nodeName.split(':')[-1]1584 self.buildChildren(child_, nodeName_)1585 def buildAttributes(self, attrs):1586 if attrs.get('units'):1587 self.units = attrs.get('units').value1588 def buildChildren(self, child_, nodeName_):1589 if child_.nodeType == Node.TEXT_NODE:1590 self.valueOf_ += child_.nodeValue1591 elif child_.nodeType == Node.CDATA_SECTION_NODE:1592 self.valueOf_ += '![CDATA['+child_.nodeValue+']]'1593# end class content_length1594class hashes(GeneratedsSuper):1595 subclass = None1596 superclass = None1597 def __init__(self, hash=None):1598 if hash is None:1599 self.hash = []1600 else:1601 self.hash = hash1602 def factory(*args_, **kwargs_):1603 if hashes.subclass:1604 return hashes.subclass(*args_, **kwargs_)1605 else:1606 return hashes(*args_, **kwargs_)1607 factory = staticmethod(factory)1608 def get_hash(self): return self.hash1609 def set_hash(self, hash): self.hash = hash1610 def add_hash(self, value): self.hash.append(value)1611 def insert_hash(self, index, value): self.hash[index] = value1612 def export(self, outfile, level, namespace_='', name_='hashes', namespacedef_=''):1613 showIndent(outfile, level)1614 outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))1615 self.exportAttributes(outfile, level, namespace_, name_='hashes')1616 if self.hasContent_():1617 outfile.write('>\n')1618 self.exportChildren(outfile, level + 1, namespace_, name_)1619 showIndent(outfile, level)1620 outfile.write('</%s%s>\n' % (namespace_, name_))1621 else:1622 outfile.write('/>\n')1623 def exportAttributes(self, outfile, level, namespace_='', name_='hashes'):1624 pass1625 def exportChildren(self, outfile, level, namespace_='', name_='hashes'):1626 for hash_ in self.hash:1627 hash_.export(outfile, level, namespace_, name_='hash')1628 def hasContent_(self):1629 if (1630 self.hash1631 ):1632 return True1633 else:1634 return False1635 def exportLiteral(self, outfile, level, name_='hashes'):1636 level += 11637 self.exportLiteralAttributes(outfile, level, name_)1638 if self.hasContent_():1639 self.exportLiteralChildren(outfile, level, name_)1640 def exportLiteralAttributes(self, outfile, level, name_):1641 pass1642 def exportLiteralChildren(self, outfile, level, name_):1643 showIndent(outfile, level)1644 outfile.write('hash=[\n')1645 level += 11646 for hash_ in self.hash:1647 showIndent(outfile, level)1648 outfile.write('model_.hash(\n')1649 hash_.exportLiteral(outfile, level)1650 showIndent(outfile, level)1651 outfile.write('),\n')1652 level -= 11653 showIndent(outfile, level)1654 outfile.write('],\n')1655 def build(self, node_):1656 attrs = node_.attributes1657 self.buildAttributes(attrs)1658 for child_ in node_.childNodes:1659 nodeName_ = child_.nodeName.split(':')[-1]1660 self.buildChildren(child_, nodeName_)1661 def buildAttributes(self, attrs):1662 pass1663 def buildChildren(self, child_, nodeName_):1664 if child_.nodeType == Node.ELEMENT_NODE and \1665 nodeName_ == 'hash':1666 obj_ = hash.factory()1667 obj_.build(child_)1668 self.hash.append(obj_)1669# end class hashes1670class hash(GeneratedsSuper):1671 subclass = None1672 superclass = None1673 def __init__(self, algorithm=None, valueOf_=''):1674 self.algorithm = _cast(None, algorithm)1675 self.valueOf_ = valueOf_1676 def factory(*args_, **kwargs_):1677 if hash.subclass:1678 return hash.subclass(*args_, **kwargs_)1679 else:1680 return hash(*args_, **kwargs_)1681 factory = staticmethod(factory)1682 def get_algorithm(self): return self.algorithm1683 def set_algorithm(self, algorithm): self.algorithm = algorithm1684 def getValueOf_(self): return self.valueOf_1685 def setValueOf_(self, valueOf_): self.valueOf_ = valueOf_1686 def export(self, outfile, level, namespace_='', name_='hash', namespacedef_=''):1687 showIndent(outfile, level)1688 outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))1689 self.exportAttributes(outfile, level, namespace_, name_='hash')1690 if self.hasContent_():1691 outfile.write('>')1692 self.exportChildren(outfile, level + 1, namespace_, name_)1693 outfile.write('</%s%s>\n' % (namespace_, name_))1694 else:1695 outfile.write('/>\n')1696 def exportAttributes(self, outfile, level, namespace_='', name_='hash'):1697 if self.algorithm is not None:1698 outfile.write(' algorithm=%s' % (quote_attrib(self.algorithm), ))1699 def exportChildren(self, outfile, level, namespace_='', name_='hash'):1700 if self.valueOf_.find('![CDATA') > -1:1701 value=quote_xml('%s' % self.valueOf_)1702 value=value.replace('![CDATA','<![CDATA')1703 value=value.replace(']]',']]>')1704 outfile.write(value)1705 else:1706 outfile.write(quote_xml('%s' % self.valueOf_))1707 def hasContent_(self):1708 if (1709 self.valueOf_1710 ):1711 return True1712 else:1713 return False1714 def exportLiteral(self, outfile, level, name_='hash'):1715 level += 11716 self.exportLiteralAttributes(outfile, level, name_)1717 if self.hasContent_():1718 self.exportLiteralChildren(outfile, level, name_)1719 def exportLiteralAttributes(self, outfile, level, name_):1720 if self.algorithm is not None:1721 showIndent(outfile, level)1722 outfile.write('algorithm = %s,\n' % (self.algorithm,))1723 def exportLiteralChildren(self, outfile, level, name_):1724 showIndent(outfile, level)1725 outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))1726 def build(self, node_):1727 attrs = node_.attributes1728 self.buildAttributes(attrs)1729 self.valueOf_ = ''1730 for child_ in node_.childNodes:1731 nodeName_ = child_.nodeName.split(':')[-1]1732 self.buildChildren(child_, nodeName_)1733 def buildAttributes(self, attrs):1734 if attrs.get('algorithm'):1735 self.algorithm = attrs.get('algorithm').value1736 def buildChildren(self, child_, nodeName_):1737 if child_.nodeType == Node.TEXT_NODE:1738 self.valueOf_ += child_.nodeValue1739 elif child_.nodeType == Node.CDATA_SECTION_NODE:1740 self.valueOf_ += '![CDATA['+child_.nodeValue+']]'1741# end class hash1742class outgoingLinks(GeneratedsSuper):1743 subclass = None1744 superclass = None1745 def __init__(self, link=None):1746 if link is None:1747 self.link = []1748 else:1749 self.link = link1750 def factory(*args_, **kwargs_):1751 if outgoingLinks.subclass:1752 return outgoingLinks.subclass(*args_, **kwargs_)1753 else:1754 return outgoingLinks(*args_, **kwargs_)1755 factory = staticmethod(factory)1756 def get_link(self): return self.link1757 def set_link(self, link): self.link = link1758 def add_link(self, value): self.link.append(value)1759 def insert_link(self, index, value): self.link[index] = value1760 def export(self, outfile, level, namespace_='', name_='outgoingLinks', namespacedef_=''):1761 showIndent(outfile, level)1762 outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))1763 self.exportAttributes(outfile, level, namespace_, name_='outgoingLinks')1764 if self.hasContent_():1765 outfile.write('>\n')1766 self.exportChildren(outfile, level + 1, namespace_, name_)1767 showIndent(outfile, level)1768 outfile.write('</%s%s>\n' % (namespace_, name_))1769 else:1770 outfile.write('/>\n')1771 def exportAttributes(self, outfile, level, namespace_='', name_='outgoingLinks'):1772 pass1773 def exportChildren(self, outfile, level, namespace_='', name_='outgoingLinks'):1774 for link_ in self.link:1775 link_.export(outfile, level, namespace_, name_='link')1776 def hasContent_(self):1777 if (1778 self.link1779 ):1780 return True1781 else:1782 return False1783 def exportLiteral(self, outfile, level, name_='outgoingLinks'):1784 level += 11785 self.exportLiteralAttributes(outfile, level, name_)1786 if self.hasContent_():1787 self.exportLiteralChildren(outfile, level, name_)1788 def exportLiteralAttributes(self, outfile, level, name_):1789 pass1790 def exportLiteralChildren(self, outfile, level, name_):1791 showIndent(outfile, level)1792 outfile.write('link=[\n')1793 level += 11794 for link_ in self.link:1795 showIndent(outfile, level)1796 outfile.write('model_.link(\n')1797 link_.exportLiteral(outfile, level)1798 showIndent(outfile, level)1799 outfile.write('),\n')1800 level -= 11801 showIndent(outfile, level)1802 outfile.write('],\n')1803 def build(self, node_):1804 attrs = node_.attributes1805 self.buildAttributes(attrs)1806 for child_ in node_.childNodes:1807 nodeName_ = child_.nodeName.split(':')[-1]1808 self.buildChildren(child_, nodeName_)1809 def buildAttributes(self, attrs):1810 pass1811 def buildChildren(self, child_, nodeName_):1812 if child_.nodeType == Node.ELEMENT_NODE and \1813 nodeName_ == 'link':1814 obj_ = link.factory()1815 obj_.build(child_)1816 self.link.append(obj_)1817# end class outgoingLinks1818class link(GeneratedsSuper):1819 subclass = None1820 superclass = None1821 def __init__(self, tag=None, valueOf_=''):1822 self.tag = _cast(None, tag)1823 self.valueOf_ = valueOf_1824 def factory(*args_, **kwargs_):1825 if link.subclass:1826 return link.subclass(*args_, **kwargs_)1827 else:1828 return link(*args_, **kwargs_)1829 factory = staticmethod(factory)1830 def get_tag(self): return self.tag1831 def set_tag(self, tag): self.tag = tag1832 def getValueOf_(self): return self.valueOf_1833 def setValueOf_(self, valueOf_): self.valueOf_ = valueOf_1834 def export(self, outfile, level, namespace_='', name_='link', namespacedef_=''):1835 showIndent(outfile, level)1836 outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))1837 self.exportAttributes(outfile, level, namespace_, name_='link')1838 if self.hasContent_():1839 outfile.write('>')1840 self.exportChildren(outfile, level + 1, namespace_, name_)1841 outfile.write('</%s%s>\n' % (namespace_, name_))1842 else:1843 outfile.write('/>\n')1844 def exportAttributes(self, outfile, level, namespace_='', name_='link'):1845 if self.tag is not None:1846 outfile.write(' tag=%s' % (self.format_string(quote_attrib(self.tag).encode(ExternalEncoding), input_name='tag'), ))1847 def exportChildren(self, outfile, level, namespace_='', name_='link'):1848 if self.valueOf_.find('![CDATA') > -1:1849 value=quote_xml('%s' % self.valueOf_)1850 value=value.replace('![CDATA','<![CDATA')1851 value=value.replace(']]',']]>')1852 outfile.write(value)1853 else:1854 outfile.write(quote_xml('%s' % self.valueOf_))1855 def hasContent_(self):1856 if (1857 self.valueOf_1858 ):1859 return True1860 else:1861 return False1862 def exportLiteral(self, outfile, level, name_='link'):1863 level += 11864 self.exportLiteralAttributes(outfile, level, name_)1865 if self.hasContent_():1866 self.exportLiteralChildren(outfile, level, name_)1867 def exportLiteralAttributes(self, outfile, level, name_):1868 if self.tag is not None:1869 showIndent(outfile, level)1870 outfile.write('tag = "%s",\n' % (self.tag,))1871 def exportLiteralChildren(self, outfile, level, name_):1872 showIndent(outfile, level)1873 outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))1874 def build(self, node_):1875 attrs = node_.attributes1876 self.buildAttributes(attrs)1877 self.valueOf_ = ''1878 for child_ in node_.childNodes:1879 nodeName_ = child_.nodeName.split(':')[-1]1880 self.buildChildren(child_, nodeName_)1881 def buildAttributes(self, attrs):1882 if attrs.get('tag'):1883 self.tag = attrs.get('tag').value1884 def buildChildren(self, child_, nodeName_):1885 if child_.nodeType == Node.TEXT_NODE:1886 self.valueOf_ += child_.nodeValue1887 elif child_.nodeType == Node.CDATA_SECTION_NODE:1888 self.valueOf_ += '![CDATA['+child_.nodeValue+']]'1889# end class link1890class kit(GeneratedsSuper):1891 subclass = None1892 superclass = None1893 def __init__(self, version=None, valueOf_=''):1894 self.version = _cast(None, version)1895 self.valueOf_ = valueOf_1896 def factory(*args_, **kwargs_):1897 if kit.subclass:1898 return kit.subclass(*args_, **kwargs_)1899 else:1900 return kit(*args_, **kwargs_)1901 factory = staticmethod(factory)1902 def get_version(self): return self.version1903 def set_version(self, version): self.version = version1904 def getValueOf_(self): return self.valueOf_1905 def setValueOf_(self, valueOf_): self.valueOf_ = valueOf_1906 def export(self, outfile, level, namespace_='', name_='kit', namespacedef_=''):1907 showIndent(outfile, level)1908 outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))1909 self.exportAttributes(outfile, level, namespace_, name_='kit')1910 if self.hasContent_():1911 outfile.write('>')1912 self.exportChildren(outfile, level + 1, namespace_, name_)1913 outfile.write('</%s%s>\n' % (namespace_, name_))1914 else:1915 outfile.write('/>\n')1916 def exportAttributes(self, outfile, level, namespace_='', name_='kit'):1917 if self.version is not None:1918 outfile.write(' version=%s' % (self.format_string(quote_attrib(self.version).encode(ExternalEncoding), input_name='version'), ))1919 def exportChildren(self, outfile, level, namespace_='', name_='kit'):1920 if self.valueOf_.find('![CDATA') > -1:1921 value=quote_xml('%s' % self.valueOf_)1922 value=value.replace('![CDATA','<![CDATA')1923 value=value.replace(']]',']]>')1924 outfile.write(value)1925 else:1926 outfile.write(quote_xml('%s' % self.valueOf_))1927 def hasContent_(self):1928 if (1929 self.valueOf_1930 ):1931 return True1932 else:1933 return False1934 def exportLiteral(self, outfile, level, name_='kit'):1935 level += 11936 self.exportLiteralAttributes(outfile, level, name_)1937 if self.hasContent_():1938 self.exportLiteralChildren(outfile, level, name_)1939 def exportLiteralAttributes(self, outfile, level, name_):1940 if self.version is not None:1941 showIndent(outfile, level)1942 outfile.write('version = "%s",\n' % (self.version,))1943 def exportLiteralChildren(self, outfile, level, name_):1944 showIndent(outfile, level)1945 outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))1946 def build(self, node_):1947 attrs = node_.attributes1948 self.buildAttributes(attrs)1949 self.valueOf_ = ''1950 for child_ in node_.childNodes:1951 nodeName_ = child_.nodeName.split(':')[-1]1952 self.buildChildren(child_, nodeName_)1953 def buildAttributes(self, attrs):1954 if attrs.get('version'):1955 self.version = attrs.get('version').value1956 def buildChildren(self, child_, nodeName_):1957 if child_.nodeType == Node.TEXT_NODE:1958 self.valueOf_ += child_.nodeValue1959 elif child_.nodeType == Node.CDATA_SECTION_NODE:1960 self.valueOf_ += '![CDATA['+child_.nodeValue+']]'1961# end class kit1962class exploits(GeneratedsSuper):1963 subclass = None1964 superclass = None1965 def __init__(self, exploit=None):1966 if exploit is None:1967 self.exploit = []1968 else:1969 self.exploit = exploit1970 def factory(*args_, **kwargs_):1971 if exploits.subclass:1972 return exploits.subclass(*args_, **kwargs_)1973 else:1974 return exploits(*args_, **kwargs_)1975 factory = staticmethod(factory)1976 def get_exploit(self): return self.exploit1977 def set_exploit(self, exploit): self.exploit = exploit1978 def add_exploit(self, value): self.exploit.append(value)1979 def insert_exploit(self, index, value): self.exploit[index] = value1980 def export(self, outfile, level, namespace_='', name_='exploits', namespacedef_=''):1981 showIndent(outfile, level)1982 outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))1983 self.exportAttributes(outfile, level, namespace_, name_='exploits')1984 if self.hasContent_():1985 outfile.write('>\n')1986 self.exportChildren(outfile, level + 1, namespace_, name_)1987 showIndent(outfile, level)1988 outfile.write('</%s%s>\n' % (namespace_, name_))1989 else:1990 outfile.write('/>\n')1991 def exportAttributes(self, outfile, level, namespace_='', name_='exploits'):1992 pass1993 def exportChildren(self, outfile, level, namespace_='', name_='exploits'):1994 for exploit_ in self.exploit:1995 exploit_.export(outfile, level, namespace_, name_='exploit')1996 def hasContent_(self):1997 if (1998 self.exploit1999 ):2000 return True2001 else:2002 return False2003 def exportLiteral(self, outfile, level, name_='exploits'):2004 level += 12005 self.exportLiteralAttributes(outfile, level, name_)2006 if self.hasContent_():2007 self.exportLiteralChildren(outfile, level, name_)2008 def exportLiteralAttributes(self, outfile, level, name_):2009 pass2010 def exportLiteralChildren(self, outfile, level, name_):2011 showIndent(outfile, level)2012 outfile.write('exploit=[\n')2013 level += 12014 for exploit_ in self.exploit:2015 showIndent(outfile, level)2016 outfile.write('model_.exploit(\n')2017 exploit_.exportLiteral(outfile, level)2018 showIndent(outfile, level)2019 outfile.write('),\n')2020 level -= 12021 showIndent(outfile, level)2022 outfile.write('],\n')2023 def build(self, node_):2024 attrs = node_.attributes2025 self.buildAttributes(attrs)2026 for child_ in node_.childNodes:2027 nodeName_ = child_.nodeName.split(':')[-1]2028 self.buildChildren(child_, nodeName_)2029 def buildAttributes(self, attrs):2030 pass2031 def buildChildren(self, child_, nodeName_):2032 if child_.nodeType == Node.ELEMENT_NODE and \2033 nodeName_ == 'exploit':2034 obj_ = exploit.factory()2035 obj_.build(child_)2036 self.exploit.append(obj_)2037# end class exploits2038class exploit(GeneratedsSuper):2039 subclass = None2040 superclass = None2041 def __init__(self, shellcode=None, vulnerability=None, module=None, consequence=None):2042 if shellcode is None:2043 self.shellcode = []2044 else:2045 self.shellcode = shellcode2046 if vulnerability is None:2047 self.vulnerability = []2048 else:2049 self.vulnerability = vulnerability2050 if module is None:2051 self.module = []2052 else:2053 self.module = module2054 if consequence is None:2055 self.consequence = []2056 else:2057 self.consequence = consequence2058 def factory(*args_, **kwargs_):2059 if exploit.subclass:2060 return exploit.subclass(*args_, **kwargs_)2061 else:2062 return exploit(*args_, **kwargs_)2063 factory = staticmethod(factory)2064 def get_shellcode(self): return self.shellcode2065 def set_shellcode(self, shellcode): self.shellcode = shellcode2066 def add_shellcode(self, value): self.shellcode.append(value)2067 def insert_shellcode(self, index, value): self.shellcode[index] = value2068 def get_vulnerability(self): return self.vulnerability2069 def set_vulnerability(self, vulnerability): self.vulnerability = vulnerability2070 def add_vulnerability(self, value): self.vulnerability.append(value)2071 def insert_vulnerability(self, index, value): self.vulnerability[index] = value2072 def get_module(self): return self.module2073 def set_module(self, module): self.module = module2074 def add_module(self, value): self.module.append(value)2075 def insert_module(self, index, value): self.module[index] = value2076 def get_consequence(self): return self.consequence2077 def set_consequence(self, consequence): self.consequence = consequence2078 def add_consequence(self, value): self.consequence.append(value)2079 def insert_consequence(self, index, value): self.consequence[index] = value2080 def export(self, outfile, level, namespace_='', name_='exploit', namespacedef_=''):2081 showIndent(outfile, level)2082 outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))2083 self.exportAttributes(outfile, level, namespace_, name_='exploit')2084 if self.hasContent_():2085 outfile.write('>\n')2086 self.exportChildren(outfile, level + 1, namespace_, name_)2087 showIndent(outfile, level)2088 outfile.write('</%s%s>\n' % (namespace_, name_))2089 else:2090 outfile.write('/>\n')2091 def exportAttributes(self, outfile, level, namespace_='', name_='exploit'):2092 pass2093 def exportChildren(self, outfile, level, namespace_='', name_='exploit'):2094 for shellcode_ in self.shellcode:2095 showIndent(outfile, level)2096 outfile.write('<%sshellcode>%s</%sshellcode>\n' % (namespace_, self.format_string(quote_xml(shellcode_).encode(ExternalEncoding), input_name='shellcode'), namespace_))2097 for vulnerability_ in self.vulnerability:2098 vulnerability_.export(outfile, level, namespace_, name_='vulnerability')2099 for module_ in self.module:2100 module_.export(outfile, level, namespace_, name_='module')2101 for consequence_ in self.consequence:2102 consequence_.export(outfile, level, namespace_, name_='consequence')2103 def hasContent_(self):2104 if (2105 self.shellcode or2106 self.vulnerability or2107 self.module or2108 self.consequence2109 ):2110 return True2111 else:2112 return False2113 def exportLiteral(self, outfile, level, name_='exploit'):2114 level += 12115 self.exportLiteralAttributes(outfile, level, name_)2116 if self.hasContent_():2117 self.exportLiteralChildren(outfile, level, name_)2118 def exportLiteralAttributes(self, outfile, level, name_):2119 pass2120 def exportLiteralChildren(self, outfile, level, name_):2121 showIndent(outfile, level)2122 outfile.write('shellcode=[\n')2123 level += 12124 for shellcode_ in self.shellcode:2125 showIndent(outfile, level)2126 outfile.write('%s,\n' % quote_python(shellcode_).encode(ExternalEncoding))2127 level -= 12128 showIndent(outfile, level)2129 outfile.write('],\n')2130 showIndent(outfile, level)2131 outfile.write('vulnerability=[\n')2132 level += 12133 for vulnerability_ in self.vulnerability:2134 showIndent(outfile, level)2135 outfile.write('model_.vulnerability(\n')2136 vulnerability_.exportLiteral(outfile, level)2137 showIndent(outfile, level)2138 outfile.write('),\n')2139 level -= 12140 showIndent(outfile, level)2141 outfile.write('],\n')2142 showIndent(outfile, level)2143 outfile.write('module=[\n')2144 level += 12145 for module_ in self.module:2146 showIndent(outfile, level)2147 outfile.write('model_.module(\n')2148 module_.exportLiteral(outfile, level)2149 showIndent(outfile, level)2150 outfile.write('),\n')2151 level -= 12152 showIndent(outfile, level)2153 outfile.write('],\n')2154 showIndent(outfile, level)2155 outfile.write('consequence=[\n')2156 level += 12157 for consequence_ in self.consequence:2158 showIndent(outfile, level)2159 outfile.write('model_.consequence(\n')2160 consequence_.exportLiteral(outfile, level)2161 showIndent(outfile, level)2162 outfile.write('),\n')2163 level -= 12164 showIndent(outfile, level)2165 outfile.write('],\n')2166 def build(self, node_):2167 attrs = node_.attributes2168 self.buildAttributes(attrs)2169 for child_ in node_.childNodes:2170 nodeName_ = child_.nodeName.split(':')[-1]2171 self.buildChildren(child_, nodeName_)2172 def buildAttributes(self, attrs):2173 pass2174 def buildChildren(self, child_, nodeName_):2175 if child_.nodeType == Node.ELEMENT_NODE and \2176 nodeName_ == 'shellcode':2177 shellcode_ = ''2178 for text__content_ in child_.childNodes:2179 shellcode_ += text__content_.nodeValue2180 self.shellcode.append(shellcode_)2181 elif child_.nodeType == Node.ELEMENT_NODE and \2182 nodeName_ == 'vulnerability':2183 obj_ = vulnerability.factory()2184 obj_.build(child_)2185 self.vulnerability.append(obj_)2186 elif child_.nodeType == Node.ELEMENT_NODE and \2187 nodeName_ == 'module':2188 obj_ = module.factory()2189 obj_.build(child_)2190 self.module.append(obj_)2191 elif child_.nodeType == Node.ELEMENT_NODE and \2192 nodeName_ == 'consequence':2193 obj_ = consequence.factory()2194 obj_.build(child_)2195 self.consequence.append(obj_)2196# end class exploit2197class vulnerability(GeneratedsSuper):2198 subclass = None2199 superclass = None2200 def __init__(self, id=None, valueOf_=''):2201 self.id = _cast(None, id)2202 self.valueOf_ = valueOf_2203 def factory(*args_, **kwargs_):2204 if vulnerability.subclass:2205 return vulnerability.subclass(*args_, **kwargs_)2206 else:2207 return vulnerability(*args_, **kwargs_)2208 factory = staticmethod(factory)2209 def get_id(self): return self.id2210 def set_id(self, id): self.id = id2211 def getValueOf_(self): return self.valueOf_2212 def setValueOf_(self, valueOf_): self.valueOf_ = valueOf_2213 def export(self, outfile, level, namespace_='', name_='vulnerability', namespacedef_=''):2214 showIndent(outfile, level)2215 outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))2216 self.exportAttributes(outfile, level, namespace_, name_='vulnerability')2217 if self.hasContent_():2218 outfile.write('>')2219 self.exportChildren(outfile, level + 1, namespace_, name_)2220 outfile.write('</%s%s>\n' % (namespace_, name_))2221 else:2222 outfile.write('/>\n')2223 def exportAttributes(self, outfile, level, namespace_='', name_='vulnerability'):2224 if self.id is not None:2225 outfile.write(' id=%s' % (self.format_string(quote_attrib(self.id).encode(ExternalEncoding), input_name='id'), ))2226 def exportChildren(self, outfile, level, namespace_='', name_='vulnerability'):2227 if self.valueOf_.find('![CDATA') > -1:2228 value=quote_xml('%s' % self.valueOf_)2229 value=value.replace('![CDATA','<![CDATA')2230 value=value.replace(']]',']]>')2231 outfile.write(value)2232 else:2233 outfile.write(quote_xml('%s' % self.valueOf_))2234 def hasContent_(self):2235 if (2236 self.valueOf_2237 ):2238 return True2239 else:2240 return False2241 def exportLiteral(self, outfile, level, name_='vulnerability'):2242 level += 12243 self.exportLiteralAttributes(outfile, level, name_)2244 if self.hasContent_():2245 self.exportLiteralChildren(outfile, level, name_)2246 def exportLiteralAttributes(self, outfile, level, name_):2247 if self.id is not None:2248 showIndent(outfile, level)2249 outfile.write('id = "%s",\n' % (self.id,))2250 def exportLiteralChildren(self, outfile, level, name_):2251 showIndent(outfile, level)2252 outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))2253 def build(self, node_):2254 attrs = node_.attributes2255 self.buildAttributes(attrs)2256 self.valueOf_ = ''2257 for child_ in node_.childNodes:2258 nodeName_ = child_.nodeName.split(':')[-1]2259 self.buildChildren(child_, nodeName_)2260 def buildAttributes(self, attrs):2261 if attrs.get('id'):2262 self.id = attrs.get('id').value2263 def buildChildren(self, child_, nodeName_):2264 if child_.nodeType == Node.TEXT_NODE:2265 self.valueOf_ += child_.nodeValue2266 elif child_.nodeType == Node.CDATA_SECTION_NODE:2267 self.valueOf_ += '![CDATA['+child_.nodeValue+']]'2268# end class vulnerability2269class module(GeneratedsSuper):2270 subclass = None2271 superclass = None2272 def __init__(self, clsname=None, clsid=None, valueOf_=''):2273 self.clsname = _cast(None, clsname)2274 self.clsid = _cast(None, clsid)2275 self.valueOf_ = valueOf_2276 def factory(*args_, **kwargs_):2277 if module.subclass:2278 return module.subclass(*args_, **kwargs_)2279 else:2280 return module(*args_, **kwargs_)2281 factory = staticmethod(factory)2282 def get_clsname(self): return self.clsname2283 def set_clsname(self, clsname): self.clsname = clsname2284 def get_clsid(self): return self.clsid2285 def set_clsid(self, clsid): self.clsid = clsid2286 def getValueOf_(self): return self.valueOf_2287 def setValueOf_(self, valueOf_): self.valueOf_ = valueOf_2288 def export(self, outfile, level, namespace_='', name_='module', namespacedef_=''):2289 showIndent(outfile, level)2290 outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))2291 self.exportAttributes(outfile, level, namespace_, name_='module')2292 if self.hasContent_():2293 outfile.write('>')2294 self.exportChildren(outfile, level + 1, namespace_, name_)2295 outfile.write('</%s%s>\n' % (namespace_, name_))2296 else:2297 outfile.write('/>\n')2298 def exportAttributes(self, outfile, level, namespace_='', name_='module'):2299 if self.clsname is not None:2300 outfile.write(' clsname=%s' % (self.format_string(quote_attrib(self.clsname).encode(ExternalEncoding), input_name='clsname'), ))2301 if self.clsid is not None:2302 outfile.write(' clsid=%s' % (self.format_string(quote_attrib(self.clsid).encode(ExternalEncoding), input_name='clsid'), ))2303 def exportChildren(self, outfile, level, namespace_='', name_='module'):2304 if self.valueOf_.find('![CDATA') > -1:2305 value=quote_xml('%s' % self.valueOf_)2306 value=value.replace('![CDATA','<![CDATA')2307 value=value.replace(']]',']]>')2308 outfile.write(value)2309 else:2310 outfile.write(quote_xml('%s' % self.valueOf_))2311 def hasContent_(self):2312 if (2313 self.valueOf_2314 ):2315 return True2316 else:2317 return False2318 def exportLiteral(self, outfile, level, name_='module'):2319 level += 12320 self.exportLiteralAttributes(outfile, level, name_)2321 if self.hasContent_():2322 self.exportLiteralChildren(outfile, level, name_)2323 def exportLiteralAttributes(self, outfile, level, name_):2324 if self.clsname is not None:2325 showIndent(outfile, level)2326 outfile.write('clsname = "%s",\n' % (self.clsname,))2327 if self.clsid is not None:2328 showIndent(outfile, level)2329 outfile.write('clsid = "%s",\n' % (self.clsid,))2330 def exportLiteralChildren(self, outfile, level, name_):2331 showIndent(outfile, level)2332 outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))2333 def build(self, node_):2334 attrs = node_.attributes2335 self.buildAttributes(attrs)2336 self.valueOf_ = ''2337 for child_ in node_.childNodes:2338 nodeName_ = child_.nodeName.split(':')[-1]2339 self.buildChildren(child_, nodeName_)2340 def buildAttributes(self, attrs):2341 if attrs.get('clsname'):2342 self.clsname = attrs.get('clsname').value2343 if attrs.get('clsid'):2344 self.clsid = attrs.get('clsid').value2345 def buildChildren(self, child_, nodeName_):2346 if child_.nodeType == Node.TEXT_NODE:2347 self.valueOf_ += child_.nodeValue2348 elif child_.nodeType == Node.CDATA_SECTION_NODE:2349 self.valueOf_ += '![CDATA['+child_.nodeValue+']]'2350# end class module2351class consequence(GeneratedsSuper):2352 subclass = None2353 superclass = None2354 def __init__(self, type_=None, additionalData=None):2355 self.type_ = _cast(None, type_)2356 if additionalData is None:2357 self.additionalData = []2358 else:2359 self.additionalData = additionalData2360 def factory(*args_, **kwargs_):2361 if consequence.subclass:2362 return consequence.subclass(*args_, **kwargs_)2363 else:2364 return consequence(*args_, **kwargs_)2365 factory = staticmethod(factory)2366 def get_additionalData(self): return self.additionalData2367 def set_additionalData(self, additionalData): self.additionalData = additionalData2368 def add_additionalData(self, value): self.additionalData.append(value)2369 def insert_additionalData(self, index, value): self.additionalData[index] = value2370 def get_type(self): return self.type_2371 def set_type(self, type_): self.type_ = type_2372 def export(self, outfile, level, namespace_='', name_='consequence', namespacedef_=''):2373 showIndent(outfile, level)2374 outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))2375 self.exportAttributes(outfile, level, namespace_, name_='consequence')2376 if self.hasContent_():2377 outfile.write('>\n')2378 self.exportChildren(outfile, level + 1, namespace_, name_)2379 showIndent(outfile, level)2380 outfile.write('</%s%s>\n' % (namespace_, name_))2381 else:2382 outfile.write('/>\n')2383 def exportAttributes(self, outfile, level, namespace_='', name_='consequence'):2384 if self.type_ is not None:2385 outfile.write(' type=%s' % (self.format_string(quote_attrib(self.type_).encode(ExternalEncoding), input_name='type'), ))2386 def exportChildren(self, outfile, level, namespace_='', name_='consequence'):2387 for additionalData_ in self.additionalData:2388 showIndent(outfile, level)2389 outfile.write('<%sadditionalData>%s</%sadditionalData>\n' % (namespace_, self.format_string(quote_xml(additionalData_).encode(ExternalEncoding), input_name='additionalData'), namespace_))2390 def hasContent_(self):2391 if (2392 self.additionalData2393 ):2394 return True2395 else:2396 return False2397 def exportLiteral(self, outfile, level, name_='consequence'):2398 level += 12399 self.exportLiteralAttributes(outfile, level, name_)2400 if self.hasContent_():2401 self.exportLiteralChildren(outfile, level, name_)2402 def exportLiteralAttributes(self, outfile, level, name_):2403 if self.type_ is not None:2404 showIndent(outfile, level)2405 outfile.write('type_ = "%s",\n' % (self.type_,))2406 def exportLiteralChildren(self, outfile, level, name_):2407 showIndent(outfile, level)2408 outfile.write('additionalData=[\n')2409 level += 12410 for additionalData_ in self.additionalData:2411 showIndent(outfile, level)2412 outfile.write('%s,\n' % quote_python(additionalData_).encode(ExternalEncoding))2413 level -= 12414 showIndent(outfile, level)2415 outfile.write('],\n')2416 def build(self, node_):2417 attrs = node_.attributes2418 self.buildAttributes(attrs)2419 for child_ in node_.childNodes:2420 nodeName_ = child_.nodeName.split(':')[-1]2421 self.buildChildren(child_, nodeName_)2422 def buildAttributes(self, attrs):2423 if attrs.get('type'):2424 self.type_ = attrs.get('type').value2425 def buildChildren(self, child_, nodeName_):2426 if child_.nodeType == Node.ELEMENT_NODE and \2427 nodeName_ == 'additionalData':2428 additionalData_ = ''2429 for text__content_ in child_.childNodes:2430 additionalData_ += text__content_.nodeValue2431 self.additionalData.append(additionalData_)2432# end class consequence2433class classifications(GeneratedsSuper):2434 subclass = None2435 superclass = None2436 def __init__(self, classification=None):2437 if classification is None:2438 self.classification = []2439 else:2440 self.classification = classification2441 def factory(*args_, **kwargs_):2442 if classifications.subclass:2443 return classifications.subclass(*args_, **kwargs_)2444 else:2445 return classifications(*args_, **kwargs_)2446 factory = staticmethod(factory)2447 def get_classification(self): return self.classification2448 def set_classification(self, classification): self.classification = classification2449 def add_classification(self, value): self.classification.append(value)2450 def insert_classification(self, index, value): self.classification[index] = value2451 def export(self, outfile, level, namespace_='', name_='classifications', namespacedef_=''):2452 showIndent(outfile, level)2453 outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))2454 self.exportAttributes(outfile, level, namespace_, name_='classifications')2455 if self.hasContent_():2456 outfile.write('>\n')2457 self.exportChildren(outfile, level + 1, namespace_, name_)2458 showIndent(outfile, level)2459 outfile.write('</%s%s>\n' % (namespace_, name_))2460 else:2461 outfile.write('/>\n')2462 def exportAttributes(self, outfile, level, namespace_='', name_='classifications'):2463 pass2464 def exportChildren(self, outfile, level, namespace_='', name_='classifications'):2465 for classification_ in self.classification:2466 classification_.export(outfile, level, namespace_, name_='classification')2467 def hasContent_(self):2468 if (2469 self.classification2470 ):2471 return True2472 else:2473 return False2474 def exportLiteral(self, outfile, level, name_='classifications'):2475 level += 12476 self.exportLiteralAttributes(outfile, level, name_)2477 if self.hasContent_():2478 self.exportLiteralChildren(outfile, level, name_)2479 def exportLiteralAttributes(self, outfile, level, name_):2480 pass2481 def exportLiteralChildren(self, outfile, level, name_):2482 showIndent(outfile, level)2483 outfile.write('classification=[\n')2484 level += 12485 for classification_ in self.classification:2486 showIndent(outfile, level)2487 outfile.write('model_.classification(\n')2488 classification_.exportLiteral(outfile, level)2489 showIndent(outfile, level)2490 outfile.write('),\n')2491 level -= 12492 showIndent(outfile, level)2493 outfile.write('],\n')2494 def build(self, node_):2495 attrs = node_.attributes2496 self.buildAttributes(attrs)2497 for child_ in node_.childNodes:2498 nodeName_ = child_.nodeName.split(':')[-1]2499 self.buildChildren(child_, nodeName_)2500 def buildAttributes(self, attrs):2501 pass2502 def buildChildren(self, child_, nodeName_):2503 if child_.nodeType == Node.ELEMENT_NODE and \2504 nodeName_ == 'classification':2505 obj_ = classification.factory()2506 obj_.build(child_)2507 self.classification.append(obj_)2508# end class classifications2509class classification(GeneratedsSuper):2510 subclass = None2511 superclass = None2512 def __init__(self, antivirus=None, urlbls=None):2513 if antivirus is None:2514 self.antivirus = []2515 else:2516 self.antivirus = antivirus2517 if urlbls is None:2518 self.urlbls = []2519 else:2520 self.urlbls = urlbls2521 def factory(*args_, **kwargs_):2522 if classification.subclass:2523 return classification.subclass(*args_, **kwargs_)2524 else:2525 return classification(*args_, **kwargs_)2526 factory = staticmethod(factory)2527 def get_antivirus(self): return self.antivirus2528 def set_antivirus(self, antivirus): self.antivirus = antivirus2529 def add_antivirus(self, value): self.antivirus.append(value)2530 def insert_antivirus(self, index, value): self.antivirus[index] = value2531 def get_urlbls(self): return self.urlbls2532 def set_urlbls(self, urlbls): self.urlbls = urlbls2533 def add_urlbls(self, value): self.urlbls.append(value)2534 def insert_urlbls(self, index, value): self.urlbls[index] = value2535 def export(self, outfile, level, namespace_='', name_='classification', namespacedef_=''):2536 showIndent(outfile, level)2537 outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))2538 self.exportAttributes(outfile, level, namespace_, name_='classification')2539 if self.hasContent_():2540 outfile.write('>\n')2541 self.exportChildren(outfile, level + 1, namespace_, name_)2542 showIndent(outfile, level)2543 outfile.write('</%s%s>\n' % (namespace_, name_))2544 else:2545 outfile.write('/>\n')2546 def exportAttributes(self, outfile, level, namespace_='', name_='classification'):2547 pass2548 def exportChildren(self, outfile, level, namespace_='', name_='classification'):2549 for antivirus_ in self.antivirus:2550 antivirus_.export(outfile, level, namespace_, name_='antivirus')2551 for urlbls_ in self.urlbls:2552 urlbls_.export(outfile, level, namespace_, name_='urlbls')2553 def hasContent_(self):2554 if (2555 self.antivirus or2556 self.urlbls2557 ):2558 return True2559 else:2560 return False2561 def exportLiteral(self, outfile, level, name_='classification'):2562 level += 12563 self.exportLiteralAttributes(outfile, level, name_)2564 if self.hasContent_():2565 self.exportLiteralChildren(outfile, level, name_)2566 def exportLiteralAttributes(self, outfile, level, name_):2567 pass2568 def exportLiteralChildren(self, outfile, level, name_):2569 showIndent(outfile, level)2570 outfile.write('antivirus=[\n')2571 level += 12572 for antivirus_ in self.antivirus:2573 showIndent(outfile, level)2574 outfile.write('model_.antivirus(\n')2575 antivirus_.exportLiteral(outfile, level)2576 showIndent(outfile, level)2577 outfile.write('),\n')2578 level -= 12579 showIndent(outfile, level)2580 outfile.write('],\n')2581 showIndent(outfile, level)2582 outfile.write('urlbls=[\n')2583 level += 12584 for urlbls_ in self.urlbls:2585 showIndent(outfile, level)2586 outfile.write('model_.urlbls(\n')2587 urlbls_.exportLiteral(outfile, level)2588 showIndent(outfile, level)2589 outfile.write('),\n')2590 level -= 12591 showIndent(outfile, level)2592 outfile.write('],\n')2593 def build(self, node_):2594 attrs = node_.attributes2595 self.buildAttributes(attrs)2596 for child_ in node_.childNodes:2597 nodeName_ = child_.nodeName.split(':')[-1]2598 self.buildChildren(child_, nodeName_)2599 def buildAttributes(self, attrs):2600 pass2601 def buildChildren(self, child_, nodeName_):2602 if child_.nodeType == Node.ELEMENT_NODE and \2603 nodeName_ == 'antivirus':2604 obj_ = antivirus.factory()2605 obj_.build(child_)2606 self.antivirus.append(obj_)2607 elif child_.nodeType == Node.ELEMENT_NODE and \2608 nodeName_ == 'urlbls':2609 obj_ = urlbls.factory()2610 obj_.build(child_)2611 self.urlbls.append(obj_)2612# end class classification2613class antivirus(GeneratedsSuper):2614 subclass = None2615 superclass = None2616 def __init__(self, engine=None, version=None, datVersion=None, timestamp=None, result=None):2617 if engine is None:2618 self.engine = []2619 else:2620 self.engine = engine2621 if version is None:2622 self.version = []2623 else:2624 self.version = version2625 if datVersion is None:2626 self.datVersion = []2627 else:2628 self.datVersion = datVersion2629 if timestamp is None:2630 self.timestamp = []2631 else:2632 self.timestamp = timestamp2633 if result is None:2634 self.result = []2635 else:2636 self.result = result2637 def factory(*args_, **kwargs_):2638 if antivirus.subclass:2639 return antivirus.subclass(*args_, **kwargs_)2640 else:2641 return antivirus(*args_, **kwargs_)2642 factory = staticmethod(factory)2643 def get_engine(self): return self.engine2644 def set_engine(self, engine): self.engine = engine2645 def add_engine(self, value): self.engine.append(value)2646 def insert_engine(self, index, value): self.engine[index] = value2647 def get_version(self): return self.version2648 def set_version(self, version): self.version = version2649 def add_version(self, value): self.version.append(value)2650 def insert_version(self, index, value): self.version[index] = value2651 def get_datVersion(self): return self.datVersion2652 def set_datVersion(self, datVersion): self.datVersion = datVersion2653 def add_datVersion(self, value): self.datVersion.append(value)2654 def insert_datVersion(self, index, value): self.datVersion[index] = value2655 def get_timestamp(self): return self.timestamp2656 def set_timestamp(self, timestamp): self.timestamp = timestamp2657 def add_timestamp(self, value): self.timestamp.append(value)2658 def insert_timestamp(self, index, value): self.timestamp[index] = value2659 def get_result(self): return self.result2660 def set_result(self, result): self.result = result2661 def add_result(self, value): self.result.append(value)2662 def insert_result(self, index, value): self.result[index] = value2663 def export(self, outfile, level, namespace_='', name_='antivirus', namespacedef_=''):2664 showIndent(outfile, level)2665 outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))2666 self.exportAttributes(outfile, level, namespace_, name_='antivirus')2667 if self.hasContent_():2668 outfile.write('>\n')2669 self.exportChildren(outfile, level + 1, namespace_, name_)2670 showIndent(outfile, level)2671 outfile.write('</%s%s>\n' % (namespace_, name_))2672 else:2673 outfile.write('/>\n')2674 def exportAttributes(self, outfile, level, namespace_='', name_='antivirus'):2675 pass2676 def exportChildren(self, outfile, level, namespace_='', name_='antivirus'):2677 for engine_ in self.engine:2678 showIndent(outfile, level)2679 outfile.write('<%sengine>%s</%sengine>\n' % (namespace_, self.format_string(quote_xml(engine_).encode(ExternalEncoding), input_name='engine'), namespace_))2680 for version_ in self.version:2681 showIndent(outfile, level)2682 outfile.write('<%sversion>%s</%sversion>\n' % (namespace_, self.format_string(quote_xml(version_).encode(ExternalEncoding), input_name='version'), namespace_))2683 for datVersion_ in self.datVersion:2684 showIndent(outfile, level)2685 outfile.write('<%sdatVersion>%s</%sdatVersion>\n' % (namespace_, self.format_string(quote_xml(datVersion_).encode(ExternalEncoding), input_name='datVersion'), namespace_))2686 for timestamp_ in self.timestamp:2687 showIndent(outfile, level)2688 outfile.write('<%stimestamp>%s</%stimestamp>\n' % (namespace_, self.format_string(quote_xml(timestamp_).encode(ExternalEncoding), input_name='timestamp'), namespace_))2689 for result_ in self.result:2690 showIndent(outfile, level)2691 outfile.write('<%sresult>%s</%sresult>\n' % (namespace_, self.format_string(quote_xml(result_).encode(ExternalEncoding), input_name='result'), namespace_))2692 def hasContent_(self):2693 if (2694 self.engine or2695 self.version or2696 self.datVersion or2697 self.timestamp or2698 self.result2699 ):2700 return True2701 else:2702 return False2703 def exportLiteral(self, outfile, level, name_='antivirus'):2704 level += 12705 self.exportLiteralAttributes(outfile, level, name_)2706 if self.hasContent_():2707 self.exportLiteralChildren(outfile, level, name_)2708 def exportLiteralAttributes(self, outfile, level, name_):2709 pass2710 def exportLiteralChildren(self, outfile, level, name_):2711 showIndent(outfile, level)2712 outfile.write('engine=[\n')2713 level += 12714 for engine_ in self.engine:2715 showIndent(outfile, level)2716 outfile.write('%s,\n' % quote_python(engine_).encode(ExternalEncoding))2717 level -= 12718 showIndent(outfile, level)2719 outfile.write('],\n')2720 showIndent(outfile, level)2721 outfile.write('version=[\n')2722 level += 12723 for version_ in self.version:2724 showIndent(outfile, level)2725 outfile.write('%s,\n' % quote_python(version_).encode(ExternalEncoding))2726 level -= 12727 showIndent(outfile, level)2728 outfile.write('],\n')2729 showIndent(outfile, level)2730 outfile.write('datVersion=[\n')2731 level += 12732 for datVersion_ in self.datVersion:2733 showIndent(outfile, level)2734 outfile.write('%s,\n' % quote_python(datVersion_).encode(ExternalEncoding))2735 level -= 12736 showIndent(outfile, level)2737 outfile.write('],\n')2738 showIndent(outfile, level)2739 outfile.write('timestamp=[\n')2740 level += 12741 for timestamp_ in self.timestamp:2742 showIndent(outfile, level)2743 outfile.write('%s,\n' % quote_python(timestamp_).encode(ExternalEncoding))2744 level -= 12745 showIndent(outfile, level)2746 outfile.write('],\n')2747 showIndent(outfile, level)2748 outfile.write('result=[\n')2749 level += 12750 for result_ in self.result:2751 showIndent(outfile, level)2752 outfile.write('%s,\n' % quote_python(result_).encode(ExternalEncoding))2753 level -= 12754 showIndent(outfile, level)2755 outfile.write('],\n')2756 def build(self, node_):2757 attrs = node_.attributes2758 self.buildAttributes(attrs)2759 for child_ in node_.childNodes:2760 nodeName_ = child_.nodeName.split(':')[-1]2761 self.buildChildren(child_, nodeName_)2762 def buildAttributes(self, attrs):2763 pass2764 def buildChildren(self, child_, nodeName_):2765 if child_.nodeType == Node.ELEMENT_NODE and \2766 nodeName_ == 'engine':2767 engine_ = ''2768 for text__content_ in child_.childNodes:2769 engine_ += text__content_.nodeValue2770 self.engine.append(engine_)2771 elif child_.nodeType == Node.ELEMENT_NODE and \2772 nodeName_ == 'version':2773 version_ = ''2774 for text__content_ in child_.childNodes:2775 version_ += text__content_.nodeValue2776 self.version.append(version_)2777 elif child_.nodeType == Node.ELEMENT_NODE and \2778 nodeName_ == 'datVersion':2779 datVersion_ = ''2780 for text__content_ in child_.childNodes:2781 datVersion_ += text__content_.nodeValue2782 self.datVersion.append(datVersion_)2783 elif child_.nodeType == Node.ELEMENT_NODE and \2784 nodeName_ == 'timestamp':2785 timestamp_ = ''2786 for text__content_ in child_.childNodes:2787 timestamp_ += text__content_.nodeValue2788 self.timestamp.append(timestamp_)2789 elif child_.nodeType == Node.ELEMENT_NODE and \2790 nodeName_ == 'result':2791 result_ = ''2792 for text__content_ in child_.childNodes:2793 result_ += text__content_.nodeValue2794 self.result.append(result_)2795# end class antivirus2796class urlbls(GeneratedsSuper):2797 subclass = None2798 superclass = None2799 def __init__(self, urlbl=None):2800 if urlbl is None:2801 self.urlbl = []2802 else:2803 self.urlbl = urlbl2804 def factory(*args_, **kwargs_):2805 if urlbls.subclass:2806 return urlbls.subclass(*args_, **kwargs_)2807 else:2808 return urlbls(*args_, **kwargs_)2809 factory = staticmethod(factory)2810 def get_urlbl(self): return self.urlbl2811 def set_urlbl(self, urlbl): self.urlbl = urlbl2812 def add_urlbl(self, value): self.urlbl.append(value)2813 def insert_urlbl(self, index, value): self.urlbl[index] = value2814 def export(self, outfile, level, namespace_='', name_='urlbls', namespacedef_=''):2815 showIndent(outfile, level)2816 outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))2817 self.exportAttributes(outfile, level, namespace_, name_='urlbls')2818 if self.hasContent_():2819 outfile.write('>\n')2820 self.exportChildren(outfile, level + 1, namespace_, name_)2821 showIndent(outfile, level)2822 outfile.write('</%s%s>\n' % (namespace_, name_))2823 else:2824 outfile.write('/>\n')2825 def exportAttributes(self, outfile, level, namespace_='', name_='urlbls'):2826 pass2827 def exportChildren(self, outfile, level, namespace_='', name_='urlbls'):2828 for urlbl_ in self.urlbl:2829 urlbl_.export(outfile, level, namespace_, name_='urlbl')2830 def hasContent_(self):2831 if (2832 self.urlbl2833 ):2834 return True2835 else:2836 return False2837 def exportLiteral(self, outfile, level, name_='urlbls'):2838 level += 12839 self.exportLiteralAttributes(outfile, level, name_)2840 if self.hasContent_():2841 self.exportLiteralChildren(outfile, level, name_)2842 def exportLiteralAttributes(self, outfile, level, name_):2843 pass2844 def exportLiteralChildren(self, outfile, level, name_):2845 showIndent(outfile, level)2846 outfile.write('urlbl=[\n')2847 level += 12848 for urlbl_ in self.urlbl:2849 showIndent(outfile, level)2850 outfile.write('model_.urlbl(\n')2851 urlbl_.exportLiteral(outfile, level)2852 showIndent(outfile, level)2853 outfile.write('),\n')2854 level -= 12855 showIndent(outfile, level)2856 outfile.write('],\n')2857 def build(self, node_):2858 attrs = node_.attributes2859 self.buildAttributes(attrs)2860 for child_ in node_.childNodes:2861 nodeName_ = child_.nodeName.split(':')[-1]2862 self.buildChildren(child_, nodeName_)2863 def buildAttributes(self, attrs):2864 pass2865 def buildChildren(self, child_, nodeName_):2866 if child_.nodeType == Node.ELEMENT_NODE and \2867 nodeName_ == 'urlbl':2868 obj_ = urlbl.factory()2869 obj_.build(child_)2870 self.urlbl.append(obj_)2871# end class urlbls2872class urlbl(GeneratedsSuper):2873 subclass = None2874 superclass = None2875 def __init__(self, bl=None, timestamp=None, result=None):2876 if bl is None:2877 self.bl = []2878 else:2879 self.bl = bl2880 if timestamp is None:2881 self.timestamp = []2882 else:2883 self.timestamp = timestamp2884 if result is None:2885 self.result = []2886 else:2887 self.result = result2888 def factory(*args_, **kwargs_):2889 if urlbl.subclass:2890 return urlbl.subclass(*args_, **kwargs_)2891 else:2892 return urlbl(*args_, **kwargs_)2893 factory = staticmethod(factory)2894 def get_bl(self): return self.bl2895 def set_bl(self, bl): self.bl = bl2896 def add_bl(self, value): self.bl.append(value)2897 def insert_bl(self, index, value): self.bl[index] = value2898 def get_timestamp(self): return self.timestamp2899 def set_timestamp(self, timestamp): self.timestamp = timestamp2900 def add_timestamp(self, value): self.timestamp.append(value)2901 def insert_timestamp(self, index, value): self.timestamp[index] = value2902 def get_result(self): return self.result2903 def set_result(self, result): self.result = result2904 def add_result(self, value): self.result.append(value)2905 def insert_result(self, index, value): self.result[index] = value2906 def export(self, outfile, level, namespace_='', name_='urlbl', namespacedef_=''):2907 showIndent(outfile, level)2908 outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))2909 self.exportAttributes(outfile, level, namespace_, name_='urlbl')2910 if self.hasContent_():2911 outfile.write('>\n')2912 self.exportChildren(outfile, level + 1, namespace_, name_)2913 showIndent(outfile, level)2914 outfile.write('</%s%s>\n' % (namespace_, name_))2915 else:2916 outfile.write('/>\n')2917 def exportAttributes(self, outfile, level, namespace_='', name_='urlbl'):2918 pass2919 def exportChildren(self, outfile, level, namespace_='', name_='urlbl'):2920 for bl_ in self.bl:2921 showIndent(outfile, level)2922 outfile.write('<%sbl>%s</%sbl>\n' % (namespace_, self.format_string(quote_xml(bl_).encode(ExternalEncoding), input_name='bl'), namespace_))2923 for timestamp_ in self.timestamp:2924 showIndent(outfile, level)2925 outfile.write('<%stimestamp>%s</%stimestamp>\n' % (namespace_, self.format_string(quote_xml(timestamp_).encode(ExternalEncoding), input_name='timestamp'), namespace_))2926 for result_ in self.result:2927 showIndent(outfile, level)2928 outfile.write('<%sresult>%s</%sresult>\n' % (namespace_, self.format_string(quote_xml(result_).encode(ExternalEncoding), input_name='result'), namespace_))2929 def hasContent_(self):2930 if (2931 self.bl or2932 self.timestamp or2933 self.result2934 ):2935 return True2936 else:2937 return False2938 def exportLiteral(self, outfile, level, name_='urlbl'):2939 level += 12940 self.exportLiteralAttributes(outfile, level, name_)2941 if self.hasContent_():2942 self.exportLiteralChildren(outfile, level, name_)...
encoding_test.py
Source:encoding_test.py
...57 av_class2 = round_trip(av_class)58 self.assertEqual(av_class.engine_version, av_class2.engine_version)59 self.assertEqual(av_class.definition_version, av_class2.definition_version)60 self.assertEqual(av_class.classification_name, av_class2.classification_name)61 def test_quote_xml(self):62 s = bindings.quote_xml(UNICODE_STR)63 self.assertEqual(s, UNICODE_STR)64 def test_quote_attrib(self):65 """Tests that the maec.bindings.quote_attrib method works properly66 on unicode inputs.67 Note:68 The quote_attrib method (more specifically, saxutils.quoteattr())69 adds quotation marks around the input data, so we need to strip70 the leading and trailing chars to test effectively71 """72 s = bindings.quote_attrib(UNICODE_STR)73 s = s[1:-1]74 self.assertEqual(s, UNICODE_STR)75 def test_quote_attrib_int(self):76 i = 6553677 s = bindings.quote_attrib(i)78 self.assertEqual(u'"65536"', s)79 def test_quote_attrib_bool(self):80 b = True81 s = bindings.quote_attrib(b)82 self.assertEqual(u'"True"', s)83 def test_quote_xml_int(self):84 i = 6553685 s = bindings.quote_xml(i)86 self.assertEqual(unicode(i), s)87 def test_quote_xml_bool(self):88 b = True89 s = bindings.quote_xml(b)90 self.assertEqual(unicode(b), s)91 def test_quote_xml_encoded(self):92 encoding = bindings.ExternalEncoding93 encoded = UNICODE_STR.encode(encoding)94 quoted = bindings.quote_xml(encoded)95 self.assertEqual(UNICODE_STR, quoted)96 def test_quote_attrib_encoded(self):97 encoding = bindings.ExternalEncoding98 encoded = UNICODE_STR.encode(encoding)99 quoted = bindings.quote_attrib(encoded)[1:-1]100 self.assertEqual(UNICODE_STR, quoted)101 def test_quote_xml_zero(self):102 i = 0103 s = bindings.quote_xml(i)104 self.assertEqual(unicode(i), s)105 def test_quote_attrib_zero(self):106 i = 0107 s = bindings.quote_attrib(i)108 self.assertEqual(u'"0"', s)109 def test_quote_xml_none(self):110 i = None111 s = bindings.quote_xml(i)112 self.assertEqual(u'', s)113 def test_quote_attrib_none(self):114 i = None115 s = bindings.quote_attrib(i)116 self.assertEqual(u'""', s)117 def test_quote_attrib_empty(self):118 i = ''119 s = bindings.quote_attrib(i)120 self.assertEqual(u'""', s)121 def test_quote_xml_empty(self):122 i = ''123 s = bindings.quote_xml(i)124 self.assertEqual(u'', s)125 def test_to_xml_utf16_encoded(self):126 encoding = 'utf-16'127 b = Behavior()128 b.description = UNICODE_STR129 xml = b.to_xml(encoding=encoding)130 self.assertTrue(UNICODE_STR in xml.decode(encoding))131 def test_to_xml_default_encoded(self):132 b = Behavior()133 b.description = UNICODE_STR134 xml = b.to_xml()135 self.assertTrue(UNICODE_STR in xml.decode('utf-8'))136 def test_to_xml_no_encoding(self):137 b = Behavior()...
quote.py
Source:quote.py
1import requests as req2import json3import time4import xmltodict as xml5def quote_print():6 with open("config.json") as config:7 config_file = json.load(config)8 while True:9 lang = config_file['lang']10 format = config_file['format']11 delay = config_file['delay']12 delay = delay_change_seconds(delay)13 if lang == "en" or lang == "ru":14 if format == "json":15 extracting_details_using_json(lang, format, delay)16 else:17 extracting_details_using_xml(lang, format, delay)18 else:19 lang = "en"20 if format == "json":21 extracting_details_using_json(lang, format, delay)22 else:23 extracting_details_using_xml(lang, format, delay)24def delay_change_seconds(delay):25 delay = delay.split(" ")26 for value in range(len(delay)):27 value_store = delay[value][-2:]28 time_split = int(delay[value][:-2])29 if value_store == "yr":30 change_year = time_split * 365 * 24 * 60 * 6031 if value_store == "mt":32 change_month = time_split * 24 * 60 * 60 * 3033 if value_store == "dy":34 change_day = time_split * 24 * 60 * 6035 if value_store == "mi":36 change_minute = time_split * 6037 if value_store == "se":38 seconds = time_split39 delay = change_year + change_month + change_day + change_minute + seconds40 return delay41def extracting_details_using_json(lang, format, delay):42 url = "https://api.forismatic.com/api/1.0/?method=getQuote&lang=" + lang + "&format=" + format43 res = req.get(url)44 if lang == "ru":45 quote_dictionary = json.loads(res.text)46 if lang == "en":47 quote_dictionary = json.loads(bytes(res.text, "utf-8").decode("unicode_escape"))48 author_name = quote_dictionary['quoteAuthor']49 author_quote = quote_dictionary['quoteText']50 if author_name == '':51 author_name = "Unknown"52 print(author_name, "says", author_quote)53 else:54 print(author_name, "says", author_quote)55 time.sleep(delay)56def extracting_details_using_xml(lang, format, delay):57 url = "https://api.forismatic.com/api/1.0/?method=getQuote&lang=" + lang + "&format=" + format58 res = req.get(url)59 quote_xml = json.loads(json.dumps((xml.parse(res.text))))60 if quote_xml['forismatic']['quote']['quoteAuthor'] == None:61 quote_xml['forismatic']['quote']['quoteAuthor'] = "Unknown"62 print(quote_xml['forismatic']['quote']['quoteAuthor'], "says",63 quote_xml['forismatic']['quote']['quoteText'])64 else:65 print(quote_xml['forismatic']['quote']['quoteAuthor'], "says",66 quote_xml['forismatic']['quote']['quoteText'])67 time.sleep(delay)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!