Esempio n. 1
0
    def loads(self, serialized_activity):
        parts = serialized_activity.split(',')
        # convert these to ids
        actor_id, verb_id, object_id, target_id = map(
            int, parts[:4])
        activity_datetime = epoch_to_datetime(float(parts[4]))
        pickle_string = str(parts[5])
        if not target_id:
            target_id = None
        verb = get_verb_by_id(verb_id)
        extra_context = {}
        if pickle_string:
            extra_context = pickle.loads(pickle_string)
        activity = self.activity_class(actor_id, verb, object_id, target_id,
                                       time=activity_datetime, extra_context=extra_context)

        return activity
Esempio n. 2
0
    def loads(self, serialized_aggregated):
        activity_serializer = self.activity_serializer_class(Activity)
        try:
            serialized_aggregated = serialized_aggregated[2:]
            parts = serialized_aggregated.split(';;')
            # start with the group
            group = parts[0]
            aggregated = self.aggregated_activity_class(group)

            # get the date and activities
            date_dict = dict(zip(self.date_fields, parts[1:5]))
            for k, v in date_dict.items():
                date_value = None
                if v != '-1':
                    date_value = epoch_to_datetime(float(v))
                setattr(aggregated, k, date_value)

            # looks for ; not \;
            unescaped_semicolons_regex = re.compile("(?<=[^\\\]);")
            # write the activities
            serializations = unescaped_semicolons_regex.split(parts[5])
            if self.dehydrate:
                activity_ids = list(map(int, serializations))
                aggregated._activity_ids = activity_ids
                aggregated.dehydrated = True
            else:
                activities = []
                for s in serializations:
                    s = s.replace("\;", ";")
                    deserialized = activity_serializer.loads(s)
                    activities.append(deserialized)
                aggregated.activities = activities
                aggregated.dehydrated = False

            # write the minimized activities
            minimized = int(parts[6])
            aggregated.minimized_activities = minimized

            return aggregated
        except Exception as e:
            msg = six.text_type(e)
            raise SerializationException(msg)
    def loads(self, serialized_activity):
        parts = serialized_activity.split(',')
        # convert these to ids
        actor_id, verb_id, object_id, target_id = map(int, parts[:4])
        activity_datetime = epoch_to_datetime(float(parts[4]))
        pickle_string = str(parts[5])
        if not target_id:
            target_id = None
        verb = get_verb_by_id(verb_id)
        extra_context = {}
        if pickle_string:
            extra_context = pickle.loads(pickle_string)
        activity = self.activity_class(actor_id,
                                       verb,
                                       object_id,
                                       target_id,
                                       time=activity_datetime,
                                       extra_context=extra_context)

        return activity
    def loads(self, serialized_aggregated):
        activity_serializer = self.activity_serializer_class(
            self.activity_class)
        try:
            serialized_aggregated = serialized_aggregated[2:]
            parts = serialized_aggregated.split(';;')
            # start with the group
            group = parts[0]
            aggregated = self.aggregated_activity_class(group)

            # get the date and activities
            date_dict = dict(zip(self.date_fields, parts[1:5]))
            for k, v in date_dict.items():
                date_value = None
                if v != '-1':
                    date_value = epoch_to_datetime(float(v))
                setattr(aggregated, k, date_value)

            # write the activities
            serializations = parts[5].split(';')
            if self.dehydrate:
                activity_ids = list(map(int, serializations))
                aggregated._activity_ids = activity_ids
                aggregated.dehydrated = True
            else:
                activities = [
                    activity_serializer.loads(s) for s in serializations
                ]
                aggregated.activities = activities
                aggregated.dehydrated = False

            # write the minimized activities
            minimized = int(parts[6])
            aggregated.minimized_activities = minimized

            return aggregated
        except Exception as e:
            msg = six.text_type(e)
            raise SerializationException(msg)
    def loads(self, serialized_aggregated):
        activity_serializer = self.activity_serializer_class(Activity)
        try:
            serialized_aggregated = serialized_aggregated[2:]
            parts = serialized_aggregated.split(';;')
            # start with the group
            group = parts[0]
            aggregated = self.aggregated_activity_class(group)

            # get the date and activities
            date_dict = dict(zip(self.date_fields, parts[1:5]))
            for k, v in date_dict.items():
                date_value = None
                if v != '-1':
                    date_value = epoch_to_datetime(float(v))
                setattr(aggregated, k, date_value)

            # write the activities
            serializations = parts[5].split(';')
            if self.dehydrate:
                activity_ids = map(int, serializations)
                aggregated._activity_ids = activity_ids
                aggregated.dehydrated = True
            else:
                activities = [activity_serializer.loads(s)
                              for s in serializations]
                aggregated.activities = activities
                aggregated.dehydrated = False

            # write the minimized activities
            minimized = int(parts[6])
            aggregated.minimized_activities = minimized

            return aggregated
        except Exception, e:
            msg = unicode(e)
            raise SerializationException(msg)
Esempio n. 6
0
    def test_conversion(self):
        source_date = datetime.now()
        epoch = datetime_to_epoch(source_date)
        converted_date = epoch_to_datetime(epoch)

        assert source_date == converted_date