cookie

使用

C = Cookie.SimpleCookie()
C["rocky"] = "road"
C["rocky"]["path"] = "/cookie"
print C.output(header="Cookie:")
Cookie: rocky=road; Path=/cookie
print C.output(attrs=[], header="Cookie:")
Cookie: rocky=road

C = Cookie.SimpleCookie()
C.load('keebler="E=everybody; L=\"Loves\"; fudge=\012;";')
print C
Set-Cookie: keebler="E=everybody; L="Loves"; fudge=\012;"

Cookie

class Cookie.BaseCookie([input])

value_decode value_encode load(rawdata)

class Cookie.SimpleCookie([input])

Morsel

实现时,只接收下列key值的赋值,并取key值为小写,并提供了isReservedKey(K)
方法来判断

expires
path
comment
domain
max-age
secure
version
httponly

value coded_value key

set(key, value, coded_value)

判断key值不为ReservedKey
判断key值是否合法
然后赋值key value coded_value

OutputString([attrs])

输出cookie形式的字符串

output([attrs[, header]])

return "%s %s" % ( header, self.OutputString(attrs) )

js_output([attrs])

    return """
    
    """ % ( self.OutputString(attrs).replace('"',r'\"'), )

你可能感兴趣的:(cookie)