Endian banner

endian.core package

Submodules

endian.core.alteration_monitor module

install_altertion_monitor(callback_func, args=None, kwargs=None, frequency=1, match=None, ignore_files=None, debug=False, changed_modules_arg=False)

Install the alteration monitor, which execute a function when monitored python source files change.

Parameters:
  • callback_func (function) – callback function executed when python source files change
  • args (list) – optional function args (default None)
  • kwargs (dict) – optional function kwargs (default None)
  • frequency (int) – The optional interval in seconds at which to poll for modified files (default 1 s)
  • match (string) – An optional regular expression by which to match filenames (default match any file)
  • ignore_files (list) – An optional list of files to be ignored (default empty)
  • debug (boolean) – Enable debug mode
  • changed_modules_arg (boolean) – If true, add the arg ‘changed_modules’ (list of changed modules) when calling the callback function

endian.core.ansi module

sane_tty(fd=None)

Change the terminal line settings to a sane state, like the ‘stty sane’ command

endian.core.cache module

class Cache

Bases: object

get(key)
put(key, value, onExpire=None, onPut=None, onGet=None)
setDirty(key)
exception CacheException

Bases: exceptions.Exception

exception CacheExpiredException

Bases: endian.core.cache.CacheException

exception CacheMissException

Bases: endian.core.cache.CacheException

class CacheObject(value)

Bases: object

expire(quiet=False)
get()
class Expirer

Bases: object

classmethod isValid(obj, key=None)
keys = [<class endian.data.interfaces.ExpireableFile at 0x905cbcc>]
classmethod register(method, cls=None, key=None)
registry = {<class endian.data.interfaces.ExpireableFile at 0x905cbcc>: <function fileExpirer at 0x906f8ec>}
class TimeExpirer(timeout)

Bases: object

Is an expirer which allows to define a timeout of how long the object should be kept in cache.

isExpired(obj)
fsExpirer(fsitem, timestamp)

endian.core.classtools module

class classproperty(fget)

Bases: object

Return a read-only class property attribute for new-style classes (classes that derive from object).

Parameters:fget (function) – fget is a function for getting an attribute value

It possible to create read-only class properties easily using property() as a decorator:

class Angle(object):

    @classproperty
    def max(cls):
        return 90

print Angle.max

endian.core.commands module

register(command, func)

Register a command (or a status) based on a command name command (Example ‘module.command’)

lookup(command)

Lookup a command in the command registry

getRegistry(flat=False, root_node=None)

Return the global commmand registry

Parameters:
  • flat (boolean) – If true, return the registry as a ‘flat’ dictionary
  • root_node (string) – Root node, e.g. ‘status’ (used for filter the results)
unregister(command)

Unregister a command (or a status) based on a command name command (Example ‘module.command’)

registerCommand(command, func)

Register a command (or a status) based on a command name command (Example ‘module.command’)

lookupCommand(command)

Lookup a command in the command registry

getCommandRegistry(flat=False, root_node=None)

Return the global commmand registry

Parameters:
  • flat (boolean) – If true, return the registry as a ‘flat’ dictionary
  • root_node (string) – Root node, e.g. ‘status’ (used for filter the results)
call(cmd, http=False, *argl, **args)

Calls the supplied method ‘method’ and returns the result.

Parameters:http (boolean) – If True, uses the http parser, which gets the options from POST/GET variables. Otherwise uses normal option parser, which reads from sys.stdin
exception HTTPOptionError(msg)

Bases: optparse.OptParseError

exception OptionParserHelpExit(msg)

Bases: optparse.OptParseError

exception OptParseError(msg)

Bases: exceptions.Exception

parseFunctionDoc(func)

Parses the docstring of function ‘func’ and returns a structure containing the relevant items as seen below:

{'summary': 'summary text',
 'description': 'description text',
 'parameters': {
    'parameter1': {
        'description': 'parameter description',
        'type': 'type name'
        }
    }
 }
Parameters:func (function) – The function to parse
Returns:dict with all parsed elements
registerCommandsDict(prefix, command_dict)

Register a dict of commands under a common prefix

has_force_json_output(cmd)

Return true if the output format of the command is forced to JSON.

force_json_output(fn)

Force the JSON output format to an Emi command:

@force_json_output
def login_test(name, password):
     ...

endian.core.countries module

country_from_timezone()
city_from_timezone()

endian.core.cpu module

number_of_cores()

endian.core.csvfile module

class CSVFile(filename=None, obj=None, delimiter=', ', tolerant=False)
get(i)
load()

Loads the CSV file and populates a dictionary with representations of the supplied class containing the read data.

size()
store(filename=None)

Stores the current configuration into a file

If no filename is set then it uses the filename of currently opened file.

exception CSVFileException(value)

Bases: exceptions.Exception

class Test
toclass(meta, cls, row, tolerant)
todict(meta, obj)

endian.core.daemon module

Generic daemon class which implements all generic handling which is necessary to have a daemon work correctly in a linux environment.

class Daemon(name='/usr/bin/sphinx-build')

Bases: object

cleanup()
do(*args, **kwargs)
getOptionParserGroup(title='Custom Daemon Options')
opthandler()
reload()
run(*args, **kwargs)
exception MainLoopExit

Bases: exceptions.SystemExit

Will be thrown if an application decides to reload itself and for this need to exit from its main loop in order to re-instantiate itself.

daemonize(stdoutlog='/dev/null', stderrlog='/dev/null', pidfile=None, cwd='/')

Detach a process from the controlling terminal and run it in the background as a daemon.

registerSignalHandler(sig, callbacks)

register one or more signal handlers for the specified signal ‘sig’.

The Daemon() class installs these handlers after daemonizing and calls every registered handler for the appropriate signal.

endian.core.dictdiff module

diff(a, b)

Compares the both dictionaries a and b and returns a dictionary with the differencies.

The returning dict holds for each key the differencies as a tuple of the value of a and the value of b.

Raises AttributeError if one of both is not a dict.

endian.core.download_file module

get_http_file(url, webuser=None, webpass=None, proxy_settings=None, get_method=None)

Retrieves a http file.

The function will take care of eventual passed authentication parameters(webuser, webpass) or a passed upstream proxy setting.

Parameters:
  • url (String) – The requested url.
  • webuser (String or None) – The username of a http authentication.
  • webpass (String or None) – The password of a http authentication.
  • proxy_settings (dict) – A dict with upstream proxy settings. Must contain: enabled, server and port. May contains: user and password.
Returns:

A file like object, see urllib2.

Return type:

file like object

download_file(url, webuser=None, webpass=None, proxy_settings=None)

Generator to download a file from the internet. The yielded function will return each time a line.

The generator will take care of eventual passed authentication parameters(webuser, webpass) or a passed upstream proxy setting.

Parameters:
  • url (String) – The requested url.
  • webuser (String or None) – The username of a http authentication.
  • webpass (String or None) – The password of a http authentication.
  • proxy_settings (dict) – A dict with upstream proxy settings. Must contain: enabled, server and port. May contains: user and password.
Returns:

The lines of the requested file.

Return type:

String

download_file_to(url, target, webuser=None, webpass=None, proxy_settings=None)

Downloads a url to a local file.

The generator will take care of eventual passed authentication parameters(webuser, webpass) or a passed upstream proxy setting.

Parameters:
  • url (String) – The requested url.
  • target (String) – The location on the fs to store the file.
  • webuser (String or None) – The username of a http authentication.
  • webpass (String or None) – The password of a http authentication.
  • proxy_settings (dict) – A dict with upstream proxy settings. Must contain: enabled, server and port. May contains: user and password.
Returns:

The lines of the requested file.

Return type:

String

endian.core.enumerate_plus module

enumerate_plus(sequence, start=0)

Enhanced version of the enumerate function

Parameters:sequence (must be a sequence, an iterator, or some other object which supports iteration.) – a sequence
Returns:
The next() method of the iterator returned by enumerate_plus()
returns a tuple containing:
  • a count (from start which defaults to 0),
  • a boolean, True if the current item is the first of the sequence
  • a boolean, True if the current item is the last of the sequence
  • the current value in the sequence

endian.core.events module

class EventRegistry

Bases: object

getRegistry()
register(event, description)

Register a new event type that can be used for subscribing functions to trigger

subscribe(event, function, priority=0)

Subscribe a function that will be called on event trigger.

The priority can be used to influence the order in which the functions of an event are called. The default priority “0” means that a function will be called as the first, the functions will be ordered by the priority and name before they’re called.

trigger(event, args=None, detach=False)

The trigger method is used to fire a specific event by calling all the relate functions.

If detach is set to True the functions will be triggered in backgrund using an own thread.

class EventRunner

Bases: threading.Thread

run()
start(args)

endian.core.filetools module

exception NotFoundException

Bases: exceptions.Exception

filterGlob(pattern, filtersuffix, sort=False, reverse=False)

glob.glob() generator with possibility to filter away files by file suffices

:param pattern glob() pattern :type pattern string :param filtersuffix filter away files with these suffices :type filtersuffix list :param sort make the generator sorted :type sort bool :param reverse reverse sort if generator is sorted :type sort bool

openLocking(filename, mode='r', bufsize=0)
searchPath(filename, searchpath=['.', '~', '/etc'], appendSearchPath=None, altname=None, firstFiles=[], method=<function exists at 0xb76ceb1c>)
walkSearchPath(filename, searchpath=['.', '~', '/etc'], appendSearchPath=None, altname=None, firstFiles=[])

endian.core.i18n module

class I18nString(id)

Bases: str

capitalize(*argl, **argd)
center(*argl, **argd)
count(*argl, **argd)
decode(*argl, **argd)
encode(*argl, **argd)
endswith(*argl, **argd)
expandtabs(*argl, **argd)
find(*argl, **argd)
format(*argl, **argd)
index(*argl, **argd)
isalnum(*argl, **argd)
isalpha(*argl, **argd)
isdigit(*argl, **argd)
islower(*argl, **argd)
isspace(*argl, **argd)
istitle(*argl, **argd)
isupper(*argl, **argd)
join(*argl, **argd)
ljust(*argl, **argd)
lower(*argl, **argd)
lstrip(*argl, **argd)
partition(*argl, **argd)
replace(*argl, **argd)
rfind(*argl, **argd)
rindex(*argl, **argd)
rjust(*argl, **argd)
rpartition(*argl, **argd)
rsplit(*argl, **argd)
rstrip(*argl, **argd)
split(*argl, **argd)
splitlines(*argl, **argd)
startswith(*argl, **argd)
strip(*argl, **argd)
swapcase(*argl, **argd)
title(*argl, **argd)
translate(*argl, **argd)
upper(*argl, **argd)
zfill(*argl, **argd)
class I18nUnicode(id)

Bases: str

capitalize(*argl, **argd)
center(*argl, **argd)
count(*argl, **argd)
decode(*argl, **argd)
encode(*argl, **argd)
endswith(*argl, **argd)
expandtabs(*argl, **argd)
find(*argl, **argd)
format(*argl, **argd)
index(*argl, **argd)
isalnum(*argl, **argd)
isalpha(*argl, **argd)
isdigit(*argl, **argd)
islower(*argl, **argd)
isspace(*argl, **argd)
istitle(*argl, **argd)
isupper(*argl, **argd)
join(*argl, **argd)
ljust(*argl, **argd)
lower(*argl, **argd)
lstrip(*argl, **argd)
partition(*argl, **argd)
replace(*argl, **argd)
rfind(*argl, **argd)
rindex(*argl, **argd)
rjust(*argl, **argd)
rpartition(*argl, **argd)
rsplit(*argl, **argd)
rstrip(*argl, **argd)
split(*argl, **argd)
splitlines(*argl, **argd)
startswith(*argl, **argd)
strip(*argl, **argd)
swapcase(*argl, **argd)
title(*argl, **argd)
translate(*argl, **argd)
upper(*argl, **argd)
zfill(*argl, **argd)
class TranslatingString

Bases: type

getTranslationsInstance(language, domain=None)
get_language()
i18nAllMethods(methodname)
registerDomain(domain)
setLanguage()
translate(message, domain=None, locale=None)
translationWrapper(id, *argl, **args)

endian.core.lazylist module

class LazyList(func, *args, **kwargs)

Bases: object

next()
class CachedList(func, *args, **kwargs)

Bases: object

CachedList acts like LazyList, but the function’s result is cached for ‘timeout’ seconds

defaultTimeout = 60
invalidate()

Invalidate the cached result (force reexecuting the function at the next access to the list)

endian.core.led module

write_led(led, content)
led_storage_nand()
led_storage_sd()
led_error()
led_power_on()
led_boot()
led_ok()
led_online()

endian.core.logger module

The endian logger module creates a pre-configured default logger.

Once the logger module will be loaded using

from endian.core.logger import *

the functions debug(), info(), warn(), critical() and error() are defined and can be used without configuration and without instantiation. Those functions use the default logger instance which is stored in ‘’logger’‘.

The default logger automatically use the current program name as log name and logs to both console and syslog handlers.

The default facility for the syslog handler is LOCAL4 and logs through ‘’/dev/log’‘.

Per default all log messages will be forwarded to the handlers. If you would like to change this behaviour, use logger.setLevel() in order to set the minimum log level.

A special log level has been implemented: ‘’DEVELDEBUG’’ Once set, it enables logging of filename:function:lineno of where the log call came from.

Special behaviour:

  • info() and error() use the notification framework in order to communicate with the ajax notification interface.
  • debug() adds the caller-frame to the log-name.
  • syslog handler splits messages containing multiple lines and sends one syslog message per line. Traceback’s captured with exc_info=True will also be splitted in multiple lines.
DEVELDEBUG = 5

DEBUG log level which enables logging of caller filename:function:lineno

class EndianLogRecord(name, level, pathname, lineno, func, msg, args, exc_info)

Bases: logging.LogRecord

A LogRecord instance represents an event being logged.

LogRecord instances are created every time something is logged. They contain all the information pertinent to the event being logged. The main information passed in is in msg and args, which are combined using str(msg) % args to create the message field of the record. The record also includes information such as when the record was created, the source line where the logging call was made, and any exception information to be logged.

class EndianLogger(name, level=0, name_prefix=None)

Bases: logging.Logger

Instances of the Logger class represent a single logging channel. A “logging channel” indicates an area of an application. Exactly how an “area” is defined is up to the application developer. Since an application can have any number of areas, logging channels are identified by a unique string. Application areas can be nested (e.g. an area of “input processing” might include sub-areas “read CSV files”, “read XLS files” and “read Gnumeric files”). To cater for this natural nesting, channel names are organized into a namespace hierarchy where levels are separated by periods, much like the Java or Python package namespace. So in the instance given above, channel names might be “input” for the upper level, and “input.csv”, “input.xls” and “input.gnu” for the sub-levels. There is no arbitrary limit to the depth of nesting.

enable_notifications(servicename)

Post log messages of type info and error to the notification service

end_notifications()
error(msg, *args, **kw)

Log ‘msg % args’ with severity ‘ERROR’ and passes the message also to the endian ajax notification framework.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.error(“Houston, we have a %s”, “major problem”, exc_info=1)

findCaller()
has_notification_service

True if logger has notification service

info(msg, *args, **kw)

Log ‘msg % args’ with severity ‘INFO’ and passes the message also to the endian ajax notification framework.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.info(“Houston, we have a %s”, “interesting problem”, exc_info=1)

makeRecord(name, level, fn, lno, msg, args, exc_info, func=None, extra=None)
setLevel(level)

Set the logging level of this logger.

If the level is set to DEVELDEBUG, caller filename:function:lineno will be prefixed to each log message.

class MultiLineSysLogHandler(address=('localhost', 514), facility=1, socktype=2)

Bases: logging.handlers.SysLogHandler

A handler class which sends formatted logging records to a syslog server. Based on Sam Rushing’s syslog module: http://www.nightmare.com/squirl/python-ext/misc/syslog.py Contributed by Nicolas Untz (after which minor refactoring changes have been made).

emit(record)

Emit a record. Splits multilines in a record per line. Gets also rid of Tracebacks in order to have them splitted to one line per record.

unixsocket = 0
configureLogger(options)
create_logger(name=None, level=0, name_prefix=None, log_format=None, log_formatter=None)
disableLogHandler(id)

Disables the specified log handler.

Parameters:id (string) – The log handler id. Valid id’s are: ‘file’, ‘syslog’, ‘console’
enableLogHandler(id)

Enables the specified log handler.

Parameters:id (string) – The log handler id. Valid id’s are: ‘file’, ‘syslog’, ‘console’
enable_notifications(servicename)

Post log messages of type info and error to the notification service

end_notifications()
logger = <endian.core.logger.EndianLogger object at 0x8f6426c>

Default logger to which buildin logging functions are bound

logname(name)

Sets the name for a log section and should be called at the top of a method.

reopenLogfile()

If the file handler is active (setLogfile) called before), this function reopen’s the file. This can be used to reopen the logfile after SIGHUP has been caught, which may happen while log rotation.

Does nothing if setLogFile() has not been called before.

setLogfile(f)

Defines file ‘’f’’ as logfile. All other log handlers will be disabled. It will only be logged to this file

@type f: string @param f: The filename

endian.core.lvm module

backupVolumes(volumes, pidname, volumegroup='local', callback=None, **callback_args)
cloneVolumeFromBackup(source, destination, disksize, pidname, volumegroup='local', callback=None, **callback_args)

Clones LVM volumes from backup and calls a callback function at the end.

cloneVolumes(volumes, pidname, volumegroup='local', callback=None, **callback_args)

Clones LVM volumes and calls a callback function at the end.

createSnapshot(volumename, snapshotname, size=2000, volumegroup='local')
createVolume(volumename, size, volumegroup='local')
getFreeGroupSpace(volumegroup='local')

Returns the free space in a volume group in megabytes.

getGroupSize(volumegroup='local')

Returns the size of a volume group in megabytes.

getVolumeList(volumegroup='local')

Returns a list of volume names of a volume group

getVolumeSize(volumename, volumegroup='local')

Returns the volume size in megabytes.

isUsed()

Check whether we are using LVM or not.

removeVolume(volumename, volumegroup='local')
revertToBackups(volumes, pidname, volumegroup='local', callback=None, **callback_args)

Reverts LVM volumes to a previously created snapshot.

endian.core.magicset module

magicset.py

Created by Raphael Vallazza on 2007-04-23. Copyright (c) 2007 Endian. All rights reserved.

class MagicSet(items=None, identifier='id')

Bases: list

A list that acts like a dictionary

get(key, default=None)
keys()

endian.core.mail module

buildMIMEMessage(body, subject, to_addr, from_addr='', _subtype='text')

Create a MIMEMultipart message.

@type body string @param body The body of the message @type subject string @param subject The subject of the message @type to_addr string @param to_addr The receiver’s email address @type from_addr string @param from_addr The sender’s email address (guessed, if empty)

guess_mailfrom()
guess_smarthost()
sendmail(from_addr, to_addr, msg, mailhost='')

Send an email; if from_addr and mailhost are empty strings, they are guessed from the system configuration.

@type to_addr string @param to_addr The receiver’s email address @type from_addr string @param from_addr The sender’s email address (guessed, if empty) @type msg string @param msg A MIMEMultipart or a string with a complete message. @type mailhost string @param mailhost Smarthost used to send the email.

endian.core.md5crypt module

md5crypt(password, salt, magic='$1$')

endian.core.md5sum module

md5sum(fname)

Returns an md5 hash for file fname, or stdin if fname is “-”.

sumfile(fobj)

Returns an md5 hash for an object with read() method.

endian.core.modules module

family(family_name)

This decorator assign a ‘family’ to a module (or better, to the init function of a module). The family can be used to filter the modules to include/exclude

Usage example:

@family("EndianNetwork")
def init(root):
    registerController(root, "beautiful_controller", ABeautifulController())  

endian.core.monit module

monit.py

Created by Raphael Vallazza on 2007-02-19. Copyright (c) 2007 Endian. All rights reserved.

class Monit

Bases: object

docstring for Monit

getStatus()
parseStatus(status)

endian.core.mutex module

— mutex class — @author Peter Warasin <peter@endian.com> @copyright (c) Endian 2008

implements file mutex

class FileMutex(mutexfile)
acquire(blocking=True)

Blocks immediately if the lockfile already exists and the creating process is still running.

release()

Releases the lock

endian.core.niclist module

attribution(item, key, value, deep=True)
clearCache()
getBondDevices()
getDeviceByName(name)
getDummyNicList(dir='tests/data/niclist/')
getNicDevices()
getNicList(includeIPSec=False)
getPurpleDevices()
getSystemNics()
getVPNs(includeIPSec=False)
getVlanDevices()
getZoneDevices()
registerDevice(name, obj)
sanitizeList(list)

endian.core.notification module

Notification system for Endian Firewall Services.

This class implements an interface for restartscripts to publish updates of there ongoing status to the webinterface.

The current status is stored using the JSON syntax in a file which is named after the restartscript or the service, which uses this class.

The JSON file is used in a JavaScript service notification subscriber class. The Javascript Class is responsible to present the status updates, contained in the JSON file to the end user via the WEB UI.

Contents:

  • ServiceNotification: Generic JSON Interface to publish status updates
  • StatusFile: Extends FileMutex. Adds file-object like functions.

Example:

>>> from endian.core.notification import ServiceNotification
>>> # Create and initialize the notification system for snort 
>>> snortstatus = ServiceNotification("snort")
>>> # Publish first notification
>>> snortstatus.update("Reading configuration")
>>> ...
>>> # Publish another notification
>>> snortstatus.update("Restarting snortrules.py")
>>> # Publish error notification
>>> snortstatus.error("Failure: Snortrules incomplete!")
>>> # Call .end() to tell the signal the notification subscriber that
>>> # no more notifications will follow for this service.
>>> snortstatus.end()
exception InvalidNameError

Bases: exceptions.Exception

Exception for invalid names.

This Error is thrown if the user of the ServiceNotification class, passes an empty string as the name of the service. Notice: May be extended in the future, to be thrown on other occasions as well.

class ServiceNotification(name)

Notification class for services.

Provide a generic JSON interface for Endian Firewall services or restartscripts to publish status updates displayed on the Endian Firewall Web UI.

Each status update is represented by a json object, containing the following attributes:

msg
precise description of the status
type

either info or error. info is used to display status updates. error is used to inform the user about an error which occured.

Note

types may be extended in future.

date
a timestamp reflecting the time when the status was published

An Example entry:

{msg: "Reading SNORT configuration...", type: "info", date: 1214821339}

The created JSON File conforms to the following syntax:

[{msg: "Reading SNORT configuration...", type: "info", date: "1214821339"},
 {msg: "Applying migration rules...", type: "info", date: "1214821345"}]
Public methods:
update – publish an update of the status of the service end – end notification.
end()

Tell subscribers that no notifications will follow.

error(msg)

Post an error wich occured during execution of the service.

update(msg)

Post an update of the service status.

class StatusFile(statusfile)

Status file class holding status updates from the service.

Each status file contains that latest notification. A separate history file keeps track of all posted notifications and holds a JSON-list of notification entries. Lines written to the file are automatically converted from python dictionaries into JSON objects.

To improve the performance, despite the fact that JSON can’t be streamed, each call of write(object), removes an ending ‘]’ (represents the end of a list in JSON) and adds it again after the actual json object was added. As soon as the file is created, a ‘[‘ representing the begin of a list in JSON is automatically added.

close()

Release lock and remove the status file.

write(data)

Convert object to JSON and write the result to the status file.

Arguments:

object – the object containing status information, to convert to json
and to write to the status file

Convert object into a JSON-object and write it into the status file.

If this is first object to be writte to the history file, a preceding ‘[‘ is added, initiating a JSON list. A ‘]’ is appended after the object, to indicate the end of a JSON list.

class StatusFileMutex(mutexfile)

Bases: endian.core.mutex.FileMutex

Extends FileMutex class with file-like access options.

flush()

Flush the file buffer.

seek(offset, mode=0)

Modify the offset of the locked file-descriptor.

tell()

Return the current offset the locked file-descriptor.

truncate(size)

Truncate the file to the given size.

write(data)

Write data into the file.

endian.core.pattern module

class Observer

Bases: object

register(method)
update()
class ThreadableObserver

Bases: endian.core.pattern.Observer

register(method)
update()

endian.core.pdict module

class PersistentDict(filename, format='pickle', *args, **kargs)

Bases: UserDict.DictMixin

Persistent dictionary, stored with pickle

check()

Check if the file has been updated after the last loading

clear()

Remove all items from the dictionary.

has_key(key)

Test for the presence of key in the dictionary.

items()

Test for the presence of key in the dictionary.

iteritems()

Return an iterator over the dictionary’s (key, value) pairs.

iterkeys()

Return an iterator over the dictionary’s keys.

itervalues()

Return an iterator over the dictionary’s values.

keys()

Return a copy of the dictionary’s list of keys.

pop(*args, **kargs)

If key is in the dictionary, remove it and return its value, else return default. If default is not given and key is not in the dictionary, a KeyError is raised.

popitem()

Update the dictionary with the key/value pairs from other, overwriting existing keys

sync()

Store the content of the dictionary on the disk

update(*args, **kargs)

Update the dictionary with the key/value pairs from other, overwriting existing keys

values()

Return a copy of the dictionary’s list of (key, value) pairs.

endian.core.pidfile module

— pidfile class — @author Peter Warasin <peter@endian.it> @copyright (c) Endian 2007

handles pidfiles

exception AlreadyRunning

Bases: exceptions.Exception

Another process is already running

exception InvalidPid

Bases: exceptions.Exception

Happens if pid could not read

exception PidFileExists

Bases: exceptions.Exception

Happens if pid file already exists

class Pidfile(pidfile)
create(removestale=True)

Creates the pidfile and stores the actual PID. If the pidfile already exists PidFileExists will be raised if ‘removestale’ is False. If ‘removestale’ is True and there is a process with the PID of the pidfile, the exception AlreadyRunning will be raised. Otherwise the stale Pidfile will be overwritten with the actual PID. (If removestale is ‘True’, which is the default)

getPid()

reads out the PID from the pidfile and returns it.

Throws InvalidPid if the PID is no valid PID number.

isRunning()

Checks if the Process which created this PID file is running.

pid

reads out the PID from the pidfile and returns it.

Throws InvalidPid if the PID is no valid PID number.

remove()

Removes the pidfile

running

Checks if the Process which created this PID file is running.

endian.core.procutils module

set_process_name(new_process_name)

Change the process name

endian.core.profiler module

timeit(msg='')

endian.core.reserved_networks module

exception AlreadyInUseException(cidr, used_by)

Bases: exceptions.Exception

class ReservedNetworks(special_networks=[<0.0.0.0/255.0.0.0 CIDR>, <127.0.0.0/255.0.0.0 CIDR>, <169.254.0.0/255.255.0.0 CIDR>, <192.0.0.0/255.255.255.0 CIDR>, <192.0.2.0/255.255.255.0 CIDR>, <192.88.99.0/255.255.255.0 CIDR>, <198.18.0.0/255.254.0.0 CIDR>, <198.51.100.0/255.255.255.0 CIDR>, <203.0.113.0/255.255.255.0 CIDR>, <224.0.0.0/240.0.0.0 CIDR>, <240.0.0.0/240.0.0.0 CIDR>], private_networks=[<10.0.0.0/255.0.0.0 CIDR>, <172.16.0.0/255.240.0.0 CIDR>, <192.168.0.0/255.255.0.0 CIDR>], address_range=None)

Bases: object

Manage a list of reserved networks

add(cidr, force=False)

Add a network to the reserved networks

Raises:
  • AlreadyInUseException – if the network is not reservable
  • AddressNotInRange – if the cidr is outside the address range
Parameters:

cidr (string or iplib.CIDR) – a network address in CIDR notation

addresses

Number of reserved addresses

available_addresses

Number of not reserved addresses Warning! If there are some ‘forced’ networks (i.e. networks conflicts), this number is wrong!

is_available(cidr)

Check if a network is available.

Raises:AddressNotInRange: if the cidr is outside the address range
Parameters:cidr (string or iplib.CIDR) – a network address in CIDR notation
Returns:return True if the network is free, False otherwise
Return type:string
is_in_conflict(cidr)

Check if an existing network (i.e. a network that is just present in the reserved network list) is in conflicts with other networks

Raises AddressNotInRange:
 if the cidr is outside the address range
Parameters:cidr (string or iplib.CIDR) – a network address in CIDR notation
Returns:True is the given network is in conflict with other networks, False otherwise
Return type:boolean
largest_available_block_size

Return the size of the largest available block

remove(cidr)

Remove a network from the reserved networks

Raises:
  • KeyError – if the network is not present
  • AddressNotInRange – if the cidr is outside the address range
Parameters:

cidr (string or iplib.CIDR) – a network address in CIDR notation

search(addresses, address_range=None)

Search for a free network address in a given address range

Raises AddressNotInRange:
 

if the cidr is outside the address range

Parameters:
  • addresses (int) – required size for the network (in number of addresses)
  • address_range (string or iplib.CIDR) – a network address in CIDR notation
Returns:

return a network in CIDR notation or None if there is not enough space

Return type:

string

search_alternative(cidr)

Search for an alternative address for a given (not free) network

Parameters:cidr (string or iplib.CIDR) – a (not free) network address in CIDR notation
Returns:return a network in CIDR notation or None if there is not enough space
Return type:string
search_and_add(addresses, address_range=None)

Search for a free network address (in a given address range) to be allocated

Raises AddressSpaceExhausted:
 

if there is not enough allocable space

Parameters:
  • addresses (int) – required size for the network (in number of addresses)
  • address_range (string or iplib.CIDR) – a network address in CIDR notation
Returns:

return a network in CIDR notation

Return type:

string

search_and_add_alternative(cidr)

Search and allocate an alternative address of the same size of the given (not free) network.

Raises AddressSpaceExhausted:
 if there is not enough allocable space
Parameters:cidr (string or iplib.CIDR) – a (not free) network address in CIDR notation
Returns:return a network in CIDR notation
Return type:string
exception AddressNotInRange(cidr)

Bases: exceptions.Exception

exception AddressSpaceExhausted

Bases: exceptions.Exception

endian.core.runner module

Expect(to, cmdlog=None)
class LoggingTelnet(host=None, port=0, cmdlog=None)

Bases: telnetlib.Telnet

expect(list, timeout=None)
msg(msg, *args)
class Process(args, bufsize=4096, shell=True, cwd=None, env=None, cmdlog=None)

Bases: object

XXX: doc This is a telnetlib compatible subprocess module

close(force=False, kill=False)
expect(list, timeout=None)
msg(msg)
open()
readline(timeout=None)
write(buffer)
class Runner

Bases: object

close()

For popen compatibility

getOutput()
read()

For popen compatibility

readlines()

For popen compatibility

run(cmd, failOk=False, shell=True, suppress_output=False)
xreadlines()

For popen compatibility

endian.core.schema module

class All(*args, **kw)

Bases: formencode.compound.CompoundValidator

This class is like an ‘and’ operator for validators. All validators must work, and the results are passed in turn through all validators for conversion.

attempt_convert(value, state, validate)
declarative_count = 9
if_missing
if_missing__get()
is_empty(value)
classmethod join(*validators)

Joins several validators together as a single validator, filtering out None and trying to keep All validators from being nested (which isn’t needed).

not_empty
not_empty__get()
validators = []
with_validator(validator)

Adds the validator (or list of validators) to a copy of this validator.

class Any(*args, **kw)

Bases: formencode.compound.CompoundValidator

This class is like an ‘or’ operator for validators. The first validator/converter that validates the value will be used. (You can pass in lists of validators, which will be ANDed)

attempt_convert(value, state, validate)
declarative_count = 8
not_empty
not_empty__get()
validators = []
class Bool(*args, **kw)

Bases: formencode.api.FancyValidator

Always Valid, returns True or False based on the value and the existance of the value.

If you want to convert strings like 'true' to booleans, then use StringBoolean.

Examples:

>>> Bool.to_python(0)
False
>>> Bool.to_python(1)
True
>>> Bool.to_python('')
False
>>> Bool.to_python(None)
False

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
declarative_count = 25
empty_value(value)
if_missing = False
class CIDR(*args, **kw)

Bases: formencode.api.FancyValidator

Validator to check whether a string is in correct CIDR notation (IP address, or IP address plus /mask)

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
bad_format:
Please enter a valid IP address (a.b.c.d) or IP network (a.b.c.d/e)
empty:
Please enter a value
noneType:
The input must be a string (not None)
declarative_count = 145
use_datatype = False
class ConditionalValidator(*args, **kws)

Bases: formencode.validators.FormValidator

Does only apply the validator if the condition (a function which return True, if the validator should be applied, or a validator, which does not throw a exception) does not fail.

Also a list of conditions or validators can be passed.

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
condition = []
declarative_count = 141
validator = []
class ConfirmType(*args, **kw)

Bases: formencode.api.FancyValidator

Confirms that the input/output is of the proper type.

Uses the parameters:

subclass:
The class or a tuple of classes; the item must be an instance of the class or a subclass.
type:
A type or tuple of types (or classes); the item must be of the exact class or type. Subclasses are not allowed.

Examples:

>>> cint = ConfirmType(subclass=int)
>>> cint.to_python(True)
True
>>> cint.to_python('1')
Traceback (most recent call last):
    ...
Invalid: '1' is not a subclass of <type 'int'>
>>> cintfloat = ConfirmType(subclass=(float, int))
>>> cintfloat.to_python(1.0), cintfloat.from_python(1.0)
(1.0, 1.0)
>>> cintfloat.to_python(1), cintfloat.from_python(1)
(1, 1)
>>> cintfloat.to_python(None)
Traceback (most recent call last):
    ...
Invalid: None is not a subclass of one of the types <type 'float'>, <type 'int'>
>>> cint2 = ConfirmType(type=int)
>>> cint2(accept_python=False).from_python(True)
Traceback (most recent call last):
    ...
Invalid: True must be of the type <type 'int'>

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
inSubclass:
%(object)r is not a subclass of one of the types %(subclassList)s
inType:
%(object)r must be one of the types %(typeList)s
noneType:
The input must be a string (not None)
subclass:
%(object)r is not a subclass of %(subclass)s
type:
%(object)r must be of the type %(type)s
confirm_subclass(value, state)
confirm_type(value, state)
declarative_count = 12
is_empty(value)
subclass = None
type = None
class Constant(*args, **kw)

Bases: formencode.api.FancyValidator

This converter converts everything to the same thing.

I.e., you pass in the constant value when initializing, then all values get converted to that constant value.

This is only really useful for funny situations, like:

fromEmailValidator = ValidateAny(
                         ValidEmailAddress(),
                         Constant('unknown@localhost'))

In this case, the if the email is not valid 'unknown@localhost' will be used instead. Of course, you could use if_invalid instead.

Examples:

>>> Constant('X').to_python('y')
'X'

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
declarative_count = 14
class DateConverter(*args, **kw)

Bases: formencode.api.FancyValidator

Validates and converts a string date, like mm/yy, dd/mm/yy, dd-mm-yy, etc. Using month_style you can support 'mm/dd/yyyy' or 'dd/mm/yyyy'. Only these two general styles are supported.

Accepts English month names, also abbreviated. Returns value as a datetime object (you can get mx.DateTime objects if you use datetime_module='mxDateTime'). Two year dates are assumed to be within 1950-2020, with dates from 21-49 being ambiguous and signaling an error.

Use accept_day=False if you just want a month/year (like for a credit card expiration date).

>>> d = DateConverter()
>>> d.to_python('12/3/09')
datetime.date(2009, 12, 3)
>>> d.to_python('12/3/2009')
datetime.date(2009, 12, 3)
>>> d.to_python('2/30/04')
Traceback (most recent call last):
    ...
Invalid: That month only has 29 days
>>> d.to_python('13/2/05')
Traceback (most recent call last):
    ...
Invalid: Please enter a month from 1 to 12
>>> d.to_python('1/1/200')
Traceback (most recent call last):
    ...
Invalid: Please enter a four-digit year after 1899

If you change month_style you can get European-style dates:

>>> d = DateConverter(month_style='dd/mm/yyyy')
>>> date = d.to_python('12/3/09')
>>> date
datetime.date(2009, 3, 12)
>>> d.from_python(date)
'12/03/2009'

Messages

badFormat:
Please enter the date in the form %(format)s
badType:
The input must be a string (not a %(type)s: %(value)r)
dayRange:
That month only has %(days)i days
empty:
Please enter a value
fourDigitYear:
Please enter a four-digit year after 1899
invalidDate:
That is not a valid day (%(exception)s)
invalidDay:
Please enter a valid day
invalidYear:
Please enter a number for the year
monthRange:
Please enter a month from 1 to 12
noneType:
The input must be a string (not None)
unknownMonthName:
Unknown month name: %(month)s
wrongFormat:
Please enter the date in the form %(format)s
accept_day = True
convert_day(value, state)
convert_month(value, state)
datetime_module = None
declarative_count = 38
make_month(value, state)
make_year(year, state)
month_style = 'mm/dd/yyyy'
unconvert_day(value, state)
unconvert_month(value, state)
class DateValidator(*args, **kw)

Bases: formencode.api.FancyValidator

Validates that a date is within the given range. Be sure to call DateConverter first if you aren’t expecting mxDateTime input.

earliest_date and latest_date may be functions; if so, they will be called each time before validating.

after_now means a time after the current timestamp; note that just a few milliseconds before now is invalid! today_or_after is more permissive, and ignores hours and minutes.

Examples:

>>> from datetime import datetime, timedelta
>>> d = DateValidator(earliest_date=datetime(2003, 1, 1))
>>> d.to_python(datetime(2004, 1, 1))
datetime.datetime(2004, 1, 1, 0, 0)
>>> d.to_python(datetime(2002, 1, 1))
Traceback (most recent call last):
    ...
Invalid: Date must be after Wednesday, 01 January 2003
>>> d.to_python(datetime(2003, 1, 1))
datetime.datetime(2003, 1, 1, 0, 0)
>>> d = DateValidator(after_now=True)
>>> now = datetime.now()
>>> d.to_python(now+timedelta(seconds=5)) == now+timedelta(seconds=5)
True
>>> d.to_python(now-timedelta(days=1))
Traceback (most recent call last):
    ...
Invalid: The date must be sometime in the future
>>> d.to_python(now+timedelta(days=1)) > now
True
>>> d = DateValidator(today_or_after=True)
>>> d.to_python(now) == now
True

Messages

after:
Date must be after %(date)s
badType:
The input must be a string (not a %(type)s: %(value)r)
before:
Date must be before %(date)s
date_format:
%%A, %%d %%B %%Y
empty:
Please enter a value
future:
The date must be sometime in the future
noneType:
The input must be a string (not None)
after_now = False
datetime_module = None
declarative_count = 24
earliest_date = None
latest_date = None
today_or_after = False
validate_python(value, state)
class DictConverter(*args, **kw)

Bases: formencode.api.FancyValidator

Converts values based on a dictionary which has values as keys for the resultant values.

If allowNull is passed, it will not balk if a false value (e.g., ‘’ or None) is given (it will return None in these cases).

to_python takes keys and gives values, from_python takes values and gives keys.

If you give hideDict=True, then the contents of the dictionary will not show up in error messages.

Examples:

>>> dc = DictConverter({1: 'one', 2: 'two'})
>>> dc.to_python(1)
'one'
>>> dc.from_python('one')
1
>>> dc.to_python(3)
Traceback (most recent call last):
Invalid: Enter a value from: 1; 2
>>> dc2 = dc(hideDict=True)
>>> dc2.hideDict
True
>>> dc2.dict
{1: 'one', 2: 'two'}
>>> dc2.to_python(3)
Traceback (most recent call last):
Invalid: Choose something
>>> dc.from_python('three')
Traceback (most recent call last):
Invalid: Nothing in my dictionary goes by the value 'three'.  Choose one of: 'one'; 'two'

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
chooseKey:
Enter a value from: %(items)s
chooseValue:
Nothing in my dictionary goes by the value %(value)s. Choose one of: %(items)s
empty:
Please enter a value
keyNotFound:
Choose something
noneType:
The input must be a string (not None)
valueNotFound:
That value is not known
declarative_count = 22
dict = None
hideDict = False
class Email(*args, **kw)

Bases: formencode.api.FancyValidator

Validate an email address.

If you pass resolve_domain=True, then it will try to resolve the domain name to make sure it’s valid. This takes longer, of course. You must have the pyDNS modules installed to look up DNS (MX and A) records.

>>> e = Email()
>>> e.to_python(' test@foo.com ')
'test@foo.com'
>>> e.to_python('test')
Traceback (most recent call last):
    ...
Invalid: An email address must contain a single @
>>> e.to_python('test@foobar')
Traceback (most recent call last):
    ...
Invalid: The domain portion of the email address is invalid (the portion after the @: foobar)
>>> e.to_python('test@foobar.com.5')
Traceback (most recent call last):
    ...
Invalid: The domain portion of the email address is invalid (the portion after the @: foobar.com.5)
>>> e.to_python('test@foo..bar.com')
Traceback (most recent call last):
    ...
Invalid: The domain portion of the email address is invalid (the portion after the @: foo..bar.com)
>>> e.to_python('test@.foo.bar.com')
Traceback (most recent call last):
    ...
Invalid: The domain portion of the email address is invalid (the portion after the @: .foo.bar.com)
>>> e.to_python('nobody@xn--m7r7ml7t24h.com')
'nobody@xn--m7r7ml7t24h.com'
>>> e.to_python('o*reilly@test.com')
'o*reilly@test.com'
>>> e = Email(resolve_domain=True)
>>> e.resolve_domain
True
>>> e.to_python('doesnotexist@colorstudy.com')
'doesnotexist@colorstudy.com'
>>> e.to_python('test@forums.nyu.edu')
'test@forums.nyu.edu'
>>> # NOTE: If you do not have PyDNS installed this example won't work:
>>> e.to_python('test@thisdomaindoesnotexistithinkforsure.com')
Traceback (most recent call last):
    ...
Invalid: The domain of the email address does not exist (the portion after the @: thisdomaindoesnotexistithinkforsure.com)
>>> e.to_python(u'test@google.com')
u'test@google.com'
>>> e = Email(not_empty=False)
>>> e.to_python('')

Messages

badDomain:
The domain portion of the email address is invalid (the portion after the @: %(domain)s)
badType:
The input must be a string (not a %(type)s: %(value)r)
badUsername:
The username portion of the email address is invalid (the portion before the @: %(username)s)
domainDoesNotExist:
The domain of the email address does not exist (the portion after the @: %(domain)s)
empty:
Please enter an email address
noAt:
An email address must contain a single @
noneType:
The input must be a string (not None)
socketError:
An error occured when trying to connect to the server: %(error)s
declarative_count = 32
domainRE = <_sre.SRE_Pattern object at 0x94b6d40>
resolve_domain = False
usernameRE = <_sre.SRE_Pattern object at 0x9105f20>
validate_python(value, state)
class Empty(*args, **kw)

Bases: formencode.api.FancyValidator

Invalid unless the value is empty. Use cleverly, if at all.

Examples:

>>> Empty.to_python(0)
Traceback (most recent call last):
  ...
Invalid: You cannot enter a value here

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
notEmpty:
You cannot enter a value here
declarative_count = 18
validate_python(value, state)
class FancyValidator(*args, **kw)

Bases: formencode.api.Validator

FancyValidator is the (abstract) superclass for various validators and converters. A subclass can validate, convert, or do both. There is no formal distinction made here.

Validators have two important external methods:

  • .to_python(value, state): Attempts to convert the value. If there is a problem, or the value is not valid, an Invalid exception is raised. The argument for this exception is the (potentially HTML-formatted) error message to give the user.
  • .from_python(value, state): Reverses to_python.

There are five important methods for subclasses to override, however none of these have to be overridden, only the ones that are appropriate for the validator:

  • __init__(): if the declarative.Declarative model doesn’t work for this.
  • .validate_python(value, state): This should raise an error if necessary. The value is a Python object, either the result of to_python, or the input to from_python.
  • .validate_other(value, state): Validates the source, before to_python, or after from_python. It’s more common to use .validate_python() however.
  • ._to_python(value, state): This returns the converted value, or raises an Invalid exception if there is an error. The argument to this exception should be the error message.
  • ._from_python(value, state): Should undo .to_python() in some reasonable way, returning a string.

Validators should have no internal state besides the values given at instantiation. They should be reusable and reentrant.

All subclasses can take the arguments/instance variables:

  • if_empty: If set, then this value will be returned if the input evaluates to false (empty list, empty string, None, etc), but not the 0 or False objects. This only applies to .to_python().
  • not_empty: If true, then if an empty value is given raise an error. (Both with .to_python() and also .from_python() if .validate_python is true).
  • strip: If true and the input is a string, strip it (occurs before empty tests).
  • if_invalid: If set, then when this validator would raise Invalid during .to_python(), instead return this value.
  • if_invalid_python: If set, when the Python value (converted with .from_python()) is invalid, this value will be returned.
  • accept_python: If True (the default), then .validate_python() and .validate_other() will not be called when .from_python() is used.

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
accept_python = True
assert_string(value, state)
base64encode(value)

Encode a string in base64, stripping whitespace and removing newlines.

declarative_count = 4
empty_value(value)
classmethod from_python(value, state=None)
if_empty

alias of NoDefault

if_invalid

alias of NoDefault

if_invalid_python

alias of NoDefault

is_empty(value)
not_empty = False
strip = False
classmethod to_python(value, state=None)
validate_other(value, state)

A validation method that doesn’t do anything.

validate_python(value, state)

A validation method that doesn’t do anything.

class FieldStorageUploadConverter(*args, **kw)

Bases: formencode.api.FancyValidator

Handles cgi.FieldStorage instances that are file uploads.

This doesn’t do any conversion, but it can detect empty upload fields (which appear like normal fields, but have no filename when no upload was given).

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
declarative_count = 36
is_empty(value)
class FieldValueCount(*args, **kw)

Bases: formencode.validators.FormValidator

Validator for checking if more then a defined count of items with a fieldvalue already exist.

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
to_many:
Too many items with same value
to_many_long:
To many items with same value for %(field)s
count = 4
declarative_count = 137
entity = None
field = 'enabled'
storage = None
value = True
class FieldsMatch(*args, **kw)

Bases: formencode.validators.FormValidator

Tests that the given fields match, i.e., are identical. Useful for password+confirmation fields. Pass the list of field names in as field_names.

>>> f = FieldsMatch('pass', 'conf')
>>> f.to_python({'pass': 'xx', 'conf': 'xx'})
{'conf': 'xx', 'pass': 'xx'}
>>> f.to_python({'pass': 'xx', 'conf': 'yy'})
Traceback (most recent call last):
    ...
Invalid: conf: Fields do not match

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
invalid:
Fields do not match (should be %(match)s)
invalidNoMatch:
Fields do not match
noneType:
The input must be a string (not None)
notDict:
Fields should be a dictionary
declarative_count = 48
field_names = None
show_match = False
validate_partial(field_dict, state)
validate_partial_form = True
validate_python(field_dict, state)
class FileUploadKeeper(*args, **kw)

Bases: formencode.api.FancyValidator

Takes two inputs (a dictionary with keys static and upload) and converts them into one value on the Python side (a dictionary with filename and content keys). The upload takes priority over the static value. The filename may be None if it can’t be discovered.

Handles uploads of both text and cgi.FieldStorage upload values.

This is basically for use when you have an upload field, and you want to keep the upload around even if the rest of the form submission fails. When converting back to the form submission, there may be extra values 'original_filename' and 'original_content', which may want to use in your form to show the user you still have their content around.

To use this, make sure you are using variabledecode, then use something like:

<input type="file" name="myfield.upload">
<input type="hidden" name="myfield.static">

Then in your scheme:

class MyScheme(Scheme):
    myfield = FileUploadKeeper()

Note that big file uploads mean big hidden fields, and lots of bytes passed back and forth in the case of an error.

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
declarative_count = 37
pack_content(filename, content)
static_key = 'static'
upload_key = 'upload'
class ForEach(*args, **kw)

Bases: formencode.compound.CompoundValidator

Use this to apply a validator/converter to each item in a list.

For instance:

ForEach(AsInt(), InList([1, 2, 3]))

Will take a list of values and try to convert each of them to an integer, and then check if each integer is 1, 2, or 3. Using multiple arguments is equivalent to:

ForEach(All(AsInt(), InList([1, 2, 3])))

Use convert_to_list=True if you want to force the input to be a list. This will turn non-lists into one-element lists, and None into the empty list. This tries to detect sequences by iterating over them (except strings, which aren’t considered sequences).

ForEach will try to convert the entire list, even if errors are encountered. If errors are encountered, they will be collected and a single Invalid exception will be raised at the end (with error_list set).

If the incoming value is a set, then we return a set.

attempt_convert(value, state, validate)
convert_to_list = True
declarative_count = 11
empty_value(value)
if_empty

alias of NoDefault

if_missing = []
repeating = True
validators = []
class FormValidator(*args, **kw)

Bases: formencode.api.FancyValidator

A FormValidator is something that can be chained with a Schema. Unlike normal chaining the FormValidator can validate forms that aren’t entirely valid.

The important method is .validate(), of course. It gets passed a dictionary of the (processed) values from the form. If you have .validate_partial_form set to True, then it will get the incomplete values as well – use .has_key() to test if the field was able to process any particular field.

Anyway, .validate() should return a string or a dictionary. If a string, it’s an error message that applies to the whole form. If not, then it should be a dictionary of fieldName: errorMessage. The special key “form” is the error message for the form as a whole (i.e., a string is equivalent to {“form”: string}).

Return None on no errors.

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
declarative_count = 46
is_empty(value)
validate_partial_form = False
validate_partial_other = None
validate_partial_python = None
class IPAddress(*args, **kw)

Bases: formencode.api.FancyValidator

Validator to check whether a string is a correct IP address

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
bad_format:
Please enter a valid IP address (a.b.c.d)
empty:
Please enter a value
noneType:
The input must be a string (not None)
declarative_count = 144
use_datatype = False
class IndexListConverter(*args, **kw)

Bases: formencode.api.FancyValidator

Converts a index (which may be a string like ‘2’) to the value in the given list.

Examples:

>>> index = IndexListConverter(['zero', 'one', 'two'])
>>> index.to_python(0)
'zero'
>>> index.from_python('zero')
0
>>> index.to_python('1')
'one'
>>> index.to_python(5)
Traceback (most recent call last):
Invalid: Index out of range
>>> index(not_empty=True).to_python(None)
Traceback (most recent call last):
Invalid: Please enter a value
>>> index.from_python('five')
Traceback (most recent call last):
Invalid: Item 'five' was not found in the list

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
integer:
Must be an integer index
noneType:
The input must be a string (not None)
notFound:
Item %(value)s was not found in the list
outOfRange:
Index out of range
declarative_count = 23
list = None
class Int(*args, **kw)

Bases: formencode.validators.RangeValidator

Convert a value to an integer.

Example:

>>> Int.to_python('10')
10
>>> Int.to_python('ten')
Traceback (most recent call last):
    ...
Invalid: Please enter an integer value
>>> Int(min=5).to_python('6')
6
>>> Int(max=10).to_python('11')
Traceback (most recent call last):
    ...
Invalid: Please enter a number that is 10 or smaller

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
integer:
Please enter an integer value
noneType:
The input must be a string (not None)
tooHigh:
Please enter a number that is %(max)s or smaller
tooLow:
Please enter a number that is %(min)s or greater
declarative_count = 27
exception Invalid(msg, value, state, error_list=None, error_dict=None)

Bases: exceptions.Exception

This is raised in response to invalid input. It has several public attributes:

msg:
The message, without values substituted. For instance, if you want HTML quoting of values, you can apply that.
substituteArgs:
The arguments (a dictionary) to go with msg.
str(self):
The message describing the error, with values substituted.
value:
The offending (invalid) value.
state:
The state that went with this validator. This is an application-specific object.
error_list:
If this was a compound validator that takes a repeating value, and sub-validator(s) had errors, then this is a list of those exceptions. The list will be the same length as the number of values – valid values will have None instead of an exception.
error_dict:
Like error_list, but for dictionary compound validators.
unpack_errors(encode_variables=False, dict_char='.', list_char='-')

Returns the error as a simple data structure – lists, dictionaries, and strings.

If encode_variables is true, then this will return a flat dictionary, encoded with variable_encode

class IpRange(*args, **kw)

Bases: formencode.validators.FormValidator

Controlls if the first ip greater than the second. Optional: controlls if both are in a certain network(may multiple with comma separated).

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
bad_format:
The ip string is formated bad!
empty:
Please enter a value
first_greater:
The first ip must be smaller than the second!
noneType:
The input must be a string (not None)
not_subnetwork:
The ip is not in the network!
declarative_count = 136
first_ip = None
network = None
second_ip = None
class MACAddress(*args, **kw)

Bases: formencode.api.FancyValidator

Formencode validator to check whether a string is a correct hardware (MAC) address.

Examples:

>>> mac = MACAddress()
>>> mac.to_python('aa:bb:cc:dd:ee:ff')
'aabbccddeeff'
>>> mac.to_python('aa:bb:cc:dd:ee:ff:e')
Traceback (most recent call last):
    ...
Invalid: A MAC address must contain 12 digits and A-F; the value you gave has 13 characters
>>> mac.to_python('aa:bb:cc:dd:ee:fx')
Traceback (most recent call last):
    ...
Invalid: MAC addresses may only contain 0-9 and A-F (and optionally :), not 'x'
>>> MACAddress(add_colons=True).to_python('aabbccddeeff')
'aa:bb:cc:dd:ee:ff'

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
bad_character:
MAC addresses may only contain 0-9 and A-F (and optionally :), not %(char)r
bad_length:
A MAC address must contain 12 digits and A-F; the value you gave has %(length)s characters
empty:
Please enter a value
noneType:
The input must be a string (not None)
add_colons = True
declarative_count = 45
strip = True
valid_characters = '0123456789abcdefABCDEF'
class MaxLength(*args, **kw)

Bases: formencode.api.FancyValidator

Invalid if the value is longer than maxLength. Uses len(), so it can work for strings, lists, or anything with length.

Examples:

>>> max5 = MaxLength(5)
>>> max5.to_python('12345')
'12345'
>>> max5.from_python('12345')
'12345'
>>> max5.to_python('123456')
Traceback (most recent call last):
  ...
Invalid: Enter a value less than 5 characters long
>>> max5(accept_python=False).from_python('123456')
Traceback (most recent call last):
  ...
Invalid: Enter a value less than 5 characters long
>>> max5.to_python([1, 2, 3])
[1, 2, 3]
>>> max5.to_python([1, 2, 3, 4, 5, 6])
Traceback (most recent call last):
  ...
Invalid: Enter a value less than 5 characters long
>>> max5.to_python(5)
Traceback (most recent call last):
  ...
Invalid: Invalid value (value with length expected)

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
invalid:
Invalid value (value with length expected)
noneType:
The input must be a string (not None)
tooLong:
Enter a value less than %(maxLength)i characters long
declarative_count = 15
validate_python(value, state)
class MinLength(*args, **kw)

Bases: formencode.api.FancyValidator

Invalid if the value is shorter than minlength. Uses len(), so it can work for strings, lists, or anything with length. Note that you must use not_empty=True if you don’t want to accept empty values – empty values are not tested for length.

Examples:

>>> min5 = MinLength(5)
>>> min5.to_python('12345')
'12345'
>>> min5.from_python('12345')
'12345'
>>> min5.to_python('1234')
Traceback (most recent call last):
  ...
Invalid: Enter a value at least 5 characters long
>>> min5(accept_python=False).from_python('1234')
Traceback (most recent call last):
  ...
Invalid: Enter a value at least 5 characters long
>>> min5.to_python([1, 2, 3, 4, 5])
[1, 2, 3, 4, 5]
>>> min5.to_python([1, 2, 3])
Traceback (most recent call last):
  ...
Invalid: Enter a value at least 5 characters long
>>> min5.to_python(5)
Traceback (most recent call last):
  ...
Invalid: Invalid value (value with length expected)

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
invalid:
Invalid value (value with length expected)
noneType:
The input must be a string (not None)
tooShort:
Enter a value at least %(minLength)i characters long
declarative_count = 16
validate_python(value, state)
class Multichoice(*args, **kw)

Bases: formencode.foreach.ForEach

declarative_count = 124
validators = []
class Multiline(*args, **kw)

Bases: formencode.foreach.ForEach

declarative_count = 123
empty_value(value)
required = False
validators = []
class NetworkAddress(*args, **kw)

Bases: formencode.api.FancyValidator

Validator to check whether a string is in correct CIDR notation IP address/mask Netmask is mandatory - i.e. IP address without netmask is not valid

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
bad_format:
Please enter a valid IP network (a.b.c.d/e)
empty:
Please enter a value
noneType:
The input must be a string (not None)
declarative_count = 146
use_datatype = False
class NetworkIPS(*args, **kw)

Bases: formencode.api.FancyValidator

Controlls:

  • if the ip is the same as the network address.
  • if the ip is the same as the network broadcast address.
  • if the network contains just one ip.

If so shows an error.

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
bad_format:
Please enter a valid IP address (a.b.c.d) or IP network (a.b.c.d/e)
empty:
Please enter a value
ip_same_as_broadcast:
The address is the same as its broadcast address, which is not allowed!
ip_same_as_network:
The address is the same as its network address, which is not allowed!
noneType:
The input must be a string (not None)
only_one_ip:
The network mask addresses less than 4 IP address, which will lock you out if applied. Choose another one!
declarative_count = 147
use_datatype = False
class NetworkIntersection(*args, **kws)

Bases: formencode.validators.FormValidator

Controlls if the CIDR values intersect.

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
bad_format:
The network string is formated bad!
empty:
Please enter a value
intersect:
The different networks do intersect!
noneType:
The input must be a string (not None)
declarative_count = 135
networks = []
class NetworkMultiIPS(*args, **kw)

Bases: formencode.api.FancyValidator

Controlls for comma seperated ips:

  • if the ip is the same as the network address.
  • if the ip is the same as the network broadcast address.
  • if the network contains just one ip.

If so shows an error.

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
intersect:
The networks do intersect, which is not allowed!
ip_same_as_broadcast:
One address is the same as its broadcast address, which is not allowed!
ip_same_as_network:
One address is the same as its network address, which is not allowed!
noneType:
The input must be a string (not None)
only_one_ip:
One network mask addresses less than 4 IP address, which will lock you out if applied. Choose another one!
declarative_count = 148
use_datatype = False
class NetworkSelectorContains(*args, **kws)

Bases: formencode.validators.FormValidator

Controlls if the required interface types occure(as sum) at least count times.

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
missing_interface_selection:
Not all needed interfaces selected.
noneType:
The input must be a string (not None)
count = 1
declarative_count = 134
interface = None
selector = None
class NoDefault
class NotEmpty(*args, **kw)

Bases: formencode.api.FancyValidator

Invalid if value is empty (empty string, empty list, etc).

Generally for objects that Python considers false, except zero which is not considered invalid.

Examples:

>>> ne = NotEmpty(messages={'empty': 'enter something'})
>>> ne.to_python('')
Traceback (most recent call last):
  ...
Invalid: enter something
>>> ne.to_python(0)
0

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
declarative_count = 17
not_empty = True
validate_python(value, state)
class Number(*args, **kw)

Bases: formencode.validators.RangeValidator

Convert a value to a float or integer.

Tries to convert it to an integer if no information is lost.

Example:

>>> Number.to_python('10')
10
>>> Number.to_python('10.5')
10.5
>>> Number.to_python('ten')
Traceback (most recent call last):
    ...
Invalid: Please enter a number
>>> Number(min=5).to_python('6.5')
6.5
>>> Number(max=10.5).to_python('11.5')
Traceback (most recent call last):
    ...
Invalid: Please enter a number that is 10.5 or smaller
>>> Number().to_python('infinity')
inf

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
number:
Please enter a number
tooHigh:
Please enter a number that is %(max)s or smaller
tooLow:
Please enter a number that is %(min)s or greater
declarative_count = 28
class OneOf(*args, **kw)

Bases: formencode.api.FancyValidator

Tests that the value is one of the members of a given list.

If testValueList=True, then if the input value is a list or tuple, all the members of the sequence will be checked (i.e., the input must be a subset of the allowed values).

Use hideList=True to keep the list of valid values out of the error message in exceptions.

Examples:

>>> oneof = OneOf([1, 2, 3])
>>> oneof.to_python(1)
1
>>> oneof.to_python(4)
Traceback (most recent call last):
  ...
Invalid: Value must be one of: 1; 2; 3 (not 4)
>>> oneof(testValueList=True).to_python([2, 3, [1, 2, 3]])
[2, 3, [1, 2, 3]]
>>> oneof.to_python([2, 3, [1, 2, 3]])
Traceback (most recent call last):
  ...
Invalid: Value must be one of: 1; 2; 3 (not [2, 3, [1, 2, 3]])

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
invalid:
Invalid value
noneType:
The input must be a string (not None)
notIn:
Value must be one of: %(items)s (not %(value)r)
declarative_count = 21
hideList = False
list = None
testValueList = False
validate_python(value, state)
class OpenId(add_schema=False, **kwargs)

Bases: formencode.api.FancyValidator

OpenId validator.

::
>>> v = OpenId(add_schema=True)
>>> v.to_python(' example.net ')
'http://example.net'
>>> v.to_python('@TurboGears')
'xri://@TurboGears'
>>> w = OpenId(add_schema=False)
>>> w.to_python(' example.net ')
Traceback (most recent call last):
...
Invalid: "example.net" is not a valid OpenId (it is neither an URL nor an XRI)
>>> w.to_python('!!1000')
'!!1000'
>>> w.to_python('look@me.com')
Traceback (most recent call last):
...
Invalid: "look@me.com" is not a valid OpenId (it is neither an URL nor an XRI)

Messages

badId:
%(id)s” is not a valid OpenId (it is neither an URL nor an XRI)
badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
declarative_count = 35
validate_python(value, state)
class Percentage(*args, **kw)

Bases: formencode.api.FancyValidator

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
invalid:
Invalid percentage value
noneType:
The input must be a string (not None)
declarative_count = 125
class Pipe(*args, **kw)

Bases: formencode.compound.All

This class works like ‘All’, all validators muss pass, but the result of one validation pass is handled over to the next validator. A behaviour known to Unix and GNU users as ‘pipe’.

>>> from validators import DictConverter
>>> pv = Pipe(validators=[DictConverter({1: 2}), DictConverter({2: 3}), DictConverter({3: 4})])
>>> pv.to_python(1)
4
>>> pv.to_python(1)
4
>>> pv.from_python(4)
1
>>> pv.from_python(4)
1
>>> pv.to_python(1)
4
attempt_convert(value, state, validate)
declarative_count = 10
validators = []
class PlainText(*args, **kw)

Bases: formencode.validators.Regex

Test that the field contains only letters, numbers, underscore, and the hyphen. Subclasses Regex.

Examples:

>>> PlainText.to_python('_this9_')
'_this9_'
>>> PlainText.from_python('  this  ')
'  this  '
>>> PlainText(accept_python=False).from_python('  this  ')
Traceback (most recent call last):
  ...
Invalid: Enter only letters, numbers, or _ (underscore)
>>> PlainText(strip=True).to_python('  this  ')
'this'
>>> PlainText(strip=True).from_python('  this  ')
'this'

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
invalid:
Enter only letters, numbers, or _ (underscore)
noneType:
The input must be a string (not None)
declarative_count = 20
regex = '^[a-zA-Z_\\-0-9]*$'
class Port(*args, **kw)

Bases: formencode.validators.Int

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
integer:
Invalid port number
noneType:
The input must be a string (not None)
tooHigh:
Port number must be smaller than 65536
tooLow:
Port number must be bigger than 0
declarative_count = 142
max = 65536
min = 0
class PortRange(*args, **kw)

Bases: endian.validators.network.Port

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
integer:
Invalid port number
invalid:
Start port must be smaller then end port
noneType:
The input must be a string (not None)
range:
Invalid port range
tooHigh:
Port number must be smaller than 65536
tooLow:
Port number must be bigger than 0
declarative_count = 143
validate_python(value, state)
class RangeValidator(*args, **kw)

Bases: formencode.api.FancyValidator

This is an abstract base class for Int and Number.

It verifies that a value is within range. It accepts min and max values in the constructor.

(Since this is an abstract base class, the tests are in Int and Number.)

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
tooHigh:
Please enter a number that is %(max)s or smaller
tooLow:
Please enter a number that is %(min)s or greater
declarative_count = 26
max = None
min = None
validate_python(value, state)
class Regex(*args, **kw)

Bases: formencode.api.FancyValidator

Invalid if the value doesn’t match the regular expression regex.

The regular expression can be a compiled re object, or a string which will be compiled for you.

Use strip=True if you want to strip the value before validation, and as a form of conversion (often useful).

Examples:

>>> cap = Regex(r'^[A-Z]+$')
>>> cap.to_python('ABC')
'ABC'

Note that .from_python() calls (in general) do not validate the input:

>>> cap.from_python('abc')
'abc'
>>> cap(accept_python=False).from_python('abc')
Traceback (most recent call last):
  ...
Invalid: The input is not valid
>>> cap.to_python(1)
Traceback (most recent call last):
  ...
Invalid: The input must be a string (not a <type 'int'>: 1)
>>> Regex(r'^[A-Z]+$', strip=True).to_python('  ABC  ')
'ABC'
>>> Regex(r'this', regexOps=('I',)).to_python('THIS')
'THIS'

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
invalid:
The input is not valid
noneType:
The input must be a string (not None)
declarative_count = 19
regex = None
regexOps = ()
strip = False
validate_python(value, state)
class Relation(*args, **kw)

Bases: formencode.validators.OneOf

Checks if the item is inside a list of values and if “values” is callable it does a lazy call to lookup the values.

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
invalid:
Invalid value
noneType:
The input must be a string (not None)
notIn:
Value must be one of: %(items)s (not %(value)r)
declarative_count = 126
key = None
lookup = None
validate_python(value, state)
class Require(*args, **kws)

Bases: formencode.validators.FormValidator

Require for the id(or list of id) an input value.

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
declarative_count = 138
require = []
class RequireIfMissing(*args, **kw)

Bases: formencode.validators.FormValidator

This requires one field based on another field being present or missing. This is applied to a form, not an individual field (usually using a Schema’s pre_validators or chained_validators).

If you provide a missing value (a string key name) then if that field is missing the field must be entered. This gives you an either/or situation.

If you provide a present value (another string key name) then if that field is present, the required field must also be present.

>>> from formencode import validators
>>> v = validators.RequireIfPresent('phone_type',
...                                 present='phone')
>>> v.to_python({'phone_type':'', 'phone':'510 420  4577'})
Traceback (most recent call last):
    ...
Invalid: You must give a value for phone_type
>>> v.to_python({'phone': ''})
{'phone': ''}

Note that if you have a validator on the optionally-required field, you should probably use if_missing=None. This way you won’t get an error from the Schema about a missing value. For example:

class PhoneInput(Schema):
    phone = PhoneNumber()
    phone_type = String(if_missing=None)
    chained_validators = [RequireifPresent('phone_type', present='phone')]

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
declarative_count = 47
missing = None
present = None
required = None
RequireIfPresent

alias of RequireIfMissing

class RequireIfPresentSelected(*args, **kws)

Bases: formencode.validators.FormValidator

This requires one field based on another field being present or missing. This is applied to a form, not an individual field (usually using a Schema’s pre_validators or chained_validators).

If you provide a present value (another string key name) then if that field is present, the required field must also be present.

If you provide a selected value (value of the present key) then if that value is selected, the required field must also be present. You may pass a list of acceptable values.

>>> from formencode import validators
>>> v = validators.RequireIfPresent('phone_type',
...                                 present='phone')
>>> v.to_python({'phone_type':'', 'phone':'510 420  4577'})
Traceback (most recent call last):
    ...
Invalid: You must give a value for phone_type
>>> v.to_python({'phone': ''})
{'phone': ''}

Note that if you have a validator on the optionally-required field, you should probably use if_missing=None. This way you won’t get an error from the Schema about a missing value. For example:

class PhoneInput(Schema):
    phone = PhoneNumber()
    phone_type = String(if_missing=None)
    chained_validators = [RequireifPresent('phone_type', present='phone')]

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
declarative_count = 140
present = None
required = None
selected = None
class Schema(*args, **kw)

Bases: formencode.api.FancyValidator

A schema validates a dictionary of values, applying different validators (be key) to the different values. If allow_extra_fields=True, keys without validators will be allowed; otherwise they will raise Invalid. If filter_extra_fields is set to true, then extra fields are not passed back in the results.

Validators are associated with keys either with a class syntax, or as keyword arguments (class syntax is usually easier). Something like:

class MySchema(Schema):
    name = Validators.PlainText()
    phone = Validators.PhoneNumber()

These will not be available as actual instance variables, but will be collected in a dictionary. To remove a validator in a subclass that is present in a superclass, set it to None, like:

class MySubSchema(MySchema):
    name = None

Note that missing fields are handled at the Schema level. Missing fields can have the ‘missing’ message set to specify the error message, or if that does not exist the schema message ‘missingValue’ is used.

Messages

badDictType:
The input must be dict-like (not a %(type)s: %(value)r)
badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
missingValue:
Missing value
noneType:
The input must be a string (not None)
notExpected:
The input field %(name)s was not expected.
add_chained_validator = <bound class method Schema.add_chained_validator>
add_field = <bound class method Schema.add_field>
add_pre_validator = <bound class method Schema.add_pre_validator>
allow_extra_fields = False
assert_dict(value, state)

Helper to assure we have proper input

chained_validators = []
compound = True
declarative_count = 5
empty_value(value)
fields = {}
filter_extra_fields = False
if_key_missing

alias of NoDefault

ignore_key_missing = False
is_empty(value)
order = []
pre_validators = []
classmethod subvalidators()
class Set(*args, **kw)

Bases: formencode.api.FancyValidator

This is for when you think you may return multiple values for a certain field.

This way the result will always be a list, even if there’s only one result. It’s equivalent to ForEach(convertToList=True).

If you give use_set=True, then it will return an actual set object.

>>> Set.to_python(None)
[]
>>> Set.to_python('this')
['this']
>>> Set.to_python(('this', 'that'))
['this', 'that']
>>> s = Set(use_set=True)
>>> s.to_python(None)
set([])
>>> s.to_python('this')
set(['this'])
>>> s.to_python(('this',))
set(['this'])

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
declarative_count = 31
empty_value(value)
if_missing = ()
use_set = False
class SignedString(*args, **kw)

Bases: formencode.api.FancyValidator

Encodes a string into a signed string, and base64 encodes both the signature string and a random nonce.

It is up to you to provide a secret, and to keep the secret handy and consistent.

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
badsig:
Signature is not correct
empty:
Please enter a value
malformed:
Value does not contain a signature
noneType:
The input must be a string (not None)
declarative_count = 42
encode(value)
make_nonce()
nonce_length = 4
secret = None
class String(*args, **kw)

Bases: formencode.api.FancyValidator

Converts things to string, but treats empty things as the empty string.

Also takes a max and min argument, and the string length must fall in that range.

Also you may give an encoding argument, which will encode any unicode that is found. Lists and tuples are joined with list_joiner (default ', ') in from_python.

>>> String(min=2).to_python('a')
Traceback (most recent call last):
    ...
Invalid: Enter a value 2 characters long or more
>>> String(max=10).to_python('xxxxxxxxxxx')
Traceback (most recent call last):
    ...
Invalid: Enter a value less than 10 characters long
>>> String().from_python(None)
''
>>> String().from_python([])
''
>>> String().to_python(None)
''
>>> String(min=3).to_python(None)
Traceback (most recent call last):
    ...
Invalid: Please enter a value
>>> String(min=1).to_python('')
Traceback (most recent call last):
    ...
Invalid: Please enter a value

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
tooLong:
Enter a value less than %(max)i characters long
tooShort:
Enter a value %(min)i characters long or more
declarative_count = 29
empty_value(value)
encoding = None
list_joiner = ', '
max = None
min = None
not_empty = None
validate_other(value, state)
class StringBool(*args, **kw)

Bases: formencode.api.FancyValidator

Converts a string to a boolean.

Values like ‘true’ and ‘false’ are considered True and False, respectively; anything in true_values is true, anything in false_values is false, case-insensitive). The first item of those lists is considered the preferred form.

>>> s = StringBoolean()
>>> s.to_python('yes'), s.to_python('no')
(True, False)
>>> s.to_python(1), s.to_python('N')
(True, False)
>>> s.to_python('ye')
Traceback (most recent call last):
    ...
Invalid: Value should be 'true' or 'false'

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
string:
Value should be %(true)r or %(false)r
declarative_count = 41
false_values = ['false', 'f', 'no', 'n', 'off', '0']
true_values = ['true', 't', 'yes', 'y', 'on', '1']
StringBoolean

alias of StringBool

class StripField(*args, **kw)

Bases: formencode.api.FancyValidator

Take a field from a dictionary, removing the key from the dictionary.

name is the key. The field value and a new copy of the dictionary with that field removed are returned.

>>> StripField('test').to_python({'a': 1, 'test': 2})
(2, {'a': 1})
>>> StripField('test').to_python({})
Traceback (most recent call last):
    ...
Invalid: The name 'test' is missing

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
missing:
The name %(name)s is missing
noneType:
The input must be a string (not None)
declarative_count = 40
is_empty(value)
class TimeConverter(*args, **kw)

Bases: formencode.api.FancyValidator

Converts times in the format HH:MM:SSampm to (h, m, s). Seconds are optional.

For ampm, set use_ampm = True. For seconds, use_seconds = True. Use ‘optional’ for either of these to make them optional.

Examples:

>>> tim = TimeConverter()
>>> tim.to_python('8:30')
(8, 30)
>>> tim.to_python('20:30')
(20, 30)
>>> tim.to_python('30:00')
Traceback (most recent call last):
    ...
Invalid: You must enter an hour in the range 0-23
>>> tim.to_python('13:00pm')
Traceback (most recent call last):
    ...
Invalid: You must enter an hour in the range 1-12
>>> tim.to_python('12:-1')
Traceback (most recent call last):
    ...
Invalid: You must enter a minute in the range 0-59
>>> tim.to_python('12:02pm')
(12, 2)
>>> tim.to_python('12:02am')
(0, 2)
>>> tim.to_python('1:00PM')
(13, 0)
>>> tim.from_python((13, 0))
'13:00:00'
>>> tim2 = tim(use_ampm=True, use_seconds=False)
>>> tim2.from_python((13, 0))
'1:00pm'
>>> tim2.from_python((0, 0))
'12:00am'
>>> tim2.from_python((12, 0))
'12:00pm'

Examples with datetime.time:

>>> v = TimeConverter(use_datetime=True)
>>> a = v.to_python('18:00')
>>> a
datetime.time(18, 0)
>>> b = v.to_python('30:00')
Traceback (most recent call last):
    ...
Invalid: You must enter an hour in the range 0-23
>>> v2 = TimeConverter(prefer_ampm=True, use_datetime=True)
>>> v2.from_python(a)
'6:00:00pm'
>>> v3 = TimeConverter(prefer_ampm=True,
...                    use_seconds=False, use_datetime=True)
>>> a = v3.to_python('18:00')
>>> a
datetime.time(18, 0)
>>> v3.from_python(a)
'6:00pm'
>>> a = v3.to_python('18:00:00')
Traceback (most recent call last):
    ...
Invalid: You may not enter seconds

Messages

badHour:
You must enter an hour in the range %(range)s
badMinute:
You must enter a minute in the range 0-59
badNumber:
The %(part)s value you gave is not a number: %(number)r
badSecond:
You must enter a second in the range 0-59
badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
minutesRequired:
You must enter minutes (after a :)
noAMPM:
You must indicate AM or PM
noSeconds:
You may not enter seconds
noneType:
The input must be a string (not None)
secondsRequired:
You must enter seconds
tooManyColon:
There are too many :’s
datetime_module = None
declarative_count = 39
prefer_ampm = False
use_ampm = 'optional'
use_datetime = False
use_seconds = 'optional'
class URL(*args, **kw)

Bases: formencode.api.FancyValidator

Validate a URL, either http://... or https://. If check_exists is true, then we’ll actually make a request for the page.

If add_http is true, then if no scheme is present we’ll add http://

>>> u = URL(add_http=True)
>>> u.to_python('foo.com')
'http://foo.com'
>>> u.to_python('http://hahaha.ha/bar.html')
'http://hahaha.ha/bar.html'
>>> u.to_python('http://xn--m7r7ml7t24h.com')
'http://xn--m7r7ml7t24h.com'
>>> u.to_python('http://foo.com/test?bar=baz&fleem=morx')
'http://foo.com/test?bar=baz&fleem=morx'
>>> u.to_python('http://foo.com/login?came_from=http%3A%2F%2Ffoo.com%2Ftest')
'http://foo.com/login?came_from=http%3A%2F%2Ffoo.com%2Ftest'
>>> u.to_python('http://foo.com:8000/test.html')
'http://foo.com:8000/test.html'
>>> u.to_python('http://foo.com/something\nelse')
Traceback (most recent call last):
    ...
Invalid: That is not a valid URL
>>> u.to_python('https://test.com')
'https://test.com'
>>> u.to_python('http://test')
Traceback (most recent call last):
    ...
Invalid: You must provide a full domain name (like test.com)
>>> u.to_python('http://test..com')
Traceback (most recent call last):
    ...
Invalid: That is not a valid URL
>>> u = URL(add_http=False, check_exists=True)
>>> u.to_python('http://google.com')
'http://google.com'
>>> u.to_python('google.com')
Traceback (most recent call last):
    ...
Invalid: You must start your URL with http://, https://, etc
>>> u.to_python('http://ianbicking.org/doesnotexist.html')
Traceback (most recent call last):
    ...
Invalid: The server responded that the page could not be found
>>> u.to_python('http://this.domain.does.not.exist.example.org/test.html')
Traceback (most recent call last):
    ...
Invalid: An error occured when trying to connect to the server: ...

If you want to allow addresses without a TLD (e.g., localhost) you can do:

>>> URL(require_tld=False).to_python('http://localhost')
'http://localhost'

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
badURL:
That is not a valid URL
empty:
Please enter a value
httpError:
An error occurred when trying to access the URL: %(error)s
noScheme:
You must start your URL with http://, https://, etc
noTLD:
You must provide a full domain name (like %(domain)s.com)
noneType:
The input must be a string (not None)
notFound:
The server responded that the page could not be found
socketError:
An error occured when trying to connect to the server: %(error)s
status:
The server responded with a bad status code (%(status)s)
add_http = True
check_exists = False
declarative_count = 33
require_tld = True
scheme_re = <_sre.SRE_Pattern object at 0x8f6eb60>
url_re = <_sre.SRE_Pattern object at 0x9207f88>
class UnicodeString(inputEncoding=None, outputEncoding=None, **kw)

Bases: formencode.validators.UnicodeString

The FormEncode UnicodeString validator encodes strings as utf-8 for display. However, this is not desired behaviour in tw.forms, as Genshi will fail when it receives such strings. Instead, this validator renders Python unicode objects where possible, strings otherwise.

Messages

badEncoding:
Invalid data or incorrect encoding
badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
tooLong:
Enter a value less than %(max)i characters long
tooShort:
Enter a value %(min)i characters long or more
declarative_count = 122
class Unique(*args, **kw)

Bases: formencode.validators.FormValidator

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
unique:
Must be unique
declarative_count = 139
entity = None
storage = None
unique = None
class Validator(*args, **kw)

Bases: formencode.declarative.Declarative

The base class of most validators. See IValidator for more, and FancyValidator for the more common (and more featureful) class.

Messages

classmethod all_messages()

Return a dictionary of all the messages of this validator, and any subvalidators if present. Keys are message names, values may be a message or list of messages. This is really just intended for documentation purposes, to show someone all the messages that a validator or compound validator (like Schemas) can produce.

@@: Should this produce a more structured set of messages, so that messages could be unpacked into a rendered form to see the placement of all the messages? Well, probably so.

compound = False
declarative_count = 1
classmethod from_python(value, state=None)
gettextargs = {'domain': 'FormEncode'}
if_missing

alias of NoDefault

classmethod message(msgName, state, **kw)
repeating = False
classmethod subvalidators()

Return any validators that this validator contains. This is not useful for functional, except to inspect what values are available. Specifically the .all_messages() method uses this to accumulate all possible messages.

classmethod to_python(value, state=None)
use_builtins_gettext = True
class Wrapper(*args, **kw)

Bases: formencode.api.FancyValidator

Used to convert functions to validator/converters.

You can give a simple function for to_python, from_python, validate_python or validate_other. If that function raises an exception, the value is considered invalid. Whatever value the function returns is considered the converted value.

Unlike validators, the state argument is not used. Functions like int can be used here, that take a single argument.

Examples:

>>> def downcase(v):
...     return v.lower()
>>> wrap = Wrapper(to_python=downcase)
>>> wrap.to_python('This')
'this'
>>> wrap.from_python('This')
'This'
>>> wrap2 = Wrapper(from_python=downcase)
>>> wrap2.from_python('This')
'this'
>>> wrap2.from_python(1)
Traceback (most recent call last):
  ...
Invalid: 'int' object has no attribute 'lower'
>>> wrap3 = Wrapper(validate_python=int)
>>> wrap3.to_python('1')
'1'
>>> wrap3.to_python('a') 
Traceback (most recent call last):
  ...
Invalid: invalid literal for int()...

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
declarative_count = 13
func_from_python = None
func_to_python = None
func_validate_other = None
func_validate_python = None
wrap(func)
class XRI(add_xri=False, xri_type='i-name', **kwargs)

Bases: formencode.api.FancyValidator

Validator for XRIs.

It supports both i-names and i-numbers, of the first version of the XRI standard.

>>> inames = XRI(xri_type="i-name")
>>> inames.to_python("   =John.Smith ")
'=John.Smith'
>>> inames.to_python("@Free.Software.Foundation")
'@Free.Software.Foundation'
>>> inames.to_python("Python.Software.Foundation")
Traceback (most recent call last):
    ...
Invalid: The type of i-name is not defined; it may be either individual or organizational
>>> inames.to_python("http://example.org")
Traceback (most recent call last):
    ...
Invalid: The type of i-name is not defined; it may be either individual or organizational
>>> inames.to_python("=!2C43.1A9F.B6F6.E8E6")
Traceback (most recent call last):
    ...
Invalid: "!2C43.1A9F.B6F6.E8E6" is an invalid i-name
>>> iname_with_schema = XRI(True, xri_type="i-name")
>>> iname_with_schema.to_python("=Richard.Stallman")
'xri://=Richard.Stallman'
>>> inames.to_python("=John Smith")
Traceback (most recent call last):
    ...
Invalid: "John Smith" is an invalid i-name
>>> inumbers = XRI(xri_type="i-number")
>>> inumbers.to_python("!!1000!de21.4536.2cb2.8074")
'!!1000!de21.4536.2cb2.8074'
>>> inumbers.to_python("@!1000.9554.fabd.129c!2847.df3c")
'@!1000.9554.fabd.129c!2847.df3c'

Messages

badIname:
%(iname)s” is an invalid i-name
badInameStart:
i-names may not start with numbers nor punctuation marks
badInumber:
%(inumber)s” is an invalid i-number
badType:
The XRI must be a string (not a %(type)s: %(value)r)
badXri:
%(xri_type)s” is not a valid type of XRI
empty:
Please enter a value
noType:
The type of i-name is not defined; it may be either individual or organizational
noneType:
The input must be a string (not None)
repeatedChar:
Dots and dashes may not be repeated consecutively
declarative_count = 34
iname_invalid_start = <_sre.SRE_Pattern object at 0x948b520>
iname_valid_pattern = <_sre.SRE_Pattern object at 0x9252b18>
inumber_pattern = <_sre.SRE_Pattern object at 0x8e85820>
validate_python(value, state=None)

Validate an XRI

@raise Invalid: If at least one of the following conditions in met:
  • C{value} is not a string.

  • The XRI is not a personal, organizational or network one.

  • The relevant validator (i-name or i-number) considers the XRI

    is not valid.

endian.core.session_cache module

session_cached_function(key, func, application=False, *args, **kwargs)
session_cached_property(key, func, application=False, *args, **kwargs)
session_cache_delete()

Remove all the elements stored in the current user’s cache

endian.core.set_diff module

set_diff(a, b)

Compares the set a and b and return the elements that are only in a, only in b and in both the set. It a and b are lists, they are converted to sets.c

Parameters:
  • a (set (or iterable to be converted to set)) – first set to be compared
  • b (set (or iterable to be converted to set)) – second set to be compared
Returns:

a set of elements only in a, a set of elements only in b, a set of common elements

Return type:

tuple of set

endian.core.settingsfile module

This is a wrapper for endian.data.container.settings

endian.core.sha512crypt module

sha512crypt(word, salt=None, rounds=5000)

The sha512crypt() function performs password encryption, based on the SHA-512 Crypt developed in 2008 by Ulrich Drepper.

Parameters:
  • word (str or unicode) – the password to be encrypted
  • salt (str or unicode) – an optional salt with characters in in the set [./a-zA-Z0-9] or a full crypted password
  • rounds (int) – optional number of rounds (must be > 1000, default is 5000)
Returns:

An sha512-crypt hash string has the format: $6$[rounds=<ROUNDS>]$<SALT>$<PWD> The default number of rounds (if omitted) is 5000.

Return type:

str

endian.core.smart module

class SmartManager(log=None, proxy=None)

Bases: object

Interface for the Smart Package Manager

add_channel(channel_alias, url, name, type)

Add a channel. If the channel exists, first delete the old channel

Parameters:
  • channel_alias (string) – channel alias, e.g. ‘rpm-sys’, ‘efw2.3-base’
  • url (string) – channel url
  • name (string) – name, e.g. ‘Endian Firewall 2.3’
  • type (string) – type, e.g. ‘rpm-md’
Returns:

True if ok, False if channel not found

Return type:

boolean

channel_list()

Returns the output of ‘smart channel –show’ as a dictionary, e.g.:

{
    'rpm-sys': {'type': 'rpm-sys', 'name': 'RPM System'},
    'aaabbbb': {'baseurl': 'http://...', 'name': 'AAA BBB', 'type': 'rpm-md'}
}
Returns:channel list
Return type:dict
get_channel(channel_alias)

Returns a channel by its alias

Parameters:channel_alias (string) – channel alias, e.g. ‘rpm-sys’, ‘efw2.3-base’
Returns:channel info as a dictionary, e.g. {‘baseurl’: ‘http://...’, ‘name’: ‘AAA BBB’, ‘type’: ‘rpm-md’} or None
Return type:dict
install_package(package_name, interface='endian')

Install a package

Parameters:package_name (string) – package name
Returns:True if no error, False otherwise
Return type:boolean
remove_channel(channel_alias)

Remove a channel by its alias

Parameters:channel_alias (string) – channel alias, e.g. ‘rpm-sys’, ‘efw2.3-base’
Returns:True if ok, False if channel not found
Return type:boolean
remove_package(package_name, interface='endian')

Remove a package

Parameters:package_name (string) – package name
Returns:True if no error, False otherwise
Return type:boolean
updatable_packages(interface='endian')

Return the number of updatable packages

return:The number of updatable packages
rtype:int
update(interface='endian')

Exec the ‘smart update’ command

Returns:True if no error, False otherwise
Return type:boolean

endian.core.spawnverbose module

— spawnverbose —

spawns a command, logs its output and returns the exitcode

@author Peter Warasin <peter@endian.com> @copyright (c) Endian 2007

class Popen(args, bufsize=0, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=False, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0, ignoreSignals=[])

Bases: subprocess.Popen

exception TimeoutException

Bases: exceptions.Exception

Will be thrown if a timeout has been exceeded.

spawn(cmd, errlevel=20, ignoreSignals=[], timeout=-1)

Spawns a command and returns the return code

errlevel sets the logging level with which the output should be logged when the command returns with an error. if ignoreSignals is True, the spawned process will ignore all signals. if timeout is greater than 0, the spawned process will be killed after timeout seconds, if it will not exit and let spawn() return.

endian.core.timetools module

utcnow()

Return a new datetime representing UTC day and time.

now()

[tz] -> new datetime with tz’s local day and time.

class timedelta

Bases: object

Difference between two datetime values.

days

Number of days.

max = datetime.timedelta(999999999, 86399, 999999)
microseconds

Number of microseconds (>= 0 and less than 1 second).

min = datetime.timedelta(-999999999)
resolution = datetime.timedelta(0, 0, 1)
seconds

Number of seconds (>= 0 and less than 1 day).

total_seconds()

Total seconds in the duration.

format_time(seconds=0, days=0, hide_seconds=False, abbreviate=False)

Format a temporal interval in a human readable format

Parameters:
  • seconds (integer) – number of seconds
  • days (integer) – number of days
  • hide_seconds (boolean) – if true, don’t display the seconds
  • abbreviate (boolean) – if true, hide the secconds if the temporal interval is longer than one day and hide the seconds, minutes and hours if it is longer than one month
Returns:

the formatted temporal interval

Return type:

str

is_same_day(date1, date2)

Checks if two dates are on the same day ignoring time.

get_timezone_tuple()
get_timezone_string()
datetime_from_ISO8601(datestring)

Parses ISO 8601 dates into datetime objects. The timezone is ignored, means we expect the ISO8601 datestring uses the local timezone. If you know that it is UTC and you want it to be local time, use utcdatetime_to_datetime.

datetime_to_ISO8601(datetime_object)

convert datetime object to ISO 8601 with localtimezone

utcdatetime_from_datetime(datetime_object)

convert datetime object with local timezone to utc datetime object

utcdatetime_to_datetime(utcdatetime_object)

convert utc datetime object into datetime object with local timezone

datetime_from_timestamp(timestamp)

convert timestamp into datetime object

datetime_to_timestamp(datetime_object)

convert datetime object into timestamp

endian.core.treefilter module

join(left, right, leftid, rightid, targetnode='', select=None, mapper=None)

Iterates the root nodes of the ‘’‘right’‘’ tree and merges the values of corresponding ‘rows’ of the ‘’‘left’‘’ tree.

‘’‘leftid’‘’ and ‘’‘rightid’‘’ are those id’s of the tree’s which will be compared in order to check if the records correspond.

‘’‘targetnode’‘’ is the address of the subtree of the left tree to which the values from the right tree should be merged. For example: ‘actions.mail’

‘’‘select’ is a list of keys which should be taken from right to merge into left.

‘’‘mapper’‘’ is a dict which maps right key names to left key names, while the right key name is the dict’s key and the left key name is the dict’s value. During merge this mapping will be applied to the key names which will me merged from right data to left data.

take(root, path)

Returns a subtree of root identified by ‘’‘path’‘’. ‘’‘path’‘’ is a string containing node names separated by ‘.’.

For example: ‘actions.mail’, returns root[‘actions’][‘mail’]

takeCached(root, path, cache, onExpire=None, onPut=None, onGet=None)

Same as take(), but caches values within cache object ‘cache’ onExpire: callback called when item expires onPut: callback called when item will be replaced in cache onGet: callback called when item will be read out

toBool(value, default=False)

transforms ‘’‘value’‘’ to a boolean value.

In order to return True, ‘’‘value’‘’ may be one of (case insensitive) ‘on’, 1, ‘1’, True, ‘enabled’

If the value does not correspond to True or False, for example ‘’ or None, the value of ‘’‘default’‘’ will be returned, which is False if not specified.

Parameters:
  • value (any) – value to transform to boolean
  • default (boolean) – value to return when no corresponding boolean value for ‘’‘value’‘’ could be found. Defaults to False.
Return type:

boolean

Returns:

corresponding boolean value of ‘’‘value’‘’

endian.core.usb module

getDrivers(u_vendor, u_product)
unloadDrivers(u_vendor, u_product)

endian.core.users module

collectUsersData()

Collect information about the users on this system.

countArpEntries()

Count the number of arp entries.

countHotspotUsers()

Count the number of hotspot users.

countIpsecUsers()

Count the number of IPsec users.

countVpnUsers()

Count the number of VPN users.

endian.core.utmp module

read_utmp(filename='/var/run/utmp')

Read all the entries from the utmp file and return a list of UtmpLine instances

Parameters:filename (string) – The path of the utmp file (default: /var/run/utmp)
read_wtmp(filename='/var/log/wtmp')

Read all the entries from the wtmp file and return a list of UtmpLine instances

Parameters:filename (string) – The path of the utmp file (default: /var/log/wtmp)
update_utmp(filename='/var/run/utmp', line=None, type=None, user=None, host=None, pid=None)

Update an utmp entry identified by a line (the default value for the line is the current tty)

Parameters:
  • filename (string) – The path of the utmp file (default: /var/run/utmp)
  • line (string (e.g. /dev/tty1)) – The line to update (the default value for the line is the current tty)
  • time – The entry type (LOGIN_PROCESS, USER_PROCESS, ...)
  • user (string) – The user name
  • user – The user’s remote host name (default: None)
  • pid (int) – Process id (default: current pid)
class Wtmp(filename='/var/log/wtmp')

Bases: UserList.UserList

Parse the wtmp file

last()

Returns the content of the wtmp file in a format similar to the last command

endian.core.version module

get_architecture()

Returns the machine type.

Returns:machine type, e.g. ‘i686’, ‘armv5tel’
Return type:str

endian.core.widget module

class AccordionWidget(accordion)

Bases: endian.core.widget.BaseWidget

params (hashref):

V_ACCORDION (required)
desc - value -
T_TITLE (required)
desc - value -
T_DESCRIPTION (required)
desc - value -
T_SAVE_BUTTON (optional)
desc - value -
H_CONTAINER (required)
desc - value -
V_HIDDEN (optional)
desc - value -
T_STARTONLY (optional)
desc - for backwards compatability to use instead of openbox value -
T_ENDONLY (optional)
desc - for backwards compatability to use instead of openbox value -
filename = '/usr/share/efw-gui/core/widgets/accordion.pltmpl'
class ApplyBubbleWidget(message, applyaction, applytext)

Bases: endian.core.widget.BaseWidget

params (hashref):
T_MESSAGE (required)
desc - the text that should be displayed in the bubble
V_APPLY_ACTION (required)
desc - the action for the form that is triggered when the apply button is clicked
T_APPLY (required)
desc - the value of the ‘Apply’ button
filename = '/usr/share/efw-gui/core/widgets/bubble_apply.pltmpl'
class BaseWidget(filename, cheetah=False)

Bases: object

cheetah = False
display(content_type='text/html')
filename = None
getString(exception=False)
isTrue(x)
set(name, value)
setValue(name, value)
values = {}
class BubbleWidget(color, message, style=None)

Bases: endian.core.widget.BaseWidget

params (hashref):
V_COLOR (required)
desc - the color of the bubble (red or yellow) value - red/yellow
T_MESSAGE (required)
desc - the text that should be displayed in the bubble
V_STYLE (optional)
desc - optional styles for the bubble
filename = '/usr/share/efw-gui/core/widgets/bubble.pltmpl'
class CategoryWidget(title, name, subcategories, hidden=False)

Bases: endian.core.widget.BaseWidget

params (hashref):

T_TITLE (required)
desc - value -
V_NAME (required)
desc - value -
V_HIDDEN (optional)
desc - defines if this field is visible value - 1 if true, 0 if false (default=0)
V_SUBCATEGORIES (required)
desc - value -
T_TITLE (required)
desc - value -
V_NAME (required)
desc - value -
V_ALLOWED (optional)
desc - value -
filename = '/usr/share/efw-gui/core/widgets/category.pltmpl'
class CheckboxFieldWidget(id, name, value, checkbox, required=False, hidden=False, checked=False, disabled=False, toggle_id=None, label=None)

Bases: endian.core.widget.BaseWidget

params (hashref):
V_ID (required)
desc - id of the field, label id=<id>_field value - string required
V_NAME (required)
desc - name of the field, used by post value - string
V_VALUE (required)
desc - value of the field value - string
V_CHECKED (optional)
desc - status of the checkbox value - 1 if true, 0 if false (default=0)
V_REQUIRED (optional)
desc - show * if required value - 1 if true, 0 if false (default=0)
V_HIDDEN (optional)
desc - defines if this field is visible value - 1 if true, 0 if false (default=0)
V_DISABLED (optional)
desc - value of the field value - 1 if true, 0 if false (default=0)
V_TOGGLE_ID (optional)
desc - id of field which toggles this field value - string (default=undefined)
T_LABEL (optional)
desc - label text which descripes the field value - string (default=undefined)
T_CHECKBOX (required)
desc - label text which descripes the field value - string
filename = '/usr/share/efw-gui/core/widgets/checkbox.pltmpl'
class EmptyFieldWidget(hidden=None, toggle_id=None)

Bases: endian.core.widget.BaseWidget

params (hashref):
V_HIDDEN (optional)
desc - defines if this field is visible value - 1 if true, 0 if false (default=0)
V_TOGGLE_ID (optional)
desc - id of field which toggles this field value - string (default=undefined)
filename = '/usr/share/efw-gui/core/widgets/empty.pltmpl'
class FormWidget(fields)

Bases: endian.core.widget.BaseWidget

params (hashref):

V_FIELDS (required)
desc - value of the field value - array
V_HIDDEN (optional)
desc - defines if this field is visible (only needed if a field needs to be toggled by 2 diffrent toggle_ids) value - 1 if true, 0 if false (default=0)
V_TOGGLE_ID (optional)
desc - id of field which toggles this field (only needed if a field needs to be toggled by 2 diffrent toggle_ids) value - string (default=undefined)
H_FIELD (required)
desc - html code of the field value - valid html
Returns:rendered html code
filename = '/usr/share/efw-gui/core/widgets/form.pltmpl'
class ListTableWidget(headings, rows, actions=0, id=None)

Bases: endian.core.widget.BaseWidget

disableAction(type)
enableAction(type)
filename = '/usr/share/efw-gui/core/widgets/listtable.pltmpl'
getString(ex)
class MainPageWidget(title, filename)

Bases: endian.core.widget.BaseWidget

addCSSInclude(url)
addJSInclude(url)
getString(exception=False)
setContent(content)
class MultiSelectFieldWidget(id, name, options, required=False, hidden=False, disabled=False, toggle_action=False, toggle_id=None, label=None, size='9')

Bases: endian.core.widget.SelectFieldWidget

params (hashref):

V_ID (required)
desc - id of the field, label id=<id>_field value - string required
V_NAME (required)
desc - name of the field, used by post value - string
V_OPTIONS (required)
desc - array of the options for the select box value - array
V_VALUE (required)
desc - value of the option value - string
V_SELECTED (required)
desc - defines if option is selected value - string
T_OPTION (optional)
desc - text which describes the option value - string (default=<V_VALUE> not implemented yet)
V_SIZE (optional)
desc - size of input field value - int (default=9)
V_REQUIRED (optional)
desc - show * if required value - 1 if true, 0 if false (default=0)
V_HIDDEN (optional)
desc - defines if this field is visible value - 1 if true, 0 if false (default=0)
V_DISABLED (optional)
desc - value of the field value - 1 if true, 0 if false (default=0)
V_TOGGLE_ID (optional)
desc - id of field which toggles this field value - string (default=undefined)
T_LABEL (optional)
desc - label text which descripes the field value - string (default=undefined)
filename = '/usr/share/efw-gui/core/widgets/multiselect.pltmpl'
class PasswordFieldWidget(id, name, value, required=False, hidden=False, disabled=False, size='30', maxlength=None, toggle_id=None, label=None)

Bases: endian.core.widget.TextFieldWidget

params (hashref):
V_ID (required)
desc - id of the field, label id=<id>_field value - string required
V_NAME (required)
desc - name of the field, used by post value - string
V_VALUE (required)
desc - value of the field value - string
V_REQUIRED (optional)
desc - show * if required value - 1 if true, 0 if false (default=0)
V_HIDDEN (optional)
desc - defines if this field is visible value - 1 if true, 0 if false (default=0)
V_DISABLED (optional)
desc - value of the field value - 1 if true, 0 if false (default=0)
V_SIZE (optional)
desc - size of input field value - int (default=30)
V_MAXLENGTH (optional)
desc - max length of value value - int optional (default=undefined)
V_TOGGLE_ID (optional)
desc - id of field which toggles this field value - string (default=undefined)
T_LABEL (optional)
desc - label text which descripes the field value - string (default=undefined)
filename = '/usr/share/efw-gui/core/widgets/password.pltmpl'
class RadiobuttonFieldWidget(id, name, options, description=None, required=False, label=None, hidden=False)

Bases: endian.core.widget.BaseWidget

params (hashref):
V_ID (required)
desc - id of the field, label id=<id>_field value - string
T_NAME (required)
desc - name of the field, used by post value - string
V_OPTIONS (required)
desc - value of the field value - string
V_VALUE (required)
desc - value of the option value - string
V_CHECKED (required)
desc - defines if option is selected value - string
T_DESCRIPTION (required)
desc - text which describes the option value - string (default=<V_VALUE> not implemented yet)
T_DESCRIPTION (optional)
desc - text which describes the radiobutton-group value - string
V_REQUIRED (optional)
desc - show * if required value - 1 if true, 0 if false (default=0)
V_HIDDEN (optional)
desc - defines if this field is visible value - 1 if true, 0 if false (default=0)
T_LABEL (optional)
desc - label text which descripes the field value - string (default=undefined)
filename = '/usr/share/efw-gui/core/widgets/radiobutton.pltmpl'
class SelectFieldWidget(id, name, options, required=False, hidden=False, disabled=False, toggle_action=False, toggle_id=None, label=None)

Bases: endian.core.widget.BaseWidget

params (hashref):
V_ID (required)
desc - id of the field, label id=<id>_field value - string required
V_NAME (required)
desc - name of the field, used by post value - string
V_OPTIONS (required)
desc - array of the options for the select box value - array
V_VALUE (required)
desc - value of the option value - string
V_SELECTED (required)
desc - defines if option is selected value - string
T_OPTION (optional)
desc - text which describes the option value - string (default=<V_VALUE> not implemented yet)
V_REQUIRED (optional)
desc - show * if required value - 1 if true, 0 if false (default=0)
V_HIDDEN (optional)
desc - defines if this field is visible value - 1 if true, 0 if false (default=0)
V_DISABLED (optional)
desc - value of the field value - 1 if true, 0 if false (default=0)
V_TOGGLE_ACTION (optional)
desc - defines if field toggles other fields, uses <TOGGLE_ID> to identify the other fields value - 1 if true, 0 if false (default=0)
V_TOGGLE_ID (optional)
desc - id of field which toggles this field value - string (default=undefined)
T_LABEL (optional)
desc - label text which descripes the field value - string (default=undefined)
filename = '/usr/share/efw-gui/core/widgets/select.pltmpl'
class SubsectionWidget(id, submenues)

Bases: endian.core.widget.BaseWidget

filename = '/usr/share/efw-gui/core/widgets/subsection.pltmpl'
class SwitchWidget(script_name, service_validation, service_notification_name, service_on, service_ajaxian_save, service_partial_reload, options_container, service_title, service_starting, service_shutdown, service_restarting, service_description, service_save)

Bases: endian.core.widget.BaseWidget

example param hash (all keys are needed!!!!):

my %params = (
    P_SCRIPT_NAME => $ENV{'SCRIPT_NAME'}, # empty string is $ENV{'SCRIPT_NAME}

    V_SERVICE_VALIDATION => "", # needs to be the name of the validation js function (empty string => null)

    V_SERVICE_NOTIFICATION_NAME => "smtp", # empty string deactivates the ajax notification (can also be a list of names: snort, snort-rules)

    V_SERVICE_ON => 1, # required # 1 or 0 (empty == 0)
    V_SERVICE_AJAXIAN_SAVE => 0, # 1 or 0 (empty == 0)
    V_SERVICE_PARTIAL_RELOAD => 0, # 1 or 0 (empty == 0)

    H_OPTIONS_CONTAINER => $template,

    T_SERVICE_TITLE => _('Enable SMTP Proxy'),
    T_SERVICE_STARTING => _("The SMTP Proxy is being enabled. Please hold..."),
    T_SERVICE_SHUTDOWN => _("The SMTP Proxy is being disabled. Please hold..."),
    T_SERVICE_RESTARTING => _("Settings are saved and the SMTP Proxy is being restarted. Please hold..."),
    T_SERVICE_DESCRIPTION => _("Use the switch above to set the status of the SMTP Proxy. Click on the save button below to make the changes active."),
    T_SERVICE_SAVE => _("Save and restart") # empty string is _("Save")
);
filename = '/usr/share/efw-gui/core/widgets/switch.pltmpl'
class TextFieldWidget(id, name, value, required=False, hidden=False, disabled=False, size='30', maxlength=None, toggle_id=None, label=None)

Bases: endian.core.widget.BaseWidget

params (hashref):
V_ID (required)
desc - id of the field, label id=<id>_field value - string required
V_NAME (required)
desc - name of the field, used by post value - string
V_VALUE (required)
desc - value of the field value - string
V_REQUIRED (optional)
desc - show * if required value - 1 if true, 0 if false (default=0)
V_HIDDEN (optional)
desc - defines if this field is visible value - 1 if true, 0 if false (default=0)
V_DISABLED (optional)
desc - value of the field value - 1 if true, 0 if false (default=0)
V_SIZE (optional)
desc - size of input field value - int (default=30)
V_MAXLENGTH (optional)
desc - max length of value value - int optional (default=undefined)
V_TOGGLE_ID (optional)
desc - id of field which toggles this field value - string (default=undefined)
T_LABEL (optional)
desc - label text which descripes the field value - string (default=undefined)
filename = '/usr/share/efw-gui/core/widgets/text.pltmpl'
class TextareaFieldWidget(id, name, value, required=False, hidden=False, disabled=False, cols='28', rows='10', toggle_id=None, label=None)

Bases: endian.core.widget.BaseWidget

params (hashref):
V_ID (required)
desc - id of the field, label id=<id>_field value - string required
V_NAME (required)
desc - name of the field, used by post value - string
V_VALUE (required)
desc - value of the field value - string
V_REQUIRED (optional)
desc - show * if required value - 1 if true, 0 if false (default=0)
V_HIDDEN (optional)
desc - defines if this field is visible value - 1 if true, 0 if false (default=0)
V_DISABLED (optional)
desc - value of the field value - 1 if true, 0 if false (default=0)
V_COLS (optional)
desc - cols of textarea field value - int (default=28)
V_ROWS (optional)
desc - rows of textarea field value - int (default=10)
V_TOGGLE_ID (optional)
desc - id of field which toggles this field value - string (default=undefined)
T_LABEL (optional)
desc - label text which descripes the field value - string (default=undefined)
filename = '/usr/share/efw-gui/core/widgets/textarea.pltmpl'
class ZoneStatusWidget

Bases: endian.core.widget.BaseWidget

filename = '/usr/share/efw-gui/core/widgets/zonestatus.pltmpl'

endian.core.zones module

cidrnet2nmnet(net)

Converts ip/cidr to ip/netmask

@param net: netaddress in ip/cidr format @type net: string

@returns netaddress in ip/netmask format

getZones()

reads zones and their settings for future support of datasource

@returns boolean

hasBlue()

checks if blue zone exists

@returns boolean

hasOrange()

checks if orange zone exists

@returns boolean

Table Of Contents

Previous topic

endian.commands.web package

Next topic

endian.core.development package