Permalink
Browse files

Prepare for py3k: print(), except as, and imports.

 * pyrseas/dbconn.py, pyrseas/dbobject/constraint.py,
   pyrseas/dbobject/index.py, pyrseas/dbobject/language.py,
   pyrseas/dbobject/rule.py, pyrseas/dbobject/schema.py
   pyrseas/dbobject/table.py, pyrseas/dbobject/textsearch.py: Change
   except Xxx, exc to except Xxx as exc.
 * pyrseas/dbobject/table.py, pyrseas/dbobject/schema.py: Use full
   paths for imports.
 * pyrseas/dbtoyaml.py, pyrseas/yamltodb.py: Replace print statement
   by print() function.
  • Loading branch information...
jmafc committed Jan 10, 2012
1 parent 6f458cf commit ddaf933ae9105366785d44e3cd256d49b9bc1709
View
@@ -61,7 +61,7 @@ def _execute(self, query):
curs = self.conn.cursor()
try:
curs.execute(query)
- except Exception, exc:
+ except Exception as exc:
exc.args += (query, )
raise
return curs
@@ -322,7 +322,7 @@ def from_map(self, table, inconstrs, target=''):
val = chks[cns]
try:
check.expression = val['expression']
- except KeyError, exc:
+ except KeyError as exc:
exc.args = ("Constraint '%s' is missing expression"
% cns, )
raise
@@ -342,7 +342,7 @@ def from_map(self, table, inconstrs, target=''):
val = inconstrs['primary_key'][cns]
try:
pkey.keycols = val['columns']
- except KeyError, exc:
+ except KeyError as exc:
exc.args = ("Constraint '%s' is missing columns" % cns, )
raise
if 'access_method' in val:
@@ -374,23 +374,23 @@ def from_map(self, table, inconstrs, target=''):
fkey.deferred = True
try:
fkey.keycols = val['columns']
- except KeyError, exc:
+ except KeyError as exc:
exc.args = ("Constraint '%s' is missing columns" % cns, )
raise
try:
refs = val['references']
- except KeyError, exc:
+ except KeyError as exc:
exc.args = ("Constraint '%s' missing references" % cns, )
raise
try:
fkey.ref_table = refs['table']
- except KeyError, exc:
+ except KeyError as exc:
exc.args = ("Constraint '%s' missing table reference"
% cns, )
raise
try:
fkey.ref_cols = refs['columns']
- except KeyError, exc:
+ except KeyError as exc:
exc.args = ("Constraint '%s' missing reference columns"
% cns, )
raise
@@ -409,7 +409,7 @@ def from_map(self, table, inconstrs, target=''):
val = uconstrs[cns]
try:
unq.keycols = val['columns']
- except KeyError, exc:
+ except KeyError as exc:
exc.args = ("Constraint '%s' is missing columns" % cns, )
raise
if 'access_method' in val:
@@ -160,7 +160,7 @@ def diff_map(self, inindexes):
stmts.append(self[(sch, tbl, oldname)].rename(
inidx.name))
del self[(sch, tbl, oldname)]
- except KeyError, exc:
+ except KeyError as exc:
exc.args = ("Previous name '%s' for index '%s' "
"not found" % (oldname, inidx.name), )
raise
@@ -124,7 +124,7 @@ def diff_map(self, inlanguages, dbversion):
try:
stmts.append(self[oldname].rename(inlng.name))
del self[oldname]
- except KeyError, exc:
+ except KeyError as exc:
exc.args = ("Previous name '%s' for language '%s' "
"not found" % (oldname, inlng.name), )
raise
View
@@ -120,7 +120,7 @@ def diff_map(self, inrules):
try:
stmts.append(self[oldname].rename(inrul.name))
del self[oldname]
- except KeyError, exc:
+ except KeyError as exc:
exc.args = ("Previous name '%s' for rule '%s' "
"not found" % (oldname, inrul.name), )
raise
@@ -8,8 +8,8 @@
"""
from pyrseas.dbobject import DbObjectDict, DbObject
from pyrseas.dbobject import quote_id, split_schema_obj
-from dbtype import BaseType, Composite, Domain, Enum
-from table import Table, Sequence, View
+from pyrseas.dbobject.dbtype import BaseType, Composite, Domain, Enum
+from pyrseas.dbobject.table import Table, Sequence, View
class Schema(DbObject):
@@ -312,7 +312,7 @@ def diff_map(self, inschemas):
try:
stmts.append(self[oldname].rename(insch.name))
del self[oldname]
- except KeyError, exc:
+ except KeyError as exc:
exc.args = ("Previous name '%s' for schema '%s' "
"not found" % (oldname, insch.name), )
raise
@@ -11,8 +11,8 @@
from pyrseas.dbobject import DbObjectDict, DbSchemaObject
from pyrseas.dbobject import quote_id, split_schema_obj
-from constraint import CheckConstraint, PrimaryKey, ForeignKey, \
- UniqueConstraint
+from pyrseas.dbobject.constraint import CheckConstraint, PrimaryKey
+from pyrseas.dbobject.constraint import ForeignKey, UniqueConstraint
MAX_BIGINT = 9223372036854775807L
@@ -422,7 +422,7 @@ def from_map(self, schema, inobjs, newdb):
raise ValueError("Table '%s' has no specification" % k)
try:
newdb.columns.from_map(table, intable['columns'])
- except KeyError, exc:
+ except KeyError as exc:
exc.args = ("Table '%s' has no columns" % key, )
raise
if 'inherits' in intable:
@@ -551,7 +551,7 @@ def _rename(self, obj, objtype):
stmt = self[(obj.schema, oldname)].rename(obj.name)
self[(obj.schema, obj.name)] = self[(obj.schema, oldname)]
del self[(obj.schema, oldname)]
- except KeyError, exc:
+ except KeyError as exc:
exc.args = ("Previous name '%s' for %s '%s' not found" % (
oldname, objtype, obj.name), )
raise
@@ -105,7 +105,7 @@ def diff_map(self, inconfigs):
try:
stmts.append(self[oldname].rename(intsc.name))
del self[oldname]
- except KeyError, exc:
+ except KeyError as exc:
exc.args = ("Previous name '%s' for configuration "
"'%s' not found" % (oldname, intsc.name), )
raise
@@ -201,7 +201,7 @@ def diff_map(self, indicts):
try:
stmts.append(self[oldname].rename(intsd.name))
del self[oldname]
- except KeyError, exc:
+ except KeyError as exc:
exc.args = ("Previous name '%s' for dictionary '%s' "
"not found" % (oldname, intsd.name), )
raise
@@ -300,7 +300,7 @@ def diff_map(self, inparsers):
try:
stmts.append(self[oldname].rename(intsp.name))
del self[oldname]
- except KeyError, exc:
+ except KeyError as exc:
exc.args = ("Previous name '%s' for parser '%s' "
"not found" % (oldname, intsp.name), )
raise
@@ -396,7 +396,7 @@ def diff_map(self, intemplates):
try:
stmts.append(self[oldname].rename(intst.name))
del self[oldname]
- except KeyError, exc:
+ except KeyError as exc:
exc.args = ("Previous name '%s' for template '%s' "
"not found" % (oldname, intst.name), )
raise
View
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
"""dbtoyaml - extract the schema of a PostgreSQL database in YAML format"""
+from __future__ import print_function
import os
from optparse import OptionParser
@@ -54,7 +55,7 @@ def main(host='localhost', port=5432, schema=None):
if not dbmap[sch]:
del dbmap[sch]
- print yaml.dump(dbmap, default_flow_style=False)
+ print(yaml.dump(dbmap, default_flow_style=False))
if __name__ == '__main__':
main()
View
@@ -3,6 +3,7 @@
"""yamltodb - generate SQL statements to update a PostgreSQL database
to match the schema specified in a YAML file"""
+from __future__ import print_function
import os
import sys
from optparse import OptionParser
@@ -51,10 +52,10 @@ def main(host='localhost', port=5432):
stmts = db.diff_map(inmap, options.schlist)
if stmts:
if options.onetrans or options.update:
- print "BEGIN;"
- print ";\n".join(stmts) + ';'
+ print("BEGIN;")
+ print(";\n".join(stmts) + ';')
if options.onetrans or options.update:
- print "COMMIT;"
+ print("COMMIT;")
if options.update:
dbconn.connect()
try:
@@ -65,7 +66,7 @@ def main(host='localhost', port=5432):
raise
else:
dbconn.conn.commit()
- print >> sys.stderr, "Changes applied"
+ print("Changes applied", file=sys.stderr)
if __name__ == '__main__':
main()

0 comments on commit ddaf933

Please sign in to comment.