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>
* src/plugins/ReadGrdb.py (importData): Only copy environment if
it exists.

View File

@ -31,14 +31,6 @@ Provides autocompletion functionality.
#-------------------------------------------------------------------------
import locale
#-------------------------------------------------------------------------
#
# set up logging
#
#-------------------------------------------------------------------------
import logging
log = logging.getLogger(".AutoComp")
#-------------------------------------------------------------------------
#
# GNOME modules
@ -226,34 +218,17 @@ class StandardCustomSelector:
@param val: (int,str) tuple with the values to set.
@type val: tuple
"""
i, s = val
if i in self.mapping.keys() and i != self.custom_key:
self.store.foreach(self.set_int_value, i)
key, text = val
if key in self.mapping.keys() and key != self.custom_key:
self.store.foreach(self.set_int_value, key)
elif self.custom_key != None:
self.selector.child.set_text(s)
self.selector.child.set_text(text)
else:
print "StandardCustomSelector.set(): Option not available:", val
def set_int_value(self, model, path, iter, val):
if model.get_value(iter, 0) == val:
self.selector.set_active_iter(iter)
def set_int_value(self, model, path, node, val):
if model.get_value(node, 0) == val:
self.selector.set_active_iter(node)
return True
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
obj, instead of creating an empty StyleSheet
"""
self._para_styles = {}
self._draw_styles = {}
self._table_styles = {}
self._cell_styles = {}
self.para_styles = {}
self.draw_styles = {}
self.table_styles = {}
self.cell_styles = {}
self.name = ""
if obj != None:
for style_name in obj._para_styles.keys():
style = obj._para_styles[style_name]
self._para_styles[style_name] = ParagraphStyle(style)
for style_name in obj._draw_styles.keys():
style = obj._draw_styles[style_name]
self._draw_styles[style_name] = GraphicsStyle(style)
for style_name in obj._table_styles.keys():
style = obj._table_styles[style_name]
self._table_styles[style_name] = TableStyle(style)
for style_name in obj._cell_styles.keys():
style = obj._cell_styles[style_name]
self._cell_styles[style_name] = TableCellStyle(style)
for style_name in obj.para_styles.keys():
style = obj.para_styles[style_name]
self.para_styles[style_name] = ParagraphStyle(style)
for style_name in obj.draw_styles.keys():
style = obj.draw_styles[style_name]
self.draw_styles[style_name] = GraphicsStyle(style)
for style_name in obj.table_styles.keys():
style = obj.table_styles[style_name]
self.table_styles[style_name] = TableStyle(style)
for style_name in obj.cell_styles.keys():
style = obj.cell_styles[style_name]
self.cell_styles[style_name] = TableCellStyle(style)
def set_name(self, name):
"""
@ -1048,10 +1048,10 @@ class StyleSheet:
def clear(self):
"Removes all styles from the StyleSheet"
self._para_styles = {}
self._draw_styles = {}
self._table_styles = {}
self._cell_styles = {}
self.para_styles = {}
self.draw_styles = {}
self.table_styles = {}
self.cell_styles = {}
def add_paragraph_style(self, name, style):
"""
@ -1060,7 +1060,7 @@ class StyleSheet:
@param name: The name of the ParagraphStyle
@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):
"""
@ -1068,11 +1068,11 @@ class StyleSheet:
@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):
"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):
"""
@ -1081,7 +1081,7 @@ class StyleSheet:
@param name: The name of the GraphicsStyle
@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):
"""
@ -1089,11 +1089,11 @@ class StyleSheet:
@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):
"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):
"""
@ -1102,7 +1102,7 @@ class StyleSheet:
@param name: The name of the TableStyle
@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):
"""
@ -1110,11 +1110,11 @@ class StyleSheet:
@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):
"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):
"""
@ -1123,7 +1123,7 @@ class StyleSheet:
@param name: The name of the TableCellStyle
@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):
"""
@ -1131,11 +1131,11 @@ class StyleSheet:
@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):
"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.
"""
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.
"""
self.key = key
self.type = type
self.type = itype
self.level = level
#------------------------------------------------------------------------
@ -1358,7 +1358,7 @@ class BaseDoc:
"""
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.

View File

@ -64,8 +64,8 @@ import Utils
#
#-------------------------------------------------------------------------
_top = '''<ui><menubar name="MenuBar"><menu action="BookMenu">'''
_btm = '''</menu></menubar></ui>'''
TOP = '''<ui><menubar name="MenuBar"><menu action="BookMenu">'''
BTM = '''</menu></menubar></ui>'''
DISABLED = -1
@ -125,7 +125,7 @@ class Bookmarks :
def redraw(self):
"""Create the pulldown menu"""
text = StringIO()
text.write(_top)
text.write(TOP)
self.undisplay()
@ -150,7 +150,7 @@ class Bookmarks :
text.write('</placeholder>')
self.bookmarks.set(new_list)
text.write(_btm)
text.write(BTM)
self.action_group.add_actions(actions)
self.uistate.uimanager.insert_action_group(self.action_group, 1)
self.active = self.uistate.uimanager.add_ui_from_string(text.getvalue())
@ -414,5 +414,8 @@ class NoteBookmarks(ListBookmarks) :
def connect_signals(self):
self.dbstate.db.connect('note-delete', self.remove_handles)
def make_callback(n, f):
return lambda x: f(n)
def make_callback(handle, function):
"""
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')) )
CAL_TO_MONTHS_NAMES = {
Date.CAL_GREGORIAN : DateHandler.displayer._MONS,
Date.CAL_JULIAN : DateHandler.displayer._MONS,
Date.CAL_HEBREW : DateHandler.displayer._hebrew,
Date.CAL_FRENCH : DateHandler.displayer._french,
Date.CAL_PERSIAN : DateHandler.displayer._persian,
Date.CAL_ISLAMIC : DateHandler.displayer._islamic }
Date.CAL_GREGORIAN : DateHandler.displayer.MONS,
Date.CAL_JULIAN : DateHandler.displayer.MONS,
Date.CAL_HEBREW : DateHandler.displayer.hebrew,
Date.CAL_FRENCH : DateHandler.displayer.french,
Date.CAL_PERSIAN : DateHandler.displayer.persian,
Date.CAL_ISLAMIC : DateHandler.displayer.islamic }
#-------------------------------------------------------------------------
#

View File

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

View File

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

View File

@ -92,7 +92,7 @@ class DateParser:
_fmt_parse = re.compile(".*%(\S).*%(\S).*%(\S).*")
# 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 = {
'Jan' : 1, 'Feb' : 2, 'Mar' : 3, 'Apr' : 4,
'May' : 5, 'Jun' : 6, 'Jul' : 7, 'Aug' : 8,
@ -200,8 +200,8 @@ class DateParser:
fmt = GrampsLocale.tformat
match = self._fmt_parse.match(fmt.lower())
if match:
self.dmy = (match.groups() == ('d','m','y'))
self.ymd = (match.groups() == ('y','m','d'))
self.dmy = (match.groups() == ('d', 'm', 'y'))
self.ymd = (match.groups() == ('y', 'm', 'd'))
else:
self.dmy = True
self.ymd = False
@ -213,7 +213,7 @@ class DateParser:
are quoted.
"""
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):
"""
@ -248,45 +248,45 @@ class DateParser:
self._bce_re = re.compile("(.*)\s+%s( ?.*)" % self._bce_str)
self._cal = re.compile("(.*)\s+\(%s\)( ?.*)" % self._cal_str,
re.IGNORECASE)
re.IGNORECASE)
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>.+)",
re.IGNORECASE)
re.IGNORECASE)
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,
re.IGNORECASE)
re.IGNORECASE)
self._modifier_after = re.compile('(.*)\s+%s' % self._mod_after_str,
re.IGNORECASE)
self._abt2 = re.compile('<(.*)>',re.IGNORECASE)
re.IGNORECASE)
self._abt2 = re.compile('<(.*)>', re.IGNORECASE)
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,
re.IGNORECASE)
re.IGNORECASE)
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,
re.IGNORECASE)
re.IGNORECASE)
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,
re.IGNORECASE)
re.IGNORECASE)
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,
re.IGNORECASE)
re.IGNORECASE)
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,
re.IGNORECASE)
re.IGNORECASE)
self._numeric = re.compile("((\d+)[/\.]\s*)?((\d+)[/\.]\s*)?(\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_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
value is None, a zero is returned
@ -296,27 +296,27 @@ class DateParser:
else:
return int(val)
def _parse_hebrew(self,text):
return self._parse_calendar(text,self._jtext,self._jtext2,
def _parse_hebrew(self, text):
return self._parse_calendar(text, self._jtext, self._jtext2,
self.hebrew_to_int)
def _parse_islamic(self,text):
return self._parse_calendar(text,self._itext,self._itext2,
def _parse_islamic(self, text):
return self._parse_calendar(text, self._itext, self._itext2,
self.islamic_to_int)
def _parse_persian(self,text):
return self._parse_calendar(text,self._ptext,self._ptext2,
def _parse_persian(self, text):
return self._parse_calendar(text, self._ptext, self._ptext2,
self.persian_to_int)
def _parse_french(self,text):
return self._parse_calendar(text,self._ftext,self._ftext2,
def _parse_french(self, text):
return self._parse_calendar(text, self._ftext, self._ftext2,
self.french_to_int)
def _parse_greg_julian(self,text):
return self._parse_calendar(text,self._text,self._text2,
self.month_to_int,gregorian_valid)
def _parse_greg_julian(self, text):
return self._parse_calendar(text, self._text, self._text2,
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())
if match:
groups = match.groups()
@ -333,8 +333,8 @@ class DateParser:
d = self._get_int(groups[1])
y = int(groups[3])
s = groups[4] != None
value = (d,m,y,s)
if check and not check((d,m,y)):
value = (d, m, y, s)
if check and not check((d, m, y)):
value = Date.EMPTY
return value
@ -354,14 +354,14 @@ class DateParser:
else:
y = int(groups[3])
s = groups[4] != None
value = (d,m,y,s)
if check and not check((d,m,y)):
value = (d, m, y, s)
if check and not check((d, m, y)):
value = Date.EMPTY
return value
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.
"""
@ -383,12 +383,12 @@ class DateParser:
y = self._get_int(groups[0])
m = self._get_int(groups[3])
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
if groups[2]:
return (d,m,y,True)
return (d, m, y, True)
else:
return (d,m,y,False)
return (d, m, y, False)
match = self._rfc.match(text)
if match:
@ -396,8 +396,8 @@ class DateParser:
d = self._get_int(groups[2])
m = self._rfc_mons_to_int[groups[3]]
y = self._get_int(groups[4])
value = (d,m,y,False)
if check and not check((d,m,y)):
value = (d, m, y, False)
if check and not check((d, m, y)):
value = Date.EMPTY
return value
@ -422,14 +422,14 @@ class DateParser:
else:
m = self._get_int(groups[1])
d = self._get_int(groups[3])
value = (d,m,y,False)
if check and not check((d,m,y)):
value = (d, m, y, False)
if check and not check((d, m, y)):
value = Date.EMPTY
return value
return Date.EMPTY
def match_calendar(self,text,cal):
def match_calendar(self, text, cal):
"""
Try parsing calendar.
@ -439,9 +439,9 @@ class DateParser:
if match:
cal = self.calendar_to_int[match.group(2).lower()]
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.
@ -451,9 +451,9 @@ class DateParser:
if match:
qual = self.quality_to_int[match.group(2).lower()]
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.
@ -462,21 +462,21 @@ class DateParser:
match = self._span.match(text)
if match:
text_parser = self.parser[cal]
(text1,bc1) = self.match_bce(match.group('start'))
start = self._parse_subdate(text1,text_parser)
(text1, bc1) = self.match_bce(match.group('start'))
start = self._parse_subdate(text1, text_parser)
if bc1:
start = self.invert_year(start)
(text2,bc2) = self.match_bce(match.group('stop'))
stop = self._parse_subdate(text2,text_parser)
(text2, bc2) = self.match_bce(match.group('stop'))
stop = self._parse_subdate(text2, text_parser)
if bc2:
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 0
def match_range(self,text,cal,qual,date):
def match_range(self, text, cal, qual, date):
"""
Try matching range date.
@ -485,21 +485,21 @@ class DateParser:
match = self._range.match(text)
if match:
text_parser = self.parser[cal]
(text1,bc1) = self.match_bce(match.group('start'))
start = self._parse_subdate(text1,text_parser)
(text1, bc1) = self.match_bce(match.group('start'))
start = self._parse_subdate(text1, text_parser)
if bc1:
start = self.invert_year(start)
(text2,bc2) = self.match_bce(match.group('stop'))
stop = self._parse_subdate(text2,text_parser)
(text2, bc2) = self.match_bce(match.group('stop'))
stop = self._parse_subdate(text2, text_parser)
if bc2:
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 0
def match_bce(self,text):
def match_bce(self, text):
"""
Try matching BCE qualifier.
@ -514,9 +514,9 @@ class DateParser:
except:
print "MATCH:", match.groups()
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.
@ -529,9 +529,9 @@ class DateParser:
start = self._parse_subdate(grps[1], self.parser[cal])
mod = self.modifier_to_int.get(grps[0].lower(), Date.MOD_NONE)
if bc:
date.set(qual,mod,cal,self.invert_year(start))
date.set(qual, mod, cal, self.invert_year(start))
else:
date.set(qual,mod,cal,start)
date.set(qual, mod, cal, start)
return True
# modifiers after the date
if self.modifier_after_to_int:
@ -542,9 +542,9 @@ class DateParser:
mod = self.modifier_after_to_int.get(grps[1].lower(),
Date.MOD_NONE)
if bc:
date.set(qual,mod,cal,self.invert_year(start))
date.set(qual, mod, cal, self.invert_year(start))
else:
date.set(qual,mod,cal,start)
date.set(qual, mod, cal, start)
return True
match = self._abt2.match(text)
if match:
@ -552,13 +552,13 @@ class DateParser:
start = self._parse_subdate(grps[0])
mod = Date.MOD_ABOUT
if bc:
date.set(qual,mod,cal,self.invert_year(start))
date.set(qual, mod, cal, self.invert_year(start))
else:
date.set(qual,mod,cal,start)
date.set(qual, mod, cal, start)
return True
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.
"""
@ -567,20 +567,20 @@ class DateParser:
qual = Date.QUAL_NONE
cal = Date.CAL_GREGORIAN
(text,cal) = self.match_calendar(text,cal)
(text,qual) = self.match_quality(text,qual)
(text, cal) = self.match_calendar(text, cal)
(text, qual) = self.match_quality(text, qual)
if self.match_span(text,cal,qual,date):
if self.match_span(text, cal, qual, date):
return
if self.match_range(text,cal,qual,date):
if self.match_range(text, cal, qual, date):
return
(text,bc) = self.match_bce(text)
if self.match_modifier(text,cal,qual,bc,date):
(text, bc) = self.match_bce(text)
if self.match_modifier(text, cal, qual, bc, date):
return
try:
subdate = self._parse_subdate(text,self.parser[cal])
subdate = self._parse_subdate(text, self.parser[cal])
if subdate == Date.EMPTY and text != "":
date.set_as_text(text)
return
@ -589,20 +589,20 @@ class DateParser:
return
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:
date.set(qual,Date.MOD_NONE,cal,subdate)
date.set(qual, Date.MOD_NONE, cal, subdate)
def invert_year(self,subdate):
return (subdate[0],subdate[1],-subdate[2],subdate[3])
def invert_year(self, subdate):
return (subdate[0], subdate[1], -subdate[2], subdate[3])
def parse(self,text):
def parse(self, text):
"""
Parses the text, returning a Date object.
"""
new_date = Date()
try:
self.set_date(new_date,text)
self.set_date(new_date, text)
except DateError:
new_date.set_as_text(text)
return new_date

View File

@ -29,7 +29,7 @@ Class handling language-specific selection for date parser and displayer.
# 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
"""
try:
return _lang_to_display[_lang].formats
return LANG_TO_DISPLAY[LANG].formats
except:
return _lang_to_display["C"].formats
return LANG_TO_DISPLAY["C"].formats
def set_format(value):
try:

View File

@ -9,7 +9,7 @@
# the Free Software Foundation; either version 2 of the License, or
# (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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
@ -79,49 +79,51 @@ class DateParserDE(DateParser):
modifier_to_int = {
u'vor' : Date.MOD_BEFORE,
u'nach' : Date.MOD_AFTER,
u'gegen' : Date.MOD_ABOUT,
u'um' : Date.MOD_ABOUT,
u'etwa' : Date.MOD_ABOUT,
u'circa' : Date.MOD_ABOUT,
u'ca.' : Date.MOD_ABOUT,
u'nach' : Date.MOD_AFTER,
u'gegen' : Date.MOD_ABOUT,
u'um' : Date.MOD_ABOUT,
u'etwa' : Date.MOD_ABOUT,
u'circa' : Date.MOD_ABOUT,
u'ca.' : Date.MOD_ABOUT,
}
calendar_to_int = {
u'gregorianisch' : Date.CAL_GREGORIAN,
u'greg.' : Date.CAL_GREGORIAN,
u'julianisch' : Date.CAL_JULIAN,
u'jul.' : Date.CAL_JULIAN,
u'hebräisch' : Date.CAL_HEBREW,
u'hebr.' : Date.CAL_HEBREW,
u'islamisch' : Date.CAL_ISLAMIC,
u'isl.' : Date.CAL_ISLAMIC,
u'französisch republikanisch': Date.CAL_FRENCH,
u'franz.' : Date.CAL_FRENCH,
u'persisch' : Date.CAL_PERSIAN,
u'gregorianisch' : Date.CAL_GREGORIAN,
u'greg.' : Date.CAL_GREGORIAN,
u'julianisch' : Date.CAL_JULIAN,
u'jul.' : Date.CAL_JULIAN,
u'hebräisch' : Date.CAL_HEBREW,
u'hebr.' : Date.CAL_HEBREW,
u'islamisch' : Date.CAL_ISLAMIC,
u'isl.' : Date.CAL_ISLAMIC,
u'französisch republikanisch': Date.CAL_FRENCH,
u'franz.' : Date.CAL_FRENCH,
u'persisch' : Date.CAL_PERSIAN,
}
quality_to_int = {
u'geschätzt' : Date.QUAL_ESTIMATED,
u'gesch.' : Date.QUAL_ESTIMATED,
u'errechnet' : Date.QUAL_CALCULATED,
u'berechnet' : Date.QUAL_CALCULATED,
u'ber.' : Date.QUAL_CALCULATED,
u'geschätzt' : Date.QUAL_ESTIMATED,
u'gesch.' : Date.QUAL_ESTIMATED,
u'errechnet' : Date.QUAL_CALCULATED,
u'berechnet' : Date.QUAL_CALCULATED,
u'ber.' : Date.QUAL_CALCULATED,
}
bce = ["vor unserer Zeitrechnung", "vor unserer Zeit",
"vor der Zeitrechnung", "vor der Zeit",
bce = ["vor unserer Zeitrechnung", "vor unserer Zeit",
"vor der Zeitrechnung", "vor der Zeit",
"v. u. Z.", "v. d. Z.", "v.u.Z.", "v.d.Z.",
"vor Christi Geburt", "vor Christus", "v. Chr."] + DateParser.bce
def init_strings(self):
DateParser.init_strings(self)
self._span = re.compile("(von|vom)\s+(?P<start>.+)\s+(bis)\s+(?P<stop>.+)",re.IGNORECASE)
self._range = re.compile("zwischen\s+(?P<start>.+)\s+und\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)
self._span = re.compile("(von|vom)\s+(?P<start>.+)\s+(bis)\s+(?P<stop>.+)",
re.IGNORECASE)
self._range = re.compile("zwischen\s+(?P<start>.+)\s+und\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)
#-------------------------------------------------------------------------
#
@ -135,19 +137,19 @@ class DateDisplayDE(DateDisplay):
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."
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"
)
def _display_gregorian(self,date_val):
year = self._slash_year(date_val[2],date_val[3])
def _display_gregorian(self, date_val):
year = self._slash_year(date_val[2], date_val[3])
if self.format == 0:
return self.display_iso(date_val)
elif self.format == 1:
@ -157,51 +159,51 @@ class DateDisplayDE(DateDisplay):
if date_val[0] == 0 and date_val[1] == 0:
value = str(date_val[2])
else:
value = self._tformat.replace('%m',str(date_val[1]))
value = value.replace('%d',str(date_val[0]))
value = value.replace('%Y',str(date_val[2]))
value = self._tformat.replace('%m', str(date_val[1]))
value = value.replace('%d', str(date_val[0]))
value = value.replace('%Y', str(date_val[2]))
elif self.format == 2:
# Month Day, Year
if date_val[0] == 0:
if date_val[1] == 0:
value = year
else:
value = "%s %s" % (self._months[date_val[1]],year)
value = "%s %s" % (self._months[date_val[1]], year)
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:
# MON Day, Year
if date_val[0] == 0:
if date_val[1] == 0:
value = year
else:
value = "%s %s" % (self._MONS[date_val[1]],year)
value = "%s %s" % (self.MONS[date_val[1]], year)
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:
# Day Month Year
if date_val[0] == 0:
if date_val[1] == 0:
value = year
else:
value = "%s %s" % (self._months[date_val[1]],year)
value = "%s %s" % (self._months[date_val[1]], year)
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:
# Day MON Year
if date_val[0] == 0:
if date_val[1] == 0:
value = year
else:
value = "%s %s" % (self._MONS[date_val[1]],year)
value = "%s %s" % (self.MONS[date_val[1]], year)
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:
return self._bce_str % value
else:
return value
def display(self,date):
def display(self, date):
"""
Returns a text string representing the date.
"""
@ -219,20 +221,20 @@ class DateDisplayDE(DateDisplay):
elif mod == Date.MOD_SPAN:
d1 = self.display_cal[cal](start)
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:
d1 = self.display_cal[cal](start)
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:
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_datehandler(('de_DE','german','de_AT','de_CH',
'de_LI','de_LU','de_BE','de'),
register_datehandler(('de_DE', 'german', 'de_AT', 'de_CH',
'de_LI', 'de_LU', 'de_BE', 'de'),
DateParserDE, DateDisplayDE)

View File

@ -9,7 +9,7 @@
# the Free Software Foundation; either version 2 of the License, or
# (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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
@ -54,57 +54,57 @@ class DateParserES(DateParser):
u'antes' : Date.MOD_BEFORE,
u'ant.' : Date.MOD_BEFORE,
u'ant' : Date.MOD_BEFORE,
u'después de' : Date.MOD_AFTER,
u'después' : Date.MOD_AFTER,
u'desp.' : Date.MOD_AFTER,
u'desp' : Date.MOD_AFTER,
u'aprox.' : Date.MOD_ABOUT,
u'aprox' : Date.MOD_ABOUT,
u'apr.' : Date.MOD_ABOUT,
u'apr' : Date.MOD_ABOUT,
u'circa' : Date.MOD_ABOUT,
u'ca.' : Date.MOD_ABOUT,
u'ca' : Date.MOD_ABOUT,
u'c.' : Date.MOD_ABOUT,
u'hacia' : Date.MOD_ABOUT,
u'después de' : Date.MOD_AFTER,
u'después' : Date.MOD_AFTER,
u'desp.' : Date.MOD_AFTER,
u'desp' : Date.MOD_AFTER,
u'aprox.' : Date.MOD_ABOUT,
u'aprox' : Date.MOD_ABOUT,
u'apr.' : Date.MOD_ABOUT,
u'apr' : Date.MOD_ABOUT,
u'circa' : Date.MOD_ABOUT,
u'ca.' : Date.MOD_ABOUT,
u'ca' : Date.MOD_ABOUT,
u'c.' : Date.MOD_ABOUT,
u'hacia' : Date.MOD_ABOUT,
}
calendar_to_int = {
u'gregoriano' : Date.CAL_GREGORIAN,
u'g' : Date.CAL_GREGORIAN,
u'juliano' : Date.CAL_JULIAN,
u'j' : Date.CAL_JULIAN,
u'hebreo' : Date.CAL_HEBREW,
u'h' : Date.CAL_HEBREW,
u'islámico' : Date.CAL_ISLAMIC,
u'i' : Date.CAL_ISLAMIC,
u'revolucionario': Date.CAL_FRENCH,
u'r' : Date.CAL_FRENCH,
u'persa' : Date.CAL_PERSIAN,
u'p' : Date.CAL_PERSIAN,
u'gregoriano' : Date.CAL_GREGORIAN,
u'g' : Date.CAL_GREGORIAN,
u'juliano' : Date.CAL_JULIAN,
u'j' : Date.CAL_JULIAN,
u'hebreo' : Date.CAL_HEBREW,
u'h' : Date.CAL_HEBREW,
u'islámico' : Date.CAL_ISLAMIC,
u'i' : Date.CAL_ISLAMIC,
u'revolucionario' : Date.CAL_FRENCH,
u'r' : Date.CAL_FRENCH,
u'persa' : Date.CAL_PERSIAN,
u'p' : Date.CAL_PERSIAN,
}
quality_to_int = {
u'estimado' : Date.QUAL_ESTIMATED,
u'est.' : Date.QUAL_ESTIMATED,
u'est' : Date.QUAL_ESTIMATED,
u'calc.' : Date.QUAL_CALCULATED,
u'calc' : Date.QUAL_CALCULATED,
u'calculado' : Date.QUAL_CALCULATED,
u'estimado' : Date.QUAL_ESTIMATED,
u'est.' : Date.QUAL_ESTIMATED,
u'est' : Date.QUAL_ESTIMATED,
u'calc.' : Date.QUAL_CALCULATED,
u'calc' : Date.QUAL_CALCULATED,
u'calculado' : Date.QUAL_CALCULATED,
}
def init_strings(self):
DateParser.init_strings(self)
_span_1 = [u'de']
_span_2 = [u'a']
_range_1 = [u'entre',u'ent\.',u'ent']
_range_1 = [u'entre', u'ent\.', u'ent']
_range_2 = [u'y']
self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1),'|'.join(_span_2)),
re.IGNORECASE)
self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_range_1),'|'.join(_range_2)),
re.IGNORECASE)
self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1), '|'.join(_span_2)),
re.IGNORECASE)
self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_range_1), '|'.join(_range_2)),
re.IGNORECASE)
#-------------------------------------------------------------------------
#
@ -118,16 +118,16 @@ class DateDisplayES(DateDisplay):
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 = (
"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"
)
def display(self,date):
def display(self, date):
"""
Returns a text string representing the date.
"""
@ -145,18 +145,18 @@ class DateDisplayES(DateDisplay):
elif mod == Date.MOD_SPAN:
d1 = self.display_cal[cal](start)
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:
d1 = self.display_cal[cal](start)
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:
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_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
# (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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
@ -60,49 +60,50 @@ class DateParserFI(DateParser):
# examples:
# - ennen 1.1.2005
# - noin 1.1.2005
u'ennen' : Date.MOD_BEFORE,
u'e.' : Date.MOD_BEFORE,
u'noin' : Date.MOD_ABOUT,
u'n.' : Date.MOD_ABOUT,
u'ennen' : Date.MOD_BEFORE,
u'e.' : Date.MOD_BEFORE,
u'noin' : Date.MOD_ABOUT,
u'n.' : Date.MOD_ABOUT,
}
modifier_after_to_int = {
# examples:
# - 1.1.2005 jälkeen
u'jälkeen' : Date.MOD_AFTER,
u'j.' : Date.MOD_AFTER,
u'jälkeen' : Date.MOD_AFTER,
u'j.' : Date.MOD_AFTER,
}
bce = [u"ekr.", u"ekr"]
calendar_to_int = {
u'gregoriaaninen' : Date.CAL_GREGORIAN,
u'greg.' : Date.CAL_GREGORIAN,
u'juliaaninen' : Date.CAL_JULIAN,
u'jul.' : Date.CAL_JULIAN,
u'heprealainen' : Date.CAL_HEBREW,
u'hepr.' : Date.CAL_HEBREW,
u'islamilainen' : Date.CAL_ISLAMIC,
u'isl.' : Date.CAL_ISLAMIC,
u'ranskan vallankumouksen aikainen': Date.CAL_FRENCH,
u'ranskan v.' : Date.CAL_FRENCH,
u'persialainen' : Date.CAL_PERSIAN,
u'pers.' : Date.CAL_PERSIAN,
u'gregoriaaninen' : Date.CAL_GREGORIAN,
u'greg.' : Date.CAL_GREGORIAN,
u'juliaaninen' : Date.CAL_JULIAN,
u'jul.' : Date.CAL_JULIAN,
u'heprealainen' : Date.CAL_HEBREW,
u'hepr.' : Date.CAL_HEBREW,
u'islamilainen' : Date.CAL_ISLAMIC,
u'isl.' : Date.CAL_ISLAMIC,
u'ranskan vallankumouksen aikainen': Date.CAL_FRENCH,
u'ranskan v.' : Date.CAL_FRENCH,
u'persialainen' : Date.CAL_PERSIAN,
u'pers.' : Date.CAL_PERSIAN,
}
quality_to_int = {
u'arviolta' : Date.QUAL_ESTIMATED,
u'arv.' : Date.QUAL_ESTIMATED,
u'laskettuna' : Date.QUAL_CALCULATED,
u'lask.' : Date.QUAL_CALCULATED,
u'arviolta' : Date.QUAL_ESTIMATED,
u'arv.' : Date.QUAL_ESTIMATED,
u'laskettuna' : Date.QUAL_CALCULATED,
u'lask.' : Date.QUAL_CALCULATED,
}
def init_strings(self):
DateParser.init_strings(self)
# date, whitespace
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ä",
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)
#-------------------------------------------------------------------------
#
@ -111,11 +112,11 @@ class DateParserFI(DateParser):
#-------------------------------------------------------------------------
class DateDisplayFI(DateDisplay):
calendar = ("",
u"(juliaaninen)",
calendar = ("",
u"(juliaaninen)",
u"(heprealainen)",
u"(ranskan v.)",
u"(persialainen)",
u"(ranskan v.)",
u"(persialainen)",
u"(islamilainen)")
_qual_str = (u"", u"arviolta", u"laskettuna")
@ -123,11 +124,11 @@ class DateDisplayFI(DateDisplay):
_bce_str = u"%s ekr."
formats = (
"VVVV-KK-PP (ISO)",
"VVVV-KK-PP (ISO)",
"PP.KK.VVVV"
)
def display(self,date):
def display(self, date):
"""
Returns a text string representing the date.
"""
@ -160,19 +161,19 @@ class DateDisplayFI(DateDisplay):
text = u"%s ja %s välillä" % (d1, d2)
else:
text = self.display_cal[date.get_calendar()](start)
if mod == Date.MOD_AFTER:
text = text + u" jälkeen"
elif mod == Date.MOD_ABOUT:
text = u"noin " + text
elif mod == Date.MOD_BEFORE:
text = u"ennen " + text
if mod == Date.MOD_AFTER:
text = text + u" jälkeen"
elif mod == Date.MOD_ABOUT:
text = u"noin " + text
elif mod == Date.MOD_BEFORE:
text = u"ennen " + text
if qual:
# prepend quality
text = u"%s %s" % (self._qual_str[qual], text)
if cal:
# append calendar type
text = u"%s %s" % (text, self.calendar[cal])
if qual:
# prepend quality
text = u"%s %s" % (self._qual_str[qual], text)
if cal:
# append calendar type
text = u"%s %s" % (text, self.calendar[cal])
return text
@ -181,4 +182,4 @@ class DateDisplayFI(DateDisplay):
# 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
# (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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
@ -104,47 +104,47 @@ class DateParserFR(DateParser):
month_to_int[u"nebelmonat"] = 10
modifier_to_int = {
u'avant' : Date.MOD_BEFORE,
u'av.' : Date.MOD_BEFORE,
u'après' : Date.MOD_AFTER,
u'ap.' : Date.MOD_AFTER,
u'ap' : Date.MOD_AFTER,
u'env.' : Date.MOD_ABOUT,
u'env' : Date.MOD_ABOUT,
u'environ': Date.MOD_ABOUT,
u'circa' : Date.MOD_ABOUT,
u'c.' : Date.MOD_ABOUT,
u'ca' : Date.MOD_ABOUT,
u'ca.' : Date.MOD_ABOUT,
u'vers' : Date.MOD_ABOUT,
u'~' : Date.MOD_ABOUT,
u'avant' : Date.MOD_BEFORE,
u'av.' : Date.MOD_BEFORE,
u'après' : Date.MOD_AFTER,
u'ap.' : Date.MOD_AFTER,
u'ap' : Date.MOD_AFTER,
u'env.' : Date.MOD_ABOUT,
u'env' : Date.MOD_ABOUT,
u'environ': Date.MOD_ABOUT,
u'circa' : Date.MOD_ABOUT,
u'c.' : Date.MOD_ABOUT,
u'ca' : Date.MOD_ABOUT,
u'ca.' : Date.MOD_ABOUT,
u'vers' : Date.MOD_ABOUT,
u'~' : Date.MOD_ABOUT,
}
calendar_to_int = {
u'grégorien' : Date.CAL_GREGORIAN,
u'g' : Date.CAL_GREGORIAN,
u'julien' : Date.CAL_JULIAN,
u'j' : Date.CAL_JULIAN,
u'hébreu' : Date.CAL_HEBREW,
u'h' : Date.CAL_HEBREW,
u'islamique' : Date.CAL_ISLAMIC,
u'i' : Date.CAL_ISLAMIC,
u'révolutionnaire' : Date.CAL_FRENCH,
u'r' : Date.CAL_FRENCH,
u'perse' : Date.CAL_PERSIAN,
u'p' : Date.CAL_PERSIAN,
u'grégorien' : Date.CAL_GREGORIAN,
u'g' : Date.CAL_GREGORIAN,
u'julien' : Date.CAL_JULIAN,
u'j' : Date.CAL_JULIAN,
u'hébreu' : Date.CAL_HEBREW,
u'h' : Date.CAL_HEBREW,
u'islamique' : Date.CAL_ISLAMIC,
u'i' : Date.CAL_ISLAMIC,
u'révolutionnaire' : Date.CAL_FRENCH,
u'r' : Date.CAL_FRENCH,
u'perse' : Date.CAL_PERSIAN,
u'p' : Date.CAL_PERSIAN,
}
quality_to_int = {
u'estimée' : Date.QUAL_ESTIMATED,
u'est.' : Date.QUAL_ESTIMATED,
u'est' : Date.QUAL_ESTIMATED,
u'calculée' : Date.QUAL_CALCULATED,
u'calc.' : Date.QUAL_CALCULATED,
u'calc' : Date.QUAL_CALCULATED,
u'comptée' : Date.QUAL_CALCULATED,
u'compt' : Date.QUAL_CALCULATED,
u'compt.' : Date.QUAL_CALCULATED,
u'estimée' : Date.QUAL_ESTIMATED,
u'est.' : Date.QUAL_ESTIMATED,
u'est' : Date.QUAL_ESTIMATED,
u'calculée' : Date.QUAL_CALCULATED,
u'calc.' : Date.QUAL_CALCULATED,
u'calc' : Date.QUAL_CALCULATED,
u'comptée' : Date.QUAL_CALCULATED,
u'compt' : Date.QUAL_CALCULATED,
u'compt.' : Date.QUAL_CALCULATED,
}
def init_strings(self):
@ -153,25 +153,25 @@ class DateParserFR(DateParser):
# by allowing space after the slash/dot (need by fr_CH)
# and avoid bug gregorian / french calendar conversion (+/-10 days)
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._range = re.compile(u"(entre|ent\.|ent)\s+(?P<start>.+)\s+(et)\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)
# This self._text are different from the base
# by adding ".?" after the first date and removing "\s*$" at the end
#gregorian and julian
self._text2 =re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._mon_str,
re.IGNORECASE)
self._text2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._mon_str,
re.IGNORECASE)
#hebrew
self._jtext2 =re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._jmon_str,
re.IGNORECASE)
self._jtext2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._jmon_str,
re.IGNORECASE)
#french
self._ftext2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._fmon_str,
re.IGNORECASE)
self._ftext2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._fmon_str,
re.IGNORECASE)
#persian
self._ptext2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._pmon_str,
re.IGNORECASE)
self._ptext2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._pmon_str,
re.IGNORECASE)
#islamic
self._itext2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._imon_str,
re.IGNORECASE)
self._itext2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._imon_str,
re.IGNORECASE)
#-------------------------------------------------------------------------
#
@ -181,21 +181,21 @@ class DateParserFR(DateParser):
class DateDisplayFR(DateDisplay):
calendar = (
"", u" (Julien)", u" (Hébreu)",
"", u" (Julien)", u" (Hébreu)",
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 = (
"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"
)
def _display_gregorian(self,date_val):
year = self._slash_year(date_val[2],date_val[3])
def _display_gregorian(self, date_val):
year = self._slash_year(date_val[2], date_val[3])
if self.format == 0:
return self.display_iso(date_val)
elif self.format == 1:
@ -205,59 +205,59 @@ class DateDisplayFR(DateDisplay):
if date_val[0] == 0 and date_val[1] == 0:
value = str(date_val[2])
else:
value = self._tformat.replace('%m',str(date_val[1]))
value = value.replace('%d',str(date_val[0]))
value = self._tformat.replace('%m', str(date_val[1]))
value = value.replace('%d', str(date_val[0]))
# base_display :
# value = value.replace('%Y',str(abs(date_val[2])))
# value = value.replace('-','/')
value = value.replace('%Y',str(date_val[2]))
# value = value.replace('%Y', str(abs(date_val[2])))
# value = value.replace('-', '/')
value = value.replace('%Y', str(date_val[2]))
elif self.format == 2:
# Month Day, Year
if date_val[0] == 0:
if date_val[1] == 0:
value = year
else:
value = "%s %s" % (self._months[date_val[1]],year)
value = "%s %s" % (self._months[date_val[1]], year)
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:
# MON Day, Year
if date_val[0] == 0:
if date_val[1] == 0:
value = year
else:
value = "%s %s" % (self._MONS[date_val[1]],year)
value = "%s %s" % (self.MONS[date_val[1]], year)
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:
# Day Month Year
if date_val[0] == 0:
if date_val[1] == 0:
value = year
else:
value = "%s %s" % (self._months[date_val[1]],year)
value = "%s %s" % (self._months[date_val[1]], year)
else:
# 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:
# Day MON Year
if date_val[0] == 0:
if date_val[1] == 0:
value = year
else:
value = "%s %s" % (self._MONS[date_val[1]],year)
value = "%s %s" % (self.MONS[date_val[1]], year)
else:
# 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:
return self._bce_str % value
else:
return value
def display(self,date):
def display(self, date):
"""
Returns a text string representing the date.
"""
@ -275,14 +275,14 @@ class DateDisplayFR(DateDisplay):
elif mod == Date.MOD_SPAN:
d1 = self.display_cal[cal](start)
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:
d1 = self.display_cal[cal](start)
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:
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(
('fr_FR','fr','french','fr_CA','fr_BE','fr_CH'),
DateParserFR,DateDisplayFR)
('fr_FR', 'fr', 'french', 'fr_CA', 'fr_BE', 'fr_CH'),
DateParserFR, DateDisplayFR)

View File

@ -9,7 +9,7 @@
# the Free Software Foundation; either version 2 of the License, or
# (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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
@ -51,28 +51,28 @@ class DateParserLT(DateParser):
modifier_to_int = {
u'prieš' : Date.MOD_BEFORE,
u'po' : Date.MOD_AFTER,
u'apie' : Date.MOD_ABOUT,
u'po' : Date.MOD_AFTER,
u'apie' : Date.MOD_ABOUT,
}
calendar_to_int = {
u'grigaliaus' : Date.CAL_GREGORIAN,
u'g' : Date.CAL_GREGORIAN,
u'julijaus' : Date.CAL_JULIAN,
u'j' : Date.CAL_JULIAN,
u'hebrajų' : Date.CAL_HEBREW,
u'h' : Date.CAL_HEBREW,
u'islamo' : Date.CAL_ISLAMIC,
u'i' : Date.CAL_ISLAMIC,
u'prancuzų respublikos': Date.CAL_FRENCH,
u'r' : Date.CAL_FRENCH,
u'persų' : Date.CAL_PERSIAN,
u'p' : Date.CAL_PERSIAN,
u'grigaliaus' : Date.CAL_GREGORIAN,
u'g' : Date.CAL_GREGORIAN,
u'julijaus' : Date.CAL_JULIAN,
u'j' : Date.CAL_JULIAN,
u'hebrajų' : Date.CAL_HEBREW,
u'h' : Date.CAL_HEBREW,
u'islamo' : Date.CAL_ISLAMIC,
u'i' : Date.CAL_ISLAMIC,
u'prancuzų respublikos': Date.CAL_FRENCH,
u'r' : Date.CAL_FRENCH,
u'persų' : Date.CAL_PERSIAN,
u'p' : Date.CAL_PERSIAN,
}
quality_to_int = {
u'apytikriai' : Date.QUAL_ESTIMATED,
u'apskaičiuota' : Date.QUAL_CALCULATED,
u'apytikriai' : Date.QUAL_ESTIMATED,
u'apskaičiuota' : Date.QUAL_CALCULATED,
}
def init_strings(self):
@ -81,12 +81,14 @@ class DateParserLT(DateParser):
_span_2 = [u'iki']
_range_1 = [u'tarp']
_range_2 = [u'ir']
self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1),'|'.join(_span_2)),
re.IGNORECASE)
self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_range_1),'|'.join(_range_2)),
re.IGNORECASE)
self._span = re.compile(
"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1), '|'.join(_span_2)),
re.IGNORECASE)
self._range = re.compile(
"(%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)"
)
_mod_str = (u"",
u"prieš ",
u"po ",
u"apie ",
u"",u"",u"")
_mod_str = (u"",
u"prieš ",
u"po ",
u"apie ",
u"", u"", u"")
_qual_str = (u"",u"apytikriai ",u"apskaičiuota ")
_qual_str = (u"", u"apytikriai ", u"apskaičiuota ")
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"
)
def display(self,date):
def display(self, date):
"""
Returns a text string representing the date.
"""
@ -134,18 +136,21 @@ class DateDisplayLT(DateDisplay):
elif mod == Date.MOD_SPAN:
d1 = self.display_cal[cal](start)
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:
d1 = self.display_cal[cal](start)
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:
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_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
# (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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
@ -83,49 +83,49 @@ class DateParserNL(DateParser):
modifier_to_int = {
u'voor' : Date.MOD_BEFORE,
u'na' : Date.MOD_AFTER,
u'tegen' : Date.MOD_ABOUT,
u'om' : Date.MOD_ABOUT,
u'rond' : Date.MOD_ABOUT,
u'circa' : Date.MOD_ABOUT,
u'ca.' : Date.MOD_ABOUT,
u'na' : Date.MOD_AFTER,
u'tegen' : Date.MOD_ABOUT,
u'om' : Date.MOD_ABOUT,
u'rond' : Date.MOD_ABOUT,
u'circa' : Date.MOD_ABOUT,
u'ca.' : Date.MOD_ABOUT,
}
calendar_to_int = {
u'gregoriaans' : Date.CAL_GREGORIAN,
u'greg.' : Date.CAL_GREGORIAN,
u'juliaans' : Date.CAL_JULIAN,
u'jul.' : Date.CAL_JULIAN,
u'hebreeuws' : Date.CAL_HEBREW,
u'hebr.' : Date.CAL_HEBREW,
u'islamitisch' : Date.CAL_ISLAMIC,
u'isl.' : Date.CAL_ISLAMIC,
u'franse republiek': Date.CAL_FRENCH,
u'fran.' : Date.CAL_FRENCH,
u'persisch' : Date.CAL_PERSIAN,
u'gregoriaans' : Date.CAL_GREGORIAN,
u'greg.' : Date.CAL_GREGORIAN,
u'juliaans' : Date.CAL_JULIAN,
u'jul.' : Date.CAL_JULIAN,
u'hebreeuws' : Date.CAL_HEBREW,
u'hebr.' : Date.CAL_HEBREW,
u'islamitisch' : Date.CAL_ISLAMIC,
u'isl.' : Date.CAL_ISLAMIC,
u'franse republiek': Date.CAL_FRENCH,
u'fran.' : Date.CAL_FRENCH,
u'persisch' : Date.CAL_PERSIAN,
}
quality_to_int = {
u'geschat' : Date.QUAL_ESTIMATED,
u'gesch.' : Date.QUAL_ESTIMATED,
u'berekend' : Date.QUAL_CALCULATED,
u'ber.' : Date.QUAL_CALCULATED,
u'geschat' : Date.QUAL_ESTIMATED,
u'gesch.' : Date.QUAL_ESTIMATED,
u'berekend' : 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):
DateParser.init_strings(self)
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,
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)
#-------------------------------------------------------------------------
#
@ -139,19 +139,19 @@ class DateDisplayNL(DateDisplay):
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."
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"
)
def _display_gregorian(self,date_val):
year = self._slash_year(date_val[2],date_val[3])
def _display_gregorian(self, date_val):
year = self._slash_year(date_val[2], date_val[3])
if self.format == 0:
return self.display_iso(date_val)
elif self.format == 1:
@ -162,52 +162,52 @@ class DateDisplayNL(DateDisplay):
if date_val[0] == 0 and date_val[1] == 0:
value = str(date_val[2])
else:
value = self._tformat.replace('%m',str(date_val[1]))
value = value.replace('%d',str(date_val[0]))
value = value.replace('%Y',str(abs(date_val[2])))
value = value.replace('-','/')
value = self._tformat.replace('%m', str(date_val[1]))
value = value.replace('%d', str(date_val[0]))
value = value.replace('%Y', str(abs(date_val[2])))
value = value.replace('-', '/')
elif self.format == 2:
# Month Day, Year
if date_val[0] == 0:
if date_val[1] == 0:
value = year
else:
value = "%s %s" % (self._months[date_val[1]],year)
value = "%s %s" % (self._months[date_val[1]], year)
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:
# Mnd Day, Year
if date_val[0] == 0:
if date_val[1] == 0:
value = year
else:
value = "%s %s" % (self._MONS[date_val[1]],year)
value = "%s %s" % (self.MONS[date_val[1]], year)
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:
# Day Month Year
if date_val[0] == 0:
if date_val[1] == 0:
value = year
else:
value = "%s %s" % (self._months[date_val[1]],year)
value = "%s %s" % (self._months[date_val[1]], year)
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:
# Day Mnd Year
if date_val[0] == 0:
if date_val[1] == 0:
value = year
else:
value = "%s %s" % (self._MONS[date_val[1]],year)
value = "%s %s" % (self.MONS[date_val[1]], year)
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:
return self._bce_str % value
else:
return value
def display(self,date):
def display(self, date):
"""
Returns a text string representing the date.
"""
@ -225,19 +225,22 @@ class DateDisplayNL(DateDisplay):
elif mod == Date.MOD_SPAN:
d1 = self.display_cal[cal](start)
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:
d1 = self.display_cal[cal](start)
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:
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_datehandler(('nl_NL','dutch','nl_BE','nl'),
register_datehandler(('nl_NL', 'dutch', 'nl_BE', 'nl'),
DateParserNL, DateDisplayNL)

View File

@ -9,7 +9,7 @@
# the Free Software Foundation; either version 2 of the License, or
# (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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
@ -51,112 +51,112 @@ class DateParserRU(DateParser):
modifier_to_int = {
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_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_BEFORE,
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,
}
calendar_to_int = {
u'григорианский' : Date.CAL_GREGORIAN,
u'г' : Date.CAL_GREGORIAN,
u'юлианский' : Date.CAL_JULIAN,
u'ю' : Date.CAL_JULIAN,
u'еврейский' : Date.CAL_HEBREW,
u'е' : Date.CAL_HEBREW,
u'исламский' : Date.CAL_ISLAMIC,
u'и' : Date.CAL_ISLAMIC,
u'республиканский': Date.CAL_FRENCH,
u'р' : Date.CAL_FRENCH,
u'персидский' : Date.CAL_PERSIAN,
u'п' : Date.CAL_PERSIAN,
u'григорианский' : Date.CAL_GREGORIAN,
u'г' : Date.CAL_GREGORIAN,
u'юлианский' : Date.CAL_JULIAN,
u'ю' : Date.CAL_JULIAN,
u'еврейский' : Date.CAL_HEBREW,
u'е' : Date.CAL_HEBREW,
u'исламский' : Date.CAL_ISLAMIC,
u'и' : Date.CAL_ISLAMIC,
u'республиканский': Date.CAL_FRENCH,
u'р' : Date.CAL_FRENCH,
u'персидский' : Date.CAL_PERSIAN,
u'п' : Date.CAL_PERSIAN,
}
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_CALCULATED,
u'вычисл.' : Date.QUAL_CALCULATED,
u'выч.' : Date.QUAL_CALCULATED,
u'вычисл' : Date.QUAL_CALCULATED,
u'выч' : Date.QUAL_CALCULATED,
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,
}
hebrew_to_int = {
u"тишрей":1,
u"хешван":2,
u"кислев":3,
u"тевет":4,
u"шеват":5,
u"адар":6,
u"адар бет":7,
u"нисан":8,
u"ияр":9,
u"сиван":10,
u"таммуз":11,
u"ав":12,
u"элул":13,
u"тишрей":1,
u"хешван":2,
u"кислев":3,
u"тевет":4,
u"шеват":5,
u"адар":6,
u"адар бет":7,
u"нисан":8,
u"ияр":9,
u"сиван":10,
u"таммуз":11,
u"ав":12,
u"элул":13,
}
islamic_to_int = {
u"мухаррам":1,
u"сафар":2,
u"раби-аль-авваль":3,
u"раби-ассани":4,
u"джумада-аль-уля":5,
u"джумада-аль-ахира":6,
u"раджаб":7,
u"шаабан":8,
u"рамадан":9,
u"шавваль":10,
u"зуль-каада":11,
u"зуль-хиджжа":12,
u"мухаррам":1,
u"сафар":2,
u"раби-аль-авваль":3,
u"раби-ассани":4,
u"джумада-аль-уля":5,
u"джумада-аль-ахира":6,
u"раджаб":7,
u"шаабан":8,
u"рамадан":9,
u"шавваль":10,
u"зуль-каада":11,
u"зуль-хиджжа":12,
}
persian_to_int = {
u"фарвардин":1,
u"урдбихишт":2,
u"хурдад":3,
u"тир":4,
u"мурдад":5,
u"шахривар":6,
u"михр":7,
u"абан":8,
u"азар":9,
u"дай":10,
u"бахман":11,
u"исфаидармуз":12,
u"фарвардин":1,
u"урдбихишт":2,
u"хурдад":3,
u"тир":4,
u"мурдад":5,
u"шахривар":6,
u"михр":7,
u"абан":8,
u"азар":9,
u"дай":10,
u"бахман":11,
u"исфаидармуз":12,
}
french_to_int = {
u"вандемьер":1,
u"брюмер":2,
u"фример":3,
u"нивоз":4,
u"вандемьер":1,
u"брюмер":2,
u"фример":3,
u"нивоз":4,
u"плювиоз":5,
u"вантоз":6,
u"жерминаль":7,
u"флореаль":8,
u"прериаль":9,
u"мессидор":10,
u"термидор":11,
u"фрюктидор":12,
u"дополнит.":13,
u"вантоз":6,
u"жерминаль":7,
u"флореаль":8,
u"прериаль":9,
u"мессидор":10,
u"термидор":11,
u"фрюктидор":12,
u"дополнит.":13,
}
bce = [
@ -165,17 +165,17 @@ class DateParserRU(DateParser):
def init_strings(self):
DateParser.init_strings(self)
_span_1 = [u'с',u'от']
_span_1 = [u'с', u'от']
_span_2 = [u'по']
_range_1 = [u'между',u'меж\.',u'меж']
_range_1 = [u'между', u'меж\.', u'меж']
_range_2 = [u'и']
self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1),'|'.join(_span_2)),
re.IGNORECASE)
('|'.join(_span_1), '|'.join(_span_2)),
re.IGNORECASE)
self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_range_1),'|'.join(_range_2)),
re.IGNORECASE)
('|'.join(_range_1), '|'.join(_range_2)),
re.IGNORECASE)
#-------------------------------------------------------------------------
#
# Russian displayer
@ -184,7 +184,7 @@ class DateParserRU(DateParser):
class DateDisplayRU(DateDisplay):
calendar = (
u"",
u"",
u" (юлианский)",
u" (еврейский)",
u" (республиканский)",
@ -193,84 +193,84 @@ class DateDisplayRU(DateDisplay):
)
_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 до н.э."
formats = (
"ГГГГ-ММ-ДД (ISO)", "Численный", "Месяц День, Год",
"ГГГГ-ММ-ДД (ISO)", "Численный", "Месяц День, Год",
"МЕС ДД, ГГГГГ", "День Месяц, Год", "ДД МЕС, ГГГГГ"
)
_hebrew = ( u"",
u"Тишрей",
u"Хешван",
u"Кислев",
u"Тевет",
u"Шеват",
u"Адар",
u"Адар бет",
u"Нисан",
u"Ияр",
u"Сиван",
u"Таммуз",
u"Ав",
u"Элул",
hebrew = ( u"",
u"Тишрей",
u"Хешван",
u"Кислев",
u"Тевет",
u"Шеват",
u"Адар",
u"Адар бет",
u"Нисан",
u"Ияр",
u"Сиван",
u"Таммуз",
u"Ав",
u"Элул",
)
_islamic = ( u"",
u"Мухаррам",
u"Сафар",
u"Раби-аль-авваль",
u"Раби-ассани",
u"Джумада-аль-уля",
u"Джумада-аль-ахира",
u"Раджаб",
u"Шаабан",
u"Рамадан",
u"Шавваль",
u"Зуль-каада",
u"Зуль-хиджжа",
islamic = ( u"",
u"Мухаррам",
u"Сафар",
u"Раби-аль-авваль",
u"Раби-ассани",
u"Джумада-аль-уля",
u"Джумада-аль-ахира",
u"Раджаб",
u"Шаабан",
u"Рамадан",
u"Шавваль",
u"Зуль-каада",
u"Зуль-хиджжа",
)
_persian = ( u"",
u"Фарвардин",
u"Урдбихишт",
u"Хурдад",
u"Тир",
u"Мурдад",
u"Шахривар",
u"Михр",
u"Абан",
u"Азар",
u"Дай",
u"Бахман",
u"Исфаидармуз",
persian = ( u"",
u"Фарвардин",
u"Урдбихишт",
u"Хурдад",
u"Тир",
u"Мурдад",
u"Шахривар",
u"Михр",
u"Абан",
u"Азар",
u"Дай",
u"Бахман",
u"Исфаидармуз",
)
_french = ( u"",
u"Вандемьер",
u"Брюмер",
u"Фример",
u"Нивоз",
french = ( 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.
"""
@ -288,18 +288,21 @@ class DateDisplayRU(DateDisplay):
elif mod == Date.MOD_SPAN:
d1 = self.display_cal[cal](start)
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:
d1 = self.display_cal[cal](start)
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:
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_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
# (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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
@ -19,7 +19,7 @@
# 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.
@ -50,34 +50,34 @@ from _DateHandler import register_datehandler
class DateParserSK(DateParser):
modifier_to_int = {
u'pred' : Date.MOD_BEFORE,
u'do' : Date.MOD_BEFORE,
u'po' : Date.MOD_AFTER,
u'asi' : Date.MOD_ABOUT,
u'okolo' : Date.MOD_ABOUT,
u'pribl.' : Date.MOD_ABOUT,
u'pred' : Date.MOD_BEFORE,
u'do' : Date.MOD_BEFORE,
u'po' : Date.MOD_AFTER,
u'asi' : Date.MOD_ABOUT,
u'okolo' : Date.MOD_ABOUT,
u'pribl.' : Date.MOD_ABOUT,
}
calendar_to_int = {
u'gregoriánsky' : Date.CAL_GREGORIAN,
u'g' : Date.CAL_GREGORIAN,
u'juliánský' : Date.CAL_JULIAN,
u'j' : Date.CAL_JULIAN,
u'hebrejský' : Date.CAL_HEBREW,
u'h' : Date.CAL_HEBREW,
u'islamský' : Date.CAL_ISLAMIC,
u'i' : Date.CAL_ISLAMIC,
u'republikánsky': Date.CAL_FRENCH,
u'r' : Date.CAL_FRENCH,
u'perzský' : Date.CAL_PERSIAN,
u'p' : Date.CAL_PERSIAN,
u'gregoriánsky' : Date.CAL_GREGORIAN,
u'g' : Date.CAL_GREGORIAN,
u'juliánský' : Date.CAL_JULIAN,
u'j' : Date.CAL_JULIAN,
u'hebrejský' : Date.CAL_HEBREW,
u'h' : Date.CAL_HEBREW,
u'islamský' : Date.CAL_ISLAMIC,
u'i' : Date.CAL_ISLAMIC,
u'republikánsky' : Date.CAL_FRENCH,
u'r' : Date.CAL_FRENCH,
u'perzský' : Date.CAL_PERSIAN,
u'p' : Date.CAL_PERSIAN,
}
quality_to_int = {
u'odhadovaný' : Date.QUAL_ESTIMATED,
u'odh.' : Date.QUAL_ESTIMATED,
u'vypočítaný' : Date.QUAL_CALCULATED,
u'vyp.' : Date.QUAL_CALCULATED,
u'odhadovaný' : Date.QUAL_ESTIMATED,
u'odh.' : Date.QUAL_ESTIMATED,
u'vypočítaný' : Date.QUAL_CALCULATED,
u'vyp.' : Date.QUAL_CALCULATED,
}
def init_strings(self):
@ -86,12 +86,12 @@ class DateParserSK(DateParser):
_span_2 = [u'do']
_range_1 = [u'medzi']
_range_2 = [u'a']
self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1),'|'.join(_span_2)),
re.IGNORECASE)
self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_range_1),'|'.join(_range_2)),
re.IGNORECASE)
self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1), '|'.join(_span_2)),
re.IGNORECASE)
self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_range_1), '|'.join(_range_2)),
re.IGNORECASE)
#-------------------------------------------------------------------------
#
@ -105,16 +105,16 @@ class DateDisplaySK(DateDisplay):
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 = (
"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"
)
def display(self,date):
def display(self, date):
"""
Returns a text string representing the date.
"""
@ -132,18 +132,21 @@ class DateDisplaySK(DateDisplay):
elif mod == Date.MOD_SPAN:
d1 = self.display_cal[cal](start)
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:
d1 = self.display_cal[cal](start)
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:
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_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
# (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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
@ -50,53 +50,53 @@ from _DateHandler import register_datehandler
class DateParserSv(DateParser):
"""
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.
"""
# modifiers before the date
modifier_to_int = {
u'före' : Date.MOD_BEFORE,
u'innan' : Date.MOD_BEFORE,
u'efter' : Date.MOD_AFTER,
u'omkring' : Date.MOD_ABOUT,
u'ca' : Date.MOD_ABOUT,
u'före' : Date.MOD_BEFORE,
u'innan' : Date.MOD_BEFORE,
u'efter' : Date.MOD_AFTER,
u'omkring' : Date.MOD_ABOUT,
u'ca' : Date.MOD_ABOUT,
u'c:a' : Date.MOD_ABOUT
}
bce = ["f Kr"]
calendar_to_int = {
u'gregoriansk ' : Date.CAL_GREGORIAN,
u'g' : Date.CAL_GREGORIAN,
u'juliansk' : Date.CAL_JULIAN,
u'j' : Date.CAL_JULIAN,
u'hebreisk' : Date.CAL_HEBREW,
u'h' : Date.CAL_HEBREW,
u'islamisk' : Date.CAL_ISLAMIC,
u'muslimsk' : Date.CAL_ISLAMIC,
u'i' : Date.CAL_ISLAMIC,
u'fransk' : Date.CAL_FRENCH,
u'fransk republikansk' : Date.CAL_FRENCH,
u'f' : Date.CAL_FRENCH,
u'persisk' : Date.CAL_PERSIAN,
u'p' : Date.CAL_PERSIAN,
u'gregoriansk ' : Date.CAL_GREGORIAN,
u'g' : Date.CAL_GREGORIAN,
u'juliansk' : Date.CAL_JULIAN,
u'j' : Date.CAL_JULIAN,
u'hebreisk' : Date.CAL_HEBREW,
u'h' : Date.CAL_HEBREW,
u'islamisk' : Date.CAL_ISLAMIC,
u'muslimsk' : Date.CAL_ISLAMIC,
u'i' : Date.CAL_ISLAMIC,
u'fransk' : Date.CAL_FRENCH,
u'fransk republikansk' : Date.CAL_FRENCH,
u'f' : Date.CAL_FRENCH,
u'persisk' : Date.CAL_PERSIAN,
u'p' : Date.CAL_PERSIAN,
}
quality_to_int = {
u'uppskattat' : Date.QUAL_ESTIMATED,
u'uppskattad' : Date.QUAL_ESTIMATED,
u'bedömt' : Date.QUAL_ESTIMATED,
u'bedömd' : Date.QUAL_ESTIMATED,
u'beräknat' : Date.QUAL_CALCULATED,
u'beräknad' : Date.QUAL_CALCULATED,
u'uppskattat' : Date.QUAL_ESTIMATED,
u'uppskattad' : Date.QUAL_ESTIMATED,
u'bedömt' : Date.QUAL_ESTIMATED,
u'bedömd' : Date.QUAL_ESTIMATED,
u'beräknat' : Date.QUAL_CALCULATED,
u'beräknad' : Date.QUAL_CALCULATED,
}
def 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)
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)
#-------------------------------------------------------------------------
@ -110,30 +110,30 @@ class DateDisplaySv(DateDisplay):
"""
formats = (
u"YYYY-MM-DD (ISO)",
u"Numerisk",
u"Månad dag, år",
u"MÅN DAG ÅR",
u"Dag månad år",
u"DAG MÅN ÅR",
u"YYYY-MM-DD (ISO)",
u"Numerisk",
u"Månad dag, år",
u"MÅN DAG ÅR",
u"Dag månad år",
u"DAG MÅN ÅR",
)
calendar = (
"",
" (juliansk)",
" (hebreisk)",
" (fransk republikansk)",
" (persisk)",
"",
" (juliansk)",
" (hebreisk)",
" (fransk republikansk)",
" (persisk)",
" (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"
def display(self,date):
def display(self, date):
"""
Returns a text string representing the date.
"""
@ -151,20 +151,20 @@ class DateDisplaySv(DateDisplay):
elif mod == Date.MOD_SPAN:
d1 = self.display_cal[cal](start)
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:
d1 = self.display_cal[cal](start)
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])
else:
text = self.display_cal[date.get_calendar()](start)
return u"%s%s%s%s" % (qual_str,self._mod_str[mod],
text,self.calendar[cal])
return u"%s%s%s%s" % (qual_str, self._mod_str[mod],
text, self.calendar[cal])
#-------------------------------------------------------------------------
#
# 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
# (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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# 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
from _DateHandler import _lang, _lang_short, \
_lang_to_parser, _lang_to_display, register_datehandler
from _DateHandler import LANG, LANG_SHORT, \
LANG_TO_PARSER, LANG_TO_DISPLAY, register_datehandler
# Import all the localized handlers
import _Date_de
@ -41,32 +41,32 @@ import _Date_sk
# Initialize global parser
try:
if _lang_to_parser.has_key(_lang):
parser = _lang_to_parser[_lang]()
if LANG_TO_PARSER.has_key(LANG):
parser = LANG_TO_PARSER[LANG]()
else:
parser = _lang_to_parser[_lang_short]()
parser = LANG_TO_PARSER[LANG_SHORT]()
except:
print "Date parser for",_lang,"not available, using default"
parser = _lang_to_parser["C"]()
print "Date parser for", LANG, "not available, using default"
parser = LANG_TO_PARSER["C"]()
# Initialize global displayer
try:
import Config
val = Config.get_date_format(_lang_to_display[_lang].formats)
val = Config.get_date_format(LANG_TO_DISPLAY[LANG].formats)
except:
try:
val = Config.get_date_format(_lang_to_display["C"].formats)
val = Config.get_date_format(LANG_TO_DISPLAY["C"].formats)
except:
val = 0
try:
if _lang_to_display.has_key(_lang):
displayer = _lang_to_display[_lang](val)
if LANG_TO_DISPLAY.has_key(LANG):
displayer = LANG_TO_DISPLAY[LANG](val)
else:
displayer = _lang_to_display[_lang_short](val)
displayer = LANG_TO_DISPLAY[LANG_SHORT](val)
except:
print "Date displayer for",_lang,"not available, using default"
displayer = _lang_to_display["C"](val)
print "Date displayer for", LANG, "not available, using default"
displayer = LANG_TO_DISPLAY["C"](val)
# Import utility functions