Beispiel #1
0
    def test_method(self):
        self.assertEqual(self.r.method, 'GET')

        self.r.method = u('POST')
        self.assertEqual(self.r.method, 'POST')

        self.r.method = b'PUT'
        self.assertEqual(self.r.method, 'PUT')
Beispiel #2
0
    def test_method(self):
        self.assertEqual(self.r.method, 'GET')

        self.r.method = u('POST')
        self.assertEqual(self.r.method, 'POST')

        self.r.method = b'PUT'
        self.assertEqual(self.r.method, 'PUT')
Beispiel #3
0
    def after_setup(self):
        @condition(host(b"sub1.foobar.com"))
        @self.app.get('/')
        def sub1():
            return 'sub1'

        @condition(host(u("sub2.foobar.com")))
        @self.app.get('/')
        def sub2():
            return 'sub2'
Beispiel #4
0
    def after_setup(self):
        @condition(user_agent(b"^Uagent1"))
        @self.app.get("/")
        def route_one():
            return "one"

        @condition(user_agent(u("^Uagent2")))
        @self.app.get("/")
        def route_two():
            return "two"
Beispiel #5
0
    def after_setup(self):
        @condition(host(b"sub1.foobar.com"))
        @self.app.get('/')
        def sub1():
            return 'sub1'

        @condition(host(u("sub2.foobar.com")))
        @self.app.get('/')
        def sub2():
            return 'sub2'
Beispiel #6
0
    def after_setup(self):
        @condition(user_agent(b"^Uagent1"))
        @self.app.get("/")
        def route_one():
            return "one"

        @condition(user_agent(u("^Uagent2")))
        @self.app.get("/")
        def route_two():
            return "two"
Beispiel #7
0
    def test_ua_conditions(self):
        ua_vals = {
            'family': 'a',
            'major':  'b',
            'minor':  'c',
            'patch':  'd',
        }

        # Unicode-encode one of the values to test.
        ua_vals['family'] = u(ua_vals['family'])

        self.assertTrue(self.call_ua_condition(ua_vals, ua_vals=ua_vals))
Beispiel #8
0
    def test_ua_conditions(self):
        ua_vals = {
            'family': 'a',
            'major': 'b',
            'minor': 'c',
            'patch': 'd',
        }

        # Unicode-encode one of the values to test.
        ua_vals['family'] = u(ua_vals['family'])

        self.assertTrue(self.call_ua_condition(ua_vals, ua_vals=ua_vals))
Beispiel #9
0
    def test_os_conditions(self):
        os_vals = {
            'family': 'a',
            'major':  'b',
            'minor':  'c',
            'patch':  'd',
        }
        kwargs = {}
        for k, v in os_vals.items():
            kwargs['os_' + k] = v

        # Unicode-encode one of the values to test.
        kwargs['os_family'] = u(kwargs['os_family'])

        self.assertTrue(self.call_ua_condition(kwargs, os_vals=os_vals))
Beispiel #10
0
    def test_os_conditions(self):
        os_vals = {
            'family': 'a',
            'major': 'b',
            'minor': 'c',
            'patch': 'd',
        }
        kwargs = {}
        for k, v in os_vals.items():
            kwargs['os_' + k] = v

        # Unicode-encode one of the values to test.
        kwargs['os_family'] = u(kwargs['os_family'])

        self.assertTrue(self.call_ua_condition(kwargs, os_vals=os_vals))
Beispiel #11
0
    def escape_string(self, string):
        base_escapes = {
            b'&': b'\\u0026', b'>': b'\\u003E', b'<': b'\\u003C'
        }
        escapes = base_escapes.copy()
        for k, v in iteritems(base_escapes):
            escapes[k.decode('latin-1')] = v.decode('latin-1')

        # Decode our unicode line/paragraph seperators.
        line_sep = b'\xE2\x80\xA8'.decode('utf-8')
        line_sep_escape = b'\\u2028'.decode('latin-1')
        paragraph_sep = b'\xE2\x80\xA9'.decode('utf-8')
        paragraph_sep_escape = b'\\u2029'.decode('latin-1')

        def encoder(match):
            v = match.group(0)
            return escapes[v]

        if isinstance(string, text_type):
            ret = re.sub(u(r"[&<>]"), encoder, string)
            return ret.replace(line_sep, line_sep_escape).replace(
                paragraph_sep, paragraph_sep_escape)
        else:
            return re.sub(br"[&<>]", encoder, string)
 def test_set_body_with_invalid(self):
     with self.assertRaises(ValueError):
         self.m.body = u('foo')
 def test_get_text(self):
     self.m.response_iter = [b'foo', b'bar']
     self.assertEqual(self.m.text, u('foobar'))
 def test_set_text(self):
     self.m.text = u('foobar')
     self.assertEqual(self.m.response_iter, [b'foobar'])
Beispiel #15
0
 def test_unsafe_re(self):
     unsafe = u('[a-z]')
     enc = quote('aSDF', unsafe=unsafe)
     self.assertEqual(enc, b'%61SDF')
Beispiel #16
0
 def test_unsafe_re(self):
     unsafe = u('[a-z]')
     enc = quote('aSDF', unsafe=unsafe)
     self.assertEqual(enc, b'%61SDF')