Install the alteration monitor, which execute a function when monitored python source files change.
Parameters: |
|
---|
Change the terminal line settings to a sane state, like the ‘stty sane’ command
Bases: object
Bases: exceptions.Exception
Bases: object
Bases: object
Is an expirer which allows to define a timeout of how long the object should be kept in cache.
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
Register a command (or a status) based on a command name command (Example ‘module.command’)
Lookup a command in the command registry
Return the global commmand registry
Parameters: |
|
---|
Unregister a command (or a status) based on a command name command (Example ‘module.command’)
Register a command (or a status) based on a command name command (Example ‘module.command’)
Lookup a command in the command registry
Return the global commmand registry
Parameters: |
|
---|
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 |
---|
Bases: optparse.OptParseError
Bases: optparse.OptParseError
Bases: exceptions.Exception
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 |
Register a dict of commands under a common prefix
Return true if the output format of the command is forced to JSON.
Force the JSON output format to an Emi command:
@force_json_output
def login_test(name, password):
...
Loads the CSV file and populates a dictionary with representations of the supplied class containing the read data.
Stores the current configuration into a file
If no filename is set then it uses the filename of currently opened file.
Bases: exceptions.Exception
Generic daemon class which implements all generic handling which is necessary to have a daemon work correctly in a linux environment.
Bases: object
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.
Detach a process from the controlling terminal and run it in the background as a daemon.
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.
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.
Retrieves a http file.
The function will take care of eventual passed authentication parameters(webuser, webpass) or a passed upstream proxy setting.
Parameters: |
|
---|---|
Returns: | A file like object, see urllib2. |
Return type: | file like object |
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: |
|
---|---|
Returns: | The lines of the requested file. |
Return type: | String |
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: |
|
---|---|
Returns: | The lines of the requested file. |
Return type: | String |
Enhanced version of the enumerate function
Parameters: | sequence (must be a sequence, an iterator, or some other object which supports iteration.) – a sequence |
---|---|
Returns: |
|
Bases: object
Register a new event type that can be used for subscribing functions to trigger
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.
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.
Bases: exceptions.Exception
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
Bases: str
Bases: str
Bases: type
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:
DEBUG log level which enables logging of caller filename:function:lineno
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.
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.
Post log messages of type info and error to the notification service
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)
True if logger has notification service
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)
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.
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 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.
Disables the specified log handler.
Parameters: | id (string) – The log handler id. Valid id’s are: ‘file’, ‘syslog’, ‘console’ |
---|
Enables the specified log handler.
Parameters: | id (string) – The log handler id. Valid id’s are: ‘file’, ‘syslog’, ‘console’ |
---|
Post log messages of type info and error to the notification service
Default logger to which buildin logging functions are bound
Sets the name for a log section and should be called at the top of a method.
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.
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
Clones LVM volumes from backup and calls a callback function at the end.
Clones LVM volumes and calls a callback function at the end.
Returns the free space in a volume group in megabytes.
Returns the size of a volume group in megabytes.
Returns a list of volume names of a volume group
Returns the volume size in megabytes.
Check whether we are using LVM or not.
Reverts LVM volumes to a previously created snapshot.
magicset.py
Created by Raphael Vallazza on 2007-04-23. Copyright (c) 2007 Endian. All rights reserved.
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)
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.
Returns an md5 hash for file fname, or stdin if fname is “-”.
Returns an md5 hash for an object with read() method.
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())
monit.py
Created by Raphael Vallazza on 2007-02-19. Copyright (c) 2007 Endian. All rights reserved.
— mutex class — @author Peter Warasin <peter@endian.com> @copyright (c) Endian 2008
implements file mutex
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:
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()
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.
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:
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.
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"}]
Tell subscribers that no notifications will follow.
Post an error wich occured during execution of the service.
Post an update of the service status.
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.
Release lock and remove the status file.
Convert object to JSON and write the result to the status file.
Arguments:
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.
Bases: endian.core.mutex.FileMutex
Extends FileMutex class with file-like access options.
Flush the file buffer.
Modify the offset of the locked file-descriptor.
Return the current offset the locked file-descriptor.
Truncate the file to the given size.
Write data into the file.
Bases: endian.core.pattern.Observer
Bases: UserDict.DictMixin
Persistent dictionary, stored with pickle
Check if the file has been updated after the last loading
Remove all items from the dictionary.
Test for the presence of key in the dictionary.
Test for the presence of key in the dictionary.
Return an iterator over the dictionary’s (key, value) pairs.
Return an iterator over the dictionary’s keys.
Return an iterator over the dictionary’s values.
Return a copy of the dictionary’s list of keys.
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.
Update the dictionary with the key/value pairs from other, overwriting existing keys
Store the content of the dictionary on the disk
Update the dictionary with the key/value pairs from other, overwriting existing keys
Return a copy of the dictionary’s list of (key, value) pairs.
— pidfile class — @author Peter Warasin <peter@endian.it> @copyright (c) Endian 2007
handles pidfiles
Bases: exceptions.Exception
Another process is already running
Bases: exceptions.Exception
Happens if pid could not read
Bases: exceptions.Exception
Happens if pid file already exists
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)
reads out the PID from the pidfile and returns it.
Throws InvalidPid if the PID is no valid PID number.
Checks if the Process which created this PID file is running.
reads out the PID from the pidfile and returns it.
Throws InvalidPid if the PID is no valid PID number.
Removes the pidfile
Checks if the Process which created this PID file is running.
Bases: exceptions.Exception
Bases: object
Manage a list of reserved networks
Add a network to the reserved networks
Raises: |
|
---|---|
Parameters: | cidr (string or iplib.CIDR) – a network address in CIDR notation |
Number of reserved addresses
Number of not reserved addresses Warning! If there are some ‘forced’ networks (i.e. networks conflicts), this number is wrong!
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 |
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 |
Return the size of the largest available block
Remove a network from the reserved networks
Raises: |
|
---|---|
Parameters: | cidr (string or iplib.CIDR) – a network address in CIDR notation |
Search for a free network address in a given address range
Raises AddressNotInRange: | |
---|---|
if the cidr is outside the address range |
|
Parameters: |
|
Returns: | return a network in CIDR notation or None if there is not enough space |
Return type: | string |
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 for a free network address (in a given address range) to be allocated
Raises AddressSpaceExhausted: | |
---|---|
if there is not enough allocable space |
|
Parameters: |
|
Returns: | return a network in CIDR notation |
Return type: | string |
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 |
Bases: exceptions.Exception
Bases: exceptions.Exception
Bases: telnetlib.Telnet
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.
Joins several validators together as a single validator, filtering out None and trying to keep All validators from being nested (which isn’t needed).
Adds the validator (or list of validators) to a copy of this validator.
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)
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
Bases: formencode.api.FancyValidator
Validator to check whether a string is in correct CIDR notation (IP address, or IP address plus /mask)
Messages
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
Bases: formencode.api.FancyValidator
Confirms that the input/output is of the proper type.
Uses the parameters:
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
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
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
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
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
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
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
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:
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:
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:
Messages
Encode a string in base64, stripping whitespace and removing newlines.
A validation method that doesn’t do anything.
A validation method that doesn’t do anything.
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
Bases: formencode.validators.FormValidator
Validator for checking if more then a defined count of items with a fieldvalue already exist.
Messages
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
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
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.
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
Bases: formencode.api.FancyValidator
Validator to check whether a string is a correct IP address
Messages
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
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
Bases: exceptions.Exception
This is raised in response to invalid input. It has several public attributes:
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
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
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
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
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
Bases: formencode.foreach.ForEach
Bases: formencode.foreach.ForEach
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
Bases: formencode.api.FancyValidator
Controlls:
If so shows an error.
Messages
Bases: formencode.validators.FormValidator
Controlls if the CIDR values intersect.
Messages
Bases: formencode.api.FancyValidator
Controlls for comma seperated ips:
If so shows an error.
Messages
Bases: formencode.validators.FormValidator
Controlls if the required interface types occure(as sum) at least count times.
Messages
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
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
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
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
Bases: formencode.api.FancyValidator
Messages
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
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
Bases: formencode.validators.Int
Messages
Bases: endian.validators.network.Port
Messages
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
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
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
Bases: formencode.validators.FormValidator
Require for the id(or list of id) an input value.
Messages
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
alias of RequireIfMissing
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
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
Helper to assure we have proper input
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
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
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
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
alias of StringBool
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
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
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
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
Bases: formencode.validators.FormValidator
Messages
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
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.
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.
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
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
Validate an XRI
C{value} is not a string.
The XRI is not a personal, organizational or network one.
is not valid.
Remove all the elements stored in the current user’s cache
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: |
|
---|---|
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 |
This is a wrapper for endian.data.container.settings
The sha512crypt() function performs password encryption, based on the SHA-512 Crypt developed in 2008 by Ulrich Drepper.
Parameters: |
|
---|---|
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 |
Bases: object
Interface for the Smart Package Manager
Add a channel. If the channel exists, first delete the old channel
Parameters: |
|
---|---|
Returns: | True if ok, False if channel not found |
Return type: | boolean |
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 |
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 a package
Parameters: | package_name (string) – package name |
---|---|
Returns: | True if no error, False otherwise |
Return type: | boolean |
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 a package
Parameters: | package_name (string) – package name |
---|---|
Returns: | True if no error, False otherwise |
Return type: | boolean |
Return the number of updatable packages
return: The number of updatable packages rtype: int
Exec the ‘smart update’ command
Returns: | True if no error, False otherwise |
---|---|
Return type: | boolean |
— spawnverbose —
spawns a command, logs its output and returns the exitcode
@author Peter Warasin <peter@endian.com> @copyright (c) Endian 2007
Bases: subprocess.Popen
Bases: exceptions.Exception
Will be thrown if a timeout has been exceeded.
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.
Return a new datetime representing UTC day and time.
[tz] -> new datetime with tz’s local day and time.
Bases: object
Difference between two datetime values.
Number of days.
Number of microseconds (>= 0 and less than 1 second).
Number of seconds (>= 0 and less than 1 day).
Total seconds in the duration.
Format a temporal interval in a human readable format
Parameters: |
|
---|---|
Returns: | the formatted temporal interval |
Return type: | str |
Checks if two dates are on the same day ignoring time.
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.
convert datetime object to ISO 8601 with localtimezone
convert datetime object with local timezone to utc datetime object
convert utc datetime object into datetime object with local timezone
convert timestamp into datetime object
convert datetime object into timestamp
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.
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’]
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
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: |
|
---|---|
Return type: | boolean |
Returns: | corresponding boolean value of ‘’‘value’‘’ |
Collect information about the users on this system.
Count the number of arp entries.
Count the number of hotspot users.
Count the number of IPsec users.
Count the number of VPN users.
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 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 an utmp entry identified by a line (the default value for the line is the current tty)
Parameters: |
|
---|
Returns the machine type.
Returns: | machine type, e.g. ‘i686’, ‘armv5tel’ |
---|---|
Return type: | str |
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 -
Bases: endian.core.widget.BaseWidget
Bases: object
Bases: endian.core.widget.BaseWidget
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 -
Bases: endian.core.widget.BaseWidget
Bases: endian.core.widget.BaseWidget
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 |
---|
Bases: endian.core.widget.BaseWidget
Bases: endian.core.widget.BaseWidget
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)
Bases: endian.core.widget.TextFieldWidget
Bases: endian.core.widget.BaseWidget
Bases: endian.core.widget.BaseWidget
Bases: endian.core.widget.BaseWidget
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")
);
Bases: endian.core.widget.BaseWidget
Bases: endian.core.widget.BaseWidget
Bases: endian.core.widget.BaseWidget
Converts ip/cidr to ip/netmask
@param net: netaddress in ip/cidr format @type net: string
@returns netaddress in ip/netmask format
reads zones and their settings for future support of datasource
@returns boolean
checks if blue zone exists
@returns boolean
checks if orange zone exists
@returns boolean