2007-06-26 Don Allingham <don@gramps-project.org>

* src/Bookmarks.py: pylint
	* src/DateEdit.py: pylint
	* src/AutoComp.py: pylint
	* src/BaseDoc.py: pylint
	* src/DateHandler/_DateParser.py: pylint
	* src/DateHandler/_Date_fi.py: pylint
	* src/DateHandler/_DateUtils.py: pylint
	* src/DateHandler/__init__.py: pylint
	* src/DateHandler/_DateDisplay.py: pylint
	* src/DateHandler/_Date_fr.py: pylint
	* src/DateHandler/_Date_es.py: pylint
	* src/DateHandler/_Date_nl.py: pylint
	* src/DateHandler/_Date_sk.py: pylint
	* src/DateHandler/_DateHandler.py: pylint
	* src/DateHandler/_Date_lt.py: pylint
	* src/DateHandler/_Date_ru.py: pylint
	* src/DateHandler/_Date_sv.py: pylint
	* src/DateHandler/_Date_de.py: pylint



svn: r8675
This commit is contained in:
Don Allingham
2007-06-27 04:50:33 +00:00
parent aee6772c66
commit 48c04f4798
19 changed files with 853 additions and 834 deletions

View File

@@ -1,3 +1,23 @@
2007-06-26 Don Allingham <don@gramps-project.org>
* src/Bookmarks.py: pylint
* src/DateEdit.py: pylint
* src/AutoComp.py: pylint
* src/BaseDoc.py: pylint
* src/DateHandler/_DateParser.py: pylint
* src/DateHandler/_Date_fi.py: pylint
* src/DateHandler/_DateUtils.py: pylint
* src/DateHandler/__init__.py: pylint
* src/DateHandler/_DateDisplay.py: pylint
* src/DateHandler/_Date_fr.py: pylint
* src/DateHandler/_Date_es.py: pylint
* src/DateHandler/_Date_nl.py: pylint
* src/DateHandler/_Date_sk.py: pylint
* src/DateHandler/_DateHandler.py: pylint
* src/DateHandler/_Date_lt.py: pylint
* src/DateHandler/_Date_ru.py: pylint
* src/DateHandler/_Date_sv.py: pylint
* src/DateHandler/_Date_de.py: pylint
2007-06-26 Alex Roitman <shura@gramps-project.org> 2007-06-26 Alex Roitman <shura@gramps-project.org>
* src/plugins/ReadGrdb.py (importData): Only copy environment if * src/plugins/ReadGrdb.py (importData): Only copy environment if
it exists. it exists.

View File

@@ -31,14 +31,6 @@ Provides autocompletion functionality.
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import locale import locale
#-------------------------------------------------------------------------
#
# set up logging
#
#-------------------------------------------------------------------------
import logging
log = logging.getLogger(".AutoComp")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GNOME modules # GNOME modules
@@ -226,34 +218,17 @@ class StandardCustomSelector:
@param val: (int,str) tuple with the values to set. @param val: (int,str) tuple with the values to set.
@type val: tuple @type val: tuple
""" """
i, s = val key, text = val
if i in self.mapping.keys() and i != self.custom_key: if key in self.mapping.keys() and key != self.custom_key:
self.store.foreach(self.set_int_value, i) self.store.foreach(self.set_int_value, key)
elif self.custom_key != None: elif self.custom_key != None:
self.selector.child.set_text(s) self.selector.child.set_text(text)
else: else:
print "StandardCustomSelector.set(): Option not available:", val print "StandardCustomSelector.set(): Option not available:", val
def set_int_value(self, model, path, iter, val): def set_int_value(self, model, path, node, val):
if model.get_value(iter, 0) == val: if model.get_value(node, 0) == val:
self.selector.set_active_iter(iter) self.selector.set_active_iter(node)
return True return True
return False return False
#-------------------------------------------------------------------------
#
# Testing code below this point
#
#-------------------------------------------------------------------------
if __name__ == "__main__":
def here(obj, event):
print s.get_values()
gtk.main_quit()
s = StandardCustomSelector({0:'abc', 1:'abd', 2:'bbe' }, None, 0, 1)
s.set_values((2, 'bbe'))
w = gtk.Dialog()
w.child.add(s.selector)
w.connect('delete-event', here)
w.show_all()
gtk.main()

View File

@@ -1013,24 +1013,24 @@ class StyleSheet:
@param obj: if not None, creates the StyleSheet from the values in @param obj: if not None, creates the StyleSheet from the values in
obj, instead of creating an empty StyleSheet obj, instead of creating an empty StyleSheet
""" """
self._para_styles = {} self.para_styles = {}
self._draw_styles = {} self.draw_styles = {}
self._table_styles = {} self.table_styles = {}
self._cell_styles = {} self.cell_styles = {}
self.name = "" self.name = ""
if obj != None: if obj != None:
for style_name in obj._para_styles.keys(): for style_name in obj.para_styles.keys():
style = obj._para_styles[style_name] style = obj.para_styles[style_name]
self._para_styles[style_name] = ParagraphStyle(style) self.para_styles[style_name] = ParagraphStyle(style)
for style_name in obj._draw_styles.keys(): for style_name in obj.draw_styles.keys():
style = obj._draw_styles[style_name] style = obj.draw_styles[style_name]
self._draw_styles[style_name] = GraphicsStyle(style) self.draw_styles[style_name] = GraphicsStyle(style)
for style_name in obj._table_styles.keys(): for style_name in obj.table_styles.keys():
style = obj._table_styles[style_name] style = obj.table_styles[style_name]
self._table_styles[style_name] = TableStyle(style) self.table_styles[style_name] = TableStyle(style)
for style_name in obj._cell_styles.keys(): for style_name in obj.cell_styles.keys():
style = obj._cell_styles[style_name] style = obj.cell_styles[style_name]
self._cell_styles[style_name] = TableCellStyle(style) self.cell_styles[style_name] = TableCellStyle(style)
def set_name(self, name): def set_name(self, name):
""" """
@@ -1048,10 +1048,10 @@ class StyleSheet:
def clear(self): def clear(self):
"Removes all styles from the StyleSheet" "Removes all styles from the StyleSheet"
self._para_styles = {} self.para_styles = {}
self._draw_styles = {} self.draw_styles = {}
self._table_styles = {} self.table_styles = {}
self._cell_styles = {} self.cell_styles = {}
def add_paragraph_style(self, name, style): def add_paragraph_style(self, name, style):
""" """
@@ -1060,7 +1060,7 @@ class StyleSheet:
@param name: The name of the ParagraphStyle @param name: The name of the ParagraphStyle
@param style: ParagraphStyle instance to be added. @param style: ParagraphStyle instance to be added.
""" """
self._para_styles[name] = ParagraphStyle(style) self.para_styles[name] = ParagraphStyle(style)
def get_paragraph_style(self, name): def get_paragraph_style(self, name):
""" """
@@ -1068,11 +1068,11 @@ class StyleSheet:
@param name: name of the ParagraphStyle that is wanted @param name: name of the ParagraphStyle that is wanted
""" """
return ParagraphStyle(self._para_styles[name]) return ParagraphStyle(self.para_styles[name])
def get_paragraph_style_names(self): def get_paragraph_style_names(self):
"Returns the the list of paragraph names in the StyleSheet" "Returns the the list of paragraph names in the StyleSheet"
return self._para_styles.keys() return self.para_styles.keys()
def add_draw_style(self, name, style): def add_draw_style(self, name, style):
""" """
@@ -1081,7 +1081,7 @@ class StyleSheet:
@param name: The name of the GraphicsStyle @param name: The name of the GraphicsStyle
@param style: GraphicsStyle instance to be added. @param style: GraphicsStyle instance to be added.
""" """
self._draw_styles[name] = GraphicsStyle(style) self.draw_styles[name] = GraphicsStyle(style)
def get_draw_style(self, name): def get_draw_style(self, name):
""" """
@@ -1089,11 +1089,11 @@ class StyleSheet:
@param name: name of the GraphicsStyle that is wanted @param name: name of the GraphicsStyle that is wanted
""" """
return GraphicsStyle(self._draw_styles[name]) return GraphicsStyle(self.draw_styles[name])
def get_draw_style_names(self): def get_draw_style_names(self):
"Returns the the list of draw style names in the StyleSheet" "Returns the the list of draw style names in the StyleSheet"
return self._draw_styles.keys() return self.draw_styles.keys()
def add_table_style(self, name, style): def add_table_style(self, name, style):
""" """
@@ -1102,7 +1102,7 @@ class StyleSheet:
@param name: The name of the TableStyle @param name: The name of the TableStyle
@param style: TableStyle instance to be added. @param style: TableStyle instance to be added.
""" """
self._table_styles[name] = TableStyle(style) self.table_styles[name] = TableStyle(style)
def get_table_style(self, name): def get_table_style(self, name):
""" """
@@ -1110,11 +1110,11 @@ class StyleSheet:
@param name: name of the TableStyle that is wanted @param name: name of the TableStyle that is wanted
""" """
return TableStyle(self._table_styles[name]) return TableStyle(self.table_styles[name])
def get_table_style_names(self): def get_table_style_names(self):
"Returns the the list of table style names in the StyleSheet" "Returns the the list of table style names in the StyleSheet"
return self._table_styles.keys() return self.table_styles.keys()
def add_cell_style(self, name, style): def add_cell_style(self, name, style):
""" """
@@ -1123,7 +1123,7 @@ class StyleSheet:
@param name: The name of the TableCellStyle @param name: The name of the TableCellStyle
@param style: TableCellStyle instance to be added. @param style: TableCellStyle instance to be added.
""" """
self._cell_styles[name] = TableCellStyle(style) self.cell_styles[name] = TableCellStyle(style)
def get_cell_style(self, name): def get_cell_style(self, name):
""" """
@@ -1131,11 +1131,11 @@ class StyleSheet:
@param name: name of the TableCellStyle that is wanted @param name: name of the TableCellStyle that is wanted
""" """
return TableCellStyle(self._cell_styles[name]) return TableCellStyle(self.cell_styles[name])
def get_cell_style_names(self): def get_cell_style_names(self):
"Returns the the list of cell style names in the StyleSheet" "Returns the the list of cell style names in the StyleSheet"
return self._cell_styles.keys() return self.cell_styles.keys()
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -1299,12 +1299,12 @@ class IndexMark:
""" """
Defines a mark to be associated with text for indexing. Defines a mark to be associated with text for indexing.
""" """
def __init__(self, key="", type=INDEX_TYPE_ALP, level=1): def __init__(self, key="", itype=INDEX_TYPE_ALP, level=1):
""" """
Initialize the object with default values, unless values are specified. Initialize the object with default values, unless values are specified.
""" """
self.key = key self.key = key
self.type = type self.type = itype
self.level = level self.level = level
#------------------------------------------------------------------------ #------------------------------------------------------------------------
@@ -1358,7 +1358,7 @@ class BaseDoc:
""" """
return StyleSheet(self._style_sheet) return StyleSheet(self._style_sheet)
def set_style_sheet(self,style_sheet): def set_style_sheet(self, style_sheet):
""" """
Sets the StyleSheet of the document. Sets the StyleSheet of the document.

View File

@@ -64,8 +64,8 @@ import Utils
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
_top = '''<ui><menubar name="MenuBar"><menu action="BookMenu">''' TOP = '''<ui><menubar name="MenuBar"><menu action="BookMenu">'''
_btm = '''</menu></menubar></ui>''' BTM = '''</menu></menubar></ui>'''
DISABLED = -1 DISABLED = -1
@@ -125,7 +125,7 @@ class Bookmarks :
def redraw(self): def redraw(self):
"""Create the pulldown menu""" """Create the pulldown menu"""
text = StringIO() text = StringIO()
text.write(_top) text.write(TOP)
self.undisplay() self.undisplay()
@@ -150,7 +150,7 @@ class Bookmarks :
text.write('</placeholder>') text.write('</placeholder>')
self.bookmarks.set(new_list) self.bookmarks.set(new_list)
text.write(_btm) text.write(BTM)
self.action_group.add_actions(actions) self.action_group.add_actions(actions)
self.uistate.uimanager.insert_action_group(self.action_group, 1) self.uistate.uimanager.insert_action_group(self.action_group, 1)
self.active = self.uistate.uimanager.add_ui_from_string(text.getvalue()) self.active = self.uistate.uimanager.add_ui_from_string(text.getvalue())
@@ -414,5 +414,8 @@ class NoteBookmarks(ListBookmarks) :
def connect_signals(self): def connect_signals(self):
self.dbstate.db.connect('note-delete', self.remove_handles) self.dbstate.db.connect('note-delete', self.remove_handles)
def make_callback(n, f): def make_callback(handle, function):
return lambda x: f(n) """
Builds a unique call to the function with the associated handle
"""
return lambda x: function(handle)

View File

@@ -90,12 +90,12 @@ QUAL_TEXT = (
(Date.QUAL_CALCULATED, _('Calculated')) ) (Date.QUAL_CALCULATED, _('Calculated')) )
CAL_TO_MONTHS_NAMES = { CAL_TO_MONTHS_NAMES = {
Date.CAL_GREGORIAN : DateHandler.displayer._MONS, Date.CAL_GREGORIAN : DateHandler.displayer.MONS,
Date.CAL_JULIAN : DateHandler.displayer._MONS, Date.CAL_JULIAN : DateHandler.displayer.MONS,
Date.CAL_HEBREW : DateHandler.displayer._hebrew, Date.CAL_HEBREW : DateHandler.displayer.hebrew,
Date.CAL_FRENCH : DateHandler.displayer._french, Date.CAL_FRENCH : DateHandler.displayer.french,
Date.CAL_PERSIAN : DateHandler.displayer._persian, Date.CAL_PERSIAN : DateHandler.displayer.persian,
Date.CAL_ISLAMIC : DateHandler.displayer._islamic } Date.CAL_ISLAMIC : DateHandler.displayer.islamic }
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #

View File

@@ -52,66 +52,66 @@ import GrampsLocale
class DateDisplay: class DateDisplay:
_months = GrampsLocale.long_months _months = GrampsLocale.long_months
_MONS = GrampsLocale.short_months MONS = GrampsLocale.short_months
_tformat = GrampsLocale.tformat _tformat = GrampsLocale.tformat
_hebrew = ( hebrew = (
"", "Tishri", "Heshvan", "Kislev", "Tevet", "Shevat", "", "Tishri", "Heshvan", "Kislev", "Tevet", "Shevat",
"AdarI", "AdarII", "Nisan", "Iyyar", "Sivan", "Tammuz", "AdarI", "AdarII", "Nisan", "Iyyar", "Sivan", "Tammuz",
"Av", "Elul" "Av", "Elul"
) )
_french = ( french = (
u'', u'',
u"Vendémiaire", u"Vendémiaire",
u'Brumaire', u'Brumaire',
u'Frimaire', u'Frimaire',
u"Nivôse", u"Nivôse",
u"Pluviôse", u"Pluviôse",
u"Ventôse", u"Ventôse",
u'Germinal', u'Germinal',
u"Floréal", u"Floréal",
u'Prairial', u'Prairial',
u'Messidor', u'Messidor',
u'Thermidor', u'Thermidor',
u'Fructidor', u'Fructidor',
u'Extra', u'Extra',
) )
_persian = ( persian = (
"", "Farvardin", "Ordibehesht", "Khordad", "Tir", "", "Farvardin", "Ordibehesht", "Khordad", "Tir",
"Mordad", "Shahrivar", "Mehr", "Aban", "Azar", "Mordad", "Shahrivar", "Mehr", "Aban", "Azar",
"Dey", "Bahman", "Esfand" "Dey", "Bahman", "Esfand"
) )
_islamic = ( islamic = (
"", "Muharram", "Safar", "Rabi`al-Awwal", "Rabi`ath-Thani", "", "Muharram", "Safar", "Rabi`al-Awwal", "Rabi`ath-Thani",
"Jumada l-Ula", "Jumada t-Tania", "Rajab", "Sha`ban", "Jumada l-Ula", "Jumada t-Tania", "Rajab", "Sha`ban",
"Ramadan", "Shawwal", "Dhu l-Qa`da", "Dhu l-Hijja" "Ramadan", "Shawwal", "Dhu l-Qa`da", "Dhu l-Hijja"
) )
formats = ("YYYY-MM-DD (ISO)",) formats = ("YYYY-MM-DD (ISO)", )
calendar = ( calendar = (
""," (Julian)"," (Hebrew)"," (French Republican)", "", " (Julian)", " (Hebrew)", " (French Republican)",
" (Persian)"," (Islamic)" " (Persian)", " (Islamic)"
) )
_mod_str = ("","before ","after ","about ","","","") _mod_str = ("", "before ", "after ", "about ", "", "", "")
_qual_str = ("","estimated ","calculated ") _qual_str = ("", "estimated ", "calculated ")
_bce_str = "%s B.C.E." _bce_str = "%s B.C.E."
def __init__(self,format=None): def __init__(self, format=None):
self.display_cal = [ self.display_cal = [
self._display_gregorian, self._display_gregorian,
self._display_julian, self._display_julian,
self._display_hebrew, self._display_hebrew,
self._display_french, self._display_french,
self._display_persian, self._display_persian,
self._display_islamic, self._display_islamic,
] ]
self.verify_format(format) self.verify_format(format)
@@ -120,13 +120,13 @@ class DateDisplay:
else: else:
self.format = format self.format = format
def set_format(self,format): def set_format(self, format):
self.format = format self.format = format
def verify_format(self,format): def verify_format(self, format):
pass pass
def quote_display(self,date): def quote_display(self, date):
""" """
Similar to the display task, except that if the value is a text only Similar to the display task, except that if the value is a text only
value, it is enclosed in quotes. value, it is enclosed in quotes.
@@ -136,7 +136,7 @@ class DateDisplay:
else: else:
return self.display(date) return self.display(date)
def display(self,date): def display(self, date):
""" """
Returns a text string representing the date. Returns a text string representing the date.
""" """
@@ -154,44 +154,45 @@ class DateDisplay:
elif mod == Date.MOD_SPAN or mod == Date.MOD_RANGE: elif mod == Date.MOD_SPAN or mod == Date.MOD_RANGE:
d1 = self.display_iso(start) d1 = self.display_iso(start)
d2 = self.display_iso(date.get_stop_date()) d2 = self.display_iso(date.get_stop_date())
return "%s %s - %s%s" % (qual_str,d1,d2,self.calendar[cal]) return "%s %s - %s%s" % (qual_str, d1, d2, self.calendar[cal])
else: else:
text = self.display_iso(start) text = self.display_iso(start)
return "%s%s%s%s" % (qual_str,self._mod_str[mod],text,self.calendar[cal]) return "%s%s%s%s" % (qual_str, self._mod_str[mod], text,
self.calendar[cal])
def _slash_year(self,val,slash): def _slash_year(self, val, slash):
if val < 0: if val < 0:
val = - val val = - val
if slash: if slash:
if val % 100 == 99: if val % 100 == 99:
year = "%d/%d" % (val,(val%1000)+1) year = "%d/%d" % (val, (val%1000)+1)
elif val % 10 == 9: elif val % 10 == 9:
year = "%d/%d" % (val,(val%100)+1) year = "%d/%d" % (val, (val%100)+1)
else: else:
year = "%d/%d" % (val,(val%10)+1) year = "%d/%d" % (val, (val%10)+1)
else: else:
year = "%d" % (val) year = "%d" % (val)
return year return year
def display_iso(self,date_val): def display_iso(self, date_val):
# YYYY-MM-DD (ISO) # YYYY-MM-DD (ISO)
year = self._slash_year(date_val[2],date_val[3]) year = self._slash_year(date_val[2], date_val[3])
# FIXME: This prodices 1789-11-00 and 1789-00-00 for incomplete dates. # FIXME: This prodices 1789-11-00 and 1789-00-00 for incomplete dates.
if False:#date_val[0] == 0: if False:#date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
else: else:
value = "%s-%02d" % (year,date_val[1]) value = "%s-%02d" % (year, date_val[1])
else: else:
value = "%s-%02d-%02d" % (year,date_val[1],date_val[0]) value = "%s-%02d-%02d" % (year, date_val[1], date_val[0])
if date_val[2] < 0: if date_val[2] < 0:
return self._bce_str % value return self._bce_str % value
else: else:
return value return value
def text_display(self,date): def text_display(self, date):
""" """
Similar to the display task, except that if the value is a text only Similar to the display task, except that if the value is a text only
value, it is enclosed in quotes. value, it is enclosed in quotes.
@@ -199,8 +200,8 @@ class DateDisplay:
return date.get_text() return date.get_text()
def _display_gregorian(self,date_val): def _display_gregorian(self, date_val):
year = self._slash_year(date_val[2],date_val[3]) year = self._slash_year(date_val[2], date_val[3])
if self.format == 0: if self.format == 0:
return self.display_iso(date_val) return self.display_iso(date_val)
elif self.format == 1: elif self.format == 1:
@@ -210,56 +211,59 @@ class DateDisplay:
if date_val[0] == 0 and date_val[1] == 0: if date_val[0] == 0 and date_val[1] == 0:
value = str(date_val[2]) value = str(date_val[2])
else: else:
value = self._tformat.replace('%m',str(date_val[1])) value = self._tformat.replace('%m', str(date_val[1]))
value = value.replace('%d',str(date_val[0])) value = value.replace('%d', str(date_val[0]))
value = value.replace('%Y',str(abs(date_val[2]))) value = value.replace('%Y', str(abs(date_val[2])))
value = value.replace('-','/') value = value.replace('-', '/')
elif self.format == 2: elif self.format == 2:
# Month Day, Year # Month Day, Year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
else: else:
value = "%s %s" % (self._months[date_val[1]],year) value = "%s %s" % (self._months[date_val[1]], year)
else: else:
value = "%s %d, %s" % (self._months[date_val[1]],date_val[0],year) value = "%s %d, %s" % (self._months[date_val[1]],
date_val[0], year)
elif self.format == 3: elif self.format == 3:
# MON Day, Year # MON Day, Year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
else: else:
value = "%s %s" % (self._MONS[date_val[1]],year) value = "%s %s" % (self.MONS[date_val[1]], year)
else: else:
value = "%s %d, %s" % (self._MONS[date_val[1]],date_val[0],year) value = "%s %d, %s" % (self.MONS[date_val[1]],
date_val[0], year)
elif self.format == 4: elif self.format == 4:
# Day Month Year # Day Month Year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
else: else:
value = "%s %s" % (self._months[date_val[1]],year) value = "%s %s" % (self._months[date_val[1]], year)
else: else:
value = "%d %s %s" % (date_val[0],self._months[date_val[1]],year) value = "%d %s %s" % (date_val[0], self._months[date_val[1]],
year)
else: else:
# Day MON Year # Day MON Year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
else: else:
value = "%s %s" % (self._MONS[date_val[1]],year) value = "%s %s" % (self.MONS[date_val[1]], year)
else: else:
value = "%d %s %s" % (date_val[0],self._MONS[date_val[1]],year) value = "%d %s %s" % (date_val[0], self.MONS[date_val[1]], year)
if date_val[2] < 0: if date_val[2] < 0:
return self._bce_str % value return self._bce_str % value
else: else:
return value return value
def _display_julian(self,date_val): def _display_julian(self, date_val):
# Julian date display is the same as Gregorian # Julian date display is the same as Gregorian
return self._display_gregorian(date_val) return self._display_gregorian(date_val)
def _display_calendar(self,date_val,month_list): def _display_calendar(self, date_val, month_list):
year = abs(date_val[2]) year = abs(date_val[2])
if self.format == 0 or self.format == 1: if self.format == 0 or self.format == 1:
return self.display_iso(date_val) return self.display_iso(date_val)
@@ -268,15 +272,15 @@ class DateDisplay:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
else: else:
value = u"%s %d" % (month_list[date_val[1]],year) value = u"%s %d" % (month_list[date_val[1]], year)
else: else:
value = u"%s %d, %s" % (month_list[date_val[1]],date_val[0],year) value = u"%s %d, %s" % (month_list[date_val[1]], date_val[0], year)
if date_val[2] < 0: if date_val[2] < 0:
return self._bce_str % value return self._bce_str % value
else: else:
return value return value
def _display_french(self,date_val): def _display_french(self, date_val):
year = abs(date_val[2]) year = abs(date_val[2])
if self.format == 0 or self.format == 1: if self.format == 0 or self.format == 1:
return self.display_iso(date_val) return self.display_iso(date_val)
@@ -285,22 +289,22 @@ class DateDisplay:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
else: else:
value = u"%s %d" % (self._french[date_val[1]],year) value = u"%s %d" % (self.french[date_val[1]], year)
else: else:
value = u"%d %s %s" % (date_val[0],self._french[date_val[1]],year) value = u"%d %s %s" % (date_val[0], self.french[date_val[1]], year)
if date_val[2] < 0: if date_val[2] < 0:
return self._bce_str % value return self._bce_str % value
else: else:
return value return value
def _display_hebrew(self,date_val): def _display_hebrew(self, date_val):
return self._display_calendar(date_val,self._hebrew) return self._display_calendar(date_val, self.hebrew)
def _display_persian(self,date_val): def _display_persian(self, date_val):
return self._display_calendar(date_val,self._persian) return self._display_calendar(date_val, self.persian)
def _display_islamic(self,date_val): def _display_islamic(self, date_val):
return self._display_calendar(date_val,self._islamic) return self._display_calendar(date_val, self.islamic)
class DateDisplayEn(DateDisplay): class DateDisplayEn(DateDisplay):
""" """
@@ -308,20 +312,20 @@ class DateDisplayEn(DateDisplay):
""" """
formats = ( formats = (
"YYYY-MM-DD (ISO)", "Numerical", "Month Day, Year", "YYYY-MM-DD (ISO)", "Numerical", "Month Day, Year",
"MON DAY, YEAR", "Day Month Year", "DAY MON YEAR" "MON DAY, YEAR", "Day Month Year", "DAY MON YEAR"
) )
def __init__(self,format=None): def __init__(self, format=None):
""" """
Creates a DateDisplay class that converts a Date object to a string Creates a DateDisplay class that converts a Date object to a string
of the desired format. The format value must correspond to the format of the desired format. The format value must correspond to the format
list value (DateDisplay.format[]). list value (DateDisplay.format[]).
""" """
DateDisplay.__init__(self,format) DateDisplay.__init__(self, format)
def display(self,date): def display(self, date):
""" """
Returns a text string representing the date. Returns a text string representing the date.
""" """
@@ -339,13 +343,13 @@ class DateDisplayEn(DateDisplay):
elif mod == Date.MOD_SPAN: elif mod == Date.MOD_SPAN:
d1 = self.display_cal[cal](start) d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date()) d2 = self.display_cal[cal](date.get_stop_date())
return "%sfrom %s to %s%s" % (qual_str,d1,d2,self.calendar[cal]) return "%sfrom %s to %s%s" % (qual_str, d1, d2, self.calendar[cal])
elif mod == Date.MOD_RANGE: elif mod == Date.MOD_RANGE:
d1 = self.display_cal[cal](start) d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date()) d2 = self.display_cal[cal](date.get_stop_date())
return "%sbetween %s and %s%s" % (qual_str,d1,d2, return "%sbetween %s and %s%s" % (qual_str, d1, d2,
self.calendar[cal]) self.calendar[cal])
else: else:
text = self.display_cal[date.get_calendar()](start) text = self.display_cal[date.get_calendar()](start)
return "%s%s%s%s" % (qual_str,self._mod_str[mod], return "%s%s%s%s" % (qual_str, self._mod_str[mod],
text,self.calendar[cal]) text, self.calendar[cal])

View File

@@ -52,18 +52,18 @@ from _DateDisplay import DateDisplay, DateDisplayEn
# Constants # Constants
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
_lang = locale.getlocale(locale.LC_TIME)[0] LANG = locale.getlocale(locale.LC_TIME)[0]
if _lang: if LANG:
_lang_short = _lang.split('_')[0] LANG_SHORT = LANG.split('_')[0]
else: else:
_lang_short = "C" LANG_SHORT = "C"
_lang_to_parser = { LANG_TO_PARSER = {
'C' : DateParser, 'C' : DateParser,
'en' : DateParser, 'en' : DateParser,
} }
_lang_to_display = { LANG_TO_DISPLAY = {
'C' : DateDisplayEn, 'C' : DateDisplayEn,
'en' : DateDisplayEn, 'en' : DateDisplayEn,
'zh_CN' : DateDisplay, 'zh_CN' : DateDisplay,
@@ -89,5 +89,5 @@ def register_datehandler(locales,parse_class,display_class):
@type display_class: DateDisplay @type display_class: DateDisplay
""" """
for lang_str in locales: for lang_str in locales:
_lang_to_parser[lang_str] = parse_class LANG_TO_PARSER[lang_str] = parse_class
_lang_to_display[lang_str] = display_class LANG_TO_DISPLAY[lang_str] = display_class

View File

@@ -92,7 +92,7 @@ class DateParser:
_fmt_parse = re.compile(".*%(\S).*%(\S).*%(\S).*") _fmt_parse = re.compile(".*%(\S).*%(\S).*%(\S).*")
# RFC-2822 only uses capitalized English abbreviated names, no locales. # RFC-2822 only uses capitalized English abbreviated names, no locales.
_rfc_days = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat') _rfc_days = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat')
_rfc_mons_to_int = { _rfc_mons_to_int = {
'Jan' : 1, 'Feb' : 2, 'Mar' : 3, 'Apr' : 4, 'Jan' : 1, 'Feb' : 2, 'Mar' : 3, 'Apr' : 4,
'May' : 5, 'Jun' : 6, 'Jul' : 7, 'Aug' : 8, 'May' : 5, 'Jun' : 6, 'Jul' : 7, 'Aug' : 8,
@@ -200,8 +200,8 @@ class DateParser:
fmt = GrampsLocale.tformat fmt = GrampsLocale.tformat
match = self._fmt_parse.match(fmt.lower()) match = self._fmt_parse.match(fmt.lower())
if match: if match:
self.dmy = (match.groups() == ('d','m','y')) self.dmy = (match.groups() == ('d', 'm', 'y'))
self.ymd = (match.groups() == ('y','m','d')) self.ymd = (match.groups() == ('y', 'm', 'd'))
else: else:
self.dmy = True self.dmy = True
self.ymd = False self.ymd = False
@@ -213,7 +213,7 @@ class DateParser:
are quoted. are quoted.
""" """
keys.sort(lambda x, y: cmp(len(y), len(x))) keys.sort(lambda x, y: cmp(len(y), len(x)))
return '(' + '|'.join([key.replace('.','\.') for key in keys]) + ')' return '(' + '|'.join([key.replace('.', '\.') for key in keys]) + ')'
def init_strings(self): def init_strings(self):
""" """
@@ -248,45 +248,45 @@ class DateParser:
self._bce_re = re.compile("(.*)\s+%s( ?.*)" % self._bce_str) self._bce_re = re.compile("(.*)\s+%s( ?.*)" % self._bce_str)
self._cal = re.compile("(.*)\s+\(%s\)( ?.*)" % self._cal_str, self._cal = re.compile("(.*)\s+\(%s\)( ?.*)" % self._cal_str,
re.IGNORECASE) re.IGNORECASE)
self._qual = re.compile("(.* ?)%s\s+(.+)" % self._qual_str, self._qual = re.compile("(.* ?)%s\s+(.+)" % self._qual_str,
re.IGNORECASE) re.IGNORECASE)
self._span = re.compile("(from)\s+(?P<start>.+)\s+to\s+(?P<stop>.+)", self._span = re.compile("(from)\s+(?P<start>.+)\s+to\s+(?P<stop>.+)",
re.IGNORECASE) re.IGNORECASE)
self._range = re.compile("(bet|bet.|between)\s+(?P<start>.+)\s+and\s+(?P<stop>.+)", self._range = re.compile("(bet|bet.|between)\s+(?P<start>.+)\s+and\s+(?P<stop>.+)",
re.IGNORECASE) re.IGNORECASE)
self._modifier = re.compile('%s\s+(.*)' % self._mod_str, self._modifier = re.compile('%s\s+(.*)' % self._mod_str,
re.IGNORECASE) re.IGNORECASE)
self._modifier_after = re.compile('(.*)\s+%s' % self._mod_after_str, self._modifier_after = re.compile('(.*)\s+%s' % self._mod_after_str,
re.IGNORECASE) re.IGNORECASE)
self._abt2 = re.compile('<(.*)>',re.IGNORECASE) self._abt2 = re.compile('<(.*)>', re.IGNORECASE)
self._text = re.compile('%s\s+(\d+)?\s*,?\s*((\d+)(/\d+)?)?\s*$' % self._mon_str, self._text = re.compile('%s\s+(\d+)?\s*,?\s*((\d+)(/\d+)?)?\s*$' % self._mon_str,
re.IGNORECASE) re.IGNORECASE)
self._text2 = re.compile('(\d+)?\s+?%s\s*((\d+)(/\d+)?)?\s*$' % self._mon_str, self._text2 = re.compile('(\d+)?\s+?%s\s*((\d+)(/\d+)?)?\s*$' % self._mon_str,
re.IGNORECASE) re.IGNORECASE)
self._jtext = re.compile('%s\s+(\d+)?\s*,?\s*((\d+)(/\d+)?)?\s*$' % self._jmon_str, self._jtext = re.compile('%s\s+(\d+)?\s*,?\s*((\d+)(/\d+)?)?\s*$' % self._jmon_str,
re.IGNORECASE) re.IGNORECASE)
self._jtext2 = re.compile('(\d+)?\s+?%s\s*((\d+)(/\d+)?)?\s*$' % self._jmon_str, self._jtext2 = re.compile('(\d+)?\s+?%s\s*((\d+)(/\d+)?)?\s*$' % self._jmon_str,
re.IGNORECASE) re.IGNORECASE)
self._ftext = re.compile('%s\s+(\d+)?\s*,?\s*((\d+)(/\d+)?)?\s*$' % self._fmon_str, self._ftext = re.compile('%s\s+(\d+)?\s*,?\s*((\d+)(/\d+)?)?\s*$' % self._fmon_str,
re.IGNORECASE) re.IGNORECASE)
self._ftext2 = re.compile('(\d+)?\s+?%s\s*((\d+)(/\d+)?)?\s*$' % self._fmon_str, self._ftext2 = re.compile('(\d+)?\s+?%s\s*((\d+)(/\d+)?)?\s*$' % self._fmon_str,
re.IGNORECASE) re.IGNORECASE)
self._ptext = re.compile('%s\s+(\d+)?\s*,?\s*((\d+)(/\d+)?)?\s*$' % self._pmon_str, self._ptext = re.compile('%s\s+(\d+)?\s*,?\s*((\d+)(/\d+)?)?\s*$' % self._pmon_str,
re.IGNORECASE) re.IGNORECASE)
self._ptext2 = re.compile('(\d+)?\s+?%s\s*((\d+)(/\d+)?)?\s*$' % self._pmon_str, self._ptext2 = re.compile('(\d+)?\s+?%s\s*((\d+)(/\d+)?)?\s*$' % self._pmon_str,
re.IGNORECASE) re.IGNORECASE)
self._itext = re.compile('%s\s+(\d+)?\s*,?\s*((\d+)(/\d+)?)?\s*$' % self._imon_str, self._itext = re.compile('%s\s+(\d+)?\s*,?\s*((\d+)(/\d+)?)?\s*$' % self._imon_str,
re.IGNORECASE) re.IGNORECASE)
self._itext2 = re.compile('(\d+)?\s+?%s\s*((\d+)(/\d+)?)?\s*$' % self._imon_str, self._itext2 = re.compile('(\d+)?\s+?%s\s*((\d+)(/\d+)?)?\s*$' % self._imon_str,
re.IGNORECASE) re.IGNORECASE)
self._numeric = re.compile("((\d+)[/\.]\s*)?((\d+)[/\.]\s*)?(\d+)\s*$") self._numeric = re.compile("((\d+)[/\.]\s*)?((\d+)[/\.]\s*)?(\d+)\s*$")
self._iso = re.compile("(\d+)(/(\d+))?-(\d+)-(\d+)\s*$") self._iso = re.compile("(\d+)(/(\d+))?-(\d+)-(\d+)\s*$")
self._rfc = re.compile("(%s,)?\s+(\d|\d\d)\s+%s\s+(\d+)\s+\d\d:\d\d(:\d\d)?\s+(\+|-)\d\d\d\d" self._rfc = re.compile("(%s,)?\s+(\d|\d\d)\s+%s\s+(\d+)\s+\d\d:\d\d(:\d\d)?\s+(\+|-)\d\d\d\d"
% (self._rfc_day_str,self._rfc_mon_str)) % (self._rfc_day_str, self._rfc_mon_str))
def _get_int(self,val): def _get_int(self, val):
""" """
Converts the string to an integer if the value is not None. If the Converts the string to an integer if the value is not None. If the
value is None, a zero is returned value is None, a zero is returned
@@ -296,27 +296,27 @@ class DateParser:
else: else:
return int(val) return int(val)
def _parse_hebrew(self,text): def _parse_hebrew(self, text):
return self._parse_calendar(text,self._jtext,self._jtext2, return self._parse_calendar(text, self._jtext, self._jtext2,
self.hebrew_to_int) self.hebrew_to_int)
def _parse_islamic(self,text): def _parse_islamic(self, text):
return self._parse_calendar(text,self._itext,self._itext2, return self._parse_calendar(text, self._itext, self._itext2,
self.islamic_to_int) self.islamic_to_int)
def _parse_persian(self,text): def _parse_persian(self, text):
return self._parse_calendar(text,self._ptext,self._ptext2, return self._parse_calendar(text, self._ptext, self._ptext2,
self.persian_to_int) self.persian_to_int)
def _parse_french(self,text): def _parse_french(self, text):
return self._parse_calendar(text,self._ftext,self._ftext2, return self._parse_calendar(text, self._ftext, self._ftext2,
self.french_to_int) self.french_to_int)
def _parse_greg_julian(self,text): def _parse_greg_julian(self, text):
return self._parse_calendar(text,self._text,self._text2, return self._parse_calendar(text, self._text, self._text2,
self.month_to_int,gregorian_valid) self.month_to_int, gregorian_valid)
def _parse_calendar(self,text,regex1,regex2,mmap,check=None): def _parse_calendar(self, text, regex1, regex2, mmap, check=None):
match = regex1.match(text.lower()) match = regex1.match(text.lower())
if match: if match:
groups = match.groups() groups = match.groups()
@@ -333,8 +333,8 @@ class DateParser:
d = self._get_int(groups[1]) d = self._get_int(groups[1])
y = int(groups[3]) y = int(groups[3])
s = groups[4] != None s = groups[4] != None
value = (d,m,y,s) value = (d, m, y, s)
if check and not check((d,m,y)): if check and not check((d, m, y)):
value = Date.EMPTY value = Date.EMPTY
return value return value
@@ -354,14 +354,14 @@ class DateParser:
else: else:
y = int(groups[3]) y = int(groups[3])
s = groups[4] != None s = groups[4] != None
value = (d,m,y,s) value = (d, m, y, s)
if check and not check((d,m,y)): if check and not check((d, m, y)):
value = Date.EMPTY value = Date.EMPTY
return value return value
return Date.EMPTY return Date.EMPTY
def _parse_subdate(self,text,subparser=None): def _parse_subdate(self, text, subparser=None):
""" """
Converts only the date portion of a date. Converts only the date portion of a date.
""" """
@@ -383,12 +383,12 @@ class DateParser:
y = self._get_int(groups[0]) y = self._get_int(groups[0])
m = self._get_int(groups[3]) m = self._get_int(groups[3])
d = self._get_int(groups[4]) d = self._get_int(groups[4])
if check and not check((d,m,y)): if check and not check((d, m, y)):
return Date.EMPTY return Date.EMPTY
if groups[2]: if groups[2]:
return (d,m,y,True) return (d, m, y, True)
else: else:
return (d,m,y,False) return (d, m, y, False)
match = self._rfc.match(text) match = self._rfc.match(text)
if match: if match:
@@ -396,8 +396,8 @@ class DateParser:
d = self._get_int(groups[2]) d = self._get_int(groups[2])
m = self._rfc_mons_to_int[groups[3]] m = self._rfc_mons_to_int[groups[3]]
y = self._get_int(groups[4]) y = self._get_int(groups[4])
value = (d,m,y,False) value = (d, m, y, False)
if check and not check((d,m,y)): if check and not check((d, m, y)):
value = Date.EMPTY value = Date.EMPTY
return value return value
@@ -422,14 +422,14 @@ class DateParser:
else: else:
m = self._get_int(groups[1]) m = self._get_int(groups[1])
d = self._get_int(groups[3]) d = self._get_int(groups[3])
value = (d,m,y,False) value = (d, m, y, False)
if check and not check((d,m,y)): if check and not check((d, m, y)):
value = Date.EMPTY value = Date.EMPTY
return value return value
return Date.EMPTY return Date.EMPTY
def match_calendar(self,text,cal): def match_calendar(self, text, cal):
""" """
Try parsing calendar. Try parsing calendar.
@@ -439,9 +439,9 @@ class DateParser:
if match: if match:
cal = self.calendar_to_int[match.group(2).lower()] cal = self.calendar_to_int[match.group(2).lower()]
text = match.group(1) + match.group(3) text = match.group(1) + match.group(3)
return (text,cal) return (text, cal)
def match_quality(self,text,qual): def match_quality(self, text, qual):
""" """
Try matching quality. Try matching quality.
@@ -451,9 +451,9 @@ class DateParser:
if match: if match:
qual = self.quality_to_int[match.group(2).lower()] qual = self.quality_to_int[match.group(2).lower()]
text = match.group(1) + match.group(3) text = match.group(1) + match.group(3)
return (text,qual) return (text, qual)
def match_span(self,text,cal,qual,date): def match_span(self, text, cal, qual, date):
""" """
Try matching span date. Try matching span date.
@@ -462,21 +462,21 @@ class DateParser:
match = self._span.match(text) match = self._span.match(text)
if match: if match:
text_parser = self.parser[cal] text_parser = self.parser[cal]
(text1,bc1) = self.match_bce(match.group('start')) (text1, bc1) = self.match_bce(match.group('start'))
start = self._parse_subdate(text1,text_parser) start = self._parse_subdate(text1, text_parser)
if bc1: if bc1:
start = self.invert_year(start) start = self.invert_year(start)
(text2,bc2) = self.match_bce(match.group('stop')) (text2, bc2) = self.match_bce(match.group('stop'))
stop = self._parse_subdate(text2,text_parser) stop = self._parse_subdate(text2, text_parser)
if bc2: if bc2:
stop = self.invert_year(stop) stop = self.invert_year(stop)
date.set(qual,Date.MOD_SPAN,cal,start + stop) date.set(qual, Date.MOD_SPAN, cal, start + stop)
return 1 return 1
return 0 return 0
def match_range(self,text,cal,qual,date): def match_range(self, text, cal, qual, date):
""" """
Try matching range date. Try matching range date.
@@ -485,21 +485,21 @@ class DateParser:
match = self._range.match(text) match = self._range.match(text)
if match: if match:
text_parser = self.parser[cal] text_parser = self.parser[cal]
(text1,bc1) = self.match_bce(match.group('start')) (text1, bc1) = self.match_bce(match.group('start'))
start = self._parse_subdate(text1,text_parser) start = self._parse_subdate(text1, text_parser)
if bc1: if bc1:
start = self.invert_year(start) start = self.invert_year(start)
(text2,bc2) = self.match_bce(match.group('stop')) (text2, bc2) = self.match_bce(match.group('stop'))
stop = self._parse_subdate(text2,text_parser) stop = self._parse_subdate(text2, text_parser)
if bc2: if bc2:
stop = self.invert_year(stop) stop = self.invert_year(stop)
date.set(qual,Date.MOD_RANGE,cal,start + stop) date.set(qual, Date.MOD_RANGE, cal, start + stop)
return 1 return 1
return 0 return 0
def match_bce(self,text): def match_bce(self, text):
""" """
Try matching BCE qualifier. Try matching BCE qualifier.
@@ -514,9 +514,9 @@ class DateParser:
except: except:
print "MATCH:", match.groups() print "MATCH:", match.groups()
bc = True bc = True
return (text,bc) return (text, bc)
def match_modifier(self,text,cal,qual,bc,date): def match_modifier(self, text, cal, qual, bc, date):
""" """
Try matching date with modifier. Try matching date with modifier.
@@ -529,9 +529,9 @@ class DateParser:
start = self._parse_subdate(grps[1], self.parser[cal]) start = self._parse_subdate(grps[1], self.parser[cal])
mod = self.modifier_to_int.get(grps[0].lower(), Date.MOD_NONE) mod = self.modifier_to_int.get(grps[0].lower(), Date.MOD_NONE)
if bc: if bc:
date.set(qual,mod,cal,self.invert_year(start)) date.set(qual, mod, cal, self.invert_year(start))
else: else:
date.set(qual,mod,cal,start) date.set(qual, mod, cal, start)
return True return True
# modifiers after the date # modifiers after the date
if self.modifier_after_to_int: if self.modifier_after_to_int:
@@ -542,9 +542,9 @@ class DateParser:
mod = self.modifier_after_to_int.get(grps[1].lower(), mod = self.modifier_after_to_int.get(grps[1].lower(),
Date.MOD_NONE) Date.MOD_NONE)
if bc: if bc:
date.set(qual,mod,cal,self.invert_year(start)) date.set(qual, mod, cal, self.invert_year(start))
else: else:
date.set(qual,mod,cal,start) date.set(qual, mod, cal, start)
return True return True
match = self._abt2.match(text) match = self._abt2.match(text)
if match: if match:
@@ -552,13 +552,13 @@ class DateParser:
start = self._parse_subdate(grps[0]) start = self._parse_subdate(grps[0])
mod = Date.MOD_ABOUT mod = Date.MOD_ABOUT
if bc: if bc:
date.set(qual,mod,cal,self.invert_year(start)) date.set(qual, mod, cal, self.invert_year(start))
else: else:
date.set(qual,mod,cal,start) date.set(qual, mod, cal, start)
return True return True
return False return False
def set_date(self,date,text): def set_date(self, date, text):
""" """
Parses the text and sets the date according to the parsing. Parses the text and sets the date according to the parsing.
""" """
@@ -567,20 +567,20 @@ class DateParser:
qual = Date.QUAL_NONE qual = Date.QUAL_NONE
cal = Date.CAL_GREGORIAN cal = Date.CAL_GREGORIAN
(text,cal) = self.match_calendar(text,cal) (text, cal) = self.match_calendar(text, cal)
(text,qual) = self.match_quality(text,qual) (text, qual) = self.match_quality(text, qual)
if self.match_span(text,cal,qual,date): if self.match_span(text, cal, qual, date):
return return
if self.match_range(text,cal,qual,date): if self.match_range(text, cal, qual, date):
return return
(text,bc) = self.match_bce(text) (text, bc) = self.match_bce(text)
if self.match_modifier(text,cal,qual,bc,date): if self.match_modifier(text, cal, qual, bc, date):
return return
try: try:
subdate = self._parse_subdate(text,self.parser[cal]) subdate = self._parse_subdate(text, self.parser[cal])
if subdate == Date.EMPTY and text != "": if subdate == Date.EMPTY and text != "":
date.set_as_text(text) date.set_as_text(text)
return return
@@ -589,20 +589,20 @@ class DateParser:
return return
if bc: if bc:
date.set(qual,Date.MOD_NONE,cal,self.invert_year(subdate)) date.set(qual, Date.MOD_NONE, cal, self.invert_year(subdate))
else: else:
date.set(qual,Date.MOD_NONE,cal,subdate) date.set(qual, Date.MOD_NONE, cal, subdate)
def invert_year(self,subdate): def invert_year(self, subdate):
return (subdate[0],subdate[1],-subdate[2],subdate[3]) return (subdate[0], subdate[1], -subdate[2], subdate[3])
def parse(self,text): def parse(self, text):
""" """
Parses the text, returning a Date object. Parses the text, returning a Date object.
""" """
new_date = Date() new_date = Date()
try: try:
self.set_date(new_date,text) self.set_date(new_date, text)
except DateError: except DateError:
new_date.set_as_text(text) new_date.set_as_text(text)
return new_date return new_date

View File

@@ -29,7 +29,7 @@ Class handling language-specific selection for date parser and displayer.
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from DateHandler import _lang_to_display, _lang, parser, displayer from DateHandler import LANG_TO_DISPLAY, LANG, parser, displayer
#-------------------------------------------------------------- #--------------------------------------------------------------
# #
@@ -41,9 +41,9 @@ def get_date_formats():
Returns the lists supported formats for date parsers and displayers Returns the lists supported formats for date parsers and displayers
""" """
try: try:
return _lang_to_display[_lang].formats return LANG_TO_DISPLAY[LANG].formats
except: except:
return _lang_to_display["C"].formats return LANG_TO_DISPLAY["C"].formats
def set_format(value): def set_format(value):
try: try:

View File

@@ -9,7 +9,7 @@
# the Free Software Foundation; either version 2 of the License, or # the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. # (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
@@ -79,49 +79,51 @@ class DateParserDE(DateParser):
modifier_to_int = { modifier_to_int = {
u'vor' : Date.MOD_BEFORE, u'vor' : Date.MOD_BEFORE,
u'nach' : Date.MOD_AFTER, u'nach' : Date.MOD_AFTER,
u'gegen' : Date.MOD_ABOUT, u'gegen' : Date.MOD_ABOUT,
u'um' : Date.MOD_ABOUT, u'um' : Date.MOD_ABOUT,
u'etwa' : Date.MOD_ABOUT, u'etwa' : Date.MOD_ABOUT,
u'circa' : Date.MOD_ABOUT, u'circa' : Date.MOD_ABOUT,
u'ca.' : Date.MOD_ABOUT, u'ca.' : Date.MOD_ABOUT,
} }
calendar_to_int = { calendar_to_int = {
u'gregorianisch' : Date.CAL_GREGORIAN, u'gregorianisch' : Date.CAL_GREGORIAN,
u'greg.' : Date.CAL_GREGORIAN, u'greg.' : Date.CAL_GREGORIAN,
u'julianisch' : Date.CAL_JULIAN, u'julianisch' : Date.CAL_JULIAN,
u'jul.' : Date.CAL_JULIAN, u'jul.' : Date.CAL_JULIAN,
u'hebräisch' : Date.CAL_HEBREW, u'hebräisch' : Date.CAL_HEBREW,
u'hebr.' : Date.CAL_HEBREW, u'hebr.' : Date.CAL_HEBREW,
u'islamisch' : Date.CAL_ISLAMIC, u'islamisch' : Date.CAL_ISLAMIC,
u'isl.' : Date.CAL_ISLAMIC, u'isl.' : Date.CAL_ISLAMIC,
u'französisch republikanisch': Date.CAL_FRENCH, u'französisch republikanisch': Date.CAL_FRENCH,
u'franz.' : Date.CAL_FRENCH, u'franz.' : Date.CAL_FRENCH,
u'persisch' : Date.CAL_PERSIAN, u'persisch' : Date.CAL_PERSIAN,
} }
quality_to_int = { quality_to_int = {
u'geschätzt' : Date.QUAL_ESTIMATED, u'geschätzt' : Date.QUAL_ESTIMATED,
u'gesch.' : Date.QUAL_ESTIMATED, u'gesch.' : Date.QUAL_ESTIMATED,
u'errechnet' : Date.QUAL_CALCULATED, u'errechnet' : Date.QUAL_CALCULATED,
u'berechnet' : Date.QUAL_CALCULATED, u'berechnet' : Date.QUAL_CALCULATED,
u'ber.' : Date.QUAL_CALCULATED, u'ber.' : Date.QUAL_CALCULATED,
} }
bce = ["vor unserer Zeitrechnung", "vor unserer Zeit", bce = ["vor unserer Zeitrechnung", "vor unserer Zeit",
"vor der Zeitrechnung", "vor der Zeit", "vor der Zeitrechnung", "vor der Zeit",
"v. u. Z.", "v. d. Z.", "v.u.Z.", "v.d.Z.", "v. u. Z.", "v. d. Z.", "v.u.Z.", "v.d.Z.",
"vor Christi Geburt", "vor Christus", "v. Chr."] + DateParser.bce "vor Christi Geburt", "vor Christus", "v. Chr."] + DateParser.bce
def init_strings(self): def init_strings(self):
DateParser.init_strings(self) DateParser.init_strings(self)
self._span = re.compile("(von|vom)\s+(?P<start>.+)\s+(bis)\s+(?P<stop>.+)",re.IGNORECASE) self._span = re.compile("(von|vom)\s+(?P<start>.+)\s+(bis)\s+(?P<stop>.+)",
self._range = re.compile("zwischen\s+(?P<start>.+)\s+und\s+(?P<stop>.+)", re.IGNORECASE) re.IGNORECASE)
self._text2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._mon_str, self._range = re.compile("zwischen\s+(?P<start>.+)\s+und\s+(?P<stop>.+)",
re.IGNORECASE) re.IGNORECASE)
self._jtext2= re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._jmon_str, self._text2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._mon_str,
re.IGNORECASE) re.IGNORECASE)
self._jtext2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._jmon_str,
re.IGNORECASE)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -135,19 +137,19 @@ class DateDisplayDE(DateDisplay):
u" (französisch republikanisch)", u" (persisch)", u" (islamisch)" u" (französisch republikanisch)", u" (persisch)", u" (islamisch)"
) )
_mod_str = ("",u"vor ",u"nach ",u"etwa ","","","") _mod_str = ("", u"vor ", u"nach ", u"etwa ", "", "", "")
_qual_str = ("",u"geschätzt ",u"errechnet ") _qual_str = ("", u"geschätzt ", u"errechnet ")
_bce_str = "%s v. u. Z." _bce_str = "%s v. u. Z."
formats = ( formats = (
"JJJJ-MM-DD (ISO)", "Numerisch", "Monat Tag Jahr", "JJJJ-MM-DD (ISO)", "Numerisch", "Monat Tag Jahr",
"MONAT Tag Jahr", "Tag. Monat Jahr", "Tag. MONAT Jahr" "MONAT Tag Jahr", "Tag. Monat Jahr", "Tag. MONAT Jahr"
) )
def _display_gregorian(self,date_val): def _display_gregorian(self, date_val):
year = self._slash_year(date_val[2],date_val[3]) year = self._slash_year(date_val[2], date_val[3])
if self.format == 0: if self.format == 0:
return self.display_iso(date_val) return self.display_iso(date_val)
elif self.format == 1: elif self.format == 1:
@@ -157,51 +159,51 @@ class DateDisplayDE(DateDisplay):
if date_val[0] == 0 and date_val[1] == 0: if date_val[0] == 0 and date_val[1] == 0:
value = str(date_val[2]) value = str(date_val[2])
else: else:
value = self._tformat.replace('%m',str(date_val[1])) value = self._tformat.replace('%m', str(date_val[1]))
value = value.replace('%d',str(date_val[0])) value = value.replace('%d', str(date_val[0]))
value = value.replace('%Y',str(date_val[2])) value = value.replace('%Y', str(date_val[2]))
elif self.format == 2: elif self.format == 2:
# Month Day, Year # Month Day, Year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
else: else:
value = "%s %s" % (self._months[date_val[1]],year) value = "%s %s" % (self._months[date_val[1]], year)
else: else:
value = "%s %d, %s" % (self._months[date_val[1]],date_val[0],year) value = "%s %d, %s" % (self._months[date_val[1]], date_val[0], year)
elif self.format == 3: elif self.format == 3:
# MON Day, Year # MON Day, Year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
else: else:
value = "%s %s" % (self._MONS[date_val[1]],year) value = "%s %s" % (self.MONS[date_val[1]], year)
else: else:
value = "%s %d, %s" % (self._MONS[date_val[1]],date_val[0],year) value = "%s %d, %s" % (self.MONS[date_val[1]], date_val[0], year)
elif self.format == 4: elif self.format == 4:
# Day Month Year # Day Month Year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
else: else:
value = "%s %s" % (self._months[date_val[1]],year) value = "%s %s" % (self._months[date_val[1]], year)
else: else:
value = "%d. %s %s" % (date_val[0],self._months[date_val[1]],year) value = "%d. %s %s" % (date_val[0], self._months[date_val[1]], year)
else: else:
# Day MON Year # Day MON Year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
else: else:
value = "%s %s" % (self._MONS[date_val[1]],year) value = "%s %s" % (self.MONS[date_val[1]], year)
else: else:
value = "%d. %s %s" % (date_val[0],self._MONS[date_val[1]],year) value = "%d. %s %s" % (date_val[0], self.MONS[date_val[1]], year)
if date_val[2] < 0: if date_val[2] < 0:
return self._bce_str % value return self._bce_str % value
else: else:
return value return value
def display(self,date): def display(self, date):
""" """
Returns a text string representing the date. Returns a text string representing the date.
""" """
@@ -219,20 +221,20 @@ class DateDisplayDE(DateDisplay):
elif mod == Date.MOD_SPAN: elif mod == Date.MOD_SPAN:
d1 = self.display_cal[cal](start) d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date()) d2 = self.display_cal[cal](date.get_stop_date())
return "%s%s %s %s %s%s" % (qual_str,u'von',d1,u'bis',d2,self.calendar[cal]) return "%s%s %s %s %s%s" % (qual_str, u'von', d1, u'bis', d2, self.calendar[cal])
elif mod == Date.MOD_RANGE: elif mod == Date.MOD_RANGE:
d1 = self.display_cal[cal](start) d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date()) d2 = self.display_cal[cal](date.get_stop_date())
return "%szwischen %s und %s%s" % (qual_str,d1,d2,self.calendar[cal]) return "%szwischen %s und %s%s" % (qual_str, d1, d2, self.calendar[cal])
else: else:
text = self.display_cal[date.get_calendar()](start) text = self.display_cal[date.get_calendar()](start)
return "%s%s%s%s" % (qual_str,self._mod_str[mod],text,self.calendar[cal]) return "%s%s%s%s" % (qual_str, self._mod_str[mod], text, self.calendar[cal])
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Register classes # Register classes
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
register_datehandler(('de_DE','german','de_AT','de_CH', register_datehandler(('de_DE', 'german', 'de_AT', 'de_CH',
'de_LI','de_LU','de_BE','de'), 'de_LI', 'de_LU', 'de_BE', 'de'),
DateParserDE, DateDisplayDE) DateParserDE, DateDisplayDE)

View File

@@ -9,7 +9,7 @@
# the Free Software Foundation; either version 2 of the License, or # the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. # (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
@@ -54,57 +54,57 @@ class DateParserES(DateParser):
u'antes' : Date.MOD_BEFORE, u'antes' : Date.MOD_BEFORE,
u'ant.' : Date.MOD_BEFORE, u'ant.' : Date.MOD_BEFORE,
u'ant' : Date.MOD_BEFORE, u'ant' : Date.MOD_BEFORE,
u'después de' : Date.MOD_AFTER, u'después de' : Date.MOD_AFTER,
u'después' : Date.MOD_AFTER, u'después' : Date.MOD_AFTER,
u'desp.' : Date.MOD_AFTER, u'desp.' : Date.MOD_AFTER,
u'desp' : Date.MOD_AFTER, u'desp' : Date.MOD_AFTER,
u'aprox.' : Date.MOD_ABOUT, u'aprox.' : Date.MOD_ABOUT,
u'aprox' : Date.MOD_ABOUT, u'aprox' : Date.MOD_ABOUT,
u'apr.' : Date.MOD_ABOUT, u'apr.' : Date.MOD_ABOUT,
u'apr' : Date.MOD_ABOUT, u'apr' : Date.MOD_ABOUT,
u'circa' : Date.MOD_ABOUT, u'circa' : Date.MOD_ABOUT,
u'ca.' : Date.MOD_ABOUT, u'ca.' : Date.MOD_ABOUT,
u'ca' : Date.MOD_ABOUT, u'ca' : Date.MOD_ABOUT,
u'c.' : Date.MOD_ABOUT, u'c.' : Date.MOD_ABOUT,
u'hacia' : Date.MOD_ABOUT, u'hacia' : Date.MOD_ABOUT,
} }
calendar_to_int = { calendar_to_int = {
u'gregoriano' : Date.CAL_GREGORIAN, u'gregoriano' : Date.CAL_GREGORIAN,
u'g' : Date.CAL_GREGORIAN, u'g' : Date.CAL_GREGORIAN,
u'juliano' : Date.CAL_JULIAN, u'juliano' : Date.CAL_JULIAN,
u'j' : Date.CAL_JULIAN, u'j' : Date.CAL_JULIAN,
u'hebreo' : Date.CAL_HEBREW, u'hebreo' : Date.CAL_HEBREW,
u'h' : Date.CAL_HEBREW, u'h' : Date.CAL_HEBREW,
u'islámico' : Date.CAL_ISLAMIC, u'islámico' : Date.CAL_ISLAMIC,
u'i' : Date.CAL_ISLAMIC, u'i' : Date.CAL_ISLAMIC,
u'revolucionario': Date.CAL_FRENCH, u'revolucionario' : Date.CAL_FRENCH,
u'r' : Date.CAL_FRENCH, u'r' : Date.CAL_FRENCH,
u'persa' : Date.CAL_PERSIAN, u'persa' : Date.CAL_PERSIAN,
u'p' : Date.CAL_PERSIAN, u'p' : Date.CAL_PERSIAN,
} }
quality_to_int = { quality_to_int = {
u'estimado' : Date.QUAL_ESTIMATED, u'estimado' : Date.QUAL_ESTIMATED,
u'est.' : Date.QUAL_ESTIMATED, u'est.' : Date.QUAL_ESTIMATED,
u'est' : Date.QUAL_ESTIMATED, u'est' : Date.QUAL_ESTIMATED,
u'calc.' : Date.QUAL_CALCULATED, u'calc.' : Date.QUAL_CALCULATED,
u'calc' : Date.QUAL_CALCULATED, u'calc' : Date.QUAL_CALCULATED,
u'calculado' : Date.QUAL_CALCULATED, u'calculado' : Date.QUAL_CALCULATED,
} }
def init_strings(self): def init_strings(self):
DateParser.init_strings(self) DateParser.init_strings(self)
_span_1 = [u'de'] _span_1 = [u'de']
_span_2 = [u'a'] _span_2 = [u'a']
_range_1 = [u'entre',u'ent\.',u'ent'] _range_1 = [u'entre', u'ent\.', u'ent']
_range_2 = [u'y'] _range_2 = [u'y']
self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1),'|'.join(_span_2)), ('|'.join(_span_1), '|'.join(_span_2)),
re.IGNORECASE) re.IGNORECASE)
self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_range_1),'|'.join(_range_2)), ('|'.join(_range_1), '|'.join(_range_2)),
re.IGNORECASE) re.IGNORECASE)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -118,16 +118,16 @@ class DateDisplayES(DateDisplay):
u" (Revolucionario)", u" (Persa)", u" (Islámico)" u" (Revolucionario)", u" (Persa)", u" (Islámico)"
) )
_mod_str = ("",u"antes de ",u"después de ",u"hacia ","","","") _mod_str = ("", u"antes de ", u"después de ", u"hacia ", "", "", "")
_qual_str = ("","estimado ","calculado ") _qual_str = ("", "estimado ", "calculado ")
formats = ( formats = (
"AAAA-MM-DD (ISO)", "Numérica", "Mes Día, Año", "AAAA-MM-DD (ISO)", "Numérica", "Mes Día, Año",
"MES Día, Año", "Día Mes, Año", "Día MES, Año" "MES Día, Año", "Día Mes, Año", "Día MES, Año"
) )
def display(self,date): def display(self, date):
""" """
Returns a text string representing the date. Returns a text string representing the date.
""" """
@@ -145,18 +145,18 @@ class DateDisplayES(DateDisplay):
elif mod == Date.MOD_SPAN: elif mod == Date.MOD_SPAN:
d1 = self.display_cal[cal](start) d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date()) d2 = self.display_cal[cal](date.get_stop_date())
return "%s%s %s %s %s%s" % (qual_str,u'de',d1,u'a',d2,self.calendar[cal]) return "%s%s %s %s %s%s" % (qual_str, u'de', d1, u'a', d2, self.calendar[cal])
elif mod == Date.MOD_RANGE: elif mod == Date.MOD_RANGE:
d1 = self.display_cal[cal](start) d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date()) d2 = self.display_cal[cal](date.get_stop_date())
return "%s%s %s %s %s%s" % (qual_str,u'entre',d1,u'y',d2,self.calendar[cal]) return "%s%s %s %s %s%s" % (qual_str, u'entre', d1, u'y', d2, self.calendar[cal])
else: else:
text = self.display_cal[date.get_calendar()](start) text = self.display_cal[date.get_calendar()](start)
return "%s%s%s%s" % (qual_str,self._mod_str[mod],text,self.calendar[cal]) return "%s%s%s%s" % (qual_str, self._mod_str[mod], text, self.calendar[cal])
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Register classes # Register classes
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
register_datehandler(('es_ES','es','spanish'),DateParserES, DateDisplayES) register_datehandler(('es_ES', 'es', 'spanish'), DateParserES, DateDisplayES)

View File

@@ -9,7 +9,7 @@
# the Free Software Foundation; either version 2 of the License, or # the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. # (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
@@ -60,49 +60,50 @@ class DateParserFI(DateParser):
# examples: # examples:
# - ennen 1.1.2005 # - ennen 1.1.2005
# - noin 1.1.2005 # - noin 1.1.2005
u'ennen' : Date.MOD_BEFORE, u'ennen' : Date.MOD_BEFORE,
u'e.' : Date.MOD_BEFORE, u'e.' : Date.MOD_BEFORE,
u'noin' : Date.MOD_ABOUT, u'noin' : Date.MOD_ABOUT,
u'n.' : Date.MOD_ABOUT, u'n.' : Date.MOD_ABOUT,
} }
modifier_after_to_int = { modifier_after_to_int = {
# examples: # examples:
# - 1.1.2005 jälkeen # - 1.1.2005 jälkeen
u'jälkeen' : Date.MOD_AFTER, u'jälkeen' : Date.MOD_AFTER,
u'j.' : Date.MOD_AFTER, u'j.' : Date.MOD_AFTER,
} }
bce = [u"ekr.", u"ekr"] bce = [u"ekr.", u"ekr"]
calendar_to_int = { calendar_to_int = {
u'gregoriaaninen' : Date.CAL_GREGORIAN, u'gregoriaaninen' : Date.CAL_GREGORIAN,
u'greg.' : Date.CAL_GREGORIAN, u'greg.' : Date.CAL_GREGORIAN,
u'juliaaninen' : Date.CAL_JULIAN, u'juliaaninen' : Date.CAL_JULIAN,
u'jul.' : Date.CAL_JULIAN, u'jul.' : Date.CAL_JULIAN,
u'heprealainen' : Date.CAL_HEBREW, u'heprealainen' : Date.CAL_HEBREW,
u'hepr.' : Date.CAL_HEBREW, u'hepr.' : Date.CAL_HEBREW,
u'islamilainen' : Date.CAL_ISLAMIC, u'islamilainen' : Date.CAL_ISLAMIC,
u'isl.' : Date.CAL_ISLAMIC, u'isl.' : Date.CAL_ISLAMIC,
u'ranskan vallankumouksen aikainen': Date.CAL_FRENCH, u'ranskan vallankumouksen aikainen': Date.CAL_FRENCH,
u'ranskan v.' : Date.CAL_FRENCH, u'ranskan v.' : Date.CAL_FRENCH,
u'persialainen' : Date.CAL_PERSIAN, u'persialainen' : Date.CAL_PERSIAN,
u'pers.' : Date.CAL_PERSIAN, u'pers.' : Date.CAL_PERSIAN,
} }
quality_to_int = { quality_to_int = {
u'arviolta' : Date.QUAL_ESTIMATED, u'arviolta' : Date.QUAL_ESTIMATED,
u'arv.' : Date.QUAL_ESTIMATED, u'arv.' : Date.QUAL_ESTIMATED,
u'laskettuna' : Date.QUAL_CALCULATED, u'laskettuna' : Date.QUAL_CALCULATED,
u'lask.' : Date.QUAL_CALCULATED, u'lask.' : Date.QUAL_CALCULATED,
} }
def init_strings(self): def init_strings(self):
DateParser.init_strings(self) DateParser.init_strings(self)
# date, whitespace # date, whitespace
self._span = re.compile(u"(?P<start>.+)\s+(-)\s+(?P<stop>.+)", self._span = re.compile(u"(?P<start>.+)\s+(-)\s+(?P<stop>.+)",
re.IGNORECASE)
self._range = re.compile(u"(vuosien\s*)?(?P<start>.+)\s+ja\s+(?P<stop>.+)\s+välillä",
re.IGNORECASE) re.IGNORECASE)
self._range = re.compile(
u"(vuosien\s*)?(?P<start>.+)\s+ja\s+(?P<stop>.+)\s+välillä",
re.IGNORECASE)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -111,11 +112,11 @@ class DateParserFI(DateParser):
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class DateDisplayFI(DateDisplay): class DateDisplayFI(DateDisplay):
calendar = ("", calendar = ("",
u"(juliaaninen)", u"(juliaaninen)",
u"(heprealainen)", u"(heprealainen)",
u"(ranskan v.)", u"(ranskan v.)",
u"(persialainen)", u"(persialainen)",
u"(islamilainen)") u"(islamilainen)")
_qual_str = (u"", u"arviolta", u"laskettuna") _qual_str = (u"", u"arviolta", u"laskettuna")
@@ -123,11 +124,11 @@ class DateDisplayFI(DateDisplay):
_bce_str = u"%s ekr." _bce_str = u"%s ekr."
formats = ( formats = (
"VVVV-KK-PP (ISO)", "VVVV-KK-PP (ISO)",
"PP.KK.VVVV" "PP.KK.VVVV"
) )
def display(self,date): def display(self, date):
""" """
Returns a text string representing the date. Returns a text string representing the date.
""" """
@@ -160,19 +161,19 @@ class DateDisplayFI(DateDisplay):
text = u"%s ja %s välillä" % (d1, d2) text = u"%s ja %s välillä" % (d1, d2)
else: else:
text = self.display_cal[date.get_calendar()](start) text = self.display_cal[date.get_calendar()](start)
if mod == Date.MOD_AFTER: if mod == Date.MOD_AFTER:
text = text + u" jälkeen" text = text + u" jälkeen"
elif mod == Date.MOD_ABOUT: elif mod == Date.MOD_ABOUT:
text = u"noin " + text text = u"noin " + text
elif mod == Date.MOD_BEFORE: elif mod == Date.MOD_BEFORE:
text = u"ennen " + text text = u"ennen " + text
if qual: if qual:
# prepend quality # prepend quality
text = u"%s %s" % (self._qual_str[qual], text) text = u"%s %s" % (self._qual_str[qual], text)
if cal: if cal:
# append calendar type # append calendar type
text = u"%s %s" % (text, self.calendar[cal]) text = u"%s %s" % (text, self.calendar[cal])
return text return text
@@ -181,4 +182,4 @@ class DateDisplayFI(DateDisplay):
# Register classes # Register classes
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
register_datehandler(('fi_FI','fi','finnish'), DateParserFI, DateDisplayFI) register_datehandler(('fi_FI', 'fi', 'finnish'), DateParserFI, DateDisplayFI)

View File

@@ -9,7 +9,7 @@
# the Free Software Foundation; either version 2 of the License, or # the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. # (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
@@ -104,47 +104,47 @@ class DateParserFR(DateParser):
month_to_int[u"nebelmonat"] = 10 month_to_int[u"nebelmonat"] = 10
modifier_to_int = { modifier_to_int = {
u'avant' : Date.MOD_BEFORE, u'avant' : Date.MOD_BEFORE,
u'av.' : Date.MOD_BEFORE, u'av.' : Date.MOD_BEFORE,
u'après' : Date.MOD_AFTER, u'après' : Date.MOD_AFTER,
u'ap.' : Date.MOD_AFTER, u'ap.' : Date.MOD_AFTER,
u'ap' : Date.MOD_AFTER, u'ap' : Date.MOD_AFTER,
u'env.' : Date.MOD_ABOUT, u'env.' : Date.MOD_ABOUT,
u'env' : Date.MOD_ABOUT, u'env' : Date.MOD_ABOUT,
u'environ': Date.MOD_ABOUT, u'environ': Date.MOD_ABOUT,
u'circa' : Date.MOD_ABOUT, u'circa' : Date.MOD_ABOUT,
u'c.' : Date.MOD_ABOUT, u'c.' : Date.MOD_ABOUT,
u'ca' : Date.MOD_ABOUT, u'ca' : Date.MOD_ABOUT,
u'ca.' : Date.MOD_ABOUT, u'ca.' : Date.MOD_ABOUT,
u'vers' : Date.MOD_ABOUT, u'vers' : Date.MOD_ABOUT,
u'~' : Date.MOD_ABOUT, u'~' : Date.MOD_ABOUT,
} }
calendar_to_int = { calendar_to_int = {
u'grégorien' : Date.CAL_GREGORIAN, u'grégorien' : Date.CAL_GREGORIAN,
u'g' : Date.CAL_GREGORIAN, u'g' : Date.CAL_GREGORIAN,
u'julien' : Date.CAL_JULIAN, u'julien' : Date.CAL_JULIAN,
u'j' : Date.CAL_JULIAN, u'j' : Date.CAL_JULIAN,
u'hébreu' : Date.CAL_HEBREW, u'hébreu' : Date.CAL_HEBREW,
u'h' : Date.CAL_HEBREW, u'h' : Date.CAL_HEBREW,
u'islamique' : Date.CAL_ISLAMIC, u'islamique' : Date.CAL_ISLAMIC,
u'i' : Date.CAL_ISLAMIC, u'i' : Date.CAL_ISLAMIC,
u'révolutionnaire' : Date.CAL_FRENCH, u'révolutionnaire' : Date.CAL_FRENCH,
u'r' : Date.CAL_FRENCH, u'r' : Date.CAL_FRENCH,
u'perse' : Date.CAL_PERSIAN, u'perse' : Date.CAL_PERSIAN,
u'p' : Date.CAL_PERSIAN, u'p' : Date.CAL_PERSIAN,
} }
quality_to_int = { quality_to_int = {
u'estimée' : Date.QUAL_ESTIMATED, u'estimée' : Date.QUAL_ESTIMATED,
u'est.' : Date.QUAL_ESTIMATED, u'est.' : Date.QUAL_ESTIMATED,
u'est' : Date.QUAL_ESTIMATED, u'est' : Date.QUAL_ESTIMATED,
u'calculée' : Date.QUAL_CALCULATED, u'calculée' : Date.QUAL_CALCULATED,
u'calc.' : Date.QUAL_CALCULATED, u'calc.' : Date.QUAL_CALCULATED,
u'calc' : Date.QUAL_CALCULATED, u'calc' : Date.QUAL_CALCULATED,
u'comptée' : Date.QUAL_CALCULATED, u'comptée' : Date.QUAL_CALCULATED,
u'compt' : Date.QUAL_CALCULATED, u'compt' : Date.QUAL_CALCULATED,
u'compt.' : Date.QUAL_CALCULATED, u'compt.' : Date.QUAL_CALCULATED,
} }
def init_strings(self): def init_strings(self):
@@ -153,25 +153,25 @@ class DateParserFR(DateParser):
# by allowing space after the slash/dot (need by fr_CH) # by allowing space after the slash/dot (need by fr_CH)
# and avoid bug gregorian / french calendar conversion (+/-10 days) # and avoid bug gregorian / french calendar conversion (+/-10 days)
self._numeric = re.compile("((\d+)[/\. ])?\s*((\d+)[/\.])?\s*(\d+)\s*$") self._numeric = re.compile("((\d+)[/\. ])?\s*((\d+)[/\.])?\s*(\d+)\s*$")
self._span = re.compile(u"(de)\s+(?P<start>.+)\s+(à)\s+(?P<stop>.+)",re.IGNORECASE) self._span = re.compile(u"(de)\s+(?P<start>.+)\s+(à)\s+(?P<stop>.+)", re.IGNORECASE)
self._range = re.compile(u"(entre|ent\.|ent)\s+(?P<start>.+)\s+(et)\s+(?P<stop>.+)",re.IGNORECASE) self._range = re.compile(u"(entre|ent\.|ent)\s+(?P<start>.+)\s+(et)\s+(?P<stop>.+)", re.IGNORECASE)
# This self._text are different from the base # This self._text are different from the base
# by adding ".?" after the first date and removing "\s*$" at the end # by adding ".?" after the first date and removing "\s*$" at the end
#gregorian and julian #gregorian and julian
self._text2 =re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._mon_str, self._text2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._mon_str,
re.IGNORECASE) re.IGNORECASE)
#hebrew #hebrew
self._jtext2 =re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._jmon_str, self._jtext2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._jmon_str,
re.IGNORECASE) re.IGNORECASE)
#french #french
self._ftext2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._fmon_str, self._ftext2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._fmon_str,
re.IGNORECASE) re.IGNORECASE)
#persian #persian
self._ptext2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._pmon_str, self._ptext2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._pmon_str,
re.IGNORECASE) re.IGNORECASE)
#islamic #islamic
self._itext2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._imon_str, self._itext2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._imon_str,
re.IGNORECASE) re.IGNORECASE)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -181,21 +181,21 @@ class DateParserFR(DateParser):
class DateDisplayFR(DateDisplay): class DateDisplayFR(DateDisplay):
calendar = ( calendar = (
"", u" (Julien)", u" (Hébreu)", "", u" (Julien)", u" (Hébreu)",
u" (Révolutionnaire)", u" (Perse)", u" (Islamique)" u" (Révolutionnaire)", u" (Perse)", u" (Islamique)"
) )
_mod_str = ("",u"avant ",u"après ",u"vers ","","","") _mod_str = ("", u"avant ", u"après ", u"vers ", "", "", "")
_qual_str = ("",u"estimée ",u"calculée ","") _qual_str = ("", u"estimée ", u"calculée ", "")
formats = ( formats = (
"AAAA-MM-JJ (ISO)", "Numérique", "Mois Jour, Année", "AAAA-MM-JJ (ISO)", "Numérique", "Mois Jour, Année",
"MOI Jour, Année", "Jour Mois, Année", "Jour MOI Année" "MOI Jour, Année", "Jour Mois, Année", "Jour MOI Année"
) )
def _display_gregorian(self,date_val): def _display_gregorian(self, date_val):
year = self._slash_year(date_val[2],date_val[3]) year = self._slash_year(date_val[2], date_val[3])
if self.format == 0: if self.format == 0:
return self.display_iso(date_val) return self.display_iso(date_val)
elif self.format == 1: elif self.format == 1:
@@ -205,59 +205,59 @@ class DateDisplayFR(DateDisplay):
if date_val[0] == 0 and date_val[1] == 0: if date_val[0] == 0 and date_val[1] == 0:
value = str(date_val[2]) value = str(date_val[2])
else: else:
value = self._tformat.replace('%m',str(date_val[1])) value = self._tformat.replace('%m', str(date_val[1]))
value = value.replace('%d',str(date_val[0])) value = value.replace('%d', str(date_val[0]))
# base_display : # base_display :
# value = value.replace('%Y',str(abs(date_val[2]))) # value = value.replace('%Y', str(abs(date_val[2])))
# value = value.replace('-','/') # value = value.replace('-', '/')
value = value.replace('%Y',str(date_val[2])) value = value.replace('%Y', str(date_val[2]))
elif self.format == 2: elif self.format == 2:
# Month Day, Year # Month Day, Year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
else: else:
value = "%s %s" % (self._months[date_val[1]],year) value = "%s %s" % (self._months[date_val[1]], year)
else: else:
value = "%s %d, %s" % (self._months[date_val[1]],date_val[0],year) value = "%s %d, %s" % (self._months[date_val[1]], date_val[0], year)
elif self.format == 3: elif self.format == 3:
# MON Day, Year # MON Day, Year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
else: else:
value = "%s %s" % (self._MONS[date_val[1]],year) value = "%s %s" % (self.MONS[date_val[1]], year)
else: else:
value = "%s %d, %s" % (self._MONS[date_val[1]],date_val[0],year) value = "%s %d, %s" % (self.MONS[date_val[1]], date_val[0], year)
elif self.format == 4: elif self.format == 4:
# Day Month Year # Day Month Year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
else: else:
value = "%s %s" % (self._months[date_val[1]],year) value = "%s %s" % (self._months[date_val[1]], year)
else: else:
# base_display : # base_display :
# value = "%d %s %s" % (date_val[0],self._months[date_val[1]],year) # value = "%d %s %s" % (date_val[0], self._months[date_val[1]], year)
value = "%d. %s %s" % (date_val[0],self._months[date_val[1]],year) value = "%d. %s %s" % (date_val[0], self._months[date_val[1]], year)
else: else:
# Day MON Year # Day MON Year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
else: else:
value = "%s %s" % (self._MONS[date_val[1]],year) value = "%s %s" % (self.MONS[date_val[1]], year)
else: else:
# base_display : # base_display :
# value = "%d %s %s" % (date_val[0],self._MONS[date_val[1]],year) # value = "%d %s %s" % (date_val[0], self.MONS[date_val[1]], year)
value = "%d. %s %s" % (date_val[0],self._MONS[date_val[1]],year) value = "%d. %s %s" % (date_val[0], self.MONS[date_val[1]], year)
if date_val[2] < 0: if date_val[2] < 0:
return self._bce_str % value return self._bce_str % value
else: else:
return value return value
def display(self,date): def display(self, date):
""" """
Returns a text string representing the date. Returns a text string representing the date.
""" """
@@ -275,14 +275,14 @@ class DateDisplayFR(DateDisplay):
elif mod == Date.MOD_SPAN: elif mod == Date.MOD_SPAN:
d1 = self.display_cal[cal](start) d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date()) d2 = self.display_cal[cal](date.get_stop_date())
return "%s%s %s %s %s%s" % (qual_str,u'de',d1,u'à',d2,self.calendar[cal]) return "%s%s %s %s %s%s" % (qual_str, u'de', d1, u'à', d2, self.calendar[cal])
elif mod == Date.MOD_RANGE: elif mod == Date.MOD_RANGE:
d1 = self.display_cal[cal](start) d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date()) d2 = self.display_cal[cal](date.get_stop_date())
return "%s%s %s %s %s%s" % (qual_str,u'entre',d1,u'et',d2,self.calendar[cal]) return "%s%s %s %s %s%s" % (qual_str, u'entre', d1, u'et', d2, self.calendar[cal])
else: else:
text = self.display_cal[date.get_calendar()](start) text = self.display_cal[date.get_calendar()](start)
return "%s%s%s%s" % (qual_str,self._mod_str[mod],text,self.calendar[cal]) return "%s%s%s%s" % (qual_str, self._mod_str[mod], text, self.calendar[cal])
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -290,5 +290,5 @@ class DateDisplayFR(DateDisplay):
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
register_datehandler( register_datehandler(
('fr_FR','fr','french','fr_CA','fr_BE','fr_CH'), ('fr_FR', 'fr', 'french', 'fr_CA', 'fr_BE', 'fr_CH'),
DateParserFR,DateDisplayFR) DateParserFR, DateDisplayFR)

View File

@@ -9,7 +9,7 @@
# the Free Software Foundation; either version 2 of the License, or # the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. # (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
@@ -51,28 +51,28 @@ class DateParserLT(DateParser):
modifier_to_int = { modifier_to_int = {
u'prieš' : Date.MOD_BEFORE, u'prieš' : Date.MOD_BEFORE,
u'po' : Date.MOD_AFTER, u'po' : Date.MOD_AFTER,
u'apie' : Date.MOD_ABOUT, u'apie' : Date.MOD_ABOUT,
} }
calendar_to_int = { calendar_to_int = {
u'grigaliaus' : Date.CAL_GREGORIAN, u'grigaliaus' : Date.CAL_GREGORIAN,
u'g' : Date.CAL_GREGORIAN, u'g' : Date.CAL_GREGORIAN,
u'julijaus' : Date.CAL_JULIAN, u'julijaus' : Date.CAL_JULIAN,
u'j' : Date.CAL_JULIAN, u'j' : Date.CAL_JULIAN,
u'hebrajų' : Date.CAL_HEBREW, u'hebrajų' : Date.CAL_HEBREW,
u'h' : Date.CAL_HEBREW, u'h' : Date.CAL_HEBREW,
u'islamo' : Date.CAL_ISLAMIC, u'islamo' : Date.CAL_ISLAMIC,
u'i' : Date.CAL_ISLAMIC, u'i' : Date.CAL_ISLAMIC,
u'prancuzų respublikos': Date.CAL_FRENCH, u'prancuzų respublikos': Date.CAL_FRENCH,
u'r' : Date.CAL_FRENCH, u'r' : Date.CAL_FRENCH,
u'persų' : Date.CAL_PERSIAN, u'persų' : Date.CAL_PERSIAN,
u'p' : Date.CAL_PERSIAN, u'p' : Date.CAL_PERSIAN,
} }
quality_to_int = { quality_to_int = {
u'apytikriai' : Date.QUAL_ESTIMATED, u'apytikriai' : Date.QUAL_ESTIMATED,
u'apskaičiuota' : Date.QUAL_CALCULATED, u'apskaičiuota' : Date.QUAL_CALCULATED,
} }
def init_strings(self): def init_strings(self):
@@ -81,12 +81,14 @@ class DateParserLT(DateParser):
_span_2 = [u'iki'] _span_2 = [u'iki']
_range_1 = [u'tarp'] _range_1 = [u'tarp']
_range_2 = [u'ir'] _range_2 = [u'ir']
self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % self._span = re.compile(
('|'.join(_span_1),'|'.join(_span_2)), "(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
re.IGNORECASE) ('|'.join(_span_1), '|'.join(_span_2)),
self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % re.IGNORECASE)
('|'.join(_range_1),'|'.join(_range_2)), self._range = re.compile(
re.IGNORECASE) "(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_range_1), '|'.join(_range_2)),
re.IGNORECASE)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -103,20 +105,20 @@ class DateDisplayLT(DateDisplay):
u" (islamo)" u" (islamo)"
) )
_mod_str = (u"", _mod_str = (u"",
u"prieš ", u"prieš ",
u"po ", u"po ",
u"apie ", u"apie ",
u"",u"",u"") u"", u"", u"")
_qual_str = (u"",u"apytikriai ",u"apskaičiuota ") _qual_str = (u"", u"apytikriai ", u"apskaičiuota ")
formats = ( formats = (
"YYYY-MM-DD (ISO)", "Skaitmeninis", "Mėnuo Diena, Metai", "YYYY-MM-DD (ISO)", "Skaitmeninis", "Mėnuo Diena, Metai",
"Mėn DD, YYYY", "Diena Mėnuo Metai", "DD Mėn YYYY" "Mėn DD, YYYY", "Diena Mėnuo Metai", "DD Mėn YYYY"
) )
def display(self,date): def display(self, date):
""" """
Returns a text string representing the date. Returns a text string representing the date.
""" """
@@ -134,18 +136,21 @@ class DateDisplayLT(DateDisplay):
elif mod == Date.MOD_SPAN: elif mod == Date.MOD_SPAN:
d1 = self.display_cal[cal](start) d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date()) d2 = self.display_cal[cal](date.get_stop_date())
return "%s%s %s %s %s%s" % (qual_str,u'nuo',d1,u'iki',d2,self.calendar[cal]) return "%s%s %s %s %s%s" % (qual_str, u'nuo', d1, u'iki',
d2, self.calendar[cal])
elif mod == Date.MOD_RANGE: elif mod == Date.MOD_RANGE:
d1 = self.display_cal[cal](start) d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date()) d2 = self.display_cal[cal](date.get_stop_date())
return "%s%s %s %s %s%s" % (qual_str,u'tarp',d1,u'ir',d2,self.calendar[cal]) return "%s%s %s %s %s%s" % (qual_str, u'tarp', d1, u'ir',
d2, self.calendar[cal])
else: else:
text = self.display_cal[date.get_calendar()](start) text = self.display_cal[date.get_calendar()](start)
return "%s%s%s%s" % (qual_str,self._mod_str[mod],text,self.calendar[cal]) return "%s%s%s%s" % (qual_str, self._mod_str[mod], text,
self.calendar[cal])
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Register classes # Register classes
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
register_datehandler(('lt_LT','lt','lithuanian'),DateParserLT, DateDisplayLT) register_datehandler(('lt_LT', 'lt', 'lithuanian'), DateParserLT, DateDisplayLT)

View File

@@ -9,7 +9,7 @@
# the Free Software Foundation; either version 2 of the License, or # the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. # (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
@@ -83,49 +83,49 @@ class DateParserNL(DateParser):
modifier_to_int = { modifier_to_int = {
u'voor' : Date.MOD_BEFORE, u'voor' : Date.MOD_BEFORE,
u'na' : Date.MOD_AFTER, u'na' : Date.MOD_AFTER,
u'tegen' : Date.MOD_ABOUT, u'tegen' : Date.MOD_ABOUT,
u'om' : Date.MOD_ABOUT, u'om' : Date.MOD_ABOUT,
u'rond' : Date.MOD_ABOUT, u'rond' : Date.MOD_ABOUT,
u'circa' : Date.MOD_ABOUT, u'circa' : Date.MOD_ABOUT,
u'ca.' : Date.MOD_ABOUT, u'ca.' : Date.MOD_ABOUT,
} }
calendar_to_int = { calendar_to_int = {
u'gregoriaans' : Date.CAL_GREGORIAN, u'gregoriaans' : Date.CAL_GREGORIAN,
u'greg.' : Date.CAL_GREGORIAN, u'greg.' : Date.CAL_GREGORIAN,
u'juliaans' : Date.CAL_JULIAN, u'juliaans' : Date.CAL_JULIAN,
u'jul.' : Date.CAL_JULIAN, u'jul.' : Date.CAL_JULIAN,
u'hebreeuws' : Date.CAL_HEBREW, u'hebreeuws' : Date.CAL_HEBREW,
u'hebr.' : Date.CAL_HEBREW, u'hebr.' : Date.CAL_HEBREW,
u'islamitisch' : Date.CAL_ISLAMIC, u'islamitisch' : Date.CAL_ISLAMIC,
u'isl.' : Date.CAL_ISLAMIC, u'isl.' : Date.CAL_ISLAMIC,
u'franse republiek': Date.CAL_FRENCH, u'franse republiek': Date.CAL_FRENCH,
u'fran.' : Date.CAL_FRENCH, u'fran.' : Date.CAL_FRENCH,
u'persisch' : Date.CAL_PERSIAN, u'persisch' : Date.CAL_PERSIAN,
} }
quality_to_int = { quality_to_int = {
u'geschat' : Date.QUAL_ESTIMATED, u'geschat' : Date.QUAL_ESTIMATED,
u'gesch.' : Date.QUAL_ESTIMATED, u'gesch.' : Date.QUAL_ESTIMATED,
u'berekend' : Date.QUAL_CALCULATED, u'berekend' : Date.QUAL_CALCULATED,
u'ber.' : Date.QUAL_CALCULATED, u'ber.' : Date.QUAL_CALCULATED,
} }
bce = ["voor onze tijdrekening","voor Christus","v. Chr."] + DateParser.bce bce = ["voor onze tijdrekening", "voor Christus", "v. Chr."] + DateParser.bce
def init_strings(self): def init_strings(self):
DateParser.init_strings(self) DateParser.init_strings(self)
self._span = re.compile("(van)\s+(?P<start>.+)\s+(tot)\s+(?P<stop>.+)", self._span = re.compile("(van)\s+(?P<start>.+)\s+(tot)\s+(?P<stop>.+)",
re.IGNORECASE)
self._range = re.compile("tussen\s+(?P<start>.+)\s+en\s+(?P<stop>.+)",
re.IGNORECASE)
self._text2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?'
% self._mon_str,
re.IGNORECASE)
self._jtext2= re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?'
% self._jmon_str,
re.IGNORECASE) re.IGNORECASE)
self._range = re.compile("tussen\s+(?P<start>.+)\s+en\s+(?P<stop>.+)",
re.IGNORECASE)
self._text2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?'
% self._mon_str,
re.IGNORECASE)
self._jtext2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?'
% self._jmon_str,
re.IGNORECASE)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -139,19 +139,19 @@ class DateDisplayNL(DateDisplay):
u" (franse republiek)", u" (persisch)", u" (islamitisch)" u" (franse republiek)", u" (persisch)", u" (islamitisch)"
) )
_mod_str = ("",u"voor ",u"na ",u"rond ","","","") _mod_str = ("", u"voor ", u"na ", u"rond ", "", "", "")
_qual_str = ("",u"geschat ",u"berekend ") _qual_str = ("", u"geschat ", u"berekend ")
_bce_str = "%s v. Chr." _bce_str = "%s v. Chr."
formats = ( formats = (
"JJJJ-MM-DD (ISO)", "Numerisch DD/MM/JJ", "Maand Dag, Jaar", "JJJJ-MM-DD (ISO)", "Numerisch DD/MM/JJ", "Maand Dag, Jaar",
"Mnd. Dag Jaar", "Dag Maand Jaar", "Dag Mnd. Jaar" "Mnd. Dag Jaar", "Dag Maand Jaar", "Dag Mnd. Jaar"
) )
def _display_gregorian(self,date_val): def _display_gregorian(self, date_val):
year = self._slash_year(date_val[2],date_val[3]) year = self._slash_year(date_val[2], date_val[3])
if self.format == 0: if self.format == 0:
return self.display_iso(date_val) return self.display_iso(date_val)
elif self.format == 1: elif self.format == 1:
@@ -162,52 +162,52 @@ class DateDisplayNL(DateDisplay):
if date_val[0] == 0 and date_val[1] == 0: if date_val[0] == 0 and date_val[1] == 0:
value = str(date_val[2]) value = str(date_val[2])
else: else:
value = self._tformat.replace('%m',str(date_val[1])) value = self._tformat.replace('%m', str(date_val[1]))
value = value.replace('%d',str(date_val[0])) value = value.replace('%d', str(date_val[0]))
value = value.replace('%Y',str(abs(date_val[2]))) value = value.replace('%Y', str(abs(date_val[2])))
value = value.replace('-','/') value = value.replace('-', '/')
elif self.format == 2: elif self.format == 2:
# Month Day, Year # Month Day, Year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
else: else:
value = "%s %s" % (self._months[date_val[1]],year) value = "%s %s" % (self._months[date_val[1]], year)
else: else:
value = "%s %d, %s" % (self._months[date_val[1]],date_val[0],year) value = "%s %d, %s" % (self._months[date_val[1]], date_val[0], year)
elif self.format == 3: elif self.format == 3:
# Mnd Day, Year # Mnd Day, Year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
else: else:
value = "%s %s" % (self._MONS[date_val[1]],year) value = "%s %s" % (self.MONS[date_val[1]], year)
else: else:
value = "%s %d, %s" % (self._MONS[date_val[1]],date_val[0],year) value = "%s %d, %s" % (self.MONS[date_val[1]], date_val[0], year)
elif self.format == 4: elif self.format == 4:
# Day Month Year # Day Month Year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
else: else:
value = "%s %s" % (self._months[date_val[1]],year) value = "%s %s" % (self._months[date_val[1]], year)
else: else:
value = "%d %s %s" % (date_val[0],self._months[date_val[1]],year) value = "%d %s %s" % (date_val[0], self._months[date_val[1]], year)
else: else:
# Day Mnd Year # Day Mnd Year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
else: else:
value = "%s %s" % (self._MONS[date_val[1]],year) value = "%s %s" % (self.MONS[date_val[1]], year)
else: else:
value = "%d %s %s" % (date_val[0],self._MONS[date_val[1]],year) value = "%d %s %s" % (date_val[0], self.MONS[date_val[1]], year)
if date_val[2] < 0: if date_val[2] < 0:
return self._bce_str % value return self._bce_str % value
else: else:
return value return value
def display(self,date): def display(self, date):
""" """
Returns a text string representing the date. Returns a text string representing the date.
""" """
@@ -225,19 +225,22 @@ class DateDisplayNL(DateDisplay):
elif mod == Date.MOD_SPAN: elif mod == Date.MOD_SPAN:
d1 = self.display_cal[cal](start) d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date()) d2 = self.display_cal[cal](date.get_stop_date())
return "%s%s %s %s %s%s" % (qual_str,u'van',d1,u'tot',d2,self.calendar[cal]) return "%s%s %s %s %s%s" % (qual_str, u'van', d1,
u'tot', d2, self.calendar[cal])
elif mod == Date.MOD_RANGE: elif mod == Date.MOD_RANGE:
d1 = self.display_cal[cal](start) d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date()) d2 = self.display_cal[cal](date.get_stop_date())
return "%stussen %s en %s%s" % (qual_str,d1,d2,self.calendar[cal]) return "%stussen %s en %s%s" % (qual_str, d1, d2,
self.calendar[cal])
else: else:
text = self.display_cal[date.get_calendar()](start) text = self.display_cal[date.get_calendar()](start)
return "%s%s%s%s" % (qual_str,self._mod_str[mod],text,self.calendar[cal]) return "%s%s%s%s" % (qual_str, self._mod_str[mod], text,
self.calendar[cal])
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Register classes # Register classes
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
register_datehandler(('nl_NL','dutch','nl_BE','nl'), register_datehandler(('nl_NL', 'dutch', 'nl_BE', 'nl'),
DateParserNL, DateDisplayNL) DateParserNL, DateDisplayNL)

View File

@@ -9,7 +9,7 @@
# the Free Software Foundation; either version 2 of the License, or # the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. # (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
@@ -51,112 +51,112 @@ class DateParserRU(DateParser):
modifier_to_int = { modifier_to_int = {
u'перед' : Date.MOD_BEFORE, u'перед' : Date.MOD_BEFORE,
u'по' : Date.MOD_BEFORE, u'по' : Date.MOD_BEFORE,
u'после' : Date.MOD_AFTER, u'после' : Date.MOD_AFTER,
u'п.' : Date.MOD_AFTER, u'п.' : Date.MOD_AFTER,
u'п' : Date.MOD_AFTER, u'п' : Date.MOD_AFTER,
u'с' : Date.MOD_AFTER, u'с' : Date.MOD_AFTER,
u'ок' : Date.MOD_ABOUT, u'ок' : Date.MOD_ABOUT,
u'ок.' : Date.MOD_ABOUT, u'ок.' : Date.MOD_ABOUT,
u'около' : Date.MOD_ABOUT, u'около' : Date.MOD_ABOUT,
u'примерно' : Date.MOD_ABOUT, u'примерно' : Date.MOD_ABOUT,
u'прим' : Date.MOD_ABOUT, u'прим' : Date.MOD_ABOUT,
u'прим.' : Date.MOD_ABOUT, u'прим.' : Date.MOD_ABOUT,
u'приблизительно' : Date.MOD_ABOUT, u'приблизительно' : Date.MOD_ABOUT,
u'приб.' : Date.MOD_ABOUT, u'приб.' : Date.MOD_ABOUT,
u'прибл.' : Date.MOD_ABOUT, u'прибл.' : Date.MOD_ABOUT,
u'приб' : Date.MOD_ABOUT, u'приб' : Date.MOD_ABOUT,
u'прибл' : Date.MOD_ABOUT, u'прибл' : Date.MOD_ABOUT,
} }
calendar_to_int = { calendar_to_int = {
u'григорианский' : Date.CAL_GREGORIAN, u'григорианский' : Date.CAL_GREGORIAN,
u'г' : Date.CAL_GREGORIAN, u'г' : Date.CAL_GREGORIAN,
u'юлианский' : Date.CAL_JULIAN, u'юлианский' : Date.CAL_JULIAN,
u'ю' : Date.CAL_JULIAN, u'ю' : Date.CAL_JULIAN,
u'еврейский' : Date.CAL_HEBREW, u'еврейский' : Date.CAL_HEBREW,
u'е' : Date.CAL_HEBREW, u'е' : Date.CAL_HEBREW,
u'исламский' : Date.CAL_ISLAMIC, u'исламский' : Date.CAL_ISLAMIC,
u'и' : Date.CAL_ISLAMIC, u'и' : Date.CAL_ISLAMIC,
u'республиканский': Date.CAL_FRENCH, u'республиканский': Date.CAL_FRENCH,
u'р' : Date.CAL_FRENCH, u'р' : Date.CAL_FRENCH,
u'персидский' : Date.CAL_PERSIAN, u'персидский' : Date.CAL_PERSIAN,
u'п' : Date.CAL_PERSIAN, u'п' : Date.CAL_PERSIAN,
} }
quality_to_int = { quality_to_int = {
u'оценено' : Date.QUAL_ESTIMATED, u'оценено' : Date.QUAL_ESTIMATED,
u'оцен.' : Date.QUAL_ESTIMATED, u'оцен.' : Date.QUAL_ESTIMATED,
u'оц.' : Date.QUAL_ESTIMATED, u'оц.' : Date.QUAL_ESTIMATED,
u'оцен' : Date.QUAL_ESTIMATED, u'оцен' : Date.QUAL_ESTIMATED,
u'оц' : Date.QUAL_ESTIMATED, u'оц' : Date.QUAL_ESTIMATED,
u'вычислено' : Date.QUAL_CALCULATED, u'вычислено' : Date.QUAL_CALCULATED,
u'вычисл.' : Date.QUAL_CALCULATED, u'вычисл.' : Date.QUAL_CALCULATED,
u'выч.' : Date.QUAL_CALCULATED, u'выч.' : Date.QUAL_CALCULATED,
u'вычисл' : Date.QUAL_CALCULATED, u'вычисл' : Date.QUAL_CALCULATED,
u'выч' : Date.QUAL_CALCULATED, u'выч' : Date.QUAL_CALCULATED,
} }
hebrew_to_int = { hebrew_to_int = {
u"тишрей":1, u"тишрей":1,
u"хешван":2, u"хешван":2,
u"кислев":3, u"кислев":3,
u"тевет":4, u"тевет":4,
u"шеват":5, u"шеват":5,
u"адар":6, u"адар":6,
u"адар бет":7, u"адар бет":7,
u"нисан":8, u"нисан":8,
u"ияр":9, u"ияр":9,
u"сиван":10, u"сиван":10,
u"таммуз":11, u"таммуз":11,
u"ав":12, u"ав":12,
u"элул":13, u"элул":13,
} }
islamic_to_int = { islamic_to_int = {
u"мухаррам":1, u"мухаррам":1,
u"сафар":2, u"сафар":2,
u"раби-аль-авваль":3, u"раби-аль-авваль":3,
u"раби-ассани":4, u"раби-ассани":4,
u"джумада-аль-уля":5, u"джумада-аль-уля":5,
u"джумада-аль-ахира":6, u"джумада-аль-ахира":6,
u"раджаб":7, u"раджаб":7,
u"шаабан":8, u"шаабан":8,
u"рамадан":9, u"рамадан":9,
u"шавваль":10, u"шавваль":10,
u"зуль-каада":11, u"зуль-каада":11,
u"зуль-хиджжа":12, u"зуль-хиджжа":12,
} }
persian_to_int = { persian_to_int = {
u"фарвардин":1, u"фарвардин":1,
u"урдбихишт":2, u"урдбихишт":2,
u"хурдад":3, u"хурдад":3,
u"тир":4, u"тир":4,
u"мурдад":5, u"мурдад":5,
u"шахривар":6, u"шахривар":6,
u"михр":7, u"михр":7,
u"абан":8, u"абан":8,
u"азар":9, u"азар":9,
u"дай":10, u"дай":10,
u"бахман":11, u"бахман":11,
u"исфаидармуз":12, u"исфаидармуз":12,
} }
french_to_int = { french_to_int = {
u"вандемьер":1, u"вандемьер":1,
u"брюмер":2, u"брюмер":2,
u"фример":3, u"фример":3,
u"нивоз":4, u"нивоз":4,
u"плювиоз":5, u"плювиоз":5,
u"вантоз":6, u"вантоз":6,
u"жерминаль":7, u"жерминаль":7,
u"флореаль":8, u"флореаль":8,
u"прериаль":9, u"прериаль":9,
u"мессидор":10, u"мессидор":10,
u"термидор":11, u"термидор":11,
u"фрюктидор":12, u"фрюктидор":12,
u"дополнит.":13, u"дополнит.":13,
} }
bce = [ bce = [
@@ -165,17 +165,17 @@ class DateParserRU(DateParser):
def init_strings(self): def init_strings(self):
DateParser.init_strings(self) DateParser.init_strings(self)
_span_1 = [u'с',u'от'] _span_1 = [u'с', u'от']
_span_2 = [u'по'] _span_2 = [u'по']
_range_1 = [u'между',u'меж\.',u'меж'] _range_1 = [u'между', u'меж\.', u'меж']
_range_2 = [u'и'] _range_2 = [u'и']
self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1),'|'.join(_span_2)), ('|'.join(_span_1), '|'.join(_span_2)),
re.IGNORECASE) re.IGNORECASE)
self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_range_1),'|'.join(_range_2)), ('|'.join(_range_1), '|'.join(_range_2)),
re.IGNORECASE) re.IGNORECASE)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Russian displayer # Russian displayer
@@ -184,7 +184,7 @@ class DateParserRU(DateParser):
class DateDisplayRU(DateDisplay): class DateDisplayRU(DateDisplay):
calendar = ( calendar = (
u"", u"",
u" (юлианский)", u" (юлианский)",
u" (еврейский)", u" (еврейский)",
u" (республиканский)", u" (республиканский)",
@@ -193,84 +193,84 @@ class DateDisplayRU(DateDisplay):
) )
_mod_str = ( _mod_str = (
u"", u"",
u"перед ", u"перед ",
u"после ", u"после ",
u"около ", u"около ",
u"",u"",u"") u"", u"", u"")
_qual_str = (u"",u"оцен ",u"вычисл ") _qual_str = (u"", u"оцен ", u"вычисл ")
_bce_str = u"%s до н.э." _bce_str = u"%s до н.э."
formats = ( formats = (
"ГГГГ-ММ-ДД (ISO)", "Численный", "Месяц День, Год", "ГГГГ-ММ-ДД (ISO)", "Численный", "Месяц День, Год",
"МЕС ДД, ГГГГГ", "День Месяц, Год", "ДД МЕС, ГГГГГ" "МЕС ДД, ГГГГГ", "День Месяц, Год", "ДД МЕС, ГГГГГ"
) )
_hebrew = ( u"", hebrew = ( u"",
u"Тишрей", u"Тишрей",
u"Хешван", u"Хешван",
u"Кислев", u"Кислев",
u"Тевет", u"Тевет",
u"Шеват", u"Шеват",
u"Адар", u"Адар",
u"Адар бет", u"Адар бет",
u"Нисан", u"Нисан",
u"Ияр", u"Ияр",
u"Сиван", u"Сиван",
u"Таммуз", u"Таммуз",
u"Ав", u"Ав",
u"Элул", u"Элул",
) )
_islamic = ( u"", islamic = ( u"",
u"Мухаррам", u"Мухаррам",
u"Сафар", u"Сафар",
u"Раби-аль-авваль", u"Раби-аль-авваль",
u"Раби-ассани", u"Раби-ассани",
u"Джумада-аль-уля", u"Джумада-аль-уля",
u"Джумада-аль-ахира", u"Джумада-аль-ахира",
u"Раджаб", u"Раджаб",
u"Шаабан", u"Шаабан",
u"Рамадан", u"Рамадан",
u"Шавваль", u"Шавваль",
u"Зуль-каада", u"Зуль-каада",
u"Зуль-хиджжа", u"Зуль-хиджжа",
) )
_persian = ( u"", persian = ( u"",
u"Фарвардин", u"Фарвардин",
u"Урдбихишт", u"Урдбихишт",
u"Хурдад", u"Хурдад",
u"Тир", u"Тир",
u"Мурдад", u"Мурдад",
u"Шахривар", u"Шахривар",
u"Михр", u"Михр",
u"Абан", u"Абан",
u"Азар", u"Азар",
u"Дай", u"Дай",
u"Бахман", u"Бахман",
u"Исфаидармуз", u"Исфаидармуз",
) )
_french = ( u"", french = ( u"",
u"Вандемьер", u"Вандемьер",
u"Брюмер", u"Брюмер",
u"Фример", u"Фример",
u"Нивоз", u"Нивоз",
u"Плювиоз", u"Плювиоз",
u"Вантоз", u"Вантоз",
u"Жерминаль", u"Жерминаль",
u"Флореаль", u"Флореаль",
u"Прериаль", u"Прериаль",
u"Мессидор", u"Мессидор",
u"Термидор", u"Термидор",
u"Фрюктидор", u"Фрюктидор",
u"Дополнит." u"Дополнит."
) )
def display(self,date): def display(self, date):
""" """
Returns a text string representing the date. Returns a text string representing the date.
""" """
@@ -288,18 +288,21 @@ class DateDisplayRU(DateDisplay):
elif mod == Date.MOD_SPAN: elif mod == Date.MOD_SPAN:
d1 = self.display_cal[cal](start) d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date()) d2 = self.display_cal[cal](date.get_stop_date())
return "%sс %s %s %s%s" % (qual_str,d1,u'по',d2,self.calendar[cal]) return "%sс %s %s %s%s" % (qual_str, d1, u'по', d2,
self.calendar[cal])
elif mod == Date.MOD_RANGE: elif mod == Date.MOD_RANGE:
d1 = self.display_cal[cal](start) d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date()) d2 = self.display_cal[cal](date.get_stop_date())
return "%s%s %s %s %s%s" % (qual_str,u'между',d1,u'и',d2,self.calendar[cal]) return "%s%s %s %s %s%s" % (qual_str, u'между', d1, u'и',
d2, self.calendar[cal])
else: else:
text = self.display_cal[date.get_calendar()](start) text = self.display_cal[date.get_calendar()](start)
return "%s%s%s%s" % (qual_str,self._mod_str[mod],text,self.calendar[cal]) return "%s%s%s%s" % (qual_str, self._mod_str[mod],
text, self.calendar[cal])
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Register classes # Register classes
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
register_datehandler(('ru_RU','ru','russian'),DateParserRU, DateDisplayRU) register_datehandler(('ru_RU', 'ru', 'russian'), DateParserRU, DateDisplayRU)

View File

@@ -9,7 +9,7 @@
# the Free Software Foundation; either version 2 of the License, or # the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. # (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
@@ -19,7 +19,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# #
# $Id: Date_sk.py,v 1.1.2.4 2006/04/16 03:20:06 rshura Exp $ # $Id: Date_sk.py, v 1.1.2.4 2006/04/16 03:20:06 rshura Exp $
""" """
Slovak-specific classes for parsing and displaying dates. Slovak-specific classes for parsing and displaying dates.
@@ -50,34 +50,34 @@ from _DateHandler import register_datehandler
class DateParserSK(DateParser): class DateParserSK(DateParser):
modifier_to_int = { modifier_to_int = {
u'pred' : Date.MOD_BEFORE, u'pred' : Date.MOD_BEFORE,
u'do' : Date.MOD_BEFORE, u'do' : Date.MOD_BEFORE,
u'po' : Date.MOD_AFTER, u'po' : Date.MOD_AFTER,
u'asi' : Date.MOD_ABOUT, u'asi' : Date.MOD_ABOUT,
u'okolo' : Date.MOD_ABOUT, u'okolo' : Date.MOD_ABOUT,
u'pribl.' : Date.MOD_ABOUT, u'pribl.' : Date.MOD_ABOUT,
} }
calendar_to_int = { calendar_to_int = {
u'gregoriánsky' : Date.CAL_GREGORIAN, u'gregoriánsky' : Date.CAL_GREGORIAN,
u'g' : Date.CAL_GREGORIAN, u'g' : Date.CAL_GREGORIAN,
u'juliánský' : Date.CAL_JULIAN, u'juliánský' : Date.CAL_JULIAN,
u'j' : Date.CAL_JULIAN, u'j' : Date.CAL_JULIAN,
u'hebrejský' : Date.CAL_HEBREW, u'hebrejský' : Date.CAL_HEBREW,
u'h' : Date.CAL_HEBREW, u'h' : Date.CAL_HEBREW,
u'islamský' : Date.CAL_ISLAMIC, u'islamský' : Date.CAL_ISLAMIC,
u'i' : Date.CAL_ISLAMIC, u'i' : Date.CAL_ISLAMIC,
u'republikánsky': Date.CAL_FRENCH, u'republikánsky' : Date.CAL_FRENCH,
u'r' : Date.CAL_FRENCH, u'r' : Date.CAL_FRENCH,
u'perzský' : Date.CAL_PERSIAN, u'perzský' : Date.CAL_PERSIAN,
u'p' : Date.CAL_PERSIAN, u'p' : Date.CAL_PERSIAN,
} }
quality_to_int = { quality_to_int = {
u'odhadovaný' : Date.QUAL_ESTIMATED, u'odhadovaný' : Date.QUAL_ESTIMATED,
u'odh.' : Date.QUAL_ESTIMATED, u'odh.' : Date.QUAL_ESTIMATED,
u'vypočítaný' : Date.QUAL_CALCULATED, u'vypočítaný' : Date.QUAL_CALCULATED,
u'vyp.' : Date.QUAL_CALCULATED, u'vyp.' : Date.QUAL_CALCULATED,
} }
def init_strings(self): def init_strings(self):
@@ -86,12 +86,12 @@ class DateParserSK(DateParser):
_span_2 = [u'do'] _span_2 = [u'do']
_range_1 = [u'medzi'] _range_1 = [u'medzi']
_range_2 = [u'a'] _range_2 = [u'a']
self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1),'|'.join(_span_2)), ('|'.join(_span_1), '|'.join(_span_2)),
re.IGNORECASE) re.IGNORECASE)
self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_range_1),'|'.join(_range_2)), ('|'.join(_range_1), '|'.join(_range_2)),
re.IGNORECASE) re.IGNORECASE)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -105,16 +105,16 @@ class DateDisplaySK(DateDisplay):
u" (republikánsky)", u" (perzský)", u" (islamský)" u" (republikánsky)", u" (perzský)", u" (islamský)"
) )
_mod_str = ("",u"pred ",u"po ",u"okolo ","","","") _mod_str = ("", u"pred ", u"po ", u"okolo ", "", "", "")
_qual_str = ("","odh. ","vyp. ") _qual_str = ("", "odh. ", "vyp. ")
formats = ( formats = (
"RRRR-MM-DD (ISO)", "numerický", "Mesiac Deň, Rok", "RRRR-MM-DD (ISO)", "numerický", "Mesiac Deň, Rok",
"MES Deň, Rok", "Deň, Mesiac, Rok", "Deň MES Rok" "MES Deň, Rok", "Deň, Mesiac, Rok", "Deň MES Rok"
) )
def display(self,date): def display(self, date):
""" """
Returns a text string representing the date. Returns a text string representing the date.
""" """
@@ -132,18 +132,21 @@ class DateDisplaySK(DateDisplay):
elif mod == Date.MOD_SPAN: elif mod == Date.MOD_SPAN:
d1 = self.display_cal[cal](start) d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date()) d2 = self.display_cal[cal](date.get_stop_date())
return "%s%s %s %s %s%s" % (qual_str,u'od',d1,u'do',d2,self.calendar[cal]) return "%s%s %s %s %s%s" % (qual_str, u'od', d1,
u'do', d2, self.calendar[cal])
elif mod == Date.MOD_RANGE: elif mod == Date.MOD_RANGE:
d1 = self.display_cal[cal](start) d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date()) d2 = self.display_cal[cal](date.get_stop_date())
return "%s%s %s %s %s%s" % (qual_str,u'medzi',d1,u'a',d2,self.calendar[cal]) return "%s%s %s %s %s%s" % (qual_str, u'medzi',
d1, u'a', d2, self.calendar[cal])
else: else:
text = self.display_cal[date.get_calendar()](start) text = self.display_cal[date.get_calendar()](start)
return "%s%s%s%s" % (qual_str,self._mod_str[mod],text,self.calendar[cal]) return "%s%s%s%s" % (qual_str, self._mod_str[mod],
text, self.calendar[cal])
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Register classes # Register classes
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
register_datehandler(('sk_SK','sk','SK'),DateParserSK, DateDisplaySK) register_datehandler(('sk_SK', 'sk', 'SK'), DateParserSK, DateDisplaySK)

View File

@@ -9,7 +9,7 @@
# the Free Software Foundation; either version 2 of the License, or # the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. # (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
@@ -50,53 +50,53 @@ from _DateHandler import register_datehandler
class DateParserSv(DateParser): class DateParserSv(DateParser):
""" """
Converts a text string into a Date object, expecting a date Converts a text string into a Date object, expecting a date
notation in the swedish language. If the date cannot be converted, notation in the swedish language. If the date cannot be converted,
the text string is assigned. the text string is assigned.
""" """
# modifiers before the date # modifiers before the date
modifier_to_int = { modifier_to_int = {
u'före' : Date.MOD_BEFORE, u'före' : Date.MOD_BEFORE,
u'innan' : Date.MOD_BEFORE, u'innan' : Date.MOD_BEFORE,
u'efter' : Date.MOD_AFTER, u'efter' : Date.MOD_AFTER,
u'omkring' : Date.MOD_ABOUT, u'omkring' : Date.MOD_ABOUT,
u'ca' : Date.MOD_ABOUT, u'ca' : Date.MOD_ABOUT,
u'c:a' : Date.MOD_ABOUT u'c:a' : Date.MOD_ABOUT
} }
bce = ["f Kr"] bce = ["f Kr"]
calendar_to_int = { calendar_to_int = {
u'gregoriansk ' : Date.CAL_GREGORIAN, u'gregoriansk ' : Date.CAL_GREGORIAN,
u'g' : Date.CAL_GREGORIAN, u'g' : Date.CAL_GREGORIAN,
u'juliansk' : Date.CAL_JULIAN, u'juliansk' : Date.CAL_JULIAN,
u'j' : Date.CAL_JULIAN, u'j' : Date.CAL_JULIAN,
u'hebreisk' : Date.CAL_HEBREW, u'hebreisk' : Date.CAL_HEBREW,
u'h' : Date.CAL_HEBREW, u'h' : Date.CAL_HEBREW,
u'islamisk' : Date.CAL_ISLAMIC, u'islamisk' : Date.CAL_ISLAMIC,
u'muslimsk' : Date.CAL_ISLAMIC, u'muslimsk' : Date.CAL_ISLAMIC,
u'i' : Date.CAL_ISLAMIC, u'i' : Date.CAL_ISLAMIC,
u'fransk' : Date.CAL_FRENCH, u'fransk' : Date.CAL_FRENCH,
u'fransk republikansk' : Date.CAL_FRENCH, u'fransk republikansk' : Date.CAL_FRENCH,
u'f' : Date.CAL_FRENCH, u'f' : Date.CAL_FRENCH,
u'persisk' : Date.CAL_PERSIAN, u'persisk' : Date.CAL_PERSIAN,
u'p' : Date.CAL_PERSIAN, u'p' : Date.CAL_PERSIAN,
} }
quality_to_int = { quality_to_int = {
u'uppskattat' : Date.QUAL_ESTIMATED, u'uppskattat' : Date.QUAL_ESTIMATED,
u'uppskattad' : Date.QUAL_ESTIMATED, u'uppskattad' : Date.QUAL_ESTIMATED,
u'bedömt' : Date.QUAL_ESTIMATED, u'bedömt' : Date.QUAL_ESTIMATED,
u'bedömd' : Date.QUAL_ESTIMATED, u'bedömd' : Date.QUAL_ESTIMATED,
u'beräknat' : Date.QUAL_CALCULATED, u'beräknat' : Date.QUAL_CALCULATED,
u'beräknad' : Date.QUAL_CALCULATED, u'beräknad' : Date.QUAL_CALCULATED,
} }
def init_strings(self): def init_strings(self):
DateParser.init_strings(self) DateParser.init_strings(self)
self._span = re.compile(u"(från)?\s*(?P<start>.+)\s*(till|--|)\s*(?P<stop>.+)", self._span = re.compile(u"(från)?\s*(?P<start>.+)\s*(till|--|)\s*(?P<stop>.+)",
re.IGNORECASE) re.IGNORECASE)
self._range = re.compile(u"(mellan)\s+(?P<start>.+)\s+och\s+(?P<stop>.+)", self._range = re.compile(u"(mellan)\s+(?P<start>.+)\s+och\s+(?P<stop>.+)",
re.IGNORECASE) re.IGNORECASE)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@@ -110,30 +110,30 @@ class DateDisplaySv(DateDisplay):
""" """
formats = ( formats = (
u"YYYY-MM-DD (ISO)", u"YYYY-MM-DD (ISO)",
u"Numerisk", u"Numerisk",
u"Månad dag, år", u"Månad dag, år",
u"MÅN DAG ÅR", u"MÅN DAG ÅR",
u"Dag månad år", u"Dag månad år",
u"DAG MÅN ÅR", u"DAG MÅN ÅR",
) )
calendar = ( calendar = (
"", "",
" (juliansk)", " (juliansk)",
" (hebreisk)", " (hebreisk)",
" (fransk republikansk)", " (fransk republikansk)",
" (persisk)", " (persisk)",
" (islamisk)" " (islamisk)"
) )
_mod_str = ("",u"före ",u"efter ",u"c:a ","","","") _mod_str = ("", u"före ", u"efter ", u"c:a ", "", "", "")
_qual_str = ("",u"uppskattat ",u"beräknat ") _qual_str = ("", u"uppskattat ", u"beräknat ")
_bce_str = "%s f Kr" _bce_str = "%s f Kr"
def display(self,date): def display(self, date):
""" """
Returns a text string representing the date. Returns a text string representing the date.
""" """
@@ -151,20 +151,20 @@ class DateDisplaySv(DateDisplay):
elif mod == Date.MOD_SPAN: elif mod == Date.MOD_SPAN:
d1 = self.display_cal[cal](start) d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date()) d2 = self.display_cal[cal](date.get_stop_date())
return u"%sfrån %s till %s%s" % (qual_str,d1,d2,self.calendar[cal]) return u"%sfrån %s till %s%s" % (qual_str, d1, d2, self.calendar[cal])
elif mod == Date.MOD_RANGE: elif mod == Date.MOD_RANGE:
d1 = self.display_cal[cal](start) d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date()) d2 = self.display_cal[cal](date.get_stop_date())
return u"%smellan %s och %s%s" % (qual_str,d1,d2, return u"%smellan %s och %s%s" % (qual_str, d1, d2,
self.calendar[cal]) self.calendar[cal])
else: else:
text = self.display_cal[date.get_calendar()](start) text = self.display_cal[date.get_calendar()](start)
return u"%s%s%s%s" % (qual_str,self._mod_str[mod], return u"%s%s%s%s" % (qual_str, self._mod_str[mod],
text,self.calendar[cal]) text, self.calendar[cal])
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Register classes # Register classes
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
register_datehandler(('sv_SE','sv','svensk'),DateParserSv, DateDisplaySv) register_datehandler(('sv_SE', 'sv', 'svensk'), DateParserSv, DateDisplaySv)

View File

@@ -8,7 +8,7 @@
# the Free Software Foundation; either version 2 of the License, or # the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. # (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
@@ -25,8 +25,8 @@ Class handling language-specific selection for date parser and displayer.
""" """
# import prerequisites for localized handlers # import prerequisites for localized handlers
from _DateHandler import _lang, _lang_short, \ from _DateHandler import LANG, LANG_SHORT, \
_lang_to_parser, _lang_to_display, register_datehandler LANG_TO_PARSER, LANG_TO_DISPLAY, register_datehandler
# Import all the localized handlers # Import all the localized handlers
import _Date_de import _Date_de
@@ -41,32 +41,32 @@ import _Date_sk
# Initialize global parser # Initialize global parser
try: try:
if _lang_to_parser.has_key(_lang): if LANG_TO_PARSER.has_key(LANG):
parser = _lang_to_parser[_lang]() parser = LANG_TO_PARSER[LANG]()
else: else:
parser = _lang_to_parser[_lang_short]() parser = LANG_TO_PARSER[LANG_SHORT]()
except: except:
print "Date parser for",_lang,"not available, using default" print "Date parser for", LANG, "not available, using default"
parser = _lang_to_parser["C"]() parser = LANG_TO_PARSER["C"]()
# Initialize global displayer # Initialize global displayer
try: try:
import Config import Config
val = Config.get_date_format(_lang_to_display[_lang].formats) val = Config.get_date_format(LANG_TO_DISPLAY[LANG].formats)
except: except:
try: try:
val = Config.get_date_format(_lang_to_display["C"].formats) val = Config.get_date_format(LANG_TO_DISPLAY["C"].formats)
except: except:
val = 0 val = 0
try: try:
if _lang_to_display.has_key(_lang): if LANG_TO_DISPLAY.has_key(LANG):
displayer = _lang_to_display[_lang](val) displayer = LANG_TO_DISPLAY[LANG](val)
else: else:
displayer = _lang_to_display[_lang_short](val) displayer = LANG_TO_DISPLAY[LANG_SHORT](val)
except: except:
print "Date displayer for",_lang,"not available, using default" print "Date displayer for", LANG, "not available, using default"
displayer = _lang_to_display["C"](val) displayer = LANG_TO_DISPLAY["C"](val)
# Import utility functions # Import utility functions