Source code for wirecurly.directory

import logging

log = logging.getLogger(__name__)

__all__ = ['User']
		
[docs]class User(object): """A user object for the directory""" def __init__(self, user_id, password=None): super(User, self).__init__() self.user_id = user_id self.variables = [] self.parameters = [] if password: self.addParameter('password', password)
[docs] def addVariable(self, var, val): ''' Set an extra variable for an user ''' try: self.getVariable(var) except ValueError: self.variables.append({'name': var, 'value': val}) return log.warning('Cannot replace existing variable.') raise ValueError
[docs] def addParameter(self, param, val): ''' Set an extra parameter for an user ''' try: self.getParameter(param) except ValueError: self.parameters.append({'name': param, 'value': val}) return log.warning('Cannot replace existing parameter.') raise ValueError
[docs] def getParameter(self, param): ''' Retrieve the value of a parameter by its name ''' for p in self.parameters: if p.get('name') == param: return p.get('value') raise ValueError
[docs] def getVariable(self, var): ''' Retrieve the value of a variable by its name ''' for v in self.variables: if v.get('name') == var: return v.get('value') raise ValueError
[docs] def todict(self): ''' Create a dict so it can be converted/serialized ''' children = [{'tag': 'params', 'children': [ {'tag': 'param', 'attrs': p} for p in self.parameters ]}] if self.variables: children.append({'tag': 'variables', 'children': [ {'tag': 'variable', 'attrs': v} for v in self.variables ]}) return {'tag': 'user', 'children': children, 'attrs': {'id': self.user_id}}
Read the Docs v: latest
Versions
latest
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.