Skip to content

Commit 88feeba

Browse files
akxc00kiemon5ter
authored andcommitted
Run pyupgrade --py36-plus + black + isort
1 parent 4fa20a9 commit 88feeba

File tree

106 files changed

+582
-661
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+582
-661
lines changed

docs/conf.py

+54-55
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# pysaml2 documentation build configuration file, created by
43
# sphinx-quickstart on Mon Aug 24 08:13:41 2009.
@@ -11,41 +10,41 @@
1110
# All configuration values have a default; values that are commented out
1211
# serve to show the default.
1312

14-
from __future__ import unicode_literals
1513

1614
import os
1715

1816
import alabaster
1917

2018
import saml2.version
2119

20+
2221
# If extensions (or modules to document with autodoc) are in another directory,
2322
# add these directories to sys.path here. If the directory is relative to the
2423
# documentation root, use os.path.abspath to make it absolute, like shown here.
25-
#sys.path.append(os.path.abspath('.'))
24+
# sys.path.append(os.path.abspath('.'))
2625

2726
# -- General configuration -----------------------------------------------------
2827

2928
# Add any Sphinx extension module names here, as strings. They can be extensions
3029
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
3130

32-
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.coverage']
31+
extensions = ["sphinx.ext.autodoc", "sphinx.ext.doctest", "sphinx.ext.coverage"]
3332

3433
# Add any paths that contain templates here, relative to this directory.
35-
templates_path = ['_templates']
34+
templates_path = ["_templates"]
3635

3736
# The suffix of source filenames.
38-
source_suffix = '.rst'
37+
source_suffix = ".rst"
3938

4039
# The encoding of source files.
41-
#source_encoding = 'utf-8'
40+
# source_encoding = 'utf-8'
4241

4342
# The master toctree document.
44-
master_doc = 'index'
43+
master_doc = "index"
4544

4645
# General information about the project.
47-
project = 'pysaml2'
48-
copyright = '2010-2011, Roland Hedberg'
46+
project = "pysaml2"
47+
copyright = "2010-2011, Roland Hedberg"
4948

5049
# The version info for the project you're documenting, acts as replacement for
5150
# |version| and |release|, also used in various other places throughout the
@@ -54,159 +53,159 @@
5453
# The short X.Y version.
5554
version = str(saml2.version.version)
5655
# The full version, including alpha/beta/rc tags.
57-
release = ''
56+
release = ""
5857

5958
# The language for content autogenerated by Sphinx. Refer to documentation
6059
# for a list of supported languages.
61-
#language = None
60+
# language = None
6261

6362
# There are two options for replacing |today|: either, you set today to some
6463
# non-false value, then it is used:
65-
#today = ''
64+
# today = ''
6665
# Else, today_fmt is used as the format for a strftime call.
67-
#today_fmt = '%B %d, %Y'
66+
# today_fmt = '%B %d, %Y'
6867

6968
# List of documents that shouldn't be included in the build.
70-
#unused_docs = []
69+
# unused_docs = []
7170

7271
# List of directories, relative to source directory, that shouldn't be searched
7372
# for source files.
74-
exclude_trees = ['_build']
73+
exclude_trees = ["_build"]
7574

7675
# The reST default role (used for this markup: `text`) to use for all documents.
77-
#default_role = None
76+
# default_role = None
7877

7978
# If true, '()' will be appended to :func: etc. cross-reference text.
80-
#add_function_parentheses = True
79+
# add_function_parentheses = True
8180

8281
# If true, the current module name will be prepended to all description
8382
# unit titles (such as .. function::).
84-
#add_module_names = True
83+
# add_module_names = True
8584

8685
# If true, sectionauthor and moduleauthor directives will be shown in the
8786
# output. They are ignored by default.
88-
#show_authors = False
87+
# show_authors = False
8988

9089
# The name of the Pygments (syntax highlighting) style to use.
91-
pygments_style = 'sphinx'
90+
pygments_style = "sphinx"
9291

9392
# A list of ignored prefixes for module index sorting.
94-
#modindex_common_prefix = []
93+
# modindex_common_prefix = []
9594

9695

9796
# -- Options for HTML output ---------------------------------------------------
9897

9998
# The theme to use for HTML and HTML Help pages. Major themes that come with
10099
# Sphinx are currently 'default' and 'sphinxdoc'.
101100
html_theme_path = [alabaster.get_path()]
102-
html_theme = 'alabaster'
103-
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
101+
html_theme = "alabaster"
102+
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
104103

105104
if on_rtd: # only import and set the theme if we're building docs locally
106-
html_theme = 'sphinx_rtd_theme'
105+
html_theme = "sphinx_rtd_theme"
107106

108107

109108
# Theme options are theme-specific and customize the look and feel of a theme
110109
# further. For a list of options available for each theme, see the
111110
# documentation.
112-
#html_theme_options = {}
111+
# html_theme_options = {}
113112

114113
# Add any paths that contain custom themes here, relative to this directory.
115-
#html_theme_path = []
114+
# html_theme_path = []
116115

117116
# The name for this set of Sphinx documents. If None, it defaults to
118117
# "<project> v<release> documentation".
119-
#html_title = None
118+
# html_title = None
120119

121120
# A shorter title for the navigation bar. Default is the same as html_title.
122-
#html_short_title = None
121+
# html_short_title = None
123122

124123
# The name of an image file (relative to this directory) to place at the top
125124
# of the sidebar.
126-
#html_logo = None
125+
# html_logo = None
127126

128127
# The name of an image file (within the static path) to use as favicon of the
129128
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
130129
# pixels large.
131-
#html_favicon = None
130+
# html_favicon = None
132131

133132
# Add any paths that contain custom static files (such as style sheets) here,
134133
# relative to this directory. They are copied after the builtin static files,
135134
# so a file named "default.css" will overwrite the builtin "default.css".
136-
html_static_path = ['_static']
135+
html_static_path = ["_static"]
137136

138137
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
139138
# using the given strftime format.
140-
#html_last_updated_fmt = '%b %d, %Y'
139+
# html_last_updated_fmt = '%b %d, %Y'
141140

142141
# If true, SmartyPants will be used to convert quotes and dashes to
143142
# typographically correct entities.
144-
#html_use_smartypants = True
143+
# html_use_smartypants = True
145144

146145
# Custom sidebar templates, maps document names to template names.
147-
#html_sidebars = {}
146+
# html_sidebars = {}
148147

149148
# Additional templates that should be rendered to pages, maps page names to
150149
# template names.
151-
#html_additional_pages = {}
150+
# html_additional_pages = {}
152151

153152
# If false, no module index is generated.
154-
#html_use_modindex = True
153+
# html_use_modindex = True
155154

156155
# If false, no index is generated.
157-
#html_use_index = True
156+
# html_use_index = True
158157

159158
# If true, the index is split into individual pages for each letter.
160-
#html_split_index = False
159+
# html_split_index = False
161160

162161
# If true, links to the reST sources are added to the pages.
163-
#html_show_sourcelink = True
162+
# html_show_sourcelink = True
164163

165164
# If true, an OpenSearch description file will be output, and all pages will
166165
# contain a <link> tag referring to it. The value of this option must be the
167166
# base URL from which the finished HTML is served.
168-
#html_use_opensearch = ''
167+
# html_use_opensearch = ''
169168

170169
# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
171-
#html_file_suffix = ''
170+
# html_file_suffix = ''
172171

173172
# Output file base name for HTML help builder.
174-
htmlhelp_basename = 'pysaml2doc'
173+
htmlhelp_basename = "pysaml2doc"
175174

176175

177176
# -- Options for LaTeX output --------------------------------------------------
178177

179178
# The paper size ('letter' or 'a4').
180-
#latex_paper_size = 'letter'
179+
# latex_paper_size = 'letter'
181180

182181
# The font size ('10pt', '11pt' or '12pt').
183-
#latex_font_size = '10pt'
182+
# latex_font_size = '10pt'
184183

185184
# Grouping the document tree into LaTeX files. List of tuples
186185
# (source start file, target name, title, author, documentclass [howto/manual]).
187186
latex_documents = [
188187
(
189-
'index',
190-
'pysaml2.tex',
191-
'pysaml2 Documentation',
192-
'Roland Hedberg',
193-
'manual',
188+
"index",
189+
"pysaml2.tex",
190+
"pysaml2 Documentation",
191+
"Roland Hedberg",
192+
"manual",
194193
),
195194
]
196195

197196
# The name of an image file (relative to this directory) to place at the top of
198197
# the title page.
199-
#latex_logo = None
198+
# latex_logo = None
200199

201200
# For "manual" documents, if this is true, then toplevel headings are parts,
202201
# not chapters.
203-
#latex_use_parts = False
202+
# latex_use_parts = False
204203

205204
# Additional stuff for the LaTeX preamble.
206-
#latex_preamble = ''
205+
# latex_preamble = ''
207206

208207
# Documents to append as an appendix to all manuals.
209-
#latex_appendices = []
208+
# latex_appendices = []
210209

211210
# If false, no module index is generated.
212-
#latex_use_modindex = True
211+
# latex_use_modindex = True

example/idp2/idp.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
import argparse
33
import base64
44
from hashlib import sha1
5+
from http.cookies import SimpleCookie
56
import importlib
67
import logging
78
import os
89
import re
910
import time
11+
from urllib.parse import parse_qs
1012

1113
from idp_user import EXTRA
1214
from idp_user import USERS
1315
from mako.lookup import TemplateLookup
1416
import six
15-
from six.moves.http_cookies import SimpleCookie
16-
from six.moves.urllib.parse import parse_qs
1717

1818
from saml2 import BINDING_HTTP_ARTIFACT
1919
from saml2 import BINDING_HTTP_POST
@@ -61,7 +61,7 @@
6161
logger.setLevel(logging.WARNING)
6262

6363

64-
class Cache(object):
64+
class Cache:
6565
def __init__(self):
6666
self.user2uid = {}
6767
self.uid2user = {}
@@ -93,7 +93,7 @@ def dict2list_of_tuples(d):
9393
# -----------------------------------------------------------------------------
9494

9595

96-
class Service(object):
96+
class Service:
9797
def __init__(self, environ, start_response, user=None):
9898
self.environ = environ
9999
logger.debug("ENVIRON: %s", environ)
@@ -103,7 +103,7 @@ def __init__(self, environ, start_response, user=None):
103103
def unpack_redirect(self):
104104
if "QUERY_STRING" in self.environ:
105105
_qs = self.environ["QUERY_STRING"]
106-
return dict([(k, v[0]) for k, v in parse_qs(_qs).items()])
106+
return {k: v[0] for k, v in parse_qs(_qs).items()}
107107
else:
108108
return None
109109

@@ -112,7 +112,7 @@ def unpack_post(self):
112112
_dict = parse_qs(post_data if isinstance(post_data, str) else post_data.decode("utf-8"))
113113
logger.debug("unpack_post:: %s", _dict)
114114
try:
115-
return dict([(k, v[0]) for k, v in _dict.items()])
115+
return {k: v[0] for k, v in _dict.items()}
116116
except Exception:
117117
return None
118118

@@ -323,11 +323,11 @@ def do(self, query, binding_in, relay_state="", encrypt_cert=None, **kwargs):
323323
resp_args, _resp = self.verify_request(query, binding_in)
324324
except UnknownPrincipal as excp:
325325
logger.error("UnknownPrincipal: %s", excp)
326-
resp = ServiceError("UnknownPrincipal: %s" % (excp,))
326+
resp = ServiceError(f"UnknownPrincipal: {excp}")
327327
return resp(self.environ, self.start_response)
328328
except UnsupportedBinding as excp:
329329
logger.error("UnsupportedBinding: %s", excp)
330-
resp = ServiceError("UnsupportedBinding: %s" % (excp,))
330+
resp = ServiceError(f"UnsupportedBinding: {excp}")
331331
return resp(self.environ, self.start_response)
332332

333333
if not _resp:
@@ -350,7 +350,7 @@ def do(self, query, binding_in, relay_state="", encrypt_cert=None, **kwargs):
350350
)
351351
except Exception as excp:
352352
logging.error(exception_trace(excp))
353-
resp = ServiceError("Exception: %s" % (excp,))
353+
resp = ServiceError(f"Exception: {excp}")
354354
return resp(self.environ, self.start_response)
355355

356356
logger.info("AuthNResponse: %s", _resp)
@@ -566,7 +566,7 @@ def verify_username_and_password(dic):
566566

567567
def do_verify(environ, start_response, _):
568568
query_str = get_post(environ)
569-
if not isinstance(query_str, six.string_types):
569+
if not isinstance(query_str, str):
570570
query_str = query_str.decode("ascii")
571571
query = parse_qs(query_str)
572572

@@ -588,7 +588,7 @@ def do_verify(environ, start_response, _):
588588

589589
kaka = set_cookie("idpauthn", "/", uid, query["authn_reference"][0])
590590

591-
lox = "%s?id=%s&key=%s" % (query["redirect_uri"][0], uid, query["key"][0])
591+
lox = "{}?id={}&key={}".format(query["redirect_uri"][0], uid, query["key"][0])
592592
logger.debug("Redirect => %s", lox)
593593
resp = Redirect(lox, headers=[kaka], content="text/html")
594594

@@ -849,7 +849,7 @@ def info_from_cookie(kaka):
849849
if morsel:
850850
try:
851851
data = base64.b64decode(morsel.value)
852-
if not isinstance(data, six.string_types):
852+
if not isinstance(data, str):
853853
data = data.decode("ascii")
854854
key, ref = data.split(":", 1)
855855
return IDP.cache.uid2user[key], ref
@@ -879,11 +879,11 @@ def set_cookie(name, _, *args):
879879
cookie = SimpleCookie()
880880

881881
data = ":".join(args)
882-
if not isinstance(data, six.binary_type):
882+
if not isinstance(data, bytes):
883883
data = data.encode("ascii")
884884

885885
data64 = base64.b64encode(data)
886-
if not isinstance(data64, six.string_types):
886+
if not isinstance(data64, str):
887887
data64 = data64.decode("ascii")
888888

889889
cookie[name] = data64
@@ -979,7 +979,7 @@ def staticfile(environ, start_response):
979979
resp = Unauthorized()
980980
return resp(environ, start_response)
981981
start_response("200 OK", [("Content-Type", "text/xml")])
982-
return open(path, "r").read()
982+
return open(path).read()
983983
except Exception as ex:
984984
logger.error("An error occured while creating metadata: %s", ex.message)
985985
return not_found(environ, start_response)
@@ -1110,7 +1110,7 @@ def application(environ, start_response):
11101110
SRV.ssl_adapter = BuiltinSSLAdapter(CONFIG.SERVER_CERT, CONFIG.SERVER_KEY, CONFIG.CERT_CHAIN)
11111111

11121112
logger.info("Server starting")
1113-
print("IDP listening on %s:%s%s" % (HOST, PORT, _https))
1113+
print(f"IDP listening on {HOST}:{PORT}{_https}")
11141114
try:
11151115
SRV.start()
11161116
except KeyboardInterrupt:

0 commit comments

Comments
 (0)