Permalink
Browse files

python: better check and to str convertion

  • Loading branch information...
1 parent 5c77a8d commit 395f63d7a2384c7dc10ba5e28c761936b8e2419a @timurhai timurhai committed Jun 27, 2012
Showing with 16 additions and 7 deletions.
  1. +7 −6 afanasy/python/afpathmap.py
  2. +8 −0 lib/python/cgruutils.py
  3. +1 −1 utilities/moviemaker/dialog.py
@@ -5,6 +5,8 @@
import afenv
+import cgruutils
+
#PathSeparators = ' ";=,\''
PathSeparators = ' ";=,\':'
#if sys.platform.find('win') != 0: PathSeparators += ':'
@@ -61,11 +63,11 @@ def findPathMapFiles( folder):
PathMapFile = 'pathmap'
pathmap_files = []
if folder is not None:
- if not isinstance( folder, str): folder = str( folder,'utf-8')
+ folder = cgruutils.toStr( folder)
if os.path.isdir( folder):
files = os.listdir( folder)
for afile in files:
- if not isinstance( afile, str): folder = str( afile,'utf-8')
+ afile = cgruutils.toStr( afile)
if afile.find( PathMapFile) != 0: continue
filename = os.path.join( folder, afile)
if not os.path.isfile( filename): continue
@@ -91,7 +93,7 @@ def __init__( self, UnixSeparators = False, Verbose = False):
file = open( filename, 'r')
for line in file:
- if not isinstance( line, str): line = str( line,'utf-8')
+ if not isinstance( line, str): line = cgruutils.toStr( line)
line = line.strip()
linelen = len(line)
if linelen <= 3: continue
@@ -124,8 +126,7 @@ def __init__( self, UnixSeparators = False, Verbose = False):
def translatePath( self, path, toserver, Verbose):
- newpath = path
- if not isinstance( newpath, str): newpath = str( newpath,'utf-8')
+ newpath = cgruutils.toStr( path)
if len(newpath) < 1: return newpath
if not self.initialized: return newpath
position = 0
@@ -196,7 +197,7 @@ def translateFile( self, infile, outfile, toserver, SearchStrings, Verbose):
filein.close()
outdata = ''
for line in inlines:
- if not isinstance( line, str): line = str( line,'utf-8')
+ if not isinstance( line, str): line = cgruutils.toStr( line)
toskip = False
if len( SearchStrings): toskip = True
for searchstr in SearchStrings:
@@ -165,3 +165,11 @@ def copyJobFile( fileName, jobName = '', fileExtension = ''):
copyFile = ''
return copyFile
+def toStr( data):
+ if isinstance( data, str):
+ return data
+
+ if sys.version_info[0] < 3:
+ return str( data)
+
+ return str( data, 'utf-8')
@@ -1641,7 +1641,7 @@ def evaluate( self):
def execute( self):
if not self.evaluated: return
- command = "%s" % self.cmdField.toPlainText()
+ command = '%s' % self.cmdField.toPlainText()
if len(command) == 0: return
afanasy = False

0 comments on commit 395f63d

Please sign in to comment.