예제 #1
0
 def _setUpWidgets(self):
     adapted = self.schema(self.context)
     if adapted is not self.context:
         if not ILocation.providedBy(adapted):
             adapted = LocationProxy(adapted)
         adapted.__parent__ = self.context
     self.adapted = adapted
     setUpEditWidgets(self, self.schema, source=self.adapted,
                      names=self.fieldNames)
예제 #2
0
 def _setUpWidgets(self):
     adapted = self.schema(self.context)
     if adapted is not self.context:
         if not ILocation.providedBy(adapted):
             adapted = LocationProxy(adapted)
         adapted.__parent__ = self.context
     self.adapted = adapted
     setUpEditWidgets(self, self.schema, source=self.adapted,
                      names=self.fieldNames)
예제 #3
0
 def update_batch(self):
     if self.createBatch:
         content = self.getContentData().getContent()
         if not ILocation.providedBy(content):
             content = LocationProxy(content)
             content.__parent__ = self
             content.__name__ = ''
         self.batcher = Batcher(
             content, self.request, self.prefix, size=self.batchSize)
         self.batcher.update(self.lines)
예제 #4
0
    def handleException(self, object, request, exc_info, retry_allowed=True):
        transaction.abort()
        # TODO handle Retry, ConflictError, etc.
        # TODO handle logging
        exception_type, exception, traceback = exc_info

        loc = object
        if Acquisition.aq_parent(object) is None:
            # Try to get an object, since we apparently have a method
            # Note: We are guaranteed that an object has a location,
            # so just getting the instance the method belongs to is
            # sufficient.
            loc = getattr(loc, 'im_self', loc)
            loc = getattr(loc, '__self__', loc)

        # Give the exception instance its location and look up the
        # view.
        exception = LocationProxy(exception, loc, '')
        name = queryDefaultViewName(exception, request)
        if name is not None:
            # TODO annotate the transaction
            view = queryMultiAdapter((exception, request), name=name)
            if view is not None:
                # XXX should we use mapply here?
                body = self.callObject(request, view)
                request.response.setResult(body)
                transaction.commit()
            else:
                # This is the last resort. We shouldn't get here, but
                # in case we do, we have to set the result to something.
                request.response.setStatus(500)
                request.response.setResult('An error occurred.')
예제 #5
0
 def __getitem__(self, az):
     user = None
     cn = '%s-%s' % (self.mnr, az)
     if self.um.getUser(cn):
         user = LocationProxy(self.um.getUser(cn), self, az)
         directlyProvides(user, IOnTheFlyUser)
     return user
예제 #6
0
    def traverse(self, name, ignore):
        if not name:
            raise NotImplementedError('Please specify a service.')

        service = getMultiAdapter((self.context, self.request),
                                  IService,
                                  name=name)
        if service.layer is not None:
            applySkin(self.request, service.layer)
        return LocationProxy(service, self.context, "++services++%s" % name)
예제 #7
0
def assertLocation(adapter, parent):
    """Assert locatable adapters.

    This function asserts that the adapter get location-proxied if
    it doesn't provide ILocation itself. Further more the returned
    locatable adapter get its parent set if its __parent__ attribute
    is currently None.
    """
    # handle none-locatable adapters (A)
    if not ILocation.providedBy(adapter):
        locatable = LocationProxy(adapter)
        locatable.__parent__ = parent
        return locatable

    # handle locatable, parentless adapters (B)
    if adapter.__parent__ is None:
        adapter.__parent__ = parent
        return adapter

    # handle locatable, parentful adapters (C)
    return adapter
예제 #8
0
    def traverse(self, name, ignore):
        if not name:
            raise NotImplementedError("Please specify a service.")

        service = queryMultiAdapter((self.context, self.request), IService, name=name)

        if service is None:
            raise LookupError("Unknown service : %s" % name)
        else:
            if service.layer is not None:
                applySkin(self.request, service.layer)
            return LocationProxy(service, self.context, "++services++%s" % name)
예제 #9
0
def assertLocation(adapter, parent):
    """Assert locatable adapters.

    This function asserts that the adapter get location-proxied if
    it doesn't provide ILocation itself. Further more the returned
    locatable adapter get its parent set if its __parent__ attribute
    is currently None.
    """
    # handle none-locatable adapters (A)
    if not ILocation.providedBy(adapter):
        locatable = LocationProxy(adapter)
        locatable.__parent__ = parent
        return locatable

    # handle locatable, parentless adapters (B)
    if adapter.__parent__ is None:
        adapter.__parent__ = parent
        return adapter

    # handle locatable, parentful adapters (C)
    return adapter
예제 #10
0
def get_plugin_configuration(homefolder=None, request=None, name=None):
    if homefolder is None:
        if request is None:
            request = uvcsite.utils.shorties.getRequest()
        homefolder = uvcsite.interfaces.IHomeFolder(request.principal)
    if '__config__' not in homefolder:
        homefolder['__config__'] = Configurator()
    configurator = homefolder['__config__']
    if not name:
        return configurator
    elif name not in configurator:
        config_item = getUtility(IConfigurablePlugin, name=name)
        configurator[name] = config_item()
    return LocationProxy(configurator[name], configurator, name)
예제 #11
0
 def traverse(self, path):
     namespace = 'anno'
     print "TRAVERSE", path
     if path.startswith(namespace):
         name = path[len(namespace):]
         naked = removeSecurityProxy(self.context)
         annotations = IAnnotations(naked)
         print annotations.items()
         #obj = name and annotations[name] or annotations
         #obj = path and annotations[name] or annotations
         obj = ObjectInfo("Hello")
         if not IPhysicallyLocatable(obj, False):
             #obj = LocationProxy(
             #    obj, self.context, namespace + name)
             obj = LocationProxy(obj, self.context, 'anno' + name)
         return obj
     return
예제 #12
0
    def action(self, type_name='', id=''):
        if not type_name:
            raise UserError(_(u"You must select the type of object to add."))

        if type_name.startswith('@@'):
            type_name = type_name[2:]

        if '/' in type_name:
            view_name = type_name.split('/', 1)[0]
        else:
            view_name = type_name

        if queryMultiAdapter((self, self.request),
                                  name=view_name) is not None:
            url = "%s/%s=%s" % (
                absoluteURL(self, self.request), type_name, id)
            self.request.response.redirect(url)
            return

        if not self.contentName:
            self.contentName = id

        # TODO: If the factory wrapped by LocationProxy is already a Proxy,
        #       then ProxyFactory does not do the right thing and the
        #       original's checker info gets lost. No factory that was
        #       registered via ZCML and was used via addMenuItem worked
        #       here. (SR)
        factory = getUtility(IFactory, type_name)
        if not type(factory) is zope.security.checker.Proxy:
            factory = LocationProxy(factory, self, type_name)
            factory = zope.security.checker.ProxyFactory(factory)
        content = factory()

        # Can't store security proxies.
        # Note that it is important to do this here, rather than
        # in add, otherwise, someone might be able to trick add
        # into unproxying an existing object,
        content = removeSecurityProxy(content)

        notify(ObjectCreatedEvent(content))

        self.add(content)
        self.request.response.redirect(self.nextURL())
예제 #13
0
 def traverse(self, name, ignored):
     location = (self.context, '++control++')
     ob = Control()
     locate(ob, *location)
     return LocationProxy(ob, *location)
예제 #14
0
    def handleException(self, object, request, exc_info, retry_allowed=True):
        # This transaction had an exception that reached the publisher.
        # It must definitely be aborted.
        transaction.abort()

        # Reraise Retry exceptions for the publisher to deal with.
        if retry_allowed and isinstance(exc_info[1], Retry):
            raise

        # Convert ConflictErrors to Retry exceptions.
        if retry_allowed and isinstance(exc_info[1], ConflictError):
            tryToLogWarning(
                'ZopePublication',
                'Competing writes/reads at %s: %s' % (
                    request.get('PATH_INFO', '???'),
                    exc_info[1],
                ),
            )
            raise Retry(exc_info)
        # Are there any reasons why we'd want to let application-level error
        # handling determine whether a retry is allowed or not?
        # Assume not for now.

        # Record the error with the ErrorReportingUtility
        self._logErrorWithErrorReportingUtility(object, request, exc_info)

        response = request.response
        response.reset()
        exception = None
        legacy_exception = not isinstance(exc_info[1], Exception)
        if legacy_exception:
            response.handleException(exc_info)
            if isinstance(exc_info[1], str):
                tryToLogWarning(
                    'Publisher received a legacy string exception: %s.'
                    ' This will be handled by the request.' % exc_info[1])
            else:
                tryToLogWarning(
                    'Publisher received a legacy classic class exception: %s.'
                    ' This will be handled by the request.' %
                    exc_info[1].__class__)
        else:
            # We definitely have an Exception
            # Set the request body, and abort the current transaction.
            self.beginErrorHandlingTransaction(request, object,
                                               'application error-handling')
            view = None
            try:
                # We need to get a location, because some template content of
                # the exception view might require one.
                #
                # The object might not have a parent, because it might be a
                # method. If we don't have a `__parent__` attribute but have
                # an im_self or a __self__, use it.
                loc = object
                if not hasattr(object, '__parent__'):
                    loc = removeSecurityProxy(object)
                    # Try to get an object, since we apparently have a method
                    # Note: We are guaranteed that an object has a location,
                    # so just getting the instance the method belongs to is
                    # sufficient.
                    loc = getattr(loc, 'im_self', loc)
                    loc = getattr(loc, '__self__', loc)
                    # Protect the location with a security proxy
                    loc = ProxyFactory(loc)

                # Give the exception instance its location and look up the
                # view.
                exception = LocationProxy(exc_info[1], loc, '')
                name = queryDefaultViewName(exception, request)
                if name is not None:
                    view = zope.component.queryMultiAdapter(
                        (exception, request), name=name)
            except:
                # Problem getting a view for this exception. Log an error.
                tryToLogException('Exception while getting view on exception')

            if view is not None:
                try:
                    # We use mapply instead of self.callObject here
                    # because we don't want to pass positional
                    # arguments.  The positional arguments were meant
                    # for the published object, not an exception view.
                    body = mapply(view, (), request)
                    response.setResult(body)
                    transaction.commit()
                    if (ISystemErrorView.providedBy(view)
                            and view.isSystemError()):
                        # Got a system error, want to log the error

                        # Lame hack to get around logging missfeature
                        # that is fixed in Python 2.4
                        try:
                            raise exc_info[0], exc_info[1], exc_info[2]
                        except:
                            logging.getLogger('SiteError').exception(
                                str(request.URL), )

                except:
                    # Problem rendering the view for this exception.
                    # Log an error.
                    tryToLogException(
                        'Exception while rendering view on exception')

                    # Record the error with the ErrorReportingUtility
                    self._logErrorWithErrorReportingUtility(
                        object, request, sys.exc_info())

                    view = None

            if view is None:
                # Either the view was not found, or view was set to None
                # because the view couldn't be rendered. In either case,
                # we let the request handle it.
                response.handleException(exc_info)
                transaction.abort()

            # See if there's an IExceptionSideEffects adapter for the
            # exception
            try:
                adapter = IExceptionSideEffects(exception, None)
            except:
                tryToLogException(
                    'Exception while getting IExceptionSideEffects adapter')
                adapter = None

            if adapter is not None:
                self.beginErrorHandlingTransaction(
                    request, object, 'application error-handling side-effect')
                try:
                    # Although request is passed in here, it should be
                    # considered read-only.
                    adapter(object, request, exc_info)
                    transaction.commit()
                except:
                    tryToLogException('Exception while calling'
                                      ' IExceptionSideEffects adapter')
                    transaction.abort()
예제 #15
0
 def get_users(self):
     for user in self.um.getUserGroups(self.mnr):
         directlyProvides(user, IOnTheFlyUser)
         yield LocationProxy(user, self, user['az'])
예제 #16
0
 def __getattribute__(self, name):
     if name == 'context':
         raise AttributeError
     return LocationProxy.__getattribute__(self, name)
예제 #17
0
 def __iter__(self):
     plugins = zope.component.getUtilitiesFor(IPlugin)
     for name, plugin in plugins:
         yield name, LocationProxy(plugin, self, name)
예제 #18
0
 def __getitem__(self, name):
     plugin = zope.component.queryUtility(IPlugin, name=name)
     if plugin is None:
         raise KeyError(name)
     return LocationProxy(plugin, self, name)
예제 #19
0
 def traverse(self, name, ignored):
     auth = getUtility(IAuthentication)
     return LocationProxy(auth.getPrincipal(name),
                          self.context, '++user++%s' % name)
예제 #20
0
 def traverse(self, name, ignored):
     return LocationProxy(SecuritySettings(self.context, name),
                          self.context, '++security++%s' % name)