def test_write_xsi_type_with_derived_class(self): var = XmlVar( element=True, qname="a", name="a", dataclass=True, types=[BookForm] ) ebook = make_dataclass("eBook", [], bases=(BookForm,)) value = ebook(id="123") expected = [ (XmlWriterEvent.START, "a"), (XmlWriterEvent.ATTR, "id", "123"), (XmlWriterEvent.ATTR, "lang", "en"), (XmlWriterEvent.ATTR, QNames.XSI_TYPE, QName("eBook")), (XmlWriterEvent.END, "a"), ] result = self.serializer.write_value(value, var, "xsdata") self.assertIsInstance(result, Generator) self.assertEqual(expected, list(result))
def from_xml(cls, element: Element, source: AnyStr | None = None) -> Filter: """Parse the <fes20:Filter> element.""" if len(element) > 1 or element[0].tag == QName(FES20, "ResourceId"): # fes20:ResourceId is the only element that may appear multiple times. return Filter( predicate=operators.IdOperator([ identifiers.Id.from_child_xml(child) for child in element ]), source=source, ) else: return Filter( predicate=tag_registry.from_child_xml( element[0], allowed_types=(expressions.Function, operators.Operator)), source=source, )
def test_write_any_type_with_derived_element_dataclass(self): var = XmlVar(wildcard=True, qname="a", name="a") value = DerivedElement(qname="a", value=BookForm(title="def"), substituted=True) expected = [ (XmlWriterEvent.START, "a"), (XmlWriterEvent.ATTR, "lang", "en"), (XmlWriterEvent.ATTR, QNames.XSI_TYPE, QName("{urn:books}BookForm")), (XmlWriterEvent.START, "title"), (XmlWriterEvent.DATA, "def"), (XmlWriterEvent.END, "title"), (XmlWriterEvent.END, "a"), ] result = self.serializer.write_value(value, var, "xsdata") self.assertIsInstance(result, Generator) self.assertEqual(expected, list(result))
def getIMDBids(self): movies = [] rotten_tomatoes_namespace = 'http://www.rottentomatoes.com/xmlns/rtmovie/' urls = dict( zip(splitString(self.conf('automation_urls')), [ tryInt(x) for x in splitString(self.conf('automation_urls_use')) ])) for url in urls: if not urls[url]: continue rss_movies = self.getRSSData(url) rating_tag = str( QName(rotten_tomatoes_namespace, 'tomatometer_percent')) for movie in rss_movies: value = self.getTextElement(movie, "title") result = re.search('(?<=%\s).*', value) if result: rating = tryInt(self.getTextElement(movie, rating_tag)) name = result.group(0) print rating, tryInt(self.conf('tomatometer_percent')) if rating < tryInt(self.conf('tomatometer_percent')): log.info2('%s seems to be rotten...', name) else: log.info2('Found %s with fresh rating %s', (name, rating)) year = datetime.datetime.now().strftime("%Y") imdb = self.search(name, year) if imdb and self.isMinimalMovie(imdb): movies.append(imdb['imdb']) return movies
def create(): element = Element(QName(NS_WST, 'RequestSecurityToken')) token_type = Element(QName(NS_WST, 'TokenType')) token_type.text = TOKEN_TYPE element.append(token_type) request_type = Element(QName(NS_WST, 'RequestType')) request_type.text = ISSUE_REQUEST_TYPE element.append(request_type) token = Element(QName(NS_WST_SECEXT, 'BinarySecurityToken')) token.set(QName(NS_WST_SECEXT, 'ValueType'), VALUE_TYPE) token.set(QName(NS_WST_SECEXT, 'EncodingType'), ENCODING_TYPE) token.set(QName(NS_ADDRESSING, 'Id'), '') element.append(token) return element
class NistschemaSvIvAtomicQnameEnumeration5Type(Enum): UTHE_BASE_THE_ABILITY_INTO_TARGET_THE_TESTABILITY_DISCOVE = QName( "{NISTSchema-SV-IV-atomic-QName-enumeration-5-NS}uthe.base_the_ability-into-target_the_testability-discove" ) FOR_FILES_SUPPLY_FOR_TO_MUST_MEASUR = QName( "{NISTSchema-SV-IV-atomic-QName-enumeration-5-NS}_for-files.supply.for.to-must_measur" ) D_I = QName("{http://www.nist.gov/xsdNS}i") PS_PERVASIVE_IN_HOUSE_ON_PERFORMANCE_ALS = QName( "{NISTSchema-SV-IV-atomic-QName-enumeration-5-NS}ps.pervasive.in-house_on.performance-als" ) BUILD_RETRIEVES_COR_AMONG_TO_MUST_AND_INDUSTRY_FROM_THAT = QName( "{http://www.nist.gov/xsdNS}_among.to.must_and.industry-from-that_") HMANIPULATE_US = QName( "{NISTSchema-SV-IV-atomic-QName-enumeration-5-NS}hmanipulate-us")
class Array: class Meta: namespace = "http://schemas.microsoft.com/2003/10/Serialization/" item: List[object] = field( default_factory=list, metadata={ "name": "Item", "type": "Element", "namespace": "", "nillable": True, } ) item_type: QName = field( default=QName("{http://www.w3.org/2001/XMLSchema}anyType"), metadata={ "name": "ItemType", "type": "Attribute", "namespace": "http://schemas.microsoft.com/2003/10/Serialization/", } ) dimensions: List[int] = field( default_factory=lambda: [ 1, ], metadata={ "name": "Dimensions", "type": "Attribute", "tokens": True, } ) lower_bounds: List[int] = field( default_factory=lambda: [ 0, ], metadata={ "name": "LowerBounds", "type": "Attribute", "tokens": True, } )
def __build_tag(namespace, tag, parent=None, text=None): """ Returns the Element that was created with the properties given appended to the parent element given (or just the new element if no parent element was given) :param namespace: the namespace the new tag belongs to i.e. gmd, nas :param tag: the name of the tag i.e. abstract, CI_Citation :param parent: parent element :param text: inner text of the element :return: the Element that was created with the properties given appended to the parent element given (or just the new element if no parent element was given) """ args: List[Any] = [QName(namespace, tag)] element_type: Union[Type[Element], Callable] = Element if parent is not None: element_type = SubElement args.insert(0, parent) new_element = element_type(*args) if text: new_element.text = str(text) return new_element
def load_from_docinfo(self, docinfo, delete_missing=False): """Populate the XMP metadata object with DocumentInfo A few entries in the deprecated DocumentInfo dictionary are considered approximately equivalent to certain XMP records. This method copies those entries into the XMP metadata. """ for uri, shortkey, docinfo_name, converter in self.DOCINFO_MAPPING: qname = QName(uri, shortkey) # docinfo might be a dict or pikepdf.Dictionary, so lookup keys # by str(Name) val = docinfo.get(str(docinfo_name)) if val is None: if delete_missing and qname in self: del self[qname] continue val = str(val) if converter: val = converter.xmp_from_docinfo(val) if not val: continue self[qname] = val
def add_attribute(self, key: str, value: Any, check_pending: bool = True): """ Add attribute notification receiver. The receiver will convert the key to a namespace, name tuple and convert the value to string. Internally the converter will also generate any missing namespace prefixes. :param key: Attribute name :param value: Attribute value :param check_pending: Raise exception if not no element is pending start """ if not self.pending_tag and check_pending: raise XmlWriterError("Empty pending tag.") if self.is_xsi_type(key, value): value = QName(value) name = split_qname(key) self.attrs[name] = self.encode_data(value)
def tips_orderlist(self, names): el = Element(QName(XMLNS, 'EntityOrderList'), {'entity': self.entity}) for name in names: subel = SubElement(el, QName(XMLNS, 'Name')) subel.text = name return el
def tips_delete(self, identifiers): el = Element(QName(XMLNS, 'Delete')) for name in identifiers: subel = SubElement(el, QName(XMLNS, 'Element-Id')) subel.text = name return el
def tips_namelist(self, entity=None): if entity is None: entity = self.entity return Element(QName(XMLNS, 'EntityNameList'), {'entity': entity})
def generate_library_windows(package, frida_root, host, flavor, output_dir, library_filename): zlib = [ sdk_lib_path("libz.a", frida_root, host), ] brotli = [ sdk_lib_path("libbrotlicommon.a", frida_root, host), sdk_lib_path("libbrotlienc.a", frida_root, host), sdk_lib_path("libbrotlidec.a", frida_root, host), ] glib = [ sdk_lib_path("libglib-2.0.a", frida_root, host), ] gobject = glib + [ sdk_lib_path("libgobject-2.0.a", frida_root, host), sdk_lib_path("libffi.a", frida_root, host), ] gmodule = glib + [ sdk_lib_path("libgmodule-2.0.a", frida_root, host), ] gio = glib + gobject + gmodule + zlib + [ sdk_lib_path("libgio-2.0.a", frida_root, host), ] tls_provider = [ sdk_lib_path(os.path.join("gio", "modules", "libgioschannel.a"), frida_root, host), ] json_glib = glib + gobject + [ sdk_lib_path("libjson-glib-1.0.a", frida_root, host), ] gee = glib + gobject + [ sdk_lib_path("libgee-0.8.a", frida_root, host), ] sqlite = [ sdk_lib_path("libsqlite3.a", frida_root, host), ] libsoup = brotli + [ sdk_lib_path("libsoup-2.4.a", frida_root, host), sdk_lib_path("libpsl.a", frida_root, host), sdk_lib_path("libxml2.a", frida_root, host), ] capstone = [sdk_lib_path("libcapstone.a", frida_root, host)] quickjs = [sdk_lib_path("libquickjs.a", frida_root, host)] tinycc = [sdk_lib_path("libtcc.a", frida_root, host)] v8 = [] build_props = ElementTree.parse( os.path.join(frida_root, "releng", "frida.props")) frida_v8_tag = str( QName("http://schemas.microsoft.com/developer/msbuild/2003", "FridaV8")) for elem in build_props.iter(): if elem.tag == frida_v8_tag: if elem.text == "Enabled": v8 += [ sdk_lib_path("libv8-8.0.a", frida_root, host), ] break gum_lib = internal_arch_lib_path("gum", frida_root, host) gum_deps = deduplicate(glib + gobject + gio + capstone) gumjs_deps = deduplicate([gum_lib] + gum_deps + quickjs + v8 + tls_provider + json_glib + tinycc + sqlite + libsoup) frida_core_deps = deduplicate(glib + gobject + gio + tls_provider + json_glib + gmodule + gee + libsoup + capstone) if package == "frida-gum-1.0": package_lib_path = gum_lib package_lib_deps = gum_deps elif package == "frida-gumjs-1.0": package_lib_path = internal_arch_lib_path("gumjs", frida_root, host) package_lib_deps = gumjs_deps elif package == "frida-core-1.0": package_lib_path = internal_noarch_lib_path("frida-core", frida_root, host) package_lib_deps = frida_core_deps else: raise Exception("Unhandled package") input_libs = [package_lib_path] + package_lib_deps subprocess.check_output([ msvs_lib_exe(host), "/nologo", "/out:" + os.path.join(output_dir, library_filename) ] + input_libs, cwd=msvs_runtime_path(host), shell=False) extra_flags = [os.path.basename(lib_path) for lib_path in input_libs] thirdparty_symbol_mappings = [] return (extra_flags, thirdparty_symbol_mappings)
if str(f) != ".xml" : bn = os.path.basename(inputdir) print bn ff = str(inputdir + "/" + str(f)) print ff tree = ET.parse(ff) doc = tree.getroot() namespace = 'http://www.abbyy.com/FineReader_xml/FineReader10-schema-v1.xml' lineList = [] wordList = [] word = '' confidence=word_l=word_t=word_r=word_b=None for block in doc.iter(str( QName( namespace, 'block' ) )): for line in block.iter(str( QName( namespace, 'line' ) )): lineobj = Line(sortIndex(block)) for formatting in line.iter(str( QName( namespace, 'formatting' ) )): for c in formatting.iter(str( QName( namespace, 'charParams' ) )): if c.get('wordStart') == '1': if word is not '': lineobj.words.append(Word(word, formatting.get('fs'), confidence, word_l, word_t, word_r, word_b)) if c.get('charConfidence') is not None: confidence=int(c.get('charConfidence')) word_l=int(c.get('l')) word_t=int(c.get('t')) word_r=int(c.get('r')) word_b=int(c.get('b')) word=c.text else:
def _output_document(cls, element): for parent in element.findall(str(QName(TEST, 'outputDocument'))): for child in parent: return Document.from_element(child)
if __name__ == '__main__': while (1): # if not os.path.exists(filename): # find_weather() # else: # with open(filename,'r') as f: # readrow = f.readlines() # line = readrow[len(readrow)-1] url = WEATHER_URL % 1103816 url = url + METRIC_PARAMETER xml = ET.parse(urllib.urlopen(url)) root = xml.getroot() ns = "http://xml.weather.yahoo.com/ns/rss/1.0" site = root[0][0].text.split(' - ')[1] body_tag = str(QName(ns, 'condition')) body = root[0][12].findall(body_tag) dicweather = body[0].attrib date = dicweather['date'] # if line.split(',')[0] <> date: couch = couchdb.Server('http://127.0.0.1:5984/') db = couch['weather_hourly'] find_weather() time.sleep(7200) # baseurl = "https://query.yahooapis.com/v1/public/yql?" # yql_query = "select wind from weather.forecast where woeid=2460286"
def __init__(self, text_or_uri, tag=None, sortkey=None): QName.__init__(self, text_or_uri, tag=tag) self.sortkey = sortkey
def __hash__(self): return QName.__hash__(self)
class BuildNotation(Enum): JPEG = QName("jpeg") MPEG = QName("mpeg") G = QName("g")
def _warning(cls, element): element = element.find(str(QName(TEST, 'warning'))) if element is not None: return element.text
def __init__(self, body): self.xml = ElementTree.fromstring(body) if self.statuscode == 'Failure': tag = QName(XMLNS, 'TipsApiError').text raise TipsApiError(self.xml.find(tag))
def from_element(cls, element): return cls(QName(element.tag), element.get(QName(RDF, 'about')))
parser.add_option("-f", "--filename", dest="filename") if len(sys.argv) > 0: opts, args = parser.parse_args(sys.argv) ## Opening the hazelcast.xml file try: ## f = open(opts.filename) ## Registering default namespace hazelcast_ns = "http://www.hazelcast.com/schema/config" ET.register_namespace('', hazelcast_ns) ns = {'hazelcast_ns': hazelcast_ns} ## Loading the root parser tree = ET.parse(opts.filename) root = tree.getroot() ## Finding and replacing the old group tag with the new one for group in root.iter(str(QName(hazelcast_ns, "group"))): group.find("hazelcast_ns:name", ns).text = opts.cluster_name print("Updated cluster user name...") for network in root.iter(str(QName(hazelcast_ns, "network"))): network.find("hazelcast_ns:port", ns).text = opts.cluster_port print("Updated cluster port...") print("Updating Azure discovery...") for azure in root.iter(str(QName(hazelcast_ns, "azure"))): azure.find("hazelcast_ns:client-id", ns).text = opts.aad_client_id azure.find("hazelcast_ns:client-secret", ns).text = opts.aad_client_secret azure.find("hazelcast_ns:tenant-id", ns).text = opts.tenant_id azure.find("hazelcast_ns:subscription-id",
def errorcode(self): tag = QName(XMLNS, 'ErrorCode').text return self.xml.find(tag).text
def _description(cls, element): element = element.find(str(QName(TEST, 'description'))) if element is not None: return element.text
def messages(self): tag = QName(XMLNS, 'Message').text return [m.text for m in self.xml.findall(tag)]
def _input_documents(cls, element): for parent in element.findall(str(QName(TEST, 'inputDocument'))): for child in parent: yield Document.from_element(child)
def statuscode(self): tag = QName(XMLNS, 'StatusCode').text return self.xml.find(tag).text
def prefixtag(ns_prefix, tagname): if tagname: if ns_prefix and ns_prefix in constants.xmlns_map: return str(QName(constants.xmlns_map[ns_prefix], tagname)) else: return tagname
class FaultCodesType(Enum): TNS_INVALID_ADDRESSING_HEADER = QName( "{http://www.w3.org/2005/08/addressing}InvalidAddressingHeader") TNS_INVALID_ADDRESS = QName( "{http://www.w3.org/2005/08/addressing}InvalidAddress") TNS_INVALID_EPR = QName("{http://www.w3.org/2005/08/addressing}InvalidEPR") TNS_INVALID_CARDINALITY = QName( "{http://www.w3.org/2005/08/addressing}InvalidCardinality") TNS_MISSING_ADDRESS_IN_EPR = QName( "{http://www.w3.org/2005/08/addressing}MissingAddressInEPR") TNS_DUPLICATE_MESSAGE_ID = QName( "{http://www.w3.org/2005/08/addressing}DuplicateMessageID") TNS_ACTION_MISMATCH = QName( "{http://www.w3.org/2005/08/addressing}ActionMismatch") TNS_MESSAGE_ADDRESSING_HEADER_REQUIRED = QName( "{http://www.w3.org/2005/08/addressing}MessageAddressingHeaderRequired" ) TNS_DESTINATION_UNREACHABLE = QName( "{http://www.w3.org/2005/08/addressing}DestinationUnreachable") TNS_ACTION_NOT_SUPPORTED = QName( "{http://www.w3.org/2005/08/addressing}ActionNotSupported") TNS_ENDPOINT_UNAVAILABLE = QName( "{http://www.w3.org/2005/08/addressing}EndpointUnavailable")
def getTnsaTagV2(self, tag: str, os_fiz: bool): return str(QName(tags_v2['os_fiz' if os_fiz else 'os_niefiz'], tag))