[Zope-Coders] Re: [ZCM] [ZC] 89/ 4 Comment "the repr of a record is broken"

Tres Seaver tseaver@zope.com
Sun, 14 Apr 2002 13:27:28 -0400


Collector: Zope Bugs, Features, and Patches ... wrote:
> Issue #89 Update (Comment) "the repr of a record is broken"
>  Status Resolved, Zope/bug+solution low
> To followup, visit:
>   http://collector.zope.org/Zope/89
> 
> ==============================================================
> = Comment - Entry #4 by drewp on Apr 12, 2002 12:59 pm
> 
> Placing ticks around the dictionary keys
> is an incomplete solution. There is a quoting
> hazard (consider a key with this name: foo'+crash()+'foo)
> 
> I really think it should be like
> "%s: %s" % (repr(item[0]), repr(item[1]))
> so that Python will properly quote the key name. Also,
> should some other immutable make it into the record as 
> a key, the repr/repr code will continue to output the
> right thing.

Because the 'record' class exists solely to allow both attribute and
mapping access to request data marhsalled using the ':record'
modifier, we don't have to worry about arbitrarily weird cases;  the
keys *must* be valid Python identifiers (and therefor strings).

The submitted patch does not create an expression which can be
'eval'ed to create a dictionary, as the "keys" look like identifiers,
rather than string literals.  The test I added showed this problem,
which is why the checkin includes the ticks.


> ________________________________________
> = Resolve - Entry #3 by tseaver on Apr 12, 2002 12:08 pm
> 
>  Status: Pending => Resolved
> 
> Fixed on HEAD and 2.5 branch:
> 
>  http://cvs.zope.org/Zope/lib/python/ZPublisher/HTTPRequest.py.diff?r1=1.66&r2=1.67
> 
>  http://cvs.zope.org/Zope/lib/python/ZPublisher/HTTPRequest.py.diff?r1=1.61.6.1&r2=1.61.6.2
> ________________________________________
> = Comment - Entry #2 by tseaver on Apr 12, 2002 11:21 am
> 
> Attached is a test which exercises what I think is the semantic you
> want, e.g.:
> 
>  eval( repr( some_record ) ) == some_record.__dict__
> 
> If that isn't what you expected, then let me know.
> ________________________________________
> = Request - Entry #1 by Anonymous User on Dec 13, 2001 6:00 pm
> 
> The record class in HTTPRequest.py gives a repr
> that is almost a Python dictionary display, but
> can't quite be eval'd into a dictionary. 
> 
> I cannot explain the rationale behind the form Zope
> returns, nor can I prove that my version is correct
> in all cases.
> 
>    def __repr__(self):
>         L1 = self.__dict__.items()
>         L1.sort()
>         return "{"+join(map(lambda item: "%s: %s" % (repr(item[0]), repr(item[1])), L1), ", ") +"}"
> 
> 
> ==============================================================
> 
> 
> 
> _______________________________________________
> Zope-Collector-Monitor mailing list
> Zope-Collector-Monitor@zope.org
> http://lists.zope.org/mailman/listinfo/zope-collector-monitor



-- 
===============================================================
Tres Seaver                                tseaver@zope.com
Zope Corporation      "Zope Dealers"       http://www.zope.com