author | Lennard de Rijk <ljvderijk@gmail.com> |
Sat, 05 Sep 2009 14:04:24 +0200 | |
changeset 2862 | 27971a13089f |
parent 1597 | e7b7ea113a3b |
permissions | -rwxr-xr-x |
1597
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python |
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
2 |
# |
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2008 Google Inc. |
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
4 |
# |
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
8 |
# |
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
10 |
# |
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
16 |
|
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
17 |
"""Convenience functions. |
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
18 |
""" |
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
19 |
|
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
20 |
from google.appengine.api import datastore |
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
21 |
|
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
22 |
|
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
23 |
def transactional(operation): |
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
24 |
"""Decorator that wraps a method in a datastore transaction. |
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
25 |
|
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
26 |
The method will be called through datastore.RunInTransaction, making the |
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
27 |
operation atomic. |
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
28 |
""" |
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
29 |
def transactional_operation(*args, **kwargs): |
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
30 |
return datastore.RunInTransaction(operation, *args, **kwargs) |
e7b7ea113a3b
Add google-app-engine-ranklist project to ranklist folder in app.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
31 |
return transactional_operation |