Minor alterations to AccountService.
This commit is contained in:
parent
adb14d1468
commit
2b004a2a55
2 changed files with 36 additions and 12 deletions
|
@ -1,5 +1,9 @@
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
|
from pyicloud.utils import underscore_to_camelcase
|
||||||
|
|
||||||
|
|
||||||
class AccountService(object):
|
class AccountService(object):
|
||||||
def __init__(self, service_root, session, params):
|
def __init__(self, service_root, session, params):
|
||||||
|
@ -24,16 +28,28 @@ class AccountService(object):
|
||||||
return self._devices
|
return self._devices
|
||||||
|
|
||||||
|
|
||||||
class AccountDevice(object):
|
@six.python_2_unicode_compatible
|
||||||
|
class AccountDevice(dict):
|
||||||
def __init__(self, device_info):
|
def __init__(self, device_info):
|
||||||
self.serialNumber = device_info['serialNumber']
|
super(AccountDevice, self).__init__(device_info)
|
||||||
self.osVersion = device_info['osVersion']
|
|
||||||
self.modelLargePhotoURL2x = device_info['modelLargePhotoURL2x']
|
def __getattr__(self, name):
|
||||||
self.modelLargePhotoURL1x = device_info['modelLargePhotoURL1x']
|
try:
|
||||||
self.name = device_info['name']
|
return self[underscore_to_camelcase(name)]
|
||||||
self.imei = device_info['imei']
|
except KeyError:
|
||||||
self.model = device_info['model']
|
raise AttributeError(name)
|
||||||
self.udid = device_info['udid']
|
|
||||||
self.modelSmallPhotoURL2x = device_info['modelSmallPhotoURL2x']
|
def __str__(self):
|
||||||
self.modelSmallPhotoURL1x = device_info['modelSmallPhotoURL1x']
|
return u"{display_name}: {name}".format(
|
||||||
self.modelDisplayName = device_info['modelDisplayName']
|
display_name=self.model_display_name,
|
||||||
|
name=self.name,
|
||||||
|
)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return '<{display}>'.format(
|
||||||
|
display=(
|
||||||
|
six.text_type(self)
|
||||||
|
if sys.version_info[0] >= 3 else
|
||||||
|
six.text_type(self).encode('utf8', 'replace')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
|
@ -62,3 +62,11 @@ def delete_password_in_keyring(username):
|
||||||
KEYRING_SYSTEM,
|
KEYRING_SYSTEM,
|
||||||
username,
|
username,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def underscore_to_camelcase(word, initial_capital=False):
|
||||||
|
words = [x.capitalize() or '_' for x in word.split('_')]
|
||||||
|
if not initial_capital:
|
||||||
|
words[0] = words[0].lower()
|
||||||
|
|
||||||
|
return ''.join(words)
|
||||||
|
|
Loading…
Reference in a new issue