Created
March 28, 2012 13:56
-
-
Save almet/2226393 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Assertions(object): | |
"""Custom class to deal with assertions. it provides some hight level | |
methods that you can call to get valid or invalid assertions. | |
If many assertions are contained, then it will loop on them. | |
""" | |
def __init__(self, assertions): | |
self._assertions = assertions | |
def get_assertion(self, key="valid"): | |
"""return an assertion""" | |
return random.choice(self._assertions[key]) | |
valid = functools.partial(get_assertion, key="valid") | |
invalid_cert = functools.partial(get_assertion, key="invalid_cert") | |
invalid_issuer = functools.partial(get_assertion, key="invalid_issuer") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
assertions = Assertions(dict_of_assertions) | |
assertions.valid() # should return the same thing than assertions.get_assertion(key="valid") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So, this will not work as-is. I need to put the extra definitions of
valid
andinvalid_*
in the init method.