Skip to content

Commit

Permalink
Is it 2020 yet? adding py2 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
mvanderlee committed Nov 28, 2019
1 parent 6ae0834 commit 0e6b1b0
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions pysnow/criterion.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def __init__(self, term):

def get_query(self, **kwargs):
term = self.term.get_query(**kwargs)
return f'{term}ISEMPTY'
return '{}ISEMPTY'.format(term)


class NotEmptyCriterion(Criterion):
Expand All @@ -256,7 +256,7 @@ def __init__(self, term):

def get_query(self, **kwargs):
term = self.term.get_query(**kwargs)
return f'{term}ISNOTEMPTY'
return '{}ISNOTEMPTY'.format(term)


class IsAnythingCriterion(Criterion):
Expand All @@ -266,7 +266,7 @@ def __init__(self, term):

def get_query(self, **kwargs):
term = self.term.get_query(**kwargs)
return f'{term}ANYTHING'
return '{}ANYTHING'.format(term)


class IsEmptyStringCriterion(Criterion):
Expand All @@ -276,7 +276,7 @@ def __init__(self, term):

def get_query(self, **kwargs):
term = self.term.get_query(**kwargs)
return f'{term}EMPTYSTRING'
return '{}EMPTYSTRING'.format(term)


class BetweenCriterion(Criterion):
Expand All @@ -300,8 +300,8 @@ def get_query(self, **kwargs):
"Expected both `start` and `end` of type `int` "
"or instance of `datetime`, not %s and %s" % (type(start), type(end))
)

return f'{term}BETWEEN{dt_between}'
return '{}BETWEEN{}'.format(term, dt_between)


class DateTimeOnCriterion(Criterion):
Expand All @@ -313,12 +313,16 @@ def __init__(self, term, criteria):
def get_query(self, **kwargs):
term = self.term.get_query(**kwargs)
if isinstance(self.criteria, DateTimeOn):
criteria = self.criteria.value
return f'{term}ON{criteria}'
return '{term}ON{criteria}'.format(
term=term,
criteria=self.criteria.value
)
else:
start = self.criteria.get_query(date_only=True, extra_param='start')
end = self.criteria.get_query(date_only=True, extra_param='end')
return f'{term}ONcustom@{start}@{end}'
return '{term}ONcustom@{start}@{end}'.format(
term=term,
start=self.criteria.get_query(date_only=True, extra_param='start'),
end=self.criteria.get_query(date_only=True, extra_param='end')
)


class DateTimeNotOnCriterion(Criterion):
Expand All @@ -330,12 +334,16 @@ def __init__(self, term, criteria):
def get_query(self, **kwargs):
term = self.term.get_query(**kwargs)
if isinstance(self.criteria, DateTimeOn):
criteria = self.criteria.value
return f'{term}NOTON{criteria}'
return '{term}NOTON{criteria}'.format(
term=term,
criteria=self.criteria.value
)
else:
start = self.criteria.get_query(date_only=True, extra_param='start')
end = self.criteria.get_query(date_only=True, extra_param='end')
return f'{term}NOTONcustom@{start}@{end}'
return '{term}NOTONcustom@{start}@{end}'.format(
term=term,
start=self.criteria.get_query(date_only=True, extra_param='start'),
end=self.criteria.get_query(date_only=True, extra_param='end')
)


class OrderCriterion(Criterion):
Expand All @@ -347,9 +355,9 @@ def __init__(self, term, direction):
def get_query(self, **kwargs):
term = self.term.get_query(**kwargs)
if self.direction == Order.asc or (isinstance(self.direction, six.string_types) and self.direction.lower() == 'asc'):
return f'ORDERBY{term}'
return 'ORDERBY{term}'.format(term=term)
elif self.direction == Order.desc or (isinstance(self.direction, six.string_types) and self.direction.lower() == 'desc'):
return f'ORDERBYDESC{term}'
return 'ORDERBYDESC{term}'.format(term=term)
else:
raise QueryTypeError(
"Expected 'asc', 'desc', or an instance of Order, not %s"
Expand Down Expand Up @@ -406,9 +414,9 @@ def get_query(self, date_only=False, extra_param=None, **kwargs):
value = datetime_.strftime("%Y-%m-%d %H:%M:%S")

if extra_param:
value += f'", "{extra_param}'
value += '", "{}'.format(extra_param)

return f'javascript:gs.dateGenerate("{value}")'
return 'javascript:gs.dateGenerate("{}")'.format(value)
else:
raise QueryTypeError(
"Expected value to be an instance of `datetime`, not %s"
Expand Down

0 comments on commit 0e6b1b0

Please sign in to comment.