'Returns the URL of this request, use parameters to override
current requests attributes:
- None to keep current attribute (default)
- 0 or "" to set attribute to NONE
- value to use explicit value
@param id: the master record ID
@param component: the component name
@param component_id: the component ID
@param target: the target record ID (choose automatically)
@param method: the URL method
@param representation: the representation for the URL
@param vars: the URL query variables
@param host: string to force absolute URL with host (True means http_host)
Particular behavior:
- changing the master record ID resets the component ID
- removing the target record ID sets the method to None
- removing the method sets the target record ID to None
- [] as id will be replaced by the "[id]" wildcard'

def url(self, id=None, component=None, component_id=None, target=None, method=None, representation=None, vars=None, host=None):

    if (vars is None):
        vars = self.get_vars
    elif (vars and isinstance(vars, str)):
        vars = json.loads(vars.replace("'", '"'))
    if ('format' in vars):
        del vars['format']
    args = []
    cname = self.component_name
    if (target is not None):
        if (cname and ((component is None) or (component == cname))):
            component_id = target
        else:
            id = target
    default_method = False
    if (method is None):
        default_method = True
        method = self.method
    elif (method == ''):
        if (component_id is None):
            if (self.component_id is not None):
                component_id = 0
            elif (not self.component):
                if (id is None):
                    if (self.id is not None):
                        id = 0
        method = None
    if (id is None):
        id = self.id
    elif (id in (0, '')):
        id = None
    elif (id in ([], '[id]', '*')):
        id = '[id]'
        component_id = 0
    elif (str(id) != str(self.id)):
        component_id = 0
    if (component is None):
        component = cname
    elif (component == ''):
        component = None
    if ((cname and (cname != component)) or (not component)):
        component_id = 0
    if (component_id is None):
        component_id = self.component_id
    elif (component_id == 0):
        component_id = None
        if (self.component_id and default_method):
            method = None
    if ((id is None) and self.id and ((not component) or (not component_id)) and default_method):
        method = None
    if id:
        args.append(id)
    if component:
        args.append(component)
    if component_id:
        args.append(component_id)
    if method:
        args.append(method)
    if (representation is None):
        representation = self.representation
    elif (representation == ''):
        representation = self.DEFAULT_REPRESENTATION
    f = self.function
    if (not (representation == self.DEFAULT_REPRESENTATION)):
        if (len(args) > 0):
            args[(-1)] = ('%s.%s' % (args[(-1)], representation))
        else:
            f = ('%s.%s' % (f, representation))
    return URL(r=self, c=self.controller, f=f, args=args, vars=vars, host=host)
