'Return a URL pointing to this resource. If it is a file on the filesystem
the URL is relative to `basedir`.
`basedir`: If None, the basedir of this resource is used (see :method:`set_basedir`).
If this resource has no basedir, then the current working directory is used as the basedir.'

def href(self, basedir=None):

    if (basedir is None):
        if self._basedir:
            basedir = self._basedir
        else:
            basedir = os.getcwdu()
    if (self.path is None):
        return self._href
    f = (self.fragment.encode('utf-8') if isinstance(self.fragment, unicode) else self.fragment)
    frag = (('#' + f) if self.fragment else '')
    if (self.path == basedir):
        return ('' + frag)
    try:
        rpath = os.path.relpath(self.path, basedir)
    except ValueError:
        rpath = self.path
    if isinstance(rpath, unicode):
        rpath = rpath.encode('utf-8')
    return (rpath.replace(os.sep, '/') + frag)
