Skip to content

Commit 0069aa3

Browse files
committed
Merge pull request #930 from belevtsoff/master
unicode support for string type checks, fixes #929
2 parents a2f9c51 + 9c2a9b0 commit 0069aa3

File tree

23 files changed

+835
-50
lines changed

23 files changed

+835
-50
lines changed

doc/sphinxext/numpy_ext/docscrape_sphinx.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import re, inspect, textwrap, pydoc
22
import sphinx
33
from docscrape import NumpyDocString, FunctionDoc, ClassDoc
4+
from nipype.external import six
45

56
class SphinxDocString(NumpyDocString):
67
def __init__(self, docstring, config={}):
@@ -140,7 +141,7 @@ def _str_references(self):
140141
out = []
141142
if self['References']:
142143
out += self._str_header('References')
143-
if isinstance(self['References'], str):
144+
if isinstance(self['References'], six.string_types):
144145
self['References'] = [self['References']]
145146
out.extend(self['References'])
146147
out += ['']

examples/fmri_ants_openfmri.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
from nipype import config
1616
config.enable_provenance()
17+
from nipype.external import six
18+
1719

1820
from glob import glob
1921
import os
@@ -443,7 +445,7 @@ def get_contrasts(contrast_file, task_id, conds):
443445

444446
def check_behav_list(behav):
445447
out_behav = []
446-
if isinstance(behav, basestring):
448+
if isinstance(behav, six.string_types):
447449
behav = [behav]
448450
for val in behav:
449451
if not isinstance(val, list):

examples/fmri_openfmri.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from nipype import config
1616
config.enable_provenance()
17+
from nipype.external import six
1718

1819
from glob import glob
1920
import os
@@ -237,7 +238,7 @@ def get_contrasts(contrast_file, task_id, conds):
237238

238239
def check_behav_list(behav):
239240
out_behav = []
240-
if isinstance(behav, basestring):
241+
if isinstance(behav, six.string_types):
241242
behav = [behav]
242243
for val in behav:
243244
if not isinstance(val, list):

nipype/algorithms/modelgen.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
isdefined)
3131
from nipype.utils.filemanip import filename_to_list
3232
from .. import config, logging
33+
from nipype.external import six
3334
iflogger = logging.getLogger('interface')
3435

3536
def gcd(a, b):
@@ -422,7 +423,7 @@ def _concatenate_info(self, infolist):
422423
for i, f in enumerate(self.inputs.functional_runs):
423424
if isinstance(f, list):
424425
numscans = len(f)
425-
elif isinstance(f, str):
426+
elif isinstance(f, six.string_types):
426427
img = load(f)
427428
numscans = img.get_shape()[3]
428429
else:

nipype/algorithms/rapidart.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import numpy as np
2727
from scipy import signal
2828
import scipy.io as sio
29+
from nipype.external import six
2930

3031
from ..interfaces.base import (BaseInterface, traits, InputMultiPath,
3132
OutputMultiPath, TraitedSpec, File,
@@ -279,7 +280,7 @@ def _get_output_filenames(self, motionfile, output_dir):
279280
output_dir: string
280281
output directory in which the files will be generated
281282
"""
282-
if isinstance(motionfile, str):
283+
if isinstance(motionfile, six.string_types):
283284
infile = motionfile
284285
elif isinstance(motionfile, list):
285286
infile = motionfile[0]
@@ -350,7 +351,7 @@ def _detect_outliers_core(self, imgfile, motionfile, runidx, cwd=None):
350351
cwd = os.getcwd()
351352

352353
# read in functional image
353-
if isinstance(imgfile, str):
354+
if isinstance(imgfile, six.string_types):
354355
nim = load(imgfile)
355356
elif isinstance(imgfile, list):
356357
if len(imgfile) == 1:

nipype/external/provcopy.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import dateutil.parser
1818
import collections
1919
from collections import defaultdict
20+
import six
2021

2122
try:
2223
from rdflib.term import URIRef, BNode
@@ -187,7 +188,7 @@ def _parse_xsd_dateTime(s):
187188

188189

189190
def _ensure_datetime(time):
190-
if isinstance(time, basestring):
191+
if isinstance(time, six.string_types):
191192
return _parse_xsd_dateTime(time)
192193
else:
193194
return time
@@ -232,12 +233,12 @@ def parse_xsd_types(value, datatype):
232233

233234

234235
def _ensure_multiline_string_triple_quoted(s):
235-
format_str = u'"""%s"""' if isinstance(s, basestring) and '\n' in s else u'"%s"'
236+
format_str = u'"""%s"""' if isinstance(s, six.string_types) and '\n' in s else u'"%s"'
236237
return format_str % s
237238

238239

239240
def encoding_PROV_N_value(value):
240-
if isinstance(value, basestring):
241+
if isinstance(value, six.string_types):
241242
return _ensure_multiline_string_triple_quoted(value)
242243
elif isinstance(value, datetime.datetime):
243244
return value.isoformat()
@@ -536,7 +537,7 @@ def _auto_literal_conversion(self, literal):
536537
if isinstance(literal, URIRef):
537538
return literal
538539

539-
if isinstance(literal, basestring):
540+
if isinstance(literal, six.string_types):
540541
return unicode(literal)
541542

542543
if isinstance(literal, Literal) and literal.has_no_langtag():
@@ -1568,7 +1569,7 @@ def _decode_JSON_container(self, jc):
15681569
key=lambda tuple_rec: tuple_rec[0])
15691570

15701571
record_map = {}
1571-
_parse_attr_value = lambda value: record_map[value] if (isinstance(value, basestring) and value in record_map) else self._decode_json_representation(value)
1572+
_parse_attr_value = lambda value: record_map[value] if (isinstance(value, six.string_types) and value in record_map) else self._decode_json_representation(value)
15721573
# Create all the records before setting their attributes
15731574
for (record_type, identifier, content) in records:
15741575
if record_type == PROV_REC_BUNDLE:

0 commit comments

Comments
 (0)