mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-04-27 17:44:42 +00:00
added is_ascii and indent
git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@2806 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
parent
866999a883
commit
4b697eccea
1 changed files with 19 additions and 0 deletions
|
|
@ -60,6 +60,17 @@ def ascii_safe (s):
|
|||
return s
|
||||
|
||||
|
||||
def is_ascii (s):
|
||||
"""
|
||||
Test if a string can be encoded in ASCII.
|
||||
"""
|
||||
try:
|
||||
s.encode('ascii', 'strict')
|
||||
return True
|
||||
except (UnicodeEncodeError, UnicodeDecodeError):
|
||||
return False
|
||||
|
||||
|
||||
def url_unicode_split (url):
|
||||
"""
|
||||
Like urlparse.urlsplit(), but always returning unicode parts.
|
||||
|
|
@ -123,6 +134,14 @@ def wrap (text, width, **kwargs):
|
|||
return os.linesep.join(ret)
|
||||
|
||||
|
||||
def indent (text, indent_string=" "):
|
||||
"""
|
||||
Indent each line of text with the given indent string.
|
||||
"""
|
||||
lines = str(text).splitlines()
|
||||
return os.linesep.join(["%s%s" % (indent_string, x) for x in lines])
|
||||
|
||||
|
||||
def get_line_number (s, index):
|
||||
"""
|
||||
Return the line number of s[index]. Lines are assumed to be separated
|
||||
|
|
|
|||
Loading…
Reference in a new issue