| 494 | range_format_constructor = RangeFormat |
| 495 | |
| 496 | def __init__(self, parent=None, session=None, **kwargs): |
| 497 | if parent and session: |
| 498 | raise ValueError('Need a parent or a session but not both') |
| 499 | |
| 500 | self.session = parent.session if parent else session |
| 501 | |
| 502 | cloud_data = kwargs.get(self._cloud_data_key, {}) |
| 503 | |
| 504 | self.object_id = cloud_data.get('address', None) |
| 505 | |
| 506 | # Choose the main_resource passed in kwargs over parent main_resource |
| 507 | main_resource = kwargs.pop('main_resource', None) or ( |
| 508 | getattr(parent, 'main_resource', None) if parent else None) |
| 509 | |
| 510 | # append the encoded range path |
| 511 | if isinstance(parent, Range): |
| 512 | # strip the main resource |
| 513 | main_resource = main_resource.split('/range')[0] |
| 514 | if isinstance(parent, (WorkSheet, Range)): |
| 515 | if '!' in self.object_id: |
| 516 | # remove the sheet string from the address as it's not needed |
| 517 | self.object_id = self.object_id.split('!')[1] |
| 518 | main_resource = "{}/range(address='{}')".format(main_resource, quote(self.object_id)) |
| 519 | else: |
| 520 | main_resource = '{}/range'.format(main_resource) |
| 521 | |
| 522 | super().__init__( |
| 523 | protocol=parent.protocol if parent else kwargs.get('protocol'), |
| 524 | main_resource=main_resource) |
| 525 | |
| 526 | self._track_changes = TrackerSet(casing=self._cc) |
| 527 | |
| 528 | self.address = cloud_data.get('address', '') |
| 529 | self.address_local = cloud_data.get('addressLocal', '') |
| 530 | self.column_count = cloud_data.get('columnCount', 0) |
| 531 | self.row_count = cloud_data.get('rowCount', 0) |
| 532 | self.cell_count = cloud_data.get('cellCount', 0) |
| 533 | self._column_hidden = cloud_data.get('columnHidden', False) |
| 534 | self.column_index = cloud_data.get('columnIndex', 0) # zero indexed |
| 535 | self._row_hidden = cloud_data.get('rowHidden', False) |
| 536 | self.row_index = cloud_data.get('rowIndex', 0) # zero indexed |
| 537 | self._formulas = cloud_data.get('formulas', [[]]) |
| 538 | self._formulas_local = cloud_data.get('formulasLocal', [[]]) |
| 539 | self._formulas_r1_c1 = cloud_data.get('formulasR1C1', [[]]) |
| 540 | self.hidden = cloud_data.get('hidden', False) |
| 541 | self._number_format = cloud_data.get('numberFormat', [[]]) |
| 542 | self.text = cloud_data.get('text', [[]]) |
| 543 | self.value_types = cloud_data.get('valueTypes', [[]]) |
| 544 | self._values = cloud_data.get('values', [[]]) |
| 545 | |
| 546 | def __str__(self): |
| 547 | return self.__repr__() |