Skip to content

Commit

Permalink
add global SENTINEL object
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed May 19, 2020
1 parent c878764 commit 3201fe3
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 10 deletions.
4 changes: 2 additions & 2 deletions gallery_dl/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ def clear():


def _path():
path = config.get(("cache",), "file", -1)
if path != -1:
path = config.get(("cache",), "file", util.SENTINEL)
if path is not util.SENTINEL:
return util.expand_path(path)

if util.WINDOWS:
Expand Down
5 changes: 2 additions & 3 deletions gallery_dl/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,19 @@ def unset(path, key, *, conf=_config):

class apply():
"""Context Manager: apply a collection of key-value pairs"""
_sentinel = object()

def __init__(self, kvlist):
self.original = []
self.kvlist = kvlist

def __enter__(self):
for path, key, value in self.kvlist:
self.original.append((path, key, get(path, key, self._sentinel)))
self.original.append((path, key, get(path, key, util.SENTINEL)))
set(path, key, value)

def __exit__(self, etype, value, traceback):
for path, key, value in self.original:
if value is self._sentinel:
if value is util.SENTINEL:
unset(path, key)
else:
set(path, key, value)
2 changes: 1 addition & 1 deletion gallery_dl/extractor/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ class SharedConfigMixin():
"""Enable sharing of config settings based on 'basecategory'"""
basecategory = ""

def config(self, key, default=None, *, sentinel=object()):
def config(self, key, default=None, *, sentinel=util.SENTINEL):
value = Extractor.config(self, key, sentinel)
return value if value is not sentinel else config.interpolate(
("extractor", self.basecategory, self.subcategory), key, default)
Expand Down
6 changes: 2 additions & 4 deletions gallery_dl/extractor/mastodon.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ def __init__(self, match):
Extractor.__init__(self, match)
self.api = MastodonAPI(self)

def config(self, key, default=None, *, sentinel=object()):
def config(self, key, default=None, *, sentinel=util.SENTINEL):
value = Extractor.config(self, key, sentinel)
if value is not sentinel:
return value
return config.interpolate(
return value if value is not sentinel else config.interpolate(
("extractor", "mastodon", self.instance, self.subcategory),
key, default,
)
Expand Down
1 change: 1 addition & 0 deletions gallery_dl/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ def __str__():

NONE = UniversalNone()
WINDOWS = (os.name == "nt")
SENTINEL = object()


def build_predicate(predicates):
Expand Down

0 comments on commit 3201fe3

Please sign in to comment.