| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import os | 5 import os |
| 6 import re |
| 7 from StringIO import StringIO |
| 8 import sys |
| 6 | 9 |
| 7 def GetAppVersion(): | 10 def GetAppVersion(): |
| 8 if 'CURRENT_VERSION_ID' in os.environ: | 11 if 'CURRENT_VERSION_ID' in os.environ: |
| 9 return os.environ['CURRENT_VERSION_ID'] | 12 return os.environ['CURRENT_VERSION_ID'] |
| 10 # Not running on appengine, get it from the app.yaml file ourselves. We | 13 # Not running on appengine, get it from the app.yaml file ourselves. We |
| 11 # could properly parse this using a yaml library but Python doesn't have | 14 # could properly parse this using a yaml library but Python doesn't have |
| 12 # one built in so whatevs. | 15 # one built in so whatevs. |
| 13 version_key = 'version:' | 16 version_key = 'version:' |
| 14 app_yaml_path = os.path.join(os.path.split(__file__)[0], 'app.yaml') | 17 app_yaml_path = os.path.join(os.path.split(__file__)[0], 'app.yaml') |
| 15 with open(app_yaml_path, 'r') as app_yaml: | 18 with open(app_yaml_path, 'r') as app_yaml: |
| 16 version_line = [line for line in app_yaml.read().split('\n') | 19 version_line = [line for line in app_yaml.read().split('\n') |
| 17 if line.startswith(version_key)][0] | 20 if line.startswith(version_key)][0] |
| 18 return version_line[len(version_key):].strip() | 21 return version_line[len(version_key):].strip() |
| 19 | 22 |
| 20 def IsDevServer(): | 23 def IsDevServer(): |
| 21 return os.environ.get('SERVER_SOFTWARE', '').find('Development') == 0 | 24 return os.environ.get('SERVER_SOFTWARE', '').find('Development') == 0 |
| 22 | 25 |
| 26 class FakeRequest(object): |
| 27 def __init__(self, path, headers=None): |
| 28 self.path = path |
| 29 self.url = '//localhost/%s' % path |
| 30 self.headers = headers or {} |
| 31 |
| 32 class FakeResponse(object): |
| 33 def __init__(self): |
| 34 self.status = 200 |
| 35 self.out = StringIO() |
| 36 self.headers = {} |
| 37 |
| 38 def set_status(self, status): |
| 39 self.status = status |
| 40 |
| 41 def clear(self, *args): |
| 42 pass |
| 43 |
| 23 # This will attempt to import the actual App Engine modules, and if it fails, | 44 # This will attempt to import the actual App Engine modules, and if it fails, |
| 24 # they will be replaced with fake modules. This is useful during testing. | 45 # they will be replaced with fake modules. This is useful during testing. |
| 25 try: | 46 try: |
| 26 import google.appengine.api.files as files | 47 import google.appengine.api.files as files |
| 27 import google.appengine.api.logservice as logservice | 48 import google.appengine.api.logservice as logservice |
| 28 import google.appengine.api.memcache as memcache | 49 import google.appengine.api.memcache as memcache |
| 29 import google.appengine.api.urlfetch as urlfetch | 50 import google.appengine.api.urlfetch as urlfetch |
| 30 import google.appengine.ext.blobstore as blobstore | 51 import google.appengine.ext.blobstore as blobstore |
| 31 from google.appengine.ext.blobstore.blobstore import BlobReferenceProperty | 52 from google.appengine.ext.blobstore.blobstore import BlobReferenceProperty |
| 32 import google.appengine.ext.db as db | 53 import google.appengine.ext.db as db |
| 33 import google.appengine.ext.webapp as webapp | 54 import google.appengine.ext.webapp as webapp |
| 34 from google.appengine.runtime import DeadlineExceededError | 55 from google.appengine.runtime import DeadlineExceededError |
| 35 except ImportError: | 56 except ImportError: |
| 36 import re | |
| 37 from StringIO import StringIO | |
| 38 | |
| 39 FAKE_URL_FETCHER_CONFIGURATION = None | 57 FAKE_URL_FETCHER_CONFIGURATION = None |
| 40 | 58 |
| 41 def ConfigureFakeUrlFetch(configuration): | 59 def ConfigureFakeUrlFetch(configuration): |
| 42 """|configuration| is a dictionary mapping strings to fake urlfetch classes. | 60 """|configuration| is a dictionary mapping strings to fake urlfetch classes. |
| 43 A fake urlfetch class just needs to have a fetch method. The keys of the | 61 A fake urlfetch class just needs to have a fetch method. The keys of the |
| 44 dictionary are treated as regex, and they are matched with the URL to | 62 dictionary are treated as regex, and they are matched with the URL to |
| 45 determine which fake urlfetch is used. | 63 determine which fake urlfetch is used. |
| 46 """ | 64 """ |
| 47 global FAKE_URL_FETCHER_CONFIGURATION | 65 global FAKE_URL_FETCHER_CONFIGURATION |
| 48 FAKE_URL_FETCHER_CONFIGURATION = dict( | 66 FAKE_URL_FETCHER_CONFIGURATION = dict( |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 db._store.pop(key, None) | 284 db._store.pop(key, None) |
| 267 return _RPC() | 285 return _RPC() |
| 268 | 286 |
| 269 @staticmethod | 287 @staticmethod |
| 270 def put_async(value): | 288 def put_async(value): |
| 271 db._store[value.key] = value | 289 db._store[value.key] = value |
| 272 return _RPC() | 290 return _RPC() |
| 273 | 291 |
| 274 class BlobReferenceProperty(object): | 292 class BlobReferenceProperty(object): |
| 275 pass | 293 pass |
| OLD | NEW |