Example #1
0
    def testParseTokenOK(self):

        data = {
            ""                                      : ("", ""),
            "unquoted"                              : ("unquoted", ""),
            "unquoted words"                        : ("unquoted", "words"),
            "unquoted  words"                       : ("unquoted", "words"),
            "unquoting a \"word\""                  : ("unquoting", "a \"word\""),
            "unquoted\twords"                       : ("unquoted", "words"),
            "unquoting\ta \"word\""                 : ("unquoting", "a \"word\""),
            "unquoted: words"                       : ("unquoted", "words"),
            "unquoting: a \"word\""                 : ("unquoting", "a \"word\""),

            "\"\""                                  : ("", ""),
            "\"quoted\""                            : ("quoted", ""),
            "\"quoted words\""                      : ("quoted words", ""),
            "\"quoting a \\\"word\\\"\""            : ("quoting a \"word\"", ""),
            "\"\" after"                            : ("", "after"),
            "\"quoted\" after"                      : ("quoted", "after"),
            "\"quoted words\" after"                : ("quoted words", "after"),
            "\"quoting a \\\"word\\\"\" after"      : ("quoting a \"word\"", "after"),
            "\"quoting a \\\"word\\\" after\" after": ("quoting a \"word\" after", "after"),
            "\"quoted\"after"                       : ("quoted", "after"),
            "\""                                    : ("", ""),
            "\"unterminated"                        : ("unterminated", ""),
            "\"unterminated words"                  : ("unterminated words", ""),
            "\"unterminated a \\\"word\\\""         : ("unterminated a \"word\"", ""),
        }

        for input, result in data.iteritems():
            self.assertEqual(parsetoken(input, " \t:"), result)
Example #2
0
    def isAllowed(self, method):
        methods = ()
        if self.hasResponseHeader(headers.Allow):

            # Look at each one and accumlate allowed methods
            for value in self.getResponseHeaders(headers.Allow):
                while value:
                    token, value = parsetoken(value, ", \t")
                    if method == token:
                        return True

        return False
Example #3
0
    def getAllowed(self):

        methods = ()
        if self.hasResponseHeader(headers.Allow):

            # Look at each one and accumlate allowed methods
            for value in self.getResponseHeaders(headers.Allow):
                while value:
                    token, value = parsetoken(value, ", \t")
                    methods += (token,)

        return methods
Example #4
0
    def parseAuthenticateHeader(self, hdrs):
        for hdr in hdrs:

            # Strip any space
            hdr = hdr.strip()

            # Must have Digest token
            if hdr[:7].lower() != "digest ":
                continue
            else:
                hdr = hdr[7:]

            # Get each name/value pair
            while True:
                name, hdr = parsetoken(hdr, " \t=")

                if not name or not hdr:
                    return
                name = name.lower()

                value, hdr = parsetoken(hdr, ", ")
                if not value:
                    return

                if name in ("realm", "domain", "nonce", "opaque", "algorithm", "qop"):
                    self.fields[name] = value

                elif name == "stale":
                    self.stale = value.lower() != "false"

                else:
                    # Unknown token - ignore
                    pass

                # Punt over space
                hdr = hdr.strip()

            break