Get an item from a dict which contains just one item.
480899
def get_single_item(d):
    """"""
    assert len(d) == 1, 'Single-item dict must have just one item, not %d.' % len(d)
    return next(six.iteritems(d))
35115
def get_one(self, qry, tpl):
        '''  '''
        self.cur.execute(qry + ' LIMIT 1', tpl)
        result = self.cur.fetchone()
        # unpack tuple if it has only
        # one element
        # TODO unpack results
        if type(result) is tuple and len(result) == 1:
            result = result[0]
        return result
503573
def key_of(d):
    
    if len(d) > 1 and not type(d) == dict():
        raise ValueError('key_of(d) may only except single element dict')
    else:
        return keys_of(d)[0]
882303
def get_item(self, key):
        
        keys = list(self.keys())

        # make sure it exists
        if not key in keys:
            self.print_message("ERROR: '"+str(key)+"' not found.")
            return None

        try:
            x = eval(self.get_value(1,keys.index(key)))
            return x

        except:
            self.print_message("ERROR: '"+str(self.get_value(1,keys.index(key)))+"' cannot be evaluated.")
            return None
782871
def one(cls, path='', index=0):
        """"""
        url = urljoin(cls._meta.base_url, path)
        pq_items = cls._get_items(url=url, **cls._meta._pyquery_kwargs)
        item = pq_items.eq(index)
        if not item:
            raise ItemDoesNotExist("%s not found" % cls.__name__)
        return cls(item=item)
1364979
def get(self, key, default):
        """"""
        with self._lock:
            try:
                return self._dict[key].copy()
            except KeyError:
                return default
1049260
def _from_dict(cls, _dict):
        """"""
        args = {}
        xtra = _dict.copy()
        if 'id' in _dict:
            args['id'] = _dict.get('id')
            del xtra['id']
        if 'metadata' in _dict:
            args['metadata'] = _dict.get('metadata')
            del xtra['metadata']
        if 'collection_id' in _dict:
            args['collection_id'] = _dict.get('collection_id')
            del xtra['collection_id']
        if 'result_metadata' in _dict:
            args['result_metadata'] = QueryResultMetadata._from_dict(
                _dict.get('result_metadata'))
            del xtra['result_metadata']
        if 'title' in _dict:
            args['title'] = _dict.get('title')
            del xtra['title']
        args.update(xtra)
        return cls(**args)
106595
def item(self, key):
    
    return _item.Item(self._name, key, context=self._context)
1038356
def get(self, item):
        """"""
        uri = "/%s/%s" % (self.uri_base, utils.get_id(item))
        return self._get(uri)
815798
def _slice(self, slicer):
        
        if isinstance(slicer, tuple):
            col, loc = slicer
            if not com.is_null_slice(col) and col != 0:
                raise IndexError("{0} only contains one item".format(self))
            return self.values[loc]
        return self.values[slicer]
1319277
def get(self, key, default=None):
        """"""
        for k, v in self:
            if k == key:
                return v
        return default
1347616
def one_item(self, item, detach:bool=False, denorm:bool=False, cpu:bool=False):
        ""
        ds = self.single_ds
        with ds.set_item(item):
            return self.one_batch(ds_type=DatasetType.Single, detach=detach, denorm=denorm, cpu=cpu)
1153893
def find_one(self, cls, id):
        """"""
        try:
            db_result = self.get_class_table(cls).lookup(id)
        except ItemNotFound:
            # according to docs, this shouldn't be required, but it IS
            db_result = None

        if not db_result:
            return None

        obj = cls.from_data(db_result['value'])
        return obj
726456
def _getitem(self, key):
        """"""
        key = int(key)
        if key < 0:
            key %= self._len
        if len(self._pages) == 1 and 0 < key < self._len:
            index = self._pages[0].index
            return self.parent.pages._getitem(index + key)
        return self._pages[key]
526163
def find_gt(self, item):
        ''
        k = self._key(item)
        i = bisect_right(self._keys, k)
        if i != len(self):
            return self._items[i]
        raise ValueError('No item found with key above: %r' % (k,))
750253
def _filter_from_dict(current: Dict[str, Any]) -> Dict[str, Any]:
    """"""
    filter_ = dict()

    for k, v in current.items():
        if isinstance(v, dict):
            for sub, v2 in _filter_from_dict(v).items():
                filter_[f'{k}.{sub}'] = v2
        else:
            filter_[k] = v

    return filter_
41519
def _get_non_empty_dict(cls, mapping):
        """"""
        res = {}
        for key, value in mapping.items():
            if hasattr(value, 'items'):
                value = cls._get_non_empty_dict(value)
            elif isinstance(value, list):
                value = cls._get_non_empty_list(value)
            if value not in [[], {}, None]:
                res[key] = value
        return res