diff --git a/pypiserver/_app.py b/pypiserver/_app.py index 84b0180..7d957c3 100644 --- a/pypiserver/_app.py +++ b/pypiserver/_app.py @@ -1,4 +1,9 @@ -import sys, os, itertools +import sys, os, itertools, zipfile + +try: + from io import BytesIO +except ImportError: + from StringIO import StringIO as BytesIO if sys.version_info >= (3, 0): from urllib.parse import urljoin @@ -114,11 +119,39 @@ def update(): except KeyError: raise HTTPError(400, output=":action field not found") - if action == "submit": + if action in ("verify", "submit"): + return "" + + if action == "doc_upload": + try: + content = request.files['content'] + except KeyError: + raise HTTPError(400, output="content file field not found") + zip_data = content.file.read() + try: + zf = zipfile.ZipFile(BytesIO(zip_data)) + info = zf.getinfo('index.html') + except Exception: + raise HTTPError(400, output="not a zip file") + return "" + + if action == "remove_pkg": + name = request.forms.get("name") + version = request.forms.get("version") + if not name or not version: + raise HTTPError(400, "Name or version not specified") + found = None + for pkg in find_packages(packages()): + if pkg.pkgname == name and pkg.version == version: + found = pkg + break + if found is None: + raise HTTPError(404, "%s (%s) not found" % (name, version)) + os.unlink(found.fn) return "" if action != "file_upload": - raise HTTPError(400, output="actions other than file_upload/submit, not supported") + raise HTTPError(400, output="action not supported: %s" % action) try: content = request.files['content']