def as_dict(self): path, line = self.get_file_and_line() return {'name': self.name, 'provided': get_dotted_name(self.provided), 'descriminators': [get_dotted_name(iface) for iface in self.descriminators], 'factory': str(self.factory), 'path': path, 'line': line, }
def as_text(self): path, line = self.get_file_and_line() data = [':'.join((path, str(line))), 'Name: %s' % self.name, 'Provides: %s' % get_dotted_name(self.provided), ] for num, iface in enumerate(self.descriminators): data.append('Adapts %i: %s' % (num, get_dotted_name(iface))) data.append('Factory: %s' % str(self.factory)) return '\n'.join(data)
def get_keys_at_level(self, level, provided=None, name=None): """Returns all keys at a specific level """ def _get_keys(dict_, path=[]): # walk into the dicts till to the end. The last key # in the path is the name, the second last is the # provided interface. keys = [] for key, value in dict_.items(): if isinstance(value, dict): # continue walking keys.extend(_get_keys(value, path + [key])) else: if name and name != key: # name does not match continue if provided and provided != path[-1]: # provided does not match continue keys.append(path[level]) return keys keys = [] for all in self.registry._adapters: keys.extend(_get_keys(all)) keys = list(set(keys)) keys = [get_dotted_name(key) for key in keys] keys.sort() return keys
def _inner_keys(dict_): # The keys of the most inner dicts are the names of the # adapters (or utilities) - we need to have the dotted # names of the dicts one level above. keys = [] for key, value in dict_.items(): if isinstance(key, types.StringTypes): return -1 sub = _inner_keys(value) if sub == -1: keys.append(get_dotted_name(key)) else: keys.extend(sub) return keys
def __call__(self, adapters, show_descriminators=False): config = Config() max_scope = 0 if show_descriminators: # count the descriminators for adapter in adapters: if adapter.descriminators: if len(adapter.descriminators) > max_scope: max_scope = len(adapter.descriminators) headings = ['Provided', 'Name'] if max_scope > 0: headings.extend(['For %i' % (i+1) for i in range(max_scope)]) if config.get('column_factory'): headings.append('Factory') if config.get('column_file'): headings.append('File') if config.get('column_line'): headings.append('Line') options = { 'headings': headings, 'rows': [], } for adapter in adapters: row = {'data': [], 'actions': ''} path, line = adapter.get_file_and_line() row['data'] = [ utils.get_dotted_name(adapter.provided), adapter.name, ] if show_descriminators and max_scope: for i in range(max_scope): if len(adapter.descriminators) > i: row['data'].append(utils.get_dotted_name( adapter.descriminators[i])) else: row['data'].append('-') if config.get('column_factory'): row['data'].append(str(adapter.factory)) if config.get('column_file'): row['data'].append(path) if config.get('column_line'): row['data'].append(line) if line != '-': row['actions'] = '<input type="button" class="open" ' + \ 'value="open" />' + \ '<input type="hidden" name="path" value="%s" />' % path + \ '<input type="hidden" name="line" value="%s" />' % line options['rows'].append(row) return self.results(**options)