Skip to content

Commit 6e2b13a

Browse files
author
Matias Melograno
committed
Merge branch 'task/deprecatePython2' of github.com:splitio/python-client into task/removingp2
2 parents 2a385d2 + 3052e6a commit 6e2b13a

File tree

7 files changed

+85
-0
lines changed

7 files changed

+85
-0
lines changed

splitio/models/grammar/condition.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ def get_segment_names(self):
8585
if isinstance(matcher, matchers.UserDefinedSegmentMatcher)
8686
]
8787

88+
def __str__(self):
89+
"""Return the string representation of the condition."""
90+
return '{matcher} then split {parts}'.format(
91+
matcher=self._matchers, parts=','.join(
92+
'{size}:{treatment}'.format(size=partition.size,
93+
treatment=partition.treatment)
94+
for partition in self._partitions))
95+
8896
def to_json(self):
8997
"""Return the JSON representation of this condition."""
9098
return {

splitio/models/grammar/matchers/keys.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ def _match(self, key, attributes=None, context=None):
3030
"""
3131
return key is not None
3232

33+
def __str__(self):
34+
"""Return string Representation."""
35+
return 'in segment all'
36+
3337
def _add_matcher_specific_properties_to_json(self):
3438
"""Add matcher specific properties to base dict before returning it."""
3539
return {}
@@ -77,3 +81,9 @@ def _add_matcher_specific_properties_to_json(self):
7781
'segmentName': self._segment_name
7882
}
7983
}
84+
85+
def __str__(self):
86+
"""Return string Representation."""
87+
return 'in segment {segment_name}'.format(
88+
segment_name=self._segment_name
89+
)

splitio/models/grammar/matchers/numeric.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ def _match(self, key, attributes=None, context=None):
108108
return False
109109
return self._lower <= self.input_parsers[self._data_type](matching_data) <= self._upper
110110

111+
def __str__(self):
112+
"""Return string Representation."""
113+
return 'between {start} and {end}'.format(start=self._lower, end=self._upper)
114+
111115
def _add_matcher_specific_properties_to_json(self):
112116
"""Return BetweenMatcher specific properties."""
113117
return {

splitio/models/grammar/matchers/sets.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ def _add_matcher_specific_properties_to_json(self):
4545
}
4646
}
4747

48+
def __str__(self):
49+
"""Return string Representation."""
50+
return 'contains all of the following set: [{whitelist}]'.format(
51+
whitelist=','.join('"{}"'.format(item) for item in self._whitelist)
52+
)
53+
4854

4955
class ContainsAnyOfSetMatcher(Matcher):
5056
"""Matcher that returns true if the intersection of both sets is not empty."""
@@ -88,6 +94,12 @@ def _add_matcher_specific_properties_to_json(self):
8894
}
8995
}
9096

97+
def __str__(self):
98+
"""Return string Representation."""
99+
return 'contains on of the following se: [{whitelist}]'.format(
100+
whitelist=','.join('"{}"'.format(item) for item in self._whitelist)
101+
)
102+
91103

92104
class EqualToSetMatcher(Matcher):
93105
"""Matcher that returns true if the set provided by the user is equal to the matcher's one."""
@@ -131,6 +143,12 @@ def _add_matcher_specific_properties_to_json(self):
131143
}
132144
}
133145

146+
def __str__(self):
147+
"""Return string Representation."""
148+
return 'equals the following set: [{whitelist}]'.format(
149+
whitelist=','.join('"{}"'.format(item) for item in self._whitelist)
150+
)
151+
134152

135153
class PartOfSetMatcher(Matcher):
136154
"""a."""
@@ -174,3 +192,9 @@ def _add_matcher_specific_properties_to_json(self):
174192
'whitelist': list(self._whitelist)
175193
}
176194
}
195+
196+
def __str__(self):
197+
"""Return string Representation."""
198+
return 'is a subset of the following set: [{whitelist}]'.format(
199+
whitelist=','.join('"{}"'.format(item) for item in self._whitelist)
200+
)

splitio/models/grammar/matchers/string.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ def _add_matcher_specific_properties_to_json(self):
7878
}
7979
}
8080

81+
def __str__(self):
82+
"""Return string Representation."""
83+
return 'in whitelist [{whitelist}]'.format(
84+
whitelist=','.join('"{}"'.format(item) for item in self._whitelist)
85+
)
86+
8187

8288
class StartsWithMatcher(Matcher):
8389
"""Matcher that returns true if the key is a prefix of the stored value."""
@@ -119,6 +125,12 @@ def _add_matcher_specific_properties_to_json(self):
119125
}
120126
}
121127

128+
def __str__(self):
129+
"""Return string Representation."""
130+
return 'has one of the following prefixes [{whitelist}]'.format(
131+
whitelist=','.join('"{}"'.format(item) for item in self._whitelist)
132+
)
133+
122134

123135
class EndsWithMatcher(Matcher):
124136
"""Matcher that returns true if the key ends with the suffix stored in matcher data."""
@@ -160,6 +172,12 @@ def _add_matcher_specific_properties_to_json(self):
160172
}
161173
}
162174

175+
def __str__(self):
176+
"""Return string Representation."""
177+
return 'has one of the following suffixes [{whitelist}]'.format(
178+
whitelist=','.join('"{}"'.format(item) for item in self._whitelist)
179+
)
180+
163181

164182
class ContainsStringMatcher(Matcher):
165183
"""Matcher that returns true if the input key is part of the string in matcher data."""
@@ -201,6 +219,12 @@ def _add_matcher_specific_properties_to_json(self):
201219
}
202220
}
203221

222+
def __str__(self):
223+
"""Return string Representation."""
224+
return 'contains one of the following string: [{whitelist}]'.format(
225+
whitelist=','.join('"{}"'.format(item) for item in self._whitelist)
226+
)
227+
204228

205229
class RegexMatcher(Matcher):
206230
"""Matcher that returns true if the user input matches the regex stored in the matcher."""

splitio/models/grammar/partitions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ def to_json(self):
3636
'size': self._size
3737
}
3838

39+
def __str__(self):
40+
"""Return string representation of a partition."""
41+
return '{size}%:{treatment}'.format(size=self._size,
42+
treatment=self._treatment)
43+
3944

4045
def from_raw(raw_partition):
4146
"""

splitio/models/splits.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,16 @@ def local_kill(self, default_treatment, change_number):
205205
self._change_number = change_number
206206
self._killed = True
207207

208+
def __str__(self):
209+
"""Return string representation."""
210+
return 'name: {name}, seed: {seed}, killed: {killed}, ' \
211+
'default treatment: {default_treatment}, ' \
212+
'conditions: {conditions}'.format(
213+
name=self._name, seed=self._seed, killed=self._killed,
214+
default_treatment=self._default_treatment,
215+
conditions=','.join(map(str, self._conditions))
216+
)
217+
208218

209219
def from_raw(raw_split):
210220
"""

0 commit comments

Comments
 (0)