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:
calvin 2005-07-05 22:06:38 +00:00
parent 56b2b422a9
commit 5244431a42

View file

@ -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.