Author: bugman Date: Thu Sep 3 15:24:48 2009 New Revision: 9455 URL: http://svn.gna.org/viewcvs/relax?rev=9455&view=rev Log: More updates for Python3k. The command used was: 2to3 -w \ -f buffer \ -f idioms \ -f set_literal \ -f ws_comma \ -x except \ -x import \ -x imports \ -x long \ -x numliterals \ -x xrange \ relax . This is from the docs/2to3_checklist document. Modified: branches/bmrb/bmrblib/base_classes.py branches/bmrb/bmrblib/misc.py branches/bmrb/prompt/bmrb.py branches/bmrb/pystarlib/File.py branches/bmrb/pystarlib/FileTest.py branches/bmrb/pystarlib/TagTable.py branches/bmrb/pystarlib/TagTableTest.py branches/bmrb/pystarlib/Text.py branches/bmrb/pystarlib/TextTest.py branches/bmrb/pystarlib/Utils.py branches/bmrb/pystarlib/UtilsTest.py Modified: branches/bmrb/bmrblib/base_classes.py URL: http://svn.gna.org/viewcvs/relax/branches/bmrb/bmrblib/base_classes.py?rev=9455&r1=9454&r2=9455&view=diff ============================================================================== --- branches/bmrb/bmrblib/base_classes.py (original) +++ branches/bmrb/bmrblib/base_classes.py Thu Sep 3 15:24:48 2009 @@ -39,7 +39,7 @@ """ # The data ID values. - self.data_ids = translate(range(1,N+1)) + self.data_ids = translate(range(1, N+1)) Modified: branches/bmrb/bmrblib/misc.py URL: http://svn.gna.org/viewcvs/relax/branches/bmrb/bmrblib/misc.py?rev=9455&r1=9454&r2=9455&view=diff ============================================================================== --- branches/bmrb/bmrblib/misc.py (original) +++ branches/bmrb/bmrblib/misc.py Thu Sep 3 15:24:48 2009 @@ -37,7 +37,7 @@ missing = False # List data. - if type(data) == list: + if isinstance(data, list): # Loop over the data. for i in range(len(data)): if data[i] == None or data[i] == 'None': @@ -60,7 +60,7 @@ """ # List data. - if type(data) == list: + if isinstance(data, list): # Loop over the data. new_data = [] for i in range(len(data)): Modified: branches/bmrb/prompt/bmrb.py URL: http://svn.gna.org/viewcvs/relax/branches/bmrb/prompt/bmrb.py?rev=9455&r1=9454&r2=9455&view=diff ============================================================================== --- branches/bmrb/prompt/bmrb.py (original) +++ branches/bmrb/prompt/bmrb.py Thu Sep 3 15:24:48 2009 @@ -80,11 +80,11 @@ print(text) # File. - if type(file) != str: + if not isinstance(file, str): raise RelaxStrError('file name', file) # Directory. - if dir != None and type(dir) != str: + if dir != None and not isinstance(dir, str): raise RelaxNoneStrError('directory name', dir) # Execute the functional code. @@ -122,15 +122,15 @@ print(text) # File. - if type(file) != str and not hasattr(file, 'write'): + if not isinstance(file, str) and not hasattr(file, 'write'): raise RelaxStrFileError('file name', file) # Directory. - if dir != None and type(dir) != str: + if dir != None and not isinstance(dir, str): raise RelaxNoneStrError('directory name', dir) # The force flag. - if type(force) != bool: + if not isinstance(force, bool): raise RelaxBoolError('force flag', force) # Execute the functional code. Modified: branches/bmrb/pystarlib/File.py URL: http://svn.gna.org/viewcvs/relax/branches/bmrb/pystarlib/File.py?rev=9455&r1=9454&r2=9455&view=diff ============================================================================== --- branches/bmrb/pystarlib/File.py (original) +++ branches/bmrb/pystarlib/File.py Thu Sep 3 15:24:48 2009 @@ -172,12 +172,12 @@ print('Items looked for are a begin or end of a saveframe, or') print('a begin of a tagtable(free or looped).') print() - print("At text (before pos=" , pos , "):") + print("At text (before pos=", pos, "):") start = pos-70 if start < 0: start = 0 print("[" + text[start:pos] + "]") - print("At text (starting pos=" , pos , "):") + print("At text (starting pos=", pos, "):") print("[" + text[pos:pos+70]+ "]") return None Modified: branches/bmrb/pystarlib/FileTest.py URL: http://svn.gna.org/viewcvs/relax/branches/bmrb/pystarlib/FileTest.py?rev=9455&r1=9454&r2=9455&view=diff ============================================================================== --- branches/bmrb/pystarlib/FileTest.py (original) +++ branches/bmrb/pystarlib/FileTest.py Thu Sep 3 15:24:48 2009 @@ -56,7 +56,7 @@ ; BOGUS_CATEGORY stop_ save_ """ - self.assertTrue(Utils.equalIgnoringWhiteSpace(exp,st)) + self.assertTrue(Utils.equalIgnoringWhiteSpace(exp, st)) def testread2(self): """STAR File read""" @@ -77,7 +77,7 @@ "&program=STAR&request_type=archive&subtype=full&type=entry") % (stage, stage, entry) fnamezip = entry+".zip" # print "DEBUG: downloading url:", urlLocation - urllib.request.urlretrieve(urlLocation,fnamezip) + urllib.request.urlretrieve(urlLocation, fnamezip) # print "DEBUG: opening local zip file:", fnamezip zfobj = zipfile.ZipFile(fnamezip) fname = None @@ -122,12 +122,12 @@ cmd = "diff --ignore-all-space --ignore-blank-lines %s %s > %s" % ( pystarlibWrittenFile, wattosWrittenFile, diffPystarWattosFile) os.system(cmd) if not os.path.exists(diffPystarWattosFile): - print("WARNING: failed to diff file: ",pystarlibWrittenFile, wattosWrittenFile) + print("WARNING: failed to diff file: ", pystarlibWrittenFile, wattosWrittenFile) # print "Most likely the below diff will fail because it depends on diff being installed" cmd = "diff --ignore-all-space --ignore-blank-lines %s %s > %s" % ( orgWattosWrittenFile, wattosWrittenFile, diffOrgWattosWattosFile) os.system(cmd) if not os.path.exists(diffOrgWattosWattosFile): - print("WARNING: failed to diff file: ",orgWattosWrittenFile, wattosWrittenFile) + print("WARNING: failed to diff file: ", orgWattosWrittenFile, wattosWrittenFile) except: # print "DEBUG: failed the rewrite or diff but as mentioned that's totally understandable." pass Modified: branches/bmrb/pystarlib/TagTable.py URL: http://svn.gna.org/viewcvs/relax/branches/bmrb/pystarlib/TagTable.py?rev=9455&r1=9454&r2=9455&view=diff ============================================================================== --- branches/bmrb/pystarlib/TagTable.py (original) +++ branches/bmrb/pystarlib/TagTable.py Thu Sep 3 15:24:48 2009 @@ -413,7 +413,7 @@ if (c == "'" or c == '"') and bc != " ": # JFD the next line takes an expensive slice of the pie? # tempendpos = idxstart + string.find(text[idxstart:],' ') - tempendpos = string.find(text,' ',idxstart) + tempendpos = string.find(text, ' ', idxstart) else: tempendpos = idxstart @@ -458,8 +458,8 @@ % ( col_length, tag_id )) print("Tag names of this table are:") print(self.tagnames) - for xxx in range(0,len(self.tagvalues[0])): - for yyy in range(0,len(self.tagvalues)): + for xxx in range(0, len(self.tagvalues[0])): + for yyy in range(0, len(self.tagvalues)): print(self.tagvalues[yyy][xxx]) print('-----------------------------------------------') pos = 0 Modified: branches/bmrb/pystarlib/TagTableTest.py URL: http://svn.gna.org/viewcvs/relax/branches/bmrb/pystarlib/TagTableTest.py?rev=9455&r1=9454&r2=9455&view=diff ============================================================================== --- branches/bmrb/pystarlib/TagTableTest.py (original) +++ branches/bmrb/pystarlib/TagTableTest.py Thu Sep 3 15:24:48 2009 @@ -17,7 +17,7 @@ tagvalues = [], verbosity = __init__.verbosity) pos = tt.parse( text = text, pos = 0) - self.assertEqual(pos,len(text)) + self.assertEqual(pos, len(text)) tt.tagvalues[0][0] = "A" tt.tagvalues[0][1] = "B\nC\n" @@ -51,7 +51,7 @@ """ # print exp # print tt.star_text() - self.assertEqual(exp,tt.star_text()) + self.assertEqual(exp, tt.star_text()) if __name__ == "__main__": Modified: branches/bmrb/pystarlib/Text.py URL: http://svn.gna.org/viewcvs/relax/branches/bmrb/pystarlib/Text.py?rev=9455&r1=9454&r2=9455&view=diff ============================================================================== --- branches/bmrb/pystarlib/Text.py (original) +++ branches/bmrb/pystarlib/Text.py Thu Sep 3 15:24:48 2009 @@ -172,7 +172,7 @@ """ def pattern_unquoted_find(text, pattern, pos=0): - while 1: + while True: match = pattern.search( text, pos) if not match: ## No match at all @@ -363,7 +363,7 @@ print("ERROR in semicolon_block_collapse for text starting at: ["+ text[startpos:startpos+100]+ "]") raise - text_replace = re.sub("\n", eol_string,text[startpos:endpos]) + text_replace = re.sub("\n", eol_string, text[startpos:endpos]) # This is bulky and not very elegant but works text= text[0:startpos] + text_replace + text[endpos:] @@ -442,7 +442,7 @@ """ def semicolons_add( text, possible_bad_char=None ): if possible_bad_char: - lines = string.split(text,'\n') + lines = string.split(text, '\n') text = '' for line in lines: text = text + prepending_string + line + '\n' @@ -493,7 +493,7 @@ if __init__.verbosity >= 9: print('Done [%s] comment subs' % count) - text = string.join(lines,"\n") + text = string.join(lines, "\n") return text """ Modified: branches/bmrb/pystarlib/TextTest.py URL: http://svn.gna.org/viewcvs/relax/branches/bmrb/pystarlib/TextTest.py?rev=9455&r1=9454&r2=9455&view=diff ============================================================================== --- branches/bmrb/pystarlib/TextTest.py (original) +++ branches/bmrb/pystarlib/TextTest.py Thu Sep 3 15:24:48 2009 @@ -26,7 +26,7 @@ t2noComment = """ """ - self.assertEqual(t2noComment,comments_strip( t2 )) + self.assertEqual(t2noComment, comments_strip( t2 )) def testcomments_strip(self): """comments_strip""" Modified: branches/bmrb/pystarlib/Utils.py URL: http://svn.gna.org/viewcvs/relax/branches/bmrb/pystarlib/Utils.py?rev=9455&r1=9454&r2=9455&view=diff ============================================================================== --- branches/bmrb/pystarlib/Utils.py (original) +++ branches/bmrb/pystarlib/Utils.py Thu Sep 3 15:24:48 2009 @@ -36,8 +36,7 @@ def attrnames(self): result='' - keys = list(self.__dict__.keys()) - keys.sort() + keys = sorted(self.__dict__.keys()) for attr in keys: if attr[:2] == "__": result = result + "\tname %s=<built-in>\n" % attr @@ -71,15 +70,15 @@ """ def equalIgnoringWhiteSpace( a, b): pattern = re.compile("\s+" ) - a = re.sub(pattern, ' ',a) - b = re.sub(pattern, ' ',b) + a = re.sub(pattern, ' ', a) + b = re.sub(pattern, ' ', b) # print "a["+a+"]" # print "b["+b+"]" return a == b def dos2unix(text): - return re.sub('\r\n', '\n',text) + return re.sub('\r\n', '\n', text) def unix2dos(text): - return re.sub('([^\r])(\n)', '\1\r\n',text) + return re.sub('([^\r])(\n)', '\1\r\n', text) def mac2unix(text): - return re.sub('\r', '\n',text) + return re.sub('\r', '\n', text) Modified: branches/bmrb/pystarlib/UtilsTest.py URL: http://svn.gna.org/viewcvs/relax/branches/bmrb/pystarlib/UtilsTest.py?rev=9455&r1=9454&r2=9455&view=diff ============================================================================== --- branches/bmrb/pystarlib/UtilsTest.py (original) +++ branches/bmrb/pystarlib/UtilsTest.py Thu Sep 3 15:24:48 2009 @@ -1,12 +1,12 @@ from unittest import TestCase -import Utils,unittest +import Utils, unittest class AllChecks(TestCase): def test(self): """STAR Utils""" - m1 = [ [1,2], [3,4] ] - m2 = [ (1,3), (2,4) ] + m1 = [ [1, 2], [3, 4] ] + m2 = [ (1, 3), (2, 4) ] m1t= Utils.transpose(m1) self.assertTrue(m1t==m2) if __name__ == "__main__":