mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-25 12:12:34 +01:00
extend and rename util.CustomNone
This commit is contained in:
parent
6afb3cc766
commit
43c211f1a7
@ -528,8 +528,8 @@ def parse_inputfile(file, log):
|
||||
yield line
|
||||
|
||||
|
||||
class UniversalNone():
|
||||
"""None-style object that supports more operations than None itself"""
|
||||
class CustomNone():
|
||||
"""None-style type that supports more operations than regular None"""
|
||||
__slots__ = ()
|
||||
|
||||
def __getattribute__(self, _):
|
||||
@ -538,10 +538,28 @@ class UniversalNone():
|
||||
def __getitem__(self, _):
|
||||
return self
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
return self
|
||||
|
||||
@staticmethod
|
||||
def __next__():
|
||||
raise StopIteration
|
||||
|
||||
@staticmethod
|
||||
def __bool__():
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def __len__():
|
||||
return 0
|
||||
|
||||
@staticmethod
|
||||
def __format__(_):
|
||||
return "None"
|
||||
|
||||
@staticmethod
|
||||
def __str__():
|
||||
return "None"
|
||||
@ -549,7 +567,7 @@ class UniversalNone():
|
||||
__repr__ = __str__
|
||||
|
||||
|
||||
NONE = UniversalNone()
|
||||
NONE = CustomNone()
|
||||
EPOCH = datetime.datetime(1970, 1, 1)
|
||||
SECOND = datetime.timedelta(0, 1)
|
||||
WINDOWS = (os.name == "nt")
|
||||
|
@ -618,10 +618,21 @@ class TestOther(unittest.TestCase):
|
||||
obj = util.NONE
|
||||
|
||||
self.assertFalse(obj)
|
||||
self.assertEqual(len(obj), 0)
|
||||
self.assertEqual(str(obj), str(None))
|
||||
self.assertEqual(repr(obj), repr(None))
|
||||
self.assertEqual(format(obj), str(None))
|
||||
self.assertEqual(format(obj, "%F"), str(None))
|
||||
self.assertIs(obj.attr, obj)
|
||||
self.assertIs(obj["key"], obj)
|
||||
self.assertIs(obj(), obj)
|
||||
self.assertIs(obj(1, "a"), obj)
|
||||
self.assertIs(obj(foo="bar"), obj)
|
||||
|
||||
i = 0
|
||||
for _ in obj:
|
||||
i += 1
|
||||
self.assertEqual(i, 0)
|
||||
|
||||
|
||||
class TestExtractor():
|
||||
|
Loading…
Reference in New Issue
Block a user