Skip to content

Commit 5972812

Browse files
committed
SDK-350: Clarify comments & naming, code tidying up
1 parent c4dd161 commit 5972812

File tree

4 files changed

+33
-24
lines changed

4 files changed

+33
-24
lines changed

yoti_python_sdk/activity_details.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
import collections
33
import json
44

5-
from yoti_python_sdk import config, attribute
5+
from yoti_python_sdk import config
6+
from yoti_python_sdk.attribute import Attribute
67
from yoti_python_sdk.anchor import Anchor
78
from yoti_python_sdk.protobuf.v1.protobuf import Protobuf
89

910

1011
class ActivityDetails:
1112
def __init__(self, receipt, decrypted_profile=None):
1213
self.decrypted_profile = decrypted_profile
13-
self.user_profile = {} # will be deprecated in v3.0.0
14+
self.user_profile = {} # will be removed in v3.0.0
1415
self.profile = {}
1516
self.base64_selfie_uri = None
1617

@@ -23,8 +24,8 @@ def __init__(self, receipt, decrypted_profile=None):
2324

2425
anchors = Anchor().parse_anchors(field.anchors)
2526

26-
self.profile[field.name] = attribute.attribute(field.name, value, anchors)
27-
self.user_profile[field.name] = value # will be deprecated in v3.0.0
27+
self.profile[field.name] = Attribute(field.name, value, anchors)
28+
self.user_profile[field.name] = value # will be removed in v3.0.0
2829

2930
if field.name == config.ATTRIBUTE_SELFIE:
3031
self.try_parse_selfie_field(field)
@@ -55,11 +56,11 @@ def try_parse_age_verified_field(self, field, anchors):
5556
)
5657
if is_age_verified == 'true':
5758
self.user_profile[config.ATTRIBUTE_IS_AGE_VERIFIED] = True
58-
self.profile[config.ATTRIBUTE_IS_AGE_VERIFIED] = attribute.attribute(is_age_verified, True, anchors)
59+
self.profile[config.ATTRIBUTE_IS_AGE_VERIFIED] = Attribute(is_age_verified, True, anchors)
5960
return
6061
if is_age_verified == 'false':
6162
self.user_profile[config.ATTRIBUTE_IS_AGE_VERIFIED] = False
62-
self.profile[config.ATTRIBUTE_IS_AGE_VERIFIED] = attribute.attribute(is_age_verified, False, anchors)
63+
self.profile[config.ATTRIBUTE_IS_AGE_VERIFIED] = Attribute(is_age_verified, False, anchors)
6364
return
6465

6566
raise TypeError("age_verified_field unable to be parsed")
@@ -71,23 +72,25 @@ def try_convert_structured_postal_address_to_dict(self, field, anchors):
7172
value_to_decode = value_to_decode.decode()
7273

7374
self.user_profile[config.ATTRIBUTE_STRUCTURED_POSTAL_ADDRESS] = decoder.decode(value_to_decode)
74-
self.profile[config.ATTRIBUTE_STRUCTURED_POSTAL_ADDRESS] = attribute.attribute(
75+
self.profile[config.ATTRIBUTE_STRUCTURED_POSTAL_ADDRESS] = Attribute(
7576
config.ATTRIBUTE_STRUCTURED_POSTAL_ADDRESS,
7677
decoder.decode(value_to_decode),
7778
anchors)
7879

7980
def set_address_to_be_formatted_address_if_null(self, anchors):
81+
# setting in 'user_profile' - will be removed once user_profile is removed
8082
if config.ATTRIBUTE_POSTAL_ADDRESS not in self.user_profile and config.ATTRIBUTE_STRUCTURED_POSTAL_ADDRESS in self.user_profile:
8183
if config.KEY_FORMATTED_ADDRESS in self.user_profile[config.ATTRIBUTE_STRUCTURED_POSTAL_ADDRESS]:
8284
self.user_profile[config.ATTRIBUTE_POSTAL_ADDRESS] = \
8385
self.user_profile[config.ATTRIBUTE_STRUCTURED_POSTAL_ADDRESS][
8486
config.KEY_FORMATTED_ADDRESS]
8587

88+
# setting in 'profile'
8689
if config.ATTRIBUTE_POSTAL_ADDRESS not in self.profile and config.ATTRIBUTE_STRUCTURED_POSTAL_ADDRESS in self.profile:
8790
if config.KEY_FORMATTED_ADDRESS in self.profile[config.ATTRIBUTE_STRUCTURED_POSTAL_ADDRESS].value:
8891
formatted_address = self.profile[config.ATTRIBUTE_STRUCTURED_POSTAL_ADDRESS].value[
8992
config.KEY_FORMATTED_ADDRESS]
90-
self.profile[config.ATTRIBUTE_POSTAL_ADDRESS] = attribute.attribute(
93+
self.profile[config.ATTRIBUTE_POSTAL_ADDRESS] = Attribute(
9194
config.ATTRIBUTE_POSTAL_ADDRESS,
9295
formatted_address,
9396
anchors)

yoti_python_sdk/anchor.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def parse_anchors(anchors):
3838
parsed_anchors = []
3939
for anc in anchors:
4040
if hasattr(anc, 'origin_server_certs'):
41+
anchor_type = "Unknown"
4142
origin_server_certs_list = list(anc.origin_server_certs)
4243
origin_server_certs_item = origin_server_certs_list[0]
4344

@@ -53,18 +54,23 @@ def parse_anchors(anchors):
5354
anchor_type = config.ANCHOR_SOURCE
5455
elif oid.dotted_string == VERIFIER_EXTENSION:
5556
anchor_type = config.ANCHOR_VERIFIER
56-
else:
57-
continue
58-
59-
if hasattr(extensions, 'value'):
60-
extension_value = extensions.value
61-
if hasattr(extension_value, 'value'):
62-
parsed_anchors.append(Anchor(
63-
anchor_type,
64-
anc.sub_type,
65-
Anchor.decode_asn1_value(extension_value.value),
66-
anc.signed_time_stamp,
67-
crypto_cert))
57+
58+
if anchor_type != "Unknown":
59+
parsed_anchors = Anchor.get_values_from_extensions(anc, anchor_type, extensions, crypto_cert, parsed_anchors)
60+
61+
return parsed_anchors
62+
63+
@staticmethod
64+
def get_values_from_extensions(anc, anchor_type, extensions, crypto_cert, parsed_anchors):
65+
if hasattr(extensions, 'value'):
66+
extension_value = extensions.value
67+
if hasattr(extension_value, 'value'):
68+
parsed_anchors.append(Anchor(
69+
anchor_type,
70+
anc.sub_type,
71+
Anchor.decode_asn1_value(extension_value.value),
72+
anc.signed_time_stamp,
73+
crypto_cert))
6874

6975
return parsed_anchors
7076

yoti_python_sdk/attribute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from yoti_python_sdk import config
22

33

4-
class attribute:
4+
class Attribute:
55
def __init__(self, name="", value="", anchors={}):
66
self.__name = name
77
self.__value = value

yoti_python_sdk/tests/test_attribute.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
def test_attribute_get_values():
1111
parsed_anchors = []
1212

13-
attribute = yoti_python_sdk.attribute.attribute(NAME, VALUE, parsed_anchors)
13+
attribute = yoti_python_sdk.attribute.Attribute(NAME, VALUE, parsed_anchors)
1414

1515
assert attribute.name == NAME
1616
assert attribute.value == VALUE
@@ -19,7 +19,7 @@ def test_attribute_get_values():
1919

2020
def test_attribute_get_sources():
2121
anchors = create_source_and_verifier_anchors()
22-
attribute = yoti_python_sdk.attribute.attribute(NAME, VALUE, anchors)
22+
attribute = yoti_python_sdk.attribute.Attribute(NAME, VALUE, anchors)
2323
sources = attribute.sources
2424

2525
assert len(sources) == 1
@@ -28,7 +28,7 @@ def test_attribute_get_sources():
2828

2929
def test_attribute_get_verifiers():
3030
anchors = create_source_and_verifier_anchors()
31-
attribute = yoti_python_sdk.attribute.attribute(NAME, VALUE, anchors)
31+
attribute = yoti_python_sdk.attribute.Attribute(NAME, VALUE, anchors)
3232
verifiers = attribute.verifiers
3333

3434
assert len(verifiers) == 1

0 commit comments

Comments
 (0)