Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _calculate_addresses(self, label):
""" update values from label """
self.worksheet_title = label.split('!')[0]
self._start, self._end = Address(None, True), Address(None, True)
if len(label.split('!')) > 1:
rem = label.split('!')[1]
if ":" in rem:
self._start = Address(rem.split(":")[0], allow_non_single=True)
self._end = Address(rem.split(":")[1], allow_non_single=True)
else:
self._start = Address(rem, allow_non_single=True)
self._apply_index_constraints()
def _calculate_addresses(self, label):
""" update values from label """
self.worksheet_title = label.split('!')[0]
self._start, self._end = Address(None, True), Address(None, True)
if len(label.split('!')) > 1:
rem = label.split('!')[1]
if ":" in rem:
self._start = Address(rem.split(":")[0], allow_non_single=True)
self._end = Address(rem.split(":")[1], allow_non_single=True)
else:
self._start = Address(rem, allow_non_single=True)
self._apply_index_constraints()
def __add__(self, other):
if type(other) is tuple or isinstance(other, Address):
return Address((self._value[0] + other[0], self._value[1] + other[1]))
else:
raise NotImplementedError
def get_bounded_indexes(self):
""" get bounded indexes of this range based on worksheet size, if the indexes are unbounded """
start_r, start_c = tuple(iter(self.start)) if self.start else (None, None)
end_r, end_c = tuple(iter(self.end)) if self.end else (None, None)
start_r = start_r if start_r else 1
start_c = start_c if start_c else 1
if not self._worksheet and not (end_r or end_c):
raise InvalidArgumentValue('Worksheet not set for calculating size.')
end_r = end_r if end_r else self._worksheet.rows
end_c = end_c if end_c else self._worksheet.cols
return Address((start_r, start_c)), Address((end_r, end_c))
:param namedjson: json object of the GridRange format
Reference: `GridRange docs `__
"""
if 'sheetId' in namedjson:
self.worksheet_id = namedjson['sheetId']
start_row_idx = namedjson.get('startRowIndex', None)
end_row_idx = namedjson.get('endRowIndex', None)
start_col_idx = namedjson.get('startColumnIndex', None)
end_col_idx = namedjson.get('endColumnIndex', None)
start_row_idx = start_row_idx + 1 if start_row_idx is not None else start_row_idx
start_col_idx = start_col_idx + 1 if start_col_idx is not None else start_col_idx
self._start = Address((start_row_idx, start_col_idx), True)
self._end = Address((end_row_idx, end_col_idx), True)
self._calculate_label()
# if not self._start:
# self._end = self._start
# return
# if not self._end:
# self._start = self._end
# return
# # if range is not single celled, and one index is unbounded make it single celled
# if not self._end:
# self._end = self._start
# if not self._start:
# self._start = self._end
# Check if unbound on different axes
if ((self._start[0] and not self._start[1]) and (not self._end[0] and self._end[1])) or \
(not self._start[0] and self._start[1]) and (self._end[0] and not self._end[1]):
self._start, self._end = Address(None, True), Address(None, True)
raise InvalidArgumentValue('Invalid indexes set. Indexes should be unbounded at same axes.')
# If one axes is unbounded on an index, make other index also unbounded on same axes
if self._start[0] is None or self._end[0] is None:
self._start[0], self._end[0] = None, None
elif self._start[1] is None or self._end[1] is None:
self._start[1], self._end[1] = None, None
# verify
# if (self._start[0] and not self._end[0]) or (not self._start[0] and self._end[0]) or \
# (self._start[1] and not self._end[1]) or (not self._start[1] and self._end[1]):
# self._start, self._end = Address(None, True), Address(None, True)
# raise InvalidArgumentValue('Invalid start and end set for this range')
if self._start and self._end:
if self._start[0]:
def __eq__(self, other):
if isinstance(other, Address):
return self.label == other.label
elif type(other) is str:
return self.label == other
elif type(other) is tuple or type(other) is list:
return self._value == tuple(other)
else:
return super(Address, self).__eq__(other)