def match(self, request=None):
        """
            Match this item against request (uses GET vars)

            @param request: the request object (defaults to current.request)

            @return: the match level (integer):
                        0=no match
                        1=controller
                        2=controller+function
                        3=controller+function+args
                        4=controller+function+args+vars

            @note: currently ignores numerical arguments in the request,
                   which is though subject to change (in order to support
                   numerical arguments in the item)
        """

        level = 0
        args = self.args
        link_vars = self.vars

        if self.application is not None and \
           self.application != request.application:
            # Foreign application links never match
            return 0

        if self.opts.selectable is False:
            return 0

        # Check hook and enabled
        check = self.check_hook()
        if check:
            enabled = self.check_enabled()
            if not enabled:
                check = False
        if not check:
            # Hook failed or disabled: doesn't match in any case
            return 0

        if request is None:
            request = current.request

        c = self.get("controller")
        mc = self.get("match_controller")

        # Top-level items with no controller setting
        # (=application level items) match any controller, but not more
        if not c and self.parent is None:
            return 1


        rvars = request.get_vars
        controller = request.controller
        function = request.function

        # Handle "viewing" (foreign controller in a tab)
        # NOTE: this tries to match the item against the resource name
        # in "viewing", so if the target controller/function of the item
        # are different from prefix/name in the resource name, then this
        # may require additional match_controller/match_function to be
        # set for this item! (beware ambiguity then, though)
        if "viewing" in rvars:
            try:
                tn, record_id = rvars["viewing"].split(".")
                controller, function = tn.split("_", 1)
            except:
                pass

        # Controller
        if controller == c or controller in mc:
            level = 1

        # Function
        if level == 1:
            f = self.get("function")
            mf = self.get("match_function")
            if function == f or function in mf:
                level = 2
            elif f == "index":
                # "weak" match: homepage link matches any function
                return 1
            elif f is not None:
                return 0

        # Args and vars
        # Match levels (=order of preference):
        #   0 = args mismatch
        #   1 = last arg mismatch (numeric instead of method)
        #   2 = no args in item and vars mismatch
        #   3 = no args and no vars in item
        #   4 = no args in item but vars match
        #   5 = args match but vars mismatch
        #   6 = args match and no vars in item
        #   7 = args match and vars match
        if level == 2:
            extra = 1
            for k, v in link_vars.iteritems():
                if k not in rvars or k in rvars and rvars[k] != s3_unicode(v):
                    extra = 0
                    break
                else:
                    extra = 2
            rargs = request.args
            if rargs:
                if args:
                    largs = [a for a in request.args if not a.isdigit()]
                    if len(args) == len(largs) and \
                       all([args[i] == largs[i] for i in xrange(len(args))]):
                        level = 5
                    else:
                        if len(rargs) >= len(args) > 0 and \
                           rargs[len(args)-1].isdigit() and \
                           not str(args[-1]).isdigit():
                            level = 1
                        else:
                            return 0
                else:
                    level = 3
            elif args:
                return 0
            else:
                level = 5
            level += extra

        return level

    # -------------------------------------------------------------------------
dataset/ETHPy150Open sahana/eden/modules/s3/s3navigation.py/S3NavigationItem.match/original