Merge ~cjwatson/launchpad:services-database-print-function into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: ea374c6ff68c637af89930b733ff3556f3d863d0
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:services-database-print-function
Merge into: launchpad:master
Diff against target: 254 lines (+41/-31)
5 files modified
lib/lp/services/database/debug.py (+8/-6)
lib/lp/services/database/postgresql.py (+9/-7)
lib/lp/services/database/sort_sql.py (+4/-2)
lib/lp/services/database/sqlbase.py (+16/-14)
lib/lp/services/database/tests/script_isolation.py (+4/-2)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+387849@code.launchpad.net

Commit message

Port lp.services.database to print_function

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

Self-approving, since this is trivial and mechanical.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/lib/lp/services/database/debug.py b/lib/lp/services/database/debug.py
index a061290..fef9033 100644
--- a/lib/lp/services/database/debug.py
+++ b/lib/lp/services/database/debug.py
@@ -5,6 +5,8 @@
5Replace the psycopg connect method with one that returns a wrapped connection.5Replace the psycopg connect method with one that returns a wrapped connection.
6'''6'''
77
8from __future__ import absolute_import, print_function
9
8import logging10import logging
9import textwrap11import textwrap
10import traceback12import traceback
@@ -19,15 +21,15 @@ def LN(*args, **kwargs):
19 A variable number of positional arguments are allowed. If21 A variable number of positional arguments are allowed. If
20 LN(obj0, obj1, obj2)22 LN(obj0, obj1, obj2)
21 is called, the text part of the output looks like the output from23 is called, the text part of the output looks like the output from
22 print obj0, obj1, obj224 print(obj0, obj1, obj2)
23 The optional keyword "wrap" causes the message to be line-wrapped. The25 The optional keyword "wrap" causes the message to be line-wrapped. The
24 argument to "wrap" should be "1" or "True". "name" is another optional26 argument to "wrap" should be "1" or "True". "name" is another optional
25 keyword parameter. This is best explained by an example:27 keyword parameter. This is best explained by an example:
26 from linenum import LN28 from linenum import LN
27 def fun1():29 def fun1():
28 print LN('error', 'is', 'here')30 print(LN('error', 'is', 'here'))
29 def fun2():31 def fun2():
30 print LN('error', 'is', 'here', name='mess')32 print(LN('error', 'is', 'here', name='mess'))
31 fun1()33 fun1()
32 fun2()34 fun2()
33 The output is:35 The output is:
@@ -60,12 +62,12 @@ class ConnectionWrapper(object):
6062
61 def __getattr__(self, key):63 def __getattr__(self, key):
62 if key in ('rollback', 'close', 'commit'):64 if key in ('rollback', 'close', 'commit'):
63 print '%s %r.__getattr__(%r)' % (LN(), self, key)65 print('%s %r.__getattr__(%r)' % (LN(), self, key))
64 self.__dict__['_log']('__getattr__(%r)', key)66 self.__dict__['_log']('__getattr__(%r)', key)
65 return getattr(self._real_con, key)67 return getattr(self._real_con, key)
6668
67 def __setattr__(self, key, val):69 def __setattr__(self, key, val):
68 print '%s %r.__setattr__(%r, %r)' % (LN(), self, key, val)70 print('%s %r.__setattr__(%r, %r)' % (LN(), self, key, val))
69 self.__dict__['_log']('__setattr__(%r, %r)', key, val)71 self.__dict__['_log']('__setattr__(%r, %r)', key, val)
70 return setattr(self._real_con, key, val)72 return setattr(self._real_con, key, val)
7173
@@ -79,7 +81,7 @@ def debug_connect(*args, **kw):
79 logging.getLogger('lp.services.database.debug').debug(81 logging.getLogger('lp.services.database.debug').debug(
80 'connect(*%r, **%r) == %r', args, kw, con82 'connect(*%r, **%r) == %r', args, kw, con
81 )83 )
82 print '%s connect(*%r, **%r) == %r' % (LN(), args, kw, con)84 print('%s connect(*%r, **%r) == %r' % (LN(), args, kw, con))
83 return con85 return con
8486
8587
diff --git a/lib/lp/services/database/postgresql.py b/lib/lp/services/database/postgresql.py
index 2218f42..e6f8c38 100644
--- a/lib/lp/services/database/postgresql.py
+++ b/lib/lp/services/database/postgresql.py
@@ -6,6 +6,8 @@ PostgreSQL specific helper functions, such as database introspection
6and table manipulation6and table manipulation
7"""7"""
88
9from __future__ import absolute_import, print_function
10
9__metaclass__ = type11__metaclass__ = type
1012
11import re13import re
@@ -39,7 +41,7 @@ def listReferences(cur, table, column, indirect=True, _state=None):
39 to change keys.41 to change keys.
4042
41 >>> for r in listReferences(cur, 'a', 'aid'):43 >>> for r in listReferences(cur, 'a', 'aid'):
42 ... print repr(r)44 ... print(repr(r))
43 (u'a', u'selfref', u'a', u'aid', u'a', u'a')45 (u'a', u'selfref', u'a', u'aid', u'a', u'a')
44 (u'b', u'aid', u'a', u'aid', u'c', u'c')46 (u'b', u'aid', u'a', u'aid', u'c', u'c')
45 (u'c', u'aid', u'b', u'aid', u'a', u'a')47 (u'c', u'aid', u'b', u'aid', u'a', u'a')
@@ -192,7 +194,7 @@ def listSequences(cur):
192 standalone.194 standalone.
193195
194 >>> for r in listSequences(cur):196 >>> for r in listSequences(cur):
195 ... print repr(r)197 ... print(repr(r))
196 (u'public', u'a_aid_seq', u'a', u'aid')198 (u'public', u'a_aid_seq', u'a', u'aid')
197 (u'public', u'standalone', None, None)199 (u'public', u'standalone', None, None)
198200
@@ -434,12 +436,12 @@ def allow_sequential_scans(cur, permission):
434436
435 >>> allow_sequential_scans(cur, True)437 >>> allow_sequential_scans(cur, True)
436 >>> cur.execute("SHOW enable_seqscan")438 >>> cur.execute("SHOW enable_seqscan")
437 >>> print cur.fetchall()[0][0]439 >>> print(cur.fetchall()[0][0])
438 on440 on
439441
440 >>> allow_sequential_scans(cur, False)442 >>> allow_sequential_scans(cur, False)
441 >>> cur.execute("SHOW enable_seqscan")443 >>> cur.execute("SHOW enable_seqscan")
442 >>> print cur.fetchall()[0][0]444 >>> print(cur.fetchall()[0][0])
443 off445 off
444 """446 """
445 permission_value = 'false'447 permission_value = 'false'
@@ -490,9 +492,9 @@ def fqn(namespace, name):
490492
491 Quoting is done for the non trivial cases.493 Quoting is done for the non trivial cases.
492494
493 >>> print fqn('public', 'foo')495 >>> print(fqn('public', 'foo'))
494 public.foo496 public.foo
495 >>> print fqn(' foo ', '$bar')497 >>> print(fqn(' foo ', '$bar'))
496 " foo "."$bar"498 " foo "."$bar"
497 """499 """
498 if re.search(r"[^a-z_]", namespace) is not None:500 if re.search(r"[^a-z_]", namespace) is not None:
@@ -612,4 +614,4 @@ if __name__ == '__main__':
612 cur = con.cursor()614 cur = con.cursor()
613615
614 for table, column in listReferences(cur, 'person', 'id'):616 for table, column in listReferences(cur, 'person', 'id'):
615 print '%32s %32s' % (table, column)617 print('%32s %32s' % (table, column))
diff --git a/lib/lp/services/database/sort_sql.py b/lib/lp/services/database/sort_sql.py
index 7ce77de..e43b727 100644
--- a/lib/lp/services/database/sort_sql.py
+++ b/lib/lp/services/database/sort_sql.py
@@ -7,6 +7,8 @@ This library provides functions for the script sort_sql.py, which resides in
7database/schema/.7database/schema/.
8"""8"""
99
10from __future__ import absolute_import, print_function
11
10__metaclass__ = type12__metaclass__ = type
1113
12import re14import re
@@ -21,7 +23,7 @@ class Parser:
21 >>> p.feed("INSERT INTO foo (id, x) VALUES (1, 23);\n")23 >>> p.feed("INSERT INTO foo (id, x) VALUES (1, 23);\n")
22 >>> p.feed("INSERT INTO foo (id, x) VALUES (2, 34);\n")24 >>> p.feed("INSERT INTO foo (id, x) VALUES (2, 34);\n")
23 >>> for line in p.lines:25 >>> for line in p.lines:
24 ... print repr(line)26 ... print(repr(line))
25 (None, "UPDATE foo SET bar='baz';")27 (None, "UPDATE foo SET bar='baz';")
26 (None, '')28 (None, '')
27 (1, 'INSERT INTO foo (id, x) VALUES (1, 23);')29 (1, 'INSERT INTO foo (id, x) VALUES (1, 23);')
@@ -177,7 +179,7 @@ def print_lines_sorted(file, lines):
177179
178 for line in block:180 for line in block:
179 sort_value, string = line181 sort_value, string = line
180 print >>file, string182 print(string, file=file)
181183
182 for line in lines:184 for line in lines:
183 sort_value, string = line185 sort_value, string = line
diff --git a/lib/lp/services/database/sqlbase.py b/lib/lp/services/database/sqlbase.py
index 26e3e7a..ca35d9f 100644
--- a/lib/lp/services/database/sqlbase.py
+++ b/lib/lp/services/database/sqlbase.py
@@ -1,6 +1,8 @@
1# Copyright 2009-2012 Canonical Ltd. This software is licensed under the1# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4from __future__ import absolute_import, print_function
5
4__metaclass__ = type6__metaclass__ = type
5__all__ = [7__all__ = [
6 'block_implicit_flushes',8 'block_implicit_flushes',
@@ -423,15 +425,15 @@ def quote_identifier(identifier):
423 In SQL, identifiers are quoted using " rather than ' which is reserved425 In SQL, identifiers are quoted using " rather than ' which is reserved
424 for strings.426 for strings.
425427
426 >>> print quoteIdentifier('hello')428 >>> print(quoteIdentifier('hello'))
427 "hello"429 "hello"
428 >>> print quoteIdentifier("'")430 >>> print(quoteIdentifier("'"))
429 "'"431 "'"
430 >>> print quoteIdentifier('"')432 >>> print(quoteIdentifier('"'))
431 """"433 """"
432 >>> print quoteIdentifier("\\")434 >>> print(quoteIdentifier("\\"))
433 "\"435 "\"
434 >>> print quoteIdentifier('\\"')436 >>> print(quoteIdentifier('\\"'))
435 "\"""437 "\"""
436 '''438 '''
437 return '"%s"' % identifier.replace('"', '""')439 return '"%s"' % identifier.replace('"', '""')
@@ -453,28 +455,28 @@ def convert_storm_clause_to_string(storm_clause):
453 >>> from lp.bugs.interfaces.bugtask import BugTaskImportance455 >>> from lp.bugs.interfaces.bugtask import BugTaskImportance
454 >>> from storm.expr import And, Or456 >>> from storm.expr import And, Or
455457
456 >>> print convert_storm_clause_to_string(BugTask)458 >>> print(convert_storm_clause_to_string(BugTask))
457 BugTask459 BugTask
458460
459 >>> print convert_storm_clause_to_string(BugTask.id == 16)461 >>> print(convert_storm_clause_to_string(BugTask.id == 16))
460 BugTask.id = 16462 BugTask.id = 16
461463
462 >>> print convert_storm_clause_to_string(464 >>> print(convert_storm_clause_to_string(
463 ... BugTask.importance == BugTaskImportance.UNKNOWN)465 ... BugTask.importance == BugTaskImportance.UNKNOWN))
464 BugTask.importance = 999466 BugTask.importance = 999
465467
466 >>> print convert_storm_clause_to_string(Bug.title == "foo'bar'")468 >>> print(convert_storm_clause_to_string(Bug.title == "foo'bar'"))
467 Bug.title = E'foo''bar'''469 Bug.title = E'foo''bar'''
468470
469 >>> print convert_storm_clause_to_string(471 >>> print(convert_storm_clause_to_string(
470 ... Or(BugTask.importance == BugTaskImportance.UNKNOWN,472 ... Or(BugTask.importance == BugTaskImportance.UNKNOWN,
471 ... BugTask.importance == BugTaskImportance.HIGH))473 ... BugTask.importance == BugTaskImportance.HIGH)))
472 BugTask.importance = 999 OR BugTask.importance = 40474 BugTask.importance = 999 OR BugTask.importance = 40
473475
474 >>> print convert_storm_clause_to_string(476 >>> print(convert_storm_clause_to_string(
475 ... And(Bug.title == 'foo', BugTask.bug == Bug.id,477 ... And(Bug.title == 'foo', BugTask.bug == Bug.id,
476 ... Or(BugTask.importance == BugTaskImportance.UNKNOWN,478 ... Or(BugTask.importance == BugTaskImportance.UNKNOWN,
477 ... BugTask.importance == BugTaskImportance.HIGH)))479 ... BugTask.importance == BugTaskImportance.HIGH))))
478 Bug.title = E'foo' AND BugTask.bug = Bug.id AND480 Bug.title = E'foo' AND BugTask.bug = Bug.id AND
479 (BugTask.importance = 999 OR BugTask.importance = 40)481 (BugTask.importance = 999 OR BugTask.importance = 40)
480 """482 """
diff --git a/lib/lp/services/database/tests/script_isolation.py b/lib/lp/services/database/tests/script_isolation.py
index 887c1b4..6f9843b 100644
--- a/lib/lp/services/database/tests/script_isolation.py
+++ b/lib/lp/services/database/tests/script_isolation.py
@@ -5,6 +5,8 @@
5settings work. Note we need to use a non-default isolation level to5settings work. Note we need to use a non-default isolation level to
6confirm that the changes are actually being made by the API calls."""6confirm that the changes are actually being made by the API calls."""
77
8from __future__ import absolute_import, print_function
9
8__metaclass__ = type10__metaclass__ = type
9__all__ = []11__all__ = []
1012
@@ -26,7 +28,7 @@ def check():
26 cur = cursor()28 cur = cursor()
27 cur.execute("UPDATE Person SET homepage_content='foo' WHERE name='mark'")29 cur.execute("UPDATE Person SET homepage_content='foo' WHERE name='mark'")
28 cur.execute("SHOW transaction_isolation")30 cur.execute("SHOW transaction_isolation")
29 print cur.fetchone()[0]31 print(cur.fetchone()[0])
3032
31 transaction.abort()33 transaction.abort()
32 transaction.begin()34 transaction.begin()
@@ -34,7 +36,7 @@ def check():
34 cur = cursor()36 cur = cursor()
35 cur.execute("UPDATE Person SET homepage_content='bar' WHERE name='mark'")37 cur.execute("UPDATE Person SET homepage_content='bar' WHERE name='mark'")
36 cur.execute("SHOW transaction_isolation")38 cur.execute("SHOW transaction_isolation")
37 print cur.fetchone()[0]39 print(cur.fetchone()[0])
3840
39dbconfig.override(dbuser='launchpad_main', isolation_level='read_committed')41dbconfig.override(dbuser='launchpad_main', isolation_level='read_committed')
40disconnect_stores()42disconnect_stores()

Subscribers

People subscribed via source and target branches

to status/vote changes: