/usr/lib/python2.7/dist-packages/braintree/search.py is in python-braintree 3.4.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | class Search:
class IsNodeBuilder(object):
def __init__(self, name):
self.name = name
def __eq__(self, value):
return self.is_equal(value)
def is_equal(self, value):
return Search.Node(self.name, {"is": value})
class EqualityNodeBuilder(IsNodeBuilder):
def __ne__(self, value):
return self.is_not_equal(value)
def is_not_equal(self, value):
return Search.Node(self.name, {"is_not": value})
class KeyValueNodeBuilder(object):
def __init__(self, name):
self.name = name
def __eq__(self, value):
return self.is_equal(value)
def is_equal(self, value):
return Search.Node(self.name, value)
def __ne__(self, value):
return self.is_not_equal(value)
def is_not_equal(self, value):
return Search.Node(self.name, not value)
class PartialMatchNodeBuilder(EqualityNodeBuilder):
def starts_with(self, value):
return Search.Node(self.name, {"starts_with": value})
def ends_with(self, value):
return Search.Node(self.name, {"ends_with": value})
class TextNodeBuilder(PartialMatchNodeBuilder):
def contains(self, value):
return Search.Node(self.name, {"contains": value})
class Node(object):
def __init__(self, name, dict):
self.name = name
self.dict = dict
def to_param(self):
return self.dict
class MultipleValueNodeBuilder(object):
def __init__(self, name, whitelist = []):
self.name = name
self.whitelist = whitelist
def in_list(self, *values):
if isinstance(values[0], list):
values = values[0]
invalid_args = set(values) - set(self.whitelist)
if len(self.whitelist) > 0 and len(invalid_args) > 0:
error_string = "Invalid argument(s) for %s: %s" % (self.name, ", ".join(invalid_args))
raise AttributeError(error_string)
return Search.Node(self.name, list(values))
def __eq__(self, value):
return self.in_list([value])
class MultipleValueOrTextNodeBuilder(TextNodeBuilder, MultipleValueNodeBuilder):
def __init__(self, name, whitelist = []):
Search.MultipleValueNodeBuilder.__init__(self, name, whitelist)
class RangeNodeBuilder(object):
def __init__(self, name):
self.name = name
def __eq__(self, value):
return self.is_equal(value)
def is_equal(self, value):
return Search.EqualityNodeBuilder(self.name) == value
def __ge__(self, min):
return self.greater_than_or_equal_to(min)
def greater_than_or_equal_to(self, min):
return Search.Node(self.name, {"min": min})
def __le__(self, max):
return self.less_than_or_equal_to(max)
def less_than_or_equal_to(self, max):
return Search.Node(self.name, {"max": max})
def between(self, min, max):
return Search.Node(self.name, {"min": min, "max": max})
|