Exemplo n.º 1
0
    def new_environ(self,
                    method='GET',
                    path='',
                    query='',
                    data=None,
                    form=None,
                    accept=None):
        query = uri.quote(query.format(path=ayame.AYAME_PATH))
        environ = {
            'SERVER_NAME': 'localhost',
            'REQUEST_METHOD': method,
            'PATH_INFO': path,
            'QUERY_STRING': query,
            'ayame.session': {}
        }
        wsgiref.util.setup_testing_defaults(environ)

        if data is not None:
            environ['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'
        elif form is not None:
            environ['CONTENT_TYPE'] = ('multipart/form-data; '
                                       'boundary={}').format(self.boundary)
            data = form
        else:
            data = ''
        data = data.format(path=ayame.AYAME_PATH).encode('utf-8')
        environ['wsgi.input'].write(data)
        environ['wsgi.input'].seek(0)
        environ['CONTENT_LENGTH'] = str(len(data))
        if accept is not None:
            environ['HTTP_ACCEPT_LANGUAGE'] = accept
        return environ
Exemplo n.º 2
0
Arquivo: base.py Projeto: hattya/ayame
    def new_environ(self, method='GET', path='', query='', data=None,
                    form=None, accept=None):
        query = uri.quote(query.format(path=ayame.AYAME_PATH))
        environ = {
            'SERVER_NAME': 'localhost',
            'REQUEST_METHOD': method,
            'PATH_INFO': path,
            'QUERY_STRING': query,
            'ayame.session': {}
        }
        wsgiref.util.setup_testing_defaults(environ)

        if data is not None:
            environ['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'
        elif form is not None:
            environ['CONTENT_TYPE'] = ('multipart/form-data; '
                                       'boundary={}').format(self.boundary)
            data = form
        else:
            data = ''
        data = data.format(path=ayame.AYAME_PATH).encode('utf-8')
        environ['wsgi.input'].write(data)
        environ['wsgi.input'].seek(0)
        environ['CONTENT_LENGTH'] = str(len(data))
        if accept is not None:
            environ['HTTP_ACCEPT_LANGUAGE'] = accept
        return environ
Exemplo n.º 3
0
 def test_parse_qs_ascii(self):
     query = ('a=1&' 'b=1&' 'b=2&' 'c=1&' 'c=2&' 'c=3')
     environ = {'QUERY_STRING': uri.quote(query)}
     self.assert_equal(uri.parse_qs(environ), {
         'a': ['1'],
         'b': ['1', '2'],
         'c': ['1', '2', '3']
     })
Exemplo n.º 4
0
 def test_parse_qs_utf_8(self):
     query = (u'\u3044=\u58f1&'
              u'\u308d=\u58f1&'
              u'\u308d=\u5f10&'
              u'\u306f=\u58f1&'
              u'\u306f=\u5f10&'
              u'\u306f=\u53c2')
     environ = {'QUERY_STRING': uri.quote(query)}
     self.assert_equal(uri.parse_qs(environ),
                       {u'\u3044': [u'\u58f1'],
                        u'\u308d': [u'\u58f1', u'\u5f10'],
                        u'\u306f': [u'\u58f1', u'\u5f10', u'\u53c2']})
Exemplo n.º 5
0
 def test_parse_qs_ascii(self):
     query = ('a=1&'
              'b=1&'
              'b=2&'
              'c=1&'
              'c=2&'
              'c=3')
     environ = {'QUERY_STRING': uri.quote(query)}
     self.assert_equal(uri.parse_qs(environ),
                       {'a': ['1'],
                        'b': ['1', '2'],
                        'c': ['1', '2', '3']})
Exemplo n.º 6
0
    def test_quote(self):
        v = uri.quote('*****@*****.**')
        self.assert_is_instance(v, str)
        self.assert_equal(v, '*****@*****.**')

        v = uri.quote('/~a/cgi-bin/index.cgi')
        self.assert_is_instance(v, str)
        self.assert_equal(v, '/~a/cgi-bin/index.cgi')

        v = uri.quote('/a/=/1')
        self.assert_is_instance(v, str)
        self.assert_equal(v, '/a/=/1')

        # iroha in hiragana
        v = uri.quote(u'/\u3044\u308d\u306f')
        self.assert_is_instance(v, str)
        self.assert_equal(v, '/%E3%81%84%E3%82%8D%E3%81%AF')

        v = uri.quote(0)
        self.assert_is_instance(v, str)
        self.assert_equal(v, '0')

        v = uri.quote(3.14)
        self.assert_is_instance(v, str)
        self.assert_equal(v, '3.14')
Exemplo n.º 7
0
    def test_quote(self):
        v = uri.quote('*****@*****.**')
        self.assert_is_instance(v, str)
        self.assert_equal(v, '*****@*****.**')

        v = uri.quote('/~a/cgi-bin/index.cgi')
        self.assert_is_instance(v, str)
        self.assert_equal(v, '/~a/cgi-bin/index.cgi')

        v = uri.quote('/a/=/1')
        self.assert_is_instance(v, str)
        self.assert_equal(v, '/a/=/1')

        # iroha in hiragana
        v = uri.quote(u'/\u3044\u308d\u306f')
        self.assert_is_instance(v, str)
        self.assert_equal(v, '/%E3%81%84%E3%82%8D%E3%81%AF')

        v = uri.quote(0)
        self.assert_is_instance(v, str)
        self.assert_equal(v, '0')

        v = uri.quote(3.14)
        self.assert_is_instance(v, str)
        self.assert_equal(v, '3.14')
Exemplo n.º 8
0
 def test_parse_qs_utf_8(self):
     query = (u'\u3044=\u58f1&'
              u'\u308d=\u58f1&'
              u'\u308d=\u5f10&'
              u'\u306f=\u58f1&'
              u'\u306f=\u5f10&'
              u'\u306f=\u53c2')
     environ = {'QUERY_STRING': uri.quote(query)}
     self.assert_equal(
         uri.parse_qs(environ), {
             u'\u3044': [u'\u58f1'],
             u'\u308d': [u'\u58f1', u'\u5f10'],
             u'\u306f': [u'\u58f1', u'\u5f10', u'\u53c2']
         })
Exemplo n.º 9
0
class SpamPage(ayame.Page):

    html_t = """\
<?xml version="1.0"?>
{doctype}
<html xmlns="{xhtml}">
  <head>
    <title>SpamPage</title>
  </head>
  <body>
    <a href="http://localhost/?{query}">_</a>
  </body>
</html>
"""
    kwargs = {
        'query': uri.quote('{}=link'.format(ayame.AYAME_PATH), '/=')
    }

    def __init__(self):
        super(SpamPage, self).__init__()
        self.add(ActionLink('link'))
Exemplo n.º 10
0
    def test_get_page(self):
        # GET /page -> OK
        environ = self.new_environ('GET', '/page')
        status, headers, exc_info, content = self.wsgi_call(environ)
        html = self.format(SimplePage)
        self.assert_equal(status, http.OK.status)
        self.assert_equal(headers,
                          [('Content-Type', 'text/html; charset=UTF-8'),
                           ('Content-Length', str(len(html)))])
        self.assert_is_none(exc_info)
        self.assert_equal(content, [html])

        # GET /page?{query in EUC-JP} -> OK
        query = uri.quote('\u3044\u308d\u306f', encoding='euc-jp')
        environ = self.new_environ('GET', '/page', query=query)
        status, headers, exc_info, content = self.wsgi_call(environ)
        html = self.format(SimplePage)
        self.assert_equal(status, http.OK.status)
        self.assert_equal(headers,
                          [('Content-Type', 'text/html; charset=UTF-8'),
                           ('Content-Length', str(len(html)))])
        self.assert_is_none(exc_info)
        self.assert_equal(content, [html])
Exemplo n.º 11
0
    def test_get_page(self):
        # GET /page -> OK
        environ = self.new_environ('GET', '/page')
        status, headers, exc_info, content = self.wsgi_call(environ)
        html = self.format(SimplePage)
        self.assert_equal(status, http.OK.status)
        self.assert_equal(headers,
                          [('Content-Type', 'text/html; charset=UTF-8'),
                           ('Content-Length', str(len(html)))])
        self.assert_is_none(exc_info)
        self.assert_equal(content, [html])

        # GET /page?{query in EUC-JP} -> OK
        query = uri.quote('\u3044\u308d\u306f', encoding='euc-jp')
        environ = self.new_environ('GET', '/page', query=query)
        status, headers, exc_info, content = self.wsgi_call(environ)
        html = self.format(SimplePage)
        self.assert_equal(status, http.OK.status)
        self.assert_equal(headers,
                          [('Content-Type', 'text/html; charset=UTF-8'),
                           ('Content-Length', str(len(html)))])
        self.assert_is_none(exc_info)
        self.assert_equal(content, [html])