summaryrefslogtreecommitdiff
path: root/babel/support.py
diff options
context:
space:
mode:
authorArmin Ronacher <armin.ronacher@active-4.com>2013-07-05 12:12:27 +0200
committerArmin Ronacher <armin.ronacher@active-4.com>2013-07-05 12:12:27 +0200
commit588d1f8b711744c8d90dcbf6189866ce5ab76426 (patch)
treec92c275e0795620f1c0aa4476de884544bec6405 /babel/support.py
parent03217d2fcfdb9177e4c7cacedc623eb07da979a1 (diff)
downloadbabel-588d1f8b711744c8d90dcbf6189866ce5ab76426.tar.gz
Removed trailing whitespace
Diffstat (limited to 'babel/support.py')
-rw-r--r--babel/support.py70
1 files changed, 35 insertions, 35 deletions
diff --git a/babel/support.py b/babel/support.py
index f6e6643..cde1448 100644
--- a/babel/support.py
+++ b/babel/support.py
@@ -35,7 +35,7 @@ __docformat__ = 'restructuredtext en'
class Format(object):
"""Wrapper class providing the various date and number formatting functions
bound to a specific locale and time-zone.
-
+
>>> fmt = Format('en_US', UTC)
>>> fmt.date(date(2007, 4, 1))
u'Apr 1, 2007'
@@ -45,7 +45,7 @@ class Format(object):
def __init__(self, locale, tzinfo=None):
"""Initialize the formatter.
-
+
:param locale: the locale identifier or `Locale` instance
:param tzinfo: the time-zone info (a `tzinfo` instance or `None`)
"""
@@ -54,23 +54,23 @@ class Format(object):
def date(self, date=None, format='medium'):
"""Return a date formatted according to the given pattern.
-
+
>>> fmt = Format('en_US')
>>> fmt.date(date(2007, 4, 1))
u'Apr 1, 2007'
-
+
:see: `babel.dates.format_date`
"""
return format_date(date, format, locale=self.locale)
def datetime(self, datetime=None, format='medium'):
"""Return a date and time formatted according to the given pattern.
-
+
>>> from pytz import timezone
>>> fmt = Format('en_US', tzinfo=timezone('US/Eastern'))
>>> fmt.datetime(datetime(2007, 4, 1, 15, 30))
u'Apr 1, 2007, 11:30:00 AM'
-
+
:see: `babel.dates.format_datetime`
"""
return format_datetime(datetime, format, tzinfo=self.tzinfo,
@@ -78,23 +78,23 @@ class Format(object):
def time(self, time=None, format='medium'):
"""Return a time formatted according to the given pattern.
-
+
>>> from pytz import timezone
>>> fmt = Format('en_US', tzinfo=timezone('US/Eastern'))
>>> fmt.time(datetime(2007, 4, 1, 15, 30))
u'11:30:00 AM'
-
+
:see: `babel.dates.format_time`
"""
return format_time(time, format, tzinfo=self.tzinfo, locale=self.locale)
def timedelta(self, delta, granularity='second', threshold=.85):
"""Return a time delta according to the rules of the given locale.
-
+
>>> fmt = Format('en_US')
>>> fmt.timedelta(timedelta(weeks=11))
u'3 mths'
-
+
:see: `babel.dates.format_timedelta`
"""
return format_timedelta(delta, granularity=granularity,
@@ -102,47 +102,47 @@ class Format(object):
def number(self, number):
"""Return an integer number formatted for the locale.
-
+
>>> fmt = Format('en_US')
>>> fmt.number(1099)
u'1,099'
-
+
:see: `babel.numbers.format_number`
"""
return format_number(number, locale=self.locale)
def decimal(self, number, format=None):
"""Return a decimal number formatted for the locale.
-
+
>>> fmt = Format('en_US')
>>> fmt.decimal(1.2345)
u'1.234'
-
+
:see: `babel.numbers.format_decimal`
"""
return format_decimal(number, format, locale=self.locale)
def currency(self, number, currency):
"""Return a number in the given currency formatted for the locale.
-
+
:see: `babel.numbers.format_currency`
"""
return format_currency(number, currency, locale=self.locale)
def percent(self, number, format=None):
"""Return a number formatted as percentage for the locale.
-
+
>>> fmt = Format('en_US')
>>> fmt.percent(0.34)
u'34%'
-
+
:see: `babel.numbers.format_percent`
"""
return format_percent(number, format, locale=self.locale)
def scientific(self, number):
"""Return a number formatted using scientific notation for the locale.
-
+
:see: `babel.numbers.format_scientific`
"""
return format_scientific(number, locale=self.locale)
@@ -151,7 +151,7 @@ class Format(object):
class LazyProxy(object):
"""Class for proxy objects that delegate to a specified function to evaluate
the actual object.
-
+
>>> def greeting(name='world'):
... return 'Hello, %s!' % name
>>> lazy_greeting = LazyProxy(greeting, name='Joe')
@@ -161,16 +161,16 @@ class LazyProxy(object):
u' Hello, Joe!'
>>> u'(%s)' % lazy_greeting
u'(Hello, Joe!)'
-
+
This can be used, for example, to implement lazy translation functions that
delay the actual translation until the string is actually used. The
rationale for such behavior is that the locale of the user may not always
be available. In web applications, you only know the locale when processing
a request.
-
+
The proxy implementation attempts to be as complete as possible, so that
the lazy objects should mostly work as expected, for example for sorting:
-
+
>>> greetings = [
... LazyProxy(greeting, 'world'),
... LazyProxy(greeting, 'Joe'),
@@ -282,7 +282,7 @@ class LazyProxy(object):
self.value[key] = value
-class NullTranslations(gettext.NullTranslations, object):
+class NullTranslations(gettext.NullTranslations, object):
DEFAULT_DOMAIN = None
@@ -308,13 +308,13 @@ class NullTranslations(gettext.NullTranslations, object):
domain.
"""
return self._domains.get(domain, self).gettext(message)
-
+
def ldgettext(self, domain, message):
- """Like ``lgettext()``, but look the message up in the specified
+ """Like ``lgettext()``, but look the message up in the specified
domain.
- """
+ """
return self._domains.get(domain, self).lgettext(message)
-
+
def udgettext(self, domain, message):
"""Like ``ugettext()``, but look the message up in the specified
domain.
@@ -322,19 +322,19 @@ class NullTranslations(gettext.NullTranslations, object):
return self._domains.get(domain, self).ugettext(message)
# backward compatibility with 0.9
dugettext = udgettext
-
+
def dngettext(self, domain, singular, plural, num):
"""Like ``ngettext()``, but look the message up in the specified
domain.
"""
return self._domains.get(domain, self).ngettext(singular, plural, num)
-
+
def ldngettext(self, domain, singular, plural, num):
"""Like ``lngettext()``, but look the message up in the specified
domain.
"""
return self._domains.get(domain, self).lngettext(singular, plural, num)
-
+
def udngettext(self, domain, singular, plural, num):
"""Like ``ungettext()`` but look the message up in the specified
domain.
@@ -345,7 +345,7 @@ class NullTranslations(gettext.NullTranslations, object):
# Most of the downwards code, until it get's included in stdlib, from:
# http://bugs.python.org/file10036/gettext-pgettext.patch
- #
+ #
# The encoding of a msgctxt and a msgid in a .mo file is
# msgctxt + "\x04" + msgid (gettext version >= 0.15)
CONTEXT_ENCODING = '%s\x04%s'
@@ -393,7 +393,7 @@ class NullTranslations(gettext.NullTranslations, object):
message id for purposes of lookup in the catalog, while `num` is used to
determine which plural form to use. The returned message string is an
8-bit string encoded with the catalog's charset encoding, if known.
-
+
If the message id for `context` is not found in the catalog, and a
fallback is specified, the request is forwarded to the fallback's
``npgettext()`` method. Otherwise, when ``num`` is 1 ``singular`` is
@@ -455,7 +455,7 @@ class NullTranslations(gettext.NullTranslations, object):
message id for purposes of lookup in the catalog, while `num` is used to
determine which plural form to use. The returned message string is a
Unicode string.
-
+
If the message id for `context` is not found in the catalog, and a
fallback is specified, the request is forwarded to the fallback's
``unpgettext()`` method. Otherwise, when `num` is 1 `singular` is
@@ -478,7 +478,7 @@ class NullTranslations(gettext.NullTranslations, object):
`domain`.
"""
return self._domains.get(domain, self).pgettext(context, message)
-
+
def udpgettext(self, domain, context, message):
"""Like `upgettext()`, but look the message up in the specified
`domain`.
@@ -500,7 +500,7 @@ class NullTranslations(gettext.NullTranslations, object):
"""
return self._domains.get(domain, self).npgettext(context, singular,
plural, num)
-
+
def udnpgettext(self, domain, context, singular, plural, num):
"""Like ``unpgettext``, but look the message up in the specified
`domain`.