Skip to content

Commit

Permalink
pep-8 tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
aholmberg committed Jan 28, 2016
1 parent 8619a99 commit 25b860b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
1 change: 1 addition & 0 deletions puresasl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class SASLProtocolException(Exception):
"""
pass


class QOP(object):

AUTH = b'auth'
Expand Down
13 changes: 7 additions & 6 deletions puresasl/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class SASLClient(object):
"""

def __init__(self, host, service=None, mechanism=None, authorization_id=None,
callback=None, qops=QOP.all,
mutual_auth=False, max_buffer=65536, **mechanism_props):
callback=None, qops=QOP.all, mutual_auth=False, max_buffer=65536,
**mechanism_props):
"""
`host` is the name of the SASL server, typically an FQDN, and `service` is
usually the name of the protocol, such as `imap` or `http`.
Expand Down Expand Up @@ -176,7 +176,8 @@ def dispose(self):
self._chosen_mech.dispose()

def choose_mechanism(self, mechanism_choices, allow_anonymous=True,
allow_plaintext=True, allow_active=True, allow_dictionary=True):
allow_plaintext=True, allow_active=True,
allow_dictionary=True):
"""
Choose a mechanism from a list of mechanisms based on security
scores for mechanisms and required properties of the mechanism.
Expand All @@ -196,8 +197,8 @@ def choose_mechanism(self, mechanism_choices, allow_anonymous=True,
to passive dictionary attacks will not be considered.
"""
candidates = [mech_mod.mechanisms[choice]
for choice in mechanism_choices
if choice in mech_mod.mechanisms]
for choice in mechanism_choices
if choice in mech_mod.mechanisms]

if not allow_anonymous:
candidates = [m for m in candidates if not m.allows_anonymous]
Expand All @@ -210,7 +211,7 @@ def choose_mechanism(self, mechanism_choices, allow_anonymous=True,

if not candidates:
raise SASLError("None of the mechanisms listed meet all "
"required properties")
"required properties")

# Pick the best mechanism based on its security score
mech_class = max(candidates, key=lambda mech: mech.score)
Expand Down
13 changes: 6 additions & 7 deletions puresasl/mechanisms.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def _fetch_properties(self, *properties):
needed = [p for p in properties if getattr(self, p, None) is None]
if needed and not self.sasl.callback:
raise SASLError('The following properties are required, but a '
'callback has not been set: %s' % ', '.join(needed))
'callback has not been set: %s' % ', '.join(needed))

for prop in needed:
setattr(self, prop, self.sasl.callback(prop))
Expand All @@ -109,8 +109,8 @@ def _pick_qop(self, server_qop_set):
configured = b', '.join(configured_qops).decode('ascii')
offered = b', '.join(server_qop_set).decode('ascii')
raise SASLProtocolException("Your requested quality of "
"protection is one of (%s), but the server is only "
"offering (%s)" % (configured, offered))
"protection is one of (%s), but the server is only "
"offering (%s)" % (configured, offered))
else:
self.qops = available_qops
for qop in (QOP.AUTH_CONF, QOP.AUTH_INT, QOP.AUTH):
Expand Down Expand Up @@ -223,13 +223,12 @@ def __init__(self, sasl, principal=None, **props):

krb_service = '@'.join((self.service, self.host))
try:
_, self.context = kerberos.authGSSClientInit(
service=krb_service, principal=self.principal)
_, self.context = kerberos.authGSSClientInit(service=krb_service,
principal=self.principal)
except TypeError:
if self.principal is not None:
raise Exception("Error: kerberos library does not support principal.")
_, self.context = kerberos.authGSSClientInit(
service=krb_service)
_, self.context = kerberos.authGSSClientInit(service=krb_service)

def process(self, challenge=None):
if not self._have_negotiated_details:
Expand Down
5 changes: 2 additions & 3 deletions tests/unit/test_mechanism.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import hashlib
import hmac
import kerberos
from mock import Mock, patch
from mock import patch
import six
import struct

Expand Down Expand Up @@ -55,7 +55,7 @@ class PlainTextMechanismTest(_BaseMechanismTests):
sasl_kwargs = {'username': username, 'password': password}

def test_process(self):
for challenge in (None, '', b'asdf', u"\U0001F44D"):
for challenge in (None, '', b'asdf', u"\U0001F44D"):
response = self.sasl.process(challenge)
self.assertIn(six.b(self.username), response)
self.assertIn(six.b(self.password), response)
Expand All @@ -75,7 +75,6 @@ class GSSAPIMechanismTest(_BaseMechanismTests):
service = 'GSSAPI'
sasl_kwargs = {'service': service}


@patch('puresasl.mechanisms.kerberos.authGSSClientWrap')
@patch('puresasl.mechanisms.kerberos.authGSSClientUnwrap')
def test_wrap_unwrap(self, _inner1, _inner2, authGSSClientResponse, *args):
Expand Down

0 comments on commit 25b860b

Please sign in to comment.