PEP-8 style fixes; removing missing imports; fixing ValueError when raising PyiCloudNoDevicesException

This commit is contained in:
Adam Coddington 2013-10-11 18:33:07 -07:00
parent 565146ac3d
commit 3d87dac040
3 changed files with 31 additions and 16 deletions

View file

@ -1,4 +1,3 @@
import time
import uuid import uuid
import hashlib import hashlib
import json import json
@ -115,7 +114,11 @@ class PyiCloudService(object):
def files(self): def files(self):
if not hasattr(self, '_files'): if not hasattr(self, '_files'):
service_root = self.webservices['ubiquity']['url'] service_root = self.webservices['ubiquity']['url']
self._files = UbiquityService(service_root, self.session, self.params) self._files = UbiquityService(
service_root,
self.session,
self.params
)
return self._files return self._files
@property @property

View file

@ -54,7 +54,7 @@ class FindMyiPhoneServiceManager(object):
self._devices[device_id].update(device_info) self._devices[device_id].update(device_info)
if not self._devices: if not self._devices:
raise PyiCloudNoDevicesException(message) raise PyiCloudNoDevicesException()
def __getitem__(self, key): def __getitem__(self, key):
if isinstance(key, int): if isinstance(key, int):
@ -79,8 +79,10 @@ class FindMyiPhoneServiceManager(object):
class AppleDevice(object): class AppleDevice(object):
def __init__(self, content, session, params, manager, def __init__(
sound_url=None, lost_url=None, message_url=None): self, content, session, params, manager,
sound_url=None, lost_url=None, message_url=None
):
self.content = content self.content = content
self.manager = manager self.manager = manager
self.session = session self.session = session
@ -122,26 +124,34 @@ class AppleDevice(object):
data=data data=data
) )
def display_message (self, subject='Find My iPhone Alert', message="This is a note", sounds=False): def display_message(
self, subject='Find My iPhone Alert', message="This is a note",
sounds=False
):
""" Send a request to the device to play a sound. """ Send a request to the device to play a sound.
It's possible to pass a custom message by changing the `subject`. It's possible to pass a custom message by changing the `subject`.
""" """
data = json.dumps({'device': self.content['id'], data = json.dumps(
'subject': subject, {
'sound':sounds, 'device': self.content['id'],
'userText':True, 'subject': subject,
'text':message 'sound': sounds,
}) 'userText': True,
'text': message
}
)
self.session.post( self.session.post(
self.message_url, self.message_url,
params=self.params, params=self.params,
data=data data=data
) )
def lost_device(self, number, def lost_device(
text='This iPhone has been lost. Please call me.', self, number,
newpasscode=""): text='This iPhone has been lost. Please call me.',
newpasscode=""
):
""" Send a request to the device to trigger 'lost mode'. """ Send a request to the device to trigger 'lost mode'.
The device will show the message in `text`, and if a number has The device will show the message in `text`, and if a number has

View file

@ -97,7 +97,9 @@ class UbiquityNode(object):
return self.connection.get_file(self.item_id, **kwargs) return self.connection.get_file(self.item_id, **kwargs)
def get(self, name): def get(self, name):
return [child for child in self.get_children() if child.name == name][0] return [
child for child in self.get_children() if child.name == name
][0]
def __getitem__(self, key): def __getitem__(self, key):
try: try: