Пример #1
0
 def assertSorted(self, templates):
     matchers = sorted(
         URITemplateMatcher(URITemplate(t)) for t in templates)
     self.assertEqual(templates, [
         matcher.template.uri for matcher in matchers])
     self.assertEqual(templates, [
         matcher.template.uri for matcher in sorted(
             list(reversed(matchers)))])
Пример #2
0
 def test_interim_query(self):
     # query variables are not exactly implemented due to significant
     # complexities involved with integration with various platforms
     # and frameworks.
     template = URITemplate('/{root}/somewhere{?hello}')
     url = '/value/somewhere'
     matcher = URITemplateMatcher(template)
     result = matcher(url)
     # missing values ignored
     self.assertEqual({
         'root': 'value',
     }, result)
Пример #3
0
    def compile(self):
        self._trace = []
        self._converters = {}
        self._static_weights = []
        self._argument_weights = []

        # need to populate self.arguments
        # XXX subdomain and/or host ignored
        self._trace.append((False, '|'))
        for t, n, c, p in template_to_regex_patternstr.iter_template(
                self.rule):
            self._trace.append((isinstance(t, URIVariable), c))

        self._matcher = URITemplateMatcher(self.rule)
Пример #4
0
 def test_mismatch_types(self):
     with self.assertRaises(TypeError):
         sorted([
             '/raw_string',
             URITemplateMatcher(URITemplate('/template'))
         ])
Пример #5
0
 def test_matcher_equality_dynamic(self):
     first = URITemplateMatcher(URITemplate('/test{/path*}'))
     second = URITemplateMatcher(URITemplate('/test{/path*}'))
     self.assertEqual(first, second)
Пример #6
0
 def test_matcher_equality_static(self):
     first = URITemplateMatcher(URITemplate('/test'))
     second = URITemplateMatcher(URITemplate('/test'))
     self.assertEqual(first, second)
Пример #7
0
 def test_matcher_invalid(self):
     with self.assertRaises(ValueError):
         URITemplateMatcher(URITemplate('/{value}/{value}'))
Пример #8
0
 def test_matcher_basics(self):
     static = URITemplateMatcher(URITemplate('/test'))
     self.assertEqual(static('/test'), {})