Skip to content

Commit 284403e

Browse files
Merge pull request #686 from IdentityPython/pylint-fixes
Fix pylint errors
2 parents 24d248c + b8c9c25 commit 284403e

File tree

15 files changed

+43
-154
lines changed

15 files changed

+43
-154
lines changed

src/saml2/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
import defusedxml.ElementTree
4141

4242

43-
root_logger = logging.getLogger(__name__)
44-
root_logger.level = logging.NOTSET
43+
logger = logging.getLogger(__name__)
4544

4645
NAMESPACE = 'urn:oasis:names:tc:SAML:2.0:assertion'
4746
# TEMPLATE = '{urn:oasis:names:tc:SAML:2.0:assertion}%s'

src/saml2/authn.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ def __init__(self, srv):
2929
self.srv = srv
3030

3131
def __call__(self, *args, **kwargs):
32-
raise NotImplemented
32+
raise NotImplementedError
3333

3434
def authenticated_as(self, **kwargs):
35-
raise NotImplemented
35+
raise NotImplementedError
3636

3737
def verify(self, **kwargs):
38-
raise NotImplemented
38+
raise NotImplementedError
3939

4040

4141
def is_equal(a, b):

src/saml2/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def do_logout(self, name_id, entity_ids, reason, expire, sign=None,
222222
sign = True
223223

224224
if sign is None:
225-
sign = self.logout_requests_signed
225+
sign = self.config.logout_requests_signed
226226

227227
sigalg = None
228228
if sign:

src/saml2/config.py

Lines changed: 6 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,20 @@
1010

1111
import six
1212

13-
from saml2 import root_logger, BINDING_URI, SAMLError
14-
from saml2 import BINDING_SOAP
15-
from saml2 import BINDING_HTTP_REDIRECT
16-
from saml2 import BINDING_HTTP_POST
1713
from saml2 import BINDING_HTTP_ARTIFACT
14+
from saml2 import BINDING_HTTP_POST
15+
from saml2 import BINDING_HTTP_REDIRECT
16+
from saml2 import BINDING_SOAP
17+
from saml2 import BINDING_URI
18+
from saml2 import SAMLError
1819

1920
from saml2.attribute_converter import ac_factory
2021
from saml2.assertion import Policy
2122
from saml2.mdstore import MetadataStore
2223
from saml2.saml import NAME_FORMAT_URI
2324
from saml2.virtual_org import VirtualOrg
2425

26+
2527
logger = logging.getLogger(__name__)
2628

2729
__author__ = 'rolandh'
@@ -47,7 +49,6 @@
4749
"contact_person",
4850
"name_form",
4951
"virtual_organization",
50-
"logger",
5152
"only_use_keys_in_metadata",
5253
"disable_ssl_certificate_validation",
5354
"preferred_binding",
@@ -211,7 +212,6 @@ def __init__(self, homedir="."):
211212
self.name_id_format = None
212213
self.name_id_format_allow_create = None
213214
self.virtual_organization = None
214-
self.logger = None
215215
self.only_use_keys_in_metadata = True
216216
self.logout_requests_signed = None
217217
self.disable_ssl_certificate_validation = None
@@ -453,63 +453,6 @@ def endpoint(self, service, binding=None, context=None):
453453
else:
454454
return unspec
455455

456-
def log_handler(self):
457-
try:
458-
_logconf = self.logger
459-
except KeyError:
460-
return None
461-
462-
handler = None
463-
for htyp in LOG_HANDLER:
464-
if htyp in _logconf:
465-
if htyp == "syslog":
466-
args = _logconf[htyp]
467-
if "socktype" in args:
468-
import socket
469-
if args["socktype"] == "dgram":
470-
args["socktype"] = socket.SOCK_DGRAM
471-
elif args["socktype"] == "stream":
472-
args["socktype"] = socket.SOCK_STREAM
473-
else:
474-
raise ConfigurationError("Unknown socktype!")
475-
try:
476-
handler = LOG_HANDLER[htyp](**args)
477-
except TypeError: # difference between 2.6 and 2.7
478-
del args["socktype"]
479-
handler = LOG_HANDLER[htyp](**args)
480-
else:
481-
handler = LOG_HANDLER[htyp](**_logconf[htyp])
482-
break
483-
484-
if handler is None:
485-
# default if rotating logger
486-
handler = LOG_HANDLER["rotating"]()
487-
488-
if "format" in _logconf:
489-
formatter = logging.Formatter(_logconf["format"])
490-
else:
491-
formatter = logging.Formatter(LOG_FORMAT)
492-
493-
handler.setFormatter(formatter)
494-
return handler
495-
496-
def setup_logger(self):
497-
if root_logger.level != logging.NOTSET: # Someone got there before me
498-
return root_logger
499-
500-
_logconf = self.logger
501-
if _logconf is None:
502-
return root_logger
503-
504-
try:
505-
root_logger.setLevel(LOG_LEVEL[_logconf["loglevel"].lower()])
506-
except KeyError: # reasonable default
507-
root_logger.setLevel(logging.INFO)
508-
509-
root_logger.addHandler(self.log_handler())
510-
root_logger.info("Logging started")
511-
return root_logger
512-
513456
def endpoint2service(self, endpoint, context=None):
514457
endps = self.getattr("endpoints", context)
515458

src/saml2/cryptography/symmetric.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def build_cipher(self, *args, **kwargs):
8989
"The 'Fernet' class does not need a build_cipher method."
9090
"Remove any calls to this method. "
9191
"In the next version, this method will be removed."
92-
).format(name=cls.__name__, type=type(cls).__name__)
92+
)
9393
_warnings.warn(_deprecation_msg, DeprecationWarning)
9494

9595

src/saml2/entity.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ def __init__(self, entity_type, config=None, config_file="",
159159
vo.sp = self
160160

161161
self.metadata = self.config.metadata
162-
self.config.setup_logger()
163162
self.debug = self.config.debug
164163

165164
self.sec = security_context(self.config)

src/saml2/httpbase.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ def _since_epoch(cdate):
8484
break
8585

8686
if t == -1:
87-
raise (Exception,
88-
'ValueError: Date "{0}" does not match any of: {1}'.format(
89-
cdate,TIME_FORMAT))
87+
err = 'ValueError: Date "{0}" does not match any of: {1}'.format(
88+
cdate, TIME_FORMAT
89+
)
90+
raise Exception(err)
9091

9192
return calendar.timegm(t)
9293

@@ -328,7 +329,7 @@ def use_http_uri(message, typ, destination="", relay_state=""):
328329
"url": "%s?%s" % (destination, query)
329330
}
330331
else:
331-
raise NotImplemented
332+
raise NotImplementedError
332333

333334
return info
334335

src/saml2/ident.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def remove_remote(self, name_id):
140140
del self.db[name_id.text]
141141

142142
def remove_local(self, sid):
143-
if isinstance(sid, unicode):
143+
if not isinstance(sid, bytes):
144144
sid = sid.encode("utf-8")
145145

146146
try:

src/saml2/mongo_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def __getitem__(self, key):
321321
raise CorruptDatabase("Found more than one EPTID document")
322322

323323
def __setitem__(self, key, value):
324-
_ = self.mdb.store(key, **{"eptid": value})
324+
self.mdb.store(key, **{"eptid": value})
325325

326326

327327
#------------------------------------------------------------------------------

src/saml2/s2repoze/plugins/formswithhidden.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import urllib
1+
from six.moves.urllib.parse import urlencode
22

33
from paste.httpheaders import CONTENT_LENGTH
44
from paste.httpheaders import CONTENT_TYPE
@@ -71,7 +71,7 @@ def identify(self, environ):
7171
return None
7272
del query[self.login_form_qs]
7373
query.update(qinfo)
74-
environ["QUERY_STRING"] = urllib.urlencode(query)
74+
environ["QUERY_STRING"] = urlencode(query)
7575
environ["repoze.who.application"] = HTTPFound(construct_url(environ))
7676
credentials = {"login": login, "password": password}
7777
max_age = form.get("max_age", None)

0 commit comments

Comments
 (0)