--- a/iro/model/message.py Thu Mar 29 13:46:37 2012 +0200
+++ b/iro/model/message.py Thu Mar 29 16:27:40 2012 +0200
@@ -1,36 +1,65 @@
# -*- coding: utf-8 -*-
-
+"""All available message typs to send send.
+"""
from email.mime.text import MIMEText
from email.header import Header
from email.Utils import formatdate
class Message:
+ """ Baseclass for all different message typs."""
def __init__(self,content, typ="Message"):
+ """Constructor of Message class.
+
+ :param content: content of the message
+ :param string typ: typ of the message
+
+ .. automethod:: __eq__
+ .. automethod:: __neq__
+ """
self.content=content
self.typ = typ
def getContent(self):
+ """returns the content of the message"""
return self.content
def __eq__(self,other):
+ """return ``True`` if **other** has the same content."""
return self.content == other.content
- def __ne__(self,other):
+ def __neq__(self,other):
+ """return ``False`` if **other** has the same content."""
return not self.__eq__(other)
class SMS(Message):
+ """ A representation of one SMS"""
def __init__(self, cont, from_ = None):
+ """Constructor of SMS class.
+
+ :param string cont: SMS content
+ :param string from_: the telnumber from the SMS should be sended.
+ """
Message.__init__(self, cont.encode("utf-8"), typ="sms")
self.from_ = from_
class Fax(Message):
+ """A representation of one fax."""
def __init__(self,header,cont,attachments=[]):
+ """Constructor of one fax.
+
+ :param string header: Headline of fax
+ :param string cont: fax content
+ :param list attachments: attachments of fax
+ """
Message.__init__(self,cont.encode("utf-8"),typ="fax")
self.header=header
self.attachments=attachments
def getAttachment(self,i):
+ """returns a attachment
+ :param integer i: the i-th attachment
+ """
return self.attachments[i]
def __eq__(self,other):
@@ -51,7 +80,16 @@
class Mail(Message):
+ """A representation of one Mail"""
def __init__(self, subject, body, frm):
+ """Constructor of one mail.
+
+ :param string subject: subject of the mail
+ :param string body: body of the mail
+ :param string frm: mailaddress to send mail from
+
+ .. automethod:: __repr__
+ """
con = MIMEText(body.encode("utf-8"), _charset='utf-8')
sub = Header(subject.encode('utf-8'), 'utf-8')
con['Subject'] = sub
@@ -62,9 +100,11 @@
Message.__init__(self, con, typ='mail')
def as_string(self):
+ """returns created mail"""
return self.content.as_string()
def getFrom(self):
+ """returns the from mailaddress"""
return self.frm
def __eq__(self,other):
@@ -77,4 +117,10 @@
return True
def __repr__(self):
- return "<Mail(%s,%s,%s)>"%(self.subject,self.body,self.frm)
+ """string representation of the class.
+
+ :returns: ``<Mail(subject, body, frm)>``
+ """
+ return "<Mail(%s, %s, %s)>"%(self.subject,self.body,self.frm)
+
+__all__=["Message", "SMS", "Fax", "Mail"]