How to use the tokendito.settings.encoding function in tokendito

To help you get started, we’ve selected a few tokendito examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dowjones / tokendito / tokendito / helpers.py View on Github external
def to_unicode(bytestring):
    """Convert a string into a Unicode compliant object.

    The `unicode()` method is only available in Python 2. Python 3
    generates a `NameError`, and the same string is returned unmodified.

    :param bytestring:
    :return: unicode-compliant string
    """
    if type(bytestring) == bytes:
        bytestring = bytestring.decode(settings.encoding)
    unicode_string = bytestring
    try:
        unicode_string = unicode(bytestring, settings.encoding)
    except (NameError, TypeError):
        pass
    return unicode_string
github dowjones / tokendito / tokendito / helpers.py View on Github external
"""Update AWS credentials in ~/.aws/credentials default file.

    :param profile: AWS profile name
    :param aws_access_key: AWS access key
    :param aws_secret_key: AWS secret access key
    :param aws_session_token: Session token
    """
    cred_file = settings.aws_shared_credentials_file
    cred_dir = os.path.dirname(cred_file)
    logging.debug("Update AWS credentials in: [{}]".format(cred_file))

    create_directory(cred_dir)

    config = configparser.RawConfigParser()
    if os.path.isfile(cred_file):
        config.read(cred_file, encoding=settings.encoding)
    if not config.has_section(profile):
        config.add_section(profile)
    config.set(profile, 'aws_access_key_id', aws_access_key)
    config.set(profile, 'aws_secret_access_key', aws_secret_key)
    config.set(profile, 'aws_session_token', aws_session_token)
    with open(cred_file, 'w+', encoding=settings.encoding) as file:
        config.write(file)
github dowjones / tokendito / tokendito / helpers.py View on Github external
def to_unicode(bytestring):
    """Convert a string into a Unicode compliant object.

    The `unicode()` method is only available in Python 2. Python 3
    generates a `NameError`, and the same string is returned unmodified.

    :param bytestring:
    :return: unicode-compliant string
    """
    if type(bytestring) == bytes:
        bytestring = bytestring.decode(settings.encoding)
    unicode_string = bytestring
    try:
        unicode_string = unicode(bytestring, settings.encoding)
    except (NameError, TypeError):
        pass
    return unicode_string