@@ -533,9 +533,9 @@ def print_fs(fs,
533533 """
534534
535535 if file_out is None :
536- file_out = sys .stdout . buffer if PY3 else sys . stdout
536+ file_out = sys .stdout
537537
538- file_encoding = getattr (file_out , 'encoding' , 'utf-8' ) or 'utf-8'
538+ file_encoding = getattr (file_out , 'encoding' , u 'utf-8' ) or u 'utf-8'
539539 file_encoding = file_encoding .upper ()
540540
541541 if terminal_colors is None :
@@ -545,28 +545,31 @@ def print_fs(fs,
545545 terminal_colors = hasattr (file_out , 'isatty' ) and file_out .isatty ()
546546
547547 def write (line ):
548- file_out .write (line .encode (file_encoding , 'replace' ) + b'\n ' )
548+ if PY3 :
549+ file_out .write ((line + u'\n ' ))
550+ else :
551+ file_out .write ((line + u'\n ' ).encode (file_encoding , 'replace' ))
549552
550553 def wrap_prefix (prefix ):
551554 if not terminal_colors :
552555 return prefix
553- return '\x1b [32m%s\x1b [0m' % prefix
556+ return u '\x1b [32m%s\x1b [0m' % prefix
554557
555558 def wrap_dirname (dirname ):
556559 if not terminal_colors :
557560 return dirname
558- return '\x1b [1;34m%s\x1b [0m' % dirname
561+ return u '\x1b [1;34m%s\x1b [0m' % dirname
559562
560563 def wrap_error (msg ):
561564 if not terminal_colors :
562565 return msg
563- return '\x1b [31m%s\x1b [0m' % msg
566+ return u '\x1b [31m%s\x1b [0m' % msg
564567
565568 def wrap_filename (fname ):
566569 if not terminal_colors :
567570 return fname
568- if fname .startswith ('.' ):
569- fname = '\x1b [33m%s\x1b [0m' % fname
571+ if fname .startswith (u '.' ):
572+ fname = u '\x1b [33m%s\x1b [0m' % fname
570573 return fname
571574 dircount = [0 ]
572575 filecount = [0 ]
@@ -577,10 +580,10 @@ def print_dir(fs, path, levels=[]):
577580 char_line = u'──'
578581 char_corner = u'╰'
579582 else :
580- char_vertline = '|'
581- char_newnode = '|'
582- char_line = '--'
583- char_corner = '`'
583+ char_vertline = u '|'
584+ char_newnode = u '|'
585+ char_line = u '--'
586+ char_corner = u '`'
584587
585588 try :
586589 dirs = fs .listdir (path , dirs_only = True )
@@ -592,7 +595,7 @@ def print_dir(fs, path, levels=[]):
592595 [(False , p ) for p in files ] )
593596 except Exception , e :
594597 prefix = '' .join ([(char_vertline + ' ' , ' ' )[last ] for last in levels ]) + ' '
595- write (wrap_prefix (prefix [:- 1 ] + ' ' ) + wrap_error ("unable to retrieve directory list (%s) ..." % str (e )))
598+ write (wrap_prefix (prefix [:- 1 ] + ' ' ) + wrap_error (u "unable to retrieve directory list (%s) ..." % str (e )))
596599 return 0
597600
598601 if hide_dotfiles :
0 commit comments