Find relation implementation in the current charm, based on the
        name of the relation.

        :return: A Relation instance, or None
336974
def from_name(cls, relation_name, conversations=None):
        
        if relation_name is None:
            return None
        relation_class = cls._cache.get(relation_name)
        if relation_class:
            return relation_class(relation_name, conversations)
        role, interface = hookenv.relation_to_role_and_interface(relation_name)
        if role and interface:
            relation_class = cls._find_impl(role, interface)
            if relation_class:
                cls._cache[relation_name] = relation_class
                return relation_class(relation_name, conversations)
        return None
229575
def get_relation_cnt(self):
        """"""
        ctr = cx.Counter()
        for ntgpad in self.associations:
            if ntgpad.Extension is not None:
                ctr += ntgpad.Extension.get_relations_cnt()
        return ctr
1021264
def decorators(self, relation):
        
        if self.CONFIG.show_approx_str:
            approx_str = Decorators.relation_to_symbol(relation)
        else:
            approx_str = ''

        return _Decorators(approx_str=approx_str)
1238265
def update_relations(context, namespace_separator=':'):
    """"""
    # Add any relation data prefixed with the relation type.
    relation_type = charmhelpers.core.hookenv.relation_type()
    relations = []
    context['current_relation'] = {}
    if relation_type is not None:
        relation_data = charmhelpers.core.hookenv.relation_get()
        context['current_relation'] = relation_data
        # Deprecated: the following use of relation data as keys
        # directly in the context will be removed.
        relation_data = dict(
            ("{relation_type}{namespace_separator}{key}".format(
                relation_type=relation_type,
                key=key,
                namespace_separator=namespace_separator), val)
            for key, val in relation_data.items())
        relation_data = dict_keys_without_hyphens(relation_data)
        context.update(relation_data)
        relations = charmhelpers.core.hookenv.relations_of_type(relation_type)
        relations = [dict_keys_without_hyphens(rel) for rel in relations]

    context['relations_full'] = charmhelpers.core.hookenv.relations()

    # the hookenv.relations() data structure is effectively unusable in
    # templates and other contexts when trying to access relation data other
    # than the current relation. So provide a more useful structure that works
    # with any hook.
    local_unit = charmhelpers.core.hookenv.local_unit()
    relations = {}
    for rname, rids in context['relations_full'].items():
        relations[rname] = []
        for rid, rdata in rids.items():
            data = rdata.copy()
            if local_unit in rdata:
                data.pop(local_unit)
            for unit_name, rel_data in data.items():
                new_data = {'__relid__': rid, '__unit__': unit_name}
                new_data.update(rel_data)
                relations[rname].append(new_data)
    context['relations'] = relations
251486
def relation(name, options = EMPTY_HASH, &block)
      klass_opts = { adapter: default_adapter }.merge(options)
      klass = Relation.build_class(name, klass_opts)
      klass.schema_opts(dataset: name, relation: name)
      klass.class_eval(&block) if block
      register_relation(klass)
      klass
    end
658252
def _get_child_relation(self, child_pid):
        """"""
        return PIDRelation.query.filter_by(
            parent=self._resolved_pid,
            child=child_pid,
            relation_type=self.relation_type.id).one()
801534
def get_relations(self, database, schema):
        
        schema = _lower(schema)
        with self.lock:
            results = [
                r.inner for r in self.relations.values()
                if (r.schema == _lower(schema) and
                    r.database == _lower(database))
            ]

        if None in results:
            dbt.exceptions.raise_cache_inconsistent(
                'in get_relations, a None relation was found in the cache!'
            )
        return results
158797
def _get_relation_value(self, dictionary, key, type):
        
        value = dictionary[key]

        if type == 'one':
            return value[0]

        return self._related.new_collection(value)
1345618
def get_new_id(self, relation_name, old_id, strict=False):
    
    record = self.data_access.find(
      "relations as r inner join transfers as t on r.id = t.relation_id",
      (("r.name", relation_name), ("t.old_id", old_id)),
      columns="new_id")
    if record:
      return record[0]
    else:
      if strict:
        raise KeyError("{0} with id {1} not found".format(relation_name, old_id))
634642
def get_relation_graph(self, depth=None):
        
        url = '{}relation_graph/'.format(self.url)
        if depth is not None:
            params = {'depth': depth}
        else:
            params = {}

        from .sample_relation import SampleRelation
        return SampleRelation._get_iter_from_url(url, params=params, append_base_url=False)
551310
def relation(self, node):
        
        return self.query(select_block=str(node.attributes),
                          from_block=node.name)
787975
def gen_relations(self):
        
        relations_elem = E('relations')
        for relname in sorted(self.relations):
            relations_elem.append(
                E('rel', OrderedDict([('name', relname), ('type', self.relations[relname])])))
        return relations_elem
1352524
def _parse_with_relations(self, relations):
        
        results = {}

        for relation in relations:
            if isinstance(relation, dict):
                for name, constraints in relation.items():
                    results = self._parse_nested_with(name, results)

                    results[name] = constraints

                continue
            else:
                name = relation
                constraints = self.__class__(self.get_query().new_query())

            results = self._parse_nested_with(name, results)

            results[name] = constraints

        return results
690725
def relation_ids(self):
        
        if self.scope == scopes.GLOBAL:
            # the namespace is the relation name and this conv speaks for all
            # connected instances of that relation
            return hookenv.relation_ids(self.namespace)
        else:
            # the namespace is the relation ID
            return [self.namespace]
15708
def wait_for_relation(service_name, relation_name, timeout=120):
    """"""
    start_time = time.time()
    while True:
        relation = unit_info(service_name, 'relations').get(relation_name)
        if relation is not None and relation['state'] == 'up':
            break
        if time.time() - start_time >= timeout:
            raise RuntimeError('timeout waiting for relation to be up')
        time.sleep(SLEEP_AMOUNT)
558831
def get_relations(self, cursor, table_name):
        
        cursor.execute(self._get_relations_query, {
            'schema': self.connection.schema_name,
            'table': table_name
        })
        relations = {}
        for row in cursor.fetchall():
            relations[row[1]] = (row[2], row[0])

        return relations
842480
def _is_nested(self, name, relation):
        
        dots = name.find(".")

        return dots and name.startswith(relation + ".")