Пример #1
0
    def test_uuid_convert(self):
        with self.assertRaises(ValidationError):
            fields.UUID().convert(123456)

        with self.assertRaises(ValidationError):
            fields.UUID().convert("123456")

        with self.assertRaises(ValidationError):
            fields.UUID().convert("abcdefghijklmnopqrstuvwxyz")

        uuid = str(uuid4())
        self.assertEqual(uuid, fields.UUID().convert(uuid))
Пример #2
0
 def test_uuid_schema(self):
     self.assertEqual({
                         "type": "string",
                         "pattern": "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
                         "minLength": 36,
                         "maxLength": 36
                      }, fields.UUID().response)
Пример #3
0
 def session_log(self, session_uuid: fields.UUID()) -> fields.String():
     session = Session.query.filter(Session.uuid == session_uuid).first()
     session_log_path = path.session_logs + session.start.date().isoformat().replace('-', '') + '/' + \
         session.user.username + '_' + session.host.hostname + '_' + \
         session.start.time().isoformat().split('.')[0].replace(':', '') + '_' + \
         session_uuid + '.log'
     with open(session_log_path, 'rb') as session_log:
         return base64.b64encode(session_log.read()).decode(
             'utf-8', 'strict')
Пример #4
0
 class Schema:
     uuid = fields.UUID()
     user = fields.Inline('user')
     host = fields.Inline('host')
     start = fields.DateTimeString()
     end = fields.DateTimeString()
     duration = fields.Custom('{"type": "integer"}',
                              io="r",
                              formatter=lambda x: x.total_seconds())
Пример #5
0
 def session_timed_log(
     self, session_uuid: fields.UUID()) -> fields.List(fields.String()):
     session = Session.query.filter(Session.uuid == session_uuid).first()
     session_base_path = path.session_logs + session.start.date().isoformat().replace('-', '') + '/' + \
         session.user.username + '_' + session.host.hostname + '_' + \
         session.start.time().isoformat().split('.')[0].replace(':', '') + '_' + \
         session_uuid
     session_log_path = session_base_path + '.log'
     session_timer_path = session_base_path + '.timer'
     results = []
     session_time = 0.
     session_seek = 0
     with open(session_log_path, 'rb') as session_log:
         with open(session_timer_path, 'r') as session_timer:
             session_data = session_log.read()
             # todo improve this (use csv reader?)
             lines = session_timer.readlines()
             for l in lines:
                 rel_time, rel_seek = l.split(' ')
                 rel_time = float(rel_time)
                 rel_seek = int(rel_seek)
                 session_time += rel_time
                 current_seek = session_seek
                 session_seek += rel_seek
                 results.append({
                     'session_time':
                     session_time,
                     'session_seek':
                     session_seek,
                     'session_size':
                     len(session_data),
                     'data_size':
                     rel_seek,
                     'data':
                     base64.b64encode(
                         session_data[current_seek:session_seek]).decode(
                             'utf-8', 'strict')
                 })
     return results
Пример #6
0
 def uuid(self, project) -> fields.UUID():
     return project.uuid