mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-04-22 15:14:44 +00:00
add decode() method; fix file flush in case self.fd is None; expand user name of filenames
git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@3355 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
parent
4c83e19454
commit
af255b67e0
1 changed files with 20 additions and 5 deletions
|
|
@ -81,7 +81,7 @@ class Logger (object):
|
|||
self.close_fd = False
|
||||
self.fd = None
|
||||
if args.get('fileoutput'):
|
||||
self.filename = args['filename']
|
||||
self.filename = os.path.expanduser(args['filename'])
|
||||
elif args.has_key('fd'):
|
||||
self.fd = args['fd']
|
||||
else:
|
||||
|
|
@ -99,10 +99,11 @@ class Logger (object):
|
|||
"""
|
||||
Flush and close the file output denoted by self.fd.
|
||||
"""
|
||||
self.flush()
|
||||
if self.close_fd:
|
||||
self.fd.close()
|
||||
self.fd = None
|
||||
if self.fd is not None:
|
||||
self.flush()
|
||||
if self.close_fd:
|
||||
self.fd.close()
|
||||
self.fd = None
|
||||
|
||||
def encode (self, s):
|
||||
"""
|
||||
|
|
@ -118,6 +119,20 @@ class Logger (object):
|
|||
raise ValueError("tried to encode non-unicode string %r" % s)
|
||||
return s.encode(self.output_encoding, "replace")
|
||||
|
||||
def decode (self, s):
|
||||
"""
|
||||
Decode string with configured output encoding. Wrong decoded
|
||||
characters are replaced.
|
||||
|
||||
@param s: string to decode
|
||||
@type s: string
|
||||
@return: encoded string
|
||||
@rtype: unicode
|
||||
"""
|
||||
if isinstance(s, unicode):
|
||||
return s
|
||||
return s.decode(self.output_encoding, "replace")
|
||||
|
||||
def check_date (self):
|
||||
"""
|
||||
Check for special dates.
|
||||
|
|
|
|||
Loading…
Reference in a new issue