1 """This module provides access to user's settings on Diaspora*.
9 from diaspy
import errors
13 """This object is used to get access to user's settings on
14 Diaspora* and provides interface for downloading user's stuff.
16 def __init__(self
, connection
):
17 self
._connection
= connection
19 def downloadxml(self
):
20 request
= self
._connection
.get('user/export')
23 def setEmail(self
, email
):
24 """Changes user's email.
26 data
= {'_method': 'put', 'utf-8': '✓', 'user[email]': email
, 'authenticity_token': repr(self
._connection
)}
27 request
= self
._connection
.post('user')
30 """Returns currently used email.
32 data
= self
._connection
.get('user/edit')
33 email
= re
.compile('<input id="user_email" name="user\[email\]" size="30" type="text" value=".+?"').search(data
.text
)
34 if email
is None: raise errors
.DiaspyError('cannot fetch email')
35 email
= email
.group(0)[:-1]
36 email
= email
[email
.rfind('"')+1:]
39 def setLanguage(self
, lang
):
40 """Changes user's email.
42 :param lang: language identifier from getLanguages()
44 data
= {'_method': 'put', 'utf-8': '✓', 'user[language]': lang
, 'authenticity_token': repr(self
._connection
)}
45 request
= self
._connection
.post('user', data
=data
)
47 def getLanguages(self
):
48 """Returns a list of tuples containing ('Language name', 'identifier').
49 One of the Black Magic(tm) methods.
51 select_start
= '<select id="user_language" name="user[language]">'
52 select_end
= '</select>'
54 request
= self
._connection
.get('user/edit')
55 data
= request
.text
[request
.text
.find(select_start
)+len(select_start
):]
56 data
= data
[:data
.find(select_end
)].split('\n')
58 name
= item
[item
.find('>')+1:item
.rfind('<')]
59 identifier
= item
[item
.find('"')+1:]
60 identifier
= identifier
[:identifier
.find('"')]
61 languages
.append((name
, identifier
))