Skip to content

unicode support for string type checks, fixes #929 #930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 30, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/sphinxext/numpy_ext/docscrape_sphinx.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re, inspect, textwrap, pydoc
import sphinx
from docscrape import NumpyDocString, FunctionDoc, ClassDoc
from nipype.external import six

class SphinxDocString(NumpyDocString):
def __init__(self, docstring, config={}):
Expand Down Expand Up @@ -140,7 +141,7 @@ def _str_references(self):
out = []
if self['References']:
out += self._str_header('References')
if isinstance(self['References'], str):
if isinstance(self['References'], six.string_types):
self['References'] = [self['References']]
out.extend(self['References'])
out += ['']
Expand Down
4 changes: 3 additions & 1 deletion examples/fmri_ants_openfmri.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

from nipype import config
config.enable_provenance()
from nipype.external import six


from glob import glob
import os
Expand Down Expand Up @@ -443,7 +445,7 @@ def get_contrasts(contrast_file, task_id, conds):

def check_behav_list(behav):
out_behav = []
if isinstance(behav, basestring):
if isinstance(behav, six.string_types):
behav = [behav]
for val in behav:
if not isinstance(val, list):
Expand Down
3 changes: 2 additions & 1 deletion examples/fmri_openfmri.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from nipype import config
config.enable_provenance()
from nipype.external import six

from glob import glob
import os
Expand Down Expand Up @@ -237,7 +238,7 @@ def get_contrasts(contrast_file, task_id, conds):

def check_behav_list(behav):
out_behav = []
if isinstance(behav, basestring):
if isinstance(behav, six.string_types):
behav = [behav]
for val in behav:
if not isinstance(val, list):
Expand Down
3 changes: 2 additions & 1 deletion nipype/algorithms/modelgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
isdefined)
from nipype.utils.filemanip import filename_to_list
from .. import config, logging
from nipype.external import six
iflogger = logging.getLogger('interface')

def gcd(a, b):
Expand Down Expand Up @@ -422,7 +423,7 @@ def _concatenate_info(self, infolist):
for i, f in enumerate(self.inputs.functional_runs):
if isinstance(f, list):
numscans = len(f)
elif isinstance(f, str):
elif isinstance(f, six.string_types):
img = load(f)
numscans = img.get_shape()[3]
else:
Expand Down
5 changes: 3 additions & 2 deletions nipype/algorithms/rapidart.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import numpy as np
from scipy import signal
import scipy.io as sio
from nipype.external import six

from ..interfaces.base import (BaseInterface, traits, InputMultiPath,
OutputMultiPath, TraitedSpec, File,
Expand Down Expand Up @@ -279,7 +280,7 @@ def _get_output_filenames(self, motionfile, output_dir):
output_dir: string
output directory in which the files will be generated
"""
if isinstance(motionfile, str):
if isinstance(motionfile, six.string_types):
infile = motionfile
elif isinstance(motionfile, list):
infile = motionfile[0]
Expand Down Expand Up @@ -350,7 +351,7 @@ def _detect_outliers_core(self, imgfile, motionfile, runidx, cwd=None):
cwd = os.getcwd()

# read in functional image
if isinstance(imgfile, str):
if isinstance(imgfile, six.string_types):
nim = load(imgfile)
elif isinstance(imgfile, list):
if len(imgfile) == 1:
Expand Down
11 changes: 6 additions & 5 deletions nipype/external/provcopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import dateutil.parser
import collections
from collections import defaultdict
import six

try:
from rdflib.term import URIRef, BNode
Expand Down Expand Up @@ -187,7 +188,7 @@ def _parse_xsd_dateTime(s):


def _ensure_datetime(time):
if isinstance(time, basestring):
if isinstance(time, six.string_types):
return _parse_xsd_dateTime(time)
else:
return time
Expand Down Expand Up @@ -232,12 +233,12 @@ def parse_xsd_types(value, datatype):


def _ensure_multiline_string_triple_quoted(s):
format_str = u'"""%s"""' if isinstance(s, basestring) and '\n' in s else u'"%s"'
format_str = u'"""%s"""' if isinstance(s, six.string_types) and '\n' in s else u'"%s"'
return format_str % s


def encoding_PROV_N_value(value):
if isinstance(value, basestring):
if isinstance(value, six.string_types):
return _ensure_multiline_string_triple_quoted(value)
elif isinstance(value, datetime.datetime):
return value.isoformat()
Expand Down Expand Up @@ -536,7 +537,7 @@ def _auto_literal_conversion(self, literal):
if isinstance(literal, URIRef):
return literal

if isinstance(literal, basestring):
if isinstance(literal, six.string_types):
return unicode(literal)

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

record_map = {}
_parse_attr_value = lambda value: record_map[value] if (isinstance(value, basestring) and value in record_map) else self._decode_json_representation(value)
_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)
# Create all the records before setting their attributes
for (record_type, identifier, content) in records:
if record_type == PROV_REC_BUNDLE:
Expand Down
Loading