Skip to content

Commit 7afb616

Browse files
committedJun 18, 2019
Updated the keyvalue REPL utility module
... which it now properly uses both the new “appdirectories” thing, and also employs the `replutilities.NoDefault` singleton object to differentiate between calling “get('key', default=None)” and just doing “get('key')” – the latter of which will raise when 'key' is AWOL instead of returning `None`.
1 parent b49451e commit 7afb616

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed
 

‎.script-bin/keyvalue.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import appdirectories as appdirs
99
from replutilities import attr, isstring, isbytes
10-
from replutilities import Exporter
10+
from replutilities import Exporter, NoDefault
1111

1212
exporter = Exporter()
1313
export = exporter.decorator()
@@ -53,21 +53,22 @@ class ReplEnvDirs(appdirs.AppDirs):
5353

5454
def __init__(self):
5555
""" Initialize with a fixed “appname” parameter `replenv` """
56-
super(ReplEnvDirs, self).__init__(appname='replenv')
57-
self.mode = 'linux' # use Linux directory layout
56+
# use Linux directory layout:
57+
super(ReplEnvDirs, self).__init__(appname='replenv',
58+
system='linux')
5859

5960
@property
6061
def mode(self):
6162
""" The “appdirs.system” global module variable controls the
6263
operation of the properties of all `appdirs.AppDirs` instances.
6364
"""
64-
return appdirs.system
65+
return self.system
6566

6667
@mode.setter
6768
def mode(self, value):
6869
if value not in ('darwin', 'linux'):
6970
raise ValueError("invalid mode: %s" % value)
70-
appdirs.system = value
71+
self.system = value
7172

7273
@property
7374
def site_config(self):
@@ -124,14 +125,14 @@ def count():
124125
return len(zfunc)
125126

126127
@export
127-
def get(key, default_value=None):
128+
def get(key, default=NoDefault):
128129
""" Return a value from the ReplEnv user-config key-value store. """
129-
if not key:
130-
return default_value
130+
if default is NoDefault:
131+
return zfunc[key]
131132
try:
132133
return zfunc[key]
133134
except KeyError:
134-
return default_value
135+
return default
135136

136137
@export
137138
def set(key, value):

0 commit comments

Comments
 (0)
Please sign in to comment.