utils.py 459 B

12345678910111213141516171819
  1. """
  2. Email message and email sending related helper functions.
  3. """
  4. import socket
  5. # Cache the hostname, but do it lazily: socket.getfqdn() can take a couple of
  6. # seconds, which slows down the restart of the server.
  7. class CachedDnsName(object):
  8. def __str__(self):
  9. return self.get_fqdn()
  10. def get_fqdn(self):
  11. if not hasattr(self, '_fqdn'):
  12. self._fqdn = socket.getfqdn()
  13. return self._fqdn
  14. DNS_NAME = CachedDnsName()