Web utility methods¶
Utility methods for retrieving and manipulating data from Web resources.
A utility class for writing command plugins that make a single HTTP GET request and do something with the response.
Subclasses should define a
urlproperty containing the string
%s, and implement the
reply()method. When the command is invoked,
%sis substituted with the command’s literal argument string, and a deferred request to the resulting URL is made with
reply()as its success callback.
An optional property
arg_typecan be used to indicate the type of argument that your custom command expects. This is used to provide a usage message should no arguments be given; for example, setting
'a search term'sets the usage message to “Please specify a search term.” The default value is
'an argument string'.
Convert HTML entities in a string to their Unicode character equivalents. This method is equivalent to:
Deprecated since version 2.2: Use
Make an HTTP request, and return a Deferred that will yield an httplib2-style
(headers, content)tuple to its callback.
Arguments are as for a request to a typical Twisted Web agent, with the addition of one keyword argument, max_bytes, that specifies the maximum number of bytes to fetch from the desired resource. If no
User-Agentheader is specified, one is added before making the request.
Two custom headers are returned in the response, in addition to any set by the HTTP server:
X-Omni-Locationcontains the final location of the request resource after following all redirects, and
X-Omni-Lengthcontains the original value of the response’s
Content-Lengthheader, which Twisted may overwrite if the actual response exceeds max_bytes in size.
Convert the contents of html to a Unicode string. html can be either a string containing HTML markup, or a Beautiful Soup tag object. If format_output is
True, IRC formatting codes are added to simulate common element styles.