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


Python saxutils.unescape函数代码示例

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


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

示例1: allowed_token

 def allowed_token(self, token, token_type):
     if "data" in token:
         attrs = dict([(name, val) for name, val in
                       token["data"][::-1]
                       if name in self.allowed_attributes])
         for attr in self.attr_val_is_uri:
             if attr not in attrs:
                 continue
             val_unescaped = re.sub("[`\000-\040\177-\240\s]+", '',
                                    unescape(attrs[attr])).lower()
             # remove replacement characters from unescaped characters
             val_unescaped = val_unescaped.replace("\ufffd", "")
             if (re.match("^[a-z0-9][-+.a-z0-9]*:", val_unescaped) and
                 (val_unescaped.split(':')[0] not in
                  self.allowed_protocols)):
                 del attrs[attr]
         for attr in self.svg_attr_val_allows_ref:
             if attr in attrs:
                 attrs[attr] = re.sub(r'url\s*\(\s*[^#\s][^)]+?\)',
                                      ' ',
                                      unescape(attrs[attr]))
         if (token["name"] in self.svg_allow_local_href and
             'xlink:href' in attrs and re.search('^\s*[^#\s].*',
                                                 attrs['xlink:href'])):
             del attrs['xlink:href']
         if 'style' in attrs:
             attrs['style'] = self.sanitize_css(attrs['style'])
         token["data"] = [[name, val] for name, val in list(attrs.items())]
     return token
开发者ID:089git,项目名称:calibre,代码行数:29,代码来源:sanitizer.py

示例2: __init__

    def __init__(self, filename=None):
        self.author = ''
        self.description = ''
        self.instructions = ''
        self.filename = filename

        if filename is not None:
            filexml = minidom.parse(filename)
            # we have no use for all the xml data in the file. We only care
            # about what is between the "description" tags
            templatedata = filexml.getElementsByTagName('templatedata')
            if len(templatedata):
                desc_xml = templatedata[0]
                try:
                    self.author = saxutils.unescape(
                        desc_xml.getElementsByTagName(
                        'author')[0].firstChild.data)
                except (IndexError, AttributeError): self.author = ''
                try:
                    self.description = saxutils.unescape(
                        desc_xml.getElementsByTagName(
                        'description')[0].firstChild.data)
                except (IndexError, AttributeError): self.description = ''
                try:
                    self.instructions = saxutils.unescape(
                        desc_xml.getElementsByTagName(
                        'instructions')[0].firstChild.data)
                except (IndexError, AttributeError): self.instructions = ''
            else:
                self.author = ''
                self.description=''
                self.instructions=''
开发者ID:dsqiu,项目名称:qzystudy,代码行数:32,代码来源:template.py

示例3: get_tag_content

 def get_tag_content(doc,tag_name,unescape_xml=1):
     'get a tags value by tag name. looks at the type attr. default is string'
     tags = doc.getElementsByTagName(tag_name)
     if len(tags) > 0:
         tag = tags.pop() # Take the last occurance
         text_node = tag.firstChild
         if text_node:
             if len(text_node.data) > 0:
                 if tag.hasAttribute('type'):
                     type = tag.getAttribute('type')
                     if type == 'integer':
                         inner_text = int(text_node.data)
                     elif type == 'boolean':
                         inner_text =  XmlHelper.str_as_bool(text_node.data)
                     else:
                         # If type is not recognized, assume it's a string
                         inner_text = str(text_node.data)
                         if unescape_xml:
                             inner_text = unescape(inner_text)
                 else:
                     # If no type is given, assume it's a string
                     inner_text = str(text_node.data)
                     if unescape_xml:
                         inner_text = unescape(inner_text)
                 return inner_text
     return None
开发者ID:onlinemq,项目名称:python-onlinemq,代码行数:26,代码来源:onlinemq.py

示例4: read

def read(glos, filename):
  fp = open(filename, 'rb')
  glos.data = []
  xdbText = fp.read()
  i = 0
  for item in infoKeys:################## method should be changed
    inf0 = xdbText.find('<'+item+'>', i)
    if inf0==-1:
      continue
    inf0 += (len(item)+2)
    inf1 = xdbText.find('</'+item+'>', inf0)
    inf = unescape(xdbText[inf0:inf1])
    glos.setInfo(item, inf)
    i = inf1
  while True:######################################################
    i=xdbText.find('<word>', i)
    if i==-1:
      break
    in0 = xdbText.find('<in>', i) + 4
    in1 = xdbText.find('</in>', in0)
    out0= xdbText.find('<out>', in1) + 5
    out1= xdbText.find('</out>', out0)
    word = unescape(xdbText[in0:in1])
    defi = unescape(xdbText[out0:out1])
    glos.data.append((word, defi))
    #i = out1
    i = xdbText.find('</word>', out1) + 7    
开发者ID:Armel35,项目名称:pyglossary,代码行数:27,代码来源:xfardic.py

示例5: run_test_in_docker

    def run_test_in_docker(self, test, full_name, result):
        try:
            exit_with_proper_code = 'EXIT=$?; cat /app/nosetests.xml; exit $EXIT'
            xml = docker.run(
                '--rm',
                '-v',
                '%s:/app' % abspath(os.curdir),
                'nose-docker:%s' % self.container_tag,
                '/bin/bash',
                c="cd /app && echo 'running tests for %s...' && nosetests --with-xunit %s; %s" % (
                    full_name,
                    full_name,
                    exit_with_proper_code
                ),
            )

            result.addSuccess(test)
        except sh.ErrorReturnCode:
            err = sys.exc_info()[1]
            xml = err.stdout[err.stdout.index('<?xml'):]
            root = etree.fromstring(xml)

            failure = FAILURE_SELECTOR(root)
            if failure:
                failure_message = su.unescape(failure[0].text).replace('\\n', '\n')
                result.addFailure(test, failure_message)

            error = ERROR_SELECTOR(root)
            if error:
                result.addError(test, su.unescape(error[0].text))

        finally:
            result.testsRun += 1
开发者ID:naphthalene,项目名称:nose-docker-fabric,代码行数:33,代码来源:plugin.py

示例6: parsePlaylistsJSON

def parsePlaylistsJSON(doc):
    """ Parse Playlists JSON using eval to [ [], [], [] ... ] """
    log("parsePlaylistsJSON()")

    data = []
    try:
        # evals to [ {}, {}, .. ]
        items = eval( doc.replace('null', '\"\"' ) )
        # convert to [ [], [], .. ] as its easier to unpack without key knowlegde
        for item in items:
            try:
                updated = item.get('updated_at','')[:10]                # yyyy/mm/dd
            except:
                updated = ''
            data.append( (unescape(item.get('title','')), \
                        str(item.get('id','')), \
                        unescape(item.get('description','')), \
                        item.get('contents_count',0), \
                        updated, \
                        item.get('icon_url','')) )
        data.sort()
    except:
        traceback.print_exc()
        data = []
    return data
开发者ID:drrlramsey,项目名称:xbmc-addons,代码行数:25,代码来源:reeplayit.py

示例7: parse_execute_anonymous_xml

def parse_execute_anonymous_xml(result):
    """
    Get the compile result in the xml result

    @result: execute anonymous result, it's a xml

    @return: formated string
    """

    compiled = result["compiled"]
    debugLog = result["debugLog"]

    view_result = ''
    if compiled == "true":
        view_result = debugLog
    elif compiled == "false":
        line = result["line"]
        column = result["column"]
        compileProblem = result["compileProblem"]
        view_result = compileProblem + " at line " + line +\
            " column " + column + "\n" + "-" * 100 + "\n" + debugLog
        print(view_result)

    if is_python3x():
        view_result = urllib.parse.unquote(unescape(view_result, 
            {"&apos;": "'", "&quot;": '"'}))
    else:
        view_result = urllib.unquote(unescape(view_result, 
            {"&apos;": "'", "&quot;": '"'}))

    return view_result
开发者ID:VincentMiao,项目名称:SublimeApex,代码行数:31,代码来源:util.py

示例8: play

  def play(self, page, mode=''):
    if Debug: self.LOG('DEBUG: _play()\nurl: %s' % page)
    # Get current list item details...
    title = unicode(xbmc.getInfoLabel("ListItem.Title"), "utf-8")
    thumbnail = xbmc.getInfoImage("ListItem.Thumb")
    plot = unicode(xbmc.getInfoLabel("ListItem.Plot"), "utf-8")

    if mode == 'smil':
      smil = BSS(self._get(page))
      rtmp = smil.meta['base']
      video = smil.video['src']
      swfUrl = 'http://medici.tv/medici.swf'
      # rtmpdump script for console use 
      rtmpdump = "rtmpdump -r %s --swfUrl http://medici.tv/medici.swf --tcUrl '%s' --playpath '%s' -o '%s.mp4'" % \
                  (rtmp, rtmp, saxutils.unescape(video), saxutils.unescape(title))
      # Build rtmp url...
      video_url = rtmp + ' swfUrl=' + swfUrl + ' tcUrl=' + rtmp + ' playpath=' + saxutils.unescape(video)
      if Debug: self.LOG('DEBUG: rtmp link details.\n\trtmp: %s\n\tswfUrl: %s\n\ttcUrl: %s\n\tplaypath: %s\n\trtmpdump: %s' % \
                         (rtmp, swfUrl, rtmp, saxutils.unescape(video), rtmpdump))
    elif mode == 'rtmp_daily':
      video_url = page.split('&rtmp=1')[0]
      if Debug: self.LOG('DEBUG: video link details.\n\turl: %s' % video_url)
    else:
      video_url = ''
      if Debug: self.LOG('DEBUG: no video link!')
      raise
    # only need to add label, icon and thumbnail, setInfo() and addSortMethod() takes care of label2
    listitem = xbmcgui.ListItem(title, iconImage="DefaultVideo.png", thumbnailImage=thumbnail)
    # set listitem information
    listitem.setInfo('video', {'title': title,
                               'label' : title,
                               'plot': plot,
                               'plotoutline': plot, })
    # Play video...
    xbmc.Player().play(video_url , listitem)
开发者ID:lluisnaval,项目名称:plugin.video.medici.tv,代码行数:35,代码来源:addon.py

示例9: sanitize_token

    def sanitize_token(self, token):

        # accommodate filters which use token_type differently
        token_type = token["type"]
        if token_type in tokenTypes.keys():
          token_type = tokenTypes[token_type]

        if token_type in (tokenTypes["StartTag"], tokenTypes["EndTag"], 
                             tokenTypes["EmptyTag"]):
            if token["name"] in self.allowed_elements:
                if token.has_key("data"):
                    attrs = dict([(name,val) for name,val in
                                  token["data"][::-1] 
                                  if name in self.allowed_attributes])
                    for attr in self.attr_val_is_uri:
                        if not attrs.has_key(attr):
                            continue
                        val_unescaped = re.sub("[`\000-\040\177-\240\s]+", '',
                                               unescape(attrs[attr])).lower()
                        #remove replacement characters from unescaped characters
                        val_unescaped = val_unescaped.replace(u"\ufffd", "")
                        if (re.match("^[a-z0-9][-+.a-z0-9]*:",val_unescaped) and
                            (val_unescaped.split(':')[0] not in 
                             self.allowed_protocols)):
                            del attrs[attr]
                    for attr in self.svg_attr_val_allows_ref:
                        if attr in attrs:
                            attrs[attr] = re.sub(r'url\s*\(\s*[^#\s][^)]+?\)',
                                                 ' ',
                                                 unescape(attrs[attr]))
                    if (token["name"] in self.svg_allow_local_href and
                        'xlink:href' in attrs and re.search('^\s*[^#\s].*',
                                                            attrs['xlink:href'])):
                        del attrs['xlink:href']
                    if attrs.has_key('style'):
                        attrs['style'] = self.sanitize_css(attrs['style'])
                    token["data"] = [[name,val] for name,val in attrs.items()]
                return token
            else:
                if token_type == tokenTypes["EndTag"]:
                    token["data"] = "</%s>" % token["name"]
                elif token["data"]:
                    attrs = ''.join([' %s="%s"' % (k,escape(v)) for k,v in token["data"]])
                    token["data"] = "<%s%s>" % (token["name"],attrs)
                else:
                    token["data"] = "<%s>" % token["name"]
                if token.get("selfClosing"):
                    token["data"]=token["data"][:-1] + "/>"

                if token["type"] in tokenTypes.keys():
                    token["type"] = "Characters"
                else:
                    token["type"] = tokenTypes["Characters"]

                del token["name"]
                return token
        elif token_type == tokenTypes["Comment"]:
            pass
        else:
            return token
开发者ID:1974kpkpkp,项目名称:WebGL,代码行数:60,代码来源:sanitizer.py

示例10: parse

    def parse(client, xml_data):
        data = StringIO.StringIO(xml_data)
        try:
            element = ElementTree.parse(data).getroot().attrib
        except:
            raise ParseError('Invalid MSNObject')

        try:
            creator = client.address_book.contacts.\
                search_by_account(element["Creator"]).\
                search_by_network_id(NetworkID.MSN)[0]
        except IndexError:
            creator = None

        size = int(element["Size"])
        type = int(element["Type"])
        location = xml.unescape(element["Location"])
        friendly = base64.b64decode(xml.unescape(element["Friendly"]))
        shad = element.get("SHA1D", None)
        if shad is not None:
            shad = base64.b64decode(shad)
        shac = element.get("SHA1C", None)
        if shac is not None:
            shac = base64.b64decode(shac)

        result = MSNObject(creator, size, type, location, \
                             friendly, shad, shac)
        result._repr = xml_data
        return result
开发者ID:snowpunk,项目名称:papyon,代码行数:29,代码来源:p2p.py

示例11: unescape_html

def unescape_html(input_file, output_file=os.getcwd() + '/'):
    f = file(input_file, 'r')
    for line in f.xreadlines():
        if output_file == os.getcwd() + '/':
            save_result_file(unescape(line, html_unescaped_dict), output_file + input_file + '_escape')
        else:
            save_result_file(unescape(line, html_unescaped_dict), output_file + '_escape')
开发者ID:fc500110,项目名称:iamrobot,代码行数:7,代码来源:htmlEscape.py

示例12: endElement

	def endElement(self, name):
		if name == 'vampire':
			assert self.current_vampire
			self.add_vampire(self.current_vampire)
			self.current_vampire = None

		elif name == 'experience':
			assert self.current_experience
			self.current_experience = None

		elif name == 'traitlist':
			assert self.current_traitlist
			self.current_traitlist = None

		elif name == 'biography':
			assert self.reading_biography
			self.reading_biography = False
			if self.current_vampire:
				self.current_vampire['biography'] = unescape(self.current_biography)
				print self.current_biography
			self.current_biography = ''

		elif name == 'notes':
			assert self.reading_notes
			self.reading_notes = False
			if self.current_vampire:
				self.current_vampire['notes'] = unescape(self.current_notes)
				print self.current_notes
			self.current_notes = ''
开发者ID:gnu-lorien,项目名称:crapvine-online,代码行数:29,代码来源:vampire_loader.py

示例13: parse_markup

def parse_markup(markup_text):
    'Return plain text and a list of start, end TextTag'
    markup_text = BytesIO(_markup(markup_text))
    plain_text = ''
    tag_stack = []
    tags = []
    for event, element in ET.iterparse(markup_text, events=['start', 'end']):
        if element.tag == 'markup':
            if event == 'start' and element.text:
                plain_text += unescape(element.text)
            if event == 'end' and element.tail:
                plain_text += unescape(element.tail)
            continue
        if event == 'start':
            tag_stack.append((element, len(plain_text)))
            if element.text:
                plain_text += unescape(element.text)
        elif event == 'end':
            if element.tag == 'div':
                plain_text += '\n'
            assert tag_stack[-1][0] == element
            _, start = tag_stack.pop()
            end = len(plain_text)
            tags.append((start, end, element))
            if element.tail:
                plain_text += unescape(element.tail)
    return plain_text, tags
开发者ID:kret0s,项目名称:gnuhealth-live,代码行数:27,代码来源:htmltextbuffer.py

示例14: write_csv_file

def write_csv_file(filename, dictionary):
    """ Writes the dictionary as CSV to the specified file """
    with open(filename, 'w') as f:
        writer = csv.writer(f)
        for key, value in dictionary.items():
            writer.writerow([unescape(key.encode("utf-8")),
                             unescape(value.encode("utf-8"))])
开发者ID:lorden,项目名称:nosh_parser,代码行数:7,代码来源:nosh_parse.py

示例15: parse

    def parse(client, xml_data):
        data = StringIO.StringIO(xml_data)
        try:
            element = ElementTree.parse(data).getroot().attrib
        except:
            raise ParseError('Invalid MSNObject')

        creator = element["Creator"]
        size = int(element["Size"])
        type = int(element["Type"])
        location = xml.unescape(element["Location"])
        friendly = base64.b64decode(xml.unescape(element["Friendly"]))
        shad = element.get("SHA1D", None)
        if shad is not None:
            shad = _decode_shad(shad)
        shac = element.get("SHA1C", None)
        if shac is not None:
            try:
                shac = base64.b64decode(shac)
            except TypeError:
                logger.warning("Invalid SHA1C in MSNObject: %s" % shac)
                shac = None

        result = MSNObject(creator, size, type, location, friendly, shad, shac)
        result._repr = xml_data
        return result
开发者ID:cacciald,项目名称:pygmsn,代码行数:26,代码来源:p2p.py


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