Package translate :: Package storage :: Module symbian

[hide private]
[frames] | no frames]

# Source Code for Module translate.storage.symbian

     1  #!/usr/bin/env python
     2  # -*- coding: utf-8 -*-
     3  #
     4  # Copyright 2008 Zuza Software Foundation
     5  #
     6  # This file is part of translate.
     7  #
     8  # translate is free software; you can redistribute it and/or modify
     9  # it under the terms of the GNU General Public License as published by
    10  # the Free Software Foundation; either version 2 of the License, or
    11  # (at your option) any later version.
    12  #
    13  # translate is distributed in the hope that it will be useful,
    14  # but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  # GNU General Public License for more details.
    17  #
    18  # You should have received a copy of the GNU General Public License
    19  # along with translate; if not, write to the Free Software
    20  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    21
    22  import re
    23
    24  charset_re = re.compile('CHARACTER_SET[ ]+(?P<charset>.*)')
    25  header_item_or_end_re = re.compile('(((?P<key>[^ ]+)(?P<space>[ ]*:[ ]*)(?P<value>.*))|(?P<end_comment>[*]/))')
    26  header_item_re = re.compile('(?P<key>[^ ]+)(?P<space>[ ]*:[ ]*)(?P<value>.*)')
    27  string_entry_re = re.compile('(?P<start>rls_string[ ]+)(?P<id>[^ ]+)(?P<space>[ ]+)(?P<str>.*)')
    28
    29
    30 -def identity(x):
    31      return x
    32
    33
    34 -class ParseState(object):
    35
    36 -    def __init__(self, f, charset, read_hook=identity):
    37          self.f = f
    38          self.charset = charset
    39          self.current_line = u''
    40          self.read_hook = read_hook
    41          self.read_line()
    42
    43 -    def read_line(self):
    44          current_line = self.current_line
    45          self.read_hook(current_line)
    46          self.current_line = self.f.next().decode(self.charset)
    47          return current_line
    48
    49
    50 -def read_while(ps, f, test):
    51      result = f(ps.current_line)
    52      while test(result):
    53          ps.read_line()
    54          result = f(ps.current_line)
    55      return result
    56
    57
    58 -def eat_whitespace(ps):
    59      read_while(ps, identity, lambda line: line.strip() == '')
    60
    61
    62 -def skip_no_translate(ps):
    63      if ps.current_line.startswith('// DO NOT TRANSLATE'):
    64          ps.read_line()
    65          read_while(ps, identity, lambda line: not line.startswith('// DO NOT TRANSLATE'))
    66          ps.read_line()
    67          eat_whitespace(ps)
    68
    69
    70 -def read_charset(lines):
    71      for line in lines:
    72          match = charset_re.match(line)
    73          if match is not None:
    74              return match.groupdict()['charset']
    75      return 'UTF-8'
    76