Web utility methods¶
Utility methods for retrieving and manipulating data from Web resources.
-
class
omnipresence.web.WebCommand[source]¶ 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 thereply()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 withreply()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, settingarg_typeto'a search term'sets the usage message to “Please specify a search term.” The default value is'an argument string'.-
reply(response, bot, prefix, reply_target, channel, args)[source]¶ Implement this method in your command subclass. The response argument will contain a
(headers, content)response tuple as returned byrequest(). The other arguments are as passed in toICommand.execute().
-
-
omnipresence.web.decode_html_entities(s)[source]¶ Convert HTML entities in a string to their Unicode character equivalents. This method is equivalent to:
textify_html(s, format_output=False)
Deprecated since version 2.2: Use
textify_html()instead.
-
omnipresence.web.request(*args, **kwargs)[source]¶ 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, andX-Omni-Lengthcontains the original value of the response’sContent-Lengthheader, which Twisted may overwrite if the actual response exceeds max_bytes in size.