1
"""The function mimetools.choose_boundary() from Python 2.7, which seems to
2
have disappeared in Python 3 (although email.generator._make_boundary() might
3
work as a replacement?).
5
Tweaked to use lock from threading rather than thread.
8
from threading import Lock
12
def _get_next_counter():
20
def choose_boundary():
21
"""Return a string usable as a multipart boundary.
23
The string chosen is unique within a single program run, and
24
incorporates the user id (if available), process id (if available),
25
and current time. So it's very unlikely the returned string appears
26
in message text, but there's no guarantee.
28
The boundary contains dots so you have to quote it in the header."""
35
hostid = socket.gethostbyname(socket.gethostname())
36
except socket.gaierror:
39
uid = repr(os.getuid())
40
except AttributeError:
43
pid = repr(os.getpid())
44
except AttributeError:
46
_prefix = hostid + '.' + uid + '.' + pid
47
return "%s.%.3f.%d" % (_prefix, time.time(), _get_next_counter())