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

Commit

Permalink
Updating SDK to 0.67
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Mau committed May 16, 2016
1 parent 4393c44 commit 9ce1d18
Show file tree
Hide file tree
Showing 15 changed files with 167 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,8 @@ def non_deprecated_versions(self):
'django',
'http://www.djangoproject.com/',
'A full-featured web application framework for Python.',
['1.2', '1.3', '1.4', '1.5'],
['1.2', '1.3', '1.4', '1.5', '1.9'],
latest_version='1.4',
experimental_versions=['1.5'],
),
_VersionedLibrary(
'endpoints',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ def __get_v1_string_value(self, v1_value):
"""
check_conversion(v1_value.HasField('string_value'),
'Value does not contain a string value.')
return v1_value.string_value
return v1_value.string_value.encode('utf-8')

def __v1_integer_property(self, entity, name, value, indexed):
"""Populates a single-integer-valued v1 Property.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2050,9 +2050,9 @@ def _to_pb_v1(self, conn, query_options):

if self.filter_predicate and v1_ancestor_filter:
comp_filter_pb = v1_query.filter.composite_filter
comp_filter_pb.operator = googledatastore.CompositeFilter.AND
comp_filter_pb.filter.add().CopyFrom(filter_predicate_pb)
comp_filter_pb.filter.add().CopyFrom(v1_ancestor_filter)
comp_filter_pb.op = googledatastore.CompositeFilter.AND
comp_filter_pb.filters.add().CopyFrom(filter_predicate_pb)
comp_filter_pb.filters.add().CopyFrom(v1_ancestor_filter)
elif self.filter_predicate:
v1_query.filter.CopyFrom(filter_predicate_pb)
elif v1_ancestor_filter:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,17 @@ def set_appengine_imports():
from google.appengine.ext import db
from google.appengine.ext import gql
try:
# For the python-compat runtime.
from google.appengine.ext.vmruntime import callback
except ImportError:
callback = None
# For the python 2.7 runtime.
try:
from google.appengine.runtime import apiproxy as callback
# Python 2.5 and dev_appserver is not supported.
if not hasattr(callback, 'SetRequestEndCallback'):
callback = None
except ImportError:
callback = None
from google.appengine.runtime import apiproxy_errors
from google.net.proto import ProtocolBuffer
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@



import os
from google.appengine.ext.vmruntime import utils



REQUEST_ID_KEY = 'HTTP_X_CLOUD_TRACE_CONTEXT'
_callback_storage = {}


Expand All @@ -36,7 +33,7 @@ def SetRequestEndCallback(callback):
Args:
callback: A zero-argument callable whose return value is unused.
"""
req_id = GetRequestId()
req_id = utils.GetRequestId()



Expand All @@ -47,19 +44,8 @@ def SetRequestEndCallback(callback):

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

req_id = GetRequestId()
req_id = utils.GetRequestId()
if req_id in _callback_storage:
for callback in _callback_storage[req_id]:
callback(req_id)

del _callback_storage[req_id]


def GetRequestId():
"""Returns a unique ID using the cloud trace ID."""
if REQUEST_ID_KEY in os.environ:
return os.environ[REQUEST_ID_KEY]
else:
return None

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

from google.appengine.api.logservice import logservice
from google.appengine.ext.vmruntime import background_thread
from google.appengine.ext.vmruntime import utils
from google.appengine.runtime import request_environment
from google.appengine.runtime import runtime

Expand Down Expand Up @@ -122,7 +123,10 @@ def InitializeApiLogging():
def InitializeThreadingApis():
"""Helper to monkey-patch various threading APIs."""



runtime.PatchStartNewThread()
utils.PatchStartNewThread()

sys.modules[api.__name__ + '.background_thread'] = background_thread
api.background_thread = background_thread
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def FullyWrappedApp(appinfo_external, appengine_config):
app = middlewares.WsgiEnvSettingMiddleware(app, appinfo_external)
app = middlewares.FixServerEnvVarsMiddleware(app)
app = middlewares.OsEnvSetupMiddleware(app, appengine_config)
app = middlewares.RequestIdMiddleware(app)


app = middlewares.PatchLoggingMethods(app)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

from google.appengine.api import logservice
from google.appengine.ext.vmruntime import callback
from google.appengine.ext.vmruntime import utils
from google.appengine.ext.vmruntime import vmstub
from google.appengine.runtime import request_environment

Expand All @@ -41,6 +42,13 @@
REQUEST_LOG_BACKUPS = 3






REQ_ID_KEY = 'HTTP_X_CLOUD_TRACE_CONTEXT'


def PatchLoggingMethods(app):
"""Middleware for monkey patching logservice handling.
Expand Down Expand Up @@ -358,6 +366,30 @@ def PatchEnv(wsgi_env, start_response):
return PatchEnv


def RequestIdMiddleware(app):
"""Prepares a Request ID independent of os.environ for the app to use.
This middleware must be a layer above the OsEnvSetupMiddleware.
Args:
app: The WSGI app to wrap.
Returns:
The wrapped app, also a WSGI app.
"""
def HandleRequestId(wsgi_env, start_response):
"""The middleware WSGI app."""

assert REQ_ID_KEY in wsgi_env
utils.SetRequestId(wsgi_env[REQ_ID_KEY])
try:
return app(wsgi_env, start_response)
finally:
utils.DeleteRequestId(threading.current_thread().ident)

return HandleRequestId


def FixServerEnvVarsMiddleware(app):
"""Adjust SERVER_NAME and SERVER_PORT env vars to hide service bridge."""

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


"""Utility functions for python vm runtimes."""



import thread
import threading


def PatchStartNewThread(thread_module=thread, threading_module=threading):
"""Use custom version of start_new_thread."""
thread_module.start_new_thread = _MakeStartNewThread(
thread_module.start_new_thread)
reload(threading_module)


def _MakeStartNewThread(base_start_new_thread):
"""Replaces start_new_thread to register itself with the parent's request.
Args:
base_start_new_thread: The thread.start_new_thread function.
Returns:
Replacement for start_new_thread.
"""

def StartNewThread(target, args, kw=None):
"""A replacement for thread.start_new_thread.
Ensures this child thread will be associated with the correct request ID.
Args:
target: Function to be called.
args: Args to be passed in.
kw: Key word arguments to be passed in.
Returns:
Same as thread.start_new_thread
"""
req_id = GetRequestId()
if kw is None:
kw = {}
def Run():
SetRequestId(req_id)
try:
target(*args, **kw)
finally:
DeleteRequestId(threading.current_thread().ident)
return base_start_new_thread(Run, ())
return StartNewThread


_req_by_threads = {}


def GetRequestId():
"""Returns a unique ID using the cloud trace ID.
Only threads (or child threads) from user requests should have a request ID.
Other threads, such as initialization threads, do not have a request ID.
Returns:
The request ID.
"""
return _req_by_threads.setdefault(threading.current_thread().ident, None)


def SetRequestId(req_id):
"""Places the current thread in the context of the given request.
Args:
req_id: The request ID.
"""
_req_by_threads[threading.current_thread().ident] = req_id


def DeleteRequestId(thread_id):
"""Deletes the request ID associated with the thread.
Used by main request thread but also by child threads.
Args:
thread_id: The thread ID that will be deleted.
"""
del _req_by_threads[thread_id]


def InsideRequest():
"""True if we have a request ID."""
return GetRequestId() is not None

Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,8 @@ goog.DEPENDENCIES_ENABLED && (goog.dependencies_ = {pathIsModule:{}, nameToPath:
}
throw Error('Cannot write "' + src + '" after document load');
}
var isOldIE = goog.IS_OLD_IE_;
if (void 0 === opt_sourceText) {
if (isOldIE) {
if (goog.IS_OLD_IE_) {
var state = " onreadystatechange='goog.onScriptLoad_(this, " + ++goog.lastNonModuleScriptIndex_ + ")' ";
doc.write('<script type="text/javascript" src="' + src + '"' + state + ">\x3c/script>");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
// DO NOT EDIT! Generated by Protobuf-PHP protoc plugin @package_version@
// Source: google/datastore/v1beta3/datastore.proto
// Date: 2016-05-09 08:26:43
// Date: 2016-05-16 00:08:23

namespace google\datastore\v1beta3 {

Expand Down
Loading

0 comments on commit 9ce1d18

Please sign in to comment.