Merge branch 'main' into avm99963-monorail

Merged commit cd4b3b336f1f14afa02990fdc2eec5d9467a827e

GitOrigin-RevId: e67bbf185d5538e1472bb42e0abb2a141f88bac1
diff --git a/framework/servlet.py b/framework/servlet.py
index e1c0cf1..462939a 100644
--- a/framework/servlet.py
+++ b/framework/servlet.py
@@ -21,16 +21,16 @@
 from __future__ import absolute_import
 
 import gc
-import httplib
+from six.moves import http_client
 import json
 import logging
 import os
 import random
 import time
-import urllib
+from six.moves import urllib
 
 import ezt
-from third_party import httpagentparser
+import httpagentparser
 
 from google.appengine.api import app_identity
 from google.appengine.api import modules
@@ -199,8 +199,8 @@
       except MySQLdb.OperationalError as e:
         logging.exception(e)
         page_data = {
-          'http_response_code': httplib.SERVICE_UNAVAILABLE,
-          'requested_url': self.request.url,
+            'http_response_code': http_client.SERVICE_UNAVAILABLE,
+            'requested_url': self.request.url,
         }
         self.template = template_helpers.GetTemplate(
             'templates/framework/database-maintenance.ezt',
@@ -228,15 +228,15 @@
 
     except exceptions.InputException as e:
       logging.info('Rejecting invalid input: %r', e)
-      self.response.status = httplib.BAD_REQUEST
+      self.response.status = http_client.BAD_REQUEST
 
     except exceptions.NoSuchProjectException as e:
       logging.info('Rejecting invalid request: %r', e)
-      self.response.status = httplib.NOT_FOUND
+      self.response.status = http_client.NOT_FOUND
 
     except xsrf.TokenIncorrect as e:
       logging.info('Bad XSRF token: %r', e.message)
-      self.response.status = httplib.BAD_REQUEST
+      self.response.status = http_client.BAD_REQUEST
 
     except permissions.BannedUserException as e:
       logging.warning('The user has been banned')
@@ -246,7 +246,7 @@
 
     except ratelimiter.RateLimitExceeded as e:
       logging.info('RateLimitExceeded Exception %s', e)
-      self.response.status = httplib.BAD_REQUEST
+      self.response.status = http_client.BAD_REQUEST
       self.response.body = 'Slow your roll.'
 
     finally:
@@ -369,8 +369,8 @@
         # Display the missing permissions template.
         page_data = {
             'reason': e.message,
-            'http_response_code': httplib.FORBIDDEN,
-            }
+            'http_response_code': http_client.FORBIDDEN,
+        }
         with self.mr.profiler.Phase('gather base data'):
           page_data.update(self.GatherBaseData(self.mr, nonce))
         self._AddHelpDebugPageData(page_data)
@@ -431,7 +431,7 @@
     except permissions.PermissionException as e:
       logging.warning('Trapped permission-related exception "%s".', e)
       # TODO(jrobbins): can we do better than an error page? not much.
-      self.response.status = httplib.BAD_REQUEST
+      self.response.status = http_client.BAD_REQUEST
 
   def _DoCommonRequestProcessing(self, request, mr):
     """Do common processing dependent on having the user and project pbs."""