/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/export_pot.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-07-13 00:34:53 UTC
  • mfrom: (7027.3.8 python3-n)
  • Revision ID: breezy.the.bot@gmail.com-20180713003453-3wofrh7brng5jz3l
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.

Merged from https://code.launchpad.net/~jelmer/brz/python3-n/+merge/349091

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
    plugin as _mod_plugin,
41
41
    help,
42
42
    )
 
43
from .sixish import PY3
43
44
from .trace import (
44
45
    mutter,
45
46
    note,
71
72
    return s
72
73
 
73
74
 
74
 
def _parse_source(source_text):
 
75
def _parse_source(source_text, filename='<unknown>'):
75
76
    """Get object to lineno mappings from given source_text"""
76
77
    import ast
77
78
    cls_to_lineno = {}
78
79
    str_to_lineno = {}
79
 
    for node in ast.walk(ast.parse(source_text)):
 
80
    for node in ast.walk(ast.parse(source_text, filename)):
80
81
        # TODO: worry about duplicates?
81
82
        if isinstance(node, ast.ClassDef):
82
83
            # TODO: worry about nesting?
106
107
        # TODO: fix this to do the right thing rather than rely on cwd
107
108
        relpath = os.path.relpath(sourcepath)
108
109
        return cls(relpath,
109
 
            _source_info=_parse_source("".join(inspect.findsource(module)[0])))
 
110
            _source_info=_parse_source("".join(inspect.findsource(module)[0]), module.__file__))
110
111
 
111
112
    def from_class(self, cls):
112
113
        """Get new context with same details but lineno of class in source"""
157
158
            "msgstr \"\"\n"
158
159
            "\n".format(
159
160
                path=path, lineno=lineno, comment=comment, msg=_normalize(s)))
160
 
        self.outf.write(line.encode('utf-8'))
 
161
        if not PY3:
 
162
            line = line.decode('utf-8')
 
163
        self.outf.write(line)
161
164
 
162
165
    def poentry_in_context(self, context, string, comment=None):
163
166
        context = context.from_string(string)