<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def path_for(self, handler, **kwargs):
 """construct path for a given handler Example: path = path_for(show_user, user_id=109) """

        if type(handler) is not str:
            handler = handler.__qualname__
        if handler not in self.__reversedidx__:
            return None
        pattern = self.__reversedidx__[handler].pattern.lstrip('^').rstrip('$')
        path = self.param_macher.sub(lambda m: str(kwargs.pop(m.group(1))),
                                     pattern)
        if kwargs:
            path = "%s?%s" % (path, parse.urlencode(kwargs))
        return path