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

Side by Side Diff: chrome/common/extensions/docs/server2/datastore_models.py

Issue 1151283007: Docserver overhaul: Gitiles away from me. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove inform_users template to fix presubmit failure (it's now a redirect) Created 5 years, 6 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 unified diff | Download patch
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 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 cPickle 5 import cPickle
6 import google.appengine.ext.db as db
7 import logging
6 import traceback 8 import traceback
7 9
8 from appengine_wrappers import db 10
11 _MAX_ENTITY_SIZE = 1024*1024
12
9 13
10 # A collection of the data store models used throughout the server. 14 # A collection of the data store models used throughout the server.
11 # These values are global within datastore. 15 # These values are global within datastore.
12 16
13 class PersistentObjectStoreItem(db.Model): 17 class PersistentObjectStoreItem(db.Model):
14 pickled_value = db.BlobProperty() 18 pickled_value = db.BlobProperty()
15 19
16 @classmethod 20 @classmethod
17 def CreateKey(cls, namespace, key): 21 def CreateKey(cls, namespace, key):
18 path = '%s/%s' % (namespace, key) 22 path = '%s/%s' % (namespace, key)
19 try: 23 try:
20 return db.Key.from_path(cls.__name__, path) 24 return db.Key.from_path(cls.__name__, path)
21 except Exception: 25 except Exception:
22 # Probably AppEngine's BadValueError for the name being too long, but 26 # Probably AppEngine's BadValueError for the name being too long, but
23 # it's not documented which errors can actually be thrown here, so catch 27 # it's not documented which errors can actually be thrown here, so catch
24 # 'em all. 28 # 'em all.
25 raise ValueError( 29 raise ValueError(
26 'Exception thrown when trying to create db.Key from path %s: %s' % ( 30 'Exception thrown when trying to create db.Key from path %s: %s' % (
27 path, traceback.format_exc())) 31 path, traceback.format_exc()))
28 32
29 @classmethod 33 @classmethod
30 def CreateItem(cls, namespace, key, value): 34 def CreateItem(cls, namespace, key, value):
35 pickled_value = cPickle.dumps(value)
36 if len(pickled_value) > _MAX_ENTITY_SIZE:
37 logging.warn('Refusing to create entity greater than 1 MB in size: %s/%s'
38 % (namespace, key))
39 return None
31 return PersistentObjectStoreItem(key=cls.CreateKey(namespace, key), 40 return PersistentObjectStoreItem(key=cls.CreateKey(namespace, key),
32 pickled_value=cPickle.dumps(value)) 41 pickled_value=pickled_value)
33 42
34 def GetValue(self): 43 def GetValue(self):
35 return cPickle.loads(self.pickled_value) 44 return cPickle.loads(self.pickled_value)
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/data_source.py ('k') | chrome/common/extensions/docs/server2/datastore_util.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698