[Zope3-checkins] CVS: Zope3/src/zope/i18n - format.py:1.3 interfaces.py:1.4 locales.py:1.8
Albertas Agejevas
alga@codeworks.lt
Thu, 13 Mar 2003 13:49:44 -0500
Update of /cvs-repository/Zope3/src/zope/i18n
In directory cvs.zope.org:/tmp/cvs-serv1411/src/zope/i18n
Modified Files:
format.py interfaces.py locales.py
Log Message:
An unexpected raid by the Whitespace Police.
Other than fixes of nonconforming whitespace, just a couple of $Id$
docstrings has been added.
=== Zope3/src/zope/i18n/format.py 1.2 => 1.3 ===
--- Zope3/src/zope/i18n/format.py:1.2 Mon Jan 6 04:24:42 2003
+++ Zope3/src/zope/i18n/format.py Thu Mar 13 13:49:13 2003
@@ -94,7 +94,7 @@
ordered[1] = self.calendar.getMonthIdFromName(name)
# Handle AM/PM hours
for length in (1, 2):
- id = ('h', length)
+ id = ('h', length)
if id in bin_pattern:
ampm = self.calendar.getPM() == results[
bin_pattern.index(('a', 1))]
@@ -103,7 +103,7 @@
dt_fields_map = {'M': 1, 'd': 2, 'H': 3, 'm': 4, 's': 5, 'S': 6}
for field in dt_fields_map.keys():
for length in (1, 2):
- id = (field, length)
+ id = (field, length)
if id in bin_pattern:
pos = dt_fields_map[field]
ordered[pos] = int(results[bin_pattern.index(id)])
@@ -123,7 +123,7 @@
bin_pattern = parseDateTimePattern(pattern)
else:
bin_pattern = self._bin_pattern
-
+
text = ''
info = buildDateTimeInfo(obj, self.calendar)
for elem in bin_pattern:
@@ -171,7 +171,7 @@
def getPattern(self):
"See zope.i18n.interfaces.IFormat"
return self._pattern
-
+
def parse(self, text, pattern=None):
"See zope.i18n.interfaces.IFormat"
# Make or get binary form of datetime pattern
@@ -232,7 +232,7 @@
type = float
num_str.replace(self.symbols['exponential'], 'E')
return sign*type(num_str)
-
+
def _format_integer(self, integer, pattern):
size = len(integer)
min_size = pattern.count('0')
@@ -252,7 +252,7 @@
if fraction != '':
fraction = self.symbols['decimal'] + fraction
return fraction
-
+
def format(self, obj, pattern=None):
"See zope.i18n.interfaces.IFormat"
# Make or get binary form of datetime pattern
@@ -295,7 +295,7 @@
pre_padding = len(bin_pattern[FRACTION]) - len(number) + 2
post_padding = len(bin_pattern[EXPONENTIAL]) - len(exponent)
number += self.symbols['exponential'] + exponent
-
+
else:
obj_int_frac = str(obj).split('.')
if len(obj_int_frac) > 1:
@@ -304,7 +304,7 @@
else:
fraction = ''
integer = self._format_integer(str(int(math.fabs(obj))),
- bin_pattern[INTEGER])
+ bin_pattern[INTEGER])
# Adding grouping
if bin_pattern[GROUPING] == 1:
help = ''
@@ -336,7 +336,7 @@
text += bin_pattern[SUFFIX]
if bin_pattern[PADDING4] is not None and post_padding > 0:
text += bin_pattern[PADDING4]*post_padding
-
+
return text
@@ -366,7 +366,7 @@
char = ''
quote_start = -2
- for pos in range(len(pattern)):
+ for pos in range(len(pattern)):
prev_char = char
char = pattern[pos]
# Handle quotations
@@ -379,7 +379,7 @@
state = DEFAULT
elif state == IN_QUOTE:
# Do not care about putting the content of the quote in the
- # result. The next state is responsible for that.
+ # result. The next state is responsible for that.
quote_start = -1
state = DEFAULT
elif state == IN_DATETIMEFIELD:
@@ -410,7 +410,7 @@
elif state == IN_DATETIMEFIELD and prev_char == char:
helper += char
-
+
elif state == IN_DATETIMEFIELD and prev_char != char:
result.append((helper[0], len(helper)))
helper = char
@@ -459,7 +459,7 @@
('H', 1): r'([0-9]{1,2})',
('H', 2): r'([0-9]{2})',
('m', 1): r'([0-9]{1,2})',
- ('m', 2): r'([0-9]{2})',
+ ('m', 2): r'([0-9]{2})',
('s', 1): r'([0-9]{1, 2})',
('s', 2): r'([0-9]{2})',
('S', 1): r'([0-9]{0, 6})',
@@ -471,7 +471,7 @@
('k', 1): r'([0-9]{1, 2})',
('k', 2): r'([0-9]{2})',
('K', 1): r'([0-9]{1, 2})',
- ('K', 2): r'([0-9]{2})',
+ ('K', 2): r'([0-9]{2})',
('z', 1): r'([\+-][0-9]{3,4})',
('z', 2): r'([\+-][0-9]{2}:[0-9]{2})',
('z', 3): r'([a-zA-Z]{3})',
@@ -485,14 +485,14 @@
if isinstance(dt, datetime.time):
dt = datetime.datetime(1969, 01, 01, dt.hour, dt.minute, dt.second,
dt.microsecond)
- elif ( isinstance(dt, datetime.date) and
- not isinstance(dt, datetime.datetime)):
+ elif (isinstance(dt, datetime.date) and
+ not isinstance(dt, datetime.datetime)):
dt = datetime.datetime(dt.year, dt.month, dt.day)
-
+
if dt.hour >= 12:
ampm = calendar.getPM()
else:
- ampm = calendar.getAM()
+ ampm = calendar.getAM()
return {
('a', 1): ampm,
('G', 1): 'AD',
@@ -512,24 +512,24 @@
('w', 1): dt.strftime('%W'),
('w', 2): dt.strftime('%.2W'),
('h', 1): str(dt.hour%12+1),
- ('h', 2): "%.2i" %(dt.hour%12),
+ ('h', 2): "%.2i" %(dt.hour%12),
('H', 1): str(dt.hour),
- ('H', 2): "%.2i" %dt.hour,
+ ('H', 2): "%.2i" %dt.hour,
('m', 1): str(dt.minute),
- ('m', 2): "%.2i" %dt.minute,
+ ('m', 2): "%.2i" %dt.minute,
('s', 1): str(dt.second),
- ('s', 2): "%.2i" %dt.second,
+ ('s', 2): "%.2i" %dt.second,
('S', 1): str(dt.microsecond),
- ('S', 2): "%.6i" %dt.microsecond,
+ ('S', 2): "%.6i" %dt.microsecond,
# XXX not yet implemented
('F', 1): str(2),
('F', 2): "%.2i" %(2),
('W', 1): str(2),
('W', 2): "%.2i" %(2),
('k', 1): str(dt.hour+1),
- ('k', 2): "%.2i" %(dt.hour+1),
+ ('k', 2): "%.2i" %(dt.hour+1),
('K', 1): str(dt.hour%12),
- ('K', 2): "%.2i" %(dt.hour%12),
+ ('K', 2): "%.2i" %(dt.hour%12),
('z', 1): "+000",
('z', 2): "+00:00",
('z', 3): "UTC",
@@ -571,10 +571,10 @@
def parseNumberPattern(pattern):
"""Parses all sorts of number pattern."""
prefix = ''
- padding_1 = None
- padding_2 = None
- padding_3 = None
- padding_4 = None
+ padding_1 = None
+ padding_2 = None
+ padding_3 = None
+ padding_4 = None
integer = ''
fraction = ''
exponential = ''
@@ -651,7 +651,7 @@
state = READ_NEG_SUBPATTERN
elif char == "'":
integer = helper
- state = READ_SUFFIX_STRING
+ state = READ_SUFFIX_STRING
else:
integer = helper
suffix += char
@@ -673,7 +673,7 @@
state = READ_NEG_SUBPATTERN
elif char == "'":
fraction = helper
- state = READ_SUFFIX_STRING
+ state = READ_SUFFIX_STRING
else:
fraction = helper
suffix += char
@@ -691,7 +691,7 @@
state = READ_NEG_SUBPATTERN
elif char == "'":
exponential = helper
- state = READ_SUFFIX_STRING
+ state = READ_SUFFIX_STRING
else:
exponential = helper
suffix += char
@@ -710,7 +710,7 @@
state = READ_NEG_SUBPATTERN
else:
suffix += char
-
+
elif state == READ_SUFFIX_STRING:
if char == "'":
state = READ_SUFFIX
@@ -740,7 +740,7 @@
if neg_pattern is None:
neg_pattern = pattern
-
+
return pattern, neg_pattern
=== Zope3/src/zope/i18n/interfaces.py 1.3 => 1.4 ===
--- Zope3/src/zope/i18n/interfaces.py:1.3 Thu Jan 23 10:25:03 2003
+++ Zope3/src/zope/i18n/interfaces.py Thu Mar 13 13:49:13 2003
@@ -403,7 +403,7 @@
sense to have many locale facilities, especially since this one will be so
complete, since we will the ICU XML Files as data. """
- def loadLocale(language=None, country=None, variant=None):
+ def loadLocale(language=None, country=None, variant=None):
"""Load the locale with the specs that are given by the arguments of
the method. Note that the LocaleProvider must know where to get the
locales from."""
@@ -427,7 +427,7 @@
o variant -- Sometimes there are regional or historical differences even
in a certain country. For these cases we use the variant field. A good
example is the time before the Euro in Germany for example. Therefore
- a valid variant would be 'PREEURO'.
+ a valid variant would be 'PREEURO'.
Note that all of these attributes are read-only once they are set (usually
done in constructor)!
@@ -475,7 +475,7 @@
Important: ILocaleTimeZone objects are not intended to provide
implementations for the standard datetime module timezone support. They
- are merily used for Locale support.
+ are merily used for Locale support.
"""
id = Attribute("Standard name of the timezone for unique referencing.")
@@ -501,7 +501,7 @@
"""Update this calendar using data from other. Assume that unless
other's data is not present, other has always more specific
information."""
-
+
def setMonth(id, name, abbr):
"""Add a month's locale data."""
@@ -565,25 +565,25 @@
def setTimePattern(type, pattern):
"""Set the time pattern for a particular time format type. Possible
- types are full, long, medium, and short."""
+ types are full, long, medium, and short."""
def getTimePattern(type):
"""Get the time pattern for a particular time format type. Possible
- types are full, long, medium, and short."""
+ types are full, long, medium, and short."""
def setDatePattern(name, pattern):
"""Set the date pattern for a particular date format type. Possible
- types are full, long, medium, and short."""
+ types are full, long, medium, and short."""
def getDatePattern(name):
"""Get the date pattern for a particular date format type. Possible
- types are full, long, medium, and short."""
+ types are full, long, medium, and short."""
def setDateTimePattern(pattern):
- """Set the date pattern for the datetime."""
+ """Set the date pattern for the datetime."""
def getDateTimePattern():
- """Get the date pattern for the datetime."""
+ """Get the date pattern for the datetime."""
class ILocaleNumberFormat(Interface):
@@ -611,7 +611,7 @@
def getSymbolMap():
"""Return a map of all symbols. Thisis useful for the INumberFormat."""
-
+
class ILocaleCurrency(Interface):
"""Defines a particular currency."""
@@ -640,9 +640,9 @@
currency unit is often not desired."""
def getPattern():
- """Get currency pattern."""
+ """Get currency pattern."""
+
-
class ILocale(Interface):
"""This class contains all important information about the locale.
@@ -651,7 +651,7 @@
hierarchy develops. It is easy to recognize that a locale that is missing
the variant is more general applicable than the one with the
variant. Therefore, if a specific Locale does not contain the required
- information, it should look one level higher.
+ information, it should look one level higher.
There will be a root locale that specifies none of the above identifiers.
"""
@@ -719,50 +719,50 @@
rules (I modified the rules from ICU a bit, since I think they did not
agree well with the real world XML formatting strings):
- posNegPattern := ({subpattern};{subpattern} | {subpattern})
+ posNegPattern := ({subpattern};{subpattern} | {subpattern})
subpattern := {padding}{prefix}{padding}{integer}{fraction}
- {exponential}{padding}{suffix}{padding}
- prefix := '\u0000'..'\uFFFD' - specialCharacters *
+ {exponential}{padding}{suffix}{padding}
+ prefix := '\u0000'..'\uFFFD' - specialCharacters *
suffix := '\u0000'..'\uFFFD' - specialCharacters *
- integer := {digitField}'0'
- fraction := {decimalPoint}{digitField}
+ integer := {digitField}'0'
+ fraction := {decimalPoint}{digitField}
exponential := E integer
- digitField := ( {digitField} {groupingSeparator} |
- {digitField} '0'* |
- '0'* |
- {optionalDigitField} )
- optionalDigitField := ( {digitField} {groupingSeparator} |
- {digitField} '#'* |
- '#'* )
- groupingSeparator := ,
- decimalPoint := .
+ digitField := ( {digitField} {groupingSeparator} |
+ {digitField} '0'* |
+ '0'* |
+ {optionalDigitField} )
+ optionalDigitField := ( {digitField} {groupingSeparator} |
+ {digitField} '#'* |
+ '#'* )
+ groupingSeparator := ,
+ decimalPoint := .
padding := * '\u0000'..'\uFFFD'
Possible pattern symbols:
- 0 A digit. Always show this digit even if the value is zero.
- # A digit, suppressed if zero
- . Placeholder for decimal separator
- , Placeholder for grouping separator
- E Separates mantissa and exponent for exponential formats
+ 0 A digit. Always show this digit even if the value is zero.
+ # A digit, suppressed if zero
+ . Placeholder for decimal separator
+ , Placeholder for grouping separator
+ E Separates mantissa and exponent for exponential formats
; Separates formats (that is, a positive number format verses a
negative number format)
- Default negative prefix. Note that the locale's minus sign
character is used.
+ If this symbol is specified the locale's plus sign character is
used.
- % Multiply by 100, as percentage
- ? Multiply by 1000, as per mille
+ % Multiply by 100, as percentage
+ ? Multiply by 1000, as per mille
\u00A4 This is the currency sign. it will be replaced by a currency
symbol. If it is present in a pattern, the monetary decimal
separator is used instead of the decimal separator.
- \u00A4\u00A4 This is the international currency sign. It will be replaced
+ \u00A4\u00A4 This is the international currency sign. It will be replaced
by an international currency symbol. If it is present in a
- pattern, the monetary decimal separator is used instead of
- the decimal separator.
- X Any other characters can be used in the prefix or suffix
- ' Used to quote special characters in a prefix or suffix
+ pattern, the monetary decimal separator is used instead of
+ the decimal separator.
+ X Any other characters can be used in the prefix or suffix
+ ' Used to quote special characters in a prefix or suffix
"""
symbols = Attribute(
@@ -773,7 +773,7 @@
decimal, group, list, percentSign, nativeZeroDigit, patternDigit,
plusSign, minusSign, exponential, perMille, infinity, nan
-
+
""")
@@ -788,27 +788,27 @@
"""DateTime formatting and parsing interface. Here is a list of
possible characters and their meaning:
- Symbol Meaning Presentation Example
+ Symbol Meaning Presentation Example
- G era designator (Text) AD
- y year (Number) 1996
+ G era designator (Text) AD
+ y year (Number) 1996
M month in year (Text and Number) July and 07
d day in month (Number) 10
- h hour in am/pm (1~12) (Number) 12
+ h hour in am/pm (1~12) (Number) 12
H hour in day (0~23) (Number) 0
- m minute in hour (Number) 30
- s second in minute (Number) 55
- S millisecond (Number) 978
- E day in week (Text) Tuesday
- D day in year (Number) 189
+ m minute in hour (Number) 30
+ s second in minute (Number) 55
+ S millisecond (Number) 978
+ E day in week (Text) Tuesday
+ D day in year (Number) 189
F day of week in month (Number) 2 (2nd Wed in July)
- w week in year (Number) 27
- W week in month (Number) 2
- a am/pm marker (Text) pm
- k hour in day (1~24) (Number) 24
- K hour in am/pm (0~11) (Number) 0
+ w week in year (Number) 27
+ W week in month (Number) 2
+ a am/pm marker (Text) pm
+ k hour in day (1~24) (Number) 24
+ K hour in am/pm (0~11) (Number) 0
z time zone (Text) Pacific Standard Time
- ' escape for text
+ ' escape for text
'' single quote '
Meaning of the amount of characters:
=== Zope3/src/zope/i18n/locales.py 1.7 => 1.8 ===
--- Zope3/src/zope/i18n/locales.py:1.7 Mon Jan 27 16:49:01 2003
+++ Zope3/src/zope/i18n/locales.py Thu Mar 13 13:49:13 2003
@@ -97,13 +97,13 @@
filename += '_'
filename += '_'+variant
filename += '.xml'
-
+
# Making sure we have this locale
path = os.path.join(self._locale_dir, filename)
if not os.path.exists(path):
raise LoadLocaleError, \
'The desired locale is not available.\nPath: %s' %path
-
+
# Let's get it!
locale = ICUXMLLocaleFactory(path)()
self._locales[(language, country, variant)] = locale
@@ -155,7 +155,7 @@
"See zope.i18n.interfaces.ILocaleIdentity"
return "<ICULocaleIdentity (%s, %s, %s)>" %(
self.__language, self.__country, self.__variant)
-
+
class ICULocaleVersion:
__doc__ = ILocaleVersion.__doc__
@@ -213,7 +213,7 @@
__doc__ = ILocaleCalendar.__doc__
__implements__ = ILocaleCalendar
-
+
def __init__(self, klass):
"""Initialize the object."""
self.klass = klass
@@ -350,7 +350,7 @@
def getTimePattern(self, type):
"See zope.i18n.interfaces.ILocaleCalendar"
- return self._time_patterns[type]
+ return self._time_patterns[type]
def setDatePattern(self, name, pattern):
"See zope.i18n.interfaces.ILocaleCalendar"
@@ -358,7 +358,7 @@
def getDatePattern(self, name):
"See zope.i18n.interfaces.ILocaleCalendar"
- return self._date_patterns[name]
+ return self._date_patterns[name]
def setDateTimePattern(self, pattern):
"See zope.i18n.interfaces.ILocaleCalendar"
@@ -367,7 +367,7 @@
def getDateTimePattern(self):
"See zope.i18n.interfaces.ILocaleCalendar"
return self._datetime_pattern
-
+
class ICULocaleNumberFormat:
__doc__ = ILocaleNumberFormat.__doc__
@@ -433,19 +433,19 @@
def setName(self, name):
"See zope.i18n.interfaces.ILocaleCurrency"
self._name = name
-
+
def getName(self):
"See zope.i18n.interfaces.ILocaleCurrency"
return self._name
-
+
def setDecimal(self, decimal):
"See zope.i18n.interfaces.ILocaleCurrency"
self._decimal = decimal
-
+
def getDecimal(self):
"See zope.i18n.interfaces.ILocaleCurrency"
return self._decimal
-
+
def setPattern(self, pattern):
"See zope.i18n.interfaces.ILocaleCurrency"
self._pattern = pattern
@@ -454,7 +454,7 @@
"See zope.i18n.interfaces.ILocaleCurrency"
return self._pattern
-
+
class ICULocale:
__doc__ = ILocale.__doc__
@@ -495,7 +495,7 @@
def setIdentity(self, id):
"""Define the unique identification object for this locale."""
-
+
def setLanguageName(self, id, name):
"""Add a language in the locale's native language defined by its
two-letter id."""
@@ -529,7 +529,7 @@
name in its native language.
"""
self._countries.update(dict)
-
+
def getCountryName(self, id):
"""Get the localized country name for the given id."""
@@ -645,18 +645,18 @@
that has no missing information. This methos will build this
object.'''
calendar = ICULocaleCalendar('gregorian')
- for id in ( (None, None, None),
- (self.id.getLanguage(), None, None),
- (self.id.getLanguage(), self.id.getCountry(), None),
- (self.id.getLanguage(), self.id.getCountry(),
- self.id.getVariant()) ):
+ for id in ((None, None, None),
+ (self.id.getLanguage(), None, None),
+ (self.id.getLanguage(), self.id.getCountry(), None),
+ (self.id.getLanguage(), self.id.getCountry(),
+ self.id.getVariant())):
try:
calendar.update(locales.getLocale(*id).getCalendar(
'gregorian'))
except KeyError:
pass # Locale has no calendar information
return calendar
-
+
def getLocaleLanguageId(self):
"See ZopeProducts.LocaleProvider.interfaces.ILocale"
return self.id.getLanguage()
@@ -696,7 +696,7 @@
except AttributeError, KeyError:
return self._getNextLocale().getTimeFormatter(name)
return DateTimeFormat(pattern, self._createFullCalendar())
-
+
def getDateFormatter(self, name):
"See ZopeProducts.LocaleProvider.interfaces.ILocale"
try:
@@ -704,7 +704,7 @@
except AttributeError, KeyError:
return self._getNextLocale().getDateFormatter(name)
return DateTimeFormat(pattern, self._createFullCalendar())
-
+
def getDateTimeFormatter(self, name):
"See ZopeProducts.LocaleProvider.interfaces.ILocale"
try:
@@ -716,7 +716,7 @@
pattern = pattern.replace('{1}', date_pat)
pattern = pattern.replace('{0}', time_pat)
return DateTimeFormat(pattern, self._createFullCalendar())
-
+
def getNumberFormatter(self, name):
"See ZopeProducts.LocaleProvider.interfaces.ILocale"
try:
@@ -724,11 +724,11 @@
except AttributeError, KeyError:
return self._getNextLocale().getNumberFormatter(name)
symbols = {}
- for id in ( (None, None, None),
- (self.id.getLanguage(), None, None),
- (self.id.getLanguage(), self.id.getCountry(), None),
- (self.id.getLanguage(), self.id.getCountry(),
- self.id.getVariant()) ):
+ for id in ((None, None, None),
+ (self.id.getLanguage(), None, None),
+ (self.id.getLanguage(), self.id.getCountry(), None),
+ (self.id.getLanguage(), self.id.getCountry(),
+ self.id.getVariant())):
try:
format = locales.getLocale(*id).getDefaultNumberFormat()
symbols.update(format.getSymbolMap())
@@ -842,12 +842,12 @@
long_desc = self._getText(
long.getElementsByTagName(type)[0].childNodes)
except IndexError:
- long_desc = None # no long description
+ long_desc = None # no long description
try:
short_desc = self._getText(
short.getElementsByTagName(type)[0].childNodes)
except IndexError:
- short_desc = None # no short description
+ short_desc = None # no short description
if long_desc is not None or short_desc is not None:
zone.setName(type, long_desc, short_desc)
for city in node.getElementsByTagName('city'):
@@ -961,7 +961,7 @@
calendars.append((klass, calendar, default))
return calendars
-
+
def _extractNumberFormats(self):
"""Extract all number format information from the Locale's DOM
tree."""
@@ -974,7 +974,7 @@
default = True
else:
default = False
-
+
pattern_nodes = format_node.getElementsByTagName('patterns')
if len(pattern_nodes) == 1:
node = pattern_nodes[0]
@@ -998,7 +998,7 @@
pass # node does not exist
formats.append((klass, format, default))
-
+
return formats
def _extractCurrencies(self):
@@ -1034,9 +1034,9 @@
pass # No pattern node
currencies.append((id, currency, default))
-
+
return currencies
-
+
def __call__(self):
"""Create the Locale."""
@@ -1060,4 +1060,4 @@
locale.setCurrency(*currency)
return locale
-
+