andrew-morris / parsedatetime

Automatically exported from code.google.com/p/parsedatetime
0 stars 0 forks source link

parse("same 3 folders") fails when locale has been set to France (fr_FR) #17

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
This one was reported to me via email by Brian K. (one of the Chandler devs)

>>> import parsedatetime.parsedatetime as pdt
>>> import parsedatetime.parsedatetime_consts as pdc
>>> c_en = pdc.Constants()
>>> c_fr = pdc.Constants('fr_FR')
>>> c_fr.localeID
'fr_FR'
>>> c_fr.Weekdays
[u'lundi', u'mardi', u'mercredi', u'jeudi', u'vendredi', u'samedi',
u'dimanche']
>>> c2.shortWeekdays
[u'lun.', u'mar.', u'mer.', u'jeu.', u'ven.', u'sam.', u'dim.']
>>> p_en = pdt.Calendar(c_en)
>>> p_en.parse("same 3 folders")
((2007, 2, 20, 22, 28, 23, 1, 51, 0), 0)
>>> p_fr = pdt.Calendar(c_fr)
>>> p_fr.parse("same 3 folders")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File
"/Users/bear/projects/parsedatetime/trunk/parsedatetime/parsedatetime.py",
line 1446, in parse
    totalTime = self._evalString(parseStr, totalTime)
  File
"/Users/bear/projects/parsedatetime/trunk/parsedatetime/parsedatetime.py",
line 1060, in _evalString
    wkdy  = self.ptc.WeekdayOffsets[s]
KeyError: 'same'

Ah, the joys of localization.  Whats happening is that "same" is matching
the shortWeekday of "sam."  Now the . in that string is coming from ICU so
it looks like we need to do two things: 1) escape regex chars and 2) add
better error trapping

Original issue reported on code.google.com by bear42 on 21 Feb 2007 at 3:38

GoogleCodeExporter commented 8 years ago
checking in a fix for this now.  basically needed to run the short names thru
re.escape() to prevent any errant regex symbols from passing thru un-escaped.

revision 63

Original comment by bear42 on 21 Feb 2007 at 6:32