Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2007 Google Inc. | 3 # Copyright 2007 Google Inc. |
| 4 # | 4 # |
| 5 # Licensed under the Apache License, Version 2.0 (the "License"); | 5 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 # you may not use this file except in compliance with the License. | 6 # you may not use this file except in compliance with the License. |
| 7 # You may obtain a copy of the License at | 7 # You may obtain a copy of the License at |
| 8 # | 8 # |
| 9 # http://www.apache.org/licenses/LICENSE-2.0 | 9 # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 # | 10 # |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 save_cookies: If True, save the authentication cookies to local disk. | 181 save_cookies: If True, save the authentication cookies to local disk. |
| 182 If False, use an in-memory cookiejar instead. Subclasses must | 182 If False, use an in-memory cookiejar instead. Subclasses must |
| 183 implement this functionality. Defaults to False. | 183 implement this functionality. Defaults to False. |
| 184 account_type: Account type used for authentication. Defaults to | 184 account_type: Account type used for authentication. Defaults to |
| 185 AUTH_ACCOUNT_TYPE. | 185 AUTH_ACCOUNT_TYPE. |
| 186 """ | 186 """ |
| 187 self.host = host | 187 self.host = host |
| 188 if (not self.host.startswith("http://") and | 188 if (not self.host.startswith("http://") and |
| 189 not self.host.startswith("https://")): | 189 not self.host.startswith("https://")): |
| 190 self.host = "http://" + self.host | 190 self.host = "http://" + self.host |
| 191 assert re.match(r'^[a-z]+://[a-z0-9\.-_]+[a-z](|:[0-9]+)$', self.host), ( | 191 assert re.match(r'^[a-z]+://[a-z0-9\.-_]+(|:[0-9]+)$', self.host), ( |
|
nsylvain
2010/11/24 21:56:30
i dont know what this change means
M-A Ruel
2010/11/24 22:00:26
I doesn't force the host to finish with a letter,
| |
| 192 '%s is malformed' % host) | 192 '%s is malformed' % host) |
| 193 self.host_override = host_override | 193 self.host_override = host_override |
| 194 self.auth_function = auth_function | 194 self.auth_function = auth_function |
| 195 self.authenticated = False | 195 self.authenticated = False |
| 196 self.extra_headers = extra_headers | 196 self.extra_headers = extra_headers |
| 197 self.save_cookies = save_cookies | 197 self.save_cookies = save_cookies |
| 198 self.account_type = account_type | 198 self.account_type = account_type |
| 199 self.opener = self._GetOpener() | 199 self.opener = self._GetOpener() |
| 200 if self.host_override: | 200 if self.host_override: |
| 201 logging.info("Server: %s; Host: %s", self.host, self.host_override) | 201 logging.info("Server: %s; Host: %s", self.host, self.host_override) |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 | 273 |
| 274 Raises: | 274 Raises: |
| 275 HTTPError: If there was an error fetching the authentication cookies. | 275 HTTPError: If there was an error fetching the authentication cookies. |
| 276 """ | 276 """ |
| 277 # This is a dummy value to allow us to identify when we're successful. | 277 # This is a dummy value to allow us to identify when we're successful. |
| 278 continue_location = "http://localhost/" | 278 continue_location = "http://localhost/" |
| 279 args = {"continue": continue_location, "auth": auth_token} | 279 args = {"continue": continue_location, "auth": auth_token} |
| 280 tries = 0 | 280 tries = 0 |
| 281 url = "%s/_ah/login?%s" % (host, urllib.urlencode(args)) | 281 url = "%s/_ah/login?%s" % (host, urllib.urlencode(args)) |
| 282 while tries < 3: | 282 while tries < 3: |
| 283 tries += 1 | |
| 283 req = self._CreateRequest(url) | 284 req = self._CreateRequest(url) |
| 284 try: | 285 try: |
| 285 response = self.opener.open(req) | 286 response = self.opener.open(req) |
| 286 except urllib2.HTTPError, e: | 287 except urllib2.HTTPError, e: |
| 287 response = e | 288 response = e |
| 288 if e.code == 301: | 289 if e.code == 301: |
| 289 # Handle permanent redirect manually. | 290 # Handle permanent redirect manually. |
| 290 url = e.info()["location"] | 291 url = e.info()["location"] |
| 291 continue | 292 continue |
| 292 break | 293 break |
| (...skipping 1482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1775 try: | 1776 try: |
| 1776 RealMain(sys.argv) | 1777 RealMain(sys.argv) |
| 1777 except KeyboardInterrupt: | 1778 except KeyboardInterrupt: |
| 1778 print | 1779 print |
| 1779 StatusUpdate("Interrupted.") | 1780 StatusUpdate("Interrupted.") |
| 1780 sys.exit(1) | 1781 sys.exit(1) |
| 1781 | 1782 |
| 1782 | 1783 |
| 1783 if __name__ == "__main__": | 1784 if __name__ == "__main__": |
| 1784 main() | 1785 main() |
| OLD | NEW |