@@ -143,7 +143,17 @@ def __sub__(self, restriction):
143
143
"""
144
144
inverted restriction aka antijoin
145
145
"""
146
- return self & Not (restriction )
146
+ return \
147
+ self & Not (restriction )
148
+
149
+ def _repr_helper (self ):
150
+ return "None"
151
+
152
+ def __repr__ (self ):
153
+ ret = self ._repr_helper ()
154
+ if self ._restrictions :
155
+ ret += ' & %r' % self ._restrictions
156
+ return ret
147
157
148
158
# ------ data retrieval methods -----------
149
159
@@ -190,21 +200,6 @@ def cursor(self, offset=0, limit=None, order_by=None, as_dict=False):
190
200
logger .debug (sql )
191
201
return self .connection .query (sql , as_dict = as_dict )
192
202
193
- def __repr__ (self ):
194
- limit = config ['display.limit' ]
195
- width = config ['display.width' ]
196
- rel = self .project (* self .heading .non_blobs ) # project out blobs
197
- template = '%%-%d.%ds' % (width , width )
198
- columns = rel .heading .names
199
- repr_string = ' ' .join ([template % column for column in columns ]) + '\n '
200
- repr_string += ' ' .join (['+' + '-' * (width - 2 ) + '+' for _ in columns ]) + '\n '
201
- for tup in rel .fetch (limit = limit ):
202
- repr_string += ' ' .join ([template % column for column in tup ]) + '\n '
203
- if len (self ) > limit :
204
- repr_string += '...\n '
205
- repr_string += ' (%d tuples)\n ' % len (self )
206
- return repr_string
207
-
208
203
@property
209
204
def fetch1 (self ):
210
205
return Fetch1 (self )
@@ -274,6 +269,9 @@ def __init__(self, arg1, arg2):
274
269
self ._arg2 = Subquery (arg1 ) if arg2 .heading .computed else arg2
275
270
self ._restrictions = self ._arg1 .restrictions + self ._arg2 .restrictions
276
271
272
+ def _repr_helper (self ):
273
+ return "(%r) * (%r)" % (self ._arg1 , self ._arg2 )
274
+
277
275
@property
278
276
def connection (self ):
279
277
return self ._arg1 .connection
@@ -352,6 +350,10 @@ def _restrict(self, restriction):
352
350
else :
353
351
return super ()._restrict (restriction )
354
352
353
+ def _repr_helper (self ):
354
+ # TODO: create better repr
355
+ return "project(%r, %r)" % (self ._arg , self ._attributes )
356
+
355
357
356
358
class Subquery (RelationalOperand ):
357
359
"""
@@ -379,3 +381,6 @@ def from_clause(self):
379
381
@property
380
382
def heading (self ):
381
383
return self ._arg .heading .resolve ()
384
+
385
+ def _repr_helper (self ):
386
+ return "%r" % self ._arg
0 commit comments