Ejemplo n.º 1
0
def test_e3error():
    err = None

    try:
        raise E3Error(None)
    except E3Error as basicerr:
        assert str(basicerr) == "E3Error"

    try:
        raise E3Error(None, origin="here")
    except E3Error as err0:
        err = err0
        assert str(err).strip() == "here: E3Error"

    try:
        raise E3Error("one", origin="here")
    except E3Error as err1:
        err += err1

    try:
        raise E3Error(["two"])
    except E3Error as err2:
        err += err2
    assert str(err).strip() == "here: two"

    assert err.messages == ["one", "two"]

    err += "three"
    assert err.messages == ["one", "two", "three"]
Ejemplo n.º 2
0
def test_e3error():
    err = None

    try:
        raise E3Error(None)
    except E3Error as basicerr:
        assert str(basicerr) == 'E3Error'

    try:
        raise E3Error(None, origin='here')
    except E3Error as err0:
        err = err0
        assert str(err).strip() == 'here: E3Error'

    try:
        raise E3Error('one', origin='here')
    except E3Error as err1:
        err += err1

    try:
        raise E3Error(['two'])
    except E3Error as err2:
        err += err2
    assert str(err).strip() == 'here: two'

    assert err.messages == ['one', 'two']

    err += 'three'
    assert err.messages == ['one', 'two', 'three']
Ejemplo n.º 3
0
 def __init__(self,
              status: int,
              message: str,
              origin: Optional[str] = None):
     self.status = status
     if self.status < 0:
         self.status += 2**32
     E3Error.__init__(self, message, origin=origin)
Ejemplo n.º 4
0
def send_message(
    from_email: str,
    to_emails: List[str],
    subject: str,
    content: str,
    smtp_servers: List[str],
) -> None:
    """Send an e-mail message.

    :param from_email: the address sending this email (e.g. [email protected])
    :param to_emails: A list of addresses to send this email to
    :param subject: the e-mail's subject
    :param content: the e-mail's content
    """
    msg = Message()
    msg["To"] = ", ".join(to_emails)
    msg["From"] = from_email
    msg["Subject"] = subject
    msg.set_payload(content, "utf-8")

    if not sendmail(
        from_email=from_email,
        to_emails=to_emails,
        mail_as_string=msg.as_string(),
        smtp_servers=smtp_servers,
    ):
        raise E3Error(f"error when sending email {subject}")
Ejemplo n.º 5
0
    def add(self, name: str, value: str) -> None:
        """Add a fingerprint element.

        :param name: name of the new element
        :param value: associated value (should be a string)
        :raise: E3Error
        """
        if isinstance(value, str):
            self.elements[name] = value
        else:
            raise E3Error(
                f"value for {name} should be a string got {value}", "fingerprint.add",
            )
Ejemplo n.º 6
0
    def add(self, name, value):
        """Add a fingerprint element.

        :param name: name of the new element
        :type name: str
        :param value: associated value (should be a string)
        :type value: str | unicode
        :raise: E3Error
        """
        if isinstance(value, (str, unicode)):
            self.elements[name] = value
        else:
            raise E3Error(
                'value for %s should be a string got %s' % (name, value),
                'fingerprint.add')
Ejemplo n.º 7
0
 def __str__(self):
     return E3Error.__str__(self) + "(status={:X} '{}')".format(
         self.status,
         Status.msgs.get(self.status, "unknown"),
     )
Ejemplo n.º 8
0
 def __str__(self):
     return E3Error.__str__(self) + "(status=%X '%s')" % \
         (self.status, Status.msgs.get(self.status, "unknown"))
Ejemplo n.º 9
0
 def __init__(self, status, message, origin=None):
     self.status = status
     if self.status < 0:
         self.status += 2 ** 32
     E3Error.__init__(self, message, origin=origin)
Ejemplo n.º 10
0
 def __str__(self):
     return E3Error.__str__(self) + "(status=%X '%s')" % \
         (self.status, Status.msgs.get(self.status, "unknown"))
Ejemplo n.º 11
0
 def __init__(self, status, message, origin=None):
     self.status = status
     if self.status < 0:
         self.status = self.status + 2 ** 32
     E3Error.__init__(self, message, origin=origin)