lists.arthurdejong.org
RSS feed

python-pskc branch master updated. 0.5-29-g052f5bc

[Date Prev][Date Next] [Thread Prev][Thread Next]

python-pskc branch master updated. 0.5-29-g052f5bc



This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "python-pskc".

The branch, master has been updated
       via  052f5bcafac580995723108d64545d9d0db3c6b4 (commit)
      from  6f0ca70650e1a4a802a1c15dc9d6c0a683ccdefb (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://arthurdejong.org/git/python-pskc/commit/?id=052f5bcafac580995723108d64545d9d0db3c6b4

commit 052f5bcafac580995723108d64545d9d0db3c6b4
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Mon Dec 18 20:24:08 2017 +0100

    Fix typo in pin_max_failed_attempts attribute
    
    This makes the old name (pin_max_failed_attemtps) available as a
    deprecated property.

diff --git a/docs/policy.rst b/docs/policy.rst
index cad018f..3d1d8f7 100644
--- a/docs/policy.rst
+++ b/docs/policy.rst
@@ -64,7 +64,7 @@ The Policy class
       Describe how the PIN is used during the usage of the key. See
       :ref:`pin-use-constants` below.
 
-   .. attribute:: pin_max_failed_attemtps
+   .. attribute:: pin_max_failed_attempts
 
       The maximum number of times the PIN may be entered wrongly before it
       MUST NOT be possible to use the key any more.
diff --git a/pskc/parser.py b/pskc/parser.py
index d3557d2..abad663 100644
--- a/pskc/parser.py
+++ b/pskc/parser.py
@@ -338,7 +338,7 @@ class PSKCParser(object):
         if pin_policy_elm is not None:
             policy.pin_key_id = pin_policy_elm.get('PINKeyId')
             policy.pin_usage = pin_policy_elm.get('PINUsageMode')
-            policy.pin_max_failed_attemtps = getint(
+            policy.pin_max_failed_attempts = getint(
                 pin_policy_elm, 'MaxFailedAttempts')
             policy.pin_min_length = getint(pin_policy_elm, 'MinLength')
             policy.pin_max_length = getint(pin_policy_elm, 'MaxLength')
diff --git a/pskc/policy.py b/pskc/policy.py
index 62c6519..b72aca3 100644
--- a/pskc/policy.py
+++ b/pskc/policy.py
@@ -1,7 +1,7 @@
 # policy.py - module for handling PSKC policy information
 # coding: utf-8
 #
-# Copyright (C) 2014-2016 Arthur de Jong
+# Copyright (C) 2014-2017 Arthur de Jong
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -20,6 +20,8 @@
 
 """Module that provides PSKC key policy information."""
 
+import warnings
+
 
 def _make_aware(d):
     """Make tge specified datetime timezone aware."""
@@ -44,7 +46,7 @@ class Policy(object):
       pin_key: reference to the key that holds the PIN
       pin: value of the PIN to use
       pin_usage: define how the PIN is used in relation to the key
-      pin_max_failed_attemtps: max. number of times a wrong PIN may be entered
+      pin_max_failed_attempts: max. number of times a wrong PIN may be entered
       pin_min_length: minimum length of a PIN that may be set
       pin_max_length: maximum length of a PIN that may be set
       pin_encoding: DECIMAL/HEXADECIMAL/ALPHANUMERIC/BASE64/BINARY
@@ -108,12 +110,27 @@ class Policy(object):
         self.key_usage = []
         self.pin_key_id = None
         self.pin_usage = None
-        self.pin_max_failed_attemtps = None
+        self.pin_max_failed_attempts = None
         self.pin_min_length = None
         self.pin_max_length = None
         self.pin_encoding = None
         self.unknown_policy_elements = False
 
+    @property
+    def pin_max_failed_attemtps(self):
+        """Provide access to deprecated name."""
+        warnings.warn(
+            'The pin_max_failed_attemtps property has been renamed to '
+            'pin_max_failed_attempts.', DeprecationWarning, stacklevel=2)
+        return self.pin_max_failed_attempts
+
+    @pin_max_failed_attemtps.setter
+    def pin_max_failed_attemtps(self, value):
+        warnings.warn(
+            'The pin_max_failed_attemtps property has been renamed to '
+            'pin_max_failed_attempts.', DeprecationWarning, stacklevel=2)
+        self.pin_max_failed_attempts = value
+
     def may_use(self, usage=None, now=None):
         """Check whether the key may be used for the provided purpose."""
         import datetime
diff --git a/pskc/serialiser.py b/pskc/serialiser.py
index eb0b2d8..3a89da1 100644
--- a/pskc/serialiser.py
+++ b/pskc/serialiser.py
@@ -214,7 +214,7 @@ class PSKCSerialiser(object):
         if not policy.key_usage and all(x is None for x in (
                 policy.start_date, policy.expiry_date,
                 policy.number_of_transactions, policy.pin_key_id,
-                policy.pin_usage, policy.pin_max_failed_attemtps,
+                policy.pin_usage, policy.pin_max_failed_attempts,
                 policy.pin_min_length, policy.pin_max_length,
                 policy.pin_encoding)):
             return
@@ -224,7 +224,7 @@ class PSKCSerialiser(object):
         mk_elem(policy_elm, 'pskc:PINPolicy',
                 PINKeyId=policy.pin_key_id,
                 PINUsageMode=policy.pin_usage,
-                MaxFailedAttempts=policy.pin_max_failed_attemtps,
+                MaxFailedAttempts=policy.pin_max_failed_attempts,
                 MinLength=policy.pin_min_length,
                 MaxLength=policy.pin_max_length,
                 PINEncoding=policy.pin_encoding)
diff --git a/tests/test_misc.doctest b/tests/test_misc.doctest
index f01e89f..320982b 100644
--- a/tests/test_misc.doctest
+++ b/tests/test_misc.doctest
@@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 02110-1301 USA
 
 
+>>> import warnings
 >>> from binascii import a2b_hex, b2a_hex
 >>> def tostr(x):
 ...     return str(x.decode())
@@ -264,3 +265,21 @@ normally contain data.
 >>> pskc = PSKC('tests/misc/partialxml.pskcxml')
 >>> all(key.counter is None for key in pskc.keys)
 True
+
+
+A typo was fixed and the old name was provided via a deprecation wrapper
+property.
+
+>>> pskc = PSKC()
+>>> key = pskc.add_key()
+>>> with warnings.catch_warnings(record=True) as w:
+...     key.policy.pin_max_failed_attemtps = 10
+...     assert len(w) == 1
+...     assert issubclass(w[0].category, DeprecationWarning)
+>>> key.policy.pin_max_failed_attempts
+10
+>>> with warnings.catch_warnings(record=True) as w:
+...     key.policy.pin_max_failed_attemtps
+...     assert len(w) == 1
+...     assert issubclass(w[0].category, DeprecationWarning)
+10
diff --git a/tests/test_write.doctest b/tests/test_write.doctest
index 3c39f85..e22bf8b 100644
--- a/tests/test_write.doctest
+++ b/tests/test_write.doctest
@@ -71,7 +71,7 @@ Add policy information and a PIN.
 >>> key.policy.number_of_transactions = 42
 >>> key.policy.pin_key_id = 'pinID'
 >>> key.policy.pin_usage = 'Local'
->>> key.policy.pin_max_failed_attemtps = 3
+>>> key.policy.pin_max_failed_attempts = 3
 >>> key.policy.pin_min_length = 4
 >>> key.policy.pin_max_length = 4
 >>> key.policy.pin_encoding = 'DECIMAL'

-----------------------------------------------------------------------

Summary of changes:
 docs/policy.rst          |  2 +-
 pskc/parser.py           |  2 +-
 pskc/policy.py           | 23 ++++++++++++++++++++---
 pskc/serialiser.py       |  4 ++--
 tests/test_misc.doctest  | 19 +++++++++++++++++++
 tests/test_write.doctest |  2 +-
 6 files changed, 44 insertions(+), 8 deletions(-)


hooks/post-receive
-- 
python-pskc
-- 
To unsubscribe send an email to
python-pskc-commits-unsubscribe@lists.arthurdejong.org or see
https://lists.arthurdejong.org/python-pskc-commits/