mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-05-18 11:31:06 +00:00
add ascii_safe method
git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@2719 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
parent
56b2b422a9
commit
5244431a42
1 changed files with 15 additions and 0 deletions
|
|
@ -45,6 +45,21 @@ def unicode_safe (s, encoding="iso-8859-1"):
|
|||
return unicode(str(s), encoding, "ignore")
|
||||
|
||||
|
||||
def ascii_safe (s):
|
||||
"""
|
||||
Get ASCII string without raising encoding errors. Unknown
|
||||
characters of the given encoding will be ignored.
|
||||
|
||||
@param s: the Unicode string to be encoded
|
||||
@type s: unicode or None
|
||||
@return: encoded ASCII version of s, or s itself if s evaluated to False
|
||||
@rtype: string
|
||||
"""
|
||||
if s:
|
||||
s = s.encode('ascii', 'ignore')
|
||||
return s
|
||||
|
||||
|
||||
def url_unicode_split (url):
|
||||
"""
|
||||
Like urlparse.urlsplit(), but always returning unicode parts.
|
||||
|
|
|
|||
Loading…
Reference in a new issue