Skip to content

Commit

Permalink
fix and refactor lib.debug
Browse files Browse the repository at this point in the history
  • Loading branch information
tokland committed Jan 14, 2016
1 parent bff97e5 commit 514319c
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions youtube_upload/lib.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import os
import sys
import locale
Expand Down Expand Up @@ -27,18 +28,7 @@ def to_utf8(s):

def debug(obj, fd=sys.stderr):
"""Write obj to standard error."""
try:
unicode
should_encode = not isinstance(obj, unicode)
except NameError:
should_encode = False #Doing so is harmless in Python 3
string = str(obj.encode(get_encoding(fd), "backslashreplace")
if should_encode else obj)
#Python 3 handling workaround
if sys.version_info >= (3, 0) and isinstance(string, bytes):
fd.buffer.write(string + "\n") #We write the encoding directly
else:
fd.write(string + "\n")
print(obj, file=fd)

def catch_exceptions(exit_codes, fun, *args, **kwargs):
"""
Expand Down

0 comments on commit 514319c

Please sign in to comment.