Esempio 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"]
Esempio 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']
Esempio 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)
Esempio 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}")
Esempio 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",
            )
Esempio 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')
Esempio n. 7
0
 def __str__(self):
     return E3Error.__str__(self) + "(status={:X} '{}')".format(
         self.status,
         Status.msgs.get(self.status, "unknown"),
     )
Esempio n. 8
0
 def __str__(self):
     return E3Error.__str__(self) + "(status=%X '%s')" % \
         (self.status, Status.msgs.get(self.status, "unknown"))
Esempio 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)
Esempio n. 10
0
 def __str__(self):
     return E3Error.__str__(self) + "(status=%X '%s')" % \
         (self.status, Status.msgs.get(self.status, "unknown"))
Esempio 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)