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
-
raw_body
¶
-
recipient
¶
-
subject
¶
-
libfritter.file_template_factory module¶
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.
-
-
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 servertoaddr : 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
¶
-
-
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
-
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.
-
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.
-
static
libfritter.recipient_checker module¶
-
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.
-
-
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
libfritter.sqlitewrapper module¶
-
class
libfritter.sqlitewrapper.
AgedKeyedSqliteThing
(connector, birth_time_prop, id)[source]¶ Bases:
libfritter.sqlitewrapper.KeyedSqliteThing
Attributes
Methods
-
age
¶
-