/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/lazy_import.py

  • Committer: Gustav Hartvigsson
  • Date: 2021-01-09 21:36:27 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210109213627-h1xwcutzy9m7a99b
Added 'Case Preserving Working Tree Use Cases' from Canonical Wiki

* Addod a page from the Canonical Bazaar wiki
  with information on the scmeatics of case
  perserving filesystems an a case insensitive
  filesystem works.
  
  * Needs re-work, but this will do as it is the
    same inforamoton as what was on the linked
    page in the currint documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
to inherit from them).
42
42
"""
43
43
 
44
 
from __future__ import absolute_import
 
44
from .errors import BzrError, InternalBzrError
 
45
 
 
46
 
 
47
class ImportNameCollision(InternalBzrError):
 
48
 
 
49
    _fmt = ("Tried to import an object to the same name as"
 
50
            " an existing object. %(name)s")
 
51
 
 
52
    def __init__(self, name):
 
53
        BzrError.__init__(self)
 
54
        self.name = name
 
55
 
 
56
 
 
57
class IllegalUseOfScopeReplacer(InternalBzrError):
 
58
 
 
59
    _fmt = ("ScopeReplacer object %(name)r was used incorrectly:"
 
60
            " %(msg)s%(extra)s")
 
61
 
 
62
    def __init__(self, name, msg, extra=None):
 
63
        BzrError.__init__(self)
 
64
        self.name = name
 
65
        self.msg = msg
 
66
        if extra:
 
67
            self.extra = ': ' + str(extra)
 
68
        else:
 
69
            self.extra = ''
 
70
 
 
71
 
 
72
class InvalidImportLine(InternalBzrError):
 
73
 
 
74
    _fmt = "Not a valid import statement: %(msg)\n%(text)s"
 
75
 
 
76
    def __init__(self, text, msg):
 
77
        BzrError.__init__(self)
 
78
        self.text = text
 
79
        self.msg = msg
45
80
 
46
81
 
47
82
class ScopeReplacer(object):
84
119
            scope = object.__getattribute__(self, '_scope')
85
120
            obj = factory(self, scope, name)
86
121
            if obj is self:
87
 
                raise errors.IllegalUseOfScopeReplacer(name, msg="Object tried"
88
 
                                                       " to replace itself, check it's not using its own scope.")
 
122
                raise IllegalUseOfScopeReplacer(
 
123
                    name, msg="Object tried"
 
124
                    " to replace itself, check it's not using its own scope.")
89
125
 
90
126
            # Check if another thread has jumped in while obj was generated.
91
127
            real_obj = object.__getattribute__(self, '_real_obj')
99
135
 
100
136
        # Raise if proxying is disabled as obj has already been generated.
101
137
        if not ScopeReplacer._should_proxy:
102
 
            raise errors.IllegalUseOfScopeReplacer(
 
138
            raise IllegalUseOfScopeReplacer(
103
139
                name, msg="Object already replaced, did you assign it"
104
140
                          " to another variable?")
105
141
        return real_obj
260
296
            elif line.startswith('from '):
261
297
                self._convert_from_str(line)
262
298
            else:
263
 
                raise errors.InvalidImportLine(line,
264
 
                                               "doesn't start with 'import ' or 'from '")
 
299
                raise InvalidImportLine(
 
300
                    line, "doesn't start with 'import ' or 'from '")
265
301
 
266
302
    def _convert_import_str(self, import_str):
267
303
        """This converts a import string into an import map.
286
322
                name = as_hunks[1].strip()
287
323
                module_path = as_hunks[0].strip().split('.')
288
324
                if name in self.imports:
289
 
                    raise errors.ImportNameCollision(name)
 
325
                    raise ImportNameCollision(name)
290
326
                if not module_path[0]:
291
327
                    raise ImportError(path)
292
328
                # No children available in 'import foo as bar'
345
381
            else:
346
382
                name = module = path
347
383
            if name in self.imports:
348
 
                raise errors.ImportNameCollision(name)
 
384
                raise ImportNameCollision(name)
349
385
            self.imports[name] = (from_module_path, module, {})
350
386
 
351
387
    def _canonicalize_import_text(self, text):
377
413
                else:
378
414
                    out.append(line.replace('(', '').replace(')', ''))
379
415
        if cur is not None:
380
 
            raise errors.InvalidImportLine(cur, 'Unmatched parenthesis')
 
416
            raise InvalidImportLine(cur, 'Unmatched parenthesis')
381
417
        return out
382
418
 
383
419
 
408
444
    # This is just a helper around ImportProcessor.lazy_import
409
445
    proc = ImportProcessor(lazy_import_class=lazy_import_class)
410
446
    return proc.lazy_import(scope, text)
411
 
 
412
 
 
413
 
# The only module that this module depends on is 'breezy.errors'. But it
414
 
# can actually be imported lazily, since we only need it if there is a
415
 
# problem.
416
 
 
417
 
lazy_import(globals(), """
418
 
from breezy import errors
419
 
""")