GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#22)
by
unknown
01:05
created

Echo   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 6
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
c 1
b 0
f 0
dl 0
loc 6
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform_response() 0 2 1
1
# -*- coding: utf-8 -*-
2
from __future__ import unicode_literals
3
4
from .core.arguments import StringArgument
5
from .core.definitions import API
6
from .core.serializers import StringSerializer
7
from .muc import muc_room_options_serializers
8
from .muc.arguments import MUCRoomArgument, AffiliationArgument
9
from .muc.enums import MUCRoomOption
10
11
from .errors import UserAlreadyRegisteredError
12
from pyejabberd.muc.enums import Affiliation
13
from .utils import format_password_hash_sha
14
15
16
class Echo(API):
17
    method = 'echothisnew'
18
    arguments = [StringArgument('sentence')]
19
20
    def transform_response(self, api, arguments, response):
21
        return response.get('repeated')
22
23
24
class RegisteredUsers(API):
25
    method = 'registered_users'
26
    arguments = [StringArgument('host')]
27
28
    def transform_response(self, api, arguments, response):
29
        return response.get('users', [])
30
31
32
class Register(API):
33
    method = 'register'
34
    arguments = [StringArgument('user'), StringArgument('host'), StringArgument('password')]
35
36
    def validate_response(self, api, arguments, response):
37
        if response.get('res') == 1:
38
            username = arguments.get('user')
39
            raise UserAlreadyRegisteredError('User with username %s already exists' % username)
40
41
    def transform_response(self, api, arguments, response):
42
        return response.get('res') == 0
43
44
45
class UnRegister(API):
46
    method = 'unregister'
47
    arguments = [StringArgument('user'), StringArgument('host')]
48
49
    def transform_response(self, api, arguments, response):
50
        return response.get('res') == 0
51
52
53
class ChangePassword(API):
54
    method = 'change_password'
55
    arguments = [StringArgument('user'), StringArgument('host'), StringArgument('newpass')]
56
57
    def transform_response(self, api, arguments, response):
58
        return response.get('res') == 0
59
60
61
class CheckPasswordHash(API):
62
    method = 'check_password_hash'
63
    arguments = [StringArgument('user'), StringArgument('host'), StringArgument('passwordhash'),
64
                 StringArgument('hashmethod')]
65
66
    def transform_arguments(self, **kwargs):
67
        passwordhash = format_password_hash_sha(password=kwargs.pop('password'))
68
        kwargs.update({
69
            'passwordhash': passwordhash,
70
            'hashmethod': 'sha'
71
        })
72
        return kwargs
73
74
    def transform_response(self, api, arguments, response):
75
        return response.get('res') == 0
76
77
class CheckPassword(API):
78
    method = 'check_password'
79
    arguments = [StringArgument('user'), StringArgument('host'), StringArgument('password')]
80
81
    def transform_response(self, api, arguments, response):
82
        return response.get('res') == 0
83
84
class SetNickname(API):
85
    method = 'set_nickname'
86
    arguments = [StringArgument('user'), StringArgument('host'), StringArgument('nickname')]
87
88
    def transform_response(self, api, arguments, response):
89
        return response.get('res') == 0
90
91
class ConnectedUsers(API):
92
    method = 'connected_users'
93
    arguments = []
94
95
    def transform_response(self, api, arguments, response):
96
        connected_users = response.get('connected_users', [])
97
98
        return [user["sessions"] for user in connected_users]
99
100
class ConnectedUsersInfo(API):
101
    method = 'connected_users_info'
102
    arguments = []
103
104
    def transform_response(self, api, arguments, response):
105
        connected_users_info = response.get('connected_users_info', [])
106
107
        return [user["sessions"] for user in connected_users_info]
108
109
class ConnectedUsersNumber(API):
110
    method = 'connected_users_number'
111
    arguments = []
112
113
    def transform_response(self, api, arguments, response):
114
        return response.get('num_sessions')
115
116
class UserSessionInfo(API):
117
    method = 'user_sessions_info'
118
    arguments = [StringArgument('user'), StringArgument('host')]
119
120
    def transform_response(self, api, arguments, response):
121
        sessions_info = response.get('sessions_info', [])
122
        return [
123
            dict((k, v) for property_k_v in session["session"] for k, v in property_k_v.items())
124
            for session in sessions_info
125
        ]
126
127
class MucOnlineRooms(API):
128
    method = 'muc_online_rooms'
129
    arguments = [StringArgument('host')]
130
131
    def transform_response(self, api, arguments, response):
132
        return [result_dict.get('room') for result_dict in response.get('rooms', {})]
133
134
135
class CreateRoom(API):
136
    method = 'create_room'
137
    arguments = [StringArgument('name'), StringArgument('service'), StringArgument('host')]
138
139
    def transform_response(self, api, arguments, response):
140
        return response.get('res') == 0
141
142
143
class DestroyRoom(API):
144
    method = 'destroy_room'
145
    arguments = [StringArgument('name'), StringArgument('service'), StringArgument('host')]
146
147
    def transform_response(self, api, arguments, response):
148
        return response.get('res') == 0
149
150
151
class GetRoomOptions(API):
152
    method = 'get_room_options'
153
    arguments = [StringArgument('name'), StringArgument('service')]
154
155
    def transform_response(self, api, arguments, response):
156
        result = {}
157
        for option_dict in response.get('options', []):
158
            option = option_dict.get('option')
159
            if option is None:
160
                raise ValueError('Unexpected option in response: ' % str(option_dict))
161
            name_dict, value_dict = option
162
            result[name_dict['name']] = value_dict['value']
163
        return result
164
165
166
class ChangeRoomOption(API):
167
    method = 'change_room_option'
168
    arguments = [StringArgument('name'), StringArgument('service'), MUCRoomArgument('option'), StringArgument('value')]
169
170
    def transform_arguments(self, **kwargs):
171
        option = kwargs.get('option')
172
        assert isinstance(option, MUCRoomOption)
173
        serializer_class = muc_room_options_serializers.get(option, StringSerializer)
174
        kwargs['value'] = serializer_class().to_api(kwargs['value'])
175
        return kwargs
176
177
    def transform_response(self, api, arguments, response):
178
        return response.get('res') == 0
179
180
181
class SetRoomAffiliation(API):
182
    method = 'set_room_affiliation'
183
    arguments = [StringArgument('name'), StringArgument('service'), StringArgument('jid'),
184
                 AffiliationArgument('affiliation')]
185
186
    def transform_response(self, api, arguments, response):
187
        return response.get('res') == 0
188
189
190
class GetRoomAffiliations(API):
191
    method = 'get_room_affiliations'
192
    arguments = [StringArgument('name'), StringArgument('service')]
193
194
    def transform_response(self, api, arguments, response):
195
        affiliations = response.get('affiliations', [])
196
        return [{
197
            'username': subdict['affiliation'][0]['username'],
198
            'domain': subdict['affiliation'][1]['domain'],
199
            'affiliation': Affiliation.get_by_name(subdict['affiliation'][2]['affiliation']),
200
            'reason': subdict['affiliation'][3]['reason'],
201
        } for subdict in affiliations]
202
203
204
class AddRosterItem(API):
205
    method = 'add_rosteritem'
206
    arguments = [StringArgument('localuser'), StringArgument('localserver'),
207
                 StringArgument('user'), StringArgument('server'),
208
                 StringArgument('nick'), StringArgument('group'), StringArgument('subs')]
209
210
    def transform_response(self, api, arguments, response):
211
        return response.get('res') == 0
212
213
214
class DeleteRosterItem(API):
215
    method = 'delete_rosteritem'
216
    arguments = [StringArgument('localuser'), StringArgument('localserver'),
217
                 StringArgument('user'), StringArgument('server')]
218
219
    def transform_response(self, api, arguments, response):
220
        return response.get('res') == 0
221
222
223
class GetRoster(API):
224
    method = 'get_roster'
225
    arguments = [StringArgument('user'), StringArgument('host')]
226
227
    def transform_response(self, api, arguments, response):
228
        roster = []
229
        for contact in response.get('contacts', []):
230
            contact_details = {}
231
            for parameter in contact['contact']:
232
                for key, value in parameter.items():
233
                    contact_details[key] = value
234
            roster.append(contact_details)
235
        return roster
236
237
class Stats(API):
238
    method = 'stats'
239
    arguments = [StringArgument('name')]
240
241
    def transform_response(self, api, arguments, response):
242
        return response.get('stat')
243
244
class StatsHost(API):
245
    method = 'stats_host'
246
    arguments = [StringArgument('name'), StringArgument('host')]
247
248
    def transform_response(self, api, arguments, response):
249
        return response.get('stat')
250
251
class SendMessage(API):
252
    method = 'send_message'
253
    arguments = [StringArgument('type'),
254
                 StringArgument('_from'), StringArgument('to'),
255
                 StringArgument('subject'), StringArgument('body')]
256
257
    def transform_response(self, api, arguments, response):
258
        return response.get('res')
259
260
class PrivacySet(API):
261
    method = 'privacy_set'
262
    arguments = [StringArgument('user'), StringArgument('host'),
263
                 StringArgument('xmlquery')]
264
265
    def transform_response(self, api, arguments, response):
266
        return response.get('res')
267
268
class GetLast(API):
269
    method = 'get_last'
270
    arguments = [StringArgument('user'), StringArgument('host')]
271
272
    def transform_response(self, api, arguments, response):
273
        return response.get('last_activity')
274
275
class BanAccount(API):
276
    method = 'ban_account'
277
    arguments = [StringArgument('user'), StringArgument('host'), StringArgument('reason')]
278
279
    def transform_response(self, api, arguments, response):
280
        return response.get('res')
281