httplib2test.py.rej 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. --- httplib2test.py
  2. +++ httplib2test.py
  3. @@ -140,7 +140,7 @@ class _MyHTTPConnection(object):
  4. class HttpTest(unittest.TestCase):
  5. def setUp(self):
  6. - if os.path.exists(cacheDirName):
  7. + if os.path.exists(cacheDirName):
  8. [os.remove(os.path.join(cacheDirName, file)) for file in os.listdir(cacheDirName)]
  9. self.http = httplib2.Http(cacheDirName)
  10. self.http.clear_credentials()
  11. @@ -164,13 +164,13 @@ class HttpTest(unittest.TestCase):
  12. pass
  13. def testConnectionType(self):
  14. - self.http.force_exception_to_status_code = False
  15. + self.http.force_exception_to_status_code = False
  16. response, content = self.http.request("http://bitworking.org", connection_type=_MyHTTPConnection)
  17. self.assertEqual(response['content-location'], "http://bitworking.org")
  18. self.assertEqual(content, b"the body")
  19. def testGetUnknownServer(self):
  20. - self.http.force_exception_to_status_code = False
  21. + self.http.force_exception_to_status_code = False
  22. try:
  23. self.http.request("http://fred.bitworking.org/")
  24. self.fail("An httplib2.ServerNotFoundError Exception must be thrown on an unresolvable server.")
  25. @@ -206,9 +206,9 @@ class HttpTest(unittest.TestCase):
  26. uri = urllib.parse.urljoin(base, "reflector/reflector.cgi?d=\N{CYRILLIC CAPITAL LETTER DJE}")
  27. (response, content) = self.http.request(uri, "GET")
  28. d = self.reflector(content)
  29. - self.assertTrue('QUERY_STRING' in d)
  30. - self.assertTrue(d['QUERY_STRING'].find('%D0%82') > 0)
  31. -
  32. + self.assertTrue('QUERY_STRING' in d)
  33. + self.assertTrue(d['QUERY_STRING'].find('%D0%82') > 0)
  34. +
  35. def testGetIsDefaultMethod(self):
  36. # Test that GET is the default method
  37. uri = urllib.parse.urljoin(base, "methods/method_reflector.cgi")
  38. @@ -386,7 +386,7 @@ class HttpTest(unittest.TestCase):
  39. # Test that we can set a lower redirection limit
  40. # and that we raise an exception when we exceed
  41. # that limit.
  42. - self.http.force_exception_to_status_code = False
  43. + self.http.force_exception_to_status_code = False
  44. uri = urllib.parse.urljoin(base, "302/twostep.asis")
  45. try:
  46. @@ -410,7 +410,7 @@ class HttpTest(unittest.TestCase):
  47. def testGet302NoLocation(self):
  48. # Test that we throw an exception when we get
  49. # a 302 with no Location: header.
  50. - self.http.force_exception_to_status_code = False
  51. + self.http.force_exception_to_status_code = False
  52. uri = urllib.parse.urljoin(base, "302/no-location.asis")
  53. try:
  54. (response, content) = self.http.request(uri, "GET")
  55. @@ -421,14 +421,14 @@ class HttpTest(unittest.TestCase):
  56. self.fail("Threw wrong kind of exception ")
  57. # Re-run the test with out the exceptions
  58. - self.http.force_exception_to_status_code = True
  59. + self.http.force_exception_to_status_code = True
  60. (response, content) = self.http.request(uri, "GET")
  61. self.assertEqual(response.status, 500)
  62. self.assertTrue(response.reason.startswith("Redirected but"))
  63. self.assertEqual("302", response['status'])
  64. self.assertTrue(content.startswith(b"This is content"))
  65. -
  66. +
  67. def testGet301ViaHttps(self):
  68. # Google always redirects to http://google.com
  69. (response, content) = self.http.request("https://code.google.com/apis/", "GET")
  70. @@ -443,7 +443,7 @@ class HttpTest(unittest.TestCase):
  71. def testGetViaHttpsSpecViolationOnLocation(self):
  72. # Test that we follow redirects through HTTPS
  73. # even if they violate the spec by including
  74. - # a relative Location: header instead of an
  75. + # a relative Location: header instead of an
  76. # absolute one.
  77. (response, content) = self.http.request("https://google.com/adsense", "GET")
  78. self.assertEqual(200, response.status)
  79. @@ -452,8 +452,8 @@ class HttpTest(unittest.TestCase):
  80. def testGetViaHttpsKeyCert(self):
  81. # At this point I can only test
  82. - # that the key and cert files are passed in
  83. - # correctly to httplib. It would be nice to have
  84. + # that the key and cert files are passed in
  85. + # correctly to httplib. It would be nice to have
  86. # a real https endpoint to test against.
  87. http = httplib2.Http(timeout=2)
  88. @@ -517,7 +517,7 @@ class HttpTest(unittest.TestCase):
  89. def test303ForDifferentMethods(self):
  90. # Test that all methods can be used
  91. uri = urllib.parse.urljoin(base, "303/redirect-to-reflector.cgi")
  92. - for (method, method_on_303) in [("PUT", "GET"), ("DELETE", "GET"), ("POST", "GET"), ("GET", "GET"), ("HEAD", "GET")]:
  93. + for (method, method_on_303) in [("PUT", "GET"), ("DELETE", "GET"), ("POST", "GET"), ("GET", "GET"), ("HEAD", "GET")]:
  94. (response, content) = self.http.request(uri, method, body=b" ")
  95. self.assertEqual(response['x-method'], method_on_303)
  96. @@ -548,36 +548,36 @@ class HttpTest(unittest.TestCase):
  97. self.assertEqual(response.fromcache, False)
  98. def testGetIgnoreEtag(self):
  99. - # Test that we can forcibly ignore ETags
  100. + # Test that we can forcibly ignore ETags
  101. uri = urllib.parse.urljoin(base, "reflector/reflector.cgi")
  102. (response, content) = self.http.request(uri, "GET")
  103. self.assertNotEqual(response['etag'], "")
  104. (response, content) = self.http.request(uri, "GET", headers = {'cache-control': 'max-age=0'})
  105. d = self.reflector(content)
  106. - self.assertTrue('HTTP_IF_NONE_MATCH' in d)
  107. + self.assertTrue('HTTP_IF_NONE_MATCH' in d)
  108. self.http.ignore_etag = True
  109. (response, content) = self.http.request(uri, "GET", headers = {'cache-control': 'max-age=0'})
  110. d = self.reflector(content)
  111. self.assertEqual(response.fromcache, False)
  112. - self.assertFalse('HTTP_IF_NONE_MATCH' in d)
  113. + self.assertFalse('HTTP_IF_NONE_MATCH' in d)
  114. def testOverrideEtag(self):
  115. - # Test that we can forcibly ignore ETags
  116. + # Test that we can forcibly ignore ETags
  117. uri = urllib.parse.urljoin(base, "reflector/reflector.cgi")
  118. (response, content) = self.http.request(uri, "GET")
  119. self.assertNotEqual(response['etag'], "")
  120. (response, content) = self.http.request(uri, "GET", headers = {'cache-control': 'max-age=0'})
  121. d = self.reflector(content)
  122. - self.assertTrue('HTTP_IF_NONE_MATCH' in d)
  123. - self.assertNotEqual(d['HTTP_IF_NONE_MATCH'], "fred")
  124. + self.assertTrue('HTTP_IF_NONE_MATCH' in d)
  125. + self.assertNotEqual(d['HTTP_IF_NONE_MATCH'], "fred")
  126. (response, content) = self.http.request(uri, "GET", headers = {'cache-control': 'max-age=0', 'if-none-match': 'fred'})
  127. d = self.reflector(content)
  128. - self.assertTrue('HTTP_IF_NONE_MATCH' in d)
  129. - self.assertEqual(d['HTTP_IF_NONE_MATCH'], "fred")
  130. + self.assertTrue('HTTP_IF_NONE_MATCH' in d)
  131. + self.assertEqual(d['HTTP_IF_NONE_MATCH'], "fred")
  132. #MAP-commented this out because it consistently fails
  133. # def testGet304EndToEnd(self):
  134. @@ -596,7 +596,7 @@ class HttpTest(unittest.TestCase):
  135. # self.assertEqual(response.fromcache, True)
  136. def testGet304LastModified(self):
  137. - # Test that we can still handle a 304
  138. + # Test that we can still handle a 304
  139. # by only using the last-modified cache validator.
  140. uri = urllib.parse.urljoin(base, "304/last-modified-only/last-modified-only.txt")
  141. (response, content) = self.http.request(uri, "GET")
  142. @@ -715,7 +715,7 @@ class HttpTest(unittest.TestCase):
  143. self.assertEqual(response.fromcache, True, msg="Should be from cache")
  144. def testHeadGZip(self):
  145. - # Test that we don't try to decompress a HEAD response
  146. + # Test that we don't try to decompress a HEAD response
  147. uri = urllib.parse.urljoin(base, "gzip/final-destination.txt")
  148. (response, content) = self.http.request(uri, "HEAD")
  149. self.assertEqual(response.status, 200)
  150. @@ -741,7 +741,7 @@ class HttpTest(unittest.TestCase):
  151. def testGetGZipFailure(self):
  152. # Test that we raise a good exception when the gzip fails
  153. - self.http.force_exception_to_status_code = False
  154. + self.http.force_exception_to_status_code = False
  155. uri = urllib.parse.urljoin(base, "gzip/failed-compression.asis")
  156. try:
  157. (response, content) = self.http.request(uri, "GET")
  158. @@ -752,7 +752,7 @@ class HttpTest(unittest.TestCase):
  159. self.fail("Threw wrong kind of exception")
  160. # Re-run the test with out the exceptions
  161. - self.http.force_exception_to_status_code = True
  162. + self.http.force_exception_to_status_code = True
  163. (response, content) = self.http.request(uri, "GET")
  164. self.assertEqual(response.status, 500)
  165. @@ -761,7 +761,7 @@ class HttpTest(unittest.TestCase):
  166. def testIndividualTimeout(self):
  167. uri = urllib.parse.urljoin(base, "timeout/timeout.cgi")
  168. http = httplib2.Http(timeout=1)
  169. - http.force_exception_to_status_code = True
  170. + http.force_exception_to_status_code = True
  171. (response, content) = http.request(uri)
  172. self.assertEqual(response.status, 408)
  173. @@ -780,7 +780,7 @@ class HttpTest(unittest.TestCase):
  174. def testGetDeflateFailure(self):
  175. # Test that we raise a good exception when the deflate fails
  176. - self.http.force_exception_to_status_code = False
  177. + self.http.force_exception_to_status_code = False
  178. uri = urllib.parse.urljoin(base, "deflate/failed-compression.asis")
  179. try:
  180. @@ -792,7 +792,7 @@ class HttpTest(unittest.TestCase):
  181. self.fail("Threw wrong kind of exception")
  182. # Re-run the test with out the exceptions
  183. - self.http.force_exception_to_status_code = True
  184. + self.http.force_exception_to_status_code = True
  185. (response, content) = self.http.request(uri, "GET")
  186. self.assertEqual(response.status, 500)
  187. @@ -870,7 +870,7 @@ class HttpTest(unittest.TestCase):
  188. self.assertEqual(response.fromcache, False)
  189. def testUpdateInvalidatesCache(self):
  190. - # Test that calling PUT or DELETE on a
  191. + # Test that calling PUT or DELETE on a
  192. # URI that is cache invalidates that cache.
  193. uri = urllib.parse.urljoin(base, "304/test_etag.txt")
  194. @@ -884,7 +884,7 @@ class HttpTest(unittest.TestCase):
  195. self.assertEqual(response.fromcache, False)
  196. def testUpdateUsesCachedETag(self):
  197. - # Test that we natively support http://www.w3.org/1999/04/Editing/
  198. + # Test that we natively support http://www.w3.org/1999/04/Editing/
  199. uri = urllib.parse.urljoin(base, "conditional-updates/test.cgi")
  200. (response, content) = self.http.request(uri, "GET")
  201. @@ -900,7 +900,7 @@ class HttpTest(unittest.TestCase):
  202. def testUpdatePatchUsesCachedETag(self):
  203. - # Test that we natively support http://www.w3.org/1999/04/Editing/
  204. + # Test that we natively support http://www.w3.org/1999/04/Editing/
  205. uri = urllib.parse.urljoin(base, "conditional-updates/test.cgi")
  206. (response, content) = self.http.request(uri, "GET")
  207. @@ -915,7 +915,7 @@ class HttpTest(unittest.TestCase):
  208. self.assertEqual(response.status, 412)
  209. def testUpdateUsesCachedETagAndOCMethod(self):
  210. - # Test that we natively support http://www.w3.org/1999/04/Editing/
  211. + # Test that we natively support http://www.w3.org/1999/04/Editing/
  212. uri = urllib.parse.urljoin(base, "conditional-updates/test.cgi")
  213. (response, content) = self.http.request(uri, "GET")
  214. @@ -930,7 +930,7 @@ class HttpTest(unittest.TestCase):
  215. def testUpdateUsesCachedETagOverridden(self):
  216. - # Test that we natively support http://www.w3.org/1999/04/Editing/
  217. + # Test that we natively support http://www.w3.org/1999/04/Editing/
  218. uri = urllib.parse.urljoin(base, "conditional-updates/test.cgi")
  219. (response, content) = self.http.request(uri, "GET")
  220. @@ -978,7 +978,7 @@ class HttpTest(unittest.TestCase):
  221. (response, content) = self.http.request(uri, "GET")
  222. self.assertEqual(response.status, 401)
  223. - domain = urllib.parse.urlparse(base)[1]
  224. + domain = urllib.parse.urlparse(base)[1]
  225. self.http.add_credentials('joe', 'password', domain)
  226. (response, content) = self.http.request(uri, "GET")
  227. self.assertEqual(response.status, 200)
  228. @@ -1094,7 +1094,7 @@ class HttpTest(unittest.TestCase):
  229. uri = urllib.parse.urljoin(base, "reflector/reflector.cgi")
  230. (response, content) = self.http.request(uri, "GET")
  231. d = self.reflector(content)
  232. - self.assertTrue('HTTP_USER_AGENT' in d)
  233. + self.assertTrue('HTTP_USER_AGENT' in d)
  234. def testConnectionClose(self):
  235. @@ -1186,7 +1186,7 @@ class HttpPrivateTest(unittest.TestCase):
  236. def testNormalizeHeaders(self):
  237. - # Test that we normalize headers to lowercase
  238. + # Test that we normalize headers to lowercase
  239. h = httplib2._normalize_headers({'Cache-Control': 'no-cache', 'Other': 'Stuff'})
  240. self.assertTrue('cache-control' in h)
  241. self.assertTrue('other' in h)
  242. @@ -1327,19 +1327,19 @@ class HttpPrivateTest(unittest.TestCase):
  243. def testParseWWWAuthenticateEmpty(self):
  244. res = httplib2._parse_www_authenticate({})
  245. - self.assertEqual(len(list(res.keys())), 0)
  246. + self.assertEqual(len(list(res.keys())), 0)
  247. def testParseWWWAuthenticate(self):
  248. # different uses of spaces around commas
  249. res = httplib2._parse_www_authenticate({ 'www-authenticate': 'Test realm="test realm" , foo=foo ,bar="bar", baz=baz,qux=qux'})
  250. self.assertEqual(len(list(res.keys())), 1)
  251. self.assertEqual(len(list(res['test'].keys())), 5)
  252. -
  253. +
  254. # tokens with non-alphanum
  255. res = httplib2._parse_www_authenticate({ 'www-authenticate': 'T*!%#st realm=to*!%#en, to*!%#en="quoted string"'})
  256. self.assertEqual(len(list(res.keys())), 1)
  257. self.assertEqual(len(list(res['t*!%#st'].keys())), 2)
  258. -
  259. +
  260. # quoted string with quoted pairs
  261. res = httplib2._parse_www_authenticate({ 'www-authenticate': 'Test realm="a \\"test\\" realm"'})
  262. self.assertEqual(len(list(res.keys())), 1)
  263. @@ -1378,7 +1378,7 @@ class HttpPrivateTest(unittest.TestCase):
  264. def testParseWWWAuthenticateDigest(self):
  265. - res = httplib2._parse_www_authenticate({ 'www-authenticate':
  266. + res = httplib2._parse_www_authenticate({ 'www-authenticate':
  267. 'Digest realm="testrealm@host.com", qop="auth,auth-int", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", opaque="5ccc069c403ebaf9f0171e9517f40e41"'})
  268. digest = res['digest']
  269. self.assertEqual('testrealm@host.com', digest['realm'])
  270. @@ -1386,7 +1386,7 @@ class HttpPrivateTest(unittest.TestCase):
  271. def testParseWWWAuthenticateMultiple(self):
  272. - res = httplib2._parse_www_authenticate({ 'www-authenticate':
  273. + res = httplib2._parse_www_authenticate({ 'www-authenticate':
  274. 'Digest realm="testrealm@host.com", qop="auth,auth-int", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", opaque="5ccc069c403ebaf9f0171e9517f40e41" Basic REAlm="me" '})
  275. digest = res['digest']
  276. self.assertEqual('testrealm@host.com', digest['realm'])
  277. @@ -1399,7 +1399,7 @@ class HttpPrivateTest(unittest.TestCase):
  278. def testParseWWWAuthenticateMultiple2(self):
  279. # Handle an added comma between challenges, which might get thrown in if the challenges were
  280. # originally sent in separate www-authenticate headers.
  281. - res = httplib2._parse_www_authenticate({ 'www-authenticate':
  282. + res = httplib2._parse_www_authenticate({ 'www-authenticate':
  283. 'Digest realm="testrealm@host.com", qop="auth,auth-int", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", opaque="5ccc069c403ebaf9f0171e9517f40e41", Basic REAlm="me" '})
  284. digest = res['digest']
  285. self.assertEqual('testrealm@host.com', digest['realm'])
  286. @@ -1412,7 +1412,7 @@ class HttpPrivateTest(unittest.TestCase):
  287. def testParseWWWAuthenticateMultiple3(self):
  288. # Handle an added comma between challenges, which might get thrown in if the challenges were
  289. # originally sent in separate www-authenticate headers.
  290. - res = httplib2._parse_www_authenticate({ 'www-authenticate':
  291. + res = httplib2._parse_www_authenticate({ 'www-authenticate':
  292. 'Digest realm="testrealm@host.com", qop="auth,auth-int", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", opaque="5ccc069c403ebaf9f0171e9517f40e41", Basic REAlm="me", WSSE realm="foo", profile="UsernameToken"'})
  293. digest = res['digest']
  294. self.assertEqual('testrealm@host.com', digest['realm'])
  295. @@ -1426,8 +1426,8 @@ class HttpPrivateTest(unittest.TestCase):
  296. self.assertEqual('UsernameToken', wsse['profile'])
  297. def testParseWWWAuthenticateMultiple4(self):
  298. - res = httplib2._parse_www_authenticate({ 'www-authenticate':
  299. - 'Digest realm="test-real.m@host.com", qop \t=\t"\tauth,auth-int", nonce="(*)&^&$%#",opaque="5ccc069c403ebaf9f0171e9517f40e41", Basic REAlm="me", WSSE realm="foo", profile="UsernameToken"'})
  300. + res = httplib2._parse_www_authenticate({ 'www-authenticate':
  301. + 'Digest realm="test-real.m@host.com", qop \t=\t"\tauth,auth-int", nonce="(*)&^&$%#",opaque="5ccc069c403ebaf9f0171e9517f40e41", Basic REAlm="me", WSSE realm="foo", profile="UsernameToken"'})
  302. digest = res['digest']
  303. self.assertEqual('test-real.m@host.com', digest['realm'])
  304. self.assertEqual('\tauth,auth-int', digest['qop'])
  305. @@ -1448,7 +1448,7 @@ class HttpPrivateTest(unittest.TestCase):
  306. def testDigestObject(self):
  307. credentials = ('joe', 'password')
  308. host = None
  309. - request_uri = '/projects/httplib2/test/digest/'
  310. + request_uri = '/projects/httplib2/test/digest/'
  311. headers = {}
  312. response = {
  313. 'www-authenticate': 'Digest realm="myrealm", nonce="Ygk86AsKBAA=3516200d37f9a3230352fde99977bd6d472d4306", algorithm=MD5, qop="auth"'
  314. @@ -1456,7 +1456,7 @@ class HttpPrivateTest(unittest.TestCase):
  315. content = b""
  316. d = httplib2.DigestAuthentication(credentials, host, request_uri, headers, response, content, None)
  317. - d.request("GET", request_uri, headers, content, cnonce="33033375ec278a46")
  318. + d.request("GET", request_uri, headers, content, cnonce="33033375ec278a46")
  319. our_request = "authorization: %s" % headers['authorization']
  320. working_request = 'authorization: Digest username="joe", realm="myrealm", nonce="Ygk86AsKBAA=3516200d37f9a3230352fde99977bd6d472d4306", uri="/projects/httplib2/test/digest/", algorithm=MD5, response="97ed129401f7cdc60e5db58a80f3ea8b", qop=auth, nc=00000001, cnonce="33033375ec278a46"'
  321. self.assertEqual(our_request, working_request)
  322. @@ -1480,7 +1480,7 @@ class HttpPrivateTest(unittest.TestCase):
  323. def testDigestObjectStale(self):
  324. credentials = ('joe', 'password')
  325. host = None
  326. - request_uri = '/projects/httplib2/test/digest/'
  327. + request_uri = '/projects/httplib2/test/digest/'
  328. headers = {}
  329. response = httplib2.Response({ })
  330. response['www-authenticate'] = 'Digest realm="myrealm", nonce="Ygk86AsKBAA=3516200d37f9a3230352fde99977bd6d472d4306", algorithm=MD5, qop="auth", stale=true'
  331. @@ -1493,7 +1493,7 @@ class HttpPrivateTest(unittest.TestCase):
  332. def testDigestObjectAuthInfo(self):
  333. credentials = ('joe', 'password')
  334. host = None
  335. - request_uri = '/projects/httplib2/test/digest/'
  336. + request_uri = '/projects/httplib2/test/digest/'
  337. headers = {}
  338. response = httplib2.Response({ })
  339. response['www-authenticate'] = 'Digest realm="myrealm", nonce="Ygk86AsKBAA=3516200d37f9a3230352fde99977bd6d472d4306", algorithm=MD5, qop="auth", stale=true'
  340. @@ -1530,7 +1530,7 @@ class HttpPrivateTest(unittest.TestCase):
  341. end2end = httplib2._get_end2end_headers(response)
  342. self.assertEqual(0, len(end2end))
  343. - # Degenerate case of connection referrring to a header not passed in
  344. + # Degenerate case of connection referrring to a header not passed in
  345. response = {'connection': 'content-type'}
  346. end2end = httplib2._get_end2end_headers(response)
  347. self.assertEqual(0, len(end2end))