コード例 #1
0
ファイル: view.py プロジェクト: stoxy/stoxy
        def object_data_generator(obj, attrs=dict()):
            yield ('objectType', lambda: self.object_type_map[obj.type])
            yield ('objectID', lambda: obj.oid)
            yield ('objectName', lambda: obj.name)
            yield ('parentURI', lambda: obj.__parent__.__name__)
            yield ('parentID', lambda: (obj.__parent__.oid
                                        if (not IRootContainer.providedBy(obj)
                                            and not ISystemCapability.providedBy(obj))
                                        else None))
            yield ('completionStatus', lambda: 'Complete')  # TODO: report errors / incomplete status

            if IStorageContainer.providedBy(obj) or IDataObject.providedBy(obj):
                yield ('metadata', lambda: dict(obj.metadata))

            if isinstance(obj, ObjectIdContainer):
                yield ('children', lambda: [(child.oid if IInStorageContainer.providedBy(child)
                                             else child.__name__) for child in obj.listcontent()])
                yield ('childrenrange', lambda: '0-%d' % len(obj.listcontent()))
            elif IStorageContainer.providedBy(obj):
                yield ('children', lambda: [(child.name if IDataObject.providedBy(child)
                                             else child.__name__) for child in obj.listcontent()])
                yield ('childrenrange', lambda: '0-%d' % len(obj.listcontent()))
            elif IDataObject.providedBy(obj) and render_value:
                # NOTE: 'value' attribute name is mandated by the specification
                if 'value' in attrs:
                    begin, end = (int(v) for v in attrs['value'])
                else:
                    begin = 0
                    end = None
                yield ('value', lambda: get_data(obj, begin=begin, end=end))
                yield ('valuetransferencoding', lambda: 'base64')
            elif ISystemCapability.providedBy(obj):
                yield ('children', lambda: [])
                yield ('childrenrange', lambda: '0-0'),
                yield ('capabilities', lambda: current_capabilities.system)
コード例 #2
0
ファイル: view.py プロジェクト: stoxy/stoxy
 def render_delete(self, request):
     name = unicode(parse_path(request.path)[-1])
     existing_object = self.context.__parent__[name]
     if existing_object:
         log.debug('Deleting %s', self.context)
         # are we deleting a container?
         if IStorageContainer.providedBy(self.context):
             # check children
             children = [child for child in self.context.listcontent() if
                         IDataObject.providedBy(child) or
                         IStorageContainer.providedBy(child)]
             if len(children) > 0:
                 raise BadRequest('Attempt to delete a non-empty container')
         else:
             # XXX: Alternative authentication methods!
             credentials = request.getHeader('X-Auth-Token')
             storemgr = getAdapter(self.context, IDataStoreFactory).create()
             storemgr.delete(credentials)
         del self.context.__parent__[name]
         handle(self.context, ModelDeletedEvent(self.context.__parent__))
     else:
         raise NotFound