Maintain dict ordering - but make string version prettier
162711
def pretty_describe(object, nestedness=0, indent=2):
    """"""
    if not isinstance(object, dict):
        return str(object)
    sep = f'\n{" " * nestedness * indent}'
    out = sep.join((f'{k}: {pretty_describe(v, nestedness + 1)}' for k, v in object.items()))
    if nestedness > 0 and out:
        return f'{sep}{out}'
    return out
986169
def _sort(self):
        
        self.versions = OrderedDict(sorted(self.versions.items(), key=lambda v: v[0]))
521374
def format_string_values(obj, err_fallback=(IndexError, KeyError), *args, **kwargs):
    
    if isinstance(obj, dict):
        new = {}
        for key in obj.keys():
            new[key] = format_string_values(obj[key], *args, **kwargs)
        return new
    elif isinstance(obj, list):
        new = []
        for item in obj:
            new.append(format_string_values(item, *args, **kwargs))
        return new
    elif isinstance(obj, six.string_types):
        try:
            return obj.format(*args, **kwargs)
        except err_fallback:
            return obj
    else:
        return obj
1355391
def version_dict(version):
    """"""
    match = version_re.match(str(version) or '')
    letters = 'alpha pre'.split()
    numbers = 'major minor1 minor2 minor3 alpha_ver pre_ver'.split()
    if match:
        d = match.groupdict()
        for letter in letters:
            d[letter] = d[letter] if d[letter] else None
        for num in numbers:
            if d[num] == '*':
                d[num] = 99
            else:
                d[num] = int(d[num]) if d[num] else None
    else:
        d = dict((k, None) for k in numbers)
        d.update((k, None) for k in letters)
    return d
528902
function sortDjangoVersions(versions) {
  return versions.sort((a, b) => {
    if (
      parseDjangoVersionString(a).major === parseDjangoVersionString(b).major
    ) {
      return (
        parseDjangoVersionString(a).minor - parseDjangoVersionString(b).minor
      )
    } else {
      return (
        parseDjangoVersionString(a).major - parseDjangoVersionString(b).major
      )
    }
  })
}
1251359
def _dict_prefix(self, key, value, i, dj=0, color=None, separator=":"):
        just = self._justify if i > 0 else dj
        key = cut(str(key), self._key_maxlen).rjust(just)
        key = colorize(key, color=color)
        pref = "{}{} {}".format(key, separator, value)
        """"""
        return pref
1175070
def _parse_style_str(s):
    
    styledict = {}
    if s:
        # parses L -> R so later keys overwrite earlier ones
        for keyval in s.split(';'):
            l = keyval.strip().split(':')
            if l and len(l) == 2: styledict[l[0].strip()] = l[1].strip()
    return styledict
360676
def _dict_key_priority(s):
        """"""
        if isinstance(s, Hook):
            return _priority(s._schema) - 0.5
        if isinstance(s, Optional):
            return _priority(s._schema) + 0.5
        return _priority(s)
419526
def dict_mirror(d,**kwargs):
    '''
        
    '''
    md = {}
    if('sort_func' in kwargs):
        sort_func = kwargs['sort_func']
    else:
        sort_func = sorted
    vl = list(d.values())
    uvl = elel.uniqualize(vl)
    for v in uvl:
        kl = _keys_via_value_nonrecur(d,v)
        k = sorted(kl)[0]
        md[v] = k
    return(md)
1317012
def pretty(self):
        '''
        
        '''
        return '{}:{} in {}.{}'.format(
            self.filename,
            self.line_number,
            self.module_name,
            self.function_name)
557164
def _get_ordering(son):
    
    def fmt(field, direction):
        return '{0}{1}'.format({-1: '-', 1: '+'}[direction], field)

    if '$orderby' in son:
        return ', '.join(fmt(f, d) for f, d in son['$orderby'].items())
980445
def pretty(self):
        
        retval = ("Key(name={}, type={}, listable={}, compare={}, "
                  "priority={}, kind_preference={}, "
                  "replace_better={})").format(
                      self.name, self.type, self.listable, self.compare,
                      self.priority, self.kind_preference, self.replace_better)
        return retval
474047
def _toOriginal(self, val):
        
        if self._clean.isTuple():
            return tuple(val)
        elif self._clean.isList():
            return list(val)
        elif self._clean.isDict():
            return dict(val)
        else:
            return val
253093
def nsorted(
    to_sort: Iterable[str],
    key: Optional[Callable[[str], Any]] = None
) -> List[str]:
    """"""
    if key is None:
        key_callback = _natural_keys
    else:
        def key_callback(text: str) -> List[Any]:
            return _natural_keys(key(text))  # type: ignore

    return sorted(to_sort, key=key_callback)
438179
def pretty_str(self, indent=0):
        
        if self.parenthesis:
            return (' ' * indent) + '(' + self.name + ')'
        return (' ' * indent) + self.name
1003008
def _strip_nones(d: Dict[str, Any])-> Dict[str, Any]:
        
        return OrderedDict({k: None if isinstance(v, JSGNull) else v for k, v in d.items()
                            if not k.startswith("_") and v is not None and v is not Empty and
                            (issubclass(type(v), JSGObject) or
                             (not issubclass(type(v), JSGString) or v.val is not None) and
                             (not issubclass(type(v), AnyType) or v.val is not Empty))})
815587
def sort_nicely(l):
    """"""
    convert = lambda text: int(text) if text.isdigit() else text
    alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)]
    l.sort(key=alphanum_key)