Skip to content

Commit

Permalink
Fixed some flake8 errors and removed dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed May 29, 2017
1 parent b0b1fb0 commit 2b5dd69
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 240 deletions.
236 changes: 0 additions & 236 deletions asphalt/web/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,242 +9,6 @@
HTTP_METHODS = frozenset(['HEAD', 'GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'TRACE'])


# class HTTPRequest:
# """
# Represents an HTTP request.
#
# It should be noted that if the application is behind a reverse proxy such as nginx or Apache,
# some of these values may not reflect their expected values.
# This affects in particular the ``http_version``, ``peername`` and ``peercert`` attributes.
# Special measures must be taken to retain the proper values through a reverse proxy
# connection.
#
# :ivar str http_version: HTTP version (e.g. ``1.1`` or ``2``)
# :ivar str method: HTTP method (e.g. ``GET``, ``POST``, etc.)
# :ivar str path: request path (e.g. ``/some/resource/somewhere``)
# :ivar str query: HTTP query string
# :ivar str scheme: ``http`` or ``https`` depending on whether TLS was used to connect to the
# server
# :ivar str peername: IP address or UNIX socket path of the client
# :ivar str peercert: the raw client certificate data if the client presented a certificate
# .. seealso:: https://docs.python.org/3/library/ssl.html#ssl.SSLSocket.getpeercert
# """
#
# @property
# @abstractmethod
# def query(self) -> Dict[str, str]:
# """Return a dictionary of query parameters."""
#
# @property
# @abstractmethod
# def accept(self) -> HTTPAccept:
# """
# Return the parsed version of the ``accept`` header.
#
# :return: an HTTPAccept instance, or ``None`` if the header was not present
# """
#
# @property
# @abstractmethod
# def accept_charset(self) -> HTTPAcceptCharset:
# """
# Return the parsed version of the ``accept-charset`` header.
#
# :return: an HTTPAcceptCharset instance, or ``None`` if the header was not present
# """
#
# @property
# @abstractmethod
# def accept_encoding(self) -> HTTPAcceptEncoding:
# """
# Return the parsed version of the ``accept-encoding`` header.
#
# :return: an HTTPAcceptEncoding instance, or ``None`` if the header was not present
# """
#
# @property
# @abstractmethod
# def accept_language(self) -> HTTPAcceptLanguage:
# """
# Return the parsed version of the ``accept-language`` header.
#
# :return: an HTTPAcceptLanguage instance, or ``None`` if the header was not present
# """
#
# @property
# @abstractmethod
# def charset(self) -> Optional[str]:
# """
# Return the character set of the request.
#
# The character set is parsed from the of the ``content-type`` header, if present.
#
# :return: the character set of the request, or ``None`` if none was defined
# """
#
# @property
# @abstractmethod
# def content_length(self) -> Optional[int]:
# """
# Return the content length of the request.
#
# :return: the content length, or ``None`` if the header was not present
# """
#
# @property
# @abstractmethod
# def content_type(self) -> Optional[str]:
# """
# Return the content type of the request, or ``None`` if none was defined.
#
# :return:
# """
#
# @property
# @abstractmethod
# def cookies(self) -> Dict[str, str]:
# """Return a read-only dictionary containing cookie values sent by the client."""
#
# @property
# @abstractmethod
# def if_modified_since(self) -> Optional[datetime]:
# """
# Return the ``if-modified-since`` header as a timezone aware datetime.
#
# :return: the header's value as a datetime, or ``None`` if the header was not present
# """
#
# @property
# @abstractmethod
# def if_range(self) -> Optional[HTTPRange]:
# """
# Return the ``if-range`` header as a :class:`~HTTPRange` instance
#
# :return: the header's value as HTTPRange, or ``None`` if the header was not present
# """
#
# @property
# @abstractmethod
# def if_unmodified_since(self) -> Optional[datetime]:
# """
# Return the ``if-unmodified-since`` header as a timezone aware datetime.
#
# :return: the header's value as a datetime, or ``None`` if the header was not present
# """
#
# @property
# @abstractmethod
# def is_xhr(self) -> bool:
# """
# Return ``True`` if the request was made with XMLHttpRequest, ``False`` otherwise.
#
# This only works if the ``x-requested-with: XMLHttpRequest`` header was set.
# Several popular ECMAScript libraries do this but it is purely voluntary.
# As such, this is not a 100% reliable method of detecting such requests.
# """
#
# @property
# @abstractmethod
# def max_forwards(self) -> Optional[int]:
# """
# Return the ``max_forwards`` header as an integer.
#
# :return: the header's value as an integer, or ``None`` if the header was not present
# """
#
#
# class HTTPResponse(metaclass=ABCMeta):
# """
# Contains response status, headers and other related data and provides convenient shortcuts
# for often needed
#
# Do **NOT** instantiate this class yourself!
#
# :ivar int status: HTTP status code (default = 200)
# :ivar multidict.CIMultiDict headers: response headers
# :ivar str charset: character set to use for encoding a unicode response body (default =
# utf-8)
# :ivar str content_type: content type to set on the response (default = determine from the
# return value)
# """
#
# __slots__ = ()
#
# @abstractmethod
# def set_header(self, name: str, value: str, **params) -> None:
# """
# Set the value of a header, overwriting any previous value.
#
# :param name: name of the header
# :param value: value of the header
# :param params: any parameters appended to the value (e.g. ``; key=value``)
# """
#
# @abstractmethod
# def add_header(self, name: str, value: str, **params) -> None:
# """
# Add a header to the response.
#
# If the header does not exist, this method works identically to :meth:`set_header`.
# If, however, the header already exists in the response, it will have multiple values
# (the header is emitted once for every value added).
#
# :param name: name of the header
# :param value: value of the header
# :param params: any parameters appended to the value (e.g. ``; key=value``)
# """
#
# @abstractmethod
# def set_cookie(self, name: str, value, *, domain: str = None, path: str = None,
# max_age: Union[int, timedelta] = None, expires: datetime = None,
# secure: bool = False, httponly: bool = False) -> None:
# """
# Set a cookie in the response headers.
#
# :param name: name of the cookie
# :param value: value for the cookie (converted to string if it's not one already)
# :param domain: the domain the cookie applies to
# :param path: the path the cookie applies to
# :param max_age: maximum age of this cookie (in seconds or as a timedelta)
# :param expires: expiration date of the cookie (must be timezone aware)
# :param secure: ``True`` if the cookie should only be sent across secure (HTTPS)
# connections
# :param httponly: ``True`` if the cookie should not be accessible from client-side scripts
# """
#
# @abstractmethod
# def expire_cookie(self, name: str, *, domain: str = None, path: str = None):
# """
# Set the expiration date of a cookie to 1970-01-01, forcing the client to discard it.
#
# Shortcut for::
#
# ctx.response.set_cookie(NAME, '', domain=DOMAIN, path=PATH, \
# expires=datetime(1970, 1, 1))
#
# :param name: name of the cookie
# :param domain: the domain the cookie applies to
# :param path: the path the cookie applies to
# """
#
# @abstractmethod
# def send_file(self, path: Union[Path, str], *, as_attachment: bool = True) -> Path:
# """
# Send a file to the client using the best available method.
#
# Shortcut for::
#
# ctx.response.set_header('content-disposition', 'attachment')
# return Path(PATH)
#
# :param path: absolute filesystem path to the file
# :param as_attachment: ``True`` to have the web browser prompt the user for an action
# regarding the file instead of attempting to display its contents in the browser
# window
#
# """


class AbstractEndpoint(metaclass=ABCMeta):
"""
The low-level request handler interface.
Expand Down
3 changes: 2 additions & 1 deletion asphalt/web/context.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import datetime, timedelta
from email.utils import quote
from numbers import Number
from pathlib import Path
from typing import Dict, Any, Optional, Union
Expand All @@ -9,7 +10,7 @@
from asphalt.serialization.api import Serializer
from asphalt.templating.api import TemplateRenderer
from asphalt.web.request import HTTPRequest
from asphalt.web.response import HTTPResponse
from asphalt.web.response import HTTPResponse, UNIX_EPOCH
from asphalt.web.utils import encode_header_value


Expand Down
2 changes: 1 addition & 1 deletion asphalt/web/router.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
from collections import namedtuple
from functools import lru_cache
from typing import List, Dict, Iterable, Optional, Callable, Union, Tuple, Pattern # noqa
from typing import List, Dict, Iterable, Optional, Callable, Union, Pattern # noqa

from typeguard import check_argument_types

Expand Down
3 changes: 1 addition & 2 deletions asphalt/web/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typeguard import check_argument_types

from asphalt.web.request import HTTPRequest
from asphalt.web.exception import HTTPMethodNotAllowed
from asphalt.web.exceptions import HTTPMethodNotAllowed


class StaticFileEndpoint(AbstractEndpoint):
Expand All @@ -30,4 +30,3 @@ def __init__(self, basedir: Union[str, Path]):
def resolve(self, request: HTTPRequest, path: PurePath) -> Optional[AbstractEndpoint]:
final_path = cast(Path, self.basedir / path)
return StaticFileEndpoint(final_path) if final_path.is_file() else None

0 comments on commit 2b5dd69

Please sign in to comment.