mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-09 11:14:02 +02:00
py3: Replace use of StringIO
This commit is contained in:
parent
e072941c88
commit
a754bf46f1
2 changed files with 14 additions and 12 deletions
|
|
@ -7,14 +7,15 @@
|
|||
For usage information run the script.
|
||||
"""
|
||||
|
||||
import StringIO, sys, time, os
|
||||
import sys, time, os
|
||||
from optparse import OptionParser
|
||||
|
||||
from calibre import __version__, __appname__, human_readable, fsync
|
||||
from calibre import __version__, __appname__, human_readable, fsync, prints
|
||||
from calibre.devices.errors import ArgumentError, DeviceError, DeviceLocked
|
||||
from calibre.customize.ui import device_plugins
|
||||
from calibre.devices.scanner import DeviceScanner
|
||||
from calibre.utils.config import device_prefs
|
||||
from polyglot.io import PolyglotBytesIO
|
||||
|
||||
MINIMUM_COL_WIDTH = 12 # : Minimum width of columns in ls output
|
||||
|
||||
|
|
@ -127,13 +128,13 @@ def row_widths(table): # Calculate widths for each column in the row-wise table
|
|||
c += 1
|
||||
return rowwidths
|
||||
|
||||
output = StringIO.StringIO()
|
||||
output = PolyglotBytesIO()
|
||||
if path.endswith("/") and len(path) > 1:
|
||||
path = path[:-1]
|
||||
dirs = dev.list(path, recurse)
|
||||
for dir in dirs:
|
||||
if recurse:
|
||||
print(dir[0] + ":", file=output)
|
||||
prints(dir[0] + ":", file=output)
|
||||
lsoutput, lscoloutput = [], []
|
||||
files = dir[1]
|
||||
maxlen = 0
|
||||
|
|
@ -154,7 +155,7 @@ def row_widths(table): # Calculate widths for each column in the row-wise table
|
|||
size = str(file.size)
|
||||
if human_readable_size:
|
||||
size = file.human_readable_size
|
||||
print(file.mode_string, ("%"+str(maxlen)+"s")%size, file.modification_time, name, file=output)
|
||||
prints(file.mode_string, ("%"+str(maxlen)+"s")%size, file.modification_time, name, file=output)
|
||||
if not ll and len(lsoutput) > 0:
|
||||
trytable = []
|
||||
for colwidth in range(MINIMUM_COL_WIDTH, cols):
|
||||
|
|
@ -176,10 +177,10 @@ def row_widths(table): # Calculate widths for each column in the row-wise table
|
|||
for r in range(len(trytable)):
|
||||
for c in range(len(trytable[r])):
|
||||
padding = rowwidths[c] - len(trytable[r][c])
|
||||
print(trytablecol[r][c], "".ljust(padding), end=' ', file=output)
|
||||
print(file=output)
|
||||
print(file=output)
|
||||
listing = output.getvalue().rstrip()+ "\n"
|
||||
prints(trytablecol[r][c], "".ljust(padding), end=' ', file=output)
|
||||
prints(file=output)
|
||||
prints(file=output)
|
||||
listing = output.getvalue().rstrip().decode('utf-8') + "\n"
|
||||
output.close()
|
||||
return listing
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
import os
|
||||
import re
|
||||
import StringIO
|
||||
import io
|
||||
from copy import deepcopy
|
||||
|
||||
from calibre import my_unichr, prepare_string_for_xml
|
||||
|
|
@ -558,8 +558,9 @@ def parse_pml(self, pml, file_name=''):
|
|||
else:
|
||||
indent_state['et'] = False
|
||||
|
||||
# Must use StringIO, cStringIO does not support unicode
|
||||
line = StringIO.StringIO(line)
|
||||
if isinstance(line, bytes):
|
||||
line = line.decode('utf-8')
|
||||
line = io.StringIO(line)
|
||||
parsed.append(self.start_line())
|
||||
|
||||
c = line.read(1)
|
||||
|
|
|
|||
Loading…
Reference in a new issue