Python 2 support.

This commit is contained in:
Itamar Turner-Trauring 2021-11-16 11:16:26 -05:00
parent 171d1053ec
commit c195f895db
3 changed files with 46 additions and 3 deletions

View File

@ -2,6 +2,21 @@
HTTP client that talks to the HTTP storage server.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from future.utils import PY2
if PY2:
# fmt: off
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
# fmt: on
else:
from typing import Union
from treq.testing import StubTreq
import base64
# TODO Make sure to import Python version?
@ -35,7 +50,9 @@ class StorageClient(object):
HTTP client that talks to the HTTP storage server.
"""
def __init__(self, url: DecodedURL, swissnum, treq=treq):
def __init__(
self, url, swissnum, treq=treq
): # type: (DecodedURL, bytes, Union[treq,StubTreq]) -> None
self._base_url = url
self._swissnum = swissnum
self._treq = treq

View File

@ -2,6 +2,18 @@
HTTP server for storage.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from future.utils import PY2
if PY2:
# fmt: off
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
# fmt: on
from functools import wraps
from klein import Klein
@ -61,12 +73,14 @@ class HTTPServer(object):
_app = Klein()
def __init__(self, storage_server: StorageServer, swissnum):
def __init__(
self, storage_server, swissnum
): # type: (StorageServer, bytes) -> None
self._storage_server = storage_server
self._swissnum = swissnum
def get_resource(self):
"""Return twisted.web Resource for this object."""
"""Return twisted.web ``Resource`` for this object."""
return self._app.resource()
def _cbor(self, request, data):

View File

@ -2,6 +2,18 @@
Tests for HTTP storage client + server.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from future.utils import PY2
if PY2:
# fmt: off
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
# fmt: on
from twisted.trial.unittest import TestCase
from twisted.internet.defer import inlineCallbacks