Skip to content

Commit

Permalink
_ prefix for many private methods of Datasette, refs #576
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed May 30, 2020
1 parent ca56c22 commit 012c769
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
28 changes: 14 additions & 14 deletions datasette/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def __init__(
# pylint: disable=no-member
pm.hook.prepare_jinja2_environment(env=self.jinja_env)

self.register_renderers()
self._register_renderers()

def get_database(self, name=None):
if name is None:
Expand Down Expand Up @@ -392,7 +392,7 @@ def update_with_inherited_metadata(self, metadata):
}
)

def prepare_connection(self, conn, database):
def _prepare_connection(self, conn, database):
conn.row_factory = sqlite3.Row
conn.text_factory = lambda x: str(x, "utf-8", "replace")
for name, num_args, func in self.sqlite_functions:
Expand Down Expand Up @@ -468,12 +468,12 @@ def absolute_url(self, request, path):
url = "https://" + url[len("http://") :]
return url

def register_custom_units(self):
def _register_custom_units(self):
"Register any custom units defined in the metadata.json with Pint"
for unit in self.metadata("custom_units") or []:
ureg.define(unit)

def connected_databases(self):
def _connected_databases(self):
return [
{
"name": d.name,
Expand All @@ -486,9 +486,9 @@ def connected_databases(self):
for d in sorted(self.databases.values(), key=lambda d: d.name)
]

def versions(self):
def _versions(self):
conn = sqlite3.connect(":memory:")
self.prepare_connection(conn, ":memory:")
self._prepare_connection(conn, ":memory:")
sqlite_version = conn.execute("select sqlite_version()").fetchone()[0]
sqlite_extensions = {}
for extension, testsql, hasversion in (
Expand Down Expand Up @@ -534,7 +534,7 @@ def versions(self):
},
}

def plugins(self, show_all=False):
def _plugins(self, show_all=False):
ps = list(get_plugins())
if not show_all:
ps = [p for p in ps if p["name"] not in DEFAULT_PLUGINS]
Expand All @@ -548,7 +548,7 @@ def plugins(self, show_all=False):
for p in ps
]

def threads(self):
def _threads(self):
threads = list(threading.enumerate())
d = {
"num_threads": len(threads),
Expand Down Expand Up @@ -576,7 +576,7 @@ def table_metadata(self, database, table):
.get(table, {})
)

def register_renderers(self):
def _register_renderers(self):
""" Register output renderers which output data in custom formats. """
# Built-in renderers
self.renderers["json"] = (json_renderer, lambda: True)
Expand Down Expand Up @@ -724,23 +724,23 @@ def add_route(view, regex):
r"/-/metadata(?P<as_format>(\.json)?)$",
)
add_route(
JsonDataView.as_asgi(self, "versions.json", self.versions),
JsonDataView.as_asgi(self, "versions.json", self._versions),
r"/-/versions(?P<as_format>(\.json)?)$",
)
add_route(
JsonDataView.as_asgi(self, "plugins.json", self.plugins),
JsonDataView.as_asgi(self, "plugins.json", self._plugins),
r"/-/plugins(?P<as_format>(\.json)?)$",
)
add_route(
JsonDataView.as_asgi(self, "config.json", lambda: self._config),
r"/-/config(?P<as_format>(\.json)?)$",
)
add_route(
JsonDataView.as_asgi(self, "threads.json", self.threads),
JsonDataView.as_asgi(self, "threads.json", self._threads),
r"/-/threads(?P<as_format>(\.json)?)$",
)
add_route(
JsonDataView.as_asgi(self, "databases.json", self.connected_databases),
JsonDataView.as_asgi(self, "databases.json", self._connected_databases),
r"/-/databases(?P<as_format>(\.json)?)$",
)
add_route(
Expand All @@ -765,7 +765,7 @@ def add_route(view, regex):
+ renderer_regex
+ r")?$",
)
self.register_custom_units()
self._register_custom_units()

async def setup_db():
# First time server starts up, calculate table counts for immutable databases
Expand Down
2 changes: 1 addition & 1 deletion datasette/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def in_thread():
conn = getattr(connections, self.name, None)
if not conn:
conn = self.connect()
self.ds.prepare_connection(conn, self.name)
self.ds._prepare_connection(conn, self.name)
setattr(connections, self.name, conn)
return fn(conn)

Expand Down

0 comments on commit 012c769

Please sign in to comment.