-
Notifications
You must be signed in to change notification settings - Fork 594
/
RwsSet.py
62 lines (58 loc) · 2.5 KB
/
RwsSet.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
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
class RwsSet:
"""Stores the data of a Related Website Set
Attributes:
primary: A string of the primary domain for a related website set
associated_sites: a list containing domains associated with the
RWS' primary domain
service_sites: a list containing necessary service sites for the
primary domain and/or service sites and ccTLD sites.
ccTLDs: a list of domains that are country code variants of other
members of the related website set.
relevant_fields_dict: a dictionary mapping the JSON field equivalents
of each field to their value within the object.
"""
def __init__(self, ccTLDs, primary, associated_sites=[], service_sites=[]):
self.ccTLDs = {} if ccTLDs is None else ccTLDs
self.primary = "" if primary is None else primary
self.associated_sites = [] if associated_sites is None else associated_sites
self.service_sites = [] if service_sites is None else service_sites
self.relevant_fields_dict = {
"ccTLDs": self.ccTLDs,
"primary": self.primary,
"associatedSites": self.associated_sites,
"serviceSites": self.service_sites,
}
def __eq__(self, obj):
if isinstance(obj, RwsSet) and self.primary == obj.primary:
if self.ccTLDs == obj.ccTLDs:
if self.associated_sites == obj.associated_sites:
if self.service_sites == obj.service_sites:
return True
return False
def includes(self, domain, with_ccTLDs=True):
if (
self.primary == domain
or domain in (self.associated_sites or [])
or domain in (self.service_sites or [])
):
return True
if with_ccTLDs:
return domain in (
variant
for variant_list in self.ccTLDs.values()
for variant in variant_list
)
return False