Skip to content
This repository was archived by the owner on Jan 12, 2022. It is now read-only.

Commit 3343f3a

Browse files
author
Bryan Mau
committed
Updating Compat Layer
1 parent b776908 commit 3343f3a

5 files changed

Lines changed: 97 additions & 129 deletions

File tree

appengine-compat/exported_appengine_sdk/google/appengine/api/appinfo.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,12 @@
4646

4747

4848
if os.environ.get('APPENGINE_RUNTIME') == 'python27':
49-
from google.appengine.api import pagespeedinfo
5049
from google.appengine.api import validation
5150
from google.appengine.api import yaml_builder
5251
from google.appengine.api import yaml_listener
5352
from google.appengine.api import yaml_object
5453
else:
5554

56-
from google.appengine.api import pagespeedinfo
5755
from google.appengine.api import validation
5856
from google.appengine.api import yaml_builder
5957
from google.appengine.api import yaml_listener
@@ -272,7 +270,6 @@
272270
API_CONFIG = 'api_config'
273271
CODE_LOCK = 'code_lock'
274272
ENV_VARIABLES = 'env_variables'
275-
PAGESPEED = 'pagespeed'
276273

277274
SOURCE_REPO_RE_STRING = r'^[a-z][a-z0-9\-\+\.]*:[^#]*$'
278275
SOURCE_REVISION_RE_STRING = r'^[0-9a-fA-F]+$'
@@ -1874,7 +1871,6 @@ class AppInfoExternal(validation.Validated):
18741871
API_CONFIG: validation.Optional(ApiConfigHandler),
18751872
CODE_LOCK: validation.Optional(bool),
18761873
ENV_VARIABLES: validation.Optional(EnvironmentVariables),
1877-
PAGESPEED: validation.Optional(pagespeedinfo.PagespeedEntry),
18781874
}
18791875

18801876
def CheckInitialized(self):

appengine-compat/exported_appengine_sdk/google/appengine/api/pagespeedinfo.py

Lines changed: 0 additions & 115 deletions
This file was deleted.

appengine-compat/exported_appengine_sdk/google/appengine/ext/ndb/tasklets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def dump_all_pending(self, verbose=False):
178178
pending.append(line)
179179
return '\n'.join(pending)
180180

181-
def reset(self):
181+
def reset(self, unused_req_id):
182182
self.current_context = None
183183
ev = eventloop.get_event_loop()
184184
ev.clear()

appengine-compat/exported_appengine_sdk/google/appengine/ext/vmruntime/callback.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,27 @@ def SetRequestEndCallback(callback):
3636
Args:
3737
callback: A zero-argument callable whose return value is unused.
3838
"""
39-
key = _GetRequestId()
39+
req_id = GetRequestId()
4040

4141

4242

4343

44-
if key:
45-
_callback_storage.setdefault(key, []).append(callback)
44+
if req_id:
45+
_callback_storage.setdefault(req_id, []).append(callback)
4646

4747

4848
def InvokeCallbacks():
4949
"""Invokes the callbacks associated with the current request ID."""
5050

51-
key = _GetRequestId()
52-
if key in _callback_storage:
53-
for callback in _callback_storage[key]:
54-
callback()
51+
req_id = GetRequestId()
52+
if req_id in _callback_storage:
53+
for callback in _callback_storage[req_id]:
54+
callback(req_id)
5555

56-
del _callback_storage[key]
56+
del _callback_storage[req_id]
5757

5858

59-
def _GetRequestId():
59+
def GetRequestId():
6060
"""Returns a unique ID using the cloud trace ID."""
6161
if REQUEST_ID_KEY in os.environ:
6262
return os.environ[REQUEST_ID_KEY]
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright 2007 Google Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (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
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
19+
"""A Request-Local object. Note, these objects are not thread-local."""
20+
21+
22+
23+
import UserDict
24+
25+
from google.appengine.ext.vmruntime import callback
26+
27+
28+
class RequestLocal(object):
29+
"""A replica of threading.local objects except across requests.
30+
31+
RequestLocal objects, unlike thread-local objects, can and often are
32+
created outside the context of any requests. In such scenarios, any
33+
attributes set outside a request are considered global attributes that can
34+
be accessed by any request.
35+
"""
36+
37+
def __getattribute__(self, name):
38+
request_id = callback.GetRequestId()
39+
my_dict = object.__getattribute__(self, '__dict__')
40+
41+
42+
if request_id and name in my_dict.setdefault(request_id, {}):
43+
return my_dict[request_id][name]
44+
45+
46+
return object.__getattribute__(self, name)
47+
48+
def __setattr__(self, name, value):
49+
request_id = callback.GetRequestId()
50+
my_dict = object.__getattribute__(self, '__dict__')
51+
52+
if request_id:
53+
if request_id in my_dict:
54+
my_dict[request_id][name] = value
55+
else:
56+
57+
callback.SetRequestEndCallback(
58+
object.__getattribute__(self, '_cleanup'))
59+
my_dict[request_id] = {name: value}
60+
else:
61+
62+
my_dict[name] = value
63+
64+
def __delattr__(self, name):
65+
request_id = callback.GetRequestId()
66+
my_dict = object.__getattribute__(self, '__dict__')
67+
68+
69+
if not request_id:
70+
object.__delattr__(self, name)
71+
return
72+
73+
74+
if name in my_dict.setdefault(request_id, {}):
75+
del my_dict[request_id][name]
76+
elif object.__hasattr__(self, name):
77+
raise AttributeError('Cannot delete global attribute "%s"' % name)
78+
else:
79+
raise AttributeError('%s has no attribute "%s"' % (self, name))
80+
81+
def _cleanup(self, req_id):
82+
my_dict = object.__getattribute__(self, '__dict__')
83+
del my_dict[req_id]
84+
85+
86+
class RequestLocalDict(UserDict.IterableUserDict, RequestLocal):
87+
"""A dictionary with request-local contents."""

0 commit comments

Comments
 (0)