Merge ~cjwatson/launchpad:py3only-drop-py3ish-repr into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 514557d70383de57e0ad633ee5ef182a78ccdb79
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:py3only-drop-py3ish-repr
Merge into: launchpad:master
Diff against target: 123 lines (+15/-37)
1 file modified
lib/lp/services/database/postgresql.py (+15/-37)
Reviewer Review Type Date Requested Status
Cristian Gonzalez (community) Approve
Review via email: mp+406963@code.launchpad.net

Commit message

Drop lp.services.database.postgresql._py3ish_repr

To post a comment you must log in.
Revision history for this message
Cristian Gonzalez (cristiangsp) wrote :

Looks good!

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/postgresql.py b/lib/lp/services/database/postgresql.py
index 462edc6..d36c374 100644
--- a/lib/lp/services/database/postgresql.py
+++ b/lib/lp/services/database/postgresql.py
@@ -19,28 +19,6 @@ from lp.services.database.sqlbase import (
19 )19 )
2020
2121
22def _py3ish_repr(value):
23 """Like `repr`, but uses Python 3 spelling of text.
24
25 This is a local helper for doctests.
26 """
27 if isinstance(value, six.text_type):
28 value = value.encode('unicode_escape').decode('ASCII')
29 if "'" in value and '"' not in value:
30 return '"%s"' % value
31 else:
32 return "'%s'" % value.replace("'", "\\'")
33 elif isinstance(value, tuple):
34 if len(value) == 1:
35 return '(' + _py3ish_repr(value[0]) + ',)'
36 else:
37 return '(' + ', '.join(_py3ish_repr(item) for item in value) + ')'
38 elif isinstance(value, list):
39 return '[' + ', '.join(_py3ish_repr(item) for item in value) + ']'
40 else:
41 return repr(value)
42
43
44def listReferences(cur, table, column, indirect=True, _state=None):22def listReferences(cur, table, column, indirect=True, _state=None):
45 """Return a list of all foreign key references to the given table column23 """Return a list of all foreign key references to the given table column
4624
@@ -63,7 +41,7 @@ def listReferences(cur, table, column, indirect=True, _state=None):
63 to change keys.41 to change keys.
6442
65 >>> for r in listReferences(cur, 'a', 'aid'):43 >>> for r in listReferences(cur, 'a', 'aid'):
66 ... print(_py3ish_repr(r))44 ... print(repr(r))
67 ('a', 'selfref', 'a', 'aid', 'a', 'a')45 ('a', 'selfref', 'a', 'aid', 'a', 'a')
68 ('b', 'aid', 'a', 'aid', 'c', 'c')46 ('b', 'aid', 'a', 'aid', 'c', 'c')
69 ('c', 'aid', 'b', 'aid', 'a', 'a')47 ('c', 'aid', 'b', 'aid', 'a', 'a')
@@ -135,32 +113,32 @@ def listIndexes(cur, table, column, only_unique=False):
135113
136 Simple indexes114 Simple indexes
137115
138 >>> print(_py3ish_repr(listIndexes(cur, 'b', 'aid')))116 >>> listIndexes(cur, 'b', 'aid')
139 [('aid',)]117 [('aid',)]
140 >>> print(_py3ish_repr(listIndexes(cur, 'a', 'name')))118 >>> listIndexes(cur, 'a', 'name')
141 [('name',)]119 [('name',)]
142120
143 Primary keys are indexes too121 Primary keys are indexes too
144122
145 >>> print(_py3ish_repr(listIndexes(cur, 'a', 'aid')))123 >>> listIndexes(cur, 'a', 'aid')
146 [('aid',)]124 [('aid',)]
147125
148 Compound indexes126 Compound indexes
149127
150 >>> print(_py3ish_repr(listIndexes(cur, 'c', 'aid')))128 >>> listIndexes(cur, 'c', 'aid')
151 [('aid', 'bid')]129 [('aid', 'bid')]
152 >>> print(_py3ish_repr(listIndexes(cur, 'c', 'bid')))130 >>> listIndexes(cur, 'c', 'bid')
153 [('aid', 'bid')]131 [('aid', 'bid')]
154 >>> print(_py3ish_repr(listIndexes(cur, 'c', 'name')))132 >>> listIndexes(cur, 'c', 'name')
155 [('name', 'description')]133 [('name', 'description')]
156 >>> print(_py3ish_repr(listIndexes(cur, 'c', 'description')))134 >>> listIndexes(cur, 'c', 'description')
157 [('name', 'description')]135 [('name', 'description')]
158136
159 And any combination137 And any combination
160138
161 >>> l = listIndexes(cur, 'd', 'aid')139 >>> l = listIndexes(cur, 'd', 'aid')
162 >>> l.sort()140 >>> l.sort()
163 >>> print(_py3ish_repr(l))141 >>> l
164 [('aid',), ('aid', 'bid')]142 [('aid',), ('aid', 'bid')]
165143
166 If there are no indexes using the secified column144 If there are no indexes using the secified column
@@ -225,26 +203,26 @@ def listUniques(cur, table, column):
225203
226 Simple UNIQUE index204 Simple UNIQUE index
227205
228 >>> print(_py3ish_repr(listUniques(cur, 'b', 'aid')))206 >>> listUniques(cur, 'b', 'aid')
229 [('aid',)]207 [('aid',)]
230208
231 Primary keys are UNIQUE indexes too209 Primary keys are UNIQUE indexes too
232210
233 >>> print(_py3ish_repr(listUniques(cur, 'a', 'aid')))211 >>> listUniques(cur, 'a', 'aid')
234 [('aid',)]212 [('aid',)]
235213
236 Compound indexes214 Compound indexes
237215
238 >>> print(_py3ish_repr(listUniques(cur, 'c', 'aid')))216 >>> listUniques(cur, 'c', 'aid')
239 [('aid', 'bid')]217 [('aid', 'bid')]
240 >>> print(_py3ish_repr(listUniques(cur, 'c', 'bid')))218 >>> listUniques(cur, 'c', 'bid')
241 [('aid', 'bid')]219 [('aid', 'bid')]
242220
243 And any combination221 And any combination
244222
245 >>> l = listUniques(cur, 'd', 'aid')223 >>> l = listUniques(cur, 'd', 'aid')
246 >>> l.sort()224 >>> l.sort()
247 >>> print(_py3ish_repr(l))225 >>> l
248 [('aid',), ('aid', 'bid')]226 [('aid',), ('aid', 'bid')]
249227
250 If there are no UNIQUE indexes using the secified column228 If there are no UNIQUE indexes using the secified column
@@ -270,7 +248,7 @@ def listSequences(cur):
270 standalone.248 standalone.
271249
272 >>> for r in listSequences(cur):250 >>> for r in listSequences(cur):
273 ... print(_py3ish_repr(r))251 ... print(repr(r))
274 ('public', 'a_aid_seq', 'a', 'aid')252 ('public', 'a_aid_seq', 'a', 'aid')
275 ('public', 'standalone', None, None)253 ('public', 'standalone', None, None)
276254

Subscribers

People subscribed via source and target branches

to status/vote changes: