Create a workbook session object. :param parent: parent for this operation :param Connection con: connection to use if no parent specified :param Bool persist: Whether or not to persist the session changes
(self, *, parent=None, con=None, persist=True, **kwargs)
| 43 | } |
| 44 | |
| 45 | def __init__(self, *, parent=None, con=None, persist=True, **kwargs): |
| 46 | """ Create a workbook session object. |
| 47 | |
| 48 | :param parent: parent for this operation |
| 49 | :param Connection con: connection to use if no parent specified |
| 50 | :param Bool persist: Whether or not to persist the session changes |
| 51 | """ |
| 52 | if parent and con: |
| 53 | raise ValueError('Need a parent or a connection but not both') |
| 54 | self.con = parent.con if parent else con |
| 55 | |
| 56 | # Choose the main_resource passed in kwargs over parent main_resource |
| 57 | main_resource = kwargs.pop('main_resource', None) or ( |
| 58 | getattr(parent, 'main_resource', None) if parent else None) |
| 59 | |
| 60 | super().__init__( |
| 61 | protocol=parent.protocol if parent else kwargs.get('protocol'), |
| 62 | main_resource=main_resource) |
| 63 | |
| 64 | self.persist = persist |
| 65 | |
| 66 | self.inactivity_limit = dt.timedelta(seconds=PERSISTENT_SESSION_INACTIVITY_MAX_AGE) \ |
| 67 | if persist else dt.timedelta(seconds=NON_PERSISTENT_SESSION_INACTIVITY_MAX_AGE) |
| 68 | self.session_id = None |
| 69 | self.last_activity = dt.datetime.now() |
| 70 | |
| 71 | def __str__(self): |
| 72 | return self.__repr__() |