~ubuntu-branches/ubuntu/wily/python-pskc/wily

« back to all changes in this revision

Viewing changes to pskc/policy.py

  • Committer: Package Import Robot
  • Author(s): Arthur de Jong
  • Date: 2014-06-20 14:50:59 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: package-import@ubuntu.com-20140620145059-k5c0hc0259gtl3dt
Tags: upstream-0.2
ImportĀ upstreamĀ versionĀ 0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
109
109
 
110
110
    def parse(self, policy):
111
111
        """Read key policy information from the provided <Policy> tree."""
112
 
        from pskc.parse import g_e_v, g_e_i, g_e_d, namespaces
 
112
        from pskc.parse import (
 
113
            find, findall, findtext, findint, findtime, getint)
113
114
        if policy is None:
114
115
            return
115
116
 
116
 
        self.start_date = g_e_d(policy, 'pskc:StartDate')
117
 
        self.expiry_date = g_e_d(policy, 'pskc:ExpiryDate')
118
 
        self.number_of_transactions = g_e_i(
 
117
        self.start_date = findtime(policy, 'pskc:StartDate')
 
118
        self.expiry_date = findtime(policy, 'pskc:ExpiryDate')
 
119
        self.number_of_transactions = findint(
119
120
            policy, 'pskc:NumberOfTransactions')
120
 
        for key_usage in policy.findall(
121
 
                'pskc:KeyUsage', namespaces=namespaces):
122
 
            self.key_usage.append(g_e_v(key_usage, '.'))
 
121
        for key_usage in findall(policy, 'pskc:KeyUsage'):
 
122
            self.key_usage.append(findtext(key_usage, '.'))
123
123
 
124
 
        pin_policy = policy.find(
125
 
            'pskc:PINPolicy', namespaces=namespaces)
 
124
        pin_policy = find(policy, 'pskc:PINPolicy')
126
125
        if pin_policy is not None:
127
 
            self.pin_key_id = pin_policy.attrib.get('PINKeyId')
128
 
            self.pin_usage = pin_policy.attrib.get('PINUsageMode')
129
 
            v = pin_policy.attrib.get('MaxFailedAttempts')
130
 
            if v:
131
 
                self.pin_max_failed_attemtps = int(v)
132
 
            v = pin_policy.attrib.get('MinLength')
133
 
            if v:
134
 
                self.pin_min_length = int(v)
135
 
            v = pin_policy.attrib.get('MaxLength')
136
 
            if v:
137
 
                self.pin_max_length = int(v)
138
 
            self.pin_encoding = pin_policy.attrib.get('PINEncoding')
 
126
            self.pin_key_id = pin_policy.get('PINKeyId')
 
127
            self.pin_usage = pin_policy.get('PINUsageMode')
 
128
            self.pin_max_failed_attemtps = getint(
 
129
                pin_policy, 'MaxFailedAttempts')
 
130
            self.pin_min_length = getint(pin_policy, 'MinLength')
 
131
            self.pin_max_length = getint(pin_policy, 'MaxLength')
 
132
            self.pin_encoding = pin_policy.get('PINEncoding')
139
133
            # TODO: check if there are any other attributes set for PINPolicy
140
134
            # of if there are any children and set unknown_policy_elementss
141
135