Skip to content

Commit

Permalink
Merge pull request #101 from jtmoon79/blackify_1
Browse files Browse the repository at this point in the history
Blackify source pike/*.py
  • Loading branch information
jtmoon79 committed Feb 12, 2021
2 parents 5ac1f1c + da00b38 commit d01fd4f
Show file tree
Hide file tree
Showing 39 changed files with 3,474 additions and 2,645 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/test_samba.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (c) 2020, Dell Inc. or its subsidiaries.
# All rights reserved.
# See file LICENSE for licensing information.
#
# Reference: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions (https://archive.vn/1aWt2)
---
name: Run tests against samba

Expand Down Expand Up @@ -40,10 +42,10 @@ jobs:
run: python setup.py install
- name: Install pytest
run: pip install pytest
- name: Run Pike
run: python -m unittest -v pike.test.samba_suite
- name: Test Pike
env:
PIKE_SERVER: 127.0.0.1
PIKE_PORT: ${{ job.services.samba.ports[445] }}
PIKE_SHARE: pike
PIKE_CREDS: pike%GiThubCI123
run: python -m unittest -v pike.test.samba_suite
3 changes: 3 additions & 0 deletions .gitignorerevs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# blackify
03f70b27c00a188790c40a0a59e4cbfce29b9719
e347aeb25405a29e43492c125e532c969aa6d6c7
37 changes: 21 additions & 16 deletions pike/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,41 @@
#

import six

if six.PY2:
import array

oldarray = array.array
# monkey-patch tobytes for python 2.7
class newarray(oldarray):
def tobytes(self, *args, **kwargs):
return self.tostring(*args, **kwargs)

def __getslice__(self, *args, **kwargs):
return type(self)(self.typecode, super(newarray, self).__getslice__(*args, **kwargs))
return type(self)(
self.typecode, super(newarray, self).__getslice__(*args, **kwargs)
)

def __add__(self, *args, **kwargs):
return type(self)(self.typecode, super(newarray, self).__add__(*args, **kwargs))
return type(self)(
self.typecode, super(newarray, self).__add__(*args, **kwargs)
)

array.array = newarray

__all__ = [
'auth',
'core',
'crypto',
'digest',
'kerberos',
'model',
'netbios',
'ntlm'
'nttime',
'ntstatus',
'smb2',
'test',
'transport',
"auth",
"core",
"crypto",
"digest",
"kerberos",
"model",
"netbios",
"ntlm" "nttime",
"ntstatus",
"smb2",
"test",
"transport",
]
# __version__ is defined by setuptools_scm using git tag
# https://github.com/pypa/setuptools_scm/
# https://github.com/pypa/setuptools_scm/
50 changes: 27 additions & 23 deletions pike/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from builtins import object
import array
import warnings

try:
import kerberos
except ImportError:
Expand All @@ -37,12 +38,13 @@

def split_credentials(creds):
if isinstance(creds, bytes):
warnings.warn("Pass creds as unicode string, got {!r}".format(creds),
UnicodeWarning)
warnings.warn(
"Pass creds as unicode string, got {!r}".format(creds), UnicodeWarning
)
creds = creds.decode("utf-8")
user, password = creds.split('%')
if '\\' in user:
domain, user = user.split('\\')
user, password = creds.split("%")
if "\\" in user:
domain, user = user.split("\\")
else:
domain = "NONE"
return (domain, user, password)
Expand All @@ -58,32 +60,31 @@ def __init__(self, conn, creds=None):
# safe and only allow ascii characters.
cred_encoding = "ascii"
domain, user, password = split_credentials(creds)
(self.result,
self.context) = kerberos.authGSSClientInit(
(self.result, self.context) = kerberos.authGSSClientInit(
"cifs/" + conn.server,
gssmech=2,
user=user.encode(cred_encoding),
password=password.encode(cred_encoding),
domain=domain.encode(cred_encoding))
domain=domain.encode(cred_encoding),
)
else:
(self.result,
self.context) = kerberos.authGSSClientInit("cifs/" + conn.server,
gssmech=1)
(self.result, self.context) = kerberos.authGSSClientInit(
"cifs/" + conn.server, gssmech=1
)

def step(self, sec_buf):
self.result = kerberos.authGSSClientStep(
self.context,
sec_buf.tobytes())
self.result = kerberos.authGSSClientStep(self.context, sec_buf.tobytes())
if self.result == 0:
return (array.array(
'B',
kerberos.authGSSClientResponse(self.context)),
None)
return (
array.array("B", kerberos.authGSSClientResponse(self.context)),
None,
)
else:
kerberos.authGSSClientSessionKey(self.context)
return (None,
array.array('B',
kerberos.authGSSClientResponse(self.context)[:16]))
return (
None,
array.array("B", kerberos.authGSSClientResponse(self.context)[:16]),
)

def username(self):
return kerberos.authGSSClientUserName(self.context)
Expand All @@ -98,7 +99,10 @@ def step(self, sec_buf):
return (self.authenticator.negotiate(), None)
elif self.authenticator.challenge_message is None:
self.authenticator.authenticate(sec_buf)
return (self.authenticator.authenticate_buffer, self.authenticator.exported_session_key)
return (
self.authenticator.authenticate_buffer,
self.authenticator.exported_session_key,
)

def username(self):
return '{0}\{1}'.format(self.authenticator.domain, self.authenticator.username)
return "{0}\{1}".format(self.authenticator.domain, self.authenticator.username)
Loading

0 comments on commit d01fd4f

Please sign in to comment.