本文整理汇总了Python中translate.storage.pocommon.encodingToUse函数的典型用法代码示例。如果您正苦于以下问题:Python encodingToUse函数的具体用法?Python encodingToUse怎么用?Python encodingToUse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了encodingToUse函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, source=None, encoding="UTF-8"):
pocommon.pounit.__init__(self, source)
self._encoding = encodingToUse(encoding)
self._initallcomments(blankall=True)
self._msgctxt = u""
self.target = u""
示例2: __init__
def __init__(self, source=None, encoding="UTF-8"):
self._encoding = encodingToUse(encoding)
self.obsolete = False
self._initallcomments(blankall=True)
self.prev_msgctxt = []
self.prev_msgid = []
self.prev_msgid_plural = []
self.msgctxt = []
self.msgid = []
self.msgid_pluralcomments = []
self.msgid_plural = []
self.msgstr = []
pocommon.pounit.__init__(self, source)
示例3: parse
def parse(self, input, duplicatestyle="merge"):
if hasattr(input, 'name'):
self.filename = input.name
elif not getattr(self, 'filename', ''):
self.filename = ''
if hasattr(input, "read"):
posrc = input.read()
input.close()
input = posrc
needtmpfile = not os.path.isfile(input)
if needtmpfile:
# This is not a file - we write the string to a temporary file
fd, fname = tempfile.mkstemp(prefix='translate', suffix='.po')
os.write(fd, input)
input = fname
os.close(fd)
self._gpo_memory_file = gpo.po_file_read_v3(input, xerror_handler)
if self._gpo_memory_file is None:
logger.error("Error:")
if needtmpfile:
os.remove(input)
self.units = []
# Handle xerrors here
self._header = gpo.po_file_domain_header(self._gpo_memory_file, None)
if self._header:
charset = gpo.po_header_field(self._header, "Content-Type")
if charset:
charset = re.search("charset=([^\\s]+)", charset).group(1)
self._encoding = encodingToUse(charset)
self._gpo_message_iterator = gpo.po_message_iterator(self._gpo_memory_file, None)
newmessage = gpo.po_next_message(self._gpo_message_iterator)
while newmessage:
newunit = pounit(gpo_message=newmessage, encoding=self._encoding)
self.addunit(newunit, new=False)
newmessage = gpo.po_next_message(self._gpo_message_iterator)
self._free_iterator()
# duplicates are now removed by default unless duplicatestyle=allow
if duplicatestyle != "allow":
self.removeduplicates(duplicatestyle=duplicatestyle)
示例4: changeencoding
def changeencoding(self, newencoding):
"""Deprecated: changes the encoding on the file."""
# This should not be here but in poheader. It also shouldn't mangle the
# header itself, but use poheader methods. All users are removed, so
# we can deprecate after one release.
raise DeprecationWarning
self._encoding = encodingToUse(newencoding)
if not self.units:
return
header = self.header()
if not header or header.isblank():
return
charsetline = None
headerstr = header.target
for line in headerstr.split("\n"):
if not ":" in line:
continue
key, value = line.strip().split(":", 1)
if key.strip() != "Content-Type":
continue
charsetline = line
if charsetline is None:
headerstr += "Content-Type: text/plain; charset=%s" % self._encoding
else:
charset = re.search("charset=([^ ]*)", charsetline)
if charset is None:
newcharsetline = charsetline
if not newcharsetline.strip().endswith(";"):
newcharsetline += ";"
newcharsetline += " charset=%s" % self._encoding
else:
charset = charset.group(1)
newcharsetline = charsetline.replace(
"charset=%s" % charset, "charset=%s" % self._encoding, 1)
headerstr = headerstr.replace(charsetline, newcharsetline, 1)
header.target = headerstr
示例5: _encodeifneccessary
def _encodeifneccessary(self, output):
"""encodes unicode strings and returns other strings unchanged"""
if isinstance(output, unicode):
encoding = encodingToUse(getattr(self, "_encoding", "UTF-8"))
return output.encode(encoding)
return output