zope.i18n.format pytz usage (was Re: [Zope3-dev] XXX Roundup)

2005-12-16 Thread Gary Poster


On Dec 16, 2005, at 4:20 PM, Benji York wrote:

Gary zope/i18n/format.py:141 and 149


Yup: the pytz StaticTzInfo is being used in a non-API way, and while  
pickling works, unpickling doesn't (ew!).


Here's the interactive prompt example, if anyone cares.

 import pytz.tzinfo
 tz = pytz.tzinfo.StaticTzInfo()
 import pickle
 import datetime
 delta = datetime.timedelta(hours=-5)
 delta
datetime.timedelta(-1, 68400)
 tz._utcoffset = delta
 pickle.dumps(tz)
'cpytz\n_p\np0\n(Ntp1\nRp2\n.'
 pickle.loads(pickle.dumps(tz))
Traceback (most recent call last):
  File stdin, line 1, in ?
  File /home/gary/z4i/var/opt/python/lib/python2.4/pickle.py, line  
1394, in loads

return Unpickler(file).load()
  File /home/gary/z4i/var/opt/python/lib/python2.4/pickle.py, line  
872, in load

dispatch[key](self)
  File /home/gary/z4i/var/opt/python/lib/python2.4/pickle.py, line  
1153, in load_reduce

value = func(*args)
  File /home/gary/z4i/var/src/zope3/src/pytz/__init__.py, line  
163, in _p

return unpickler(*args)
  File /home/gary/z4i/var/src/zope3/src/pytz/tzinfo.py, line 340,  
in unpicklertz = pytz.timezone(zone)
  File /home/gary/z4i/var/src/zope3/src/pytz/__init__.py, line 47,  
in timezonezone = _munge_zone(zone)
  File /home/gary/z4i/var/src/zope3/src/pytz/__init__.py, line 71,  
in _munge_zone

return zone.replace('+', '_plus_').replace('-', '_minus_')
AttributeError: 'NoneType' object has no attribute 'replace'

This is not pytz's fault: it wasn't designed to work the way that the  
format module is using it, as Stuart points out following Philipp's  
'XXX'.


I think I can fix it by using the pytz.reference.FixedOffset class.   
That's what I'll try to do now.


Gary




___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



Re: zope.i18n.format pytz usage (was Re: [Zope3-dev] XXX Roundup)

2005-12-16 Thread Gary Poster


On Dec 16, 2005, at 4:56 PM, Gary Poster wrote:
...
I think I can fix it by using the pytz.reference.FixedOffset  
class.  That's what I'll try to do now.


BTW, let me note that this is still bad.  These things *should not*  
be persisted: they will generate lots and lots of little instances.   
Maybe the code should use a class that refuses to be persisted instead.


Another approach would be to copy over zope.app.datetimeutils into  
zope.i18n: it has already addressed the problem.


Gary
___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com