@@ -143,7 +143,17 @@ def __sub__(self, restriction):
143143 """
144144 inverted restriction aka antijoin
145145 """
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
147157
148158 # ------ data retrieval methods -----------
149159
@@ -190,21 +200,6 @@ def cursor(self, offset=0, limit=None, order_by=None, as_dict=False):
190200 logger .debug (sql )
191201 return self .connection .query (sql , as_dict = as_dict )
192202
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-
208203 @property
209204 def fetch1 (self ):
210205 return Fetch1 (self )
@@ -274,6 +269,9 @@ def __init__(self, arg1, arg2):
274269 self ._arg2 = Subquery (arg1 ) if arg2 .heading .computed else arg2
275270 self ._restrictions = self ._arg1 .restrictions + self ._arg2 .restrictions
276271
272+ def _repr_helper (self ):
273+ return "(%r) * (%r)" % (self ._arg1 , self ._arg2 )
274+
277275 @property
278276 def connection (self ):
279277 return self ._arg1 .connection
@@ -352,6 +350,10 @@ def _restrict(self, restriction):
352350 else :
353351 return super ()._restrict (restriction )
354352
353+ def _repr_helper (self ):
354+ # TODO: create better repr
355+ return "project(%r, %r)" % (self ._arg , self ._attributes )
356+
355357
356358class Subquery (RelationalOperand ):
357359 """
@@ -379,3 +381,6 @@ def from_clause(self):
379381 @property
380382 def heading (self ):
381383 return self ._arg .heading .resolve ()
384+
385+ def _repr_helper (self ):
386+ return "%r" % self ._arg
0 commit comments