예제 #1
0
def serviceDirective(
    _context,
    method,
    accept,
    factory,
    for_,
    permission,
    layer=IDefaultBrowserLayer,
    name=u"",
):

    _handle_for(_context, for_)

    media_types = parse_accept_header(accept)
    for media_type in media_types:
        service_id = register_service(method.upper(), media_type)
        view_name = service_id + name

        # We need a service for CORS preflight processing but we don't get the
        # desired Accept header in the preflight request. Thus we just register
        # the current service_id for the given method.
        register_method_for_preflight(method.upper(), service_id)

        # Create a new class. We'll execute some security declarations on it
        # and don't want to modify the original class.
        cdict = getSecurityInfo(factory)
        cdict["__name__"] = view_name
        cdict["method"] = method.upper()
        new_class = type(factory.__name__, (factory, BrowserView), cdict)

        _context.action(
            discriminator=("plone.rest:service", method, media_type, for_,
                           name, layer),
            callable=handler,
            args=(
                "registerAdapter",
                new_class,
                (for_, layer),
                Interface,
                view_name,
                _context.info,
            ),
        )

        _context.action(
            discriminator=("plone.rest:protectClass", new_class),
            callable=protectClass,
            args=(new_class, permission),
        )
        _context.action(
            discriminator=("plone.rest:InitializeClass", new_class),
            callable=InitializeClass,
            args=(new_class, ),
        )
예제 #2
0
파일: zcml.py 프로젝트: plone/plone.rest
def serviceDirective(
        _context,
        method,
        accept,
        factory,
        for_,
        permission,
        layer=IDefaultBrowserLayer,
        name=u'',
        ):

    _handle_for(_context, for_)

    media_types = parse_accept_header(accept)
    for media_type in media_types:
        service_id = register_service(method.upper(), media_type)
        view_name = service_id + name

        # We need a service for CORS preflight processing but we don't get the
        # desired Accept header in the preflight request. Thus we just register
        # the current service_id for the given method.
        register_method_for_preflight(method.upper(), service_id)

        # Create a new class. We'll execute some security declarations on it
        # and don't want to modify the original class.
        cdict = getSecurityInfo(factory)
        cdict['__name__'] = view_name
        cdict['method'] = method.upper()
        new_class = type(factory.__name__, (factory, BrowserView), cdict)

        _context.action(
            discriminator=('plone.rest:service', method, media_type, for_,
                           name, layer),
            callable=handler,
            args=('registerAdapter', new_class, (for_, layer), Interface,
                  view_name, _context.info),
        )

        _context.action(
            discriminator=('plone.rest:protectClass', new_class),
            callable=protectClass,
            args=(new_class, permission)
        )
        _context.action(
            discriminator=('plone.rest:InitializeClass', new_class),
            callable=InitializeClass,
            args=(new_class,)
            )
예제 #3
0
 def test_service_id_for_wildcard_subtype_is_none(self):
     register_service("GET", "text/xml")
     self.assertEqual(None, lookup_service_id("GET", "text/*"))
예제 #4
0
 def test_service_id_for_multiple_media_types_is_none(self):
     register_service("GET", "application/json")
     self.assertEqual(
         None,
         lookup_service_id("GET", "application/json,application/javascipt"))
예제 #5
0
 def test_service_id_for_wildcard_type_is_none(self):
     register_service("GET", "application/json")
     self.assertEqual(None, lookup_service_id("GET", "*/*"))
예제 #6
0
 def test_register_wildcard_subtype(self):
     self.assertEqual(u"PATCH_text_*_",
                      register_service("PATCH", ("text", "*")))
     self.assertEqual(u"PATCH_text_*_",
                      lookup_service_id("PATCH", "text/xml"))
예제 #7
0
 def test_register_wilcard_type(self):
     self.assertEqual(u"PATCH_*_*_", register_service("PATCH", ("*", "*")))
     self.assertEqual(u"PATCH_*_*_", lookup_service_id("PATCH", "foo/bar"))
예제 #8
0
 def test_service_id_for_wildcard_subtype_is_none(self):
     register_service('GET', 'text/xml')
     self.assertEqual(None, lookup_service_id('GET', 'text/*'))
예제 #9
0
 def test_register_media_type(self):
     self.assertEqual(u"GET_application_json_",
                      register_service("GET", ("application", "json")))
     self.assertEqual(u"GET_application_json_",
                      lookup_service_id("GET", "application/json"))
예제 #10
0
 def test_service_id_for_wildcard_type_is_none(self):
     register_service('GET', 'application/json')
     self.assertEqual(None, lookup_service_id('GET', '*/*'))
예제 #11
0
 def test_service_id_for_multiple_media_types_is_none(self):
     register_service('GET', 'application/json')
     self.assertEqual(None, lookup_service_id(
         'GET', 'application/json,application/javascipt'))
예제 #12
0
 def test_register_wilcard_type(self):
     self.assertEqual(u'PATCH_*_*_', register_service('PATCH', ('*', '*')))
     self.assertEqual(u'PATCH_*_*_', lookup_service_id('PATCH', 'foo/bar'))
예제 #13
0
 def test_register_wildcard_subtype(self):
     self.assertEqual(u'PATCH_text_*_',
                      register_service('PATCH', ('text', '*')))
     self.assertEqual(u'PATCH_text_*_',
                      lookup_service_id('PATCH', 'text/xml'))
예제 #14
0
 def test_register_media_type(self):
     self.assertEqual(u'GET_application_json_',
                      register_service('GET', ('application', 'json')))
     self.assertEqual(u'GET_application_json_',
                      lookup_service_id('GET', 'application/json'))