Returns an empty dict and a @register decorator.
766697
def new_registry(attribute=None):
    
    registry = {}

    def register(key):
        def decorator(func):
            registry[key] = func
            if attribute:
                setattr(func, attribute, key)
            return func
        return decorator

    return registry, register
1013071
def get(self, key):
        

        obj = super(ExtRegistry, self).get(key)
        if obj is None:
            return obj

        return (obj, self._type_info.get(key))
409985
def todict(self, dict_type=dict, index_key=0, index_value=-1):
        ''''''
        if len(self):
            return dict_type(self.items([index_key, index_value]))
        else:  # empty
            return dict_type()
1364612
def get_dict(cls):
        
        mdt = cls.get()

        if not mdt:
            return {}

        return conspectus.subs_by_mdt.get(mdt, {})
995709
def valuedispatch(func):
    
    registry = {}
    def dispatch(value):
        return registry.get(value, func)
    def register(value, func=None):
        if func is None:
            return lambda f: register(value, f)
        registry[value] = func
        return func
    def wrapper(*args, **kw):
        return dispatch(args[0])(*args, **kw)
    wrapper.register = register
    wrapper.dispatch = dispatch
    wrapper.registry = MappingProxyType(registry)
    update_wrapper(wrapper, func)
    return wrapper
20646
def remove_empty_from_dict(dictionary):
    
    if isinstance(dictionary, dict):
        return dict(
            (k,
             remove_empty_from_dict(v)) for k, v in iteritems(
                 dictionary) if v and remove_empty_from_dict(v))
    elif isinstance(dictionary, list):
        return [remove_empty_from_dict(v) for v in dictionary if v and remove_empty_from_dict(v)]
    return dictionary
1343270
def _get_py_dictionary(self, var, names=None, used___dict__=False):
        '''
        
        '''

        # TODO: Those should be options (would fix https://github.com/Microsoft/ptvsd/issues/66).
        filter_private = False
        filter_special = True
        filter_function = True
        filter_builtin = True

        if not names:
            names, used___dict__ = self.get_names(var)
        d = {}

        # Be aware that the order in which the filters are applied attempts to
        # optimize the operation by removing as many items as possible in the
        # first filters, leaving fewer items for later filters

        if filter_builtin or filter_function:
            for name in names:
                try:
                    name_as_str = name
                    if name_as_str.__class__ != str:
                        name_as_str = '%r' % (name_as_str,)

                    if filter_special:
                        if name_as_str.startswith('__') and name_as_str.endswith('__'):
                            continue

                    if filter_private:
                        if name_as_str.startswith('_') or name_as_str.endswith('__'):
                            continue
                    if not used___dict__:
                        attr = getattr(var, name)
                    else:
                        attr = var.__dict__[name]

                    # filter builtins?
                    if filter_builtin:
                        if inspect.isbuiltin(attr):
                            continue

                    # filter functions?
                    if filter_function:
                        if inspect.isroutine(attr) or isinstance(attr, MethodWrapperType):
                            continue
                except:
                    # if some error occurs getting it, let's put it to the user.
                    strIO = StringIO.StringIO()
                    traceback.print_exc(file=strIO)
                    attr = strIO.getvalue()

                d[name_as_str] = attr

        return d, used___dict__
391981
def register(cls, name):
        """"""
        def register_decorator(reg_cls):
            def name_func(self):
                return name
            reg_cls.name = property(name_func)
            assert issubclass(reg_cls, cls), \
                "Must be subclass matching your NamedRegistry class"
            cls.REGISTRY[name] = reg_cls
            return reg_cls
        return register_decorator
1119052
def returns_json(func):
    
    def decorator(*args, **kwargs):
        instance = args[0]
        request = getattr(instance, 'request', None)
        request.response.setHeader("Content-Type", "application/json")
        result = func(*args, **kwargs)
        return json.dumps(result)
    return decorator
973760
def check_empty_dict(GET_dict):
    
    empty = True
    for k, v in GET_dict.items():
        # Don't disable on p(age) or 'all' GET param
        if v and k != 'p' and k != 'all':
            empty = False
    return empty
642220
def create_empty(cls, val=0x00):
        
        userdata_dict = {}
        for i in range(1, 15):
            key = 'd{}'.format(i)
            userdata_dict.update({key: val})
        return userdata_dict
289498
def as_dict(self):
        
        if hasattr(self, 'cust_dict'):
            return self.cust_dict
        if hasattr(self, 'attr_check'):
            self.attr_check()
        cls_bltns = set(dir(self.__class__))
        return {a: getattr(self, a) for a in dir(self) if a not in cls_bltns}
860051
def visit_Dict(self, node):
        
        self.generic_visit(node)
        if node.keys:
            for key, value in zip(node.keys, node.values):
                value_type = self.result[value]
                self.combine(node, key,
                             unary_op=partial(self.builder.DictType,
                                              of_val=value_type))
        else:
            self.result[node] = self.builder.NamedType(
                "pythonic::types::empty_dict")
986070
def _simple_po_to_dict(tokens) -> BaseAbundance:
    
    dsl = FUNC_TO_DSL.get(tokens[FUNCTION])
    if dsl is None:
        raise ValueError('invalid tokens: {}'.format(tokens))

    return dsl(
        namespace=tokens[NAMESPACE],
        name=tokens.get(NAME),
        identifier=tokens.get(IDENTIFIER),
    )
825532
def filter_empty_parameters(func):
    
    @wraps(func)
    def func_wrapper(self, *args, **kwargs):
        my_kwargs = {key: value for key, value in kwargs.items()
                     if value not in EMPTIES}
        args_is_empty = all(arg in EMPTIES for arg in args)

        if (
                {'source', 'material'}.issuperset(my_kwargs) or not my_kwargs
        ) and args_is_empty:
            return
        return func(self, *args, **my_kwargs)

    return func_wrapper
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
278819
def get(identifier, value=None):
  """"""
  if value is None:
    value = identifier
  if identifier is None:
    return None
  elif isinstance(identifier, dict):
    try:
      return deserialize(identifier)
    except ValueError:
      return value
  elif isinstance(identifier, six.string_types):
    config = {'class_name': str(identifier), 'config': {}}
    try:
      return deserialize(config)
    except ValueError:
      return value
  elif callable(identifier):
    return identifier
  return value