/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 bzrlib/registry.py

  • Committer: Benoît Pierre
  • Date: 2009-02-24 00:25:32 UTC
  • mfrom: (4035 +trunk)
  • mto: (4056.1.1 trunk2)
  • mto: This revision was merged to the branch mainline in revision 4058.
  • Revision ID: benoit.pierre@gmail.com-20090224002532-i2f64ou15pa7if2y
Merge with upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006, 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
107
107
        :param obj: The object to register.
108
108
        :param help: Help text for this entry. This may be a string or
109
109
                a callable. If it is a callable, it should take two
110
 
                parameters (registry, key): this registry and the key that 
 
110
                parameters (registry, key): this registry and the key that
111
111
                the help was registered under.
112
112
        :param info: More information for this entry. Registry.get_info()
113
113
                can be used to get this information. Registry treats this as an
128
128
        """Register a new object to be loaded on request.
129
129
 
130
130
        :param module_name: The python path to the module. Such as 'os.path'.
131
 
        :param member_name: The member of the module to return.  If empty or 
 
131
        :param member_name: The member of the module to return.  If empty or
132
132
                None, get() will return the module itself.
133
133
        :param help: Help text for this entry. This may be a string or
134
134
                a callable.
135
 
        :param info: More information for this entry. Registry 
 
135
        :param info: More information for this entry. Registry
136
136
        :param override_existing: If True, replace the existing object
137
137
                with the new one. If False, if there is already something
138
138
                registered with the same key, raise a KeyError
152
152
        """Return the object register()'ed to the given key.
153
153
 
154
154
        May raise ImportError if the object was registered lazily and
155
 
        there are any problems, or AttributeError if the module does not 
 
155
        there are any problems, or AttributeError if the module does not
156
156
        have the supplied member.
157
157
 
158
158
        :param key: The key to obtain the object for. If no object has been
174
174
        :return: a tuple of (object, remainder), where the remainder is the
175
175
            portion of the name that did not match the key.
176
176
        """
177
 
        for key, value in self.iteritems():
 
177
        for key in self.keys():
178
178
            if fullname.startswith(key):
179
 
                return value, fullname[len(key):]
 
179
                return self.get(key), fullname[len(key):]
180
180
 
181
181
    def _get_key_or_default(self, key=None):
182
182
        """Return either 'key' or the default key if key is None"""
216
216
        for key, getter in self._dict.iteritems():
217
217
            yield key, getter.get_obj()
218
218
 
 
219
    def items(self):
 
220
        return sorted(self.iteritems())
 
221
 
219
222
    def _set_default_key(self, key):
220
223
        if not self._dict.has_key(key):
221
224
            raise KeyError('No object registered under key %s.' % key)