# Path: yithlibraryserver/compat.py
# PY3 = sys.version_info[0] == 3
#     def encode_header(obj):  # pragma: no cover
#     def encode_header(obj):  # pragma: no cover


import binascii
import hashlib
import hmac
import random
import time
from yithlibraryserver.compat import url_quote
                             for key, value in sorted(original_params)])

    # 2. create signature base string
    signature_base = '%s&%s&%s' % (
        method.upper(), quote(url), quote(param_string),
        )

    # 3. create the signature key
    key = '%s&%s' % (quote(consumer_secret), quote(oauth_token))

    # 4. calculate the signature
    hashed = hmac.new(key.encode('ascii'),
                      signature_base.encode('ascii'),
                      hashlib.sha1)
    return quote(binascii.b2a_base64(hashed.digest())[:-1])


def auth_header(method, url, original_params, settings, oauth_token='',
                nonce_=None, timestamp_=None):
    params = list(original_params) + [
        ('oauth_consumer_key', settings['twitter_consumer_key']),
        ('oauth_nonce', nonce_ or nonce()),
        ('oauth_signature_method', 'HMAC-SHA1'),
        ('oauth_timestamp', str(timestamp_ or timestamp())),
        ('oauth_version', '1.0'),
        ]
    params = [(quote(key), quote(value)) for key, value in params]

    signature = sign(method, url, params,
                     settings['twitter_consumer_secret'], oauth_token)

# Path: yithlibraryserver/compat.py
# PY3 = sys.version_info[0] == 3
#     def encode_header(obj):  # pragma: no cover
#     def encode_header(obj):  # pragma: no cover


# Path: yithlibraryserver/twitter/authorization.py
import binascii
import hashlib
import hmac
import random
import time
from yithlibraryserver.compat import url_quote

                             for key, value in sorted(original_params)])

    # 2. create signature base string
    signature_base = '%s&%s&%s' % (
        method.upper(), quote(url), quote(param_string),
        )

    # 3. create the signature key
    key = '%s&%s' % (quote(consumer_secret), quote(oauth_token))

    # 4. calculate the signature
    hashed = hmac.new(key.encode('ascii'),
                      signature_base.encode('ascii'),
                      hashlib.sha1)
    return quote(binascii.b2a_base64(hashed.digest())[:-1])


def auth_header(method, url, original_params, settings, oauth_token='',
                nonce_=None, timestamp_=None):
    params = list(original_params) + [
        ('oauth_consumer_key', settings['twitter_consumer_key']),
        ('oauth_nonce', nonce_ or nonce()),
        ('oauth_signature_method', 'HMAC-SHA1'),
        ('oauth_timestamp', str(timestamp_ or timestamp())),
        ('oauth_version', '1.0'),
        ]
    params = [(quote(key), quote(value)) for key, value in params]

    signature = sign(method, url, params,
                     settings['twitter_consumer_secret'], oauth_token)

    params.append(('oauth_signature', signature))