Esempio n. 1
0
 def test_quoteString(self):
     """
     L{quoteString} returns a string which when interpreted according to the
     rules for I{quoted-string} (RFC 2616 section 2.2) matches the input
     string.
     """
     self.assertEqual(
         quoteString('a\\b"c'),
         '"a\\\\b\\"c"')
Esempio n. 2
0
 def test_generateKeyValuesQuoting(self):
     """
     L{generateKeyValues} quotes the value of the 2nd element of a tuple if
     it includes a character which cannot be in an HTTP token as defined in
     RFC 2616 section 2.2.
     """
     for needsQuote in [' ', '\t', '(', ')', '<', '>', '@', ',', ';', ':',
                        '\\', '"', '/', '[', ']', '?', '=', '{', '}']:
         self.assertEqual(
             generateKeyValues([("foo", needsQuote)]),
             'foo=%s' % (quoteString(needsQuote),))
Esempio n. 3
0
def generateWWWAuthenticate(headers):
    _generated = []
    for seq in headers:
        scheme, challenge = seq[0], seq[1]

        # If we're going to parse out to something other than a dict
        # we need to be able to generate from something other than a dict

        try:
            l = []
            for k, v in dict(challenge).iteritems():
                l.append("%s=%s" % (k, k in ("algorithm", "stale") and v or http_headers.quoteString(v)))

            _generated.append("%s %s" % (scheme, ", ".join(l)))
        except ValueError:
            _generated.append("%s %s" % (scheme, challenge))

    return _generated
Esempio n. 4
0
def generateWWWAuthenticate(headers):
    _generated = []
    for seq in headers:
        scheme, challenge = seq[0], seq[1]

        # If we're going to parse out to something other than a dict
        # we need to be able to generate from something other than a dict

        try:
            l = []
            for k, v in dict(challenge).iteritems():
                l.append("%s=%s" % (k, k in ("algorithm", "stale") and v
                                    or http_headers.quoteString(v)))

            _generated.append("%s %s" % (scheme, ", ".join(l)))
        except ValueError:
            _generated.append("%s %s" % (scheme, challenge))

    return _generated