Пример #1
0
 def expire(self):
     TempObj.expire(self)
     for f in self.uploaded_files:
         try:
             os.remove(f['encrypted_path'])
         except Exception:
             pass
Пример #2
0
 def expire(self):
     TempObj.expire(self)
     for f in self.uploaded_files:
         try:
             os.remove(f['encrypted_path'])
         except:
             pass
Пример #3
0
    def test_object_expire(self):
        """
        call the expire and checks that the object is expired
        """

        c = task.Clock() # deterministic clock

        objs_dict = {}
        obj = TempObj(objs_dict, uuid4(), 1, c)
        obj.expire()
        self.assertIsNone(obj._expireCall)
Пример #4
0
    def test_object_expire(self):
        """
        call the expire and checks that the object is expired
        """

        c = task.Clock()  # deterministic clock

        objs_dict = {}
        obj = TempObj(objs_dict, uuid4(), 1, c)
        obj.expire()
        self.assertIsNone(obj._expireCall)
Пример #5
0
    def __init__(self, token_kind, uses=MAX_USES):
        """
        token_kind assumes currently only value 'submission.

        we plan to add other kinds like 'file'.

        """

        if reactor_override:
            reactor = reactor_override
        else:
            reactor = None

        self.kind = token_kind

        # both 'validity' variables need to be expressed in seconds
        self.start_validity_secs = GLSettings.memory_copy.submission_minimum_delay
        self.end_validity_secs = GLSettings.memory_copy.submission_maximum_ttl

        # Remind: this is just for developers, because if a clean house
        # is a sign of a waste life, a Token object without shortcut
        # is a sign of a psycho life. (vecnish!)
        if GLSettings.devel_mode:
            self.start_validity_secs = 0

        self.remaining_uses = uses

        # creation_date of token assignment
        self.creation_date = datetime.utcnow()

        # to keep track of the file uploaded associated
        self.uploaded_files = []

        self.id = rstr.xeger(r'[A-Za-z0-9]{42}')

        # initialization of token configuration
        self.human_captcha = False
        self.graph_captcha = False
        self.proof_of_work = False

        self.generate_token_challenge()

        TempObj.__init__(
            self,
            TokenList.token_dict,
            # token ID:
            self.id,
            # seconds of validity:
            self.start_validity_secs + self.end_validity_secs,
            reactor)
Пример #6
0
    def __init__(self, token_kind, context_id):
        """
        token_kind assumes currently only value 'submission.

        we plan to add other kinds like 'file'.

        """

        if reactor_override:
            reactor = reactor_override
        else:
            reactor = None

        self.kind = token_kind

        # both 'validity' variables need to be expressed in seconds
        self.start_validity_secs = GLSettings.memory_copy.submission_minimum_delay
        self.end_validity_secs = GLSettings.memory_copy.submission_maximum_ttl

        # Remind: this is just for developers, because if a clean house
        # is a sign of a waste life, a Token object without shortcut
        # is a sign of a psycho life. (vecnish!)
        if GLSettings.devel_mode:
            self.start_validity_secs = 0

        self.remaining_allowed_attempts = Token.MAXIMUM_ATTEMPTS_PER_TOKEN

        # creation_date of token assignment
        self.creation_date = datetime.utcnow()

        # in the future, difficulty can be trimmed on context basis too
        self.context_associated = context_id

        # to keep track of the file uploaded associated
        self.uploaded_files = []

        self.token_id = rstr.xeger(r'[A-Za-z0-9]{42}')

        # initialization
        self.human_captcha = False
        self.graph_captcha = False
        self.proof_of_work = False

        TempObj.__init__(self,
                         TokenList.token_dict,
                         # token ID:
                         self.token_id,
                         # seconds of validity:
                         self.start_validity_secs + self.end_validity_secs,
                         reactor)
Пример #7
0
    def __init__(self, token_kind, uses = MAX_USES):
        """
        token_kind assumes currently only value 'submission.

        we plan to add other kinds like 'file'.

        """

        if reactor_override:
            reactor = reactor_override
        else:
            reactor = None

        self.kind = token_kind

        # both 'validity' variables need to be expressed in seconds
        self.start_validity_secs = GLSettings.memory_copy.submission_minimum_delay
        self.end_validity_secs = GLSettings.memory_copy.submission_maximum_ttl

        # Remind: this is just for developers, because if a clean house
        # is a sign of a waste life, a Token object without shortcut
        # is a sign of a psycho life. (vecnish!)
        if GLSettings.devel_mode:
            self.start_validity_secs = 0

        self.remaining_uses = uses

        # creation_date of token assignment
        self.creation_date = datetime.utcnow()

        # to keep track of the file uploaded associated
        self.uploaded_files = []

        self.id = generateRandomKey(42)

        # initialization of token configuration
        self.human_captcha = False
        self.graph_captcha = False
        self.proof_of_work = False

        self.generate_token_challenge()

        TempObj.__init__(self,
                         TokenList.token_dict,
                         # token ID:
                         self.id,
                         # seconds of validity:
                         self.start_validity_secs + self.end_validity_secs,
                         reactor)
Пример #8
0
    def __init__(self, event_obj, request_time, debug=False):
        self.debug = debug
        self.creation_date = datetime_now()
        self.event_id = EventTrackQueue.event_number()
        self.event_type = event_obj['name']
        self.request_time = request_time

        if self.debug:
            log.debug("Creation of Event %s" % self.serialize_event())

        TempObj.__init__(self,
                         EventTrackQueue.queue,
                         self.event_id,
                         10, # seconds of validity
                         reactor_override)

        self.expireCallbacks.append(self.synthesis)
Пример #9
0
    def __init__(self, receiver_id, debug=False):
        self.debug = debug
        self.creation_date = datetime_now()
        self.receiver_id = receiver_id

        if receiver_id in LastHourMailQueue.receivers_in_threshold:
            log.err("Implementation error ? Receiver %s already present" % receiver_id)

        TempObj.__init__(self,
                         LastHourMailQueue.blocked_in_queue,
                         random.randint(0, 0xffff),
                         # seconds of validity:
                         GLSettings.memory_copy.notification_suspension_time,
                         reactor_override)

        log.info("Temporary disable emails for receiver %s for four hours" % self.receiver_id)
        LastHourMailQueue.receivers_in_threshold.append(receiver_id)
        self.expireCallbacks.append(self.reactivate_receiver_mails)
Пример #10
0
    def __init__(self, receiver_id, debug=False):
        self.debug = debug
        self.creation_date = datetime_now()
        self.receiver_id = receiver_id

        if receiver_id in LastHourMailQueue.receivers_in_threshold:
            log.err("Implementation error ? Receiver %s already present" % receiver_id)

        TempObj.__init__(self,
                         LastHourMailQueue.blocked_in_queue,
                         random.randint(0, 0xffff),
                         # seconds of validity:
                         GLSettings.memory_copy.notification_suspension_time,
                         reactor_override)

        log.info("Temporary disable emails for receiver %s for four hours" % self.receiver_id)
        LastHourMailQueue.receivers_in_threshold.append(receiver_id)
        self.expireCallbacks.append(self.reactivate_receiver_mails)
Пример #11
0
    def __init__(self, event_obj, request_time, debug=False):
        self.debug = debug
        self.creation_date = datetime_now()
        self.event_id = EventTrackQueue.event_number()
        self.event_type = event_obj['name']
        self.request_time = request_time

        if self.debug:
            log.debug("Creation of Event %s" % self.serialize_event())

        TempObj.__init__(
            self,
            EventTrackQueue.queue,
            self.event_id,
            # seconds of validity:
            GLSettings.anomaly_delta,
            reactor_override)

        self.expireCallbacks.append(self.synthesis)
Пример #12
0
    def __init__(self, event_obj, request_time, debug=False):
        self.debug = debug
        self.creation_date = datetime_now()
        self.event_id = EventTrackQueue.event_number()
        self.event_type = event_obj['name']
        self.request_time = request_time

        if self.debug:
            log.debug("Creation of Event %s" % self.serialize_event())

        TempObj.__init__(
            self,
            EventTrackQueue.queue,
            self.event_id,
            # seconds of validity:
            ANOMALY_WINDOW_SECONDS,
            reactor)

        self.expireCallbacks.append(self.synthesis)
Пример #13
0
    def __init__(self, receiver_id, receiver_name, debug=False):

        self.debug = debug
        self.creation_date = datetime_now()
        self.receiver_id = receiver_id
        self.event_id = LastHourMailQueue.get_incremental_number()

        # This variable is just used for debug/log purpose
        self.receiver_name = receiver_name

        TempObj.__init__(self,
                         LastHourMailQueue.event_queue,
                         self.event_id,
                         # seconds of validity:
                         3600,
                         reactor_override)

        LastHourMailQueue.per_receiver_lastmails.setdefault(receiver_id, 0)
        LastHourMailQueue.per_receiver_lastmails[receiver_id] += 1

        self.expireCallbacks.append(self.manage_mail_expiration)
Пример #14
0
    def __init__(self, receiver_id, receiver_name, debug=False):

        self.debug = debug
        self.creation_date = datetime_now()
        self.receiver_id = receiver_id
        self.event_id = LastHourMailQueue.get_incremental_number()

        # This variable is just used for debug/log purpose
        self.receiver_name = receiver_name

        TempObj.__init__(self,
                         LastHourMailQueue.event_queue,
                         self.event_id,
                         # seconds of validity:
                         3600,
                         reactor_override)

        LastHourMailQueue.per_receiver_lastmails.setdefault(receiver_id, 0)
        LastHourMailQueue.per_receiver_lastmails[receiver_id] += 1

        self.expireCallbacks.append(self.manage_mail_expiration)
Пример #15
0
    def test_object_notifyOnExpire(self):
        """
        add 3 notifyOnExpire and checks that they are called
        """

        c = task.Clock() # deterministic clock

        events = []
        objs_dict = {}
        obj = TempObj(objs_dict, uuid4(), 2, c)

        for x in range(0, 3):
            obj.notifyOnExpire(lambda: events.append((x)))

        c.advance(1)

        self.assertEqual(0, len(events))

        c.advance(1)

        self.assertEqual(3, len(events))
Пример #16
0
    def test_object_notifyOnExpire(self):
        """
        add 3 notifyOnExpire and checks that they are called
        """

        c = task.Clock()  # deterministic clock

        events = []
        objs_dict = {}
        obj = TempObj(objs_dict, uuid4(), 2, c)

        for x in range(0, 3):
            obj.notifyOnExpire(lambda: events.append((x)))

        c.advance(1)

        self.assertEqual(0, len(events))

        c.advance(1)

        self.assertEqual(3, len(events))
Пример #17
0
    def test_object_touch_and_expiry(self):
        """
        reproduced the test pattern of twisted/test/test_task.py: testCallLaterResetLater
        """

        c = task.Clock()  # deterministic clock

        objs_dict = {}
        obj = TempObj(objs_dict, uuid4(), 2, c)
        obj.touch()
        c.advance(1)
        obj.touch()
        c.advance(1)
        obj.touch()
        c.advance(1)
        self.assertIsNotNone(obj._expireCall)
        c.advance(1)
        self.assertIsNone(obj._expireCall)
Пример #18
0
    def test_object_touch_and_expiry(self):
        """
        reproduced the test pattern of twisted/test/test_task.py: testCallLaterResetLater
        """

        c = task.Clock() # deterministic clock

        objs_dict = {}
        obj = TempObj(objs_dict, uuid4(), 2, c)
        obj.touch()
        c.advance(1)
        obj.touch()
        c.advance(1)
        obj.touch()
        c.advance(1)
        self.assertIsNotNone(obj._expireCall)
        c.advance(1)
        self.assertIsNone(obj._expireCall)
Пример #19
0
    def test_object_creation_and_expiry(self):
        """
        creates two temporary objects and verify that they expire with the expected sequence
        reproduced the test pattern of twisted/test/test_task.py: testCallLater
        """

        c = task.Clock() # deterministic clock

        objs_dict = {}
        obj = {}

        for x in range(1, 4):
            obj[x] = TempObj(objs_dict, uuid4(), x, c)
            self.failUnless(interfaces.IDelayedCall.providedBy(obj[x]._expireCall))
            self.assertEqual(len(obj), x)

        y = len(obj)

        for x in range(1, 4):
            c.advance(1)
            self.assertEqual(len(objs_dict), y - x)