Skip to content

Commit

Permalink
Replace all references to StringIO/cStringIO to six.moves
Browse files Browse the repository at this point in the history
  • Loading branch information
ndevenish committed Aug 10, 2017
1 parent 9bb3c79 commit c793eb5
Show file tree
Hide file tree
Showing 27 changed files with 51 additions and 49 deletions.
6 changes: 3 additions & 3 deletions libtbx/command_line/easy_qsub.py
Expand Up @@ -17,14 +17,14 @@
import os
import re
import subprocess
import StringIO
import sys
import time
import stat

from libtbx import easy_run
from libtbx.utils import Sorry
from six.moves import range
from six.moves import StringIO

key_words = {
"phenix_source" : str,
Expand Down Expand Up @@ -275,7 +275,7 @@ def process_args(args):
def get_queue_machine_details():
cmd = "qstat -f"
ero = easy_run.fully_buffered(command = cmd)
out = StringIO.StringIO()
out = StringIO()
ero.show_stdout(out = out)
rc = {}
for line in out.getvalue().split("\n"):
Expand Down Expand Up @@ -525,7 +525,7 @@ def _cmp_gap(k1, k2):

# Run the command, and then find the job id in the output
ero = easy_run.fully_buffered(command = cmd)
out = StringIO.StringIO()
out = StringIO()
ero.show_stdout(out = out)
# Line looks like:
# "Your job-array 5436256.1-122:1 ("easy_qsub") has been submitted"
Expand Down
2 changes: 1 addition & 1 deletion libtbx/command_line/import_all_python.py
Expand Up @@ -4,7 +4,7 @@
import libtbx.load_env
from libtbx.utils import multi_out
from optparse import OptionParser
from cStringIO import StringIO
from six.moves import cStringIO as StringIO
import os.path as op
import os
import sys
Expand Down
2 changes: 1 addition & 1 deletion libtbx/command_line/parallel_simple.py
Expand Up @@ -64,7 +64,7 @@ def run_one_cmd(cmd_info):
join_stdout_stderr=True,
stdout_splitlines=False)
except: # intentional
from cStringIO import StringIO
from six.moves import cStringIO as StringIO
sio = StringIO()
show_traceback(file=sio)
buffers = None
Expand Down
6 changes: 3 additions & 3 deletions libtbx/command_line/py_compile_all.py
@@ -1,14 +1,14 @@
from __future__ import division
import compileall
import cStringIO
import sys, os
from six.moves import cStringIO as StringIO

def run():
dirs = sys.argv[1:]
if (len(dirs) == 0):
dirs = [os.getcwd()]
sys.stdout = cStringIO.StringIO()
sys.stderr = cStringIO.StringIO()
sys.stdout = StringIO()
sys.stderr = StringIO()
for dir in dirs:
compileall.compile_dir(dir, 100)

Expand Down
2 changes: 1 addition & 1 deletion libtbx/easy_mp.py
Expand Up @@ -4,11 +4,11 @@
from libtbx.str_utils import show_string
from libtbx.math_utils import ifloor
from libtbx import Auto
from cStringIO import StringIO
import traceback
import os
import sys
from six.moves import range
from six.moves import cStringIO as StringIO

_have_maxtasksperchild = (sys.version_info[:2] >= (2,7))

Expand Down
2 changes: 1 addition & 1 deletion libtbx/easy_run.py
Expand Up @@ -215,7 +215,7 @@ def call(command):
return subprocess.call(args=command, shell=True)

def exercise(args=None):
from cStringIO import StringIO
from six.moves import cStringIO as StringIO
import sys
if (args is None): args = sys.argv[1:]
verbose = "--verbose" in args
Expand Down
2 changes: 1 addition & 1 deletion libtbx/env_config.py
Expand Up @@ -14,7 +14,7 @@
import six.moves.cPickle as pickle
except ImportError:
import pickle
from cStringIO import StringIO
from six.moves import cStringIO as StringIO
import re
import site, sys, os
op = os.path
Expand Down
2 changes: 1 addition & 1 deletion libtbx/find_reference_cycles.py
@@ -1,7 +1,7 @@
from __future__ import division
from __future__ import print_function
from types import FrameType
from StringIO import StringIO
from six.moves import StringIO
import gc
import sys

Expand Down
2 changes: 1 addition & 1 deletion libtbx/introspection.py
Expand Up @@ -63,7 +63,7 @@ def print_trace(frame, event, arg):

def start_print_trace():
if ("pydoc" in sys.modules):
from cStringIO import StringIO
from six.moves import cStringIO as StringIO
s = StringIO()
show_stack(out=s)
for line in s.getvalue().splitlines():
Expand Down
2 changes: 1 addition & 1 deletion libtbx/phil/__init__.py
Expand Up @@ -7,7 +7,7 @@
from libtbx.utils import Sorry, format_exception, import_python_object
from itertools import count
from libtbx import Auto, slots_getstate_setstate
from cStringIO import StringIO
from six.moves import cStringIO as StringIO
import tokenize as python_tokenize
import warnings
import math
Expand Down
2 changes: 1 addition & 1 deletion libtbx/phil/tst.py
Expand Up @@ -9,7 +9,7 @@
from libtbx import easy_pickle
from libtbx import Auto
import warnings
from cStringIO import StringIO
from six.moves import cStringIO as StringIO
import copy
import sys, os
from six.moves import range
Expand Down
2 changes: 1 addition & 1 deletion libtbx/phil/tst_interface.py
Expand Up @@ -5,7 +5,7 @@
from libtbx.phil import interface
import libtbx.load_env
import libtbx.phil
from cStringIO import StringIO
from six.moves import cStringIO as StringIO
import sys

def exercise () :
Expand Down
5 changes: 3 additions & 2 deletions libtbx/runtime_utils.py
Expand Up @@ -17,7 +17,8 @@
from libtbx import adopt_init_args, group_args
import libtbx.load_env
import libtbx.phil
import cStringIO
from six.moves import cStringIO as StringIO

import traceback
import signal
import stat
Expand Down Expand Up @@ -488,7 +489,7 @@ def run (args) :
class simple_client (detached_process_client) :
def __init__ (self, *args, **kwds) :
self.n_cb = 0
self.out = cStringIO.StringIO()
self.out = StringIO()
detached_process_client.__init__(self, *args, **kwds)

def callback_error (self, error, traceback_info) :
Expand Down
6 changes: 3 additions & 3 deletions libtbx/server/SocketServer.py
Expand Up @@ -414,10 +414,10 @@ class DatagramRequestHandler(BaseRequestHandler):
"""Define self.rfile and self.wfile for datagram sockets."""

def setup(self):
import StringIO
from six.moves import StringIO
self.packet, self.socket = self.request
self.rfile = StringIO.StringIO(self.packet)
self.wfile = StringIO.StringIO(self.packet)
self.rfile = StringIO(self.packet)
self.wfile = StringIO(self.packet)

def finish(self):
self.socket.sendto(self.wfile.getvalue(), self.client_address)
2 changes: 1 addition & 1 deletion libtbx/smart_open.py
Expand Up @@ -3,7 +3,7 @@
from libtbx.utils import escape_sh_double_quoted, gzip_open, bz2_open
from libtbx import easy_run
from libtbx.str_utils import show_string
from cStringIO import StringIO
from six.moves import cStringIO as StringIO
import os

def for_reading(file_name, mode="r", gzip_mode="rb"):
Expand Down
2 changes: 1 addition & 1 deletion libtbx/sphinx/phil.py
Expand Up @@ -21,7 +21,7 @@ class PhilDirective(Directive):
'attributes-level': directives.nonnegative_int}

def run(self):
from cStringIO import StringIO
from six.moves import cStringIO as StringIO

phil_include = self.arguments[0]
expert_level = self.options.get('expert-level', None)
Expand Down
4 changes: 2 additions & 2 deletions libtbx/str_utils.py
@@ -1,7 +1,7 @@

from __future__ import division, absolute_import
from __future__ import print_function
import cStringIO
from six.moves import cStringIO
import sys
import six
from six.moves import zip
Expand Down Expand Up @@ -291,7 +291,7 @@ def next_non_empty(self):
# cStringIO with pickling support
class StringIO (object) :
def __init__ (self, *args, **kwds) :
self._buffer = cStringIO.StringIO(*args, **kwds)
self._buffer = cStringIO(*args, **kwds)

def __getattr__ (self, *args, **kwds) :
return getattr(self._buffer, *args, **kwds)
Expand Down
9 changes: 5 additions & 4 deletions libtbx/table_utils.py
Expand Up @@ -9,7 +9,8 @@
##
from __future__ import absolute_import
import libtbx.forward_compatibility # for sum
import cStringIO,operator
import operator
from six.moves import cStringIO as StringIO
from functools import reduce
from six.moves import map
from six.moves import range
Expand Down Expand Up @@ -62,7 +63,7 @@ def row_wrapper(row):
+ len(delim)*(len(max_widths)-1))
# select the appropriate justify method
justify = {'center':str.center, 'right':str.rjust, 'left':str.ljust}[justify.lower()]
output=cStringIO.StringIO()
output=StringIO()

total_row_width=0
line=None
Expand Down Expand Up @@ -316,7 +317,7 @@ def show(self,message,out,columns_to_print=['Limit','Population','MeanI']):
self.printTable(columns_to_print,printed_rows=to_print,out=out)
print(legend, file=out)

OC = cStringIO.StringIO()
OC = StringIO()
derived_1 = typical_use_case_1()
derived_1.show(message="Analysis of signals after noise suppression",out=OC)
assert "\n".join([i.rstrip() for i in OC.getvalue().split("\n")]) == \
Expand Down Expand Up @@ -358,7 +359,7 @@ def show(self,default=['Limit','Population','Fract','adjustPop'],out=None):
self.printTable(default,out=out)
#print >>out,"0"

OC = cStringIO.StringIO()
OC = StringIO()
derived_2 = typical_use_case_2()
derived_2.show(out=OC)

Expand Down
2 changes: 1 addition & 1 deletion libtbx/test_utils/__init__.py
Expand Up @@ -667,7 +667,7 @@ def run_command(
return cmd_result

def exercise():
from cStringIO import StringIO
from six.moves import cStringIO as StringIO
assert approx_equal(1, 1)
out = StringIO()
assert not approx_equal(1, 0, out=out)
Expand Down
2 changes: 1 addition & 1 deletion libtbx/test_utils/parallel.py
Expand Up @@ -8,7 +8,7 @@
from libtbx.utils import import_python_object, Sorry, multi_out
from libtbx import group_args, Auto
from multiprocessing import Pool, cpu_count
from cStringIO import StringIO
from six.moves import cStringIO as StringIO
import traceback
import time
import os
Expand Down
2 changes: 1 addition & 1 deletion libtbx/tst_easy_mp.py
Expand Up @@ -4,7 +4,7 @@
from libtbx import unpicklable
from libtbx.test_utils import Exception_expected
from libtbx import Auto
from cStringIO import StringIO
from six.moves import cStringIO as StringIO
import sys
from six.moves import range
from six.moves import zip
Expand Down
2 changes: 1 addition & 1 deletion libtbx/tst_path.py
Expand Up @@ -125,7 +125,7 @@ def exercise_move_old_create_new_directory():

def exercise_cleanup () :
from libtbx.path import clean_out_directory
from cStringIO import StringIO
from six.moves import cStringIO as StringIO
import shutil
import os
if os.path.isdir("tmp_libtbx_path_cleanup") :
Expand Down
15 changes: 8 additions & 7 deletions libtbx/tst_str_utils.py
Expand Up @@ -2,6 +2,8 @@
from __future__ import print_function
from __future__ import absolute_import
from six.moves import range
from six.moves import cStringIO as StringIO

def exercise():
from libtbx.test_utils import show_diff, Exception_expected
import six.moves.cPickle
Expand Down Expand Up @@ -61,8 +63,7 @@ def exercise():
^world """ % " "
#
from libtbx.str_utils import show_sorted_by_counts
import cStringIO
out = cStringIO.StringIO()
out = StringIO()
assert show_sorted_by_counts(
label_count_pairs=[("b", 3), ("a", 3), ("c", -2)],
out=out, prefix="%")
Expand All @@ -71,7 +72,7 @@ def exercise():
%"b" 3
%"c" -2
""")
out = cStringIO.StringIO()
out = StringIO()
assert show_sorted_by_counts(
label_count_pairs=[("b", -3), ("a", -3), ("c", 2)], reverse=False,
out=out, prefix="%", annotations=[None, "", "x"])
Expand All @@ -92,10 +93,10 @@ def exercise():
["this is", "a very", "long", "sentence", "indeed"])]:
assert [block for block in line_breaker(string, width=7)]==expected_result
#
from libtbx.str_utils import StringIO
out1 = cStringIO.StringIO()
out2 = StringIO()
out3 = StringIO("Hello world!\n")
from libtbx.str_utils import StringIO as pickleStringIO
out1 = StringIO()
out2 = pickleStringIO()
out3 = pickleStringIO("Hello world!\n")
print("Hello world!", file=out1)
print("Hello world!", file=out2)
try :
Expand Down
7 changes: 3 additions & 4 deletions libtbx/tst_thread_utils.py
Expand Up @@ -8,6 +8,7 @@
import time
import sys
from six.moves import range
from six.moves import cStringIO as StringIO

########################################################################
# THREADING ONLY
Expand Down Expand Up @@ -182,8 +183,7 @@ def _target_function04 (args, kwds, connection) :
return _tst_print(*args, **kwds)

def tst_stdout () :
import cStringIO
tmpout = cStringIO.StringIO()
tmpout = StringIO()
_tst_print(tmpout)

for buffer_stdout in [True, False] :
Expand Down Expand Up @@ -254,8 +254,7 @@ def tst_abort_2 () :

def _target_function08 (args, kwds, connection) :
import libtbx.callbacks # import dependency
import cStringIO
log = cStringIO.StringIO()
log = StringIO()
libtbx.call_back.set_warning_log(log)
time.sleep(1)
libtbx.warn("Hello, world!")
Expand Down
3 changes: 1 addition & 2 deletions libtbx/tst_utils.py
Expand Up @@ -3,14 +3,14 @@
from __future__ import absolute_import
from libtbx import utils
from libtbx.test_utils import Exception_expected, approx_equal, show_diff
from cStringIO import StringIO
import warnings
import random
import time
import os
import stat
import tempfile
from six.moves import range
from six.moves import cStringIO as StringIO

def exercise_forward_compatibility():
import itertools
Expand Down Expand Up @@ -349,7 +349,6 @@ def exercise_str_unicode():

def exercise_group_args():
from libtbx import group_args
from cStringIO import StringIO
out = StringIO()
a = group_args(
a=1,
Expand Down

0 comments on commit c793eb5

Please sign in to comment.