"BARE_NS", "OPENID1_NS", "OPENID2_NS", "SREG_URI", "IDENTIFIER_SELECT", ] import copy import warnings import urllib from askbot.deps.openid import oidutil from askbot.deps.openid import kvform try: ElementTree = oidutil.importElementTree() except ImportError: # No elementtree found, so give up, but don't fail to import, # since we have fallbacks. ElementTree = None # This doesn't REALLY belong here, but where is better? IDENTIFIER_SELECT = "http://specs.openid.net/auth/2.0/identifier_select" # URI for Simple Registration extension, the only commonly deployed # OpenID 1.x extension, and so a special case SREG_URI = "http://openid.net/sreg/1.0" # The OpenID 1.X namespace URI OPENID1_NS = "http://openid.net/signon/1.0" THE_OTHER_OPENID1_NS = "http://openid.net/signon/1.1"
def _checkForm(self, html, message_, action_url, form_tag_attrs, submit_text): E = oidutil.importElementTree() # Build element tree from HTML source input_tree = E.ElementTree(E.fromstring(html)) # Get root element form = input_tree.getroot() # Check required form attributes for k, v in self.required_form_attrs.iteritems(): assert form.attrib[k] == v, \ "Expected '%s' for required form attribute '%s', got '%s'" % \ (v, k, form.attrib[k]) # Check extra form attributes for k, v in form_tag_attrs.iteritems(): # Skip attributes that already passed the required # attribute check, since they should be ignored by the # form generation code. if k in self.required_form_attrs: continue assert form.attrib[k] == v, \ "Form attribute '%s' should be '%s', found '%s'" % \ (k, v, form.attrib[k]) # Check hidden fields against post args hiddens = [e for e in form \ if e.tag.upper() == 'INPUT' and \ e.attrib['type'].upper() == 'HIDDEN'] # For each post arg, make sure there is a hidden with that # value. Make sure there are no other hiddens. for name, value in message_.toPostArgs().iteritems(): for e in hiddens: if e.attrib['name'] == name: assert e.attrib['value'] == value, \ "Expected value of hidden input '%s' to be '%s', got '%s'" % \ (e.attrib['name'], value, e.attrib['value']) break else: self.fail("Post arg '%s' not found in form" % (name,)) for e in hiddens: assert e.attrib['name'] in message_.toPostArgs().keys(), \ "Form element for '%s' not in " + \ "original message" % (e.attrib['name']) # Check action URL assert form.attrib['action'] == action_url, \ "Expected form 'action' to be '%s', got '%s'" % \ (action_url, form.attrib['action']) # Check submit text submits = [e for e in form \ if e.tag.upper() == 'INPUT' and \ e.attrib['type'].upper() == 'SUBMIT'] assert len(submits) == 1, \ "Expected only one 'input' with type = 'submit', got %d" % \ (len(submits),) assert submits[0].attrib['value'] == submit_text, \ "Expected submit value to be '%s', got '%s'" % \ (submit_text, submits[0].attrib['value'])
"""Extension argument processing code """ __all__ = [ 'Message', 'NamespaceMap', 'no_default', 'registerNamespaceAlias', 'OPENID_NS', 'BARE_NS', 'OPENID1_NS', 'OPENID2_NS', 'SREG_URI', 'IDENTIFIER_SELECT' ] import copy import warnings import urllib from askbot.deps.openid import oidutil from askbot.deps.openid import kvform try: ElementTree = oidutil.importElementTree() except ImportError: # No elementtree found, so give up, but don't fail to import, # since we have fallbacks. ElementTree = None # This doesn't REALLY belong here, but where is better? IDENTIFIER_SELECT = 'http://specs.openid.net/auth/2.0/identifier_select' # URI for Simple Registration extension, the only commonly deployed # OpenID 1.x extension, and so a special case SREG_URI = 'http://openid.net/sreg/1.0' # The OpenID 1.X namespace URI OPENID1_NS = 'http://openid.net/signon/1.0' THE_OTHER_OPENID1_NS = 'http://openid.net/signon/1.1'
'getPriority', 'prioSort', 'iterServices', 'expandService', 'expandServices', ] import sys import random from datetime import datetime from time import strptime from askbot.deps.openid.oidutil import importElementTree ElementTree = importElementTree() # the different elementtree modules don't have a common exception # model. We just want to be able to catch the exceptions that signify # malformed XML data and wrap them, so that the other library code # doesn't have to know which XML library we're using. try: # Make the parser raise an exception so we can sniff out the type # of exceptions ElementTree.XML('> purposely malformed XML <') except (SystemExit, MemoryError, AssertionError, ImportError): raise except: XMLError = sys.exc_info()[0] from askbot.deps.openid.yadis import xri
def _checkForm(self, html, message_, action_url, form_tag_attrs, submit_text): E = oidutil.importElementTree() # Build element tree from HTML source input_tree = E.ElementTree(E.fromstring(html)) # Get root element form = input_tree.getroot() # Check required form attributes for k, v in self.required_form_attrs.iteritems(): assert form.attrib[k] == v, \ "Expected '%s' for required form attribute '%s', got '%s'" % \ (v, k, form.attrib[k]) # Check extra form attributes for k, v in form_tag_attrs.iteritems(): # Skip attributes that already passed the required # attribute check, since they should be ignored by the # form generation code. if k in self.required_form_attrs: continue assert form.attrib[k] == v, \ "Form attribute '%s' should be '%s', found '%s'" % \ (k, v, form.attrib[k]) # Check hidden fields against post args hiddens = [e for e in form \ if e.tag.upper() == 'INPUT' and \ e.attrib['type'].upper() == 'HIDDEN'] # For each post arg, make sure there is a hidden with that # value. Make sure there are no other hiddens. for name, value in message_.toPostArgs().iteritems(): for e in hiddens: if e.attrib['name'] == name: assert e.attrib['value'] == value, \ "Expected value of hidden input '%s' to be '%s', got '%s'" % \ (e.attrib['name'], value, e.attrib['value']) break else: self.fail("Post arg '%s' not found in form" % (name, )) for e in hiddens: assert e.attrib['name'] in message_.toPostArgs().keys(), \ "Form element for '%s' not in " + \ "original message" % (e.attrib['name']) # Check action URL assert form.attrib['action'] == action_url, \ "Expected form 'action' to be '%s', got '%s'" % \ (action_url, form.attrib['action']) # Check submit text submits = [e for e in form \ if e.tag.upper() == 'INPUT' and \ e.attrib['type'].upper() == 'SUBMIT'] assert len(submits) == 1, \ "Expected only one 'input' with type = 'submit', got %d" % \ (len(submits),) assert submits[0].attrib['value'] == submit_text, \ "Expected submit value to be '%s', got '%s'" % \ (submit_text, submits[0].attrib['value'])
'getPriorityStrict', 'getPriority', 'prioSort', 'iterServices', 'expandService', 'expandServices', ] import sys import random from datetime import datetime from time import strptime from askbot.deps.openid.oidutil import importElementTree ElementTree = importElementTree() # the different elementtree modules don't have a common exception # model. We just want to be able to catch the exceptions that signify # malformed XML data and wrap them, so that the other library code # doesn't have to know which XML library we're using. try: # Make the parser raise an exception so we can sniff out the type # of exceptions ElementTree.XML('> purposely malformed XML <') except (SystemExit, MemoryError, AssertionError, ImportError): raise except: XMLError = sys.exc_info()[0] from askbot.deps.openid.yadis import xri