コード例 #1
0
 def test_parse_firefox_accept_header(self):
     accept = ('text/html,application/xhtml+xml,application/xml;q=0.9,'
               '*/*;q=0.8')
     expected = [('text', 'html'),
                 ('application', 'xhtml+xml'),
                 ('application', 'xml'),
                 ('*', '*')]
     self.assertEqual(expected, parse_accept_header(accept))
コード例 #2
0
ファイル: test_negotiation.py プロジェクト: plone/plone.rest
 def test_parse_firefox_accept_header(self):
     accept = "text/html,application/xhtml+xml,application/xml;q=0.9," "*/*;q=0.8"
     expected = [
         ("text", "html"),
         ("application", "xhtml+xml"),
         ("application", "xml"),
         ("*", "*"),
     ]
     self.assertEqual(expected, parse_accept_header(accept))
コード例 #3
0
 def test_parse_chrome_accept_header(self):
     accept = ('text/html,application/xhtml+xml,application/xml;q=0.9,'
               'image/webp,*/*;q=0.8')
     expected = [('text', 'html'),
                 ('application', 'xhtml+xml'),
                 ('application', 'xml'),
                 ('image', 'webp'),
                 ('*', '*')]
     self.assertEqual(expected, parse_accept_header(accept))
コード例 #4
0
 def test_parse_jquery_json_accept_header(self):
     accept = ('text/javascript, application/javascript, '
               'application/ecmascript, application/x-ecmascript, '
               '*/*; q=0.01')
     expected = [('text', 'javascript'),
                 ('application', 'javascript'),
                 ('application', 'ecmascript'),
                 ('application', 'x-ecmascript'),
                 ('*', '*')]
     self.assertEqual(expected, parse_accept_header(accept))
コード例 #5
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, ),
        )
コード例 #6
0
ファイル: test_negotiation.py プロジェクト: plone/plone.rest
 def test_parse_chrome_accept_header(self):
     accept = ("text/html,application/xhtml+xml,application/xml;q=0.9,"
               "image/webp,*/*;q=0.8")
     expected = [
         ("text", "html"),
         ("application", "xhtml+xml"),
         ("application", "xml"),
         ("image", "webp"),
         ("*", "*"),
     ]
     self.assertEqual(expected, parse_accept_header(accept))
コード例 #7
0
ファイル: test_negotiation.py プロジェクト: plone/plone.rest
 def test_parse_jquery_json_accept_header(self):
     accept = ("text/javascript, application/javascript, "
               "application/ecmascript, application/x-ecmascript, "
               "*/*; q=0.01")
     expected = [
         ("text", "javascript"),
         ("application", "javascript"),
         ("application", "ecmascript"),
         ("application", "x-ecmascript"),
         ("*", "*"),
     ]
     self.assertEqual(expected, parse_accept_header(accept))
コード例 #8
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,)
            )
コード例 #9
0
ファイル: test_negotiation.py プロジェクト: plone/plone.rest
 def test_parse_application_json_accept_header(self):
     accept = "application/json"
     expected = [("application", "json")]
     self.assertEqual(expected, parse_accept_header(accept))
コード例 #10
0
ファイル: test_negotiation.py プロジェクト: plone/plone.rest
 def test_parse_invalid_accept_header(self):
     self.assertEqual([], parse_accept_header("invalid"))
コード例 #11
0
ファイル: test_negotiation.py プロジェクト: plone/plone.rest
 def test_parse_all_media_types_accept_header(self):
     self.assertEqual([("*", "*")], parse_accept_header("*/*"))
コード例 #12
0
ファイル: test_negotiation.py プロジェクト: plone/plone.rest
 def test_parse_invalid_accept_header(self):
     self.assertEqual([], parse_accept_header('invalid'))
コード例 #13
0
 def test_parse_all_media_types_accept_header(self):
     self.assertEqual([('*', '*')], parse_accept_header('*/*'))
コード例 #14
0
 def test_parse_application_json_accept_header(self):
     accept = 'application/json'
     expected = [('application', 'json')]
     self.assertEqual(expected, parse_accept_header(accept))