Skip to content

Commit 86dc1ab

Browse files
authored
Merge pull request ojarva#51 from ojarva/yapf
Apply yapf
2 parents ed0399a + 85b9f41 commit 86dc1ab

16 files changed

+517
-620
lines changed

Diff for: .isort.cfg

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[settings]
2-
line_length = 120
2+
combine_as_imports = true
3+
force_alphabetical_sort = true
4+
line_length = 125
5+
no_sections = true
36
not_skip = __init__.py

Diff for: .pylintrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[format]
2+
max-line-length=125
3+
4+
[messages control]
5+
disable=line-too-long,missing-docstring,no-self-use,fixme,bad-indentation,bad-continuation,invalid-name,too-many-locals,duplicate-code,too-many-branches,wrong-import-order

Diff for: .style.yapf

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[style]
2+
based_on_style = pep8
3+
allow_split_before_dict_value = false
4+
blank_line_before_nested_class_or_def = false
5+
coalesce_brackets = true
6+
column_limit = 125
7+
dedent_closing_brackets = true
8+
each_dict_entry_on_separate_line = true
9+
join_multiple_lines = true
10+
spaces_around_power_operator = true

Diff for: .travis.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ python:
99
- "nightly"
1010
install:
1111
- pip install -r requirements.txt
12-
- pip install pycodestyle isort pylint
12+
- pip install pycodestyle isort pylint yapf
1313
script:
1414
- isort --diff --check --recursive sshpubkeys tests
1515
- pycodestyle --ignore E501,E402 --exclude=.git,dev3 sshpubkeys tests
16-
- pylint sshpubkeys tests --disable line-too-long --disable missing-docstring --disable no-self-use --disable fixme --disable bad-indentation --disable bad-continuation --disable invalid-name --disable too-many-locals --disable duplicate-code --disable too-many-branches
16+
- pylint sshpubkeys tests
17+
- isort --recursive sshpubkeys tests; yapf --recursive .
18+
- git diff --exit-code # This fails if isort&yapf combo made any changes
1719
- python setup.py test

Diff for: requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
ecdsa==0.13
21
cryptography==2.1.4
2+
ecdsa==0.13
3+
yapf==0.21.0

Diff for: setup.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,12 @@
1616
author='Olli Jarva',
1717
author_email='[email protected]',
1818
license='BSD',
19-
2019
classifiers=[
2120
'Development Status :: 4 - Beta',
22-
2321
'Intended Audience :: Developers',
2422
'Intended Audience :: System Administrators',
2523
'Topic :: Security',
2624
'License :: OSI Approved :: BSD License',
27-
2825
'Programming Language :: Python :: 2.7',
2926
'Programming Language :: Python :: 3',
3027
'Programming Language :: Python :: 3.4',
@@ -37,8 +34,7 @@
3734
packages=["sshpubkeys"],
3835
test_suite="tests",
3936
install_requires=['cryptography>=2.1.4', 'ecdsa>=0.13'],
40-
4137
extras_require={
42-
'dev': ['twine', 'wheel'],
38+
'dev': ['twine', 'wheel', 'yapf'],
4339
},
4440
)

Diff for: sshpubkeys/exceptions.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# pylint:disable=line-too-long,too-many-ancestors
2-
32
"""Exceptions for sshpubkeys."""
43

54

Diff for: sshpubkeys/keys.py

+20-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# pylint:disable=line-too-long
2-
32
"""Parser for ssh public keys. Currently supports ssh-rsa, ssh-dsa, ssh-ed25519 and ssh-dss keys.
43
54
import sys
@@ -14,23 +13,22 @@
1413
sys.exit(1)
1514
print(ssh_key.bits)"""
1615

16+
from .exceptions import (InvalidKeyError, InvalidKeyLengthError, InvalidOptionNameError, InvalidOptionsError,
17+
InvalidTypeError, MalformedDataError, MissingMandatoryOptionValueError, TooLongKeyError,
18+
TooShortKeyError, UnknownOptionNameError)
19+
from cryptography.hazmat.backends import default_backend
20+
from cryptography.hazmat.primitives.asymmetric.dsa import DSAParameterNumbers, DSAPublicNumbers
21+
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicNumbers
22+
1723
import base64
1824
import binascii
25+
import ecdsa
1926
import hashlib
2027
import re
2128
import struct
2229
import sys
2330
import warnings
2431

25-
import ecdsa
26-
from cryptography.hazmat.backends import default_backend
27-
from cryptography.hazmat.primitives.asymmetric.dsa import DSAParameterNumbers, DSAPublicNumbers
28-
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicNumbers
29-
30-
from .exceptions import (InvalidKeyError, InvalidKeyLengthError, InvalidOptionNameError, InvalidOptionsError,
31-
InvalidTypeError, MalformedDataError, MissingMandatoryOptionValueError, TooLongKeyError,
32-
TooShortKeyError, UnknownOptionNameError)
33-
3432
__all__ = ["AuthorizedKeysFile", "SSHKey"]
3533

3634

@@ -180,7 +178,9 @@ def _unpack_by_int(self, data, current_position):
180178
remaining_data_length = len(data[current_position:])
181179

182180
if remaining_data_length < requested_data_length:
183-
raise MalformedDataError("Requested %s bytes, but only %s bytes available." % (requested_data_length, remaining_data_length))
181+
raise MalformedDataError(
182+
"Requested %s bytes, but only %s bytes available." % (requested_data_length, remaining_data_length)
183+
)
184184

185185
next_data = data[current_position:current_position + requested_data_length]
186186
# Move pointer to the end of the data field
@@ -312,9 +312,13 @@ def _process_ssh_rsa(self, data):
312312
min_length = self.RSA_MIN_LENGTH_LOOSE
313313
max_length = self.RSA_MAX_LENGTH_LOOSE
314314
if self.bits < min_length:
315-
raise TooShortKeyError("%s key data can not be shorter than %s bits (was %s)" % (self.key_type, min_length, self.bits))
315+
raise TooShortKeyError(
316+
"%s key data can not be shorter than %s bits (was %s)" % (self.key_type, min_length, self.bits)
317+
)
316318
if self.bits > max_length:
317-
raise TooLongKeyError("%s key data can not be longer than %s bits (was %s)" % (self.key_type, max_length, self.bits))
319+
raise TooLongKeyError(
320+
"%s key data can not be longer than %s bits (was %s)" % (self.key_type, max_length, self.bits)
321+
)
318322
return current_position
319323

320324
def _process_ssh_dss(self, data):
@@ -338,7 +342,9 @@ def _process_ssh_dss(self, data):
338342
if p_bits < min_length:
339343
raise TooShortKeyError("%s key can not be shorter than %s bits (was %s)" % (self.key_type, min_length, p_bits))
340344
if p_bits > max_length:
341-
raise TooLongKeyError("%s key data can not be longer than %s bits (was %s)" % (self.key_type, max_length, p_bits))
345+
raise TooLongKeyError(
346+
"%s key data can not be longer than %s bits (was %s)" % (self.key_type, max_length, p_bits)
347+
)
342348

343349
dsa_parameters = DSAParameterNumbers(data_fields["p"], data_fields["q"], data_fields["g"])
344350
self.dsa = DSAPublicNumbers(data_fields["y"], dsa_parameters).public_key(default_backend())

Diff for: tests/__init__.py

+17-11
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,34 @@
44
55
"""
66

7-
import sys
8-
import unittest
9-
10-
from sshpubkeys import AuthorizedKeysFile, InvalidOptionsError, SSHKey
11-
127
from .authorized_keys import items as list_of_authorized_keys
138
from .invalid_authorized_keys import items as list_of_invalid_authorized_keys
149
from .invalid_keys import keys as list_of_invalid_keys
1510
from .invalid_options import options as list_of_invalid_options
1611
from .valid_keys import keys as list_of_valid_keys
1712
from .valid_keys_rfc4716 import keys as list_of_valid_keys_rfc4716
1813
from .valid_options import options as list_of_valid_options
14+
from sshpubkeys import AuthorizedKeysFile, InvalidOptionsError, SSHKey
15+
16+
import sys
17+
import unittest
1918

2019
if sys.version_info.major == 2:
2120
from io import BytesIO as StringIO
2221
else:
2322
from io import StringIO
2423

25-
2624
DEFAULT_KEY = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEGODBKRjsFB/1v3pDRGpA6xR+QpOJg9vat0brlbUNDD"
2725

2826

2927
class TestMisc(unittest.TestCase):
30-
3128
def test_none_to_constructor(self):
3229
ssh = SSHKey(None)
3330
self.assertEqual(None, ssh.keydata) # Python2.6 does not have assertIsNone
3431
self.assertRaises(ValueError, ssh.parse)
3532

3633

3734
class TestKeys(unittest.TestCase):
38-
3935
def check_key(self, pubkey, bits, fingerprint_md5, fingerprint_sha256, options, comment, **kwargs): # pylint:disable=too-many-arguments
4036
""" Checks valid key """
4137
ssh = SSHKey(pubkey, **kwargs)
@@ -55,7 +51,6 @@ def check_fail(self, pubkey, expected_error, **kwargs):
5551

5652

5753
class TestOptions(unittest.TestCase):
58-
5954
def check_valid_option(self, option, parsed_option):
6055
ssh = SSHKey()
6156
parsed = ssh.parse_options(option)
@@ -72,7 +67,6 @@ def test_disallow_options(self):
7267

7368

7469
class TestAuthorizedKeys(unittest.TestCase):
75-
7670
def check_valid_file(self, file_str, valid_keys_count):
7771
file_obj = StringIO(file_str)
7872
key_file = AuthorizedKeysFile(file_obj)
@@ -94,8 +88,10 @@ def test_disallow_options(self):
9488

9589
def loop_options(options):
9690
""" Loop over list of options and dynamically create tests """
91+
9792
def ch(option, parsed_option):
9893
return lambda self: self.check_valid_option(option, parsed_option)
94+
9995
for i, items in enumerate(options):
10096
prefix_tmp = "%s_%s" % (items[0], i)
10197
setattr(TestOptions, "test_%s" % prefix_tmp, ch(items[1], items[2]))
@@ -104,15 +100,18 @@ def ch(option, parsed_option):
104100
def loop_invalid_options(options):
105101
def ch(option, expected_error):
106102
return lambda self: self.check_invalid_option(option, expected_error)
103+
107104
for i, items in enumerate(options):
108105
prefix_tmp = "%s_%s" % (items[0], i)
109106
setattr(TestOptions, "test_%s" % prefix_tmp, ch(items[1], items[2]))
110107

111108

112109
def loop_valid(keyset, prefix):
113110
""" Loop over list of valid keys and dynamically create tests """
111+
114112
def ch(pubkey, bits, fingerprint_md5, fingerprint_sha256, options, comment, **kwargs): # pylint:disable=too-many-arguments
115113
return lambda self: self.check_key(pubkey, bits, fingerprint_md5, fingerprint_sha256, options, comment, **kwargs)
114+
116115
for items in keyset:
117116
modes = items.pop()
118117
prefix_tmp = "%s_%s" % (prefix, items.pop())
@@ -126,13 +125,18 @@ def ch(pubkey, bits, fingerprint_md5, fingerprint_sha256, options, comment, **kw
126125
options = comment = None
127126
else:
128127
pubkey, bits, fingerprint_md5, fingerprint_sha256, options, comment = items
129-
setattr(TestKeys, "test_%s_mode_%s" % (prefix_tmp, mode), ch(pubkey, bits, fingerprint_md5, fingerprint_sha256, options, comment, **kwargs))
128+
setattr(
129+
TestKeys, "test_%s_mode_%s" % (prefix_tmp, mode),
130+
ch(pubkey, bits, fingerprint_md5, fingerprint_sha256, options, comment, **kwargs)
131+
)
130132

131133

132134
def loop_invalid(keyset, prefix):
133135
""" Loop over list of invalid keys and dynamically create tests """
136+
134137
def ch(pubkey, expected_error, **kwargs):
135138
return lambda self: self.check_fail(pubkey, expected_error, **kwargs)
139+
136140
for items in keyset:
137141
modes = items.pop()
138142
prefix_tmp = "%s_%s" % (prefix, items.pop())
@@ -148,6 +152,7 @@ def ch(pubkey, expected_error, **kwargs):
148152
def loop_authorized_keys(keyset):
149153
def ch(file_str, valid_keys_count):
150154
return lambda self: self.check_valid_file(file_str, valid_keys_count)
155+
151156
for i, items in enumerate(keyset):
152157
prefix_tmp = "%s_%s" % (items[0], i)
153158
setattr(TestAuthorizedKeys, "test_%s" % prefix_tmp, ch(items[1], items[2]))
@@ -156,6 +161,7 @@ def ch(file_str, valid_keys_count):
156161
def loop_invalid_authorized_keys(keyset):
157162
def ch(file_str, expected_error, **kwargs):
158163
return lambda self: self.check_invalid_file(file_str, expected_error, **kwargs)
164+
159165
for i, items in enumerate(keyset):
160166
prefix_tmp = "%s_%s" % (items[0], i)
161167
setattr(TestAuthorizedKeys, "test_invalid_%s" % prefix_tmp, ch(items[1], items[2]))

Diff for: tests/invalid_authorized_keys.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
from sshpubkeys.exceptions import InvalidKeyError, MalformedDataError
2-
1+
from .invalid_keys import keys as invalid_keys
32
from .valid_keys import keys as valid_keys
4-
5-
from.invalid_keys import keys as invalid_keys
3+
from sshpubkeys.exceptions import InvalidKeyError, MalformedDataError
64

75
items = [
86
["lines_with_spaces", " # Comments\n \n" + valid_keys[0][0] + "\nasdf", InvalidKeyError],

0 commit comments

Comments
 (0)