mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-05-11 16:13:11 +00:00
add is_encoding() method
git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@2980 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
parent
cff9b1341b
commit
d28567753b
1 changed files with 13 additions and 2 deletions
|
|
@ -21,6 +21,7 @@ necessarily optimised for large strings, so use with care.
|
|||
|
||||
import re
|
||||
import textwrap
|
||||
import codecs
|
||||
import os
|
||||
import time
|
||||
import urlparse
|
||||
|
|
@ -52,10 +53,10 @@ def ascii_safe (s):
|
|||
|
||||
@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
|
||||
@return: encoded ASCII version of s, or None if s was None
|
||||
@rtype: string
|
||||
"""
|
||||
if s:
|
||||
if isinstance(s, unicode):
|
||||
s = s.encode('ascii', 'ignore')
|
||||
return s
|
||||
|
||||
|
|
@ -71,6 +72,16 @@ def is_ascii (s):
|
|||
return False
|
||||
|
||||
|
||||
def is_encoding (text):
|
||||
"""
|
||||
Check if string is a valid encoding.
|
||||
"""
|
||||
try:
|
||||
return codecs.lookup(text)
|
||||
except LookupError:
|
||||
return False
|
||||
|
||||
|
||||
def url_unicode_split (url):
|
||||
"""
|
||||
Like urlparse.urlsplit(), but always returning unicode parts.
|
||||
|
|
|
|||
Loading…
Reference in a new issue