1
0
mirror of https://git.FreeBSD.org/ports.git synced 2024-11-26 00:55:14 +00:00

- Make xmlUnEscape and percentUnQuote case-insensitive

PR:		ports/147706
Submitted by:	Anonymous <swell.k AT gmail.com> (maintainer)
This commit is contained in:
Li-Wen Hsu 2010-08-22 01:12:18 +00:00
parent 219895be4b
commit e716b53261
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=259707
3 changed files with 49 additions and 1 deletions

View File

@ -7,7 +7,7 @@
PORTNAME= rssdler
PORTVERSION= 0.4.2
PORTREVISION= 1
PORTREVISION= 2
CATEGORIES= www python
MASTER_SITES= GOOGLE_CODE
PKGNAMEPREFIX= ${PYTHON_PKGNAMEPREFIX}

View File

@ -0,0 +1,16 @@
Index: rssdler.py
===================================================================
--- rssdler.py (revision 169)
+++ rssdler.py (working copy)
@@ -363,9 +363,9 @@ def percentUnQuote( sStr, p=percentunQuoteDict, re
replaced in order of the sequence"""
for search in p:
if search in reserved: continue
- sStr = sStr.replace( search, p[search] )
+ sStr = re.sub('(?i)' + re.escape(search), p[search], sStr)
for search in reserved:
- sStr = sStr.replace( search, p[search])
+ sStr = re.sub('(?i)' + re.escape(search), p[search], sStr)
return sStr
def percentQuote(sStr, urlPart=(2,), pd=percentQuoteDict):

View File

@ -0,0 +1,32 @@
Index: rssdler.py
===================================================================
--- rssdler.py (revision 169)
+++ rssdler.py (working copy)
@@ -79,6 +79,7 @@ percentQuoteDict = {u'!': u'%21', u' ': u'%20', u'
u';': u'%3B', u':': u'%3A', u']': u'%5D', u'[': u'%5B', u'?': u'%3F',
u'!':u'%7E'}
percentunQuoteDict = dict(((j,i) for (i,j) in percentQuoteDict.items()))
+xmlUnEscapeDict = { u'&lt;' : u'<', u'&gt;' : u'>', u'&amp;' : u'&' }
netscapeHeader= """# HTTP Cookie File
# http://www.netscape.com/newsref/std/cookie_spec.html
# This is a generated file! Do not edit.\n\n"""
@@ -327,16 +328,15 @@ def unicodeC( s ):
raise UnicodeEncodeError(u'could not encode %s to unicode' % s)
return s
-def xmlUnEscape( sStr, percent=0, pd=percentunQuoteDict ):
+def xmlUnEscape( sStr, percent=0, pd=percentunQuoteDict, xd=xmlUnEscapeDict ):
u"""xml unescape a string, by default also checking for percent encoded
characters. set percent=0 to ignore percent encoding.
can specify your own percent quote dict
(key, value) pairs are of (search, replace) ordering with percentunQuoteDict
"""
- sStr = sStr.replace("&lt;", "<")
- sStr = sStr.replace("&gt;", ">")
if percent: sStr = percentUnQuote( sStr, pd )
- sStr = sStr.replace("&amp;", "&")
+ for search in xd:
+ sStr = re.sub('(?i)' + re.escape(search), xd[search], sStr)
return sStr
def percentIsQuoted(sStr, testCases=percentQuoteDict.values()):