mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-04-13 09:42:01 +00:00
26 lines
662 B
Python
26 lines
662 B
Python
![]() |
import datetime
|
||
|
import time
|
||
|
|
||
|
def encode(tstr):
|
||
|
""" Encodes a unicode string in utf-8
|
||
|
"""
|
||
|
if not tstr:
|
||
|
return ''
|
||
|
# this is _not_ pretty, but it works
|
||
|
try:
|
||
|
return tstr.encode('utf-8', "xmlcharrefreplace")
|
||
|
except UnicodeDecodeError:
|
||
|
# it's already UTF8.. sigh
|
||
|
return tstr.decode('utf-8').encode('utf-8')
|
||
|
|
||
|
def prints(tstr):
|
||
|
""" lovely unicode
|
||
|
"""
|
||
|
sys.stdout.write('%s\n' % (tstr.encode(sys.getdefaultencoding(),
|
||
|
'replace')))
|
||
|
sys.stdout.flush()
|
||
|
|
||
|
def mtime(ttime):
|
||
|
""" datetime auxiliar function.
|
||
|
"""
|
||
|
return datetime.datetime.fromtimestamp(time.mktime(ttime))
|