This repo contains code to mirror other repos. It also contains the code that is getting mirrored.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

72 lines
1.6 KiB

  1. from collections import deque
  2. class fzset(frozenset):
  3. def __repr__(self):
  4. return '{%s}' % ', '.join(map(repr, self))
  5. def classify_bool(seq, pred):
  6. true_elems = []
  7. false_elems = []
  8. for elem in seq:
  9. if pred(elem):
  10. true_elems.append(elem)
  11. else:
  12. false_elems.append(elem)
  13. return true_elems, false_elems
  14. def classify(seq, key=None):
  15. d = {}
  16. for item in seq:
  17. k = key(item) if (key is not None) else item
  18. if k in d:
  19. d[k].append(item)
  20. else:
  21. d[k] = [item]
  22. return d
  23. def bfs(initial, expand):
  24. open_q = deque(list(initial))
  25. visited = set(open_q)
  26. while open_q:
  27. node = open_q.popleft()
  28. yield node
  29. for next_node in expand(node):
  30. if next_node not in visited:
  31. visited.add(next_node)
  32. open_q.append(next_node)
  33. try:
  34. STRING_TYPE = basestring
  35. except NameError: # Python 3
  36. STRING_TYPE = str
  37. Str = type(u'')
  38. import functools
  39. import types
  40. def inline_args(f):
  41. # print '@@', f.__name__, type(f), isinstance(f, types.FunctionType), isinstance(f, types.TypeType), isinstance(f, types.BuiltinFunctionType)
  42. if isinstance(f, types.FunctionType):
  43. @functools.wraps(f)
  44. def _f_func(self, args):
  45. return f(self, *args)
  46. return _f_func
  47. elif isinstance(f, (types.TypeType, types.BuiltinFunctionType)):
  48. @functools.wraps(f)
  49. def _f_builtin(self, args):
  50. return f(*args)
  51. return _f_builtin
  52. else:
  53. @functools.wraps(f)
  54. def _f(self, args):
  55. return f.__func__(self, *args)
  56. return _f