本文整理汇总了Python中xml.sax.saxutils.unescape函数的典型用法代码示例。如果您正苦于以下问题:Python unescape函数的具体用法?Python unescape怎么用?Python unescape使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unescape函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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,
{"'": "'", """: '"'}))
else:
view_result = urllib.unquote(unescape(view_result,
{"'": "'", """: '"'}))
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
示例16: endElement
def endElement(self, name):
if self.reading_creature:
if self.creatures[self.reading_creature]:
self.creatures[self.reading_creature].endElement(name)
return
if name in self.creatures_elements:
assert self.reading_creature
self.reading_creature = ''
if self.creatures[name]:
self.creatures[name].endElement(name)
return
if name == 'grapevine':
assert self.chronicle
elif name == 'usualplace':
assert self.reading_usualplace
self.reading_usualplace = False
if self.chronicle:
self.chronicle['usualplace'] = unescape(self.current_usualplace)
self.current_usualplace = ''
elif name == 'description':
assert self.reading_description
self.reading_description = False
if self.chronicle:
self.chronicle['description'] = unescape(self.current_description)
self.current_description = ''
开发者ID:gnu-lorien,项目名称:crapvine-online,代码行数:28,代码来源:chronicle_loader.py
示例17: add_entry
def add_entry(self, result):
if (not result.url):
return
# add only distinct songs (unique by title+artist+duration) to prevent duplicates
strhash = ('%s%s%s' % (result.title, result.artist, result.duration)).lower()
if strhash in self.entries_hashes:
return
self.entries_hashes.append(strhash)
try:
#first, let's try to find if the song with this url is already in db
entry = self.db.entry_lookup_by_location(result.url)
if entry is not None :
return
#add song to db
entry = RB.RhythmDBEntry.new(self.db, self.entry_type, result.url)
self.db.commit()
if entry is not None :
#update metadata
self.db.entry_set(entry, RB.RhythmDBPropType.TITLE, unescape(result.title))
self.db.entry_set(entry, RB.RhythmDBPropType.DURATION, result.duration)
self.db.entry_set(entry, RB.RhythmDBPropType.ARTIST, unescape(result.artist))
#all the songs will get "vk.com" album
self.db.entry_set(entry, RB.RhythmDBPropType.ALBUM, "vk.com")
self.db.commit()
except Exception as e: # This happens on duplicate uris being added
sys.excepthook(*sys.exc_info())
print("Couldn't add %s - %s" % (result.artist, result.title), e)
开发者ID:YurkinPark,项目名称:rhythmbox-vk,代码行数:28,代码来源:vk.py
示例18: get_parallelsentences
def get_parallelsentences(self):
"""
This function parses a ranking xml file and returns a list of parallel
sentence objects.
@return ps_list: list of tuples in format (ranking-item_id, ParallelSentence)
@type ps_list: list of tuples
"""
r_items = self.xmlObject.getElementsByTagName('ranking-item')
ps_list = []
for r_item in r_items:
stc_id = r_item.getAttribute('sentence_id')
src = ''
tgt_list = []
for rank_child in r_item.childNodes:
if rank_child.nodeName == 'source':
src = SimpleSentence(unescape(rank_child.childNodes[0].nodeValue))
elif rank_child.nodeName != '#text':
tgt = SimpleSentence(unescape(rank_child.childNodes[0].nodeValue))
for attribute_name in rank_child.attributes.keys():
attribute_value = rank_child.getAttribute(attribute_name)
tgt.add_attribute(attribute_name, attribute_value)
tgt.add_attribute('system', rank_child.getAttribute('name'))
# tgt.add_attribute('rank', rank_child.getAttribute('rank'))
tgt_list.append(tgt)
ps = ParallelSentence(src, tgt_list)
#TODO: this was old, may have to change the attribute key. Commented because overlapping with other features
# if not ps.get_attributes().has_key("id"):
# ps.add_attributes({'id': stc_id})
ps.add_attributes({'sentence_id': stc_id})
ps_list.append(ps)
return ps_list
开发者ID:lefterav,项目名称:qualitative,代码行数:34,代码来源:rankreader.py
示例19: _ofx_txn
def _ofx_txn(self, txn):
fields = []
if self._check_field("Type", txn):
fields.append(TRNTYPE(txn["Type"].strip()))
if self._check_field("Date", txn):
fields.append(DTPOSTED(txn["Date"].strip()))
if self._check_field("Amount", txn):
fields.append(TRNAMT(txn["Amount"].strip()))
if self._check_field("Number", txn):
fields.append(CHECKNUM(txn["Number"].strip()))
if self._check_field("ID", txn):
fields.append(FITID(txn["ID"].strip()))
if self._check_field("Payee", txn):
fields.append(NAME(sax.escape(sax.unescape(txn["Payee"].strip()))))
if self._check_field("Memo", txn):
fields.append(MEMO(sax.escape(sax.unescape(txn["Memo"].strip()))))
if self._check_field("Category", txn):
fields.append(CATEGORY(sax.escape(sax.unescape(txn["Category"].strip()))))
return STMTTRN(*fields)
开发者ID:myfreecomm,项目名称:fixofx,代码行数:27,代码来源:qif_converter.py
示例20: opmlimport
def opmlimport(feeds, args):
"Import configuration from OPML."
if args.file:
_LOG.info('importing feeds from {}'.format(args.file))
f = open(args.file, 'rb')
else:
_LOG.info('importing feeds from stdin')
f = _sys.stdin
try:
dom = _minidom.parse(f)
new_feeds = dom.getElementsByTagName('outline')
except Exception as e:
raise _error.OPMLReadError() from e
if args.file:
f.close()
name_slug_regexp = _re.compile('[^\w\d.-]+')
for feed in new_feeds:
if feed.hasAttribute('xmlUrl'):
url = _saxutils.unescape(feed.getAttribute('xmlUrl'))
name = None
if feed.hasAttribute('text'):
text = _saxutils.unescape(feed.getAttribute('text'))
if text != url:
name = name_slug_regexp.sub('-', text)
feed = feeds.new_feed(name=name, url=url)
_LOG.info('add new feed {}'.format(feed))
feeds.save()
开发者ID:postprefix,项目名称:rss2email,代码行数:27,代码来源:command.py
注:本文中的xml.sax.saxutils.unescape函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论