unicode correctness + bugfix images reverse

This commit is contained in:
Johann Dreo 2016-07-29 15:59:30 +02:00
commit 913e0b552e

View file

@ -19,7 +19,7 @@ def write(data, stream = sys.stdout):
Write "data" on the given stream, then flush, silently handling broken pipes. Write "data" on the given stream, then flush, silently handling broken pipes.
""" """
try: try:
stream.write(data) stream.write(data.encode(locale.getpreferredencoding(True) or "utf-8"))
stream.flush() stream.flush()
# Silently handle broken pipes # Silently handle broken pipes
@ -52,10 +52,10 @@ def setup_counter( data, asked ):
data = list(data) data = list(data)
nb = len(data) nb = len(data)
# " int/int" # " int/int"
counter_size = len(str(nb))*2 + 1 + 1 counter_size = len(str(nb).encode("utf-8").decode("utf-8") )*2 + 1 + 1
for i,line in enumerate(data): for i,line in enumerate(data):
counter = " %i/%i" % (i+1,nb) counter = u" %i/%i" % (i+1,nb)
curmax = asked.max_len - len(counter) curmax = asked.max_len - len(counter)
if len(line) > curmax: if len(line) > curmax:
if asked.ignore: if asked.ignore:
@ -109,7 +109,8 @@ def on_stdout( data, asked, endline="\n" ):
if asked.independent: if asked.independent:
yield line yield line
else: else:
yield i + " " + line l = u"%i %s" % (i,line)
yield l
# #
@ -122,7 +123,8 @@ def on_twitter( data, api, asked, endline="\n" ):
prev_status_id = None prev_status_id = None
images = asked.twitter_images images = asked.twitter_images
images.reverse() if images:
images.reverse()
for line in lines: for line in lines:
if images: if images:
@ -248,7 +250,6 @@ if __name__=="__main__":
asked = parser.parse_args() asked = parser.parse_args()
# Setup # Setup
if asked.setup: if asked.setup:
configfile = asked.api+".conf" configfile = asked.api+".conf"