-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidentification.py
68 lines (47 loc) · 1.57 KB
/
identification.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
63
64
65
66
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Raúl Piracés Alastuey
"""
Class that provides an object and methods for identifying log entries and compare each one.
Considers IP address, timestamp of petition, user,
"""
class Identification(object):
def __init__(self, ip, timestamp, user, status, case):
self.ip = ip
self.timestamp = timestamp
self.user = user
self.status = status
# Session (initially) is a simple hash of the object
self.session = self.get_hash()
self.case = case
# Getters and setters of attributes
def set_ip(self, ip):
self.ip = ip
def get_ip(self):
return self.ip
def set_timestamp(self, timestamp):
self.timestamp = timestamp
def get_timestamp(self):
return self.timestamp
def set_user(self, user):
self.user = user
def get_user(self):
return self.user
def set_status(self, status):
self.status = status
def get_status(self):
return self.status
def set_session(self):
self.session = id(self)
def get_session(self):
return self.session
def set_custom_session(self, session):
self.session = session
def set_case(self, case):
self.case = case
def get_case(self):
return self.case
# Provides an "unique" hash for this object (considering user, IP and timestamp)
def get_hash(self):
# Consider using abs() function, but it increases the probability of collision
return hash(self.user + self.ip + self.timestamp)