1

次のようなことが起こった場合、メソッドを再試行したいのですExceptionが、デコレータでこれを行う方が良いでしょうか?

class Processor(object):
    def __init__(self, username, password):
        self.username = username
        self.password = password
        self.user_info = UserInfo.objects.get(username=username)

    def get_inbox_page(self):
        try:
            # TODO process inbox page
            pass
        except NotLoginException:
            self.login()
            self.get_inbox_page()

    def get_downloaded_page(self):
            try:
            # TODO process downloaded page
            pass
        except NotLoginException:
            self.login()
            self.get_downloaded_page()

    def get_accept_msg_page(self):
        try:
            # TODO process accept message page
            pass
        except NotLoginException:
            self.login()
            self.get_accept_msg_page()

    # ... some other similar methods

    def login(self):
        session = self.login_proxy(self.username, self.password)
        self.user_info.session = session
        self.user_info.save()
4

0 に答える 0