Package ldaptor :: Module usage
[hide private]
[frames] | no frames]

Source Code for Module ldaptor.usage

  1  from twisted.python.usage import UsageError 
  2  from twisted.python import usage, reflect 
  3  from ldaptor.protocols import pureldap 
  4  from ldaptor.protocols.ldap import distinguishedname 
  5   
6 -class Options(usage.Options):
7 optParameters = ()
8 - def postOptions(self):
9 postOpt = {} 10 reflect.addMethodNamesToDict(self.__class__, postOpt, "postOptions_") 11 for name in postOpt.keys(): 12 method = getattr(self, 'postOptions_'+name) 13 method()
14
15 -class Options_service_location:
16 - def opt_service_location(self, value):
17 """Service location, in the form BASEDN:HOST[:PORT]""" 18 19 if not self.opts.has_key('service-location'): 20 self.opts['service-location']={} 21 22 base, location = value.split(':', 1) 23 try: 24 dn = distinguishedname.DistinguishedName(base) 25 except distinguishedname.InvalidRelativeDistinguishedName, e: 26 raise usage.UsageError, str(e) 27 28 if not location: 29 raise usage.UsageError, "service-location must specify host" 30 31 if ':' in location: 32 host, port = location.split(':', 1) 33 else: 34 host, port = location, None 35 36 if not host: 37 host = None 38 39 if not port: 40 port = None 41 42 self.opts['service-location'][dn] = (host, port)
43
45 if not self.opts.has_key('service-location'): 46 self.opts['service-location']={}
47
48 -class Options_base_optional:
49 optParameters = ( 50 ('base', None, None, 51 "LDAP base dn"), 52 )
53
54 -class Options_base(Options_base_optional):
55 - def postOptions_base(self):
56 # check that some things are given 57 if self.opts['base'] is None: 58 raise usage.UsageError, "%s must be given" % 'base'
59
60 -class Options_scope:
61 optParameters = ( 62 ('scope', None, 'sub', 63 "LDAP search scope (one of base, one, sub)"), 64 ) 65
66 - def postOptions_scope(self):
67 synonyms = { 68 'base': 'baseObject', 69 'single': 'singleLevel', 70 'subtree': 'wholeSubtree', 71 'sub': 'wholeSubtree', 72 } 73 scope = self.opts['scope'] 74 scope=synonyms.get(scope, scope) 75 try: 76 scope=getattr(pureldap, 'LDAP_SCOPE_'+scope) 77 except AttributeError: 78 raise usage.UsageError, "bad scope: %s" % scope 79 self.opts['scope'] = scope
80
81 -class Options_bind:
82 optParameters = ( 83 ('binddn', None, None, 84 "use Distinguished Name to bind to the directory"), 85 ('bind-auth-fd', None, None, 86 "read bind password from filedescriptor"), 87 ) 88
90 val=self.opts['bind-auth-fd'] 91 if val is not None: 92 try: 93 val = int(val) 94 except ValueError: 95 raise usage.UsageError, "%s value must be numeric" % 'bind-auth-fd' 96 self.opts['bind-auth-fd'] = val
97
98 -class Options_bind_mandatory(Options_bind):
100 if not self.opts['binddn']: 101 raise usage.UsageError, "%s must be given" % 'binddn'
102