id
int64 0
843k
| repository_name
stringlengths 7
55
| file_path
stringlengths 9
332
| class_name
stringlengths 3
290
| human_written_code
stringlengths 12
4.36M
| class_skeleton
stringlengths 19
2.2M
| total_program_units
int64 1
9.57k
| total_doc_str
int64 0
4.2k
| AvgCountLine
float64 0
7.89k
| AvgCountLineBlank
float64 0
300
| AvgCountLineCode
float64 0
7.89k
| AvgCountLineComment
float64 0
7.89k
| AvgCyclomatic
float64 0
130
| CommentToCodeRatio
float64 0
176
| CountClassBase
float64 0
48
| CountClassCoupled
float64 0
589
| CountClassCoupledModified
float64 0
581
| CountClassDerived
float64 0
5.37k
| CountDeclInstanceMethod
float64 0
4.2k
| CountDeclInstanceVariable
float64 0
299
| CountDeclMethod
float64 0
4.2k
| CountDeclMethodAll
float64 0
4.2k
| CountLine
float64 1
115k
| CountLineBlank
float64 0
9.01k
| CountLineCode
float64 0
94.4k
| CountLineCodeDecl
float64 0
46.1k
| CountLineCodeExe
float64 0
91.3k
| CountLineComment
float64 0
27k
| CountStmt
float64 1
93.2k
| CountStmtDecl
float64 0
46.1k
| CountStmtExe
float64 0
90.2k
| MaxCyclomatic
float64 0
759
| MaxInheritanceTree
float64 0
16
| MaxNesting
float64 0
34
| SumCyclomatic
float64 0
6k
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
400 |
20c/vodka
|
tests/test_wsgi.py
|
tests.test_wsgi.TestWSGI
|
class TestWSGI(unittest.TestCase):
@classmethod
def setUp(cls):
cls.plugin = vodka.plugin.get_instance({"type": "wsgi_test"})
cls.plugin_2 = vodka.plugin.get_instance(
{
"routes": {
"/a": "wsgi_test_app->a",
"/b": {"target": "wsgi_test_app->b", "methods": ["GET", "POST"]},
},
"type": "wsgi_test",
"name": "wsgi_test2",
}
)
vodka.instance.instantiate(
{"apps": {"wsgi_test_app": {"home": ".", "enabled": True}}}
)
cls.app = vodka.instance.get_instance("wsgi_test_app")
def test_default_config(self):
self.assertEqual(self.plugin.get_config("debug"), False)
self.assertEqual(self.plugin.get_config("host"), "localhost")
self.assertEqual(self.plugin.get_config("port"), 80)
self.assertEqual(self.plugin.get_config("static_url_path"), "/static")
self.assertEqual(self.plugin.get_config("server"), "self")
self.assertEqual(self.plugin.get_config("routes"), {})
def test_set_wsgi_app(self):
app = object()
self.plugin.set_wsgi_app(app)
self.assertEqual(WSGIPlugin.wsgi_application, app)
def test_request_env(self):
req = object()
self.plugin.setup()
env = self.plugin.request_env(req=req, something="other")
self.assertEqual(
env["wsgi_test_app"],
{"static_url": "/static/wsgi_test_app/", "instance": self.app},
)
self.assertEqual(env["request"], req)
self.assertEqual(env["something"], "other")
def test_set_routes(self):
self.plugin_2.set_routes()
self.assertEqual(
self.plugin_2.routes,
{
"/a": {"target": self.app.a, "methods": ["GET"]},
"/b": {"target": self.app.b, "methods": ["GET", "POST"]},
},
)
|
class TestWSGI(unittest.TestCase):
@classmethod
def setUp(cls):
pass
def test_default_config(self):
pass
def test_set_wsgi_app(self):
pass
def test_request_env(self):
pass
def test_set_routes(self):
pass
| 7 | 0 | 9 | 0 | 9 | 0 | 1 | 0 | 1 | 1 | 1 | 0 | 4 | 0 | 5 | 77 | 52 | 4 | 48 | 10 | 41 | 0 | 27 | 9 | 21 | 1 | 2 | 0 | 5 |
401 |
20c/vodka
|
tests/test_util.py
|
tests.test_util.TestUtil
|
class TestUtil(unittest.TestCase):
def test_dict_get_path(self):
a = {"1": {"2": {"3": "end"}}}
b = {"1": [{"x": "end", "name": "a"}, {"c": {"x": "end"}, "name": "b"}]}
self.assertEqual(vodka.util.dict_get_path(a, "1.2.3"), "end")
self.assertEqual(vodka.util.dict_get_path(a, "a.b.c"), None)
self.assertEqual(vodka.util.dict_get_path(a, "a.b.c", default="end"), "end")
self.assertEqual(vodka.util.dict_get_path(b, "1.a.x"), "end")
self.assertEqual(vodka.util.dict_get_path(b, "1.b.c.x"), "end")
self.assertEqual(vodka.util.dict_get_path(b, "1.c.x"), None)
|
class TestUtil(unittest.TestCase):
def test_dict_get_path(self):
pass
| 2 | 0 | 10 | 1 | 9 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 73 | 11 | 1 | 10 | 4 | 8 | 0 | 10 | 4 | 8 | 1 | 2 | 0 | 1 |
402 |
20c/vodka
|
tests/test_templated_app.py
|
tests.test_templated_app.TestTemplatedApp
|
class TestTemplatedApp(unittest.TestCase):
def test_render(self):
vodka.instance.instantiate(
{
"apps": {
TemplatedAppA.handle: {
"enabled": True,
"templates": rsrc("a"),
"template_locations": [rsrc("a2")],
},
TemplatedAppB.handle: {"enabled": True, "templates": rsrc("b")},
}
}
)
inst = vodka.instance.get_instance(TemplatedAppA.handle)
vodka.instance.ready()
r = inst.render("base.html", {})
self.assertEqual(r, "Hello World!")
r = inst.render("template_a.html", {})
self.assertEqual(r, "Hello Universe!")
r = inst.render("template_b.html", {})
self.assertEqual(r, "Hello Infinity!")
|
class TestTemplatedApp(unittest.TestCase):
def test_render(self):
pass
| 2 | 0 | 25 | 4 | 21 | 0 | 1 | 0 | 1 | 2 | 2 | 0 | 1 | 0 | 1 | 73 | 26 | 4 | 22 | 4 | 20 | 0 | 11 | 4 | 9 | 1 | 2 | 0 | 1 |
403 |
20c/vodka
|
tests/test_templated_app.py
|
tests.test_templated_app.TemplatedAppB
|
class TemplatedAppB(vodka.app.TemplatedApplication):
pass
|
class TemplatedAppB(vodka.app.TemplatedApplication):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 13 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 4 | 0 | 0 |
404 |
20c/vodka
|
src/vodka/config/shared.py
|
vodka.config.shared.Attribute
|
class Attribute(BaseAttribute):
"""
Extended config attribute that takes a "share" argument in
that allows it to be shared between differen applications
"""
def __init__(self, expected_type, **kwargs):
"""
Kwargs:
share(str): if set will initialize the apropriate sharing router
format: "{sharing_id}:{sharing_mode}"
example: "test:merge"
"""
super().__init__(expected_type, **kwargs)
share = kwargs.get("share", "")
self.share = None
if share:
sharing_id, sharing_mode = tuple(share.split(":"))
self.share = ROUTERS[expected_type](sharing_id, mode=sharing_mode)
def finalize(self, cfg, key_name, value, **kwargs):
if self.share:
cfg[key_name] = self.share.share(key_name, value)
|
class Attribute(BaseAttribute):
'''
Extended config attribute that takes a "share" argument in
that allows it to be shared between differen applications
'''
def __init__(self, expected_type, **kwargs):
'''
Kwargs:
share(str): if set will initialize the apropriate sharing router
format: "{sharing_id}:{sharing_mode}"
example: "test:merge"
'''
pass
def finalize(self, cfg, key_name, value, **kwargs):
pass
| 3 | 2 | 9 | 1 | 5 | 3 | 2 | 0.91 | 1 | 2 | 0 | 1 | 2 | 1 | 2 | 5 | 24 | 3 | 11 | 6 | 8 | 10 | 11 | 6 | 8 | 2 | 1 | 1 | 4 |
405 |
20c/vodka
|
tests/test_start.py
|
tests.test_start.TestStart
|
class TestStart(unittest.TestCase):
def test_init_and_start(self):
r = vodka.init(CONFIG, CONFIG)
# make sure plugin workers were assigned accordingly
self.assertEqual(
r,
{
"asyncio_workers": [],
"gevent_workers": [],
"thread_workers": [vodka.plugin.get_instance("test_start_plugin_a")],
},
)
# make sure app was instantiated
app = vodka.instance.get_instance("test_start_app")
self.assertEqual(app.setup_done, True)
# make sure inactive app was not instantiated
with self.assertRaises(KeyError):
vodka.instance.get_instance("test_start_app_inactive")
# make sure skipped app was not instantiated
with self.assertRaises(KeyError):
vodka.instance.get_instance("test_start_app_skipped")
# make sure plugin was setup
plugin = vodka.plugin.get_instance("test_start_plugin_a")
self.assertEqual(plugin.setup_done, True)
vodka.start(**r)
# give some time for startup to complete
time.sleep(0.25)
# make sure plugin is running
self.assertEqual(plugin.run_level, 1)
# make sure manually started plugin isnt running
plugin = vodka.plugin.get_instance("test_start_plugin_b")
self.assertEqual(hasattr(plugin, "run_level"), False)
|
class TestStart(unittest.TestCase):
def test_init_and_start(self):
pass
| 2 | 0 | 40 | 9 | 23 | 8 | 1 | 0.33 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 73 | 41 | 9 | 24 | 5 | 22 | 8 | 17 | 5 | 15 | 1 | 2 | 1 | 1 |
406 |
20c/vodka
|
src/vodka/bartender.py
|
vodka.bartender.ClickConfigurator
|
class ClickConfigurator(vodka.config.configurator.Configurator):
"""
Configurator class with prompt and echo wired to click
"""
def echo(self, msg):
click.echo(msg)
def prompt(self, *args, **kwargs):
return click.prompt(*args, **kwargs)
|
class ClickConfigurator(vodka.config.configurator.Configurator):
'''
Configurator class with prompt and echo wired to click
'''
def echo(self, msg):
pass
def prompt(self, *args, **kwargs):
pass
| 3 | 1 | 2 | 0 | 2 | 0 | 1 | 0.6 | 1 | 0 | 0 | 1 | 2 | 0 | 2 | 7 | 10 | 2 | 5 | 3 | 2 | 3 | 5 | 3 | 2 | 1 | 1 | 0 | 2 |
407 |
20c/vodka
|
src/vodka/config/shared.py
|
vodka.config.shared.Container
|
class Container(Attribute):
def finalize(self, cfg, key_name, value, **kwargs):
return
def preload(self, cfg, key_name, **kwargs):
if self.share:
if cfg.get(key_name) is not None:
for _k, _v in list(cfg.get(key_name, {}).items()):
self.share.share(_k, _v)
if self.default is not None:
for _k, _v in list(self.default.items()):
self.share.share(_k, _v)
cfg[key_name] = self.share.container
|
class Container(Attribute):
def finalize(self, cfg, key_name, value, **kwargs):
pass
def preload(self, cfg, key_name, **kwargs):
pass
| 3 | 0 | 6 | 0 | 6 | 0 | 4 | 0 | 1 | 1 | 0 | 0 | 2 | 0 | 2 | 7 | 13 | 1 | 12 | 4 | 9 | 0 | 12 | 4 | 9 | 6 | 2 | 3 | 7 |
408 |
20c/vodka
|
src/vodka/plugins/wsgi.py
|
vodka.plugins.wsgi.SSLConfiguration
|
class SSLConfiguration(vodka.config.Handler):
"""
Allows you to configure the ssl context of a wsgi
plugin
"""
enabled = vodka.config.Attribute(
bool, default=False, help_text="enable ssl encryption"
)
key = vodka.config.Attribute(
vodka.config.validators.path,
default="",
help_text="location of your ssl private key file",
)
cert = vodka.config.Attribute(
vodka.config.validators.path,
default="",
help_text="location of your ssl certificate file",
)
|
class SSLConfiguration(vodka.config.Handler):
'''
Allows you to configure the ssl context of a wsgi
plugin
'''
pass
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0.29 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 6 | 22 | 4 | 14 | 4 | 13 | 4 | 4 | 4 | 3 | 0 | 1 | 0 | 0 |
409 |
20c/vodka
|
src/vodka/config/shared.py
|
vodka.config.shared.ListRouter
|
class ListRouter(Router):
"""
Config sharing router for list configs
"""
@property
def container_type(self):
return list
def share(self, name, value):
container = super().share(name, value)
if self.mode == MODE_MERGE:
for v in value:
if v not in container:
container.append(v)
elif self.mode == MODE_APPEND:
for v in value:
container.append(v)
return container
|
class ListRouter(Router):
'''
Config sharing router for list configs
'''
@property
def container_type(self):
pass
def share(self, name, value):
pass
| 4 | 1 | 7 | 1 | 6 | 0 | 4 | 0.21 | 1 | 2 | 0 | 0 | 2 | 0 | 2 | 8 | 22 | 5 | 14 | 6 | 10 | 3 | 12 | 5 | 9 | 6 | 1 | 3 | 7 |
410 |
20c/vodka
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_vodka/tests/test_bartender.py
|
tests.test_bartender.TestBartender
|
class TestBartender(unittest.TestCase):
"""
Tests bartender CLI
"""
@pytest.fixture(autouse=True)
def setup(self, tmpdir):
self.tmpdir = tmpdir
self.appdir = tmpdir.mkdir("app")
self.config_file = tmpdir.join("config.json")
self.cli = CliRunner()
def test_newapp(self):
"""
Tests the newapp command which should generate a blank app
structure at the provided directory
"""
p = str(self.appdir)
r = self.cli.invoke(vodka.bartender.newapp, ["--path=%s" % p])
self.assertEqual(r.exit_code, 0)
self.assertEqual(os.path.exists(
os.path.join(p, "application.py")), True)
self.assertEqual(os.path.exists(
os.path.join(p, "plugins", "example.py")), True)
def test_check_config(self):
"""
Test the check_config command
"""
# create config to check, this should always validate
self.config_file.write(json.dumps(
{"logging": vodka.log.default_config()}))
# run check_config
r = self.cli.invoke(
vodka.bartender.check_config, ["--config=%s" % str(self.tmpdir)]
)
# assert no errors
self.assertEqual(r.exit_code, 0)
# assert output
self.assertEqual(
str(r.output),
"Checking config at %s for errors ...\n0 config ERRORS, 0 config WARNINGS\n"
% str(self.tmpdir),
)
def test_config(self):
"""
Test the config command
This will will generate a config based on user input and default values
"""
# run config (this will use SimPrompt
r = self.cli.invoke(
vodka.bartender.config, [
"--config=%s/config.json" % str(self.tmpdir)]
)
vodka.log.set_loggers(vodka.log.default_config())
print(r.output)
# assert no errors
self.assertEqual(r.exit_code, 0)
cfg = vodka.config.Config(read=str(self.tmpdir))
expected = {
"apps": {
"test_bartender_app": {"enabled": True, "home": HOME, "module": ""}
},
"plugins": [
{
"async": "thread",
"enabled": True,
"start_manual": False,
"name": "test_bartender_a",
"type": "test_bartender_a",
}
],
}
self.assertEqual("apps" in cfg.data, True)
self.assertEqual("plugins" in cfg.data, True)
# note: because other tests may register applications we
# cannot directly compare the entire content of "apps"
self.assertEqual(
expected["apps"]["test_bartender_app"],
cfg.data["apps"]["test_bartender_app"],
)
self.assertEqual(expected["plugins"], cfg.data["plugins"])
|
class TestBartender(unittest.TestCase):
'''
Tests bartender CLI
'''
@pytest.fixture(autouse=True)
def setup(self, tmpdir):
pass
def test_newapp(self):
'''
Tests the newapp command which should generate a blank app
structure at the provided directory
'''
pass
def test_check_config(self):
'''
Test the check_config command
'''
pass
def test_config(self):
'''
Test the config command
This will will generate a config based on user input and default values
'''
pass
| 6 | 4 | 21 | 4 | 13 | 5 | 1 | 0.42 | 1 | 2 | 1 | 0 | 4 | 4 | 4 | 76 | 95 | 20 | 53 | 16 | 47 | 22 | 28 | 15 | 23 | 1 | 2 | 0 | 4 |
411 |
20c/vodka
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_vodka/tests/test_config.py
|
tests.test_config.DictHandlerProxy.Configuration
|
class Configuration(vodka.config.Handler):
a = vodka.config.Attribute(int, default=1, help_text="dh:a")
b = vodka.config.Attribute(int, help_text="dh:b")
|
class Configuration(vodka.config.Handler):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 6 | 3 | 0 | 3 | 3 | 2 | 0 | 3 | 3 | 2 | 0 | 1 | 0 | 0 |
412 |
20c/vodka
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_vodka/tests/test_data.py
|
tests.test_data.HandlerB.Configuration
|
class Configuration(vodka.data.handlers.Handler.Configuration):
extra = vodka.config.Attribute(
int, default=1, help_text="some extra config")
|
class Configuration(vodka.data.handlers.Handler.Configuration):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 6 | 2 | 0 | 2 | 2 | 1 | 0 | 2 | 2 | 1 | 0 | 3 | 0 | 0 |
413 |
20c/vodka
|
src/vodka/util.py
|
vodka.util.register
|
class register:
"""
allows you index a class in a register
can be used as a decorator
"""
class Meta:
name = "object"
objects = {}
def __init__(self, handle):
"""
Args:
handle (str): unique class handle
Raises:
KeyError: class with handle already exists"
"""
if handle in self.Meta.objects:
raise KeyError(
f"{self.Meta.name} with handle '{handle}' already registered"
)
self.handle = handle
def __call__(self, cls):
cls.handle = self.handle
self.Meta.objects[cls.handle] = cls
return cls
|
class register:
'''
allows you index a class in a register
can be used as a decorator
'''
class Meta:
def __init__(self, handle):
'''
Args:
handle (str): unique class handle
Raises:
KeyError: class with handle already exists"
'''
pass
def __call__(self, cls):
pass
| 4 | 2 | 10 | 2 | 5 | 3 | 2 | 0.71 | 0 | 2 | 1 | 3 | 2 | 1 | 2 | 2 | 32 | 8 | 14 | 7 | 10 | 10 | 12 | 7 | 8 | 2 | 0 | 1 | 3 |
414 |
20c/vodka
|
src/vodka/plugins/zeromq.py
|
vodka.plugins.zeromq.ZeroMQ
|
class ZeroMQ(vodka.plugins.DataPlugin):
class Configuration(vodka.plugins.TimedPlugin.Configuration):
data = vodka.config.Attribute(
str,
default="generic",
help_text="arbitrary descriptor of data retrieved by this zmq probe",
)
data_id = vodka.config.Attribute(str, default="")
bind = vodka.config.Attribute(
str,
help_text="bind to this address. In the format of a URL (protocol://host:port)",
)
def init(self):
super().init()
self.connect()
def connect(self):
self.ctx = zmq.Context()
self.sock = self.ctx.socket(zmq.SUB)
try:
self.sock.setsockopt_string(zmq.SUBSCRIBE, "")
except TypeError:
self.sock.setsockopt(zmq.SUBSCRIBE, "")
self.sock.connect(self.pluginmgr_config.get("bind"))
return self.ctx, self.sock
def work(self):
try:
return super().work(self.sock.recv_json())
except zmq.error.ZMQError:
self.connect()
self.log.error(traceback.format_exc())
except Exception:
self.log.error(traceback.format_exc())
|
class ZeroMQ(vodka.plugins.DataPlugin):
class Configuration(vodka.plugins.TimedPlugin.Configuration):
def init(self):
pass
def connect(self):
pass
def work(self):
pass
| 5 | 0 | 7 | 0 | 7 | 0 | 2 | 0 | 1 | 3 | 0 | 0 | 3 | 2 | 3 | 23 | 37 | 5 | 32 | 10 | 27 | 0 | 25 | 10 | 20 | 3 | 5 | 1 | 6 |
415 |
20c/vodka
|
src/vodka/plugins/wsgi.py
|
vodka.plugins.wsgi.WSGIPlugin
|
class WSGIPlugin(vodka.plugins.PluginBase):
wsgi_application = None
class Configuration(vodka.plugins.PluginBase.Configuration):
# DEPRECATE: 4.0
host = vodka.config.Attribute(
str,
default="localhost",
help_text="host address",
deprecated="4.0. Use the 'bind' config attribute instead.",
)
# DEPRECATE: 4.0
port = vodka.config.Attribute(
int,
default=80,
help_text="host port",
deprecated="4.0. Use the 'bind' config attribute instead.",
)
bind = vodka.config.Attribute(
vodka.config.validators.host,
default="localhost:80",
help_text="bind server to this address. e.g localhost:80",
)
debug = vodka.config.Attribute(
bool,
help_text="run wsgi server in debug mode (if applicable)",
default=False,
)
server = vodka.config.Attribute(
str,
help_text="specify which wsgi server should be used",
default="self",
choices=["uwsgi", "gunicorn", "self", "gevent"],
)
static_url_path = vodka.config.Attribute(
str,
default="/static",
help_text="url path where static files can be requested from",
)
routes = vodka.config.Attribute(
dict,
help_text="routing of request endpoints to vodka application end points",
default={},
)
static_routes = vodka.config.Attribute(
dict,
help_text="routing of request endpoints to static file locations",
default={},
)
ssl = vodka.config.Attribute(
dict, help_text="ssl encryption", default={}, handler=SSLConfiguration
)
@classmethod
def set_wsgi_app(cls, app):
WSGIPlugin.wsgi_application = app
def init(self):
if "bind" in self.pluginmgr_config:
parts = re.match("^(.+):(\d+)$", self.get_config("bind"))
if not parts:
raise ValueError("Unable to parse host and port from `bind` config")
self.host = parts.group(1).strip("[]")
self.port = int(parts.group(2))
# DEPRECATE: 4.0.0
else:
self.host = self.get_config("host").strip("[]")
self.port = self.get_config("port")
def setup(self):
self.static_url_prefixes = {}
for name in list(vodka.instances.keys()):
self.static_url_prefixes[name] = self.static_url_prefix(name)
self.set_routes()
def set_server(self, wsgi_app, fnc_serve=None):
"""
figures out how the wsgi application is to be served
according to config
"""
self.set_wsgi_app(wsgi_app)
ssl_config = self.get_config("ssl")
ssl_context = {}
if self.get_config("server") == "gevent":
if ssl_config.get("enabled"):
ssl_context["certfile"] = ssl_config.get("cert")
ssl_context["keyfile"] = ssl_config.get("key")
from gevent.pywsgi import WSGIServer
http_server = WSGIServer((self.host, self.port), wsgi_app, **ssl_context)
self.log.debug("Serving WSGI via gevent.pywsgi.WSGIServer")
fnc_serve = http_server.serve_forever
elif self.get_config("server") == "uwsgi":
self.pluginmgr_config["start_manual"] = True
elif self.get_config("server") == "gunicorn":
self.pluginmgr_config["start_manual"] = True
elif self.get_config("server") == "self":
fnc_serve = self.run
# figure out async handler
if self.get_config("async") == "gevent":
# handle async via gevent
import gevent
self.log.debug("Handling wsgi on gevent")
self.worker = gevent.spawn(fnc_serve)
elif self.get_config("async") == "thread":
self.worker = fnc_serve
else:
self.worker = fnc_serve
def run(self):
pass
def set_route(self, path, target, methods=None):
pass
def static_url_prefix(self, app_name):
return os.path.join(self.get_config("static_url_path"), app_name, "")
def request_env(self, req=None, **kwargs):
renv = {"static_url": self.get_config("static_url_path"), "request": req}
for name, instance in list(vodka.instances.items()):
appenv = {
"static_url": self.static_url_prefixes.get(name, ""),
"instance": instance,
}
renv[name] = appenv
renv.update(**kwargs)
if "url" in kwargs:
renv["host"] = "{}://{}".format(kwargs["url"].scheme, kwargs["url"].netloc)
return renv
def set_static_routes(self):
pass
def set_routes(self):
self.set_static_routes()
for path, target in list(self.get_config("routes").items()):
if type(target) == str:
target = {"target": target, "methods": ["GET"]}
elif type(target) == dict:
if not target.get("methods"):
target["methods"] = "GET"
if target["target"].find("->") > -1:
# target is an application method
app_name, fnc_name = tuple(target["target"].split("->"))
inst = get_instance(app_name)
# FIXME: if for some reason we want to support different wsgi
# plugins pointing to methods on the same app in the same
# instance, this needs to change
inst.wsgi_plugin = self
meth = getattr(inst, fnc_name)
# apply route decorators (specified by config keys other than
# "target" and "methods"
for k, v in list(target.items()):
decorator = getattr(self, "decorate_route_%s" % k, None)
if decorator:
meth = decorator(**v).__call__(meth)
self.set_route(path, meth, methods=target.get("methods", []))
else:
# target is a static path
# FIXME: handled via static directory routing, probably
# redundant and not implemented at this point
continue
|
class WSGIPlugin(vodka.plugins.PluginBase):
class Configuration(vodka.plugins.PluginBase.Configuration):
@classmethod
def set_wsgi_app(cls, app):
pass
def init(self):
pass
def setup(self):
pass
def set_server(self, wsgi_app, fnc_serve=None):
'''
figures out how the wsgi application is to be served
according to config
'''
pass
def run(self):
pass
def set_route(self, path, target, methods=None):
pass
def static_url_prefix(self, app_name):
pass
def request_env(self, req=None, **kwargs):
pass
def set_static_routes(self):
pass
def set_routes(self):
pass
| 13 | 1 | 13 | 3 | 8 | 2 | 3 | 0.14 | 1 | 7 | 0 | 2 | 9 | 4 | 10 | 21 | 202 | 51 | 133 | 43 | 118 | 18 | 84 | 42 | 70 | 8 | 3 | 4 | 29 |
416 |
20c/vodka
|
tests/test_plugin.py
|
tests.test_plugin.TimedPlugin
|
class TimedPlugin(vodka.plugins.TimedPlugin):
def init(self):
self.counter = 0
def work(self):
self.counter += 1
|
class TimedPlugin(vodka.plugins.TimedPlugin):
def init(self):
pass
def work(self):
pass
| 3 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 2 | 1 | 2 | 18 | 6 | 1 | 5 | 4 | 2 | 0 | 5 | 4 | 2 | 1 | 4 | 0 | 2 |
417 |
20c/vodka
|
src/vodka/plugins/flask.py
|
vodka.plugins.flask.VodkaFlask
|
class VodkaFlask(vodka.plugins.wsgi.WSGIPlugin):
@classmethod
def decorate_route_crossdomain(cls, origin=None, methods=None, headers=None):
"""
route decorator that allows for configuration of access control allow
headers
Keyword arguments:
- origin (str, list): allowed origin hosts
- methods (str, list): allowed origin methods
- headers (str, list): allowed origin headers
Example config:
routes:
/page:
target: my_app->target
crossdomain:
origin: '*'
"""
if methods is not None and not isinstance(methods, str):
methods = ", ".join(sorted(x.upper() for x in methods))
if headers is not None and not isinstance(headers, str):
headers = ", ".join(x.upper() for x in headers)
if not isinstance(origin, str):
origin = ", ".join(origin)
def get_methods():
if methods is not None:
return methods
options_resp = current_app.make_default_options_response()
return options_resp.headers["allow"]
def decorator(f):
def wrapped_function(*args, **kwargs):
if request.method == "OPTIONS":
resp = current_app.make_default_options_response()
else:
resp = make_response(f(*args, **kwargs))
h = resp.headers
h["Access-Control-Allow-Origin"] = origin
h["Access-Control-Allow-Methods"] = get_methods()
if headers is not None:
h["Access-Control-Allow-Headers"] = headers
return resp
return update_wrapper(wrapped_function, f)
return decorator
def init(self):
super().init()
if not Flask:
raise Exception(
"Flask could not be imported, make sure flask module is installed"
)
# flask app
flask_app = Flask("__main__")
flask_app.debug = self.get_config("debug")
flask_app.use_reloader = False
self.set_server(flask_app, fnc_serve=flask_app.run)
def request_env(self, req=None, **kwargs):
url = urllib.parse.urlparse(request.url)
return super().request_env(req=request, url=url, **kwargs)
def set_static_routes(self):
def static_file(app, path):
app = vodka.get_instance(app)
return send_from_directory(
app.get_config("home"), os.path.join("static", path)
)
self.set_route(
os.path.join(self.get_config("static_url_path"), "<app>", "<path:path>"),
static_file,
)
for _url, _path in list(self.get_config("static_routes").items()):
self.set_route(
os.path.join(self.get_config("static_url_path"), _url, "<path:path>"),
lambda path: send_from_directory(_path, path),
)
def set_route(self, path, target, methods=None):
if not methods:
methods = ["GET"]
self.wsgi_application.add_url_rule(
"%s/" % path, view_func=target, methods=methods
)
def run(self):
ssl_config = self.get_config("ssl")
if ssl_config.get("enabled"):
ssl_context = (ssl_config.get("cert"), ssl_config.get("key"))
else:
ssl_context = None
self.wsgi_application.run(
self.host, self.port, use_reloader=False, ssl_context=ssl_context
)
|
class VodkaFlask(vodka.plugins.wsgi.WSGIPlugin):
@classmethod
def decorate_route_crossdomain(cls, origin=None, methods=None, headers=None):
'''
route decorator that allows for configuration of access control allow
headers
Keyword arguments:
- origin (str, list): allowed origin hosts
- methods (str, list): allowed origin methods
- headers (str, list): allowed origin headers
Example config:
routes:
/page:
target: my_app->target
crossdomain:
origin: '*'
'''
pass
def get_methods():
pass
def decorator(f):
pass
def wrapped_function(*args, **kwargs):
pass
def init(self):
pass
def request_env(self, req=None, **kwargs):
pass
def set_static_routes(self):
pass
def static_file(app, path):
pass
def set_route(self, path, target, methods=None):
pass
def run(self):
pass
| 12 | 1 | 14 | 2 | 10 | 2 | 2 | 0.21 | 1 | 4 | 0 | 0 | 5 | 2 | 6 | 27 | 109 | 23 | 71 | 21 | 59 | 15 | 54 | 19 | 43 | 4 | 4 | 1 | 20 |
418 |
20c/vodka
|
src/vodka/plugins/django.py
|
vodka.plugins.django.DjangoPlugin
|
class DjangoPlugin(vodka.plugins.PluginBase):
"""
This plugin allows you to use the django ORM in your
vodka application
Supports django >= 1.8.14
"""
class Configuration(vodka.plugins.PluginBase.Configuration):
project_path = vodka.config.Attribute(
vodka.config.validators.path,
help_text="absolute path to your django project root",
)
settings = vodka.config.Attribute(
dict,
default={},
help_text="django settings object - use uppercase keys as you would inside the actual django settings.py file. Needs INSTALLED_APPS, DATABASES and SECRET_KEY at minimum to function. If omitted, settings located within the django project will be used.",
)
def init(self):
p_path = self.get_config("project_path")
self.log.debug("initializing django from project: %s" % p_path)
# manually configure settings
if self.get_config("settings"):
# settings from vodka config
from django.conf import settings
settings.configure(**self.get_config("settings"))
else:
# settings from django project
for f in os.listdir(p_path):
if os.path.exists(os.path.join(p_path, f, "settings.py")):
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "%s.settings" % f)
break
# so we can import the apps from the django project
sys.path.append(self.get_config("project_path"))
# need this to start the django apps
from django.core.wsgi import get_wsgi_application
self.django_application = get_wsgi_application()
|
class DjangoPlugin(vodka.plugins.PluginBase):
'''
This plugin allows you to use the django ORM in your
vodka application
Supports django >= 1.8.14
'''
class Configuration(vodka.plugins.PluginBase.Configuration):
def init(self):
pass
| 3 | 1 | 25 | 6 | 14 | 5 | 4 | 0.4 | 1 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 47 | 12 | 25 | 10 | 20 | 10 | 17 | 10 | 12 | 4 | 1 | 3 | 4 |
419 |
20c/vodka
|
src/vodka/plugins/__init__.py
|
vodka.plugins.TimedPlugin
|
class TimedPlugin(PluginBase):
class Configuration(PluginBase.Configuration):
interval = vodka.config.Attribute(
float,
help_text="minimum interval between calls to work method (in seconds)",
)
def sleep(self, n):
if self.get_config("async") == "gevent":
import gevent
gevent.sleep(n)
else:
time.sleep(n)
def start(self):
self._run()
def stop(self):
self.run_level = 0
def work(self):
pass
def _run(self):
self.run_level = 1
interval = self.get_config("interval")
while self.run_level:
start = time.time()
self.work()
done = time.time()
elapsed = done - start
if elapsed <= interval:
sleeptime = interval - elapsed
if sleeptime > 0:
self.sleep(sleeptime)
|
class TimedPlugin(PluginBase):
class Configuration(PluginBase.Configuration):
def sleep(self, n):
pass
def start(self):
pass
def stop(self):
pass
def work(self):
pass
def _run(self):
pass
| 7 | 0 | 5 | 0 | 5 | 0 | 2 | 0 | 1 | 0 | 0 | 3 | 5 | 1 | 5 | 16 | 36 | 6 | 30 | 15 | 22 | 0 | 26 | 15 | 18 | 4 | 3 | 3 | 9 |
420 |
20c/vodka
|
src/vodka/plugins/__init__.py
|
vodka.plugins.PluginBase
|
class PluginBase(vodka.component.Component, pluginmgr.config.PluginBase):
class Configuration(vodka.component.Component.Configuration):
async_handler = vodka.config.Attribute(
str,
default="thread",
choices=["thread", "gevent"],
field="async",
help_text="specifies how to run this plugin async",
)
type = vodka.config.Attribute(str, help_text="plugin registration type string")
name = vodka.config.Attribute(
str,
default=lambda x, i: i.type,
help_text="plugin instance name, needs to be unique",
)
start_manual = vodka.config.Attribute(
bool, default=False, help_text="disable automatic start of this plugin"
)
@property
def config(self):
return self.pluginmgr_config
@property
def name(self):
return self.config.get("name")
def __init__(self, config, *args, **kwargs):
# cannot init component because pluginmgr turns config into an attr
pluginmgr.config.PluginBase.__init__(self, config)
def init(self):
"""executed during plugin initialization, app instances not available yet"""
pass
def setup(self):
"""executed before plugin is started, app instances available"""
pass
def start(self):
pass
|
class PluginBase(vodka.component.Component, pluginmgr.config.PluginBase):
class Configuration(vodka.component.Component.Configuration):
@property
def config(self):
pass
@property
def name(self):
pass
def __init__(self, config, *args, **kwargs):
pass
def init(self):
'''executed during plugin initialization, app instances not available yet'''
pass
def setup(self):
'''executed before plugin is started, app instances available'''
pass
def start(self):
pass
| 10 | 2 | 3 | 0 | 2 | 1 | 1 | 0.09 | 2 | 0 | 0 | 4 | 6 | 0 | 6 | 11 | 41 | 6 | 32 | 14 | 22 | 3 | 18 | 12 | 10 | 1 | 2 | 0 | 6 |
421 |
20c/vodka
|
src/vodka/plugins/__init__.py
|
vodka.plugins.DataPlugin
|
class DataPlugin(TimedPlugin):
"""
Plugin that allows to retrieve data from a source on an
interval
Don't instantiate this, but use as a base for other plugins.
"""
class Configuration(TimedPlugin.Configuration):
data = vodka.config.Attribute(
str,
help_text="specify the data type of data fetched by this plugin. Will also apply the vodka data handler with matching name if it exists",
)
data_id = vodka.config.Attribute(
str,
help_text="data id for data handled by this plugin, will default to the plugin name",
default="",
)
@property
def data_type(self):
return self.get_config("data")
@property
def data_id(self):
return self.get_config("data_id") or self.name
def init(self):
return
def work(self, data):
return vodka.data.handle(
self.data_type, data, data_id=self.data_id, caller=self
)
|
class DataPlugin(TimedPlugin):
'''
Plugin that allows to retrieve data from a source on an
interval
Don't instantiate this, but use as a base for other plugins.
'''
class Configuration(TimedPlugin.Configuration):
@property
def data_type(self):
pass
@property
def data_id(self):
pass
def init(self):
pass
def work(self, data):
pass
| 8 | 1 | 3 | 0 | 3 | 0 | 1 | 0.22 | 1 | 0 | 0 | 2 | 4 | 0 | 4 | 20 | 37 | 9 | 23 | 10 | 15 | 5 | 12 | 8 | 6 | 1 | 4 | 0 | 4 |
422 |
20c/vodka
|
src/vodka/config/shared.py
|
vodka.config.shared.DictRouter
|
class DictRouter(Router):
"""
Config sharing router for dict configs
"""
@property
def container_type(self):
return dict
def get(self, key, default=None):
return self.container.get(key, default)
def share(self, name, value):
container = super().share(name, value)
if self.mode == MODE_MERGE:
container.update(**value)
elif self.mode == MODE_APPEND:
raise ValueError("DictRouter cannot have mode: 'append'")
return container
|
class DictRouter(Router):
'''
Config sharing router for dict configs
'''
@property
def container_type(self):
pass
def get(self, key, default=None):
pass
def share(self, name, value):
pass
| 5 | 1 | 4 | 1 | 4 | 0 | 2 | 0.23 | 1 | 3 | 0 | 0 | 3 | 0 | 3 | 9 | 22 | 6 | 13 | 6 | 8 | 3 | 11 | 5 | 7 | 3 | 1 | 1 | 5 |
423 |
20c/vodka
|
src/vodka/log.py
|
vodka.log.LoggerMixin
|
class LoggerMixin:
"""
Mixin class that sets a 'log' property that will either return
the default vodka logger, or a logger specified in the object's
configuration attribute.
This mixin expects the class it is attached to have a 'config'
attribute that is either of type dict or MungeConfig
"""
@property
def log(self):
if hasattr(self, "_log"):
return self._log
else:
self._log = logging.getLogger(self.config.get("log", "vodka"))
return self._log
|
class LoggerMixin:
'''
Mixin class that sets a 'log' property that will either return
the default vodka logger, or a logger specified in the object's
configuration attribute.
This mixin expects the class it is attached to have a 'config'
attribute that is either of type dict or MungeConfig
'''
@property
def log(self):
pass
| 3 | 1 | 6 | 0 | 6 | 0 | 2 | 0.88 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 18 | 3 | 8 | 4 | 5 | 7 | 6 | 3 | 4 | 2 | 0 | 1 | 2 |
424 |
20c/vodka
|
src/vodka/exceptions.py
|
vodka.exceptions.ConfigErrorUnknown
|
class ConfigErrorUnknown(ConfigErrorMixin, KeyError):
"""
This configuration error is raised when a config variable is
specified but unknown to vodka
"""
handle = "config unknown"
def __init__(self, var_name, level="warn", attr=None):
KeyError.__init__(
self,
"%s is not a known configuration variable and has been ignored" % var_name,
)
ConfigErrorMixin.__init__(self, attr=None, level=level)
|
class ConfigErrorUnknown(ConfigErrorMixin, KeyError):
'''
This configuration error is raised when a config variable is
specified but unknown to vodka
'''
def __init__(self, var_name, level="warn", attr=None):
pass
| 2 | 1 | 6 | 0 | 6 | 0 | 1 | 0.5 | 2 | 0 | 0 | 0 | 1 | 0 | 1 | 17 | 15 | 3 | 8 | 3 | 6 | 4 | 5 | 3 | 3 | 1 | 5 | 0 | 1 |
425 |
20c/vodka
|
src/vodka/exceptions.py
|
vodka.exceptions.ConfigErrorType
|
class ConfigErrorType(ConfigErrorMixin, TypeError):
"""
This configuration error is raised when a config variable is
missconfigured with an invalid type for its value
"""
handle = "config type mismatch"
def __init__(self, var_name, attr, level="critical"):
TypeError.__init__(
self, f"{var_name} should be of type '{attr.expected_type.__name__}'"
)
ConfigErrorMixin.__init__(self, attr=attr, level=level)
|
class ConfigErrorType(ConfigErrorMixin, TypeError):
'''
This configuration error is raised when a config variable is
missconfigured with an invalid type for its value
'''
def __init__(self, var_name, attr, level="critical"):
pass
| 2 | 1 | 5 | 0 | 5 | 0 | 1 | 0.57 | 2 | 0 | 0 | 0 | 1 | 0 | 1 | 15 | 14 | 3 | 7 | 3 | 5 | 4 | 5 | 3 | 3 | 1 | 4 | 0 | 1 |
426 |
20c/vodka
|
src/vodka/exceptions.py
|
vodka.exceptions.ConfigErrorMixin
|
class ConfigErrorMixin:
handle = "config error"
def __init__(self, value=None, attr=None, level="warn", reason=None):
self.attr = attr
self.value = value
self.level = level
self.reason = reason
@property
def help_text(self):
if self.attr:
return self.attr.help_text
return ""
@property
def explanation(self):
r = f"[{self.handle}] {str(self)}"
if self.reason:
r = f"{r}, reason: {self.reason}"
if self.attr:
r = f"{r} -> {self.help_text}"
if self.attr.choices:
r = "{} (choices={})".format(r, ",".join(self.attr.choices))
return r
|
class ConfigErrorMixin:
def __init__(self, value=None, attr=None, level="warn", reason=None):
pass
@property
def help_text(self):
pass
@property
def explanation(self):
pass
| 6 | 0 | 6 | 0 | 6 | 0 | 2 | 0 | 0 | 1 | 0 | 4 | 3 | 4 | 3 | 3 | 27 | 5 | 22 | 12 | 16 | 0 | 20 | 10 | 16 | 4 | 0 | 2 | 7 |
427 |
20c/vodka
|
src/vodka/exceptions.py
|
vodka.exceptions.ConfigErrorMissing
|
class ConfigErrorMissing(ConfigErrorMixin, KeyError):
"""
This configuration error is raised when a required config variable
is missing
"""
handle = "config missing"
def __init__(self, var_name, attr, level="critical"):
KeyError.__init__(self, "%s is missing from config file" % var_name)
ConfigErrorMixin.__init__(self, attr=attr, level=level)
|
class ConfigErrorMissing(ConfigErrorMixin, KeyError):
'''
This configuration error is raised when a required config variable
is missing
'''
def __init__(self, var_name, attr, level="critical"):
pass
| 2 | 1 | 3 | 0 | 3 | 0 | 1 | 0.8 | 2 | 0 | 0 | 0 | 1 | 0 | 1 | 17 | 12 | 3 | 5 | 3 | 3 | 4 | 5 | 3 | 3 | 1 | 5 | 0 | 1 |
428 |
20c/vodka
|
src/vodka/data/renderers.py
|
vodka.data.renderers.RPC
|
class RPC(DataRenderer):
"""
RPC renderer, renders an rpc response containing meta and data objects
Should be used as a decorator. The decorated function will be called
with the data container as first argument and the meta container referenced
in the "meta" keyword argument.
"""
def __init__(self, type="json", data_type=list, errors=False):
super().__init__(type=type)
self.errors = errors
self.data_type = data_type
def __call__(self, fn):
def wrapped(*args, **kwargs):
resp = {"meta": {}, "data": self.data_type()}
try:
sig = inspect.signature(fn)
parameters = sig.parameters
if parameters and list(parameters.keys())[0] == "self":
fn(args[0], resp["data"], meta=resp["meta"], *args[1:], **kwargs)
else:
fn(resp["data"], meta=resp["meta"], *args, **kwargs)
except Exception as inst:
if self.errors:
resp["meta"]["error"] = str(inst)
else:
raise
return self.render(resp)
wrapped.__name__ = fn.__name__
return wrapped
|
class RPC(DataRenderer):
'''
RPC renderer, renders an rpc response containing meta and data objects
Should be used as a decorator. The decorated function will be called
with the data container as first argument and the meta container referenced
in the "meta" keyword argument.
'''
def __init__(self, type="json", data_type=list, errors=False):
pass
def __call__(self, fn):
pass
def wrapped(*args, **kwargs):
pass
| 4 | 1 | 13 | 0 | 12 | 0 | 2 | 0.26 | 1 | 4 | 0 | 0 | 2 | 2 | 2 | 4 | 34 | 5 | 23 | 10 | 19 | 6 | 21 | 9 | 17 | 4 | 1 | 2 | 6 |
429 |
20c/vodka
|
src/vodka/data/renderers.py
|
vodka.data.renderers.DataRenderer
|
class DataRenderer:
def __init__(self, type="json"):
self.type = type
def render(self, data):
cls = munge.get_codec(self.type)
codec = cls()
return codec.dumps(data)
|
class DataRenderer:
def __init__(self, type="json"):
pass
def render(self, data):
pass
| 3 | 0 | 3 | 0 | 3 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 2 | 1 | 2 | 2 | 8 | 1 | 7 | 6 | 4 | 0 | 7 | 6 | 4 | 1 | 0 | 0 | 2 |
430 |
20c/vodka
|
src/vodka/data/handlers.py
|
vodka.data.handlers.StorageHandler
|
class StorageHandler(Handler):
"""
Will store the data in the vodka storage.
Data will be stored using data type and data id as keys
"""
class Configuration(Handler.Configuration):
container = vodka.config.Attribute(
str,
help_text="specify how to store data",
choices=["list", "dict"],
default="list",
)
limit = vodka.config.Attribute(
int,
default=500,
help_text="Limit the maximum amount of items to keep; only applies to list storage",
)
def validate_limit(self, value):
if value < 1:
return False, "Needs to be greater than 1"
return True, ""
def __call__(self, data, caller=None):
if type(self.storage) == list:
self.storage.append(data)
l = len(self.storage)
while l > self.get_config("limit"):
self.storage.pop(0)
l -= 1
elif type(self.storage) == dict:
self.storage.update(**data["data"])
return data
def init(self):
if self.get_config("container") == "list":
self.storage = vodka.storage.get_or_create(self.data_id, [])
elif self.get_config("container") == "dict":
self.storage = vodka.storage.get_or_create(self.data_id, {})
else:
raise ValueError(
"Unknown storage container type: %s" % self.get_config("container")
)
|
class StorageHandler(Handler):
'''
Will store the data in the vodka storage.
Data will be stored using data type and data id as keys
'''
class Configuration(Handler.Configuration):
def validate_limit(self, value):
pass
def __call__(self, data, caller=None):
pass
def init(self):
pass
| 5 | 1 | 9 | 2 | 8 | 0 | 3 | 0.11 | 1 | 4 | 0 | 0 | 2 | 1 | 2 | 10 | 51 | 11 | 36 | 9 | 31 | 4 | 22 | 9 | 17 | 4 | 3 | 2 | 9 |
431 |
20c/vodka
|
src/vodka/data/handlers.py
|
vodka.data.handlers.IndexHandler
|
class IndexHandler(Handler):
"""
Will re-index data in a dictionary, indexed to the
key specified in the config
"""
class Configuration(Handler.Configuration):
index = vodka.config.Attribute(str, help_text="the field to use for indexing")
def __call__(self, data, caller=None):
if "data" in data:
r = {}
for d in data["data"]:
if isinstance(d, dict):
r[d[self.get_config("index")]] = d
elif d:
self.log.debug(
"Only dictionary type data rows may be re-indexed, row ignored"
)
else:
self.log.debug("Empty data row ignored.")
data["data"] = r
else:
self.log.debug("Empty data object ignored")
return data
|
class IndexHandler(Handler):
'''
Will re-index data in a dictionary, indexed to the
key specified in the config
'''
class Configuration(Handler.Configuration):
def __call__(self, data, caller=None):
pass
| 3 | 1 | 16 | 0 | 16 | 0 | 5 | 0.21 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 9 | 26 | 3 | 19 | 6 | 16 | 4 | 14 | 6 | 11 | 5 | 3 | 3 | 5 |
432 |
20c/vodka
|
src/vodka/data/handlers.py
|
vodka.data.handlers.Handler
|
class Handler(vodka.component.Component):
"""
Base data handler class. A data handler can be attached to a data type
to manipulate data of that type as it enters vodka.
Attribues:
config (dict or MungeConfg): configuration collection
data_id (str): data id for this handler
Classes:
Configuration: Configuration Handler
"""
class Configuration(vodka.config.ComponentHandler):
pass
def __init__(self, config, data_id):
"""
Args:
config (dict or MungeConfig): configuration collection
data_id (str): data id for this handler, needs to be unique
"""
super().__init__(config)
self.data_id = data_id
self.init()
def __call__(self, data, caller=None):
pass
def init(self):
pass
|
class Handler(vodka.component.Component):
'''
Base data handler class. A data handler can be attached to a data type
to manipulate data of that type as it enters vodka.
Attribues:
config (dict or MungeConfg): configuration collection
data_id (str): data id for this handler
Classes:
Configuration: Configuration Handler
'''
class Configuration(vodka.config.ComponentHandler):
def __init__(self, config, data_id):
'''
Args:
config (dict or MungeConfig): configuration collection
data_id (str): data id for this handler, needs to be unique
'''
pass
def __call__(self, data, caller=None):
pass
def init(self):
pass
| 5 | 2 | 4 | 0 | 3 | 2 | 1 | 1.27 | 1 | 1 | 0 | 4 | 3 | 1 | 3 | 8 | 32 | 7 | 11 | 6 | 6 | 14 | 11 | 6 | 6 | 1 | 2 | 0 | 3 |
433 |
20c/vodka
|
src/vodka/data/data_types.py
|
vodka.data.data_types.DataType
|
class DataType(vodka.component.Component):
"""
Base class for all data types
Classes:
Configuration: configuration handler
"""
class Configuration(vodka.config.ComponentHandler):
handlers = vodka.config.Attribute(
list, default=[], help_text="data handlers to apply to this data"
)
@property
def handlers(self):
"""handlers specified for this data type via config"""
return self.get_config("handlers")
def __init__(self, config):
super().__init__(config)
|
class DataType(vodka.component.Component):
'''
Base class for all data types
Classes:
Configuration: configuration handler
'''
class Configuration(vodka.config.ComponentHandler):
@property
def handlers(self):
'''handlers specified for this data type via config'''
pass
def __init__(self, config):
pass
| 5 | 2 | 3 | 0 | 2 | 1 | 1 | 0.6 | 1 | 1 | 0 | 0 | 2 | 0 | 2 | 7 | 21 | 5 | 10 | 6 | 5 | 6 | 7 | 5 | 3 | 1 | 2 | 0 | 2 |
434 |
20c/vodka
|
src/vodka/config/shared.py
|
vodka.config.shared.RoutersHandler
|
class RoutersHandler(Handler):
"""
Extend this handler in order to do nested config sharing with the same
sharing ruleset
"""
mode = "merge"
sharing_id = None
router_cls = DictRouter
@classmethod
def finalize(cls, cfg, key_name, value, **kwargs):
router_cls = cls.router_cls
share = router_cls(cls.sharing_id, mode=cls.mode)
attr_name = kwargs.get("attr_name")
parent_cfg = kwargs.get("parent_cfg")
share.share(key_name, value)
parent_cfg[attr_name] = shared[cls.sharing_id]
|
class RoutersHandler(Handler):
'''
Extend this handler in order to do nested config sharing with the same
sharing ruleset
'''
@classmethod
def finalize(cls, cfg, key_name, value, **kwargs):
pass
| 3 | 1 | 7 | 0 | 7 | 0 | 1 | 0.33 | 1 | 0 | 0 | 2 | 0 | 0 | 1 | 7 | 18 | 2 | 12 | 10 | 9 | 4 | 11 | 9 | 9 | 1 | 1 | 0 | 1 |
435 |
20c/vodka
|
src/vodka/config/shared.py
|
vodka.config.shared.Router
|
class Router:
"""
Config sharing router, will redirect shared config attributes
to a common container
"""
def __init__(self, _id, mode=MODE_MERGE):
if not _id:
raise ValueError("Name must be specified for config sharing router")
self.id = _id
self.mode = MODES.get(mode)
if not self.mode:
raise ValueError(
"Invalid mode specified for config sharing router: %s" % mode
)
def __repr__(self):
return f"{self.__class__.__name__} <{self.id}>"
@property
def container(self):
return shared.get(self.id, {})
@property
def container_type(self):
return None
@property
def empty(self):
if self.container_type:
ct = self.container_type
return ct()
return None
def share(self, name, value):
if not self.id in shared:
shared[self.id] = {}
if not name in shared[self.id]:
shared[self.id][name] = self.empty
if type(value) != self.container_type:
raise ValueError(
"Router '%s' only accepts value of type '%s'"
% (self.id, self.container_type)
)
return shared[self.id][name]
|
class Router:
'''
Config sharing router, will redirect shared config attributes
to a common container
'''
def __init__(self, _id, mode=MODE_MERGE):
pass
def __repr__(self):
pass
@property
def container(self):
pass
@property
def container_type(self):
pass
@property
def empty(self):
pass
def share(self, name, value):
pass
| 10 | 1 | 6 | 0 | 5 | 0 | 2 | 0.11 | 0 | 2 | 0 | 2 | 6 | 2 | 6 | 6 | 47 | 8 | 35 | 13 | 25 | 4 | 27 | 10 | 20 | 4 | 0 | 1 | 12 |
436 |
20c/vodka
|
src/vodka/exceptions.py
|
vodka.exceptions.ConfigErrorValue
|
class ConfigErrorValue(ConfigErrorMixin, ValueError):
"""
This configuration error is raised when a config variable
has an invalid value. Note that this is separate from a type
mismatch error which will raise ConfigErrorType
"""
handle = "config value invalid"
def __init__(self, var_name, attr, value, reason=None, level="critical"):
ValueError.__init__(self, "%s contains an invalid value" % var_name)
ConfigErrorMixin.__init__(
self, attr=attr, value=value, level=level, reason=reason
)
|
class ConfigErrorValue(ConfigErrorMixin, ValueError):
'''
This configuration error is raised when a config variable
has an invalid value. Note that this is separate from a type
mismatch error which will raise ConfigErrorType
'''
def __init__(self, var_name, attr, value, reason=None, level="critical"):
pass
| 2 | 1 | 6 | 1 | 5 | 0 | 1 | 0.71 | 2 | 0 | 0 | 0 | 1 | 0 | 1 | 15 | 16 | 4 | 7 | 3 | 5 | 5 | 5 | 3 | 3 | 1 | 4 | 0 | 1 |
437 |
20c/vodka
|
tests/test_plugin.py
|
tests.test_plugin.TestTimedPlugin
|
class TestTimedPlugin(unittest.TestCase):
def test_run(self):
plugin = vodka.plugin.get_instance({"type": "timed_test", "interval": 0.01})
vodka.start(thread_workers=[plugin])
time.sleep(1)
plugin.stop()
self.assertGreater(plugin.counter, 1)
|
class TestTimedPlugin(unittest.TestCase):
def test_run(self):
pass
| 2 | 0 | 7 | 1 | 6 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 73 | 8 | 1 | 7 | 3 | 5 | 0 | 7 | 3 | 5 | 1 | 2 | 0 | 1 |
438 |
20c/vodka
|
tests/test_templated_app.py
|
tests.test_templated_app.TemplatedAppA
|
class TemplatedAppA(vodka.app.TemplatedApplication):
pass
|
class TemplatedAppA(vodka.app.TemplatedApplication):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 13 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 4 | 0 | 0 |
439 |
20c/vodka
|
tests/test_plugin.py
|
tests.test_plugin.TestDataPlugin
|
class TestDataPlugin(unittest.TestCase):
def test_run(self):
vodka.data.data_types.instantiate_from_config(
[
{
"type": "data_test",
"handlers": [{"type": "store", "container": "list", "limit": 10}],
}
]
)
plugin = vodka.plugin.get_instance(
{"type": "data_test", "interval": 0.01, "data": "data_test"}
)
vodka.start(thread_workers=[plugin])
time.sleep(1)
self.assertEqual(len(vodka.storage.get("data_test")), 10)
for item in vodka.storage.get("data_test"):
self.assertEqual("data" in item, True)
self.assertEqual("ts" in item, True)
|
class TestDataPlugin(unittest.TestCase):
def test_run(self):
pass
| 2 | 0 | 22 | 4 | 18 | 0 | 2 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 73 | 23 | 4 | 19 | 4 | 17 | 0 | 10 | 4 | 8 | 2 | 2 | 1 | 2 |
440 |
20c/vodka
|
examples/flask/application.py
|
application.MyApp
|
class MyApp(vodka.app.WebApplication):
def index(self):
return self.render("index.html", self.wsgi_plugin.request_env())
def view(self, id):
return self.render("view.html", self.wsgi_plugin.request_env())
def create(self):
# flask request object
req = self.wsgi_plugin.request_env().get("request")
|
class MyApp(vodka.app.WebApplication):
def index(self):
pass
def view(self, id):
pass
def create(self):
pass
| 4 | 0 | 2 | 0 | 2 | 0 | 1 | 0.14 | 1 | 0 | 0 | 0 | 3 | 0 | 3 | 18 | 10 | 2 | 7 | 5 | 3 | 1 | 7 | 5 | 3 | 1 | 5 | 0 | 3 |
441 |
20c/vodka
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_vodka/tests/test_data.py
|
tests.test_data.TestData.test_RPC.Test
|
class Test:
@vodka.data.renderers.RPC(type="json", data_type=list)
def output(self, data, *args, **kwargs):
data.extend(expected_list.get("data"))
|
class Test:
@vodka.data.renderers.RPC(type="json", data_type=list)
def output(self, data, *args, **kwargs):
pass
| 3 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 1 | 0 | 1 | 1 | 4 | 0 | 4 | 3 | 1 | 0 | 3 | 2 | 1 | 1 | 0 | 0 | 1 |
442 |
20c/vodka
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_vodka/tests/test_data.py
|
tests.test_data.TestData.test_handler_register.HandlerA2
|
class HandlerA2(HandlerA):
pass
|
class HandlerA2(HandlerA):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 9 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 4 | 0 | 0 |
443 |
20c/vodka
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_vodka/tests/test_django.py
|
tests.test_django.TestDjango
|
class TestDjango(unittest.TestCase):
@pytest.fixture(autouse=True)
def setup(self, tmpdir):
self.tmpdir = tmpdir
self.dbfile = tmpdir.join("db.sqlite3")
CONFIG["settings"]["DATABASES"]["default"]["NAME"] = str(self.dbfile)
def test_init(self):
plugin = vodka.plugin.get_instance(CONFIG)
from django.core.management import execute_from_command_line
from foo.models import Test
execute_from_command_line(["manage.py", "migrate"])
self.assertEqual(Test.objects.count(), 0)
Test.objects.create(name="Test")
self.assertEqual(Test.objects.count(), 1)
|
class TestDjango(unittest.TestCase):
@pytest.fixture(autouse=True)
def setup(self, tmpdir):
pass
def test_init(self):
pass
| 4 | 0 | 8 | 2 | 6 | 0 | 1 | 0 | 1 | 2 | 1 | 0 | 2 | 2 | 2 | 74 | 18 | 4 | 14 | 9 | 8 | 0 | 13 | 8 | 8 | 1 | 2 | 0 | 2 |
444 |
20c/vodka
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_vodka/src/vodka/app.py
|
vodka.app.Application.Configuration
|
class Configuration(vodka.component.Component.Configuration):
home = vodka.config.Attribute(
vodka.config.validators.path,
default="",
help_text="absolute path to application directory. you can ignore this if application is to be loaded from an installed python package.",
)
module = vodka.config.Attribute(
str,
default="",
help_text="name of the python module containing this application (usually <namespace>.application)",
)
requires = vodka.config.Attribute(
list, default=[], help_text="list of vodka apps required by this app"
)
|
class Configuration(vodka.component.Component.Configuration):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 6 | 15 | 1 | 14 | 4 | 13 | 0 | 4 | 4 | 3 | 0 | 3 | 0 | 0 |
445 |
20c/vodka
|
tests/test_plugin.py
|
tests.test_plugin.TestPlugin
|
class TestPlugin(unittest.TestCase):
def test_get_plugin_by_name(self):
expected = vodka.plugin.get_instance({"type": "test", "name": "a"})
plugin = vodka.plugins.get_plugin_by_name("a")
self.assertEqual(plugin, expected)
def test_get_plugin_class(self):
self.assertEqual(PluginA, vodka.plugins.get_plugin_class("test"))
|
class TestPlugin(unittest.TestCase):
def test_get_plugin_by_name(self):
pass
def test_get_plugin_class(self):
pass
| 3 | 0 | 3 | 0 | 3 | 0 | 1 | 0 | 1 | 1 | 1 | 0 | 2 | 0 | 2 | 74 | 8 | 1 | 7 | 5 | 4 | 0 | 7 | 5 | 4 | 1 | 2 | 0 | 2 |
446 |
20c/vodka
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_vodka/src/vodka/app.py
|
vodka.app.TemplatedApplication.Configuration
|
class Configuration(Application.Configuration):
templates = vodka.config.Attribute(
vodka.config.validators.path,
default=lambda k, i: i.resource(k),
help_text="location of your template files",
)
template_locations = vodka.config.Attribute(
list,
default=[],
help_text="allows you to specify additional paths to load templates from",
)
template_engine = vodka.config.Attribute(
str,
default="jinja2",
choices=["jinja2"],
help_text="template engine to use to render your templates",
)
|
class Configuration(Application.Configuration):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 6 | 19 | 2 | 17 | 4 | 16 | 0 | 4 | 4 | 3 | 0 | 4 | 0 | 0 |
447 |
20c/vodka
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_vodka/src/vodka/app.py
|
vodka.app.WebApplication.Configuration
|
class Configuration(TemplatedApplication.Configuration):
includes = vodka.config.shared.Container(
dict,
default={},
nested=1,
share="includes:merge",
handler=lambda x, y: vodka.config.shared.Routers(
dict, "includes:merge", handler=SharedIncludesConfigHandler
),
help_text="allows you to specify extra media includes for js,css etc.",
)
|
class Configuration(TemplatedApplication.Configuration):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 2 | 1 | 0 | 0 | 0 | 0 | 6 | 12 | 1 | 11 | 2 | 10 | 0 | 2 | 2 | 1 | 0 | 5 | 0 | 0 |
448 |
20c/vodka
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_vodka/src/vodka/app.py
|
vodka.app.register.Meta
|
class Meta:
name = "application"
objects = applications
|
class Meta:
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 | 0 | 3 | 3 | 2 | 0 | 3 | 3 | 2 | 0 | 0 | 0 | 0 |
449 |
20c/vodka
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_vodka/src/vodka/config/shared.py
|
vodka.config.shared.Routers._Handler
|
class _Handler(handler):
mode = _mode
sharing_id = _sharing_id
router_cls = _router_cls
|
class _Handler(handler):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 4 | 0 | 4 | 4 | 3 | 0 | 4 | 4 | 3 | 0 | 1 | 0 | 0 |
450 |
20c/vodka
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_vodka/src/vodka/config/shared.py
|
vodka.config.shared.register.Meta
|
class Meta:
name = "shared config router"
objects = ROUTERS
|
class Meta:
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 | 0 | 3 | 3 | 2 | 0 | 3 | 3 | 2 | 0 | 0 | 0 | 0 |
451 |
20c/vodka
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_vodka/src/vodka/data/data_types.py
|
vodka.data.data_types.DataType.Configuration
|
class Configuration(vodka.config.ComponentHandler):
handlers = vodka.config.Attribute(
list, default=[], help_text="data handlers to apply to this data"
)
|
class Configuration(vodka.config.ComponentHandler):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 6 | 4 | 0 | 4 | 2 | 3 | 0 | 2 | 2 | 1 | 0 | 2 | 0 | 0 |
452 |
20c/vodka
|
tests/resources/django/foo/apps.py
|
foo.apps.FooConfig
|
class FooConfig(AppConfig):
name = "foo"
|
class FooConfig(AppConfig):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2 | 0 | 2 | 2 | 1 | 0 | 2 | 2 | 1 | 0 | 1 | 0 | 0 |
453 |
20c/vodka
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_vodka/src/vodka/data/handlers.py
|
vodka.data.handlers.Handler.Configuration
|
class Configuration(vodka.config.ComponentHandler):
pass
|
class Configuration(vodka.config.ComponentHandler):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 3 | 0 | 0 | 0 | 6 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 2 | 0 | 0 |
454 |
20c/vodka
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_vodka/src/vodka/data/handlers.py
|
vodka.data.handlers.StorageHandler.Configuration
|
class Configuration(Handler.Configuration):
container = vodka.config.Attribute(
str,
help_text="specify how to store data",
choices=["list", "dict"],
default="list",
)
limit = vodka.config.Attribute(
int,
default=500,
help_text="Limit the maximum amount of items to keep; only applies to list storage",
)
def validate_limit(self, value):
if value < 1:
return False, "Needs to be greater than 1"
return True, ""
|
class Configuration(Handler.Configuration):
def validate_limit(self, value):
pass
| 2 | 0 | 4 | 0 | 4 | 0 | 2 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 7 | 18 | 2 | 16 | 4 | 14 | 0 | 7 | 4 | 5 | 2 | 3 | 1 | 2 |
455 |
20c/vodka
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_vodka/src/vodka/data/handlers.py
|
vodka.data.handlers.register.Meta
|
class Meta:
objects = handlers
name = "data handler"
|
class Meta:
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 | 0 | 3 | 3 | 2 | 0 | 3 | 3 | 2 | 0 | 0 | 0 | 0 |
456 |
20c/vodka
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_vodka/src/vodka/plugins/__init__.py
|
vodka.plugins.DataPlugin.Configuration
|
class Configuration(TimedPlugin.Configuration):
data = vodka.config.Attribute(
str,
help_text="specify the data type of data fetched by this plugin. Will also apply the vodka data handler with matching name if it exists",
)
data_id = vodka.config.Attribute(
str,
help_text="data id for data handled by this plugin, will default to the plugin name",
default="",
)
|
class Configuration(TimedPlugin.Configuration):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 6 | 12 | 2 | 10 | 3 | 9 | 0 | 3 | 3 | 2 | 0 | 5 | 0 | 0 |
457 |
20c/vodka
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_vodka/src/vodka/plugins/__init__.py
|
vodka.plugins.PluginBase.Configuration
|
class Configuration(vodka.component.Component.Configuration):
async_handler = vodka.config.Attribute(
str,
default="thread",
choices=["thread", "gevent"],
field="async",
help_text="specifies how to run this plugin async",
)
type = vodka.config.Attribute(
str, help_text="plugin registration type string")
name = vodka.config.Attribute(
str,
default=lambda x, i: i.type,
help_text="plugin instance name, needs to be unique",
)
start_manual = vodka.config.Attribute(
bool, default=False, help_text="disable automatic start of this plugin"
)
|
class Configuration(vodka.component.Component.Configuration):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 2 | 0 | 0 | 0 | 6 | 17 | 0 | 17 | 5 | 16 | 0 | 5 | 5 | 4 | 0 | 3 | 0 | 0 |
458 |
20c/vodka
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_vodka/src/vodka/plugins/__init__.py
|
vodka.plugins.TimedPlugin.Configuration
|
class Configuration(PluginBase.Configuration):
interval = vodka.config.Attribute(
float,
help_text="minimum interval between calls to work method (in seconds)",
)
|
class Configuration(PluginBase.Configuration):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 2 | 0 | 0 | 0 | 6 | 5 | 0 | 5 | 2 | 4 | 0 | 2 | 2 | 1 | 0 | 4 | 0 | 0 |
459 |
20c/vodka
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_vodka/examples/js_css_include/includes_override.py
|
includes_override.TestApp.Configuration
|
class Configuration(vodka.app.WebApplication.Configuration):
includes = vodka.config.Attribute(
dict,
default={
"js": {
"jquery": {"path": "test_app/js/jquery.js"},
},
"css": {
"bootstrap": {"path": "test_app/media/bootstrap.css"},
},
},
handler=lambda x, y: vodka.config.shared.Routers(
dict, "includes:merge", handler=SharedIncludesConfigHandler
),
help_text="allows you to specify extra media includes for js,css etc.",
)
|
class Configuration(vodka.app.WebApplication.Configuration):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 17 | 1 | 16 | 2 | 15 | 0 | 2 | 2 | 1 | 0 | 1 | 0 | 0 |
460 |
20c/vodka
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_vodka/tests/test_app.py
|
tests.test_app.TestApp
|
class TestApp(unittest.TestCase):
def test_register(self):
vodka.app.register(AppA)
assert vodka.app.applications.get("app_a") == AppA
with self.assertRaises(KeyError):
@vodka.app.register("app_a")
class AppC(vodka.app.Application):
pass
def test_get_application(self):
vodka.app.register(AppB)
assert vodka.app.get_application("app_b") == AppB
with self.assertRaises(KeyError):
vodka.app.get_application("does_not_exist")
|
class TestApp(unittest.TestCase):
def test_register(self):
pass
@vodka.app.register("app_a")
class AppC(vodka.app.Application):
def test_get_application(self):
pass
| 5 | 0 | 7 | 1 | 6 | 0 | 1 | 0 | 1 | 4 | 3 | 0 | 2 | 0 | 2 | 74 | 15 | 2 | 13 | 5 | 8 | 0 | 12 | 4 | 8 | 1 | 2 | 1 | 2 |
461 |
20c/vodka
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_vodka/tests/test_app.py
|
tests.test_app.TestApp.test_register.AppC
|
class AppC(vodka.app.Application):
pass
|
class AppC(vodka.app.Application):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 8 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 3 | 0 | 0 |
462 |
20c/vodka
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_vodka/src/vodka/plugins/django.py
|
vodka.plugins.django.DjangoPlugin.Configuration
|
class Configuration(vodka.plugins.PluginBase.Configuration):
project_path = vodka.config.Attribute(
vodka.config.validators.path,
help_text="absolute path to your django project root",
)
settings = vodka.config.Attribute(
dict,
default={},
help_text="django settings object - use uppercase keys as you would inside the actual django settings.py file. Needs INSTALLED_APPS, DATABASES and SECRET_KEY at minimum to function. If omitted, settings located within the django project will be used.",
)
|
class Configuration(vodka.plugins.PluginBase.Configuration):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 12 | 2 | 10 | 3 | 9 | 0 | 3 | 3 | 2 | 0 | 1 | 0 | 0 |
463 |
20c/vodka
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_vodka/src/vodka/plugins/wsgi.py
|
vodka.plugins.wsgi.WSGIPlugin.Configuration
|
class Configuration(vodka.plugins.PluginBase.Configuration):
# DEPRECATE: 4.0
host = vodka.config.Attribute(
str,
default="localhost",
help_text="host address",
deprecated="4.0. Use the 'bind' config attribute instead.",
)
# DEPRECATE: 4.0
port = vodka.config.Attribute(
int,
default=80,
help_text="host port",
deprecated="4.0. Use the 'bind' config attribute instead.",
)
bind = vodka.config.Attribute(
vodka.config.validators.host,
default="localhost:80",
help_text="bind server to this address. e.g localhost:80",
)
debug = vodka.config.Attribute(
bool,
help_text="run wsgi server in debug mode (if applicable)",
default=False,
)
server = vodka.config.Attribute(
str,
help_text="specify which wsgi server should be used",
default="self",
choices=["uwsgi", "gunicorn", "self", "gevent"],
)
static_url_path = vodka.config.Attribute(
str,
default="/static",
help_text="url path where static files can be requested from",
)
routes = vodka.config.Attribute(
dict,
help_text="routing of request endpoints to vodka application end points",
default={},
)
static_routes = vodka.config.Attribute(
dict,
help_text="routing of request endpoints to static file locations",
default={},
)
ssl = vodka.config.Attribute(
dict, help_text="ssl encryption", default={}, handler=SSLConfiguration
)
|
class Configuration(vodka.plugins.PluginBase.Configuration):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0.04 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 6 | 57 | 8 | 47 | 10 | 46 | 2 | 10 | 10 | 9 | 0 | 4 | 0 | 0 |
464 |
20c/vodka
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_vodka/src/vodka/plugins/zeromq.py
|
vodka.plugins.zeromq.ZeroMQ.Configuration
|
class Configuration(vodka.plugins.TimedPlugin.Configuration):
data = vodka.config.Attribute(
str,
default="generic",
help_text="arbitrary descriptor of data retrieved by this zmq probe",
)
data_id = vodka.config.Attribute(str, default="")
bind = vodka.config.Attribute(
str,
help_text="bind to this address. In the format of a URL (protocol://host:port)",
)
|
class Configuration(vodka.plugins.TimedPlugin.Configuration):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 6 | 13 | 2 | 11 | 4 | 10 | 0 | 4 | 4 | 3 | 0 | 5 | 0 | 0 |
465 |
20c/vodka
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_vodka/src/vodka/util.py
|
vodka.util.register.Meta
|
class Meta:
name = "object"
objects = {}
|
class Meta:
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 | 0 | 3 | 3 | 2 | 0 | 3 | 3 | 2 | 0 | 0 | 0 | 0 |
466 |
20c/vodka
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_vodka/src/vodka/data/handlers.py
|
vodka.data.handlers.IndexHandler.Configuration
|
class Configuration(Handler.Configuration):
index = vodka.config.Attribute(
str, help_text="the field to use for indexing")
|
class Configuration(Handler.Configuration):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 6 | 2 | 0 | 2 | 2 | 1 | 0 | 2 | 2 | 1 | 0 | 3 | 0 | 0 |
467 |
20c/vodka
|
tests/resources/django/foo/migrations/0001_initial.py
|
foo.migrations.0001_initial.Migration
|
class Migration(migrations.Migration):
initial = True
dependencies = []
operations = [
migrations.CreateModel(
name="Test",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=200)),
],
),
]
|
class Migration(migrations.Migration):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 23 | 3 | 20 | 4 | 19 | 0 | 4 | 4 | 3 | 0 | 1 | 0 | 0 |
468 |
20c/vodka
|
tests/test_app.py
|
tests.test_app.AppA
|
class AppA(vodka.app.Application):
pass
|
class AppA(vodka.app.Application):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 8 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 3 | 0 | 0 |
469 |
20c/vodka
|
tests/resources/test_start_app/application.py
|
test_start_app.application.Application
|
class Application(vodka.app.Application):
setup_done = False
def setup(self):
self.setup_done = True
|
class Application(vodka.app.Application):
def setup(self):
pass
| 2 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 1 | 0 | 0 | 2 | 1 | 0 | 1 | 9 | 5 | 1 | 4 | 3 | 2 | 0 | 4 | 3 | 2 | 1 | 3 | 0 | 1 |
470 |
20c/vodka
|
tests/test_config.py
|
tests.test_config.DictHandler
|
class DictHandler(vodka.config.Handler):
a = vodka.config.Attribute(int, default=1, help_text="dh:a")
b = vodka.config.Attribute(int, help_text="dh:b")
|
class DictHandler(vodka.config.Handler):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 6 | 3 | 0 | 3 | 3 | 2 | 0 | 3 | 3 | 2 | 0 | 1 | 0 | 0 |
471 |
20c/vodka
|
tests/test_config.py
|
tests.test_config.ConfigHandler
|
class ConfigHandler(vodka.config.Handler):
a = vodka.config.Attribute(int, default=1, help_text="ht:a")
b = vodka.config.Attribute(int, help_text="ht:b")
d = vodka.config.Attribute(int, default=1, choices=[1, 2, 3], help_text="ht:d")
e = vodka.config.Attribute(int, default=1, help_text="ht:e")
f = vodka.config.Attribute(validator, default=1, help_text="ht:f")
g = vodka.config.Attribute(
int, default=lambda x, i: getattr(i, "default_g"), help_text="ht:g"
)
h = vodka.config.Attribute(int, default=1, prepare=[lambda x: x + 1])
i = vodka.config.Attribute(int, default=1)
j = vodka.config.Attribute(list, default=[], handler=lambda x, y: ListHandler)
k = vodka.config.Attribute(dict, default={}, handler=lambda x, y: DictHandler)
l = vodka.config.Attribute(dict, default={}, handler=lambda x, y: DictHandlerProxy)
depr = vodka.config.Attribute(
int, default=1, help_text="ht:depr", deprecated="2.2.0"
)
@classmethod
def validate_e(self, value):
return value < 5, "needs to be smaller than 5"
@classmethod
def prepare_i(self, value, config=None):
return value + 1
|
class ConfigHandler(vodka.config.Handler):
@classmethod
def validate_e(self, value):
pass
@classmethod
def prepare_i(self, value, config=None):
pass
| 5 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 1 | 3 | 3 | 0 | 0 | 0 | 2 | 8 | 25 | 2 | 23 | 17 | 18 | 0 | 17 | 15 | 14 | 1 | 1 | 0 | 2 |
472 |
20c/vodka
|
tests/test_flask.py
|
tests.test_flask.App
|
class App(vodka.app.Application):
def index(self):
return "nothing"
def crossdomain_test(self):
return "crossdomain_test: nothing"
def crossdomain_test_2(self):
return "crossdomain_test: nothing"
def crossdomain_test_3(self):
return "crossdomain_test: nothing"
|
class App(vodka.app.Application):
def index(self):
pass
def crossdomain_test(self):
pass
def crossdomain_test_2(self):
pass
def crossdomain_test_3(self):
pass
| 5 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 4 | 0 | 4 | 12 | 12 | 3 | 9 | 5 | 4 | 0 | 9 | 5 | 4 | 1 | 3 | 0 | 4 |
473 |
20c/vodka
|
tests/test_data.py
|
tests.test_data.HandlerB
|
class HandlerB(vodka.data.handlers.Handler):
class Configuration(vodka.data.handlers.Handler.Configuration):
extra = vodka.config.Attribute(int, default=1, help_text="some extra config")
def __call__(self, data, caller=None):
data["data"][self.handle] = True
return data
|
class HandlerB(vodka.data.handlers.Handler):
class Configuration(vodka.data.handlers.Handler.Configuration):
def __call__(self, data, caller=None):
pass
| 3 | 0 | 3 | 0 | 3 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 9 | 7 | 1 | 6 | 4 | 3 | 0 | 6 | 4 | 3 | 1 | 3 | 0 | 1 |
474 |
20c/vodka
|
tests/test_data.py
|
tests.test_data.HandlerA
|
class HandlerA(vodka.data.handlers.Handler):
def __call__(self, data, caller=None):
data["data"][self.handle] = True
return data
|
class HandlerA(vodka.data.handlers.Handler):
def __call__(self, data, caller=None):
pass
| 2 | 0 | 3 | 0 | 3 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 1 | 9 | 4 | 0 | 4 | 2 | 2 | 0 | 4 | 2 | 2 | 1 | 3 | 0 | 1 |
475 |
20c/vodka
|
tests/test_configurator.py
|
tests.test_configurator.TestConfigurator
|
class TestConfigurator(unittest.TestCase):
def test_configurator(self):
configurator = Configurator(None)
cfg = {}
configurator.set_values(
**{
"a": "what",
"b": "something",
"c": "nope",
"d": "nope",
"e.test.a": "who",
}
)
configurator.configure(cfg, Handler)
self.assertEqual(
cfg,
{"a": "what", "b": "something", "e": {"test": {"a": "who", "b": "else"}}},
)
self.assertEqual(configurator.action_required, ["f: manually"])
def test_configurator_skip_defaults(self):
configurator = Configurator(None, skip_defaults=True)
cfg = {}
configurator.set_values(
**{
"a": "what",
"b": "other",
"c": "nope",
"d": "nope",
"e.test.a": "who",
"e.test.b": "where",
}
)
configurator.configure(cfg, Handler)
self.assertEqual(
cfg,
{"a": "what", "b": "something", "e": {"test": {"a": "who", "b": "else"}}},
)
def test_configurator_override_defaults(self):
configurator = Configurator(None)
cfg = {}
configurator.set_values(
**{
"a": "what",
"b": "other",
"c": "nope",
"d": "nope",
"e.test.a": "who",
"e.test.b": "where",
}
)
configurator.configure(cfg, Handler)
self.assertEqual(
cfg, {"a": "what", "b": "other", "e": {"test": {"a": "who", "b": "where"}}}
)
def test_configurator_skip_existing(self):
configurator = Configurator(None)
cfg = {"a": "why"}
configurator.set_values(
**{
"a": "what",
"b": "other",
"c": "nope",
"d": "nope",
"e.test.a": "who",
"e.test.b": "where",
}
)
configurator.configure(cfg, Handler)
self.assertEqual(
cfg, {"a": "why", "b": "other", "e": {"test": {"a": "who", "b": "where"}}}
)
|
class TestConfigurator(unittest.TestCase):
def test_configurator(self):
pass
def test_configurator_skip_defaults(self):
pass
def test_configurator_override_defaults(self):
pass
def test_configurator_skip_existing(self):
pass
| 5 | 0 | 19 | 1 | 18 | 0 | 1 | 0 | 1 | 2 | 2 | 0 | 4 | 0 | 4 | 76 | 79 | 8 | 71 | 13 | 66 | 0 | 26 | 13 | 21 | 1 | 2 | 0 | 4 |
476 |
20c/vodka
|
tests/test_bartender.py
|
tests.test_bartender.SimPromptConfigurator
|
class SimPromptConfigurator(vodka.bartender.ClickConfigurator):
"""
We make a configurator that simulates user input for
the bartender config test. values will be sent to prompts
in order
"""
values = [
# add application,
"test_bartender_app",
# application home,
HOME,
# application from module,
"",
# dont add another application
"skip",
# add plugin type
"test_bartender_a",
# dont add another plugin
"skip",
]
def prompt(self, msg, default=None, *args, **kwargs):
if not hasattr(self, "counter"):
self.counter = 0
# default value is provided, use that
if default != "skip" and default != "." and default != "":
return default
r = self.values[self.counter]
self.counter += 1
return r
|
class SimPromptConfigurator(vodka.bartender.ClickConfigurator):
'''
We make a configurator that simulates user input for
the bartender config test. values will be sent to prompts
in order
'''
def prompt(self, msg, default=None, *args, **kwargs):
pass
| 2 | 1 | 11 | 2 | 8 | 1 | 3 | 0.71 | 1 | 0 | 0 | 0 | 1 | 1 | 1 | 8 | 34 | 5 | 17 | 5 | 15 | 12 | 10 | 5 | 8 | 3 | 2 | 1 | 3 |
477 |
20c/vodka
|
tests/test_configurator.py
|
tests.test_configurator.HandlerE
|
class HandlerE(vodka.config.Handler):
a = vodka.config.Attribute(str)
b = vodka.config.Attribute(str, default="else")
|
class HandlerE(vodka.config.Handler):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 6 | 3 | 0 | 3 | 3 | 2 | 0 | 3 | 3 | 2 | 0 | 1 | 0 | 0 |
478 |
20c/vodka
|
tests/test_configurator.py
|
tests.test_configurator.Configurator
|
class Configurator(vodka.config.configurator.Configurator):
def set_values(self, **kwargs):
self.prompt_values = kwargs
def prompt(self, k, default=None, *args, **kwargs):
return self.prompt_values.get(k, default)
|
class Configurator(vodka.config.configurator.Configurator):
def set_values(self, **kwargs):
pass
def prompt(self, k, default=None, *args, **kwargs):
pass
| 3 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 2 | 1 | 2 | 7 | 6 | 1 | 5 | 4 | 2 | 0 | 5 | 4 | 2 | 1 | 1 | 0 | 2 |
479 |
20c/vodka
|
tests/test_config_validators.py
|
tests.test_config_validators.TestConfigValidators
|
class TestConfigValidators(unittest.TestCase):
def test_path_validator(self):
b, d = vodka.config.validators.path(__file__)
self.assertEqual(b, True)
def test_host_validator(self):
b, d = vodka.config.validators.host("host:1")
self.assertEqual(b, True)
b, d = vodka.config.validators.host("host")
self.assertEqual(b, False)
b, d = vodka.config.validators.host("host:b")
self.assertEqual(b, False)
|
class TestConfigValidators(unittest.TestCase):
def test_path_validator(self):
pass
def test_host_validator(self):
pass
| 3 | 0 | 6 | 1 | 5 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 2 | 0 | 2 | 74 | 14 | 3 | 11 | 5 | 8 | 0 | 11 | 5 | 8 | 1 | 2 | 0 | 2 |
480 |
20c/vodka
|
tests/test_config.py
|
tests.test_config.TestConfig
|
class TestConfig(unittest.TestCase):
default_g = 2
def test_prepare(self):
cfg = {"h": 1, "b": 1}
c, w = ConfigHandler.validate(cfg)
self.assertEqual(cfg["h"], 2)
def test_prepare_via_handler(self):
cfg = {"i": 1, "b": 1}
c, w = ConfigHandler.validate(cfg)
self.assertEqual(cfg["i"], 2)
def test_nested_validation(self):
# should pass validation
cfg = {"b": 1, "j": [{"a": 1, "b": 1}]}
c, w = ConfigHandler.validate(cfg)
self.assertEqual(c, 0)
self.assertEqual(w, 0)
# should detect b missing from list element
cfg = {"b": 1, "j": [{"a": 1}]}
c, w = ConfigHandler.validate(cfg)
self.assertEqual(c, 1)
self.assertEqual(w, 0)
# should detect b missing from dict element
cfg = {"b": 1, "k": {"1": {"a": 1}}}
c, w = ConfigHandler.validate(cfg)
self.assertEqual(c, 1)
self.assertEqual(w, 0)
# should detect b value mismatch in list element
cfg = {"b": 1, "j": [{"a": 1, "b": "z"}]}
c, w = ConfigHandler.validate(cfg)
self.assertEqual(c, 1)
self.assertEqual(w, 0)
# should detect b missing from dict element and a value mismatch
cfg = {"b": 1, "l": {"1": {"a": "z"}}}
c, w = ConfigHandler.validate(cfg)
self.assertEqual(c, 2)
self.assertEqual(w, 0)
def test_validation(self):
# this should validate without errors
cfg = {"a": 1, "b": 1}
c, w = ConfigHandler.validate(cfg)
self.assertEqual(c, 0)
self.assertEqual(w, 0)
# this should return c=2 (2 critical errors) and
# w=1 (1 warning)
cfg = {"a": "test", "c": 3}
c, w = ConfigHandler.validate(cfg)
self.assertEqual(c, 2)
self.assertEqual(w, 1)
def test_check(self):
# this should raise ConfigErrorType
cfg = {"a": "invalid type"}
with self.assertRaises(exc.ConfigErrorType) as inst:
ConfigHandler.check(cfg, "a", "")
# this should raise ConfigErrorValue
cfg = {"d": 4}
with self.assertRaises(exc.ConfigErrorValue) as inst:
ConfigHandler.check(cfg, "d", "")
# this should raise ConfigErrorUnknown
cfg = {"c": 1}
with self.assertRaises(exc.ConfigErrorUnknown) as inst:
ConfigHandler.check(cfg, "c", "")
# this should raise ConfigErrorValue (from custom validation in class method)
cfg = {"e": 6}
with self.assertRaises(exc.ConfigErrorValue) as inst:
ConfigHandler.check(cfg, "e", "")
# this should raise ConfigErrorValue (from custom validation in validator)
cfg = {"f": 6}
with self.assertRaises(exc.ConfigErrorValue) as inst:
ConfigHandler.check(cfg, "f", "")
def test_default(self):
# default hardset value
self.assertEqual(ConfigHandler.default("a"), 1)
# default lambda value with self passed as instance
self.assertEqual(ConfigHandler.default("g", inst=self), 2)
def test_shared_config(self):
def uniq():
return str(uuid.uuid4())
cfg_a = {"__cfg_a": "a"}
cfg_b = {"__cfg_b": "b"}
i = uniq()
i2 = uniq()
i3 = uniq()
for k in ["a"]:
cfg_a[k] = {"first": i, "second": i2}
cfg_b[k] = {"third": i2, "second": i}
for k in ["b", "c"]:
cfg_a[k] = [i, i2]
cfg_b[k] = [i, i2]
cfg_a["d"] = {
"sub_1": {"first": i, "second": i2, "sub": 1},
"sub_2": {"first": i, "second": i2, "sub": 2},
}
cfg_b["d"] = {
"sub_1": {"third": i, "second": i2, "sub": 1},
"sub_2": {"first": i2, "second": i, "sub": 2},
}
cfg_b["e"] = {
"group_1": {"sub_3": {"first": "sup", "sub": 3}},
"group_2": {"sub_1": {"first": "well", "sub": 1}},
}
SharedConfigHandler.validate(cfg_a)
SharedConfigHandler.validate(cfg_b)
# test shared dict (merge)
self.assertEqual(cfg_a["a"], cfg_b["a"])
self.assertEqual(cfg_a["a"]["third"], i2)
self.assertEqual(cfg_a["a"]["second"], i)
self.assertEqual(cfg_a["a"]["first"], i)
# test shared list (merge)
self.assertEqual(cfg_a["b"], cfg_b["b"])
self.assertEqual(cfg_a["b"], [i, i2])
# test shared list (append)
self.assertEqual(cfg_a["c"], cfg_b["c"])
self.assertEqual(cfg_a["c"], [i, i2, i, i2])
print(list(cfg_b["e"].keys()))
print(json.dumps(cfg_a["e"], indent=2))
# test shared dicts in handler (merge)
self.assertEqual(cfg_a["d"], cfg_b["d"])
self.assertEqual(
cfg_a["d"],
{
"sub_1": {"first": i, "second": i2, "third": i, "sub": 1},
"sub_2": {"first": i2, "second": i, "sub": 2},
},
)
# make sure that default configs got shared as well
self.assertEqual(
cfg_a["e"],
{
"group_1": {
"sub_1": {"first": "hello", "sub": 1},
"sub_2": {"first": "world", "sub": 2},
"sub_3": {"first": "sup", "sub": 3},
},
"group_2": {"sub_1": {"first": "well", "sub": 1}},
},
)
|
class TestConfig(unittest.TestCase):
def test_prepare(self):
pass
def test_prepare_via_handler(self):
pass
def test_nested_validation(self):
pass
def test_validation(self):
pass
def test_check(self):
pass
def test_default(self):
pass
def test_shared_config(self):
pass
def uniq():
pass
| 9 | 0 | 20 | 3 | 15 | 3 | 1 | 0.17 | 1 | 7 | 5 | 0 | 7 | 0 | 7 | 79 | 169 | 33 | 116 | 26 | 107 | 20 | 91 | 25 | 82 | 3 | 2 | 1 | 10 |
481 |
20c/vodka
|
tests/resources/django/foo/models.py
|
foo.models.Test
|
class Test(models.Model):
name = models.CharField(max_length=200)
|
class Test(models.Model):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2 | 0 | 2 | 2 | 1 | 0 | 2 | 2 | 1 | 0 | 1 | 0 | 0 |
482 |
20c/vodka
|
tests/test_config.py
|
tests.test_config.SharedConfigSubHandler
|
class SharedConfigSubHandler(shared.RoutersHandler):
first = vodka.config.Attribute(str, default="")
second = vodka.config.Attribute(str, default="")
third = vodka.config.Attribute(str, default="")
sub = vodka.config.Attribute(int)
|
class SharedConfigSubHandler(shared.RoutersHandler):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 7 | 5 | 0 | 5 | 5 | 4 | 0 | 5 | 5 | 4 | 0 | 2 | 0 | 0 |
483 |
20c/vodka
|
tests/test_config.py
|
tests.test_config.SharedConfigHandler
|
class SharedConfigHandler(vodka.config.Handler):
a = shared.Attribute(dict, share="a:merge")
b = shared.Attribute(list, share="b:merge")
c = shared.Attribute(list, share="c:append")
d = shared.Container(
dict,
share="d:merge",
handler=lambda x, u: shared.Routers(
dict, "d:merge", handler=SharedConfigSubHandler
),
)
e = shared.Container(
dict,
nested=1,
share="e:merge",
default={"group_1": {"sub_1": {"sub": 1, "first": "hello"}}},
handler=lambda x, u: shared.Routers(
dict, "e:merge", handler=SharedConfigSubHandler
),
)
f = shared.Container(
dict,
nested=1,
share="e:merge",
default={"group_1": {"sub_2": {"sub": 2, "first": "world"}}},
handler=lambda x, u: shared.Routers(
dict, "e:merge", handler=SharedConfigSubHandler
),
)
|
class SharedConfigHandler(vodka.config.Handler):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 2 | 1 | 0 | 0 | 0 | 0 | 6 | 32 | 3 | 29 | 7 | 28 | 0 | 7 | 7 | 6 | 0 | 1 | 0 | 0 |
484 |
20c/vodka
|
tests/test_configurator.py
|
tests.test_configurator.Handler
|
class Handler(vodka.config.Handler):
a = vodka.config.Attribute(str)
b = vodka.config.Attribute(str, default="something")
c = vodka.config.Attribute(list, default=[])
d = vodka.config.Attribute(dict, default={})
e = vodka.config.Attribute(dict, default={})
f = vodka.config.Attribute(dict, help_text="manually")
@classmethod
def configure_e(cls, configurator, cfg, path):
_cfg = {}
configurator.configure(_cfg, HandlerE, path="{}.{}".format(path, "test"))
cfg["e"] = {"test": _cfg}
|
class Handler(vodka.config.Handler):
@classmethod
def configure_e(cls, configurator, cfg, path):
pass
| 3 | 0 | 4 | 0 | 4 | 0 | 1 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 1 | 7 | 13 | 1 | 12 | 10 | 9 | 0 | 11 | 9 | 9 | 1 | 1 | 0 | 1 |
485 |
20c/vodka
|
tests/test_bartender.py
|
tests.test_bartender.Plugin
|
class Plugin(vodka.plugins.PluginBase):
pass
|
class Plugin(vodka.plugins.PluginBase):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 11 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 3 | 0 | 0 |
486 |
20c/vodka
|
tests/test_config.py
|
tests.test_config.ListHandler
|
class ListHandler(vodka.config.Handler):
a = vodka.config.Attribute(int, default=1, help_text="lh:a")
b = vodka.config.Attribute(int, help_text="lh:b")
|
class ListHandler(vodka.config.Handler):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 6 | 3 | 0 | 3 | 3 | 2 | 0 | 3 | 3 | 2 | 0 | 1 | 0 | 0 |
487 |
20c/vodka
|
tests/resources/test_start_app/application.py
|
test_start_app.application.SkippedApplication
|
class SkippedApplication(Application):
pass
|
class SkippedApplication(Application):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 9 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 4 | 0 | 0 |
488 |
20c/vodka
|
tests/resources/test_start_app/application.py
|
test_start_app.application.InactiveApplication
|
class InactiveApplication(Application):
pass
|
class InactiveApplication(Application):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 9 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 4 | 0 | 0 |
489 |
20c/vodka
|
tests/test_plugin.py
|
tests.test_plugin.PluginA
|
class PluginA(vodka.plugins.PluginBase):
pass
|
class PluginA(vodka.plugins.PluginBase):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 11 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 3 | 0 | 0 |
490 |
20c/vodka
|
tests/test_plugin.py
|
tests.test_plugin.DataPlugin
|
class DataPlugin(vodka.plugins.DataPlugin):
def work(self):
data = {"data": [], "ts": time.time()}
return super().work(data)
|
class DataPlugin(vodka.plugins.DataPlugin):
def work(self):
pass
| 2 | 0 | 3 | 0 | 3 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 21 | 4 | 0 | 4 | 3 | 2 | 0 | 4 | 3 | 2 | 1 | 5 | 0 | 1 |
491 |
20c/vodka
|
tests/test_instance.py
|
tests.test_instance.TestInstance
|
class TestInstance(unittest.TestCase):
def test_instantiate(self):
vodka.instance.instantiate(APP_CONFIG)
inst_a = vodka.instance.get_instance(AppA.handle)
self.assertEqual(inst_a.handle, AppA.handle)
with self.assertRaises(KeyError):
vodka.instance.get_instance(AppB.handle)
def test_setup(self):
vodka.instance.instantiate(APP_CONFIG)
inst_a = vodka.instance.get_instance(AppA.handle)
vodka.instance.ready()
self.assertEqual(inst_a.initialized, True)
def test_app_versioning(self):
vodka.instance.instantiate(APP_CONFIG)
inst_a = vodka.instance.get_instance(AppA.handle)
inst_v = vodka.instance.get_instance(AppV.handle)
self.assertEqual(inst_v.versioned_handle(), "app_versioned/1.0.0")
self.assertEqual(
inst_v.versioned_path("app_versioned/b/c"), "app_versioned/1.0.0/b/c"
)
self.assertEqual(
inst_v.versioned_url("app_versioned/b/c"), "app_versioned/b/c?v=1.0.0"
)
self.assertEqual(inst_a.versioned_handle(), "app_a2")
|
class TestInstance(unittest.TestCase):
def test_instantiate(self):
pass
def test_setup(self):
pass
def test_app_versioning(self):
pass
| 4 | 0 | 10 | 3 | 8 | 0 | 1 | 0 | 1 | 4 | 3 | 0 | 3 | 0 | 3 | 75 | 34 | 10 | 24 | 8 | 20 | 0 | 20 | 8 | 16 | 1 | 2 | 1 | 3 |
492 |
20c/vodka
|
tests/test_instance.py
|
tests.test_instance.AppV
|
class AppV(vodka.app.WebApplication):
version = "1.0.0"
|
class AppV(vodka.app.WebApplication):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 15 | 2 | 0 | 2 | 2 | 1 | 0 | 2 | 2 | 1 | 0 | 5 | 0 | 0 |
493 |
20c/vodka
|
tests/test_instance.py
|
tests.test_instance.AppB
|
class AppB(vodka.app.Application):
pass
|
class AppB(vodka.app.Application):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 8 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 3 | 0 | 0 |
494 |
20c/vodka
|
tests/test_instance.py
|
tests.test_instance.AppA
|
class AppA(vodka.app.Application):
initialized = False
def setup(self):
self.initialized = True
|
class AppA(vodka.app.Application):
def setup(self):
pass
| 2 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 9 | 5 | 1 | 4 | 3 | 2 | 0 | 4 | 3 | 2 | 1 | 3 | 0 | 1 |
495 |
20c/vodka
|
tests/test_flask.py
|
tests.test_flask.TestFlask
|
class TestFlask(unittest.TestCase):
@classmethod
def setUp(cls):
cls.flask_app = FLASK_APP
cls.plugin = FLASK_PLUGIN
cls.client = FLASK_APP.test_client()
def test_init(self):
self.assertEqual(isinstance(vodka.plugins.wsgi.application(), Flask), True)
def test_request_env(self):
with self.flask_app.test_request_context("/"):
env = self.plugin.request_env(something="else")
self.assertEqual(env.get("something"), "else")
self.assertEqual(env.get("request"), request)
self.assertEqual(env.get("host"), "http://localhost")
self.assertEqual(
env.get("flask_test"),
{
"static_url": "/static/flask_test/",
"instance": vodka.instance.get_instance("flask_test"),
},
)
def _test_routing(self):
self.assertEqual(self.client.get("/").data, "nothing")
def test_crossdomain_decorator(self):
rv = self.client.get("/crossdomain_test", follow_redirects=True)
self.assertEqual(rv.data, b"crossdomain_test: nothing")
self.assertEqual(rv.headers.get("Access-Control-Allow-Origin"), "*")
self.assertEqual(
sorted(rv.headers.get("Access-Control-Allow-Methods").split(", ")),
["GET", "HEAD", "OPTIONS"],
)
rv = self.client.get("/crossdomain_test_2", follow_redirects=True)
self.assertEqual(rv.data, b"crossdomain_test: nothing")
self.assertEqual(rv.headers.get("Access-Control-Allow-Origin"), "a.com, b.com")
self.assertEqual(
sorted(rv.headers.get("Access-Control-Allow-Methods").split(", ")),
["GET", "OPTIONS"],
)
# methods = sorted(rv.headers.get("Access-Control-Allow-Methods").split(", "))
# assert ["GET", "OPTIONS"] == methods
rv = self.client.get("/crossdomain_test_3", follow_redirects=True)
self.assertEqual(rv.data, b"crossdomain_test: nothing")
self.assertEqual(rv.headers.get("Access-Control-Allow-Origin"), "a.com, b.com")
self.assertEqual(
rv.headers.get("Access-Control-Allow-Headers"),
"ANOTHER-HEADER, TEST-HEADER",
)
self.assertEqual(
sorted(rv.headers.get("Access-Control-Allow-Methods").split(", ")), ["GET"]
)
|
class TestFlask(unittest.TestCase):
@classmethod
def setUp(cls):
pass
def test_init(self):
pass
def test_request_env(self):
pass
def _test_routing(self):
pass
def test_crossdomain_decorator(self):
pass
| 7 | 0 | 10 | 0 | 9 | 0 | 1 | 0.04 | 1 | 0 | 0 | 0 | 4 | 0 | 5 | 77 | 56 | 6 | 48 | 9 | 41 | 2 | 30 | 8 | 24 | 1 | 2 | 1 | 5 |
496 |
20c/vodka
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_vodka/tests/test_data.py
|
tests.test_data.TestData
|
class TestData(unittest.TestCase):
def test_handler_register(self):
# test that handle a above was registered correctly
self.assertEqual(vodka.data.handlers.get("a"), HandlerA)
self.assertEqual(HandlerA.handle, "a")
# test that handler type 'a' cannot be reused
with self.assertRaises(KeyError) as inst:
@vodka.data.handlers.register("a")
class HandlerA2(HandlerA):
pass
def test_handlers_instantiate(self):
# instantiate single handler
handler = vodka.data.handlers.instantiate({"type": "a"}, "test_a")
self.assertEqual(handler.__class__, HandlerA)
# instantiate multiple handlers from data type test
handlers = vodka.data.handlers.instantiate_for_data_type("test")
self.assertEqual(len(handlers), 2)
self.assertEqual(handlers[0].handle, "a")
self.assertEqual(handlers[1].handle, "b")
self.assertEqual(handlers[1].get_config("extra"), 123)
def test_handlers_call(self):
handlers = vodka.data.handlers.instantiate_for_data_type("test")
data = {"data": {"this": "is a test"}}
expected = {"data": {"this": "is a test", "a": True, "b": True}}
for h in handlers:
data = h(data)
self.assertEqual(data, expected)
def test_handle(self):
data = {"data": {"this": "is a test"}}
expected = {"data": {"this": "is a test", "a": True, "b": True}}
self.assertEqual(vodka.data.handle("test", data), expected)
def test_handler_index(self):
handler = vodka.data.handlers.instantiate(
{"type": "index", "index": "name"}, "test_b"
)
objs = [{"name": "obj %s" % i} for i in range(0, 10)]
data = {"data": objs}
expected = {"data": {o["name"]: o for o in objs}}
self.assertEqual(handler(data), expected)
# test with incomplete data
objs = [{"name": "obj %s" % i} for i in range(0, 10)]
objs[2] = None
data = {"data": objs}
i = 0
expected = {"data": {}}
while i < 10:
if i == 2:
i += 1
continue
o = objs[i]
expected["data"][o["name"]] = o
i += 1
self.assertEqual(handler(data), expected)
def test_handler_store(self):
# test list storage
handler = vodka.data.handlers.instantiate(
{"type": "store", "cotainer": "list", "limit": 5}, "test_c"
)
data = [{"a": i} for i in range(0, 10)]
for d in data:
handler({"data": d})
self.assertEqual(len(handler.storage), 5)
self.assertEqual([{"data": x} for x in data[5:]], handler.storage)
# test dict storage
handler = vodka.data.handlers.instantiate(
{"type": "store", "container": "dict"}, "test_d"
)
handler({"data": {"a": 1}})
self.assertEqual(handler.storage, {"a": 1})
handler({"data": {"a": 2, "b": 1}})
self.assertEqual(handler.storage, {"a": 2, "b": 1})
def test_RPC(self):
expected_list = {"data": [1, 2, 3], "meta": {}}
expected_dict = {"data": {"a": 1, "b": 2}, "meta": {}}
# test rpc renderer to json with data type list
@vodka.data.renderers.RPC(type="json", data_type=list)
def output_list_json(data, *args, **kwargs):
data.extend(expected_list.get("data"))
self.assertEqual(json.loads(output_list_json()), expected_list)
# test rpc renderer to json with data type dict
@vodka.data.renderers.RPC(type="json", data_type=dict)
def output_dict_json(data, *args, **kwargs):
data.update(expected_dict.get("data"))
self.assertEqual(json.loads(output_dict_json()), expected_dict)
# test rpc renderer with error catching
@vodka.data.renderers.RPC(errors=True)
def output_error(data, *args, **kwargs):
raise Exception("an error occured")
self.assertEqual(
json.loads(output_error()),
{"data": [], "meta": {"error": "an error occured"}},
)
# test rpc renderer on class method
class Test:
@vodka.data.renderers.RPC(type="json", data_type=list)
def output(self, data, *args, **kwargs):
data.extend(expected_list.get("data"))
t = Test()
self.assertEqual(json.loads(t.output()), expected_list)
|
class TestData(unittest.TestCase):
def test_handler_register(self):
pass
@vodka.data.handlers.register("a")
class HandlerA2(HandlerA):
def test_handlers_instantiate(self):
pass
def test_handlers_call(self):
pass
def test_handler_register(self):
pass
def test_handler_index(self):
pass
def test_handler_store(self):
pass
def test_RPC(self):
pass
@vodka.data.renderers.RPC(type="json", data_type=list)
def output_list_json(data, *args, **kwargs):
pass
@vodka.data.renderers.RPC(type="json", data_type=dict)
def output_dict_json(data, *args, **kwargs):
pass
@vodka.data.renderers.RPC(errors=True)
def output_error(data, *args, **kwargs):
pass
class TestData(unittest.TestCase):
@vodka.data.renderers.RPC(type="json", data_type=list)
def output_list_json(data, *args, **kwargs):
pass
| 19 | 0 | 13 | 3 | 9 | 1 | 1 | 0.13 | 1 | 9 | 4 | 0 | 7 | 0 | 7 | 79 | 140 | 41 | 88 | 38 | 69 | 11 | 74 | 32 | 60 | 3 | 2 | 2 | 15 |
497 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/examples/api/two_way/client.py
|
client.Client
|
class Client(xbahn.api.Client):
touched = False
@xbahn.api.expose
def touch(self):
"""
Something for the server to call
"""
self.touched = True
return True
|
class Client(xbahn.api.Client):
@xbahn.api.expose
def touch(self):
'''
Something for the server to call
'''
pass
| 3 | 1 | 6 | 0 | 3 | 3 | 1 | 0.5 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 29 | 11 | 2 | 6 | 4 | 3 | 3 | 5 | 3 | 3 | 1 | 5 | 0 | 1 |
498 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/examples/api/widget_aware_server/client.py
|
client.Client
|
class Client(xbahn.api.Client):
pass
|
class Client(xbahn.api.Client):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 28 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 5 | 0 | 0 |
499 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/examples/api/widget_aware_server/client.py
|
client.Client
|
class Client(xbahn.api.Client):
pass
|
class Client(xbahn.api.Client):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 28 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 5 | 0 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.