[OpenLayers-Dev] Patch for building with python 3.0.1
Kris Geusebroek
kgeusebroek at xebia.com
Thu Apr 2 04:32:40 EDT 2009
Skipped content of type multipart/related-------------- next part --------------
Index: D:/projects/xebia/vtsPolitie/workspace/openlayers/build/build.py
===================================================================
--- D:/projects/xebia/vtsPolitie/workspace/openlayers/build/build.py (revision 9165)
+++ D:/projects/xebia/vtsPolitie/workspace/openlayers/build/build.py (working copy)
@@ -12,8 +12,8 @@
try:
import minimize
have_compressor = "minimize"
- except Exception, E:
- print E
+ except Exception as E:
+ print(E)
pass
sourceDirectory = "../lib"
@@ -30,21 +30,21 @@
if len(sys.argv) > 2:
outputFilename = sys.argv[2]
-print "Merging libraries."
+print("Merging libraries.")
merged = mergejs.run(sourceDirectory, None, configFilename)
if have_compressor == "jsmin":
- print "Compressing using jsmin."
+ print("Compressing using jsmin.")
minimized = jsmin.jsmin(merged)
elif have_compressor == "minimize":
- print "Compressing using minimize."
+ print("Compressing using minimize.")
minimized = minimize.minimize(merged)
else: # fallback
- print "Not compressing."
+ print("Not compressing.")
minimized = merged
-print "Adding license file."
-minimized = file("license.txt").read() + minimized
+print("Adding license file.")
+minimized = open("license.txt").read() + minimized
-print "Writing to %s." % outputFilename
-file(outputFilename, "w").write(minimized)
+print("Writing to %s." % outputFilename)
+open(outputFilename, "w").write(minimized)
-print "Done."
+print("Done.")
Index: D:/projects/xebia/vtsPolitie/workspace/openlayers/build/buildUncompressed.py
===================================================================
--- D:/projects/xebia/vtsPolitie/workspace/openlayers/build/buildUncompressed.py (revision 9165)
+++ D:/projects/xebia/vtsPolitie/workspace/openlayers/build/buildUncompressed.py (working copy)
@@ -14,12 +14,12 @@
if len(sys.argv) > 2:
outputFilename = sys.argv[2]
-print "Merging libraries."
+print("Merging libraries.")
merged = mergejs.run(sourceDirectory, None, configFilename)
-print "Adding license file."
+print("Adding license file.")
merged = file("license.txt").read() + merged
-print "Writing to %s." % outputFilename
+print("Writing to %s." % outputFilename)
file(outputFilename, "w").write(merged)
-print "Done."
+print("Done.")
Index: D:/projects/xebia/vtsPolitie/workspace/openlayers/tools/exampleparser.py
===================================================================
--- D:/projects/xebia/vtsPolitie/workspace/openlayers/tools/exampleparser.py (revision 9165)
+++ D:/projects/xebia/vtsPolitie/workspace/openlayers/tools/exampleparser.py (working copy)
@@ -53,7 +53,7 @@
"""
returns html of a specific example that is available online or locally
"""
- print '.',
+ print('.', end=" ")
if location.startswith('http'):
return urllib2.urlopen(location).read()
else:
@@ -180,8 +180,8 @@
for word in words:
if word:
word = word.lower()
- if index.has_key(word):
- if index[word].has_key(i):
+ if word in index:
+ if i in index[word]:
index[word][i] += 1
else:
index[word][i] = 1
@@ -192,7 +192,7 @@
if __name__ == "__main__":
if missing_deps:
- print "This script requires simplejson and BeautifulSoup. You don't have them. \n(%s)" % E
+ print("This script requires simplejson and BeautifulSoup. You don't have them. \n(%s)" % E)
sys.exit()
if len(sys.argv) > 1:
@@ -201,7 +201,7 @@
outFile = open('../examples/example-list.js','w')
examplesLocation = '../examples'
- print 'Reading examples from %s and writing out to %s' % (examplesLocation, outFile.name)
+ print('Reading examples from %s and writing out to %s' % (examplesLocation, outFile.name))
exampleList = []
docIds = ['title','shortdesc']
@@ -227,7 +227,7 @@
exampleList.append(tagvalues)
- print
+ print()
exampleList.sort(key=lambda x:x['example'].lower())
@@ -239,13 +239,13 @@
outFile.write(json)
outFile.close()
- print "writing feed to ../examples/%s " % feedName
+ print("writing feed to ../examples/%s " % feedName)
atom = open('../examples/%s' % feedName, 'w')
doc = createFeed(exampleList)
atom.write(doc.toxml())
atom.close()
- print 'complete'
+ print('complete')
Index: D:/projects/xebia/vtsPolitie/workspace/openlayers/tools/toposort.py
===================================================================
--- D:/projects/xebia/vtsPolitie/workspace/openlayers/tools/toposort.py (revision 9165)
+++ D:/projects/xebia/vtsPolitie/workspace/openlayers/tools/toposort.py (working copy)
@@ -103,7 +103,7 @@
try:
newdependencylevel, object = dependencies.get ( depends, (0, depends))
except TypeError:
- print depends
+ print(depends)
raise
dependencies[ depends ] = (newdependencylevel + 1, depends)
# "dependency (existence) of depended-on"
@@ -116,8 +116,8 @@
### Now we do the actual sorting
# The first task is to create the sortable
# list of dependency-levels
- sortinglist = dependencies.values()
- sortinglist.sort ()
+ sortinglist = sorted(dependencies.values())
+ #sortinglist.sort ()
output = []
while sortinglist:
deletelist = []
@@ -160,10 +160,10 @@
except KeyError:
pass
# need to recreate the sortinglist
- sortinglist = dependencies.values()
+ sortinglist = sorted(dependencies.values())
if not generation:
output.remove( generation )
- sortinglist.sort ()
+ #sortinglist.sort ()
return output
@@ -177,7 +177,7 @@
for x in toposort( nodes, route):
for a in x:
- print a
+ print(a)
raise SystemExit
@@ -227,34 +227,34 @@
(3,1),
],
]
- print 'sort, no recursion allowed'
+ print('sort, no recursion allowed')
for index in range(len(testingValues)):
-## print ' %s -- %s'%( index, testingValues[index])
+## print(' %s -- %s'%( index, testingValues[index]))
try:
- print ' ', sort( nodes, testingValues[index] )
+ print(' ', sort( nodes, testingValues[index] ))
except:
- print 'exception raised'
- print 'toposort, no recursion allowed'
+ print('exception raised')
+ print('toposort, no recursion allowed')
for index in range(len(testingValues)):
-## print ' %s -- %s'%( index, testingValues[index])
+## print(' %s -- %s'%( index, testingValues[index]))
try:
- print ' ', toposort( nodes, testingValues[index] )
+ print(' ', toposort( nodes, testingValues[index] ))
except:
- print 'exception raised'
- print 'sort, recursion allowed'
+ print('exception raised')
+ print('sort, recursion allowed')
for index in range(len(testingValues)):
-## print ' %s -- %s'%( index, testingValues[index])
+## print(' %s -- %s'%( index, testingValues[index]))
try:
- print ' ', sort( nodes, testingValues[index],0 )
+ print(' ', sort( nodes, testingValues[index],0 ))
except:
- print 'exception raised'
- print 'toposort, recursion allowed'
+ print('exception raised')
+ print('toposort, recursion allowed')
for index in range(len(testingValues)):
-## print ' %s -- %s'%( index, testingValues[index])
+## print(' %s -- %s'%( index, testingValues[index]))
try:
- print ' ', toposort( nodes, testingValues[index],0 )
+ print(' ', toposort( nodes, testingValues[index],0 ))
except:
- print 'exception raised'
+ print('exception raised')
Index: D:/projects/xebia/vtsPolitie/workspace/openlayers/tools/mergejs.py
===================================================================
--- D:/projects/xebia/vtsPolitie/workspace/openlayers/tools/mergejs.py (revision 9165)
+++ D:/projects/xebia/vtsPolitie/workspace/openlayers/tools/mergejs.py (working copy)
@@ -74,7 +74,7 @@
"""
Displays a usage message.
"""
- print "%s [-c <config file>] <output.js> <directory> [...]" % filename
+ print("%s [-c <config file>] <output.js> <directory> [...]" % filename)
class Config:
@@ -151,12 +151,12 @@
## Import file source code
## TODO: Do import when we walk the directories above?
for filepath in allFiles:
- print "Importing: %s" % filepath
+ print("Importing: %s" % filepath)
fullpath = os.path.join(sourceDirectory, filepath)
content = open(fullpath, "U").read() # TODO: Ensure end of line @ EOF?
files[filepath] = SourceFile(filepath, content) # TODO: Chop path?
- print
+ print()
from toposort import toposort
@@ -168,7 +168,7 @@
nodes = []
routes = []
## Resolve the dependencies
- print "Resolution pass %s... " % resolution_pass
+ print("Resolution pass %s... " % resolution_pass)
resolution_pass += 1
for filepath, info in files.items():
@@ -179,8 +179,8 @@
for dependencyLevel in toposort(nodes, routes):
for filepath in dependencyLevel:
order.append(filepath)
- if not files.has_key(filepath):
- print "Importing: %s" % filepath
+ if not filepath in files:
+ print("Importing: %s" % filepath)
fullpath = os.path.join(sourceDirectory, filepath)
content = open(fullpath, "U").read() # TODO: Ensure end of line @ EOF?
files[filepath] = SourceFile(filepath, content) # TODO: Chop path?
@@ -197,34 +197,34 @@
except:
complete = False
- print
+ print()
## Move forced first and last files to the required position
if cfg:
- print "Re-ordering files..."
+ print("Re-ordering files...")
order = cfg.forceFirst + [item
for item in order
if ((item not in cfg.forceFirst) and
(item not in cfg.forceLast))] + cfg.forceLast
- print
+ print()
## Output the files in the determined order
result = []
for fp in order:
f = files[fp]
- print "Exporting: ", f.filepath
+ print("Exporting: ", f.filepath)
result.append(HEADER % f.filepath)
source = f.source
result.append(source)
if not source.endswith("\n"):
result.append("\n")
- print "\nTotal files merged: %d " % len(files)
+ print("\nTotal files merged: %d " % len(files))
if outputFilename:
- print "\nGenerating: %s" % (outputFilename)
+ print("\nGenerating: %s" % (outputFilename))
open(outputFilename, "w").write("".join(result))
return "".join(result)
@@ -247,6 +247,6 @@
configFile = None
if options and options[0][0] == "-c":
configFile = options[0][1]
- print "Parsing configuration file: %s" % filename
+ print("Parsing configuration file: %s" % filename)
run( sourceDirectory, outputFilename, configFile )
Index: D:/projects/xebia/vtsPolitie/workspace/openlayers/tools/shrinksafe.py
===================================================================
--- D:/projects/xebia/vtsPolitie/workspace/openlayers/tools/shrinksafe.py (revision 9165)
+++ D:/projects/xebia/vtsPolitie/workspace/openlayers/tools/shrinksafe.py (working copy)
@@ -29,7 +29,7 @@
try:
sourceFilename = sys.argv[1]
except:
- print "Usage: %s (<source filename>|-)" % sys.argv[0]
+ print("Usage: %s (<source filename>|-)" % sys.argv[0])
raise SystemExit
if sourceFilename == "-":
@@ -51,4 +51,4 @@
""" % (BOUNDARY_MARKER, sourceFilename, sourceCode))
## Deliver the result
- print urllib2.urlopen(request).read(),
+ print(urllib2.urlopen(request).read(), end=" ")
Index: D:/projects/xebia/vtsPolitie/workspace/openlayers/tools/minimize.py
===================================================================
--- D:/projects/xebia/vtsPolitie/workspace/openlayers/tools/minimize.py (revision 9165)
+++ D:/projects/xebia/vtsPolitie/workspace/openlayers/tools/minimize.py (working copy)
@@ -35,7 +35,7 @@
functions. To add further compression algorithms, simply add
functions whose names end in _helper which take a string as input
and return a more compressed string as output."""
- for key, item in globals().iteritems():
+ for key, item in iter(globals().items()):
if key.endswith("_helper"):
func_key = key[:-7]
if not exclude or not func_key in exclude:
@@ -44,4 +44,4 @@
if __name__ == "__main__":
import sys
- print minimize(open(sys.argv[1]).read())
+ print(minimize(open(sys.argv[1]).read()))
Index: D:/projects/xebia/vtsPolitie/workspace/openlayers/tools/oldot.py
===================================================================
--- D:/projects/xebia/vtsPolitie/workspace/openlayers/tools/oldot.py (revision 9165)
+++ D:/projects/xebia/vtsPolitie/workspace/openlayers/tools/oldot.py (working copy)
@@ -20,7 +20,7 @@
cls = "OpenLayers.%s" % filepath.strip(".js").replace("/", ".")
allFiles.append([cls, parents])
return allFiles
-print """
+print("""
digraph name {
fontname = "Helvetica"
fontsize = 8
@@ -31,13 +31,13 @@
fontsize = 8
shape = "plaintext"
]
-"""
+""")
for i in run():
- print i[0].replace(".", "_")
+ print(i[0].replace(".", "_"))
for item in i[1]:
if not item: continue
- print "%s -> %s" % (i[0].replace(".","_"), item.replace(".", "_"))
- print "; "
+ print("%s -> %s" % (i[0].replace(".","_"), item.replace(".", "_")))
+ print("; ")
-print """}"""
+print("""}""")
Index: D:/projects/xebia/vtsPolitie/workspace/openlayers/tools/BeautifulSoup.py
===================================================================
--- D:/projects/xebia/vtsPolitie/workspace/openlayers/tools/BeautifulSoup.py (revision 9165)
+++ D:/projects/xebia/vtsPolitie/workspace/openlayers/tools/BeautifulSoup.py (working copy)
@@ -422,7 +422,7 @@
return self._getAttrMap().get(key, default)
def has_key(self, key):
- return self._getAttrMap().has_key(key)
+ return key in self._getAttrMap()
def __getitem__(self, key):
"""tag[key] returns the value of the 'key' attribute for the tag,
@@ -476,7 +476,7 @@
return apply(self.findAll, args, kwargs)
def __getattr__(self, tag):
- #print "Getattr %s.%s" % (self.__class__, tag)
+ #print("Getattr %s.%s" % (self.__class__, tag))
if len(tag) > 3 and tag.rfind('Tag') == len(tag)-3:
return self.find(tag[:-3])
elif tag.find('__') != 0:
@@ -759,7 +759,7 @@
return found
def search(self, markup):
- #print 'looking for %s in %s' % (self, markup)
+ #print('looking for %s in %s' % (self, markup))
found = None
# If given a list of items, scan it for a text element that
# matches.
@@ -785,7 +785,7 @@
return found
def _matches(self, markup, matchAgainst):
- #print "Matching %s against %s" % (markup, matchAgainst)
+ #print("Matching %s against %s" % (markup, matchAgainst))
result = False
if matchAgainst == True and type(matchAgainst) == types.BooleanType:
result = markup != None
@@ -977,7 +977,7 @@
def __getattr__(self, methodName):
"""This method routes method call requests to either the SGMLParser
superclass or the Tag superclass, depending on the method name."""
- #print "__getattr__ called on %s.%s" % (self.__class__, methodName)
+ #print("__getattr__ called on %s.%s" % (self.__class__, methodName))
if methodName.find('start_') == 0 or methodName.find('end_') == 0 \
or methodName.find('do_') == 0:
@@ -1012,13 +1012,13 @@
isinstance(self.currentTag.contents[0], NavigableString):
self.currentTag.string = self.currentTag.contents[0]
- #print "Pop", tag.name
+ #print("Pop", tag.name)
if self.tagStack:
self.currentTag = self.tagStack[-1]
return self.currentTag
def pushTag(self, tag):
- #print "Push", tag.name
+ #print("Push", tag.name)
if self.currentTag:
self.currentTag.append(tag)
self.tagStack.append(tag)
@@ -1050,7 +1050,7 @@
instance of the given tag. If inclusivePop is false, pops the tag
stack up to but *not* including the most recent instqance of
the given tag."""
- #print "Popping to %s" % name
+ #print("Popping to %s" % name)
if name == self.ROOT_TAG_NAME:
return
@@ -1115,10 +1115,10 @@
self._popToTag(popTo, inclusive)
def unknown_starttag(self, name, attrs, selfClosing=0):
- #print "Start tag %s: %s" % (name, attrs)
+ #print("Start tag %s: %s" % (name, attrs))
if self.quoteStack:
#This is not a real tag.
- #print "<%s> is not real!" % name
+ #print("<%s> is not real!" % name)
attrs = ''.join(map(lambda(x, y): ' %s="%s"' % (x, y), attrs))
self.handle_data('<%s%s>' % (name, attrs))
return
@@ -1139,16 +1139,16 @@
if selfClosing or self.isSelfClosingTag(name):
self.popTag()
if name in self.QUOTE_TAGS:
- #print "Beginning quote (%s)" % name
+ #print("Beginning quote (%s)" % name)
self.quoteStack.append(name)
self.literal = 1
return tag
def unknown_endtag(self, name):
- #print "End tag %s" % name
+ #print("End tag %s" % name)
if self.quoteStack and self.quoteStack[-1] != name:
#This is not a real end tag.
- #print "</%s> is not real!" % name
+ #print("</%s> is not real!" % name)
self.handle_data('</%s>' % name)
return
self.endData()
@@ -1582,15 +1582,15 @@
markup)
try:
- # print "Trying to convert document to %s" % proposed
+ # print("Trying to convert document to %s" % proposed)
u = self._toUnicode(markup, proposed)
self.markup = u
self.originalEncoding = proposed
except Exception, e:
- # print "That didn't work!"
- # print e
+ # print("That didn't work!")
+ # print(e)
return None
- #print "Correct encoding: %s" % proposed
+ #print("Correct encoding: %s" % proposed)
return self.markup
def _toUnicode(self, data, encoding):
@@ -1764,4 +1764,4 @@
if __name__ == '__main__':
import sys
soup = BeautifulSoup(sys.stdin.read())
- print soup.prettify()
+ print(soup.prettify())
More information about the Dev
mailing list