# Path: bento/utils/utils.py
# def extract_exception():
#     """Extract the last exception.
# 
#     Used to avoid the except ExceptionType as e, which cannot be written the
#     same across supported versions. I.e::
# 
#         try:
#             ...
#         except Exception, e:
#             ...
# 
#     becomes:
# 
#         try:
#             ...
#         except Exception:
#             e = extract_exception()
#     """
#     return sys.exc_info()[1]


import base64
import sys
import os.path as op
import six
from bento.pypi.register_utils \
    import \
        encode_multipart, _BOUNDARY
from bento.conv \
    import \
        pkg_to_distutils_meta_pkg_info
from bento.utils.utils \
    import \
        extract_exception
from bento.errors \
    import \
        PyPIError, InvalidRepository
from six \
    import \
        PY3
    from hashlib import md5
    from md5 import md5
    from urllib.request \
        import \
            Request, HTTPBasicAuthHandler, HTTPError, URLError, urlparse, urlopen
    from urllib2 \
        import \
            Request, HTTPBasicAuthHandler, HTTPError, URLError, urlopen
    from urlparse \
        import \
            urlparse
               'Content-length': str(len(body)),
               'Authorization': auth}

    return Request(repository, data=body, headers=headers)

def upload(dist_filename, dist_type, package, config, sign=False):
    schema, netloc, url, params, query, fragments = urlparse(config.repository)
    if params or query or fragments:
        raise InvalidRepository("Incompatible url %s" % config.repository)

    if schema not in ('http', 'https'):
        raise InvalidRepository("unsupported schema " + schema)

    if sign:
        raise NotImplementedError()

    data = build_upload_post_data(dist_filename, dist_type, package)
    userpass = (config.username + ":" + config.password).encode("ascii")
    auth = six.b("Basic ") + base64.standard_b64encode(userpass)
    request = build_request(config.repository, data, auth)

    try:
        result = urlopen(request)
        status = result.getcode()
        reason = result.msg
    except HTTPError:
        e = extract_exception()
        status = e.code
        reason = e.msg
    except URLError:

# Path: bento/utils/utils.py
# def extract_exception():
#     """Extract the last exception.
# 
#     Used to avoid the except ExceptionType as e, which cannot be written the
#     same across supported versions. I.e::
# 
#         try:
#             ...
#         except Exception, e:
#             ...
# 
#     becomes:
# 
#         try:
#             ...
#         except Exception:
#             e = extract_exception()
#     """
#     return sys.exc_info()[1]


# Path: bento/pypi/upload_utils.py
import base64
import sys
import os.path as op
import six
from bento.pypi.register_utils \
    import \
        encode_multipart, _BOUNDARY
from bento.conv \
    import \
        pkg_to_distutils_meta_pkg_info
from bento.utils.utils \
    import \
        extract_exception
from bento.errors \
    import \
        PyPIError, InvalidRepository
from six \
    import \
        PY3
    from hashlib import md5
    from md5 import md5
    from urllib.request \
        import \
            Request, HTTPBasicAuthHandler, HTTPError, URLError, urlparse, urlopen
    from urllib2 \
        import \
            Request, HTTPBasicAuthHandler, HTTPError, URLError, urlopen
    from urlparse \
        import \
            urlparse

               'Content-length': str(len(body)),
               'Authorization': auth}

    return Request(repository, data=body, headers=headers)

def upload(dist_filename, dist_type, package, config, sign=False):
    schema, netloc, url, params, query, fragments = urlparse(config.repository)
    if params or query or fragments:
        raise InvalidRepository("Incompatible url %s" % config.repository)

    if schema not in ('http', 'https'):
        raise InvalidRepository("unsupported schema " + schema)

    if sign:
        raise NotImplementedError()

    data = build_upload_post_data(dist_filename, dist_type, package)
    userpass = (config.username + ":" + config.password).encode("ascii")
    auth = six.b("Basic ") + base64.standard_b64encode(userpass)
    request = build_request(config.repository, data, auth)

    try:
        result = urlopen(request)
        status = result.getcode()
        reason = result.msg
    except HTTPError:
        e = extract_exception()
        status = e.code
        reason = e.msg
    except URLError:

        e = extract_exception()