Web¶
Request¶
-
class
dragonfly.request.
Request
(environ)¶ Bases:
object
The request object is a class representation of the WSGI environ dictionary
-
get_data
()¶ Gets any from data/query strings from the given request
Returns: A dictionary containing the given data Return type: dict
-
update_environ
(new_environ)¶ Updates the request object (singleton) with new data
Parameters: new_environ (dict) – The new environ dictionary
-
Response¶
-
class
dragonfly.response.
Response
(content='', content_type='text/html', status_code=200, reason_phrase=None)¶ Bases:
object
The base
Response
class that is readable by the WSGI server.Parameters: - content (str) – The content that will be delivered to the user. This defaults to empty.
- content_type (str) – The MIME type. This defaults to ‘text/html’.
- status_code (int) – The HTTP status code. This defaults to success (200).
- reason_phrase (int) – A written meaning of the HTTP status code. If left as None the reason phrase will be chosen from a pre-determined list.
-
header
(field_name, field_value)¶ Updates an existing header or creates a new one.
Parameters: - field_name (str) – The header field name.
- field_value (str) – The header field value.
-
set_content
()¶ Converts the given content to bytes.
-
set_status
(status_code, reason_phrase)¶ Sets the status of the
Response
object. If thereason_phrase
isNone
then a reason phrase that corresponds to the status code will be retrieved from aconstants
file.Parameters: - status_code (int) – The status code of the response.
- reason_phrase (str) – The reason phrase to accompany the status code. This can be None.
-
translate_deferred
(deferred)¶ Merges the given
DeferredResponse
object to thisResponse
instance.Parameters: deferred ( DeferredResponse
) – TheDeferredResponse
object.
ErrorResponse¶
-
class
dragonfly.response.
ErrorResponse
(error_message, status_code)¶ Bases:
dragonfly.response.Response
A
Response
object that returns an error page.Parameters: - error_message (str) – The error message.
- status_code (int) – The status code.
DeferredResponse¶
-
class
dragonfly.response.
DeferredResponse
¶ Bases:
object
Allows headers for a future response to be set before it exists.
This singleton enables attributes of any
Response
object returned in the normal fashion, i.e through thedispatch_route
method, to be set before it exists. The primary use of this class would be in the before method of a middleware.
Auth¶
-
class
dragonfly.auth.
Auth
¶ Bases:
object
Provides a way to interact with the currently authenticated user.
-
static
get
(key, model=False)¶ Retrieve any keys stored in the
Sessions
table associated with the currentsession_id
Parameters: - key – The key of the value to retrieve
- model – If the entire model should be returned or the individual key value pair
Type: str
Type: bool
Returns: The model or value
-
static
set
(key, value, force=False)¶ Set a key value pair in the
Sessions
tableParameters: - key – The key
- value – The value
- force – If the sessions table should be forced to update the value
Type: str
Type: bool
-
static
user
()¶ Get the currently logged in user using the
session_id
stored in the cookies. It should be very unlikely that two sessions with the same ID existReturns: The currently logged in user. Type: User
-
static