aboutsummaryrefslogtreecommitdiffstats
path: root/paste/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'paste/__init__.py')
-rw-r--r--paste/__init__.py25
1 files changed, 13 insertions, 12 deletions
diff --git a/paste/__init__.py b/paste/__init__.py
index 567aa8e..155e927 100644
--- a/paste/__init__.py
+++ b/paste/__init__.py
@@ -8,7 +8,8 @@ from functools import wraps
from typing import Optional
from wsgiref.util import application_uri, request_uri
-from . import store
+from . import db
+from .store import Store
from .types import (
App,
Closable,
@@ -134,10 +135,10 @@ def options(app: App, environ: Env, start_response: StartResponse) -> Response:
@middleware
-def open_store(app: App, environ: Env, start_response: StartResponse) -> Response:
+def open_database(app: App, environ: Env, start_response: StartResponse) -> Response:
db_path = environ.get("PASTE_DB", DB_PATH)
- with store.open(db_path) as stor:
- environ["paste.store"] = stor
+ with db.connect(db_path) as conn:
+ environ["paste.db_conn"] = conn
return app(environ, start_response)
@@ -154,7 +155,7 @@ def authenticate(app: App, environ: Env, start_response: StartResponse) -> Respo
value = b64decode(value.encode(), validate=True)
except (binascii.Error, UnicodeEncodeError):
return False
- return environ["paste.store"].check_token(value)
+ return Store(environ["paste.db_conn"]).check_token(value)
if environ["REQUEST_METHOD"] in {"GET", "HEAD"} or check_auth():
return app(environ, start_response)
@@ -169,13 +170,13 @@ def authenticate(app: App, environ: Env, start_response: StartResponse) -> Respo
@validate_method
@options
@if_none_match
-@open_store
+@open_database
@authenticate
def application(environ: Env, start_response: StartResponse) -> Response:
- stor = environ["paste.store"]
+ store = Store(environ["paste.db_conn"])
name = environ["PATH_INFO"]
if environ["REQUEST_METHOD"] == "GET":
- row = stor.get(name)
+ row = store.get(name)
if not row:
return simple_response(start_response, "404 Not Found")
content_type, content_hash, content = row
@@ -189,7 +190,7 @@ def application(environ: Env, start_response: StartResponse) -> Response:
)
return [content]
elif environ["REQUEST_METHOD"] == "HEAD":
- row = stor.head(name)
+ row = store.head(name)
if not row:
return simple_response(start_response, "404 Not Found")
content_type, content_hash, content_length = row
@@ -206,7 +207,7 @@ def application(environ: Env, start_response: StartResponse) -> Response:
content_type = environ.get("CONTENT_TYPE", "text/plain")
content_length = int(environ["CONTENT_LENGTH"])
content = environ["wsgi.input"].read(content_length)
- created, content_hash = stor.put(name, content, content_type)
+ created, content_hash = store.put(name, content, content_type)
start_response(
"201 Created" if created else "204 No Content",
[
@@ -219,7 +220,7 @@ def application(environ: Env, start_response: StartResponse) -> Response:
content_type = environ.get("CONTENT_TYPE", "text/plain")
content_length = int(environ["CONTENT_LENGTH"])
content = environ["wsgi.input"].read(content_length)
- path, content_hash = stor.post(name, content, content_type)
+ path, content_hash = store.post(name, content, content_type)
uri = application_uri(environ)
path = urllib.parse.quote(path)
if uri[-1] == "/" and path[:1] == "/":
@@ -234,7 +235,7 @@ def application(environ: Env, start_response: StartResponse) -> Response:
)
return []
elif environ["REQUEST_METHOD"] == "DELETE":
- if stor.delete(name):
+ if store.delete(name):
start_response("204 No Content", [])
return []
return simple_response(start_response, "404 Not Found")