def getActionURL(current, history):
    def __init__(self, history):
    def locateChild(self, request, segments):
    def render_form(self, context, data):
class LoginPage(rend.Page): def search(self, ctx, scope, searchfilter, **kw):
    filt=[]
    for k,v in kw.items():
        assert k.startswith('search_')
        if not k.startswith("search_"):
            continue
        k=k[len("search_"):]
        if v is None:
            continue
        v=v.strip()
        if v=='':
            continue

        # TODO escape ) in v
        # TODO handle unknown filter name right (old form open in browser etc)
        filter_ = config.getSearchFieldByName(k, vars={'input': v})
        filt.append(ldapfilter.parseFilter(filter_))
    if searchfilter:
        try:
            filt.append(ldapfilter.parseFilter(searchfilter))
        except ldapfilter.InvalidLDAPFilter, e:
            raise annotate.ValidateError(
                {'searchfilter': str(e), },
                partialForm=inevow.IRequest(ctx).args)

    if filt:
        if len(filt)==1:
            query=filt[0]
        else:
            query=pureldap.LDAPFilter_and(filt)
    else:
        query=pureldap.LDAPFilterMatchAll

    self.data.update(kw)

    # annotate.Choice in nevow 0.3 maps choices to a list, and
    # passes indexes to this list to client. annotate.Choice in
    # 0.4pre converts choice to string and back with callbacks,
    # defaulting to str, and leaving the value as string.  We
    # can't use the 0.4pre mechanism as long as we need 0.3
    # compatibility, so work around that by explicitly making sure
    # scope is an integer.
    scope = int(scope)

    self.data['scope'] = scope
    self.data['searchfilter'] = searchfilter
    self.filter = query
    return self def edit(self, context, **kw):
    entry = context.locate(inevow.ISession).getLoggedInRoot().loggedIn
    user = entry.dn

    d = defer.succeed(None)

    changes = []
    for k,v in kw.items():
        if v is None:
            v = ''
        if k[:len("edit_")]=="edit_":
            old=kw.get("old_"+k[len("edit_"):])
            attrtype = self._get_attrtype(k[len("edit_"):])
            assert attrtype

            if attrtype.single_value or attrtype.uiHint_multiline:
                v=v.replace('\r\n', '\n')
                v=v.strip()
                v=[v]
                if v == ['']:
                    v = []
                if old is not None:
                    old=old.replace('\r\n', '\n')
                    old=old.strip()
                    old=[old]
            else:
                v=self._textarea_to_list(v)
                if old is not None:
                    old=self._textarea_to_list(old)

            o, v = self._prune_changes(old, v)

            if ((old is None and v)
                or (old is not None
                    and (o or v))):
                attr=k[len("edit_"):]
                changes.append((attr, old, v))
                #TODO

    if not changes:
        return EditStatus(self.entry, 'No changes!')

    changes_desc=tags.ul()
    newRDN = None
    for rdn in self.entry.dn.split()[0].split():
        for attr,old,new in changes:
            if (rdn.attributeType == attr
                and old is not None
                and rdn.value in old):
                # Need to change the rdn
                if newRDN is None:
                    newRDN = list(self.entry.dn.split()[0].split())
                newRDN.remove(rdn)

                # Try to find a replacement RDN. Possibilities are
                # new values from the edit form and old values
                # currently in LDAP.
                possible = list(new)
                possible.extend(self.entry.get(rdn.attributeType, []))
                for o in old:
                    # Values to be removed are not acceptable as
                    # new RDN.
                    try:
                        possible.remove(o)
                    except ValueError:
                        pass
                if not possible:
                    raise ldapsyntax.CannotRemoveRDNError \
                          (rdn.attributeType,
                           rdn.value)
                newRDN.append(distinguishedname.LDAPAttributeTypeAndValue(attributeType=attr,
                                                                          value=possible[0]))
                old.remove(rdn.value)
                try:
                    new.remove(possible[0])
                except ValueError:
                    pass
    if newRDN is not None:
        newRDN = distinguishedname.RelativeDistinguishedName(newRDN)
        changes_desc[tags.li[
            _("changing %s: changing RDN to say %s") \
            %(repr(attr), newRDN)]]
        newDN = distinguishedname.DistinguishedName(
            (newRDN,)+self.entry.dn.split()[1:]
            )
        def _move(_):
            return self.entry.move(newDN)
        d.addCallback(_move)
        def _redirect(r, ctx, newDN):
            request = inevow.IRequest(ctx)
            u = url.URL.fromContext(ctx).curdir()
            u = u.child(uriQuote(newDN))
            request.setComponent(iformless.IRedirectAfterPost, u)
            return r
        d.addCallback(_redirect, context, newDN)

    for attr,old,new in changes:
        if new:
            if self.entry.has_key(attr):
                self.entry[attr].update(new)
            else:
                self.entry[attr]=new
        if old:
            for x in old:
                if x=='':
                    continue
                self.entry[attr].remove(x)
        if old or new:
            l=tags.ul()
            changes_desc[tags.li[_("changing %s") % attr], l]
            if old:
                l[tags.li[_("remove "), ', '.join(map(repr, old))]]
            if new:
                l[tags.li[_("add "), ', '.join(map(repr, new))]]

    d.addCallback(lambda _: self.entry.commit())
    d.addCallback(lambda e: EditStatus(e, changes_desc))
    return d def add(self, ctx, request, structuralObjectClass, **kw):
    assert structuralObjectClass is not None
    structuralObjectClass = str(structuralObjectClass)
    auxiliaryObjectClasses = []
    for k,v in kw.items():
        assert k.startswith('auxiliary_')
        if k.startswith('auxiliary_'):
            k = k[len('auxiliary_'):]
            if v:
                auxiliaryObjectClasses.append(k)
    u = url.URL.fromContext(ctx)
    u = u.child('manual').child('+'.join([structuralObjectClass]
                                         + auxiliaryObjectClasses))
    return u def delete(self, ctx):
    request = inevow.IRequest(ctx)
    user = request.getSession().getLoggedInRoot().loggedIn
    e=ldapsyntax.LDAPEntry(client=user.client,
                           dn=self.dn)
    d=e.delete()
    def cb(dummy):
        basedn = iwebui.ICurrentDN(ctx)
        while (basedn != ''
               and self.dn.contains(basedn)):
            basedn = basedn.up()
        u=url.URL.fromContext(ctx)
        u=u.parentdir().parentdir()
        if basedn != '':
            u=u.child(basedn).child('search')
        request.setComponent(iformless.IRedirectAfterPost, u)
        return _("Deleted %s.") % self.dn
    def eb(fail):
        return _("Failed: %s.") % fail.getErrorMessage()
    d.addCallbacks(cb, eb)
    return d class MassPasswordChangeStatus(object):
class MassPasswordChangeForm(configurable.Configurable):
class ReallyMassPasswordChangePage(rend.Page):
class MassPasswordChangePage(rend.Page):
    def __init__(self, deferlist):
    def __init__(self, ldapObjects):
    def _getFormFields(self):
    def getBindingNames(self, ctx):
    def bind_generate(self, ctx):
    def generatePasswords(self, request, **kw):
        def _gotPasswords(passwords, entries):
                def _cb(entry, pwd):
    def __init__(self, entries):
    def data_header(self, ctx, data):
    def configurable_(self, context):
    def render_form(self, context, data):
    def render_passthrough(self, context, data):
    def render_status(self, context, data):
    def __init__(self, baseObject):
    def render_url(self, context, data):
    def childFactory(self, context, name): def getEntry(ctx, dn):
def getEntryWithAttributes(ctx, dn, *attributes):
def getServiceName(ctx, dn):
    def _cb(e):
def checkPasswordTypos(newPassword, again):
    def __init__(self, dn):
    def getBindingNames(self, ctx):
    def bind_remove(self, ctx):
    def remove(self, ctx):
        def _delete(name, e):
        def _report(name):
    def __init__(self, dn):
    def getBindingNames(self, ctx):
    def bind_setServicePassword(self, ctx):
    def _isPasswordAcceptable(self, ctx, newPassword, again):
    def setServicePassword(self, ctx, newPassword, again):
        def _setPassword(ctx, dn, newPassword):
        def _getName(_, ctx):
        def _report(name):
    def __init__(self, dn):
    def getBindingNames(self, ctx):
    def bind_generateRandom(self, ctx):
    def generateRandom(self, ctx):
        def _first(passwords):
        def _setPass(newPassword, ctx):
            def _getName(_, ctx):
            def _report(name, newPassword):
    def __init__(self, dn):
    def getBindingNames(self, ctx):
    def bind_add(self, ctx):
    def add(self, ctx, serviceName, newPassword, again):
    def _cbSetPassword(self, ctx, newPassword, serviceName):
        def _setPass(e, newPassword):
    def _generate(self, ctx, serviceName):
        def _first(passwords):
        def _cb(newPassword, serviceName):
    def _add(self, ctx, newPassword, serviceName):
        def _report(dummy, name):
    def __init__(self, dn):
    def listServicePasswordActions(self):
    def getServicePasswordAction(self, name):
    def render_servicePasswords(self, ctx, data):
    def render_hideIfNot(self, ctx, data):
    def data_servicePasswords(self, ctx, data):
    def render_form_service(self, ctx, data):
    def locateConfigurable(self, ctx, name):
    def getBindingNames(self, ctx):
    def bind_setPassword(self, ctx):
    def bind_generateRandom(self, ctx):
    def _setPassword(self, ctx, password):
    def setPassword(self, ctx, newPassword, again):
        def eb(fail):
    def generateRandom(self, ctx):
        def _first(passwords):
        def _status(newPassword, ctx):
        def eb(fail):
    def data_status(self, ctx, data):
    def data_dn(self, ctx, data):
    def render_form(self, ctx, data):
    def render_passthrough(self, ctx, data):
    def data_header(self, ctx, data):
    def render_add(self, ctx, data):
    def configurable_add(self, ctx):
    def render_data(self, ctx, data):
    def child_(self, ctx):
    def childFactory(self, ctx, name):
def getResource():
class RemoveServicePassword(configurable.Configurable):
class SetServicePassword(configurable.Configurable):
class SetRandomServicePassword(configurable.Configurable):
class AddService(configurable.Configurable):
class ServicePasswordChangeMixin(object):
class ConfirmChange(ServicePasswordChangeMixin, rend.Page):
class GetDN(rend.Page): class MovePage(rend.Page):
    def render_url(self, ctx, data):
    def childFactory(self, context, name): class ICurrentDN(Interface): def escape(s):
def unescape(s):
def _splitOnNotEscaped(s, separator):
    def __init__(self, rdn):
    def __str__(self):
    def __init__(self, stringValue=None, attributeType=None, value=None):
    def __str__(self):
    def __repr__(self):
    def __hash__(self):
    def __eq__(self, other):
    def __ne__(self, other):
    def __lt__(self, other):
    def __gt__(self, other):
    def __le__(self, other):
    def __ge__(self, other):
    def __init__(self, magic=None, stringValue=None, attributeTypesAndValues=None):
    def split(self):
    def __str__(self):
    def __repr__(self):
    def __hash__(self):
    def __eq__(self, other):
    def __ne__(self, other):
    def __lt__(self, other):
    def __gt__(self, other):
    def __le__(self, other):
    def __ge__(self, other):
    def count(self):
    def __init__(self, magic=None, stringValue=None, listOfRDNs=None):
    def split(self):
    def up(self):
    def __str__(self):
    def __repr__(self):
    def __hash__(self):
    def __eq__(self, other):
    def __ne__(self, other):
    def __cmp__(self, other):
    def getDomainName(self):
    def contains(self, other):
class InvalidRelativeDistinguishedName(Exception):
class LDAPAttributeTypeAndValue:
class RelativeDistinguishedName:
class DistinguishedName: def uriUnquote(q):
    q=str(q)
    return urllib.unquote(q) class ILDAPEntry(Interface):
class IEditableLDAPEntry(Interface):
class IConnectedLDAPEntry(Interface):
class ILDAPConfig(Interface):
    def __getitem__(self, key):
    def get(self, key, default=None):
    def has_key(self, key):
    def __contains__(self, key):
    def keys(self):
    def items(self):
    def __str__(self):
    def __eq__(self, other):
    def __ne__(self, other):
    def __len__(self):
    def __nonzero__(self):
    def bind(self, password):
    def __setitem__(self, key, value):
    def __delitem__(self, key):
    def undo(self):
    def commit(self):
    def move(self, newDN):
    def delete(self):
    def setPassword(self, newPasswd):
    def namingContext(self):
    def fetch(self, *attributes):
    def search(self,
               filterText=None,
               filterObject=None,
               attributes=(),
               scope=None,
               derefAliases=None,
               sizeLimit=0,
               timeLimit=0,
               typesOnly=0,
               callback=None):
    def children(self, callback=None):
    def subtree(self, callback=None):
    def lookup(self, dn):
    def match(self, filter):
    def getBaseDN(self):
    def getServiceLocationOverrides(self):
    def copy(self,
             baseDN=None,
             serviceLocationOverrides=None):
    def getIdentityBaseDN(self):
    def getIdentitySearch(self, name): def render(): def render():
from zope.interface import implements
from webut.skin import iskin
from ldaptor.apps.webui import login, search, edit, add, delete, mass_change_password, change_password, move, iwebui
from ldaptor.protocols.ldap import distinguishedname
from ldaptor.apps.webui.uriquote import uriUnquote
from ldaptor import interfaces
from ldaptor.apps.webui.i18n import _
from ldaptor.apps.webui import i18n
from nevow import rend, loaders, url, inevow
from formless import annotate, webform
import os


class LdaptorWebUIGadget2(rend.Page):
    implements(iskin.ISkinnable)

    title = _('Ldaptor Web Interface')

    addSlash = True

    def __init__(self, baseObject):
        super(LdaptorWebUIGadget2, self).__init__()
        self.baseObject = baseObject

    def child_(self, context):
        return inevow.IRequest(context).URLPath().child('search')

    def child_search(self, context):
        return search.getSearchPage()

    def child_edit(self, context):
        if not inevow.ISession(context).getLoggedInRoot().loggedIn:

            return login.LoginPage([str(self.baseObject), 'edit'])