Z Documentation Release 2 Bart Thate July 06, 2014
Contents 1 DOCS 3 1.1 README................................................ 3 1.2 License.................................................. 3 2 PLUGINS 5 2.1 rext.plugs.add module.......................................... 5 2.2 rext.plugs.all module........................................... 5 2.3 rext.plugs.api module.......................................... 5 2.4 rext.plugs.cfg module.......................................... 6 2.5 rext.plugs.dump module......................................... 6 2.6 rext.plugs.find module.......................................... 6 2.7 rext.plugs.first module.......................................... 6 2.8 rext.plugs.init module.......................................... 7 2.9 rext.plugs.irc module........................................... 7 2.10 rext.plugs.join module.......................................... 7 2.11 rext.plugs.last module.......................................... 7 2.12 rext.plugs.ls module........................................... 7 2.13 rext.plugs.mbox module......................................... 7 2.14 rext.plugs.rm module........................................... 7 2.15 rext.plugs.rss module........................................... 8 2.16 rext.plugs.slice module.......................................... 8 2.17 rext.plugs.spider module......................................... 8 2.18 rext.plugs.status module......................................... 8 2.19 rext.plugs.test module.......................................... 8 2.20 rext.plugs.timer module......................................... 8 2.21 rext.plugs.udp module.......................................... 9 2.22 rext.plugs.version module........................................ 9 2.23 rext.plugs.wiki module.......................................... 9 2.24 rext.plugs.xmpp module......................................... 9 3 PACKAGE 11 3.1 rext package............................................... 11 Python Module Index 27 i
ii
Welcome to Rext! XMPP, IRC, CLI, UDP. source: http://pikacode.com/bthate/rext contact: bthate@dds.nl Contents 1
2 Contents
CHAPTER 1 DOCS 1.1 README judge not 1.2 License Copyright (c) 2014, B.H.J Thate Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software ), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: As the creator of this piece of software, Bart Thate, i disclaim all rights on the code contained in this software package. Therefore this software is free of all claims on it. This program is a given, therefore no one can be able to put it under any restriction, limitations or bounds. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PAR- TICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFT- WARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 3
4 Chapter 1. DOCS
CHAPTER 2 PLUGINS 2.1 rext.plugs.add module add a value. do_add(event) 2.2 rext.plugs.all module do_all(event) 2.3 rext.plugs.api module Object Copy API. class APIHandler(request, client_address, server) Bases: http.server.basehttprequesthandler timeserver request handler class do_delete(zelf ) handle a REST request. do_get(zelf ) handle a REST request. do_post(zelf ) handle a REST request. do_put(zelf ) handle a REST request. handle_request(zelf ) handle a REST request. log_request(zelf, code) log the request setup(zelf ) called on each incoming request. 5
write_header(zelf, type= text/plain ) write headers to the client. class APIServer(zelf, *args, **kwargs) Bases: http.server.httpserver, rext.object API server allow_reuse_address = True daemon_thread = True exit(zelf ) shutdown the API server. handle_error(zelf, request, addr) log the error serve(zelf ) serving loozelf. start(zelf, *args, **kwargs) api_all(handler, request) api_favicon(handler, request) api_get(handler, request) api_home(handler, request) api_show(handler, request) init(*args, **kwargs) 2.4 rext.plugs.cfg module cfg edit. do_cfg(event) 2.5 rext.plugs.dump module do_dump(event) 2.6 rext.plugs.find module do_find(event) 2.7 rext.plugs.first module the difference. do_first(event) 6 Chapter 2. PLUGINS
2.8 rext.plugs.init module run plugins initialization code. do_init(event) 2.9 rext.plugs.irc module start various ps. init(*args, **kwargs) start_irc(cfg) 2.10 rext.plugs.join module join etc. do_join(event) 2.11 rext.plugs.last module the difference. do_last(event) 2.12 rext.plugs.ls module list kernel attributes. do_list(event) 2.13 rext.plugs.mbox module mailbox input plugin. do_mbox(event) 2.14 rext.plugs.rm module remove. do_remove(event) 2.8. rext.plugs.init module 7
2.15 rext.plugs.rss module rss module. class RSS(zelf, time_sleep, *args, **kwargs) Bases: rext.object display(zelf, *args, **kwargs) do_run(zelf, *args, **kwargs) look(zelf, *args, **kwargs) start(zelf, *args, **kwargs) init(*args, **kwargs) 2.16 rext.plugs.slice module do_slice(event) 2.17 rext.plugs.spider module poller module. class Spider(zelf, time_sleep, *args, **kwargs) Bases: rext.object crawl(zelf, *args, **kwargs) do_spider(event) 2.18 rext.plugs.status module check the status of an object. do_status(event) 2.19 rext.plugs.test module test plugin. do_test(event) do_testwait(event) 2.20 rext.plugs.timer module time the timing. 8 Chapter 2. PLUGINS
class Timer(zelf, time_sleep, event, *args, **kwargs) Bases: rext.object do_run(zelf, *args, **kwargs) echo(zelf, *args, **kwargs) do_timer(event) 2.21 rext.plugs.udp module relay txt through a udp port listener. class UDP(zelf, *args, **kwargs) Bases: rext.object output(zelf, input, addr) init(*args, **kwargs) 2.22 rext.plugs.version module do_version(event) 2.23 rext.plugs.wiki module query wikipedia. do_wiki(event) 2.24 rext.plugs.xmpp module xmpp related stuff. init(*args, **kwargs) start_xmpp(cfg) 2.21. rext.plugs.udp module 9
10 Chapter 2. PLUGINS
CHAPTER 3 PACKAGE 3.1 rext package 3.1.1 Subpackages rext.contrib package Submodules rext.contrib.feedparser module Universal feed parser Handles RSS 0.9x, RSS 1.0, RSS 2.0, CDF, Atom 0.3, and Atom 1.0 feeds Visit https://code.google.com/p/feedparser/ for the latest version Visit http://packages.python.org/feedparser/ for the latest documentation Required: Python 2.4 or later Recommended: iconv_codec <http://cjkpython.i18n.org/> exception CharacterEncodingOverride Bases: rext.contrib.feedparser.thingsnobodycaresaboutbutme exception CharacterEncodingUnknown Bases: rext.contrib.feedparser.thingsnobodycaresaboutbutme class FeedParserDict Bases: builtins.dict get(key, default=none) has_key(key) keymap = { items : entries, date : updated, date_parsed : updated_parsed, issued : published, tagline : subtitle setdefault(key, value) exception NonXMLContentType Bases: rext.contrib.feedparser.thingsnobodycaresaboutbutme exception ThingsNobodyCaresAboutButMe Bases: builtins.exception exception UndeclaredNamespace Bases: builtins.exception 11
parse(url_file_stream_or_string, etag=none, modified=none, agent=none, referrer=none, handlers=none, request_headers=none, response_headers=none) Parse a feed from a URL, file, stream, or string. request_headers, if given, is a dict from http header name to value to add to the request; this overrides internally generated values. registerdatehandler(func) Register a date handler function (takes string, returns 9-tuple date in GMT) class sgmllib Bases: builtins.object class SGMLParser Bases: builtins.object goahead(i) parse_starttag(i) rext.contrib.rijndael module To include - from rijndael import rijndael To do a key setup - r = rijndael(key, block_size = 16) A pure python (slow) implementation of rijndael with a decent interface key must be a string of length 16, 24, or 32 blocksize must be 16, 24, or 32. Default is 16 To use - ciphertext = r.encrypt(plaintext) plaintext = r.decrypt(ciphertext) If any strings are of the wrong length a ValueError is thrown decrypt(key, block) encrypt(key, block) class rijndael(key, block_size=16) Bases: builtins.object test() decrypt(ciphertext) encrypt(plaintext) Module contents rext.plugs package Submodules rext.plugs.add module do_add(event) add a value. 12 Chapter 3. PACKAGE
rext.plugs.all module do_all(event) rext.plugs.api module Object Copy API. class APIHandler(request, client_address, server) Bases: http.server.basehttprequesthandler timeserver request handler class do_delete(zelf ) handle a REST request. do_get(zelf ) handle a REST request. do_post(zelf ) handle a REST request. do_put(zelf ) handle a REST request. handle_request(zelf ) handle a REST request. log_request(zelf, code) log the request setup(zelf ) called on each incoming request. write_header(zelf, type= text/plain ) write headers to the client. class APIServer(zelf, *args, **kwargs) Bases: http.server.httpserver, rext.object API server allow_reuse_address = True daemon_thread = True exit(zelf ) shutdown the API server. handle_error(zelf, request, addr) log the error serve(zelf ) serving loozelf. start(zelf, *args, **kwargs) api_all(handler, request) api_favicon(handler, request) api_get(handler, request) api_home(handler, request) api_show(handler, request) init(*args, **kwargs) 3.1. rext package 13
rext.plugs.cfg module do_cfg(event) cfg edit. rext.plugs.dump module do_dump(event) rext.plugs.find module do_find(event) rext.plugs.first module do_first(event) the difference. rext.plugs.init module do_init(event) run plugins initialization code. rext.plugs.irc module start various ps. init(*args, **kwargs) start_irc(cfg) rext.plugs.join module do_join(event) join etc. rext.plugs.last module do_last(event) the difference. rext.plugs.ls module do_list(event) list kernel attributes. rext.plugs.mbox module do_mbox(event) mailbox input plugin. rext.plugs.rm module do_remove(event) remove. rext.plugs.rss module rss module. class RSS(zelf, time_sleep, *args, **kwargs) Bases: rext.object display(zelf, *args, **kwargs) do_run(zelf, *args, **kwargs) look(zelf, *args, **kwargs) 14 Chapter 3. PACKAGE
start(zelf, *args, **kwargs) init(*args, **kwargs) rext.plugs.slice module do_slice(event) rext.plugs.spider module poller module. class Spider(zelf, time_sleep, *args, **kwargs) Bases: rext.object crawl(zelf, *args, **kwargs) do_spider(event) rext.plugs.status module do_status(event) check the status of an object. rext.plugs.test module do_test(event) do_testwait(event) test plugin. rext.plugs.timer module time the timing. class Timer(zelf, time_sleep, event, *args, **kwargs) Bases: rext.object do_run(zelf, *args, **kwargs) echo(zelf, *args, **kwargs) do_timer(event) rext.plugs.udp module class UDP(zelf, *args, **kwargs) Bases: rext.object output(zelf, input, addr) init(*args, **kwargs) relay txt through a udp port listener. rext.plugs.version module do_version(event) rext.plugs.wiki module do_wiki(event) query wikipedia. 3.1. rext package 15
rext.plugs.xmpp module init(*args, **kwargs) start_xmpp(cfg) xmpp related stuff. Module contents 3.1.2 Submodules rext.completer module completer stuff. class TheCompleter(options) Bases: rlcompleter.completer complete(text, state) rext.defines module defines. rext.log module provide logging infrastructure. class Filter(name= ) Bases: logging.filter filter(zelf, record) class Formatter(fmt=None, datefmt=none, style= % ) Bases: logging.formatter hooks into the logging system. format(zelf, record) cfg_log(loglevel) return a properly configured logger. rext.test module define core test classes. class Test(zelf, *args, **kwargs) Bases: unittest.case.testcase class that implements setup and teardow of tests. 16 Chapter 3. PACKAGE
rext.utils module utils package. a_time(daystr) aj(sep=none, *args) b_time(obj) check_permissions(ddir, dirmask=448, filemask=384) day() decode_char(txt, encoding= utf-8, what= ) dispatch(target, event, cmnd, *args, **kwargs) dj(*args) do_sed(filename, sedstring) replace oldbot strings with the new one. do_url(type, url, myheaders={}, postdata={}, keyfile=none, certfile=, port=80) dtime(stamp) enc_char(s) enc_name(input) enc_needed(s) error(*args, **kwargs) feed(text) format(*args, **kwargs) from_enc(txt, encoding= utf-8, what= ) get_clsname(obj) get_encoding(data) get_exception(*args, **kwargs) get_frame(search= code ) get_func(*args, **kwargs) get_funcname(func) get_highest(target, file_name) determine new file extension. get_how(*args, **kwargs) get_name(obj) get_plugname(*args, **kwargs) get_source(mod, package) get_status(target) get_strace(*args, **kwargs) get_urls(data) 3.1. rext package 17
hello(name= ) hms() intersect(a, b) class istr Bases: builtins.str j(*args) list_eggs(filter= ) list_files(*args, **kwargs) loop(*args, **kwargs) make_dir(path) make_opts(options) make_signature(data) make_time(daystr) make_version(name= ) mj(*args) need_redirect(resp) need_skip(obj, black=[], white=[]) nr_days(seconds) parse(txt) parse_email(fn) parse_url(*args, **kwargs) Attribute Index Value Value if not present scheme 0 URL scheme specifier empty string netloc 1 Network location part empty string path 2 Hierarchical path empty string query 3 Query component empty string fragment 4 Fragment identifier empty string parse_urls(*args, **kwargs) ptime(daystr) reduced_keys(*args, **kwargs) resolve(*args, **kwargs) resolve_host(ip=none, timeout=1.0) resolve_ip(hostname=none, timeout=1.0) rtime() short_date(*args, **kwargs) show_eggs(filter= rext ) smooth(a) split_txt(what, l=375) str_day(seconds) strip_html(text) 18 Chapter 3. PACKAGE
strip_wiki(text) stripbadchar(s) stripped(input) strtotime(what) convert string to time. tdiff(d1, d2) time_stamp(*args, **kwargs) time_string(*args, **kwargs) time_time(*args, **kwargs) to_enc(what, encoding= utf-8 ) today() return time of 0:00 today. touch(fname) txt_parse(txt) unescape(text) union(a, b) unique(a) useragent() verify_signature(data, signature) 3.1.3 Module contents Basic package for the Rext program. Defines all the basic Objects and functionality. class Bot(zelf, *args, **kwargs) Bases: rext.dispatcher Base Bot class. announce(zelf, *args, **kwargs) begin(zelf, *args, **kwargs) connect(zelf, *args, **kwargs) do_one(zelf, *args, **kwargs) exit(zelf, *args, **kwargs) get_prompt(zelf, *args, **kwargs) join_channels(zelf, *args, **kwargs) set_cfg(zelf, *args, **kwargs) class ConsoleBot(zelf, *args, **kwargs) Bases: rext.bot boot(zelf, *args, **kwargs) 3.1. rext package 19
do_one(zelf, *args, **kwargs) get_prompt(zelf, *args, **kwargs) say(zelf, *args, **kwargs) class Dispatcher(zelf, *args, **kwargs) Bases: rext.object The Dispatcher is the object to delegate the workload to the Runners. Runners get instantiated when needed. cleanup(zelf, dojoin=false) Remove idle Runners. dispatch(zelf, *args, **kwargs) dispatch an event (object) onto a runner if matching command is found. do_func(zelf, *args, **kwargs) Execute command/event pair if command is registered. execute(zelf, *args, **kwargs) Execute a command, event pair. If the threaded attribute is set, dispatch to a Runner. exit(zelf, name=none) Stop the Runners running in this Dispatcher. is_alive(zelf, *args, **kwargs) Check whether there are any Runners running. make_new(zelf, *args, **kwargs) Create a Runner, try for idle Runners already available first. put(zelf, *args, **kwargs) Put load to the Runner, create a new Runner if necessary. register(zelf, *args, **kwargs) register a callback type with corresponding callback function. exception Error Bases: builtins.baseexception Basic Exception used in the Rext program. exception FileNotFoundError Bases: rext.error Exception thrown when file is not found. class IRCBot(zelf, *args, **kwargs) Bases: rext.bot action(zelf, printto, what, event=none, *args, **kwargs) bind(zelf ) broadcast(zelf, txt) cc =. close(zelf ) connect(zelf, reconnect=true) ctcp(zelf, printto, what) ctcpreply(zelf, printto, what) 20 Chapter 3. PACKAGE
delop(zelf, channel, who) do_one(zelf, *args, **kwargs) donick(zelf, nick, setorig=false, save=false, whois=false) doop(zelf, channel, who) getchannelmode(zelf, channel) handle_366(zelf, *args, **kwargs) handle_433(zelf, event) handle_513(zelf, event) handle_ctcp(zelf, event) handle_invite(zelf, event) handle_notice(zelf, event) handle_ping(zelf, event) handle_privmsg(zelf, event) join(zelf, channel, password=none) join_channels(zelf, *args, **kwargs) logon(zelf ) marker = \r\n names(zelf, channel) notice(zelf, printto, what) part(zelf, channel) ping(zelf, *args, **kwargs) pong(zelf, *args, **kwargs) privmsg(zelf, printto, what) quit(zelf, reason= https://pikacode.com/bthate/z2 ) read_some(zelf, *args, **kwargs) say(zelf, *args, **kwargs) send(zelf, txt) settopic(zelf, channel, txt) voice(zelf, channel, who) who(zelf, who) whois(zelf, who) class Looper(zelf, *args, **kwargs) Bases: rext.object A Looper calls a function every x seconds. func_do(zelf, *args, **kwargs) start(zelf, *args, **kwargs) 3.1. rext package 21
exception NoJSON Bases: rext.error Exception thrown incase no JSON could be decoded/encoded. exception NoTarget Bases: rext.error Exception thrown incase of missing argument attribute. exception NotSet Bases: rext.error Exception thrown when a attribute is not set. class Object Bases: builtins.dict THE Basic Object on which the rest of the Rext program is based. announce(zelf, *args, **kwargs) announce to all the running bots. check_notwanted(zelf, *args, **kwargs) function to check whether an objects is not desired, first argument is a dict that has the attributes to be matched. check_wanted(zelf, *args, **kwargs) function to check whether an objects is desired, first argument is a dict that has the attributes to be matched. clear(zelf ) clear the object s ready state. define(zelf, *args, **kwargs) set a attribute on this object. dump(zelf, *args, **kwargs) create a JSON string ready to be saved to disk. exec_str(zelf, *args, **kwargs) execute a string as a command. first(zelf, *args, **kwargs) return the first object where the key and/or value matches. get_args(zelf, *args, **kwargs) get the arguments of the txt attribute. get_clean(zelf, *args, **kwargs) return a cloned object, with only the proper keys used. get_cmnd(zelf, *args, **kwargs) determine the command in the zelf.txt attribute, if present. get_days(zelf, *args, **kwargs) get the number of days relative to the objects creation time. get_filetime(zelf, *args, **kwargs) get timestamp related filename. get_keys(zelf, *args, **kwargs) return the keys of this object, skipping the unwanted keys e.g those that start with a _. get_parsed(zelf, *args, **kwargs) parse the txt attribute, so command can be determined. 22 Chapter 3. PACKAGE
get_rest(zelf, *args, **kwargs) get the rest of the txt arguments (words) e.g. minus the first word (the command). get_root(zelf, *args, **kwargs) return the root dir of the Rext program. get_slice(zelf, *args, **kwargs) args: list of keywords to slice the dict. get_timed(zelf, *args, **kwargs) retrieve the creation time of an object. get_url_file(zelf, *args, **kwargs) get the url of the object s file so that it can be retrieved when API server is running. get_url_show(zelf, *args, **kwargs) return url that gives a readable representation of the object s JSON file. last(zelf, *args, **kwargs) return the last object where the key and/or value matches. load(zelf, *args, **kwargs) load a JSON file into this object. make_path(zelf, *args, **kwargs) return workdir path and create the workdir if necessary. make_signature(zelf, sig=none) create a signature of the data contained in this object. obj_iter(zelf, *args, **kwargs) iterate over the pure keys (not starting with _ ). objects(zelf, *args, **kwargs) return a list of all object s in the workdir. pretty(zelf ) return a nice formatted JSON string of this object. read(zelf, *args, **kwargs) read the JSON file from disk. ready(zelf ) signal the object into the ready state. register(zelf, *args, **kwargs) register a value in a list on this object. reply(zelf, *args, **kwargs) send reply to object s origin. save(zelf, *args, **kwargs) save this object s JSON onto disk. say(zelf, *args, **kwargs) output text through the _target attribute (the bot that received the object). selected(zelf, *args, **kwargs) return a list of desired objects, first argument is a dict giving the desired attributes. selector(zelf, *args, **kwargs) boolean function to see if this objects has the desired attributes. 3.1. rext package 23
show(zelf ) return a list of key,value pairs of this object s attributes. sync(zelf, *args, **kwargs) sync this object s JSON to disk. to_full(zelf, *args, **kwargs) return full JSON dump of this object. to_json(zelf, *args, **kwargs) return the JSON string representation of this object. wait(zelf, sec=180.0) wait for the object to be put in a ready state. class Plugins(zelf, *args, **kwargs) Bases: rext.object Object to register Plugins with. do_init(zelf, *args, **kwargs) Call the init function of all plugin or a specific one if argument is given. exit(zelf, *args, **kwargs) close all plugins by calling there shutdown() function. get_names(zelf, plugsdir) Return plugnames from the plugin directory. load_mod(zelf, plugname, pdir=, force=false) load a plugin; s module. load_package(zelf, modname) Load the plugins package. load_plugs(zelf, path) Load plugins from the plugin directory. plug_init(zelf, *args, **kwargs) Initialize a plugin, use the init() function provided in the plugin, if available. plug_shutdown(zelf, plugname) Shutdown a plugin by calling the shutdown() function, if provided. reload(zelf, plugname, force=false) Reload (unload, load) a plugin. exception RemoteDisconnect Bases: rext.error Exception thrown when the connection is disconnected. class Runner(zelf, *args, **kwargs) Bases: threading.thread The working unit of the Rext program, arguments are function, objects pairs pushed to the Runner. exit(zelf, *args, **kwargs) stop the Runner by setting the status to an empty string. put(zelf, *args, **kwargs) put arguments/kwargs to the Runner. class XMPPBot(zelf, *args, **kwargs) Bases: rext.bot 24 Chapter 3. PACKAGE
announce(zelf, *args, **kwargs) connect(zelf ) do_one(zelf, *args, **kwargs) exception(zelf, ex) handle_connected(zelf, *args, **kwargs) handle_disconnected(zelf, *args, **kwargs) handle_failedauth(zelf, error, *args) handle_failure(zelf, ex, *args, **kwargs) handle_message(zelf, data, *args, **kwargs) handle_presence(zelf, data, *args, **kwargs) loop(zelf, *args, **kwargs) say(zelf, *args, **kwargs) session_start(zelf, event) boot(*args, **kwargs) The boot() function is needed to get the Rext program properly initialized. Use it at the beginning of your program. irc_parse(obj, *args, **kwargs) shutdown() The shutdown() function is used to close the Rext program in a apropiate manner. 3.1. rext package 25
26 Chapter 3. PACKAGE
Python Module Index r rext, 19 rext.completer, 16 rext.contrib, 12 rext.contrib.feedparser, 11 rext.contrib.rijndael, 12 rext.defines, 16 rext.log, 16 rext.plugs, 16 rext.plugs.add, 12 rext.plugs.all, 13 rext.plugs.api, 13 rext.plugs.cfg, 14 rext.plugs.dump, 14 rext.plugs.find, 14 rext.plugs.first, 14 rext.plugs.init, 14 rext.plugs.irc, 14 rext.plugs.join, 14 rext.plugs.last, 14 rext.plugs.ls, 14 rext.plugs.mbox, 14 rext.plugs.rm, 14 rext.plugs.rss, 14 rext.plugs.slice, 15 rext.plugs.spider, 15 rext.plugs.status, 15 rext.plugs.test, 15 rext.plugs.timer, 15 rext.plugs.udp, 15 rext.plugs.version, 15 rext.plugs.wiki, 15 rext.plugs.xmpp, 16 rext.test, 16 rext.utils, 17 27