Falcon Documentation

Add to My manuals
70 Pages

advertisement

Falcon Documentation | Manualzz

Falcon Documentation, Release 0.2.0rc1

falcon.util.to_query_str( params)

Converts a dictionary of params to a query string.

Parameters params ( dict ) – A dictionary of parameters, where each key is a parameter name, and each value is either a str or something that can be converted into a str. If params is a list , it will be converted to a comma-delimited string of values (e.g., ‘thing=1,2,3’)

Returns

A URI query string including the ‘?’ prefix, or an empty string if no params are given (the dict is empty).

Return type str

5.4 Changelogs

5.4.1 Changelog for Falcon 0.2.0

New

• Since 0.1 we’ve added proper RTD docs to make it easier for everyone to get started with the framework. Over time we will continue adding content, and we would love your help!

• Falcon now supports “wsgi.filewrapper”. You can assign any file-like object to resp.stream and Falcon will use

“wsgi.filewrapper” to more efficiently pipe the data to the WSGI server.

• Support was added for automatically parsing requests containing “application/x-www-form-urlencoded” content. Form fields are now folded into req.params.

• Custom Request and Response classes are now supported. You can specify custom types when instantiating falcon.API.

• A new middleware feature was added to the framework. Middleware deprecates global hooks, and we encourage everyone to migrate as soon as possible.

• A general-purpose dict attribute was added to Request. Middleware, hooks, and responders can now use req.context to share contextual information about the current request.

• A new method, append_header, was added to falcon.API to allow setting multiple values for the same header using comma separation. Note that this will not work for setting cookies, but we plan to address this in the next release (0.3).

• A new “resource” attribute was added to hooks. Old hooks that do not accept this new attribute are shimmed so that they will continue to function. While we have worked hard to minimize the performance impact, we recommend migrating to the new function signature to avoid any overhead.

• Error response bodies now support XML in addition to JSON. In addition, the HTTPError serialization code was refactored to make it easier to implement a custom error serializer.

• A new method, “set_error_serializer” was added to falcon.API. You can use this method to override Falcon’s default HTTPError serializer if you need to support custom media types.

• Falcon’s testing base class, testing.TestBase was improved to facilitate Py3k testing.

Notably, Test-

Base.simulate_request now takes an additional “decode” kwarg that can be used to automatically decode bytestring PEP-3333 response bodies.

• An “add_link” method was added to the Response class. Apps can use this method to add one or more Link header values to a response.

60 Chapter 5. Documentation

Falcon Documentation, Release 0.2.0rc1

• Added two new properties, req.host and req.subdomain, to make it easier to get at the hostname info in the request.

• Allow a wider variety of characters to be used in query string params.

• Internal APIs have been refactored to allow overriding the default routing mechanism. Further modularization is planned for the next release (0.3).

• Changed req.get_param so that it behaves the same whether a list was specified in the query string using the

HTML form style (in which each element is listed in a separate ‘key=val’ field) or in the more compact API style

(in which each element is comma-separated and assigned to a single param instance, as in ‘key=val1,val2,val3’)

• Added a convenience method, set_stream(...), to the Response class for setting the stream and its length at the same time, which should help people not forget to set both (and save a few keystrokes along the way).

• Added several new error classes, including HTTPRequestEntityTooLarge, HTTPInvalidParam, HTTPMissing-

Param, HTTPInvalidHeader and HTTPMissingHeader.

• Python 3.4 is now fully supported.

• Various minor performance improvements

Breaking Changes

• The deprecated util.misc.percent_escape and util.misc.percent_unescape functions were removed. Please use the functions in the util.uri module instead.

• The deprecated function, API.set_default_route, was removed. Please use sinks instead.

• HTTPRangeNotSatisfiable no longer accepts a media_type parameter.

• When using the comma-delimited list convention, req.get_param_as_list(...) will no longer insert placeholders, using the None type, for empty elements. For example, where previously the query string “foo=1„3” would result in [‘1’, None, ‘3’], it will now result in [‘1’, ‘3’].

Fixed

• Ensure 100% test coverage and fix any bugs identified in the process.

• Fix not recognizing the “bytes=” prefix in Range headers.

• Make HTTPNotFound and HTTPMethodNotAllowed fully compliant, according to RFC 7231.

• Fixed the default on_options responder causing a Cython type error.

• URI template strings can now be of type unicode under Python 2.

• When SCRIPT_NAME is not present in the WSGI environ, return an empty string for the req.app property.

• Global “after” hooks will now be executed even when a responder raises an error.

• Fixed several minor issues regarding testing.create_environ(...)

• Work around a wsgiref quirk, where if no content-length header is submitted by the client, wsgiref will set the value of that header to an empty string in the WSGI environ.

• Resolved an issue causing several source files to not be Cythonized.

• Docstrings have been edited for clarity and correctness.

5.4. Changelogs 61

Falcon Documentation, Release 0.2.0rc1

62 Chapter 5. Documentation

f falcon

,

54

falcon.routing

,

54

falcon.testing

,

58

falcon.util

,

59

falcon.util.uri

,

55

Python Module Index

63

Falcon Documentation, Release 0.2.0rc1

64 Python Module Index

Index

A accept (Request attribute),

37

add_error_handler() (falcon.API method),

33

add_link() (falcon.Response method),

42

add_route() (falcon.API method),

34

add_sink() (falcon.API method),

34

after() (in module falcon),

54

API (class in falcon),

32

api (falcon.util.uri.TestBase attribute),

57

app (Request attribute),

36

append_header() (falcon.Response method),

43

auth (Request attribute),

37

D data (Response attribute),

42

date (Request attribute),

37

decode() (in module falcon.util.uri),

55

deprecated() (in module falcon.util),

59

description (HTTPError attribute),

46

dt_to_http() (in module falcon.util),

59

E encode() (in module falcon.util.uri),

55

encode_value() (in module falcon.util.uri),

55

env (Request attribute),

36

etag (falcon.Response attribute),

43

expect (Request attribute),

37

B before() (in module falcon),

54

body (Response attribute),

41

body_encoded (Response attribute),

41

C cache_control (falcon.Response attribute),

43

call_count (falcon.util.uri.StartResponseMock attribute),

58

called (falcon.util.uri.TestResource attribute),

58

client_accepts() (falcon.Request method),

38

client_accepts_json (Request attribute),

37

client_accepts_msgpack (Request attribute),

37

client_accepts_xml (Request attribute),

37

client_prefers() (falcon.Request method),

38

code (HTTPError attribute),

47

compile_uri_template() (in module falcon.routing),

54

content_length (Request attribute),

37

content_location (falcon.Response attribute),

43

content_range (falcon.Response attribute),

43

content_type (falcon.Response attribute),

43

content_type (Request attribute),

37

context (Request attribute),

36

context_type (Request attribute),

36

create_environ() (in module falcon.testing),

58

create_http_method_map() (in module falcon.routing),

54

F falcon (module),

48 ,

54

falcon.routing (module),

54

falcon.testing (module),

58

falcon.util (module),

59

falcon.util.uri (module),

55

G get_header() (falcon.Request method),

38

get_param() (falcon.Request method),

39

get_param_as_bool() (falcon.Request method),

39

get_param_as_int() (falcon.Request method),

40

get_param_as_list() (falcon.Request method),

40

H has_representation (HTTPError attribute),

46

headers (falcon.util.uri.StartResponseMock attribute),

58

headers (HTTPError attribute),

46

headers (Request attribute),

38

headers_dict (falcon.util.uri.StartResponseMock

attribute),

58

host (Request attribute),

36

http_date_to_dt() (in module falcon.util),

59

HTTPBadGateway,

51

HTTPBadRequest,

48

65

Falcon Documentation, Release 0.2.0rc1

HTTPConflict,

50

HTTPError (class in falcon),

46

HTTPForbidden,

49

HTTPInternalServerError,

51

HTTPInvalidHeader,

48

HTTPInvalidParam,

48

HTTPLengthRequired,

50

HTTPMethodNotAllowed,

49

HTTPMissingHeader,

48

HTTPMissingParam,

48

HTTPNotAcceptable,

49

HTTPNotFound,

49

httpnow() (in module falcon.testing),

58

HTTPPreconditionFailed,

50

HTTPRangeNotSatisfiable,

51

HTTPServiceUnavailable,

51

HTTPUnauthorized,

49

HTTPUnsupportedMediaType,

50

I if_match (Request attribute),

37

if_modified_since (Request attribute),

38

if_none_match (Request attribute),

38

if_range (Request attribute),

38

if_unmodified_since (Request attribute),

38

K keep_blank_qs_values (RequestOptions attribute),

35

kwargs (falcon.util.uri.TestResource attribute),

58

L last_modified (falcon.Response attribute),

44

link (HTTPError attribute),

46

location (falcon.Response attribute),

44

log_error() (falcon.Request method),

41

M method (Request attribute),

36

N

NoRepresentation (class in falcon.http_error),

47

O on_get() (falcon.testing.TestResource method),

58

options (Request attribute),

38

P params (Request attribute),

38

parse_host() (in module falcon.util.uri),

56

parse_query_string() (in module falcon.util.uri),

56

path (Request attribute),

37

protocol (Request attribute),

36

66

Q query_string (Request attribute),

37

R rand_string() (in module falcon.testing),

58

range (Request attribute),

37

relative_uri (Request attribute),

36

req (falcon.util.uri.TestResource attribute),

58

req_options (API attribute),

33

Request (class in falcon),

36

RequestOptions (class in falcon),

35

resp (falcon.util.uri.TestResource attribute),

58

resp_headers (falcon.util.uri.TestResource attribute),

57

Response (class in falcon),

41

retry_after (falcon.Response attribute),

44

S sample_body (falcon.util.uri.TestResource attribute),

57

sample_status (falcon.util.uri.TestResource attribute),

57

set_error_serializer() (falcon.API method),

35

set_header() (falcon.Response method),

44

set_headers() (falcon.Response method),

44

set_stream() (falcon.Response method),

44

setUp() (falcon.testing.TestBase method),

57

simulate_request() (falcon.testing.TestBase method),

57

srmock (falcon.util.uri.TestBase attribute),

57

StartResponseMock (class in falcon.testing),

58

status (falcon.util.uri.StartResponseMock attribute),

58

status (HTTPError attribute),

46

status (Response attribute),

41

stream (Request attribute),

37

stream (Response attribute),

42

stream_len (Response attribute),

42

subdomain (Request attribute),

36

T tearDown() (falcon.testing.TestBase method),

57

test_route (falcon.util.uri.TestBase attribute),

57

TestBase (class in falcon.testing),

57

TestResource (class in falcon.testing),

57

title (HTTPError attribute),

46

to_dict() (falcon.HTTPError method),

47

to_json() (falcon.HTTPError method),

47

to_query_str() (in module falcon.util),

59

to_xml() (falcon.HTTPError method),

47

U uri (Request attribute),

36

url (Request attribute),

36

user_agent (Request attribute),

36

V vary (falcon.Response attribute),

44

Index

advertisement

Related manuals

advertisement