-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathXMPP_addr_access.py
62 lines (53 loc) · 1.84 KB
/
XMPP_addr_access.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from google.appengine.api import memcache
from google.appengine.ext import ndb
from google.appengine.ext import db
import logging
DEFAULT_ADDRESS_BOOK_NAME = 'default_addressbook'
def addressbook_key(addressbook_name=DEFAULT_ADDRESS_BOOK_NAME):
"""Constructs a Datastore key for a Addressbook entity with addressbook_name."""
return db.Key.from_path('Addressbook', addressbook_name)
class Address_pair(db.Model):
address = db.StringProperty()
userid = db.StringProperty()
def set_addr_id(addr,id):
memcache.set('ADDR of ' + id , addr)
memcache.set('ID of ' + addr , id)
q=Address_pair.all().ancestor(addressbook_key(DEFAULT_ADDRESS_BOOK_NAME))
q.filter('userid =', id)
entity = q.get()
if entity is not None:
entity.address = addr
entity.put()
else:
address_pair = Address_pair(parent=addressbook_key(DEFAULT_ADDRESS_BOOK_NAME))
address_pair.address = addr
address_pair.userid = id
address_pair.put()
def get_addr_from_id(id):
addr=memcache.get('ADDR of ' + id)
if addr is not None:
return addr
else:
q=Address_pair.all().ancestor(addressbook_key(DEFAULT_ADDRESS_BOOK_NAME))
q.filter('userid =', id)
entity = q.get()
if entity is not None:
addr = entity.address
else:
addr = None
memcache.set('ADDR of ' + id , addr)
return addr
def get_id_from_addr(addr):
id=memcache.get('ID of ' + addr)
if id is not None:
return id
else:
q=Address_pair.all().ancestor(addressbook_key(DEFAULT_ADDRESS_BOOK_NAME))
q.filter('address =', addr)
entity = q.get()
if entity is not None:
id = entity.userid
else:
id = None
memcache.set('ID of ' + addr , id)
return id