示例#1
0
    def testNoMatch(self):
        self.assert_(utils.FindMatch({}, "") is None)
        self.assert_(utils.FindMatch({}, "foo") is None)
        self.assert_(utils.FindMatch({}, 1234) is None)

        data = {
            "X": "Hello World",
            re.compile("^(something)$"): "Hello World",
        }

        self.assert_(utils.FindMatch(data, "") is None)
        self.assert_(utils.FindMatch(data, "Hello World") is None)
示例#2
0
    def test(self):
        data = {
            "aaaa": "Four A",
            "bb": {
                "Two B": True
            },
            re.compile(r"^x(foo|bar|bazX)([0-9]+)$"): (1, 2, 3),
        }

        self.assertEqual(utils.FindMatch(data, "aaaa"), ("Four A", []))
        self.assertEqual(utils.FindMatch(data, "bb"), ({"Two B": True}, []))

        for i in ["foo", "bar", "bazX"]:
            for j in range(1, 100, 7):
                self.assertEqual(utils.FindMatch(data, "x%s%s" % (i, j)),
                                 ((1, 2, 3), [i, str(j)]))
示例#3
0
  def getController(self, uri):
    """Find method for a given URI.

    @param uri: string with URI

    @return: None if no method is found or a tuple containing
        the following fields:
            - method: name of method mapped to URI
            - items: a list of variable intems in the path
            - args: a dictionary with additional parameters from URL

    """
    if "?" in uri:
      (path, query) = uri.split("?", 1)
      args = urllib.parse.parse_qs(query)
    else:
      path = uri
      query = None
      args = {}

    # Try to find handler for request path
    result = utils.FindMatch(self._connector, path)

    if result is None:
      raise http.HttpNotFound()

    (handler, groups) = result

    return (handler, groups, args)