File: utils.py

package info (click to toggle)
s4cmd 2.1.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 332 kB
  • sloc: python: 1,620; sh: 670; makefile: 20
file content (34 lines) | stat: -rw-r--r-- 748 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Thanks baboon project for the code.
import subprocess


def cmp_to_key(mycmp):
  """ Converts a cmp= function into a key= function.
  """

  class K(object):
    def __init__(self, obj, *args):
      self.obj = obj

    def __lt__(self, other):
      return mycmp(self.obj, other.obj) < 0

    def __gt__(self, other):
      return mycmp(self.obj, other.obj) > 0

    def __eq__(self, other):
      return mycmp(self.obj, other.obj) == 0

    def __le__(self, other):
      return mycmp(self.obj, other.obj) <= 0

    def __ge__(self, other):
      return mycmp(self.obj, other.obj) >= 0

    def __ne__(self, other):
      return mycmp(self.obj, other.obj) != 0

    def __hash__(self):
      raise TypeError('hash not implemented')

  return K