예제 #1
0
    def get_code_from_message(cls, message):
        # map error classes to facebook error codes
        # find the error code
        error_code = None
        error_code_re = re.compile('\(#(\d+)\)')
        matches = error_code_re.match(message)
        matching_groups = matches.groups() if matches else None
        if matching_groups:
            error_code = to_int(matching_groups[0]) or None

        return error_code
예제 #2
0
    def get_code_from_message(cls, message):
        # map error classes to facebook error codes
        # find the error code
        error_code = None
        error_code_re = re.compile('\(#(\d+)\)')
        matches = error_code_re.match(message)
        matching_groups = matches.groups() if matches else None
        if matching_groups:
            error_code = to_int(matching_groups[0]) or None

        return error_code
예제 #3
0
파일: api.py 프로젝트: evrenesat/ganihomes
    def raise_error(self, error_type, message):
        '''
        Search for a corresponding error class and fall back to open facebook exception
        '''
        import re
        error_class = None
        if not isinstance(error_type, int):
            error_class = getattr(facebook_exceptions, error_type, None)

        if error_class and not issubclass(error_class, facebook_exceptions.OpenFacebookException):
            error_class = None

        #map error classes to facebook error ids
        #define a string to match a single error, use ranges for complexer cases
        #also see http://fbdevwiki.com/wiki/Error_codes#User_Permission_Errors
        classes = [getattr(facebook_exceptions, e, None) for e in dir(facebook_exceptions)]
        exception_classes = [e for e in classes if getattr(e, 'codes', None) and issubclass(e, facebook_exceptions.OpenFacebookException)]
        exception_classes.sort(key=lambda e: e.range())

        #find the error code
        error_code = None
        error_code_re = re.compile('\(#(\d+)\)')
        matches = error_code_re.match(message)
        matching_groups = matches.groups() if matches else None
        if matching_groups:
            error_code = to_int(matching_groups[0]) or None

        for class_ in exception_classes:
            codes_list = class_.codes_list()
            #match the error class
            matching_error_class = None
            for code in codes_list:
                if isinstance(code, basestring):
                    #match on string
                    key = code
                    if key in message:
                        matching_error_class = class_
                        break
                elif isinstance(code, tuple):
                    start, stop = code
                    if error_code and start <= error_code <= stop:
                        matching_error_class = class_
                        break
                elif isinstance(code, (int, long)):
                    if int(code) == error_code:
                        matching_error_class = class_
                        break
                else:
                    raise ValueError, 'Dont know how to handle %s of type %s' % (code, type(code))
            #tell about the happy news if we found something
            if matching_error_class:
                error_class = matching_error_class
                break


        if 'Missing' in message and 'parameter' in message:
            error_class = facebook_exceptions.MissingParameter

        if not error_class:
            error_class = facebook_exceptions.OpenFacebookException

        raise error_class(message)
예제 #4
0
    def raise_error(self, error_type, message):
        '''
        Search for a corresponding error class and fall back to
        open facebook exception
        '''
        import re
        error_class = None
        if not isinstance(error_type, int):
            error_class = getattr(facebook_exceptions, error_type, None)
        if error_class and not issubclass(
                error_class, facebook_exceptions.OpenFacebookException):
            error_class = None
        # map error classes to facebook error ids
        # define a string to match a single error,
        # use ranges for complexer cases
        # also see http://fbdevwiki.com/wiki/Error_codes#User_Permission_Errors
        classes = [
            getattr(facebook_exceptions, e, None)
            for e in dir(facebook_exceptions)
        ]
        exception_classes = [
            e for e in classes if getattr(e, 'codes', None)
            and issubclass(e, facebook_exceptions.OpenFacebookException)
        ]
        exception_classes.sort(key=lambda e: e.range())

        # find the error code
        error_code = None
        error_code_re = re.compile('\(#(\d+)\)')
        matches = error_code_re.match(message)
        matching_groups = matches.groups() if matches else None
        if matching_groups:
            error_code = to_int(matching_groups[0]) or None

        for class_ in exception_classes:
            codes_list = class_.codes_list()
            # match the error class
            matching_error_class = None
            for code in codes_list:
                if isinstance(code, basestring):
                    # match on string
                    key = code
                    if key in message:
                        matching_error_class = class_
                        break
                elif isinstance(code, tuple):
                    start, stop = code
                    if error_code and start <= error_code <= stop:
                        matching_error_class = class_
                        break
                elif isinstance(code, (int, long)):
                    if int(code) == error_code:
                        matching_error_class = class_
                        break
                else:
                    raise(
                        ValueError, 'Dont know how to handle %s of ' \
                        'type %s' % (code, type(code)))
            #tell about the happy news if we found something
            if matching_error_class:
                error_class = matching_error_class
                break

        if 'Missing' in message and 'parameter' in message:
            error_class = facebook_exceptions.MissingParameter

        if not error_class:
            error_class = facebook_exceptions.OpenFacebookException

        raise error_class(message)