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
|
yield line
|
||||||
|
|
||||||
|
|
||||||
class UniversalNone():
|
class CustomNone():
|
||||||
"""None-style object that supports more operations than None itself"""
|
"""None-style type that supports more operations than regular None"""
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
|
|
||||||
def __getattribute__(self, _):
|
def __getattribute__(self, _):
|
||||||
@ -538,10 +538,28 @@ class UniversalNone():
|
|||||||
def __getitem__(self, _):
|
def __getitem__(self, _):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __call__(self, *args, **kwargs):
|
||||||
|
return self
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def __next__():
|
||||||
|
raise StopIteration
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __bool__():
|
def __bool__():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def __len__():
|
||||||
|
return 0
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def __format__(_):
|
||||||
|
return "None"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __str__():
|
def __str__():
|
||||||
return "None"
|
return "None"
|
||||||
@ -549,7 +567,7 @@ class UniversalNone():
|
|||||||
__repr__ = __str__
|
__repr__ = __str__
|
||||||
|
|
||||||
|
|
||||||
NONE = UniversalNone()
|
NONE = CustomNone()
|
||||||
EPOCH = datetime.datetime(1970, 1, 1)
|
EPOCH = datetime.datetime(1970, 1, 1)
|
||||||
SECOND = datetime.timedelta(0, 1)
|
SECOND = datetime.timedelta(0, 1)
|
||||||
WINDOWS = (os.name == "nt")
|
WINDOWS = (os.name == "nt")
|
||||||
|
@ -618,10 +618,21 @@ class TestOther(unittest.TestCase):
|
|||||||
obj = util.NONE
|
obj = util.NONE
|
||||||
|
|
||||||
self.assertFalse(obj)
|
self.assertFalse(obj)
|
||||||
|
self.assertEqual(len(obj), 0)
|
||||||
self.assertEqual(str(obj), str(None))
|
self.assertEqual(str(obj), str(None))
|
||||||
self.assertEqual(repr(obj), repr(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.attr, obj)
|
||||||
self.assertIs(obj["key"], 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():
|
class TestExtractor():
|
||||||
|
Loading…
Reference in New Issue
Block a user