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
1diff --git a/lib/lp/services/database/debug.py b/lib/lp/services/database/debug.py
2index a061290..fef9033 100644
3--- a/lib/lp/services/database/debug.py
4+++ b/lib/lp/services/database/debug.py
5@@ -5,6 +5,8 @@
6 Replace the psycopg connect method with one that returns a wrapped connection.
7 '''
8
9+from __future__ import absolute_import, print_function
10+
11 import logging
12 import textwrap
13 import traceback
14@@ -19,15 +21,15 @@ def LN(*args, **kwargs):
15 A variable number of positional arguments are allowed. If
16 LN(obj0, obj1, obj2)
17 is called, the text part of the output looks like the output from
18- print obj0, obj1, obj2
19+ print(obj0, obj1, obj2)
20 The optional keyword "wrap" causes the message to be line-wrapped. The
21 argument to "wrap" should be "1" or "True". "name" is another optional
22 keyword parameter. This is best explained by an example:
23 from linenum import LN
24 def fun1():
25- print LN('error', 'is', 'here')
26+ print(LN('error', 'is', 'here'))
27 def fun2():
28- print LN('error', 'is', 'here', name='mess')
29+ print(LN('error', 'is', 'here', name='mess'))
30 fun1()
31 fun2()
32 The output is:
33@@ -60,12 +62,12 @@ class ConnectionWrapper(object):
34
35 def __getattr__(self, key):
36 if key in ('rollback', 'close', 'commit'):
37- print '%s %r.__getattr__(%r)' % (LN(), self, key)
38+ print('%s %r.__getattr__(%r)' % (LN(), self, key))
39 self.__dict__['_log']('__getattr__(%r)', key)
40 return getattr(self._real_con, key)
41
42 def __setattr__(self, key, val):
43- print '%s %r.__setattr__(%r, %r)' % (LN(), self, key, val)
44+ print('%s %r.__setattr__(%r, %r)' % (LN(), self, key, val))
45 self.__dict__['_log']('__setattr__(%r, %r)', key, val)
46 return setattr(self._real_con, key, val)
47
48@@ -79,7 +81,7 @@ def debug_connect(*args, **kw):
49 logging.getLogger('lp.services.database.debug').debug(
50 'connect(*%r, **%r) == %r', args, kw, con
51 )
52- print '%s connect(*%r, **%r) == %r' % (LN(), args, kw, con)
53+ print('%s connect(*%r, **%r) == %r' % (LN(), args, kw, con))
54 return con
55
56
57diff --git a/lib/lp/services/database/postgresql.py b/lib/lp/services/database/postgresql.py
58index 2218f42..e6f8c38 100644
59--- a/lib/lp/services/database/postgresql.py
60+++ b/lib/lp/services/database/postgresql.py
61@@ -6,6 +6,8 @@ PostgreSQL specific helper functions, such as database introspection
62 and table manipulation
63 """
64
65+from __future__ import absolute_import, print_function
66+
67 __metaclass__ = type
68
69 import re
70@@ -39,7 +41,7 @@ def listReferences(cur, table, column, indirect=True, _state=None):
71 to change keys.
72
73 >>> for r in listReferences(cur, 'a', 'aid'):
74- ... print repr(r)
75+ ... print(repr(r))
76 (u'a', u'selfref', u'a', u'aid', u'a', u'a')
77 (u'b', u'aid', u'a', u'aid', u'c', u'c')
78 (u'c', u'aid', u'b', u'aid', u'a', u'a')
79@@ -192,7 +194,7 @@ def listSequences(cur):
80 standalone.
81
82 >>> for r in listSequences(cur):
83- ... print repr(r)
84+ ... print(repr(r))
85 (u'public', u'a_aid_seq', u'a', u'aid')
86 (u'public', u'standalone', None, None)
87
88@@ -434,12 +436,12 @@ def allow_sequential_scans(cur, permission):
89
90 >>> allow_sequential_scans(cur, True)
91 >>> cur.execute("SHOW enable_seqscan")
92- >>> print cur.fetchall()[0][0]
93+ >>> print(cur.fetchall()[0][0])
94 on
95
96 >>> allow_sequential_scans(cur, False)
97 >>> cur.execute("SHOW enable_seqscan")
98- >>> print cur.fetchall()[0][0]
99+ >>> print(cur.fetchall()[0][0])
100 off
101 """
102 permission_value = 'false'
103@@ -490,9 +492,9 @@ def fqn(namespace, name):
104
105 Quoting is done for the non trivial cases.
106
107- >>> print fqn('public', 'foo')
108+ >>> print(fqn('public', 'foo'))
109 public.foo
110- >>> print fqn(' foo ', '$bar')
111+ >>> print(fqn(' foo ', '$bar'))
112 " foo "."$bar"
113 """
114 if re.search(r"[^a-z_]", namespace) is not None:
115@@ -612,4 +614,4 @@ if __name__ == '__main__':
116 cur = con.cursor()
117
118 for table, column in listReferences(cur, 'person', 'id'):
119- print '%32s %32s' % (table, column)
120+ print('%32s %32s' % (table, column))
121diff --git a/lib/lp/services/database/sort_sql.py b/lib/lp/services/database/sort_sql.py
122index 7ce77de..e43b727 100644
123--- a/lib/lp/services/database/sort_sql.py
124+++ b/lib/lp/services/database/sort_sql.py
125@@ -7,6 +7,8 @@ This library provides functions for the script sort_sql.py, which resides in
126 database/schema/.
127 """
128
129+from __future__ import absolute_import, print_function
130+
131 __metaclass__ = type
132
133 import re
134@@ -21,7 +23,7 @@ class Parser:
135 >>> p.feed("INSERT INTO foo (id, x) VALUES (1, 23);\n")
136 >>> p.feed("INSERT INTO foo (id, x) VALUES (2, 34);\n")
137 >>> for line in p.lines:
138- ... print repr(line)
139+ ... print(repr(line))
140 (None, "UPDATE foo SET bar='baz';")
141 (None, '')
142 (1, 'INSERT INTO foo (id, x) VALUES (1, 23);')
143@@ -177,7 +179,7 @@ def print_lines_sorted(file, lines):
144
145 for line in block:
146 sort_value, string = line
147- print >>file, string
148+ print(string, file=file)
149
150 for line in lines:
151 sort_value, string = line
152diff --git a/lib/lp/services/database/sqlbase.py b/lib/lp/services/database/sqlbase.py
153index 26e3e7a..ca35d9f 100644
154--- a/lib/lp/services/database/sqlbase.py
155+++ b/lib/lp/services/database/sqlbase.py
156@@ -1,6 +1,8 @@
157 # Copyright 2009-2012 Canonical Ltd. This software is licensed under the
158 # GNU Affero General Public License version 3 (see the file LICENSE).
159
160+from __future__ import absolute_import, print_function
161+
162 __metaclass__ = type
163 __all__ = [
164 'block_implicit_flushes',
165@@ -423,15 +425,15 @@ def quote_identifier(identifier):
166 In SQL, identifiers are quoted using " rather than ' which is reserved
167 for strings.
168
169- >>> print quoteIdentifier('hello')
170+ >>> print(quoteIdentifier('hello'))
171 "hello"
172- >>> print quoteIdentifier("'")
173+ >>> print(quoteIdentifier("'"))
174 "'"
175- >>> print quoteIdentifier('"')
176+ >>> print(quoteIdentifier('"'))
177 """"
178- >>> print quoteIdentifier("\\")
179+ >>> print(quoteIdentifier("\\"))
180 "\"
181- >>> print quoteIdentifier('\\"')
182+ >>> print(quoteIdentifier('\\"'))
183 "\"""
184 '''
185 return '"%s"' % identifier.replace('"', '""')
186@@ -453,28 +455,28 @@ def convert_storm_clause_to_string(storm_clause):
187 >>> from lp.bugs.interfaces.bugtask import BugTaskImportance
188 >>> from storm.expr import And, Or
189
190- >>> print convert_storm_clause_to_string(BugTask)
191+ >>> print(convert_storm_clause_to_string(BugTask))
192 BugTask
193
194- >>> print convert_storm_clause_to_string(BugTask.id == 16)
195+ >>> print(convert_storm_clause_to_string(BugTask.id == 16))
196 BugTask.id = 16
197
198- >>> print convert_storm_clause_to_string(
199- ... BugTask.importance == BugTaskImportance.UNKNOWN)
200+ >>> print(convert_storm_clause_to_string(
201+ ... BugTask.importance == BugTaskImportance.UNKNOWN))
202 BugTask.importance = 999
203
204- >>> print convert_storm_clause_to_string(Bug.title == "foo'bar'")
205+ >>> print(convert_storm_clause_to_string(Bug.title == "foo'bar'"))
206 Bug.title = E'foo''bar'''
207
208- >>> print convert_storm_clause_to_string(
209+ >>> print(convert_storm_clause_to_string(
210 ... Or(BugTask.importance == BugTaskImportance.UNKNOWN,
211- ... BugTask.importance == BugTaskImportance.HIGH))
212+ ... BugTask.importance == BugTaskImportance.HIGH)))
213 BugTask.importance = 999 OR BugTask.importance = 40
214
215- >>> print convert_storm_clause_to_string(
216+ >>> print(convert_storm_clause_to_string(
217 ... And(Bug.title == 'foo', BugTask.bug == Bug.id,
218 ... Or(BugTask.importance == BugTaskImportance.UNKNOWN,
219- ... BugTask.importance == BugTaskImportance.HIGH)))
220+ ... BugTask.importance == BugTaskImportance.HIGH))))
221 Bug.title = E'foo' AND BugTask.bug = Bug.id AND
222 (BugTask.importance = 999 OR BugTask.importance = 40)
223 """
224diff --git a/lib/lp/services/database/tests/script_isolation.py b/lib/lp/services/database/tests/script_isolation.py
225index 887c1b4..6f9843b 100644
226--- a/lib/lp/services/database/tests/script_isolation.py
227+++ b/lib/lp/services/database/tests/script_isolation.py
228@@ -5,6 +5,8 @@
229 settings work. Note we need to use a non-default isolation level to
230 confirm that the changes are actually being made by the API calls."""
231
232+from __future__ import absolute_import, print_function
233+
234 __metaclass__ = type
235 __all__ = []
236
237@@ -26,7 +28,7 @@ def check():
238 cur = cursor()
239 cur.execute("UPDATE Person SET homepage_content='foo' WHERE name='mark'")
240 cur.execute("SHOW transaction_isolation")
241- print cur.fetchone()[0]
242+ print(cur.fetchone()[0])
243
244 transaction.abort()
245 transaction.begin()
246@@ -34,7 +36,7 @@ def check():
247 cur = cursor()
248 cur.execute("UPDATE Person SET homepage_content='bar' WHERE name='mark'")
249 cur.execute("SHOW transaction_isolation")
250- print cur.fetchone()[0]
251+ print(cur.fetchone()[0])
252
253 dbconfig.override(dbuser='launchpad_main', isolation_level='read_committed')
254 disconnect_stores()

Subscribers

People subscribed via source and target branches

to status/vote changes: