iro Package

iro Package

config Module

class iro.config.Config(name, options=None)[source]

Base class for all classes, that uses option from configfile.

If one option is valid, the attribute is created with the value of the validate function.

Parameters:
  • name (string) – section name.
  • options (collections.OrderedDict) – Orderd Dict of the configuration options (see options)
load(cfg)[source]

Loads configuration into object.

Parameters:cfg (dict) – The Configuration dict. Normally you use configParser.items("section").
options = None

Options collections.OrderedDict for Options used in configuration file (see iro.config.Option). Ordering of configuration fields are done by order.

Sample:

OrderedDict([
    ("dburl",Option(lambda x,y:x,long="Connection URL to database",must=True)),
    ("port",Option(partial(vInteger,minv=0),long="Port under that twisted is running",must=True)),
])

A child class typically use update to add more options.

same(other)[source]

returns True, if the options of other object are the same

sampleConf()[source]

returns a sample Configuration section.

This function also adds the long help text to the sample section.

Returns:a list of lines
validate(cfg)[source]

Validate configuration.

Parameters:cfg (dict) – The Configuration dict. Normally you use configParser.items("section").
class iro.config.MyConfigParser[source]

Bases: ConfigParser.ConfigParser

Configparser that also validate configfile.

It is possile to restiger function, that are called, when config file is reloaded

read(files)[source]

reads an validate configuration file

registerReload(func)[source]

adds func to reloadList.

func ist called with no arguments.

reload_()[source]

run all registered function.

class iro.config.Option(validate, long='', help='', must=False, default=None)[source]

One Option in the configuration file

Parameters:
  • validate (func) – a validate function, it has to return the value, if valid and raise an error if not.
  • long (string) – long description
  • help (string) – the help text
  • must (boolean) – Is this option nessasary
  • default – default value
iro.config.confFiles = ['~/iro.conf', '/etc/iro/iro.conf']

Configfile list

iro.config.configParser = <iro.config.MyConfigParser instance at 0x28478c0>

configParser to get configuration.

iro.config.init()[source]

Load the main options.

iro.config.main = <iro.config.Config instance at 0x28355f0>

Main config options

iro.config.main_options = OrderedDict([('dburl', <iro.config.Option instance at 0x2835830>), ('port', <iro.config.Option instance at 0x2835fc8>)])

options for main section

iro.config.readConfig()[source]

Read the configuration and update all registered object (see MyConfigParser.reload_()).

iro.config.registerSignal()[source]

register readConfig to SIGUSR2

error Module

exception iro.error.ConfigException(section, name)[source]

Bases: exceptions.Exception

Exception while loading configuration.

exception iro.error.ExternalException[source]

Bases: iro.error.InterfaceException

950 – error in external api

exception iro.error.InterfaceException(code=999, msg='Unknown error.')[source]

Bases: exceptions.Exception

Exception, that should be reported to external client

999 – unknown error

Parameters:
  • code (integer) – the error code
  • msg (string) – the error message
dict()[source]

dict representation of the error

exception iro.error.InvalidMail(number, field=None)[source]

Bases: iro.error.ValidateException

702 – invalid mailaddress

exception iro.error.InvalidTel(number, field=None)[source]

Bases: iro.error.ValidateException

701 – invalid telnumber

exception iro.error.JobNotFound[source]

Bases: iro.error.InterfaceException

902 – jobid is unknown

exception iro.error.NeededOption(section, name)[source]

Bases: iro.error.ConfigException

Option is missing, but needed.

exception iro.error.NoProvider(name)[source]

Bases: iro.error.OfferException

no provider found

exception iro.error.NoRoute(name)[source]

Bases: iro.error.OfferException

no valid route found

exception iro.error.NoRouteForTask[source]

Bases: exceptions.Exception

Can’t send message to recipient with given offers

exception iro.error.NoTyp(name)[source]

Bases: iro.error.OfferException

no typ found.

exception iro.error.OfferException(name)[source]

Bases: exceptions.Exception

an Exception in Offer handling

exception iro.error.RejectRecipient(recipient, status=None)[source]

Bases: exceptions.Exception

can’t handle the recipient in a route

exception iro.error.UnknownOption(section, name)[source]

Bases: iro.error.ConfigException

Option is unknown

exception iro.error.UserNotFound[source]

Bases: iro.error.InterfaceException

901 – apikey is unknown – user not found

exception iro.error.ValidateException(code=700, field=None, msg=None)[source]

Bases: exceptions.Exception

700 – validation failed.

Parameters:
  • code (integer) – the error code
  • field (string) – the field, that is not valid
  • msg (string) – the error message
dict()[source]

dict representation of the error

install Module

iro.install.checkConfig()[source]

check configuration file syntax.

Returns:boolean value.
iro.install.checkDatabase()[source]

Checks, if all tables are created.

Returns:boolean value
iro.install.checkDatabaseConnection()[source]

Checks, if database can be connected.

Returns:boolean value
iro.install.createDatabase()[source]

Create all database tables or only missing.

iro.install.createSampleConfig()[source]

create a sample configuration file ‘iro.conf’ with all possible provider sections.

iro.install.getAllRoutes(providers, write=False)[source]

Checks and update offer list.

Parameters:

write (boolean) – check or update list

Return dict:
  • “orphand” (Set) – a set of orphand offers
  • “added” (Set) – a set of new offers. The new name have a schema provider_typ_route

main Module

iro.main.runReactor(reactor, engine, port, root)[source]

start reactor.

Parameters:
  • reactor – twisted reactor
  • engine – sqlalchemy engine
  • port (integer) – port to listen to
  • root (twisted.web.resource.Resource) – resource to share

telnumber Module

class iro.telnumber.Telnumber(number=None)[source]

A telefonnumer, with splitted country part

Parameters:number (string) – a telefonnumber
__eq__(y)[source]

Return True, if y hase the same telefonnumber

__neq__(y)[source]

Return True, if y is not equal (see __eq__())

__hash__()[source]

Return the Hash for telefonnumbers.

Yust use the hash of the string representation of the Number

__str__()[source]

String representation of the telefonnumber.

Returns:the international telefonnumber with leading zeros
__repr__()[source]

debug representation of the class.

Returns:<Telnumber 0012345667>
createNumber(number)[source]

Split string into two parts: one country part and the rest.

For a local number std_land will be used for country part.

Parameters:number (string) – a telefonnumber
land = None

Country part of a telefonnumber

number = None

Localpart of the telefonnumber

re_land = <_sre.SRE_Pattern object at 0x2911cc0>

Regex for country part

re_number = <_sre.SRE_Pattern object at 0x2a25030>

Regex for numbers

re_telnum = <_sre.SRE_Pattern object at 0x2911750>

Regex for a complete telefon number

std_land = '49'

Standard country part

validate Module

iro.validate.vBool(value, field)[source]

Validate function for boolean values

Returns:value
Raises :iro.error.ValidateException
iro.validate.vEmail(value, field, allowString=True, allowList=True)[source]

validator for emailadresses (see wikipeda for strange mailadresses and RFC3696)

valid:

  • “very.(),:;<>[]”.VERY.”very@\ “very”.unusual”@strange.example.com
  • “”@example.org
  • “very.unusual.@.unusual.com”@example.com’

not valid:

Parameters:
  • allowString (boolean) – value can be a string -> a string is returned
  • allowList (boolean) – value is a a list -> a list is returned
Returns:

value

Raises :

iro.error.ValidateException, iro.error.InvalidMail

iro.validate.vFloat(value, field, minv=None, maxv=None, none_allowed=False)[source]

validate function for float values.

Parameters:
  • minv (integer) – minimum value
  • maxv (integer) – maximum value
  • none_allowed (boolean) – is None or empty string allowed
Returns:

value

Raises :

iro.error.ValidateException

see also :func:vNumber

iro.validate.vHash(value, field, minlength=None, maxlength=None)[source]

Validate function for hash values

Parameters:
  • minlength (integer) – minimum length of value string
  • maxlength (integer) – maximum length of value string
Returns:

value

Raises :

iro.error.ValidateException

iro.validate.vInteger(value, field, minv=None, maxv=None, none_allowed=False)[source]

validate function for integer values.

Parameters:
  • minv (integer) – minimum value
  • maxv (integer) – maximum value
  • none_allowed (boolean) – is None or empty string allowed
Returns:

value

Raises :

iro.error.ValidateException

see also :func:vNumber

iro.validate.vNumber(value, field, nval, minv=None, maxv=None, none_allowed=False)[source]

validate function for integer values.

Parameters:
  • minv (integer) – minimum value
  • maxv (integer) – maximum value
  • nval (func) – function that give back a number
  • none_allowed (boolean) – is None or empty string allowed
Returns:

value

Raises :

iro.error.ValidateException

iro.validate.vTel(value, field)[source]

Validator for telefon numbers :return: value :raises: iro.error.InvalidTel

iro.validate.validate(kwd, func, need=True, *args, **kargs)[source]

validate decorator.

Parameters:
  • kwd (string) – keyword to validate
  • func (func) – validate function
  • need (boolean) – FalseNone is a valid value for kwd
Params args:

arguments for validate function

Params kargs:

keyword arguments for validate function

Note

this decorator can handle function that returns a defer object.

use it like this:

@validate(kwd=userhash, func=vuserhash)
f(userhash)

that will validate userhash with the function vuserhash. Every validate function should raise an Exception, if the the value is not valid. All args and kargs are used to call the validate function. if need is True, the kwd can’t be None.

Table Of Contents

This Page