/usr/lib/python2.7/dist-packages/openid_cla/cla.py is in python-openid-cla 1.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | """CLA extension request and response parsing and object representation
@var cla_uri: The URI used for the CLA extension namespace and XRD Type Value
"""
from openid.message import (
registerNamespaceAlias,
NamespaceAliasRegistrationError,
)
from openid.extension import Extension
import logging
import six
__all__ = [
'CLARequest',
'CLAResponse',
'cla_uri',
'supportsCLA',
]
# The namespace for this extension
cla_uri = 'http://fedoraproject.org/specs/open_id/cla'
# Some predefined CLA uris
CLA_URI_FEDORA_CLICK = 'http://admin.fedoraproject.org/accounts/cla/click'
CLA_URI_FEDORA_DELL = 'http://admin.fedoraproject.org/accounts/cla/dell'
CLA_URI_FEDORA_DONE = 'http://admin.fedoraproject.org/accounts/cla/done'
CLA_URI_FEDORA_FEDORA = 'http://admin.fedoraproject.org/accounts/cla/fedora'
CLA_URI_FEDORA_FPCA = 'http://admin.fedoraproject.org/accounts/cla/fpca'
CLA_URI_FEDORA_IBM = 'http://admin.fedoraproject.org/accounts/cla/ibm'
CLA_URI_FEDORA_INTEL = 'http://admin.fedoraproject.org/accounts/cla/intel'
CLA_URI_FEDORA_REDHAT = 'http://admin.fedoraproject.org/accounts/cla/redhat'
try:
registerNamespaceAlias(cla_uri, 'cla')
except NamespaceAliasRegistrationError as e:
logging.exception('registerNamespaceAlias(%r, %r) failed: %s' % (
cla_uri, 'cla', str(e),))
def supportsCLA(endpoint):
return endpoint.usesExtension(cla_uri)
class CLARequest(Extension):
ns_uri = 'http://fedoraproject.org/specs/open_id/cla'
ns_alias = 'cla'
def __init__(self, requested=None):
Extension.__init__(self)
self.requested = []
if requested:
self.requestCLAs(requested)
def requestedCLAs(self):
return self.requested
def fromOpenIDRequest(cls, request):
self = cls()
# Since we're going to mess with namespace URI mapping, don't
# mutate the object that was passed in.
message = request.message.copy()
args = message.getArgs(self.ns_uri)
self.parseExtensionArgs(args)
return self
fromOpenIDRequest = classmethod(fromOpenIDRequest)
def parseExtensionArgs(self, args):
items = args.get('query_cla')
if items:
for cla_uri in items.split(','):
self.requestCLA(cla_uri)
def wereCLAsRequested(self):
return bool(self.requested)
def __requests__(self, cla_uri):
return cla_uri in self.requested
def requestCLA(self, cla_uri):
if not cla_uri in self.requested:
self.requested.append(cla_uri)
def requestCLAs(self, cla_uris):
if isinstance(cla_uris, six.string_types):
raise TypeError('CLA URIs should be passed as a list of '
'strings (not %r)' % (type(field_names),))
for cla_uri in cla_uris:
self.requestCLA(cla_uri)
def getExtensionArgs(self):
args = {}
if self.requested:
args['query_cla'] = ','.join(self.requested)
return args
class CLAResponse(Extension):
ns_uri = 'http://fedoraproject.org/specs/open_id/cla'
ns_alias = 'cla'
def __init__(self, clas=None):
Extension.__init__(self)
if clas is None:
self.clas = []
else:
self.clas = clas
def extractResponse(cls, request, clas):
self = cls()
for cla in request.requestedCLAs():
if cla in clas:
self.clas.append(cla)
return self
extractResponse = classmethod(extractResponse)
def fromSuccessResponse(cls, success_response, signed_only=True):
self = cls()
if signed_only:
args = success_response.getSignedNS(self.ns_uri)
else:
args = success_response.message.getArgs(self.ns_uri)
if not args:
return None
self.clas = args['signed_cla'].split(',')
return self
fromSuccessResponse = classmethod(fromSuccessResponse)
def getExtensionArgs(self):
return {'signed_cla': ','.join(self.clas)}
|