当前位置: 首页>>代码示例>>Python>>正文


Python untangle.parse方法代码示例

本文整理汇总了Python中untangle.parse方法的典型用法代码示例。如果您正苦于以下问题:Python untangle.parse方法的具体用法?Python untangle.parse怎么用?Python untangle.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在untangle的用法示例。


在下文中一共展示了untangle.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _wire_server_request

# 需要导入模块: import untangle [as 别名]
# 或者: from untangle import parse [as 别名]
def _wire_server_request(self, path, data_xml=None, headers=None,
                             parse_xml=True):
        if not self._base_url:
            raise exception.CloudbaseInitException(
                "Azure WireServer base url not set")

        all_headers = self._headers.copy()
        if data_xml:
            all_headers["Content-Type"] = "text/xml; charset=utf-8"
        if headers:
            all_headers.update(headers)

        data = self._exec_with_retry(
            lambda: super(AzureService, self)._http_request(
                path, data_xml, headers=all_headers))

        if parse_xml:
            return untangle.parse(six.StringIO(encoding.get_as_string(data)))
        else:
            return data 
开发者ID:cloudbase,项目名称:cloudbase-init,代码行数:22,代码来源:azureservice.py

示例2: populate_metadata

# 需要导入模块: import untangle [as 别名]
# 或者: from untangle import parse [as 别名]
def populate_metadata(apps, schema_editor):
    Extension = apps.get_model("studies", "Extension")

    for extension in Extension.objects.all():
        with default_storage.open(extension.xpi.name) as f:
            with zipfile.ZipFile(f) as zf:
                files = set(zf.namelist())

                if "manifest.json" in files:
                    with zf.open("manifest.json") as manifest_file:
                        data = json.load(manifest_file)
                        extension.extension_id = (
                            data.get("applications", {}).get("gecko", {}).get("id", None)
                        )
                        extension.version = data.get("version")
                elif "install.rdf" in files:
                    extension.is_legacy = True
                    with zf.open("install.rdf", "r") as rdf_file:
                        data = untangle.parse(rdf_file.read().decode())
                        extension.extension_id = data.RDF.Description.em_id.cdata
                        extension.version = data.RDF.Description.em_version.cdata
                else:
                    raise Exception("Invalid XPI.")

            if not extension.extension_id or not extension.version:
                raise Exception("Extension ID or version not set.")

            f.seek(0)
            extension.hash = hashlib.sha256(f.read()).hexdigest()
        extension.save() 
开发者ID:mozilla,项目名称:normandy,代码行数:32,代码来源:0004_auto_20190115_0812.py

示例3: parse_xml

# 需要导入模块: import untangle [as 别名]
# 或者: from untangle import parse [as 别名]
def parse_xml(s: str) -> DecklistType:
    d: DecklistType = {'maindeck': {}, 'sideboard': {}}
    try:
        doc = untangle.parse(s)
        for c in doc.Deck.Cards:
            section = 'sideboard' if c['Sideboard'] == 'true' else 'maindeck'
            d[section][c['Name']] = d[section].get(c['Name'], 0) + int(c['Quantity'])
        return d
    except xml.sax.SAXException as e: # type: ignore
        raise InvalidDataException(e)
    except AttributeError as e:
        raise InvalidDataException(e) # Not valid MTGO .deck format

# Load the cards in the intermediate dict form. 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:16,代码来源:decklist.py

示例4: BuildSMBUDPFingerprintFiles

# 需要导入模块: import untangle [as 别名]
# 或者: from untangle import parse [as 别名]
def BuildSMBUDPFingerprintFiles():
  # converting from the xml format to a more flat format that will hopefully be faster than walking the entire xml every FP lookup
  browserExactList = {}
  browserPartialList = {}

  satoriPath = str(Path(__file__).resolve().parent)

  obj = untangle.parse(satoriPath + '/fingerprints/browser.xml')
  fingerprintsCount = len(obj.SMBBROWSER.fingerprints)
  for x in range(0,fingerprintsCount):
    os = obj.SMBBROWSER.fingerprints.fingerprint[x]['name']
    testsCount = len(obj.SMBBROWSER.fingerprints.fingerprint[x].smbbrowser_tests)
    test = {}
    for y in range(0,testsCount):
      test = obj.SMBBROWSER.fingerprints.fingerprint[x].smbbrowser_tests.test[y]
      if test is None:  #if testsCount = 1, then untangle doesn't allow us to iterate through it
        test = obj.SMBBROWSER.fingerprints.fingerprint[x].smbbrowser_tests.test
      weight = test['weight']
      matchtype = test['matchtype']
      osversion = test['osversion']
      browserversion = test['browserversion']
      if matchtype == 'exact':
        fingerprint = osversion + ',' + browserversion
        if fingerprint in browserExactList:
          oldValue = browserExactList.get(fingerprint)
          browserExactList[fingerprint] = oldValue + '|' + os + ':' + weight
        else:
          browserExactList[fingerprint] = os + ':' + weight

      else:
        fingerprint = osversion + ',' + browserversion
        if fingerprint in browserPartialList:
          oldValue = browserPartialList.get(fingerprint)
          browserPartialList[fingerprint] = oldValue + '|' + os + ':' + weight
        else:
          browserPartialList[fingerprint] = os + ':' + weight

  return [browserExactList, browserPartialList] 
开发者ID:xnih,项目名称:satori,代码行数:40,代码来源:satoriSMB.py

示例5: BuildHTTPServerFingerprintFiles

# 需要导入模块: import untangle [as 别名]
# 或者: from untangle import parse [as 别名]
def BuildHTTPServerFingerprintFiles():
  # converting from the xml format to a more flat format that will hopefully be faster than walking the entire xml every FP lookup
  serverExactList = {}
  serverPartialList = {}

  satoriPath = str(Path(__file__).resolve().parent)

  obj = untangle.parse(satoriPath + '/fingerprints/web.xml')
  fingerprintsCount = len(obj.WEBSERVER.fingerprints)
  for x in range(0,fingerprintsCount):
    os = obj.WEBSERVER.fingerprints.fingerprint[x]['name']
    testsCount = len(obj.WEBSERVER.fingerprints.fingerprint[x].webserver_tests)
    test = {}
    for y in range(0,testsCount):
      test = obj.WEBSERVER.fingerprints.fingerprint[x].webserver_tests.test[y]
      if test is None:  #if testsCount = 1, then untangle doesn't allow us to iterate through it
        test = obj.WEBSERVER.fingerprints.fingerprint[x].webserver_tests.test
      matchtype = test['matchtype']
      webserver = test['webserver']
      weight = test['weight']
      if matchtype == 'exact':
        if webserver in serverExactList:
          oldValue = serverExactList.get(webserver)
          serverExactList[webserver] = oldValue + '|' + os + ':' + weight
        else:
          serverExactList[webserver] = os + ':' + weight
      else:
        if webserver in serverPartialList:
          oldValue = serverPartialList.get(webserver)
          serverPartialList[webserver] = oldValue + '|' + os + ':' + weight
        else:
          serverPartialList[webserver] = os + ':' + weight

  return [serverExactList, serverPartialList] 
开发者ID:xnih,项目名称:satori,代码行数:36,代码来源:satoriHTTP.py

示例6: BuildHTTPUserAgentFingerprintFiles

# 需要导入模块: import untangle [as 别名]
# 或者: from untangle import parse [as 别名]
def BuildHTTPUserAgentFingerprintFiles():
  # converting from the xml format to a more flat format that will hopefully be faster than walking the entire xml every FP lookup
  useragentExactList = {}
  useragentPartialList = {}

  satoriPath = str(Path(__file__).resolve().parent)

  obj = untangle.parse(satoriPath + '/fingerprints/webuseragent.xml')
  fingerprintsCount = len(obj.WEBUSERAGENT.fingerprints)
  for x in range(0,fingerprintsCount):
    os = obj.WEBUSERAGENT.fingerprints.fingerprint[x]['name']
    testsCount = len(obj.WEBUSERAGENT.fingerprints.fingerprint[x].webuseragent_tests)
    test = {}
    for y in range(0,testsCount):
      test = obj.WEBUSERAGENT.fingerprints.fingerprint[x].webuseragent_tests.test[y]
      if test is None:  #if testsCount = 1, then untangle doesn't allow us to iterate through it
        test = obj.WEBUSERAGENT.fingerprints.fingerprint[x].webuseragent_tests.test
      matchtype = test['matchtype']
      webuseragent = test['webuseragent']
      weight = test['weight']
      if matchtype == 'exact':
        if webuseragent in useragentExactList:
          oldValue = useragentExactList.get(webuseragent)
          useragentExactList[webuseragent] = oldValue + '|' + os + ':' + weight
        else:
          useragentExactList[webuseragent] = os + ':' + weight
      else:
        if webuseragent in useragentPartialList:
          oldValue = useragentPartialList.get(webuseragent)
          useragentPartialList[webuseragent] = oldValue + '|' + os + ':' + weight
        else:
          useragentPartialList[webuseragent] = os + ':' + weight

  return [useragentExactList, useragentPartialList] 
开发者ID:xnih,项目名称:satori,代码行数:36,代码来源:satoriHTTP.py

示例7: wait_for_json_message

# 需要导入模块: import untangle [as 别名]
# 或者: from untangle import parse [as 别名]
def wait_for_json_message(self, accept_message, unquote_msg=True, timeout=None):
        last = self.wait_for_message(accept_message, unquote_msg, expect_xml=False, timeout=timeout)
        json_msg = last.split('\t', 2)[-1]  # We have something as: CMD\tSEQ\tJSON
        if isinstance(json_msg, bytes):
            json_msg = json_msg.decode('utf-8')
        try:
            return json.loads(json_msg)
        except:
            traceback.print_exc()
            raise AssertionError('Unable to parse:\n%s\njson:\n%s' % (last, json_msg)) 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:12,代码来源:debugger_unittest.py

示例8: wait_for_message

# 需要导入模块: import untangle [as 别名]
# 或者: from untangle import parse [as 别名]
def wait_for_message(self, accept_message, unquote_msg=True, expect_xml=True, timeout=None):
        if isinstance(accept_message, (str, int)):
            msg_starts_with = '%s\t' % (accept_message,)

            def accept_message(msg):
                return msg.startswith(msg_starts_with)

        import untangle
        from io import StringIO
        prev = None
        while True:
            last = self.get_next_message('wait_for_message', timeout=timeout)
            if unquote_msg:
                last = unquote_plus(unquote_plus(last))
            if accept_message(last):
                if expect_xml:
                    # Extract xml and return untangled.
                    xml = ''
                    try:
                        xml = last[last.index('<xml>'):]
                        if isinstance(xml, bytes):
                            xml = xml.decode('utf-8')
                        xml = untangle.parse(StringIO(xml))
                    except:
                        traceback.print_exc()
                        raise AssertionError('Unable to parse:\n%s\nxml:\n%s' % (last, xml))
                    ret = xml.xml
                    ret.original_xml = last
                    return ret
                else:
                    return last
            if prev != last:
                print('Ignored message: %r' % (last,))

            prev = last 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:37,代码来源:debugger_unittest.py

示例9: _get_ovf_env

# 需要导入模块: import untangle [as 别名]
# 或者: from untangle import parse [as 别名]
def _get_ovf_env(self):
        if not self._ovf_env:
            ovf_env_path = self._get_ovf_env_path()
            self._ovf_env = untangle.parse(ovf_env_path)
        return self._ovf_env 
开发者ID:cloudbase,项目名称:cloudbase-init,代码行数:7,代码来源:azureservice.py

示例10: svg

# 需要导入模块: import untangle [as 别名]
# 或者: from untangle import parse [as 别名]
def svg(path):
    return untangle.parse(path).svg 
开发者ID:fossasia,项目名称:knittingpattern,代码行数:4,代码来源:test_save_as_svg.py

示例11: __init__

# 需要导入模块: import untangle [as 别名]
# 或者: from untangle import parse [as 别名]
def __init__(self, drone_type):
        # grab module path per http://www.karoltomala.com/blog/?p=622
        path = os.path.abspath(__file__)
        dir_path = os.path.dirname(path)

        self.common_sensors = untangle.parse(join(dir_path, 'common.xml'))

        if (drone_type == "Minidrone"):
            self.drone_sensors = untangle.parse(join(dir_path, 'minidrone.xml'))
        else:
            self.drone_sensors = untangle.parse(join(dir_path, 'ardrone3.xml'))

        self.project_xmls = (self.drone_sensors, self.common_sensors)

        self.sensor_tuple_cache = dict() 
开发者ID:amymcgovern,项目名称:pyparrot,代码行数:17,代码来源:DroneSensorParser.py

示例12: __init__

# 需要导入模块: import untangle [as 别名]
# 或者: from untangle import parse [as 别名]
def __init__(self):
        # store the commandsandsensors as they are called so you don't have to parse each time
        self.command_tuple_cache = dict()

        # parse the command files from XML (so we don't have to store ids and can use names
        # for readability and portability!)

        # grab module path per http://www.karoltomala.com/blog/?p=622
        path = os.path.abspath(__file__)
        dir_path = os.path.dirname(path)

        self.common_commands = untangle.parse(join(dir_path, 'common.xml'))
        self.minidrone_commands = untangle.parse(join(dir_path, 'minidrone.xml'))
        self.ardrone3_commands = untangle.parse(join(dir_path, 'ardrone3.xml')) 
开发者ID:amymcgovern,项目名称:pyparrot,代码行数:16,代码来源:DroneCommandParser.py

示例13: parse

# 需要导入模块: import untangle [as 别名]
# 或者: from untangle import parse [as 别名]
def parse(s: str) -> DecklistType:
    s = s.lstrip().rstrip()
    if looks_doublespaced(s):
        s = remove_doublespacing(s)
    maindeck: Dict[str, Any] = {}
    sideboard: Dict[str, Any] = {}
    chunks = re.split(r'\r?\n\r?\n|^\s*sideboard.*?\n', s, flags=re.IGNORECASE|re.MULTILINE)
    if len(chunks) > 1 and (len(chunks[-1]) > 1 or len(chunks[-1][0]) > 0) or 'Sideboard' in s:
        for chunk in chunks[:-1]:
            parse_chunk(chunk, maindeck)
        parse_chunk(chunks[-1], sideboard)
    else:
        # No empty lines or explicit "sideboard" section: gather 60 cards for maindeck from the beginning,
        # then gather 15 cards for sideboard starting from the end, then the rest to maindeck
        lines = s.splitlines()
        while sum(maindeck.values()) < 60 and len(lines) > 0:
            n, name = parse_line(lines.pop(0))
            add_card(maindeck, n, name)

        while len(lines) > 0:
            n, name = parse_line(lines.pop(-1))
            if sum(sideboard.values()) + n <= 15:
                add_card(sideboard, n, name)
                if sum(sideboard.values()) == 15:
                    break
            else:
                add_card(maindeck, n, name)
                break

        while len(lines) > 0:
            n, name = parse_line(lines.pop(0))
            add_card(maindeck, n, name)

        # But Commander decks are special so undo our trickery if we have exactly 100 cards and it is singleton except basics.
        if sum(maindeck.values()) + sum(sideboard.values()) == 100:
            new_maindeck, is_commander = {}, True
            for name in set(maindeck) | set(sideboard):
                new_maindeck[name] = maindeck.get(name, 0) + sideboard.get(name, 0)
                if new_maindeck[name] > 1 and name not in ['Plains', 'Island', 'Swamp', 'Mountain', 'Forest', 'Wastes']:
                    is_commander = False
            if is_commander:
                maindeck = new_maindeck
                sideboard = {}

    return {'maindeck':maindeck, 'sideboard':sideboard} 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:47,代码来源:decklist.py

示例14: BuildTCPFingerprintFiles

# 需要导入模块: import untangle [as 别名]
# 或者: from untangle import parse [as 别名]
def BuildTCPFingerprintFiles():
  # converting from the xml format to a more flat format that will hopefully be faster than walking the entire xml every FP lookup
  sExactList = {}
  saExactList = {}
  sPartialList = {}
  saPartialList = {}

  satoriPath = str(Path(__file__).resolve().parent)

  obj = untangle.parse(satoriPath + '/fingerprints/tcp.xml')
  fingerprintsCount = len(obj.TCP.fingerprints)
  for x in range(0,fingerprintsCount):
    os = obj.TCP.fingerprints.fingerprint[x]['name']
    testsCount = len(obj.TCP.fingerprints.fingerprint[x].tcp_tests)
    test = {}
    for y in range(0,testsCount):
      test = obj.TCP.fingerprints.fingerprint[x].tcp_tests.test[y]
      if test is None:  #if testsCount = 1, then untangle doesn't allow us to iterate through it
        test = obj.TCP.fingerprints.fingerprint[x].tcp_tests.test
      matchtype = test['matchtype']
      tcpflag = test['tcpflag']
      tcpsig = test['tcpsig']
      weight = test['weight']
      if matchtype == 'exact':
        if tcpflag == 'S':
          if tcpsig in sExactList:
            oldValue = sExactList.get(tcpsig)
            sExactList[tcpsig] = oldValue + '|' + os + ':' + weight
          else:
            sExactList[tcpsig] = os + ':' + weight
        else: #SA packets
          if tcpsig in saExactList:
            oldValue = saExactList.get(tcpsig)
            saExactList[tcpsig] = oldValue + '|' + os + ':' + weight
          else:
            saExactList[tcpsig] = os + ':' + weight
      else:
        if tcpflag == 'S':
          if tcpsig in sPartialList:
            oldValue = sPartialList.get(tcpsig)
            sPartialList[tcpsig] = oldValue + '|' + os + ':' + weight
          else:
            sPartialList[tcpsig] = os + ':' + weight
        else: #SA packets
          if tcpsig in saPartialList:
            oldValue = saPartialList.get(tcpsig)
            saPartialList[tcpsig] = oldValue + '|' + os + ':' + weight
          else:
            saPartialList[tcpsig] = os + ':' + weight

  return [sExactList, saExactList, sPartialList, saPartialList] 
开发者ID:xnih,项目名称:satori,代码行数:53,代码来源:satoriTCP.py

示例15: BuildSMBTCPFingerprintFiles

# 需要导入模块: import untangle [as 别名]
# 或者: from untangle import parse [as 别名]
def BuildSMBTCPFingerprintFiles():
  # converting from the xml format to a more flat format that will hopefully be faster than walking the entire xml every FP lookup
  nativeExactList = {}
  nativePartialList = {}
  lanmanExactList = {}
  lanmanPartialList = {}

  satoriPath = str(Path(__file__).resolve().parent)

  obj = untangle.parse(satoriPath + '/fingerprints/smb.xml')
  fingerprintsCount = len(obj.SMB.fingerprints)
  for x in range(0,fingerprintsCount):
    os = obj.SMB.fingerprints.fingerprint[x]['name']
    testsCount = len(obj.SMB.fingerprints.fingerprint[x].smb_tests)
    test = {}
    for y in range(0,testsCount):
      test = obj.SMB.fingerprints.fingerprint[x].smb_tests.test[y]
      if test is None:  #if testsCount = 1, then untangle doesn't allow us to iterate through it
        test = obj.SMB.fingerprints.fingerprint[x].smb_tests.test
      weight = test['weight']
      matchtype = test['matchtype']
      smbnativename = test['smbnativename']
      smbnativelanman = test['smbnativelanman']
      if matchtype == 'exact':
        if smbnativename != None:
          if smbnativename in nativeExactList:
            oldValue = nativeExactList.get(smbnativename)
            nativeExactList[smbnativename] = oldValue + '|' + os + ':' + weight
          else:
            nativeExactList[smbnativename] = os + ':' + weight
        elif smbnativelanman != None:
          if smbnativelanman in lanmanExactList:
            oldValue = lanmanExactList.get(smbnativelanman)
            lanmanExactList[smbnativelanman] = oldValue + '|' + os + ':' + weight
          else:
            lanmanExactList[smbnativelanman] = os + ':' + weight

      else:
        if smbnativename != None:
          if smbnativename in nativePartialList:
            oldValue = nativePartialList.get(smbnativename)
            nativePartialList[smbnativename] = oldValue + '|' + os + ':' + weight
          else:
            nativePartialList[smbnativename] = os + ':' + weight
        elif smbnativelanman != None:
          if smbnativelanman in lanmanPartialList:
            oldValue = lanmanPartialList.get(smbnativelanman)
            lanmanPartialList[smbnativelanman] = oldValue + '|' + os + ':' + weight
          else:
            lanmanPartialList[smbnativelanman] = os + ':' + weight

  return [nativeExactList, lanmanExactList, nativePartialList, lanmanPartialList] 
开发者ID:xnih,项目名称:satori,代码行数:54,代码来源:satoriSMB.py


注:本文中的untangle.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。