Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2217)

Unified Diff: appengine/chromium_build_logs/third_party/oauth2client/django_orm.py

Issue 1260293009: make version of ts_mon compatible with appengine (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: clean up code Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: appengine/chromium_build_logs/third_party/oauth2client/django_orm.py
diff --git a/appengine/chromium_build_logs/third_party/oauth2client/django_orm.py b/appengine/chromium_build_logs/third_party/oauth2client/django_orm.py
index d3642f7e7b457aeb7ea3e89c7cc9b6e2893648e9..65c5d2010d835ca54b2ddfccf1aac2194e9eb9d5 100644
--- a/appengine/chromium_build_logs/third_party/oauth2client/django_orm.py
+++ b/appengine/chromium_build_logs/third_party/oauth2client/django_orm.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2010 Google Inc.
+# Copyright 2014 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -31,17 +31,24 @@ class CredentialsField(models.Field):
__metaclass__ = models.SubfieldBase
+ def __init__(self, *args, **kwargs):
+ if 'null' not in kwargs:
+ kwargs['null'] = True
+ super(CredentialsField, self).__init__(*args, **kwargs)
+
def get_internal_type(self):
return "TextField"
def to_python(self, value):
- if not value:
+ if value is None:
return None
if isinstance(value, oauth2client.client.Credentials):
return value
return pickle.loads(base64.b64decode(value))
def get_db_prep_value(self, value, connection, prepared=False):
+ if value is None:
+ return None
return base64.b64encode(pickle.dumps(value))
@@ -49,6 +56,11 @@ class FlowField(models.Field):
__metaclass__ = models.SubfieldBase
+ def __init__(self, *args, **kwargs):
+ if 'null' not in kwargs:
+ kwargs['null'] = True
+ super(FlowField, self).__init__(*args, **kwargs)
+
def get_internal_type(self):
return "TextField"
@@ -60,6 +72,8 @@ class FlowField(models.Field):
return pickle.loads(base64.b64decode(value))
def get_db_prep_value(self, value, connection, prepared=False):
+ if value is None:
+ return None
return base64.b64encode(pickle.dumps(value))
@@ -102,13 +116,26 @@ class Storage(BaseStorage):
credential.set_store(self)
return credential
- def locked_put(self, credentials):
+ def locked_put(self, credentials, overwrite=False):
"""Write a Credentials to the datastore.
Args:
credentials: Credentials, the credentials to store.
+ overwrite: Boolean, indicates whether you would like these credentials to
+ overwrite any existing stored credentials.
"""
args = {self.key_name: self.key_value}
- entity = self.model_class(**args)
+
+ if overwrite:
+ entity, unused_is_new = self.model_class.objects.get_or_create(**args)
+ else:
+ entity = self.model_class(**args)
+
setattr(entity, self.property_name, credentials)
entity.save()
+
+ def locked_delete(self):
+ """Delete Credentials from the datastore."""
+
+ query = {self.key_name: self.key_value}
+ entities = self.model_class.objects.filter(**query).delete()

Powered by Google App Engine
This is Rietveld 408576698