Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sherlock-project
GitHub Repository: sherlock-project/sherlock
Path: blob/master/sherlock_project/result.py
761 views
1
"""Sherlock Result Module
2
3
This module defines various objects for recording the results of queries.
4
"""
5
from enum import Enum
6
7
8
class QueryStatus(Enum):
9
"""Query Status Enumeration.
10
11
Describes status of query about a given username.
12
"""
13
CLAIMED = "Claimed" # Username Detected
14
AVAILABLE = "Available" # Username Not Detected
15
UNKNOWN = "Unknown" # Error Occurred While Trying To Detect Username
16
ILLEGAL = "Illegal" # Username Not Allowable For This Site
17
WAF = "WAF" # Request blocked by WAF (i.e. Cloudflare)
18
19
def __str__(self):
20
"""Convert Object To String.
21
22
Keyword Arguments:
23
self -- This object.
24
25
Return Value:
26
Nicely formatted string to get information about this object.
27
"""
28
return self.value
29
30
class QueryResult():
31
"""Query Result Object.
32
33
Describes result of query about a given username.
34
"""
35
def __init__(self, username, site_name, site_url_user, status,
36
query_time=None, context=None):
37
"""Create Query Result Object.
38
39
Contains information about a specific method of detecting usernames on
40
a given type of web sites.
41
42
Keyword Arguments:
43
self -- This object.
44
username -- String indicating username that query result
45
was about.
46
site_name -- String which identifies site.
47
site_url_user -- String containing URL for username on site.
48
NOTE: The site may or may not exist: this
49
just indicates what the name would
50
be, if it existed.
51
status -- Enumeration of type QueryStatus() indicating
52
the status of the query.
53
query_time -- Time (in seconds) required to perform query.
54
Default of None.
55
context -- String indicating any additional context
56
about the query. For example, if there was
57
an error, this might indicate the type of
58
error that occurred.
59
Default of None.
60
61
Return Value:
62
Nothing.
63
"""
64
65
self.username = username
66
self.site_name = site_name
67
self.site_url_user = site_url_user
68
self.status = status
69
self.query_time = query_time
70
self.context = context
71
72
return
73
74
def __str__(self):
75
"""Convert Object To String.
76
77
Keyword Arguments:
78
self -- This object.
79
80
Return Value:
81
Nicely formatted string to get information about this object.
82
"""
83
status = str(self.status)
84
if self.context is not None:
85
# There is extra context information available about the results.
86
# Append it to the normal response text.
87
status += f" ({self.context})"
88
89
return status
90
91