hyper2web package¶
Submodules¶
hyper2web.abstract module¶
This module defines all Abstract Types in the framework. Mainly for Better Organization of Code and For Better IDE Type Inferences
-
class
hyper2web.abstract.
AbstractApp
[source]¶ Bases:
object
This class is the base class of any App classes. The framework provides an App class which implements all methods of this class.
A user can also implement this class if the user find that the App class is insufficient. But, the creator recommends user to extend App class instead of AbstractApp class.
-
class
hyper2web.abstract.
AbstractHTTP
[source]¶ Bases:
object
The HTTP class implements this class.
All methods declared here are async.
-
class
hyper2web.abstract.
AbstractResponse
[source]¶ Bases:
object
A Response should be constructed by the router. The router passes Stream information such as stream id to the Response object and Response object is passed to the end point function for top level users’ use.
The flow control is handled by the HTTP class. Therefore, a send method always ends the response.
All send methods should call HTTP’s send method
-
send
(data: bytes)[source]¶ send this response. :param headers: HTTP headers :param data: Body of the response. Has to be bytes That means, if you want to send some string, you have to convert the string to bytes. The framework does not do type conversion for you. It just fails if incorrect type is passed.
-
hyper2web.app module¶
-
class
hyper2web.app.
App
(address='0.0.0.0', port=5000, root='./public', auto_serve_static_file=True, default_file='index.html', router=<class 'hyper2web.router.Router'>)[source]¶ Bases:
hyper2web.abstract.AbstractApp
This class is the main class which users should be interact with.
This is the only class which users should construct.
-
get
(route: str, handler)[source]¶ Register a GET handler.
Parameters: - route – A string which represent a RESTful route with optional parameters
- handler – A handler function. Has to be async.
-
-
hyper2web.app.
default_get
(app)[source]¶ This function is the default handler for GET request whose :path is registered in the router.
To be more clear, a user does not have to register GET /index.html or GET /any_static_file.xxx. Any :path which is not found in the router will initiate this method.
This method treats all requests as a GET /static_file. If :path is not a existing file path, it returns status code 404.
Users should not use this function.
hyper2web.cli module¶
hyper2web.exceptions module¶
Exceptions in hyper2web
hyper2web.http module¶
This module implements HTTP methods for end user
I currently think that they should be synchronized since they should not do IO Where as endpoint module is designed for IO
-
class
hyper2web.http.
HTTP
(app: hyper2web.abstract.AbstractApp, sock, connection: h2.connection.H2Connection)[source]¶ Bases:
hyper2web.abstract.AbstractHTTP
This class further implements complete HTTP2 on top of h2
-
data_received
(event: h2.events.DataReceived)[source]¶ Handle received data for a certain stream. Currently used for POST
-
send
(stream_id: int, headers, data: bytes = None)[source]¶ send the response to the client :param stream_id: the stream id associated with this request/response :param headers: HTTP headers. a sequence(tuple/list) of tuples
- ((‘:status’, ‘200’),
- (‘content-length’, ‘0’), (‘server’, ‘hyper2web’))
Parameters: data – HTTP response body. Has to be bytes(binary data). It’s users’ responsibility to encode any kinds of data to binary.
-
-
class
hyper2web.http.
Stream
(stream_id: int, headers: dict)[source]¶ Bases:
object
As the code is right now, many stream implementation is done in endpoint.EndPointHandler Am moving those functionality to this class
The current design is that application will only return complete stream to top level api But, since a user might also want to program on a live stream. For example, the client may send a giant file 1GB, the user will want to write this stream to disk in real time Also, buffering 1GB in memory is kind of stupid.
But nonethelss, the current focus is on better organization of code instead of more API or performace.
hyper2web.router module¶
-
class
hyper2web.router.
Router
(default_get)[source]¶ Bases:
hyper2web.abstract.AbstractRouter
User should never construct Router
hyper2web.server module¶
A fully-functional HTTP/2 server written for curio.
Requires Python 3.5+.