comparison i18n/polib.py @ 19023:86531a7038ed

codingstyle: remove trailing spaces in various text files Better do it once than see random changes in diffs later.
author Mads Kiilerich <madski@unity3d.com>
date Wed, 17 Apr 2013 03:40:18 +0200
parents e40430fb787b
children e53f6b72a0e4
comparison
equal deleted inserted replaced
19022:cba222f01056 19023:86531a7038ed
275 275
276 ``entry`` 276 ``entry``
277 an instance of :class:`~polib._BaseEntry`. 277 an instance of :class:`~polib._BaseEntry`.
278 """ 278 """
279 return self.find(entry.msgid, by='msgid') is not None 279 return self.find(entry.msgid, by='msgid') is not None
280 280
281 def __eq__(self, other): 281 def __eq__(self, other):
282 return unicode(self) == unicode(other) 282 return unicode(self) == unicode(other)
283 283
284 def append(self, entry): 284 def append(self, entry):
285 """ 285 """
500 entries_len, # # of entries 500 entries_len, # # of entries
501 7*4, # start of key index 501 7*4, # start of key index
502 7*4+entries_len*8, # start of value index 502 7*4+entries_len*8, # start of value index
503 0, keystart # size and offset of hash table 503 0, keystart # size and offset of hash table
504 # Important: we don't use hash tables 504 # Important: we don't use hash tables
505 ) 505 )
506 output += array.array("i", offsets).tostring() 506 output += array.array("i", offsets).tostring()
507 output += ids 507 output += ids
508 output += strs 508 output += strs
509 return output 509 return output
510 510
629 BIG_ENDIAN = 0xde120495 629 BIG_ENDIAN = 0xde120495
630 LITTLE_ENDIAN = 0x950412de 630 LITTLE_ENDIAN = 0x950412de
631 631
632 def __init__(self, *args, **kwargs): 632 def __init__(self, *args, **kwargs):
633 """ 633 """
634 Constructor, accepts all keywords arguments accepted by 634 Constructor, accepts all keywords arguments accepted by
635 :class:`~polib._BaseFile` class. 635 :class:`~polib._BaseFile` class.
636 """ 636 """
637 _BaseFile.__init__(self, *args, **kwargs) 637 _BaseFile.__init__(self, *args, **kwargs)
638 self.magic_number = None 638 self.magic_number = None
639 self.version = 0 639 self.version = 0
772 def __str__(self): 772 def __str__(self):
773 """ 773 """
774 Returns the string representation of the entry. 774 Returns the string representation of the entry.
775 """ 775 """
776 return unicode(self).encode(self.encoding) 776 return unicode(self).encode(self.encoding)
777 777
778 def __eq__(self, other): 778 def __eq__(self, other):
779 return unicode(self) == unicode(other) 779 return unicode(self) == unicode(other)
780 780
781 def _str_field(self, fieldname, delflag, plural_index, field, wrapwidth=78): 781 def _str_field(self, fieldname, delflag, plural_index, field, wrapwidth=78):
782 lines = field.splitlines(True) 782 lines = field.splitlines(True)
785 else: 785 else:
786 escaped_field = escape(field) 786 escaped_field = escape(field)
787 specialchars_count = 0 787 specialchars_count = 0
788 for c in ['\\', '\n', '\r', '\t', '"']: 788 for c in ['\\', '\n', '\r', '\t', '"']:
789 specialchars_count += field.count(c) 789 specialchars_count += field.count(c)
790 # comparison must take into account fieldname length + one space 790 # comparison must take into account fieldname length + one space
791 # + 2 quotes (eg. msgid "<string>") 791 # + 2 quotes (eg. msgid "<string>")
792 flength = len(fieldname) + 3 792 flength = len(fieldname) + 3
793 if plural_index: 793 if plural_index:
794 flength += len(plural_index) 794 flength += len(plural_index)
795 real_wrapwidth = wrapwidth - flength + specialchars_count 795 real_wrapwidth = wrapwidth - flength + specialchars_count
888 filelist.append('%s:%s' % (fpath, lineno)) 888 filelist.append('%s:%s' % (fpath, lineno))
889 else: 889 else:
890 filelist.append(fpath) 890 filelist.append(fpath)
891 filestr = ' '.join(filelist) 891 filestr = ' '.join(filelist)
892 if wrapwidth > 0 and len(filestr) + 3 > wrapwidth: 892 if wrapwidth > 0 and len(filestr) + 3 > wrapwidth:
893 # textwrap split words that contain hyphen, this is not 893 # textwrap split words that contain hyphen, this is not
894 # what we want for filenames, so the dirty hack is to 894 # what we want for filenames, so the dirty hack is to
895 # temporally replace hyphens with a char that a file cannot 895 # temporally replace hyphens with a char that a file cannot
896 # contain, like "*" 896 # contain, like "*"
897 ret += [l.replace('*', '-') for l in wrap( 897 ret += [l.replace('*', '-') for l in wrap(
898 filestr.replace('-', '*'), 898 filestr.replace('-', '*'),
899 wrapwidth, 899 wrapwidth,
900 initial_indent='#: ', 900 initial_indent='#: ',
1097 self.add('PC', all, 'PC') 1097 self.add('PC', all, 'PC')
1098 self.add('PM', all, 'PM') 1098 self.add('PM', all, 'PM')
1099 self.add('PP', all, 'PP') 1099 self.add('PP', all, 'PP')
1100 self.add('CT', ['ST', 'HE', 'GC', 'OC', 'FL', 'TC', 'PC', 'PM', 1100 self.add('CT', ['ST', 'HE', 'GC', 'OC', 'FL', 'TC', 'PC', 'PM',
1101 'PP', 'MS', 'MX'], 'CT') 1101 'PP', 'MS', 'MX'], 'CT')
1102 self.add('MI', ['ST', 'HE', 'GC', 'OC', 'FL', 'CT', 'TC', 'PC', 1102 self.add('MI', ['ST', 'HE', 'GC', 'OC', 'FL', 'CT', 'TC', 'PC',
1103 'PM', 'PP', 'MS', 'MX'], 'MI') 1103 'PM', 'PP', 'MS', 'MX'], 'MI')
1104 self.add('MP', ['TC', 'GC', 'PC', 'PM', 'PP', 'MI'], 'MP') 1104 self.add('MP', ['TC', 'GC', 'PC', 'PM', 'PP', 'MI'], 'MP')
1105 self.add('MS', ['MI', 'MP', 'TC'], 'MS') 1105 self.add('MS', ['MI', 'MP', 'TC'], 'MS')
1106 self.add('MX', ['MI', 'MX', 'MP', 'TC'], 'MX') 1106 self.add('MX', ['MI', 'MX', 'MP', 'TC'], 'MX')
1107 self.add('MC', ['CT', 'MI', 'MP', 'MS', 'MX', 'PM', 'PP', 'PC'], 'MC') 1107 self.add('MC', ['CT', 'MI', 'MP', 'MS', 'MX', 'PM', 'PP', 'PC'], 'MC')
1211 1211
1212 if self.current_entry: 1212 if self.current_entry:
1213 # since entries are added when another entry is found, we must add 1213 # since entries are added when another entry is found, we must add
1214 # the last entry here (only if there are lines) 1214 # the last entry here (only if there are lines)
1215 self.instance.append(self.current_entry) 1215 self.instance.append(self.current_entry)
1216 # before returning the instance, check if there's metadata and if 1216 # before returning the instance, check if there's metadata and if
1217 # so extract it in a dict 1217 # so extract it in a dict
1218 firstentry = self.instance[0] 1218 firstentry = self.instance[0]
1219 if firstentry.msgid == '': # metadata found 1219 if firstentry.msgid == '': # metadata found
1220 # remove the entry 1220 # remove the entry
1221 firstentry = self.instance.pop(0) 1221 firstentry = self.instance.pop(0)
1510 entry = self._build_entry(msgid=msgid, msgstr=msgstr) 1510 entry = self._build_entry(msgid=msgid, msgstr=msgstr)
1511 self.instance.append(entry) 1511 self.instance.append(entry)
1512 # close opened file 1512 # close opened file
1513 self.fhandle.close() 1513 self.fhandle.close()
1514 return self.instance 1514 return self.instance
1515 1515
1516 def _build_entry(self, msgid, msgstr=None, msgid_plural=None, 1516 def _build_entry(self, msgid, msgstr=None, msgid_plural=None,
1517 msgstr_plural=None): 1517 msgstr_plural=None):
1518 msgctxt_msgid = msgid.split('\x04') 1518 msgctxt_msgid = msgid.split('\x04')
1519 if len(msgctxt_msgid) > 1: 1519 if len(msgctxt_msgid) > 1:
1520 kwargs = { 1520 kwargs = {
1549 """ 1549 """
1550 Subclass of textwrap.TextWrapper that backport the 1550 Subclass of textwrap.TextWrapper that backport the
1551 drop_whitespace option. 1551 drop_whitespace option.
1552 """ 1552 """
1553 def __init__(self, *args, **kwargs): 1553 def __init__(self, *args, **kwargs):
1554 drop_whitespace = kwargs.pop('drop_whitespace', True) 1554 drop_whitespace = kwargs.pop('drop_whitespace', True)
1555 textwrap.TextWrapper.__init__(self, *args, **kwargs) 1555 textwrap.TextWrapper.__init__(self, *args, **kwargs)
1556 self.drop_whitespace = drop_whitespace 1556 self.drop_whitespace = drop_whitespace
1557 1557
1558 def _wrap_chunks(self, chunks): 1558 def _wrap_chunks(self, chunks):
1559 """_wrap_chunks(chunks : [string]) -> [string] 1559 """_wrap_chunks(chunks : [string]) -> [string]