/usr/lib/python2.7/dist-packages/chameleon/i18n.py is in python-chameleon 2.6.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | ##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
from .exc import CompilationError
from .namespaces import I18N_NS as ZOPE_I18N_NS
WHITELIST = frozenset([
"translate",
"domain",
"target",
"source",
"attributes",
"data",
"name",
"mode",
"xmlns",
"xml"
])
try: # pragma: no cover
str = unicode
except NameError:
pass
try: # pragma: no cover
# optional: `zope.i18n`, `zope.i18nmessageid`
from zope.i18n import interpolate
from zope.i18n import translate
from zope.i18nmessageid import Message
except ImportError: # pragma: no cover
def fast_translate(msgid, domain=None, mapping=None, context=None,
target_language=None, default=None):
if default is None:
return msgid
return default
else: # pragma: no cover
def fast_translate(msgid, domain=None, mapping=None, context=None,
target_language=None, default=None):
if msgid is None:
return
if target_language is not None:
result = translate(
msgid, domain=domain, mapping=mapping, context=context,
target_language=target_language, default=default)
if result != msgid:
return result
if isinstance(msgid, Message):
default = msgid.default
mapping = msgid.mapping
if default is None:
default = str(msgid)
if not isinstance(default, basestring):
return default
return interpolate(default, mapping)
def parse_attributes(attrs, xml=True):
d = {}
# filter out empty items, eg:
# i18n:attributes="value msgid; name msgid2;"
# would result in 3 items where the last one is empty
attrs = [spec for spec in attrs.split(";") if spec]
for spec in attrs:
parts = spec.split()
if len(parts) == 2:
attr, msgid = parts
elif len(parts) == 1:
attr = parts[0]
msgid = None
else:
raise CompilationError(
"Illegal i18n:attributes specification.", spec)
if not xml:
attr = attr.lower()
if attr in d:
raise CompilationError(
"Attribute may only be specified once in i18n:attributes", attr)
d[attr] = msgid
return d
|