Skip to content

Commit

Permalink
Merge pull request #822 from hugovk/develop
Browse files Browse the repository at this point in the history
Remove redundant code for Python <= 3.5
  • Loading branch information
colin-pm committed Jun 23, 2022
2 parents 612daa2 + 4db3887 commit e84c959
Show file tree
Hide file tree
Showing 105 changed files with 368 additions and 508 deletions.
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Configuration file for the Sphinx documentation builder.


Expand Down
50 changes: 16 additions & 34 deletions docs/ext/hvac_doctest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
sphinx.ext.doctest
~~~~~~~~~~~~~~~~~~
Expand All @@ -9,20 +8,19 @@
:copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
from __future__ import absolute_import

import codecs
import doctest
import re
import sys
import time
from io import StringIO
from os import path

from docutils import nodes
from docutils.parsers.rst import directives
from packaging.specifiers import SpecifierSet, InvalidSpecifier
from packaging.version import Version
from six import itervalues, StringIO, binary_type, text_type, PY2

import sphinx
from sphinx.builders import Builder
Expand Down Expand Up @@ -54,21 +52,10 @@
blankline_re = re.compile(r"^\s*<BLANKLINE>", re.MULTILINE)
doctestopt_re = re.compile(r"#\s*doctest:.+$", re.MULTILINE)

if PY2:

def doctest_encode(text, encoding):
# type: (str, str) -> str
if isinstance(text, text_type):
text = text.encode(encoding)
if text.startswith(codecs.BOM_UTF8):
text = text[len(codecs.BOM_UTF8) :]
return text

else:

def doctest_encode(text, encoding):
# type: (str, str) -> str
return text
def doctest_encode(text, encoding):
# type: (str, str) -> str
return text


def is_allowed_version(spec, version):
Expand All @@ -92,10 +79,6 @@ def is_allowed_version(spec, version):

class Py23DocChecker(doctest.OutputChecker):
def check_output(self, want, got, optionflags):
if sys.version_info[0] < 3:
# Ignore str `u` prefix in repr to simplify Python 2.7 doctest coverage
got = re.sub("u'(.*?)'", "'\\1'", got)
got = re.sub('u"(.*?)"', '"\\1"', got)
return doctest.OutputChecker.check_output(self, want, got, optionflags)


Expand Down Expand Up @@ -231,7 +214,7 @@ class TestoutputDirective(TestDirective):
# helper classes


class TestGroup(object):
class TestGroup:
def __init__(self, name):
# type: (str) -> None
self.name = name
Expand Down Expand Up @@ -260,15 +243,15 @@ def add_code(self, code, prepend=False):

def __repr__(self): # type: ignore
# type: () -> str
return "TestGroup(name=%r, setup=%r, cleanup=%r, tests=%r)" % (
return "TestGroup(name={!r}, setup={!r}, cleanup={!r}, tests={!r})".format(
self.name,
self.setup,
self.cleanup,
self.tests,
)


class TestCode(object):
class TestCode:
def __init__(self, code, type, filename, lineno, options=None):
# type: (str, str, Optional[str], int, Optional[Dict]) -> None
self.code = code
Expand All @@ -279,7 +262,7 @@ def __init__(self, code, type, filename, lineno, options=None):

def __repr__(self): # type: ignore
# type: () -> str
return "TestCode(%r, %r, filename=%r, lineno=%r, options=%r)" % (
return "TestCode({!r}, {!r}, filename={!r}, lineno={!r}, options={!r})".format(
self.code,
self.type,
self.filename,
Expand All @@ -295,6 +278,7 @@ def __init__(self, *args, **kwargs):

def summarize(self, out, verbose=None): # type: ignore
# type: (Callable, bool) -> Tuple[int, int]

string_io = StringIO()
old_stdout = sys.stdout
sys.stdout = string_io
Expand Down Expand Up @@ -384,7 +368,7 @@ def _warn_out(self, text):
logger.warning(text)
else:
logger.info(text, nonl=True)
if isinstance(text, binary_type):
if isinstance(text, bytes):
text = force_decode(text, None)
self.outfile.write(text)

Expand Down Expand Up @@ -450,8 +434,6 @@ def get_filename_for_node(self, node, docname):
)[0]
except Exception:
filename = self.env.doc2path(docname, base=None)
if PY2:
return filename.encode(fs_encoding)
return filename

@staticmethod
Expand Down Expand Up @@ -527,13 +509,13 @@ def condition(node):
groups[groupname] = TestGroup(groupname)
groups[groupname].add_code(code)
for code in add_to_all_groups:
for group in itervalues(groups):
for group in groups.values():
group.add_code(code)
if self.config.doctest_global_setup:
code = TestCode(
self.config.doctest_global_setup, "testsetup", filename=None, lineno=0
)
for group in itervalues(groups):
for group in groups.values():
group.add_code(code, prepend=True)
if self.config.doctest_global_cleanup:
code = TestCode(
Expand All @@ -542,13 +524,13 @@ def condition(node):
filename=None,
lineno=0,
)
for group in itervalues(groups):
for group in groups.values():
group.add_code(code)
if not groups:
return

self._out("\nDocument: %s\n----------%s\n" % (docname, "-" * len(docname)))
for group in itervalues(groups):
self._out("\nDocument: {}\n----------{}\n".format(docname, "-" * len(docname)))
for group in groups.values():
self.test_group(group)
# Separately count results from setup code
res_f, res_t = self.setup_runner.summarize(self._out, verbose=False)
Expand Down Expand Up @@ -591,7 +573,7 @@ def run_setup_cleanup(runner, testcodes, what):
sim_doctest = doctest.DocTest(
examples,
{},
"%s (%s code)" % (group.name, what),
f"{group.name} ({what} code)",
testcodes[0].filename,
0,
None,
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with python 3.8
# This file is autogenerated by pip-compile with python 3.10
# To update, run:
#
# pip-compile --output-file=docs/requirements.txt docs/requirements.in
Expand Down
7 changes: 2 additions & 5 deletions docs/usage/secrets_engines/transit.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,13 @@ Transit

def base64ify(bytes_or_str):
"""Helper method to perform base64 encoding across Python 2.7 and Python 3.X"""
if sys.version_info[0] >= 3 and isinstance(bytes_or_str, str):
if isinstance(bytes_or_str, str):
input_bytes = bytes_or_str.encode('utf8')
else:
input_bytes = bytes_or_str

output_bytes = base64.urlsafe_b64encode(input_bytes)
if sys.version_info[0] >= 3:
return output_bytes.decode('ascii')
else:
return output_bytes
return output_bytes.decode('ascii')

Create Key
----------
Expand Down
5 changes: 2 additions & 3 deletions hvac/adapters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding=utf-8
"""
HTTP Client Library Adapters
Expand All @@ -12,7 +11,7 @@
from hvac.constants.client import DEFAULT_URL


class Adapter(object):
class Adapter:
"""Abstract base class used when constructing adapters for use with the Client class."""

__metaclass__ = ABCMeta
Expand Down Expand Up @@ -361,7 +360,7 @@ def request(self, *args, **kwargs):
:return: Dict on HTTP 200 with JSON body, otherwise the response object.
:rtype: dict | requests.Response
"""
response = super(JSONAdapter, self).request(*args, **kwargs)
response = super().request(*args, **kwargs)
if response.status_code == 200:
try:
return response.json()
Expand Down
1 change: 0 additions & 1 deletion hvac/api/auth_methods/approle.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""APPROLE methods module."""
import json
from hvac import exceptions, utils
Expand Down
1 change: 0 additions & 1 deletion hvac/api/auth_methods/aws.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
""" AWS auth method module """
import logging
import json
Expand Down
1 change: 0 additions & 1 deletion hvac/api/auth_methods/azure.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Azure auth method module."""
import logging

Expand Down
9 changes: 4 additions & 5 deletions hvac/api/auth_methods/cert.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Cert methods module."""
from hvac.api.vault_api_base import VaultApiBase
from hvac.utils import validate_pem_format
Expand Down Expand Up @@ -106,7 +105,7 @@ def create_ca_certificate_role(
:type mount_point:
"""
try:
with open(certificate, "r") as f_cert:
with open(certificate) as f_cert:
cert = f_cert.read()
except FileNotFoundError:
cert = certificate
Expand Down Expand Up @@ -179,7 +178,7 @@ def list_certificate_roles(self, mount_point="cert"):
:return: The response of the list_certificate request.
:rtype: requests.Response
"""
api_path = "/v1/auth/{mount_point}/certs".format(mount_point=mount_point)
api_path = f"/v1/auth/{mount_point}/certs"
return self._adapter.list(url=api_path)

def delete_certificate_role(self, name, mount_point="cert"):
Expand Down Expand Up @@ -218,7 +217,7 @@ def configure_tls_certificate(self, mount_point="cert", disable_binding=False):
params = {
"disable_binding": disable_binding,
}
api_path = "/v1/auth/{mount_point}/config".format(mount_point=mount_point)
api_path = f"/v1/auth/{mount_point}/config"
return self._adapter.post(
url=api_path,
json=params,
Expand Down Expand Up @@ -263,7 +262,7 @@ def login(
params = {}
if name != "":
params["name"] = name
api_path = "/v1/auth/{mount_point}/login".format(mount_point=mount_point)
api_path = f"/v1/auth/{mount_point}/login"

# Must have cert checking or a CA cert. This is caught lower down but harder to grok
if not cacert:
Expand Down
1 change: 0 additions & 1 deletion hvac/api/auth_methods/gcp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""GCP methods module."""
import logging

Expand Down
1 change: 0 additions & 1 deletion hvac/api/auth_methods/github.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Github methods module."""
from hvac import exceptions, utils
from hvac.api.vault_api_base import VaultApiBase
Expand Down
1 change: 0 additions & 1 deletion hvac/api/auth_methods/jwt.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""JWT/OIDC methods module."""
from hvac import utils
from hvac.api.vault_api_base import VaultApiBase
Expand Down
1 change: 0 additions & 1 deletion hvac/api/auth_methods/kubernetes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Kubernetes methods module."""
from hvac import utils
from hvac.api.vault_api_base import VaultApiBase
Expand Down
1 change: 0 additions & 1 deletion hvac/api/auth_methods/ldap.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""LDAP methods module."""
from hvac import exceptions, utils
from hvac.api.vault_api_base import VaultApiBase
Expand Down
1 change: 0 additions & 1 deletion hvac/api/auth_methods/mfa.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Multi-factor authentication methods module."""
from hvac.api.vault_api_base import VaultApiBase
from hvac import exceptions, utils
Expand Down
3 changes: 1 addition & 2 deletions hvac/api/auth_methods/oidc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""JWT/OIDC methods module."""
from hvac.api.auth_methods.jwt import JWT

Expand Down Expand Up @@ -131,7 +130,7 @@ def create_role(
:rtype: dict
"""

super(OIDC, self).create_role(
super().create_role(
name=name,
user_claim=user_claim,
allowed_redirect_uris=allowed_redirect_uris,
Expand Down
1 change: 0 additions & 1 deletion hvac/api/auth_methods/okta.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Okta methods module."""
from hvac import utils
from hvac.api.vault_api_base import VaultApiBase
Expand Down
1 change: 0 additions & 1 deletion hvac/api/auth_methods/radius.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""RADIUS methods module."""
from hvac import exceptions, utils
from hvac.api.vault_api_base import VaultApiBase
Expand Down

0 comments on commit e84c959

Please sign in to comment.