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

Source Code for Module ldaptor.usage

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