~ubuntu-branches/ubuntu/trusty/python-urllib3/trusty-proposed

« back to all changes in this revision

Viewing changes to urllib3/packages/mimetools_choose_boundary/__init__.py

  • Committer: Package Import Robot
  • Author(s): Daniele Tricoli, Jakub Wilk, Daniele Tricoli
  • Date: 2013-05-11 15:15:38 UTC
  • mfrom: (1.2.1) (4.2.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: package-import@ubuntu.com-20130511151538-4dshl34jt0kkpt9i
[ Jakub Wilk ]
* Use canonical URIs for Vcs-* fields.

[ Daniele Tricoli ]
* New upstream release
* Upload to unstable (Closes: #707780)
* debian/control
  - Added python3-six to Build-Depends field
  - Bumped debhelper dependency to 8.1 for build-{arch,indep} support
  - Removed python-setuptools from Build-Depends field
* debian/copyright
  - Updated copyright years
  - Added stanza for urllib3/packages/ordered_dict.py
* debian/patches/01_do-not-use-embedded-python-six.patch
  - Refreshed
* debian/patches/02_require-cert-verification.patch
  - Refreshed
* debian/patches/03_no-setuptools.patch
  - Do not use setuptools
* debian/patches/04_relax_nosetests_options.patch
  - Do not use logging-clear-handlers to see all logging output and
    disabled cover-min-percentage since it require python-nose (>= 1.3):
    this way it will be easier to backport python-urllib3 to Wheezy.
* debian/patches/05_fix_python3_syntax_error_in_ntlmpool.patch
  - Fix syntax error 'unicodeescape' codec can't decode bytes in
    position 130-132 for Python3

Show diffs side-by-side

added added

removed removed

Lines of Context:
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?).
4
 
 
5
 
Tweaked to use lock from threading rather than thread.
6
 
"""
7
 
import os
8
 
from threading import Lock
9
 
_counter_lock = Lock()
10
 
 
11
 
_counter = 0
12
 
def _get_next_counter():
13
 
    global _counter
14
 
    with _counter_lock:
15
 
        _counter += 1
16
 
        return _counter
17
 
 
18
 
_prefix = None
19
 
 
20
 
def choose_boundary():
21
 
    """Return a string usable as a multipart boundary.
22
 
 
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.
27
 
 
28
 
    The boundary contains dots so you have to quote it in the header."""
29
 
 
30
 
    global _prefix
31
 
    import time
32
 
    if _prefix is None:
33
 
        import socket
34
 
        try:
35
 
            hostid = socket.gethostbyname(socket.gethostname())
36
 
        except socket.gaierror:
37
 
            hostid = '127.0.0.1'
38
 
        try:
39
 
            uid = repr(os.getuid())
40
 
        except AttributeError:
41
 
            uid = '1'
42
 
        try:
43
 
            pid = repr(os.getpid())
44
 
        except AttributeError:
45
 
            pid = '1'
46
 
        _prefix = hostid + '.' + uid + '.' + pid
47
 
    return "%s.%.3f.%d" % (_prefix, time.time(), _get_next_counter())