libfritter package

Submodules

libfritter.email_template module

class libfritter.email_template.EmailTemplate(template_content)[source]

Bases: object

A class which prepares a template for sending

Attributes

Methods

Create a new template around the given raw content.

Parameters:

template_content : str

The raw content of the template.

Attributes

Methods

format(args)[source]
raw_body
recipient
subject
exception libfritter.email_template.InvalidTemplateException[source]

Bases: exceptions.Exception

libfritter.file_template_factory module

class libfritter.file_template_factory.FileTemplateFactory(root)[source]

Bases: object

A simple wrapper around FileTemaplateSource and EmailTemplate whose load method is suitable for passing to the Mailer or Previewer classes.

Methods

load(name)[source]

Method which actually loads the template given a name

Parameters:

name : str

The name of the template to load.

Returns:

EmailTemplate

A constructed template instance.

libfritter.mailer module

class libfritter.mailer.Mailer(config, sql_connector, template_factory, sender=None, delay_send=True)[source]

Bases: object

Parameters:

config : object

Configuration object which will be passed as the first parameter to the sender callable.

sql_connector : callable

Returning a sqlite connection

template_factory : callable(name)

Will be passed the name of a template, should return an EmailTemplate instance.

sender : callable, optional

Used to actually send the email. Defaults to send_email.

delay_send : bool, optional

Whether or not to delay all sending of emails. Defaulting to True, this means that when asked to send an email this class will instead cache it (via the provided SQL connection) for sending later. This avoids potentially length delays for the caller, at the expense of the email not being sent immediately.

Methods

email_template(toaddr, template_name, template_vars)[source]

Prepare a new email based on a template. This is expected to be the main entry point for sending new emails.

Parameters:

toaddr : str

The email addresss to send the email to. If empty this will raise ValueError.

template_name : str

The identifier for the template to use. Will be passed to the template_factory this mailer was created with.

template_vars : dict

A map of values to format the template’s body with.

load_template(template_name, template_vars)[source]
send_email(toaddr, subject, msg)[source]
send_email_template(toaddr, template_name, template_vars)[source]
store_template(toaddr, template_name, template_vars)[source]
try_send(ps)[source]
libfritter.mailer.send_email(config, toaddr, subject, msg)[source]

Sends an email.

Parameters:

config : dict_like

Must have the following keys: * fromaddr - the senders address * smtpserver - the server to send the email via * username - the username for the server * password - the password for the server

toaddr : str

subject : str

msg : str

libfritter.previewer module

exception libfritter.previewer.BadRecipient(recipient, msg_tpl)[source]

Bases: exceptions.Exception

Base exception for issues with recipients. RecipientChecker implementations can either use this directly or subclass it to provide more information.

Create a new instance.

Parameters:

recipient : str

The recipient which is bad in some manner. Will be made available via the property of the same name.

msg_tpl : str

A format string for the message of the exception. Will have the recioient value formatted into it, and the result passed to the super constructor.

recipient
exception libfritter.previewer.MissingRecipient(comment=None)[source]

Bases: exceptions.Exception

class libfritter.previewer.PreviewFormatter(valid_keys=None)[source]

Bases: string.Formatter

Create a new magic formatter

Parameters:

valid_keys : list, optional

A list of valid placeholders. If not passed then all placeholders are considered valid.

Attributes

Methods

get_value(key, args, kwargs)[source]
invalid_keys

The set of keys which were invalid.

class libfritter.previewer.Previewer(template_factory, recipient_checker, writer, valid_placeholders=None)[source]

Bases: object

Parameters:

template_factory : callable(name)

Will be passed the name of a template, should return an EmailTemplate instance.

recipient_checker : RecipientChecker

Object to provide information about the recipients. See the doc-comments on that class for details.

writer : file object

Used to output the preview of each item.

valid_placeholders : list, optional

A list of valid placeholders. If not passed then all placeholders are considered valid.

Methods

static format_section(heading, content)[source]

Formats a section with a heading.

Parameters:

heading : str

The name of the section

content : object

The content of the section. Each line of content will be indented by four spaces.

Returns:

str

The formatted section. This includes two empty lines at the end so that values are suitable for ``join``ing together with a gap in between.

static list_or_none(l, template=u'{}')[source]
preview(template_name, writer=None)[source]

Writes a text preview of the template into the given writer.

Parameters:

template_name : str

The name of the template to get the preview data for, will be passed to the factory callable the instance was created around.

writer : file object, optional

Used to output the preview of each item in preference to the writer given to the instance when it was created.

Returns:

str or None

The content of the errors section, if any.

preview_data(template_name)[source]

Returns the gathered data, as a list of content tuples ready to be output.

Parameters:

template_name : str

The name of the template to get the preview data for, will be passed to the factory callable the instance was created around.

libfritter.recipient_checker module

exception libfritter.recipient_checker.InvalidRecipient(recipient, valid_recipients)[source]

Bases: libfritter.previewer.BadRecipient

class libfritter.recipient_checker.RecipientChecker[source]

Bases: object

Methods

describe(recipient)[source]

Will be passed in turn each of the values from the “To:” line of the template, should return a description of the recipient or raise BadRecipient.

Parameters:

recipient : str

One of the values from the “To:” line of the template.

Returns:

str

A description of the recipient. The value returned will be shown in the preview, even if it is empty. Thus, if there is no description available this should just return the input value.

no_recipient()[source]

Called when there are no recipients. If this is valid, then the method need not do anything. If this is not valid, then it should raise MissingRecipient ideally with some comment about would be valid.

class libfritter.recipient_checker.RestrictedRecipientsChecker(valid_recipients)[source]

Bases: object

Create a checker which only allows recipients within a given lists. Note: the members of the valid list will be included in any exceptions that this class throws.

Parameters:

valid_recipients : list of str

A list of names which are valid for use in templates.

Methods

check_valid(recipient)[source]
describe(recipient)[source]
no_recipient()[source]

libfritter.sqlitewrapper module

class libfritter.sqlitewrapper.AgedKeyedSqliteThing(connector, birth_time_prop, id)[source]

Bases: libfritter.sqlitewrapper.KeyedSqliteThing

Attributes

Methods

age
class libfritter.sqlitewrapper.KeyedSqliteThing(connector, id=None, auto_props=[])[source]

Bases: object

Attributes

Methods

delete()[source]
id
in_db
save()[source]
class libfritter.sqlitewrapper.PendingSend(connector, id=None)[source]

Bases: libfritter.sqlitewrapper.AgedKeyedSqliteThing

Attributes

Methods

classmethod Unsent(connector, max_retry=5, max_results=50)[source]
is_sent
mark_sent()[source]
retried()[source]
retry_count
sent_time
template_vars

libfritter.template_source module

class libfritter.template_source.FileTemaplateSource(root)[source]

Bases: object

A source of template contents based on .txt files

Methods

extension = '.txt'
load(name)[source]
libfritter.template_source.load_path(path)[source]

Module contents