Return a new URL with fragment replaced.

        Autoencode fragment if needed.

        Clear fragment to default if None is passed.
546728
def with_fragment(self, fragment):
        
        # N.B. doesn't cleanup query/fragment
        if fragment is None:
            fragment = ""
        elif not isinstance(fragment, str):
            raise TypeError("Invalid fragment type")
        return URL(
            self._val._replace(fragment=self._FRAGMENT_QUOTER(fragment)), encoded=True
        )
807405
def execute(self, fragment, pretty_format=True):
        
        self.fragments = (self.fragments + "\n" + fragment).lstrip()
        try:
            line_parser.parseString(self.fragments)
        except ParseException:
            pass
        else:
            self.last_query = self.fragments.strip()
            self.fragments = ""
            return super(FragmentEngine, self).execute(self.last_query, pretty_format)
        return None
672946
def getFragment(self):
        """"""
        # assert self.innerHTML
        fragment = self.fragmentClass()
        self.openElements[0].reparentChildren(fragment)
        return fragment
1012858
def _maybe_get_default_name(self, name):
        
        if name is None and self.uri.fragment:
            name = self.uri.fragment
        return name
866511
def urljoin(base_url, url, allow_fragments=True):
    ''''''
    if url.startswith('//') and len(url) > 2:
        scheme = base_url.partition(':')[0]
        if scheme:
            return urllib.parse.urljoin(
                base_url,
                '{0}:{1}'.format(scheme, url),
                allow_fragments=allow_fragments
            )

    return urllib.parse.urljoin(
        base_url, url, allow_fragments=allow_fragments)
885818
function addFragmentParam(url, param, value) {
  return url +
      (url.indexOf('#') == -1 ? '#' : '&') +
      encodeURIComponent(param) + '=' + encodeURIComponent(value);
}
802561
def url(self, **urlargs):
        '''
        '''
        if self.defaults:
            d = self.defaults.copy()
            d.update(urlargs)
            urlargs = d
        url = '/'.join(self._url_generator(urlargs))
        if not url:
            return '/'
        else:
            url = '/' + url
            return url if self.is_leaf else url + '/'
280714
function (fragmentUrl, callback) {
    debug('  [GET] ' + fragmentUrl);
    request(fragmentUrl, function (error, response, body) {
      if (!error && response.statusCode === 200) {
        callback(null, body);
      } else {
        callback(error, null);
      }
    });
  }
1147833
public <T> AsyncMutateInBuilder replace(String path, T fragment) {
        if (StringUtil.isNullOrEmpty(path)) {
            throw new IllegalArgumentException("Path must not be empty for replace");
        }
        this.mutationSpecs.add(new MutationSpec(Mutation.REPLACE, path, fragment));
        return this;
    }
679650
def fragment(self, value=None):
        
        if value is not None:
            return URL._mutate(self, fragment=value)
        return unicode_unquote(self._tuple.fragment)
850727
public <T> MutateInBuilder replace(String path, T fragment) {
        asyncBuilder.replace(path, fragment);
        return this;
    }
1139686
def _new_url(self, relative_url):
        """"""

        return Url(
            urljoin(self._base_url, relative_url),
            **self._default_kwargs
        )
1001173
private static Opt<String> readFragment(final URI link) {
        final Opt<String> fragment;
        if (link.getRawFragment() == null) {
            fragment = new Opt.Empty<>();
        } else {
            fragment = new Opt.Single<>(link.getRawFragment());
        }
        return fragment;
    }
932412
function(fragment, forcePushState) {
      if (fragment == null) {
        if (this._hasPushState || !this._wantsHashChange || forcePushState) {
          fragment = this.location.pathname;
          var root = this.root.replace(trailingSlash, '');
          if (!fragment.indexOf(root)) fragment = fragment.slice(root.length);
        } else {
          fragment = this.getHash();
        }
      }
      return fragment.replace(routeStripper, '');
    }
1162020
function(e) {
      if (this.onbeforeunload && this.onbeforeunload()) {
        var fragment = this.fragment;
        this.fragment = '';
        return this.navigate(fragment, {trigger: false});
      }
      var current = this.getFragment();
      if (current == this.fragment && this.iframe) current = this.getFragment(this.getHash(this.iframe));
      if (current == this.fragment) return false;
      if (this.iframe) this.navigate(current);
      this.loadUrl() || this.loadUrl(this.getHash());
    }
721468
def urljoin(*fragments):
    """"""
    # Strip possible already existent final slashes of fragments except for the last one
    parts = [fragment.rstrip('/') for fragment in fragments[:len(fragments) - 1]]
    parts.append(fragments[-1])

    return '/'.join(parts)
319859
public static String addQueryStringFragment(String url, String fragment) {
        StringBuilder newUrl = new StringBuilder(url);

        if (fragment.startsWith("?") || fragment.startsWith("&")) {
            fragment = fragment.substring(1);
        }

        if (!url.endsWith("?") && !url.endsWith("&")) {
            if (url.contains("?")) {
                newUrl.append('&');
            } else {
                newUrl.append('?');
            }
        }

        return newUrl.append(fragment).toString();
    }