예제 #1
0
 def key_(kwargs):
     stream = StringIO()
     stream.write(base_cache_key)
     kwargt = f.meta["kwarg_types"]
     for a in sorted(kwargt.keys()):
         if a in kwargs:
             effective_value = kwargs[a]
         else:
             effective_value = f_pure_default_args_dict[a]
         if isinstance(kwargt[a], list):
             get_list_serializer(get_serializer(kwargt[a][0]))(stream, effective_value)
         else:
             get_serializer(kwargt[a])(stream, effective_value)
     return stream.getvalue()
예제 #2
0
 def key_(kwargs):
     stream = StringIO()
     stream.write(base_cache_key)
     kwargt = f.meta['kwarg_types']
     for a in sorted(kwargt.keys()):
         if a in kwargs:
             effective_value = kwargs[a]
         else:
             effective_value = f_pure_default_args_dict[a]
         if isinstance(kwargt[a], list):
             get_list_serializer(get_serializer(kwargt[a][0]))(
                 stream, effective_value)
         else:
             get_serializer(kwargt[a])(stream, effective_value)
     return stream.getvalue()
예제 #3
0
    s_unicode(stream, acs.service_identity_email)
    s_bool(stream, acs.removable)
    s_unicode_list(stream, acs.local)
    s_long_list(stream, acs.service_roles)


def _deserialize_auto_connected_service(stream, version):
    a = AutoConnectedService()
    a.service_identity_email = ds_unicode(stream)
    a.removable = ds_bool(stream)
    a.local = ds_unicode_list(stream)
    a.service_roles = [] if version < 2 else ds_long_list(stream)
    return a


_serialize_auto_connected_service_list = get_list_serializer(_serialize_auto_connected_service)
_deserialize_auto_connected_service_list = get_list_deserializer(_deserialize_auto_connected_service, True)


class AutoConnectedServices(SpecializedList):

    def add(self, autoConnectedService):
        self._table[autoConnectedService.service_identity_email] = autoConnectedService
        return autoConnectedService

    def get(self, service_identity_email):
        return self._table[service_identity_email] if service_identity_email in self._table else None

    def remove(self, service_identity_email):
        self._table.pop(service_identity_email, 1)
    s_unicode(stream, b.caption)
    s_unicode(stream, b.action)
    s_long(stream, b.ui_flags)
    s_unicode(stream, b.color)

def _deserialize_button(stream, version):
    b = Button()
    b.id = ds_unicode(stream)
    b.index = ds_long(stream)
    b.caption = ds_unicode(stream)
    b.action = ds_unicode(stream)
    b.ui_flags = ds_long(stream) if version >= 2 else 0
    b.color = ds_unicode(stream) if version >= 3 else None
    return b

_serialize_button_list = get_list_serializer(_serialize_button)
_deserialize_button_list = get_list_deserializer(_deserialize_button, True)

class SpecializedList(object):

    def __init__(self):
        self._table = dict()

    def __getitem__(self, key):
        if isinstance(key, (str, unicode)):
            return self._table[key]
        elif isinstance(key, int):
            for x in self.values():
                if x.index == key:
                    return x
        raise KeyError()
예제 #5
0

def _deserialize_shift(stream, version):
    s = Shift()
    s.name = ds_unicode(stream)
    s.start = ds_long(stream)
    s.end = ds_long(stream)
    s.leap_time = ds_long(stream)
    s.capacity = ds_long(stream)
    s.threshold = ds_long(stream)
    s.max_group_size = ds_long(stream)
    s.days = ds_long_list(stream)
    return s


_serialize_shift_list = get_list_serializer(_serialize_shift)
_deserialize_shift_list = get_list_deserializer(_deserialize_shift, True)


def _serialize_shifts(stream, shifts):
    s_long(stream, 1)  # version in case we need to adjust the shifts structure
    _serialize_shift_list(stream, shifts.values())


def _deserialize_shifts(stream):
    version = ds_long(stream)
    shifts = Shifts()
    for s in _deserialize_shift_list(stream, version):
        shifts.add(s)
    return shifts
예제 #6
0

def _serialize_news_buttons(stream, buttons):
    s_long(stream, 3)  # version
    _serialize_news_button_list(stream, buttons)


def _deserialize_news_buttons(stream):
    version = ds_long(stream)
    buttons = NewsButtons()
    for b in _deserialize_news_button_list(stream, version):
        buttons.add(b)
    return buttons


_serialize_news_button_list = get_list_serializer(_serialize_news_button)
_deserialize_news_button_list = get_list_deserializer(_deserialize_news_button, True)


class NewsButtons(SpecializedList):

    def add(self, button):
        if button.id in self._table:
            raise DuplicateButtonIdException()
        self._table[button.id] = button

    def __iter__(self):
        for b in sorted(self._table.itervalues(), key=lambda x: x.index):
            yield b

    def values(self):
예제 #7
0
    s_unicode(stream, md.app_id)


def _deserialize_mobile_detail(stream, version):
    from rogerthat.models import App
    md = MobileDetail()
    md.account = ds_unicode(stream)
    md.type_ = ds_long(stream)
    md.pushId = ds_unicode(stream)
    if version < 2:
        md.app_id = App.APP_ID_ROGERTHAT
    else:
        md.app_id = ds_unicode(stream)
    return md

_serialize_mobile_detail_list = get_list_serializer(_serialize_mobile_detail)
_deserialize_mobile_detail_list = get_list_deserializer(_deserialize_mobile_detail, True)


class MobileDetails(object):

    def __init__(self):
        self._table = dict()

    def append(self, md):
        if not md or not isinstance(md, MobileDetail):
            raise ValueError
        self._table[md.account] = md
        return md

    def addNew(self, account, type_, pushId, app_id):
예제 #8
0
def _s_house_list(stream, l):
    s_long(stream, 1)
    f = get_list_serializer(_s_house_to)
    f(stream, l)
예제 #9
0
def _s_collection_list(stream, l):
    s_long(stream, 1)
    f = get_list_serializer(_s_collection_to)
    f(stream, l)
예제 #10
0
def _s_activity_list(stream, l):
    #    s_long(stream, CURRENT_ACTIVITY_VERSION)
    s_long(stream, 1)
    f = get_list_serializer(_s_activity_to)
    f(stream, l)
예제 #11
0
    def app_id(self):
        from rogerthat.utils.app import get_app_id_from_app_user
        return get_app_id_from_app_user(self.user)

    @property
    def is_phone_unregistered(self):
        return self.status > Mobile.STATUS_NEW | Mobile.STATUS_ACCOUNT_CREATED | Mobile.STATUS_REGISTERED


@deserializer
def ds_mobile(stream):
    return model_deserializer(stream, Mobile)

register(Mobile, s_model, ds_mobile)

s_mobile_list = get_list_serializer(s_model)
ds_mobile_list = get_list_deserializer(ds_mobile)
register(List(Mobile), s_mobile_list, ds_mobile_list)


class ErrorPlatformVersion(NdbModel):
    platform_version = ndb.StringProperty()
    client_version = ndb.StringProperty()


class ClientError(NdbModel):
    PLATFORM_ANDROID = 1
    PLATFORM_IPHONE = 5
    PLATFORMS = (PLATFORM_ANDROID, PLATFORM_IPHONE)
    message = ndb.TextProperty()
    description = ndb.TextProperty()
예제 #12
0
    s_unicode(stream, md.pushId)
    s_unicode(stream, md.app_id)

def _deserialize_mobile_detail(stream, version):
    from rogerthat.models import App
    md = MobileDetail()
    md.account = ds_unicode(stream)
    md.type_ = ds_long(stream)
    md.pushId = ds_unicode(stream)
    if version < 2:
        md.app_id = App.APP_ID_ROGERTHAT
    else:
        md.app_id = ds_unicode(stream)
    return md

_serialize_mobile_detail_list = get_list_serializer(_serialize_mobile_detail)
_deserialize_mobile_detail_list = get_list_deserializer(_deserialize_mobile_detail, True)

class MobileDetails(object):

    def __init__(self):
        self._table = dict()

    def append(self, md):
        if not md or not isinstance(md, MobileDetail):
            raise ValueError
        self._table[md.account] = md
        return md

    def addNew(self, account, type_, pushId, app_id):
        md = MobileDetail()
예제 #13
0
    s_long(stream, comment.index)
    s_unicode(stream, comment.text)
    s_unicode(stream, comment.creator)
    s_long(stream, comment.timestamp)


def _deserialize_prospect_comment(stream, version):
    comment = ProspectComment()
    comment.index = ds_long(stream)
    comment.text = ds_unicode(stream)
    comment.creator = ds_unicode(stream)
    comment.timestamp = ds_long(stream)
    return comment


_serialize_prospect_comment_list = get_list_serializer(
    _serialize_prospect_comment)
_deserialize_prospect_comment_list = get_list_deserializer(
    _deserialize_prospect_comment, True)


class ProspectComments(SpecializedList):
    def add(self, prospect_comment):
        self._table[prospect_comment.index] = prospect_comment
        return prospect_comment


def _serialize_prospect_comments(stream, prospect_comments):
    s_long(stream, 1)  # version
    _serialize_prospect_comment_list(
        stream,
        [] if prospect_comments is None else prospect_comments.values())
예제 #14
0

def _serialize_choice(stream, c):
    s_long(stream, 1)  # version
    s_unicode(stream, c.label)
    s_unicode(stream, c.value)


def _deserialize_choice(stream):
    c = Choice()
    ds_long(stream)  # version
    c.label = ds_unicode(stream)
    c.value = ds_unicode(stream)
    return c

_serialize_choice_list = get_list_serializer(_serialize_choice)
_deserialize_choice_list = get_list_deserializer(_deserialize_choice)


def _serialize_text_widget(stream, w):
    s_long(stream, 2)  # version
    s_unicode(stream, w.value)
    s_unicode(stream, w.place_holder)
    s_long(stream, w.max_chars)
    s_unicode(stream, w.keyboard_type)


def _deserialize_text_widget(stream, w):
    version = ds_long(stream)
    w.value = ds_unicode(stream)
    w.place_holder = ds_unicode(stream)
예제 #15
0
    fd.avatarId = ds_long(stream)
    fd.shareLocation = ds_bool(stream)
    fd.sharesLocation = ds_bool(stream)
    fd.sharesContacts = ds_bool(stream)
    if version == 1:
        from rogerthat.dal.profile import is_service_identity_user
        is_svc = is_service_identity_user(users.User(fd.email))
        fd.type = FriendDetail.TYPE_SERVICE if is_svc else FriendDetail.TYPE_USER
    else:
        fd.type = ds_long(stream)
    fd.hasUserData = False if version < 3 else ds_bool(stream)
    fd.relationVersion = 0 if version < 4 else ds_long(stream)
    fd.existence = FriendDetail.FRIEND_EXISTENCE_ACTIVE if version < 5 else ds_long(stream)
    return fd

_serialize_friend_detail_list = get_list_serializer(_serialize_friend_detail)
_deserialize_friend_detail_list = get_list_deserializer(_deserialize_friend_detail, True)


class FriendDetails(object):

    def __init__(self):
        self._table = dict()

    def append(self, fd):
        if not fd or not isinstance(fd, FriendDetail):
            raise ValueError
        self._table[fd.email] = fd

    def addNew(self, user, name, avatarId, shareLocation=False, sharesLocation=False, sharesContacts=True,
               type_=FriendDetail.TYPE_USER, hasUserData=False, existence=FriendDetail.FRIEND_EXISTENCE_ACTIVE):
예제 #16
0
    ) if version > 2 else MenuItem.VISIBLE_IN_MENU | MenuItem.VISIBLE_IN_ORDER
    item.unit = ds_long(stream) if version > 3 else UNIT_PIECE
    item.step = ds_long(stream) if version > 3 else 1
    if version < 6:
        item.image_id = None
    else:
        item.image_id = ds_long(stream)
        if item.image_id == -1:
            item.image_id = None
    item.qr_url = None if version < 7 else ds_unicode(stream)
    item.has_price = item.price > 0 if version < 8 else ds_bool(stream)
    item.id = ds_unicode(stream) if version > 8 else None
    return item


_serialize_item_list = get_list_serializer(_serialize_item)
_deserialize_item_list = get_list_deserializer(_deserialize_item, True)


def _serialize_category(stream, c):
    s_unicode(stream, c.name)
    _serialize_item_list(stream, c.items)
    s_long(stream, c.index)
    s_unicode(stream, c.predescription)
    s_unicode(stream, c.postdescription)
    s_unicode(stream, c.id)


def _deserialize_category(stream, version):
    c = MenuCategory()
    c.name = ds_unicode(stream)