• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python untangle.parse函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: zone_leaf

    def zone_leaf(self, word, wwn, fid = -1):
        """
        return the info for a specified leaf in the module
            brocade-fabric-switch  yang file 
        
        """
        
        
        try:
            
            s = get_tasks(word, self.ip, wwn, self.Auth , "zoning", fid )
            #print("fs_leaf_debug___"*10)
            #print(s.text)
            #print("fs_leaf_end_____"*10)
            doc = untangle.parse(s.text)
            #print("fs_leaf_debug___"*10)
            #print(doc)
            #print("fs_leaf_end_____"*10)
            done = "none"
            if "vf-id" == word:
                done = doc.Response.fabric_switch.vf_id.cdata
            if "wwn" == word:
                done = doc.Response.fabric_switch.name.cdata
            if "switch-user-friendly-name"  == word:
                done = doc.Response.fabric_switch.switch_user_friendly_name.cdata
            if "chassis-wwn"  == word:
                done = doc.Response.fabric_switch.chassis_wwn.cdata
            if "chassis-user-friendly-name" == word:
                done = doc.Response.fabric_switch.chassis_user_friendly_name.cdata              
            if "domain-id" == word:
                done = doc.Response.fabric_switch.domain_id.cdata
            if "principal" == word:
                done = doc.Response.fabric_switch.principal.cdata
            if "fcid" == word:
                done = doc.Response.fabric_switch.fcid.cdata
            if "ip-address" == word:
                done = doc.Response.fabric_switch.ip_address.cdata
            if "fcip-address"  == word:
                done = doc.Response.fabric_switch.fcip_address.cdata
            if "ipv6-address" == word:
                done = doc.Response.fabric_switch.ipv6_address.cdata
            if "firmware-version" == word:
                done = doc.Response.fabric_switch.firmware_version.cdata
            
            if done == "none":
                pass
                print("\n\nError in fs_leaf the command requested is not one of the\
                      \ncommand requested was  %s    \
                      \n\nthe list of valid commands is \ndomain-id\nchassis-wwn\
                      \nswitch-user-friendly-name\nprincipal\nfcid\nip-address\
                      \nfcip-address\nipv6-address\nfirmware-version\n\n"  %  word)    
 
        except AttributeError:
            print("Error during untangle - None was returned")
            done = "Untangle Error"
        except:
            print("Error in untagle" , sys.exc_info()[0] )
            print("fs_leaf")
            done = "Untangle Error"
        return(done)
开发者ID:gsquire1,项目名称:automation,代码行数:60,代码来源:sm_practice.py


示例2: wait_for_message

    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.
                    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,代码行数:34,代码来源:debugger_unittest.py


示例3: access

def access():
    """
    Shows basic attribute access and node navigation.
    """
    o = untangle.parse('<node id="5">This is cdata<subnode value="abc"/></node>')
    return ("Node id = %s, subnode value = %s" %
            (o.node['id'], o.node.subnode['value']))
开发者ID:BradLeon,项目名称:untangle,代码行数:7,代码来源:examples.py


示例4: get_youtube_data

def get_youtube_data(video):
    """
    Helper to extract video and thumbnail from youtube
    """
    video.source = 'youtube'
    if 'youtube.com/watch' in video.url:
        parsed = urlsplit(video.url)
        query  = parse_qs(parsed.query)
        try:
            video.key  = query.get('v')[0]
        except IndexError:
            video.key = None
    else:
        video.key = video.url.rsplit('/', 1)[1]
    video.embed_src = 'http://www.youtube.com/embed/'

    # api docs
    #          http://gdata.youtube.com/feeds/api/videos/hNRHHRjep3E
    # https://www.googleapis.com/youtube/v3/videos?id=hNRHHRjep3E&part=snippet,contentDetails,statistics
    api_url = 'http://gdata.youtube.com/feeds/api/videos/{}'.format(video.key)
    video_data = urlopen(api_url).read()
    xml = untangle.parse(video_data)

    video.title = xml.title
    video.slug = slugify(video.title)
    video.summary = xml.content
    #video.thumb_url = xml[xml_media.group][xml_media.thumbnail:][1]('url')
    return video
开发者ID:tBaxter,项目名称:Tango,代码行数:28,代码来源:helpers.py


示例5: get_forestfireindex

    def get_forestfireindex(self):
        headers = {'user-agent': user_agent}
        r = requests.get(api_url, headers=headers)
        u = untangle.parse(r.text)
        periods = u.weatherdata.product.time

        collection = ForestFireCollection(url=api_url)
        collection.save()

        for period in periods:
            time_from = period['from']
            time_to = period['to']
            for location in period.location:
                county = location['county']
                name = location['name']
                stationid = location['stationid']
                
                ws, ws_created = WeatherStation.objects.get_or_create(stationid=stationid, name=name, county=county)
                if ws_created:
                    self.get_wsinfo(ws)

                for ff in location.forest_fire:
                    if ff['unit'] == 'danger-index':
                        dangerindex = ff['value']
                ffi = ForestFireIndex(collection=collection, time_to=time_to, time_from=time_from, weatherstation=ws, dangerindex=dangerindex)
                ffi.save()
        collection.done = True
        collection.save()
开发者ID:mboehn,项目名称:ffc,代码行数:28,代码来源:getforestfireindex.py


示例6: tweet_uyd

def tweet_uyd(api):
    if path.isfile(last_epfile):
        last_ep = datetime.strptime(open(last_epfile, 'r').read(), '%a, %d %b %Y %H:%M:%S +0000')
    else:
        last_ep = datetime.strptime('Fri, 15 Jul 2016 19:51:00 +0000', '%a, %d %b %Y %H:%M:%S +0000')

    #req = requests.get('http://uhhyeahdude.com/podcast/')
    #feed = xml.etree.ElementTree.parse(req.content).getroot()
    feed = untangle.parse('http://uhhyeahdude.com/podcast/')
    eps = feed.rss.channel.item
    new_eps = []
    for ep in eps:
        pubdate = datetime.strptime(ep.pubDate.cdata, '%a, %d %b %Y %H:%M:%S +0000')
        if pubdate > last_ep:
            new_eps.append(ep)
            last_ep = pubdate

    if new_eps == []:
        #print 'No new eps'
        return

    #pickle.dump(last_ep, open(last_epfile, 'w'))
    open(last_epfile, 'w').write(last_ep.strftime('%a, %d %b %Y %H:%M:%S +0000'))
    for ep in reversed(new_eps):
        desc = ep.description.cdata
        desc = desc.replace('\n', ' ').replace('\t', ' ')
        words = desc.split(' ')
        if set(['intro:', 'outro:', 'http://uhhyeahdude.com']).issubset(set(words)):
            intro = ' '.join(words[words.index('intro:')+1:words.index('outro:')-1])
            intro_url = youtube_search.search(intro)
            api.PostUpdate('{0} intro: {1} {2}'.format(ep.title.cdata, intro, intro_url))
            outro = ' '.join(words[words.index('outro:')+1:words.index('http://uhhyeahdude.com')])
            outro_url = youtube_search.search(outro)
            api.PostUpdate('{0} outro: {1} {2}'.format(ep.title.cdata, outro, outro_url))
开发者ID:MohamedGupta,项目名称:uydmusic,代码行数:34,代码来源:main.py


示例7: parse_xml

def parse_xml(filename):
  contents= ""
  with open(filename, "r") as f:
    contents = f.readlines()
  #print "i read the xml file, here are its contents:\n\n"
  #print contents
  root = untangle.parse(filename)
  return_dict = {}
  player1 = root.items.pName1.cdata
  player2 = root.items.pName2.cdata
  main_title = root.items.eventTitle.cdata
  titleL = root.items.rOundl.cdata 
  titleR = root.items.rOundr.cdata
  #print "p1" + player1 + "p2" + player2 + "titleL" + titleL + "titleR" + titleR + "main" + main_title
  # figure out what game we're in right now
  game_keywords = MELEE_KEYWORDS

  vod_title = main_title + ": " + titleL + " - " + titleR + ": ", player1 + " vs. " + player2
  final_title = "".join(vod_title)
  if len(final_title) > 95:
    final_title = final_title[:95]
  return_dict['title'] = final_title
  print "going to upload with the title:" + return_dict['title']
  return_dict['description'] = "VOD from" + main_title + " created by khz's auto vod uploader"
  return_dict['keywords'] = SMASH_KEYWORDS + NEBS_KEYWORDS + game_keywords
  return_dict['category'] = "20" # this is the US category for gaming
  return_dict['privacyStatus'] = "public" #XXX: change this later
  return return_dict
开发者ID:jhertz,项目名称:autovod,代码行数:28,代码来源:uploader_melee.py


示例8: NYC_outage_fraction

def NYC_outage_fraction ():
    print 'Getting the data from : http://www.grandcentral.org/developers/data/nyct/nyct_ene.xml'
    f=urllib.urlopen('http://www.grandcentral.org/developers/data/nyct/nyct_ene.xml')
    print 'Data collection is done'
    raw_data=f.read()
    print 'Parsing the data'
    raw_data_parse=untangle.parse(raw_data)
    raw_data_parse.get_elements()

    print 'Filtering the outage data'

    outages = raw_data_parse.NYCOutages.outage

    global total
    total=len(outages)

    print 'Total nr. of escalators ' +str(total)

    global repair
    repair = 0
    for outage in outages:
        outage.get_elements()
        reason=outage.reason.cdata
        if reason == 'REPAIR':
            repair=+1
        else:
            continue

    print 'Nr. of escalators need repair ' + str(repair)

    global frac
    frac=repair/total*100

    print 'This is' +str(frac)+'% of the total escalators'
开发者ID:pythonkurs,项目名称:Yoluk,代码行数:34,代码来源:session2.py


示例9: download_article_html

def download_article_html(name, only_count=False, total=-1):
    rss_archive = os.path.join(DEFAULT_SAVE_PATH, name, 'rss_archive')
    article_archive = os.path.join(DEFAULT_SAVE_PATH, name, 'raw_articles')
    mkdir_p(article_archive)
    count = 0
    for rss in glob.glob(rss_archive+'/*.xml'):
        obj = untangle.parse(rss)
        if count > 1:
            break
        for item in obj.rss.channel.item:
            guid = item.guid.cdata
            title = item.title.cdata
            try:
                orig_link = item.feedburner_origLink
            except IndexError as e:
                logging.error(e)
                break
            link = "http://web.archive.org/web/{0}".format(orig_link)
            h = hashlib.sha224(guid).hexdigest()
            f = os.path.join(article_archive, h+'.html')
            if os.path.exists(f):
                continue
            count += 1
            if only_count:
                continue
            print(u'Downloading {0}/{1}: {2}'.format(count, total, title))
            resp = requests.get(link)
            if resp.status_code == 200:
                with open(f, 'w') as fp:
                    fp.write(resp.text)
    return count
开发者ID:gregjan,项目名称:bullshit-detector,代码行数:31,代码来源:wbm_api.py


示例10: test

def test():
    query = request.args.get("q")
    result = []
    result_map = []
    url = "http://mercury-ops2.ornl.gov/usgssolr4/core1/select/"

    param2 = 'geo:"intersects(' + query + ')"'
    param3 = "*:*"
    payload = {"fq": param2, "q": param3, "start": 0, "rows": 1000}
    r = requests.get(url, params=payload)

    # faz o parsing do XML
    obj = untangle.parse(r.content)

    for doc in obj.response.result.doc:
        missing_bboxinfo = doc.str[7].cdata  # Does not the file contain bounding box info?

        if unicode.lower(missing_bboxinfo) == "false":
            projid = doc.str[0].cdata  # id
            nbc = float(doc.float[0].cdata)  # northBoundCoord //latitude
            sbc = float(doc.float[1].cdata)  # southBoundCoord //latitude
            ebc = float(doc.float[2].cdata)  # eastBoundCoord //longitude
            wbc = float(doc.float[3].cdata)  # westBoundCoord //longitude
            title = doc.str[12].cdata
            author = doc.arr[16].cdata
            abstract = doc.str[11].cdata
            update_data = doc.str[0].cdata
            network_url = doc.arr[9].cdata
            data_url = doc.arr[10].cdata

            ## obtain the centroid (based on http://gis.stackexchange.com/questions/64119/center-of-a-bounding-box_
            coords = (wbc, ebc, sbc, nbc)
            centerx, centery = (numpy.average(coords[:2]), numpy.average(coords[2:]))

            db.create_all()

            projectitr = Project(
                projid,
                nbc,
                sbc,
                ebc,
                wbc,
                centerx,
                centery,
                title,
                author,
                abstract,
                update_data,
                network_url,
                data_url,
            )

            db.session.add(projectitr)
            db.session.commit()

            # result_map.append({"properties": {"id": projid}, "geometry": Point((centery, centerx))})

            result_map.append({"properties": {"id": id}, "geometry": Point((centery, centerx))})
    print json.dumps(result_map)
    return json.dumps(result_map)
开发者ID:daniellins,项目名称:Service_I_WDS,代码行数:60,代码来源:ws.py


示例11: sync_table

    def sync_table(self, season, league, league_ssha_id, game_type):
        url = "%s/tabelle.aspx" % self.WS_URL
        params = {
            "typ": "liga",
            "id": league_ssha_id
        }
        self._logger.info("Fetching table for league %s" % (league_ssha_id, ))
        response = self._call_webservice(url, params)

        xml_table = untangle.parse(response.content)

        try:
            for xml in xml_table.ihs.Mannschaften.Mannschaft:
	        try:
                    team = self._get_team(xml.Team.cdata)
		except Club.DoesNotExist:
                    continue
                table = get_object_or_None(Table, team=team, season=season, league=league, game_type=game_type)
                if table is None:
                    table = Table(team=team, season=season, league=league, game_type=game_type)
                table.position = int(xml.Rang.cdata)
                table.gp = int(xml.Spiele.cdata)
                table.win = int(xml.Siege.cdata)
                table.loss = int(xml.Niederlagen.cdata)
                table.tie = int(xml.Remis.cdata)
                table.diff = xml.Tore.cdata
                table.points = int(xml.Punkte.cdata)

                table.save()
        except IndexError:
            self._logger.debug("No table entries found!")
开发者ID:wittwerch,项目名称:1107,代码行数:31,代码来源:synchronizer.py


示例12: populate_metadata

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:rehandalal,项目名称:normandy,代码行数:30,代码来源:0004_auto_20190115_0812.py


示例13: doSearch

    def doSearch(self, searchstring):

        print("doSearch")
        # Clear the previous results
        self.resetResults()

        # Make the request
        url = "http://search.student.utwente.nl/api/search"

        params = {"q": searchstring, "n": 500}
        result = requests.get(url, params=params)

        if result.status_code == requests.codes.ok:
            parsed_xml = untangle.parse(result.text)

            # list of results
            try:
                results = parsed_xml.campus_search.result
            except IndexError:
                return

            # Add the results
            for result in results:
                if result.type.cdata == "file":

                    self.addResultItem(result.name.cdata, result.full_path.cdata, result.netbios_name.cdata)

            # Make the results show up
            self.scrollwindow.show_all()

        else:
            print("Error: sending request to campussearch failed")
开发者ID:jdcc2,项目名称:campussearch,代码行数:32,代码来源:campussearch.py


示例14: initrecurls

 def initrecurls(self, loclist):
   for url in loclist:
     doc = untangle.parse(url)
     if int(doc.xml.changes['size']) > 0:
       for i in doc.xml.changes.id:
         self.recurls.append(baseurl + i.cdata + s + format)
   return self.recurls
开发者ID:gonzaga,项目名称:poerelief,代码行数:7,代码来源:harvest.py


示例15: __init__

    def __init__(self, path='', source = 'text', words=[]):
        if len(words) == 0:
            self.words = []
            if source == 'umarker': #xml from uncertaintymaker code
                import untangle
                template = untangle.parse(path)
                for word in template.transcription.words:
                    if not word.word.cdata in ["[sil]", "[NOISE]", "[SPEECH]"]:
                        self.words.append(Word(word.word.cdata, word.timeStart.cdata, word.timeEnd.cdata))

            elif source == 'ldc-wrd':
                wrd_file = open(path, 'r')
                for line in wrd_file:
                    elements = line.split(' ')
                    word = elements[2].rstrip()
                    time_from = self.convert_time(elements[0], from_time='ldc', to_time='ms')
                    time_to = self.convert_time(elements[1], from_time='ldc', to_time='ms')
                    self.words.append(Word(word, time_from, time_to))
                wrd_file.close()
            elif source == 'wrd':
                wrd_file = open(path, 'r')
                for line in wrd_file:
                    elements = line.split(' ')
                    word = elements[2].rstrip()
                    time_from = elements[0]
                    time_to = elements[1]
                    self.words.append(Word(word, time_from, time_to))
                wrd_file.close()
            elif source == 'text':
                path = path.encode('ascii', 'ignore')
                for word in word_tokenize(path):
                    if not word in ['"', "'", ".", "!", '``', '`', "''", '""']:
                        self.words.append(Word(word, '', ''))
        else:
            self.words = words
开发者ID:SushantKafle,项目名称:sushantkafle.github.io,代码行数:35,代码来源:Sentence.py


示例16: get_steamids

def get_steamids( group_name , page_number = 1):
	obj = 0

	while True:
		try:
			url = 'http://steamcommunity.com/groups/' + str(group_name) + '/memberslistxml/?xml=1&p=' + str(page_number)
			obj = untangle.parse(url)
		except:
			pass
		if str(obj) != '0':
			break

	try:
		string_obj = str(obj.memberList.members.steamID64)
	except:
		return []
		
	string_obj = string_obj.split(' ')
	

	
	steamids = []
	for item in string_obj:
		if '7656' in item:
			steamids.append(item[0:17])
	
	return steamids
开发者ID:vitalyturkov,项目名称:groupscanner,代码行数:27,代码来源:get_steamids.py


示例17: remove_processed_from_list

def remove_processed_from_list(filelist, logfile, outpath):

    # read original file list

    with open (filelist, "rb") as f:
        file_list_old = f.readlines()

    # read log-file
    logobj = untangle.parse(logfile)
    processed = logobj.root.process_log.list_of_processed_files.cdata.encode().strip()
    processed = processed.split(", ")

    file_list_new = list()

    for listitem in file_list_old:
        exists = 0
        for pfile in processed:
            if os.path.basename(listitem.strip()) == pfile:
                exists = 1

        if exists == 0:
            file_list_new.append(listitem.strip())

    # write results
    f = open(outpath, "wb")
    for x in file_list_new: f.write(x + '\n')
    #f.writelines(filelist)
    f.close()
开发者ID:felixgreifeneder,项目名称:Python_SGRT_devel,代码行数:28,代码来源:update_file_list.py


示例18: _url

def _url(id3tag):
    """Get the lyric's URL by calling the API

    Extract song and artist frames from the id3tag and then call
    the lyrics.wikia.com api for the URL of the actual lyric.

    Args:
        id3tag (ID3): id3-tag of the song

    Returns:
        string: lyric URL if successful, None otherwise

    """
    try:
        # Get artist and song from tag
        artist = id3tag['TPE1'].text[0].encode('utf8')
        song = id3tag['TIT2'].text[0].encode('utf8')

        # Build request
        params = {'artist':artist, 'song':song, 'fmt':'xml'}
        request = 'http://lyrics.wikia.com/api.php?' + urllib.urlencode(params)

        # Do request
        response = untangle.parse(request)
        if response.LyricsResult.lyrics.cdata == 'Not found':
            return None
        return urllib.unquote(response.LyricsResult.url.cdata)

    except Exception:
        return None
开发者ID:drachenminister,项目名称:lyrtag,代码行数:30,代码来源:lyrscraper.py


示例19: test_multiple_children

 def test_multiple_children(self):
     """ Regular case of iteration. """
     o = untangle.parse("<a><b/><b/></a>")
     cnt = 0
     for i in o.a.b:
         cnt += 1
     self.assertEquals(2, cnt)
开发者ID:marsam,项目名称:untangle,代码行数:7,代码来源:tests.py


示例20: test_python_keyword

 def test_python_keyword(self):
     o = untangle.parse("<class><return/><pass/><None/></class>")
     self.assert_(o is not None)
     self.assert_(o.class_ is not None)
     self.assert_(o.class_.return_ is not None)
     self.assert_(o.class_.pass_ is not None)
     self.assert_(o.class_.None_ is not None)
开发者ID:stchris,项目名称:untangle,代码行数:7,代码来源:tests.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python magic.sign函数代码示例发布时间:2022-05-27
下一篇:
Python unpaddedbase64.encode_base64函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap