model Package

model Package

The model pakcage represents all data, that is stored either in database or in objects.

before using the model, you have to use, you have to set the Engine with dbdefer.setEngine() and set the Threadpool with dbdefer.setPool() (see iro.main.runReactor() for initalizing this module).

dbdefer Module

class iro.model.dbdefer.DBDefer(engine, autocommit=False)[source]

Bases: object

a twisted sqlalchemy connector.

This is used as a Decorator class. It adds a session parameter to the function with a valid session. If the session parmaeter is used in calling this function only calls a commit after running the function, instead of createing a new session.

Parameters:
  • engine (sqlalchemy.engine.base.Engine) – a valid sqlalchemy engine object (normally created via sqlalchemy.create_engine()).
  • autocommit (boolean) – autocommit after running the function.
iro.model.dbdefer.dbdefer = <iro.model.dbdefer.DBDefer object at 0x31fc210>

the decorator to use. Use setEngine() to set a valid engine after program has started.

iro.model.dbdefer.setEngine(engine, autocommit=False)[source]

set the engine and autocommit for the decorator (see DBDefer).

decorators Module

All decorators, that are created by this package.

Imports:

iro.model.decorators.vRoute(value, field, typ, allowString=True, allowList=True, session=None)[source]

a validator to test a valid route. use with iro.validate.validate().

Parameters:
  • session – a valid session object (is created by decorator iro.model.dbdefer.dbdefer())
  • value – the value to test
  • field (string) – the field that is tested (only used to get a propper error message).
  • typ (string) – a typ to test the route in
  • allowString (boolean) – a single route is allowd.
  • allowList (boolean) – a list of routes is allowed.
Returns:

value, if value is a valid route for a given typ.

Raises :

iro.error.ValidateException

iro.model.decorators.vTyp(value, field, session=None)[source]

a validator to test a valid typ. use with iro.validate.validate().

Parameters:
  • session – a valid session object (is created by decorator iro.model.dbdefer.dbdefer())
  • value – the value to test
  • field (string) – the field that is tested (only used to get a propper error message).
Returns:

value, if value is a valid typ.

Raises :

iro.error.ValidateException

job Module

class iro.model.job.ExJob(dbjob, recipients, message, offers)[source]

A ExJob object represents a message to multiple recipients over multiple offers to send.

One single message to one recipient is handeld in iro.controller.task.Task. This class holds connections to all tasks. This class is responsiple to update the status in database of one job and updating the bill.

Constructor of ExJob.

Parameters:
  • dbjob – primary key of the job element in database
  • recipients (list) – list of all recipients
  • message (iro.model.message.Message) – message to send
  • offers (list) – list of all possible offers to send message over
addTask(task)[source]

adding a task to tasks dict - key is the recipient.

Parameters:task (iro.controller.task.Task) – a task
incStatus(*args, **kw)[source]
setError(task, err, session=None)[source]

errback for one task.

This function updates the database object.

setStatus(task, status, session=None)[source]

callback of one task.

This function updates the database object and the bill.

synchronized = ['incStatus', '_status']
class iro.model.job.ExJobs[source]

Bases: dict, _abcoll.MutableMapping

a dict to handle all jobs.

create(user, recipients, message, offers, info=None, session=None)[source]

creates on new Job.

Parameters:
Returns:

the new job

iro.model.job.exJobs = {}

the dict of all available jobs.

message Module

All available message typs to send send.

class iro.model.message.Message(content, typ='Message')[source]

Baseclass for all different message typs.

Constructor of Message class.

Parameters:
  • content – content of the message
  • typ (string) – typ of the message
__eq__(other)[source]

return True if other has the same content.

__neq__(other)[source]

return False if other has the same content.

getContent()[source]

returns the content of the message

class iro.model.message.SMS(cont, from_=None)[source]

Bases: iro.model.message.Message

A representation of one SMS

Constructor of SMS class.

Parameters:
  • cont (string) – SMS content
  • from (string) – the telnumber from the SMS should be sended.
class iro.model.message.Fax(header, cont, attachments=[])[source]

Bases: iro.model.message.Message

A representation of one fax.

Constructor of one fax.

Parameters:
  • header (string) – Headline of fax
  • cont (string) – fax content
  • attachments (list) – attachments of fax
getAttachment(i)[source]

returns a attachment :param integer i: the i-th attachment

class iro.model.message.Mail(subject, body, frm)[source]

Bases: iro.model.message.Message

A representation of one Mail

Constructor of one mail.

Parameters:
  • subject (string) – subject of the mail
  • body (string) – body of the mail
  • frm (string) – mailaddress to send mail from
__repr__()[source]

string representation of the class.

Returns:<Mail(subject, body, frm)>
as_string()[source]

returns created mail

getFrom()[source]

returns the from mailaddress

offer Module

iro.model.offer.extendProvider(user, typ, ps, session=None)[source]

extend and reduce the offer list to allowed routes for user.

  • extend the “default” to the default offerlist of the user.
  • extend a Provider name to all routes of that provider.
Parameters:
Returns:

a extended an reduced offer list

iro.model.offer.loadOffers(session=None)[source]

loading Offers from database and configuration file and store them in offers and providers.

Parameters:session – a valid session ( created by decorator iro.model.dbdefer.dbdefer())
iro.model.offer.offers = {}

A dict of all available offers – key is the offer name

iro.model.offer.providers = {}

A dict of all available providers – key is the provider name

pool Module

class iro.model.pool.Data[source]

A very simple class to save the thread pool for database requests

iro.model.pool.data = <iro.model.pool.Data instance at 0x31fa128>

holds connection to the actual thread pool for the database requests

iro.model.pool.runInDBPool(f)[source]

Decorator to run DB queries in Twisted’s thread pool.

If last argument is a session object, the function is called directly.

iro.model.pool.setPool(pool)[source]

setting the thread pool

schema Module

class iro.model.schema.Job(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.Base

A complete Job.

  • status show the status of the job (init, started, sending, sended or error).
  • info is used to make it possible to create different billing groups for user.
__repr__()[source]

string representation of the Job class.

Returns:<Job('id' ,'info', 'status', 'user_id')>
extend[source]

returns the connected iro.model.job.ExJob

classmethod get(session, id)[source]

returns a job object from a given id

id

job id

info

job info, for billing porpuse

status

status of a job

user

connected User object

user_id

connected user id

class iro.model.schema.Message(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.Base

A message that has created costs.

isBilled is False since the bill is paid.

count

Count of sended messages

date

date of sending the message

exID

external API id

id

primary key of the message

isBilled

is bill paid?

job

connected Job object

job_id

id of the connected job

offer

connected Offer object

offer_id

sended message over this offer woth ithe offer.name

price

price of sending the message

recipient

string representation of the recipient

class iro.model.schema.Offer(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.Base

All possible Offers over a Message can be sended. provider, typ and route are used to get the data form configuration file.

classmethod get(session, provider, route, typ)[source]

returns a Offer object.

name

name of the offer

provider

provider name

classmethod providers(session, typ)[source]

returns a list of all possible providers.

Parameters:typ (string) – get all providers that support this typ
route

route of the provider

classmethod routes(session, typ)[source]

returns a query object of all possible offers.

Parameters:typ (string) – get all offers that support this typ
typ

typ of message

classmethod typs(session)[source]

returns a list of all possible types.

class iro.model.schema.User(name, apikey)[source]

Bases: sqlalchemy.ext.declarative.Base

An user in iro.

Constructor of User class.

Parameters:
  • name (string) – username
  • apikey (string) – apikey for the user
__repr__()[source]

string representation of the user class.

Returns:<User('name', 'apikey')>
apikey

apikey only [0-9a-f]

has_right(typ, offer_name=None, provider=None, route=None)[source]

if a user has the right to use a offer, provider e. al. (arguments are and connected).

Parameters:
  • typ (string) – the typ
  • offer_name (string) – offer name
  • provider (string) – provider name
  • route (string) – a route name
Returns:

offer_name or None (not allwoed)

Raises :

sqlalchemy.orm.exc.MultipleResultsFound if not a single offer match

job(id)[source]

returns a job object.

Parameters:id (integer) – id of a Job
Returns:Job
Raises :iro.error.JobNotFound
name

Username

ng_kunde

Connection to the netzguerilla userdatabase

providers(typ, default=False)[source]

return a query object for all possible providers for a given typ

Parameters:
  • typ (string) – the typ
  • default (boolean) – use only default routes
rights

all allowed offers to send with.

routes(typ, default=False)[source]

returns a query object to get all possible routes for a given typ

Parameters:
  • typ (string) – the typ
  • default (boolean) – use only default routes
class iro.model.schema.Userright(offer, default=None)[source]

Bases: sqlalchemy.ext.declarative.Base

Allowed offers for one user. Default routes are sorted by default value.

Constructor of Userright class.

Parameters:
  • offer (Offer) – a offer object
  • default (integer) – default value
bill[source]

returns a list of unbilled messages grouped by Job.info

default

sorting defaults routes with this value

offer

connected Offer object

offer_name

offername

user

connected User object

user_name

username

status Module

class iro.model.status.Status(provider, route, costs=0.0, count=0, exID=None)[source]

status object – the resulat of one iro.controller.task.Task.

Parameters:
  • provider (iro.offer.provider.Provider) – a provider object
  • route (string) – a route of the provider
  • costs (decimal.Decimal) – costs for sending this message
  • count (integer) – count of sended messages
  • exID (string) – ID of external API

user Module

iro.model.user.getuser(apikey, session=None)[source]

Returns a valid user object.

Parameters:
  • session – a valid session object (is created by decorator iro.model.dbdefer.dbdefer())
  • apikey (string) – a vaild apikey (only [0-9a-f] is allowed)
Returns:

a iro.model.schema.User object

Raises :

iro.error.UserNotFound

iro.model.user.vUser(f)[source]

A Decorator to verify the apikey and execute the function with a valid iro.model.schema.User instead of the apikey.

The decorator expect the apikey in the user parameter.

Returns:a defer

utils Module

class iro.model.utils.WithSession(engine, autocommit=False)[source]

Bases: object

a with statement for a database session connection.

Parameters:
  • engine (sqlalchemy.engine.base.Engine) – a valid sqlalchemy engine object (normally created via sqlalchemy.create_engine()).
  • autocommit (boolean) – autocommit after running the function.
__enter__()[source]

returns a vaild session object.

__exit__(exc_type, exc_value, traceback)[source]