Skip to content

Commit d75ce17

Browse files
author
Alejandro Casanovas
committed
BUG: Respect the main resource when creating a directory from account.address_book
Changed Readme to update examples to the last changes of the api (googleapis#365).
1 parent 0374128 commit d75ce17

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

O365/account.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def address_book(self, *, resource=None, address_book='personal'):
168168
# for backwards compatibility only
169169
from .directory import Directory
170170

171-
return Directory(parent=self)
171+
return Directory(parent=self, main_resource=resource)
172172
else:
173173
raise RuntimeError(
174174
'address_book must be either "Personal" '

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -821,20 +821,23 @@ You can search by name or retrieve a contact specifying the complete email.
821821
To search the Global Address List (Users API):
822822

823823
```python
824-
global_address_list = account.address_book(address_book='gal')
824+
global_address_list = account.directory()
825+
826+
# for backwards compatibilty only this also works and returns a Directory object:
827+
# global_address_list = account.address_book(address_book='gal')
825828

826829
# start a new query:
827830
q = global_address_list.new_query('display_name')
828831
q.startswith('George Best')
829832

830-
print(global_address_list.get_contacts(query=q))
833+
print(global_address_list.get_users(query=q))
831834
```
832835

833836

834837
To retrieve a contact by their email:
835838

836839
```python
837-
contact = global_address_list.get_contact_by_email('[email protected]')
840+
contact = global_address_list.get_user('[email protected]')
838841
```
839842

840843
#### Contacts

examples/token_backends.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def save_token(self):
9999

100100
return True
101101

102+
102103
class LockableFileSystemTokenBackend(FileSystemTokenBackend):
103104
"""
104105
GH #350
@@ -108,12 +109,13 @@ class LockableFileSystemTokenBackend(FileSystemTokenBackend):
108109
method in the Portalocker package's Lock class, which itself is a wrapper
109110
around Python's fcntl and win32con.
110111
"""
112+
111113
def __init__(self, *args, **kwargs):
112114
self.max_tries = kwargs.pop('max_tries')
113115
self.fs_wait = False
114116
super().__init__(*args, **kwargs)
115117

116-
def should_refresh_token(self, con):
118+
def should_refresh_token(self, con=None):
117119
"""
118120
Method for refreshing the token when there are concurrently running
119121
O365 instances. Determines if we need to call the MS server and refresh
@@ -148,11 +150,11 @@ def should_refresh_token(self, con):
148150
if self.token.is_access_expired:
149151
try:
150152
with Lock(self.token_path, 'r+',
151-
fail_when_locked=True, timeout=0):
153+
fail_when_locked=True, timeout=0):
152154
log.debug('Locked oauth token file')
153155
if con.refresh_token() is False:
154156
raise RuntimeError('Token Refresh Operation not '
155-
'working')
157+
'working')
156158
log.info('New oauth token fetched')
157159
log.debug('Unlocked oauth token file')
158160
return None
@@ -162,7 +164,7 @@ def should_refresh_token(self, con):
162164
f'retrying {_ - 1} more times.')
163165
time.sleep(2)
164166
log.debug('Waking up and rechecking token file for update'
165-
' from other instance...')
167+
' from other instance...')
166168
self.token = self.load_token()
167169
else:
168170
log.info('Token was refreshed by another instance...')

0 commit comments

Comments
 (0)