~mvo/ubuntu-sso-client/strawman-lp711413

« back to all changes in this revision

Viewing changes to ubuntu_sso/main/windows.py

Fix pylint warnings

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# You should have received a copy of the GNU General Public License along
16
16
# with this program.  If not, see <http://www.gnu.org/licenses/>.
17
17
"""Main implementation on windows."""
18
 
 
19
18
from functools import wraps
20
19
from twisted.internet import defer, reactor
21
20
from twisted.internet.threads import deferToThread
61
60
from ubuntu_sso.main import (CredentialsManagementRoot, SSOLoginRoot,
62
61
                             SSOCredentialsRoot, except_to_errdict)
63
62
 
64
 
logger = setup_logging("ubuntu_sso.main")
 
63
logger = setup_logging("ubuntu_sso.main.windows")
65
64
NAMED_PIPE_URL = '\\\\.\\pipe\\ubuntu_sso\\%s'
66
65
 
67
66
 
74
73
 
75
74
def blocking(f, app_name, result_cb, error_cb):
76
75
    """Run f in a thread; return or throw an exception thru the callbacks."""
77
 
    d = deferToThread(f, app_name)
78
 
    d.addCallbacks(result_cb, error_cb, callbackArgs=(app_name,),
79
 
                   errbackArgs=(app_name,))
 
76
    d = deferToThread(f)
 
77
    # the calls in twisted will be called with the args in a diff order,
 
78
    # in order to follow the linux api, we swap them around with a lambda
 
79
    d.addCallback(lambda result, app: result_cb(app, result), app_name)
 
80
    d.addErrback(lambda err, app: error_cb(app, err), app_name)
80
81
 
81
82
 
82
83
class RemoteMeta(type):
164
165
        logger.debug('SSOLogin: emitting CaptchaGenerationError with '
165
166
                     'app_name "%s" and error %r', app_name, raised_error)
166
167
        self.emit_signal('on_captcha_generation_error', app_name,
167
 
                         except_to_errdict(raised_error))
 
168
                         except_to_errdict(raised_error.value))
168
169
 
169
170
    def generate_captcha(self, app_name, filename):
170
171
        """Call the matching method in the processor."""
184
185
        logger.debug('SSOLogin: emitting UserRegistrationError with '
185
186
                     'app_name "%s" and error %r', app_name, raised_error)
186
187
        self.emit_signal('on_user_registration_error', app_name,
187
 
                         except_to_errdict(raised_error))
 
188
                         except_to_errdict(raised_error.value))
188
189
 
189
190
    def register_user(self, app_name, email, password, displayname,
190
191
                      captcha_id, captcha_solution):
206
207
        logger.debug('SSOLogin: emitting LoginError with '
207
208
                     'app_name "%s" and error %r', app_name, raised_error)
208
209
        self.emit_signal('on_login_error', app_name,
209
 
                         except_to_errdict(raised_error))
 
210
                         except_to_errdict(raised_error.value))
210
211
 
211
212
    def emit_user_not_validated(self, app_name, result):
212
213
        """Signal thrown when the user is not validated."""
232
233
        logger.debug('SSOLogin: emitting EmailValidationError with '
233
234
                     'app_name "%s" and error %r', app_name, raised_error)
234
235
        self.emit_signal('on_email_validation_error', app_name,
235
 
                         except_to_errdict(raised_error))
 
236
                         except_to_errdict(raised_error.value))
236
237
 
237
238
    def validate_email(self, app_name, email, password, email_token):
238
239
        """Call the matching method in the processor."""
252
253
        logger.debug('SSOLogin: emitting PasswordResetError with '
253
254
                     'app_name "%s" and error %r', app_name, raised_error)
254
255
        self.emit_signal('on_password_reset_error', app_name,
255
 
                         except_to_errdict(raised_error))
 
256
                         except_to_errdict(raised_error.value))
256
257
 
257
258
    def request_password_reset_token(self, app_name, email):
258
259
        """Call the matching method in the processor."""
272
273
        logger.debug('SSOLogin: emitting PasswordChangeError with '
273
274
                     'app_name "%s" and error %r', app_name, raised_error)
274
275
        self.emit_signal('on_password_change_error', app_name,
275
 
                         except_to_errdict(raised_error))
 
276
                         except_to_errdict(raised_error.value))
276
277
 
277
278
    def set_new_password(self, app_name, email, token, new_password):
278
279
        """Call the matching method in the processor."""
918
919
    @defer.inlineCallbacks
919
920
    def _request_remote_objects(self, root):
920
921
        """Get the status remote object."""
921
 
        self.sso_login = yield root.callRemote('get_sso_login')
922
 
        self.sso_cred = yield root.callRemote('get_sso_credentials')
923
 
        self.cred_management = yield root.callRemote('get_cred_manager')
 
922
        sso_login = yield root.callRemote('get_sso_login')
 
923
        self.sso_login = SSOLoginClient(sso_login)
 
924
        sso_cred = yield root.callRemote('get_sso_credentials')
 
925
        self.sso_cred = SSOCredentialsClient(sso_cred)
 
926
        cred_management = yield root.callRemote('get_cred_manager')
 
927
        self.cred_management = CredentialsManagementClient(cred_management)
924
928
        defer.returnValue(self)
925
929
 
926
930
    def connect(self):