/usr/share/doc/python-twisted-web/howto/listings/client/cookies.py is in python-twisted-web 17.9.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | from __future__ import print_function
from twisted.internet import reactor
from twisted.python import log, compat
from twisted.web.client import Agent, CookieAgent
def displayCookies(response, cookieJar):
print('Received response')
print(response)
print('Cookies:', len(cookieJar))
for cookie in cookieJar:
print(cookie)
def main():
cookieJar = compat.cookielib.CookieJar()
agent = CookieAgent(Agent(reactor), cookieJar)
d = agent.request(b'GET', b'http://httpbin.org/cookies/set?some=data')
d.addCallback(displayCookies, cookieJar)
d.addErrback(log.err)
d.addCallback(lambda ignored: reactor.stop())
reactor.run()
if __name__ == "__main__":
main()
|