Reconstruct the URL from level name, code or datagouv id and slug.
488728
def to_url(self, obj):
        
        level_name = getattr(obj, 'level_name', None)
        if not level_name:
            raise ValueError('Unable to serialize "%s" to url' % obj)

        code = getattr(obj, 'code', None)
        slug = getattr(obj, 'slug', None)
        validity = getattr(obj, 'validity', None)
        if code and slug:
            return '{level_name}/{code}@{start_date}/{slug}'.format(
                level_name=level_name,
                code=code,
                start_date=getattr(validity, 'start', None) or 'latest',
                slug=slug
            )
        else:
            raise ValueError('Unable to serialize "%s" to url' % obj)
1102620
function getURLParameter (name, url) {
    name = name.replace(/[[]/, '\\[').replace(/[\]]/, '\\]');
    var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
    var results = regex.exec(url);
    return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
}
1251846
function(slug) {
  var base64 = slug
    .replace(/-/g, '+')
    .replace(/_/g, '/')
                  + '==';
  return Buffer.from(base64, 'base64');
}
709604
def from_url(cls, db_url=ALL_SETS_ZIP_URL):
        
        r = requests.get(db_url)
        r.raise_for_status()

        if r.headers['content-type'] == 'application/json':
            return cls(json.loads(r.text))

        if r.headers['content-type'] == 'application/zip':
            with zipfile.ZipFile(six.BytesIO(r.content), 'r') as zf:
                names = zf.namelist()
                assert len(names) == 1, 'One datafile in ZIP'
                return cls.from_file(io.TextIOWrapper(
                    zf.open(names[0]),
                    encoding='utf8'))
1014892
def extract_urls(url, data, unescape=HTMLParser.HTMLParser().unescape):
    """"""
    parts = urlparse.urlparse(url)
    prefix = '%s://%s' % (parts.scheme, parts.netloc)

    accessed_dir = os.path.dirname(parts.path)
    if not accessed_dir.endswith('/'):
        accessed_dir += '/'

    for pattern, replacement in REPLACEMENT_REGEXES:
        fixed = replacement % {
            'base': prefix,
            'accessed_dir': accessed_dir,
        }
        data = re.sub(pattern, fixed, data)

    result = set()
    for match in re.finditer(MAYBE_HTML_URL_REGEX, data):
        found_url = unescape(match.groupdict()['absurl'])
        found_url = clean_url(
            found_url,
            force_scheme=parts[0])  # Use the main page's scheme
        result.add(found_url)

    return result
104721
def from_url(cls, url, **kwargs):
        """"""
        url = urllib3.util.parse_url(url)
        if url.host:
            kwargs.setdefault('host', url.host)

        if url.port:
            kwargs.setdefault('port', url.port)

        if url.scheme == 'https':
            kwargs.setdefault('connection_class', urllib3.HTTPSConnectionPool)

        return cls(**kwargs)
1274956
def get_url(self, obj, view_name, request, format):
        
        # Unsaved objects will not yet have a valid URL.
        if hasattr(obj, 'pk') and obj.pk is None:
            return None

        lookup_value = getattr(obj, self.lookup_field)
        kwargs = {self.lookup_url_kwarg: lookup_value}
        return self.reverse(view_name, kwargs=kwargs, request=request, format=format)
1256782
def aggregate_url (aggregate, url, err_exit_code=2):
    """"""
    get_url_from = checker.get_url_from
    url = checker.guess_url(url)
    url_data = get_url_from(url, 0, aggregate, extern=(0, 0))
    aggregate.urlqueue.put(url_data)
207215
def top_level(url, fix_protocol=True):
    """"""
    ext = tld.get_tld(url, fix_protocol=fix_protocol)
    toplevel = '.'.join(urlparse(url).netloc.split('.')[-2:]).split(
        ext)[0] + ext
    return toplevel
670605
def _fetch_url(url):
    
    try:
        resp = urllib2.urlopen(_Request(url))
    except urllib2.URLError:
        if 'wikileaks.org' in url:
            resp = urllib2.urlopen(_Request(url.replace('wikileaks.org', 'wikileaks.ch')))
        else:
            raise
    if resp.info().get('Content-Encoding') == 'gzip':
        return gzip.GzipFile(fileobj=StringIO(resp.read())).read().decode('utf-8')
    return resp.read().decode('utf-8')
478174
def get_raw_data_from_url(pdb_id, reduced=False):
    "
    url = get_url(pdb_id,reduced)
    request = urllib2.Request(url)
    request.add_header('Accept-encoding', 'gzip')
    response = urllib2.urlopen(request)
    if response.info().get('Content-Encoding') == 'gzip':
        data = ungzip_data(response.read())
    else:
        data = response.read()
    return _unpack(data)
1210244
async def fromURL(cls, url, *, credentials=None, insecure=False):
        """"""
        session = await bones.SessionAPI.fromURL(
            url, credentials=credentials, insecure=insecure)
        return cls(session)
246222
def _relIndexLink(self):
        """"""
        return os.path.join("..", os.path.basename(self.pathname), "index.html")
402236
def slug_from_dict(d, max_len=128, delim='-'):
    
    return slug_from_iter(list(d.values()), max_len=max_len, delim=delim)
696526
def _get_dest_file_and_url(self, filepath, page_meta={}):
        

        filename = filepath.split("/")[-1]
        filepath_base = filepath.replace(filename, "").rstrip("/")
        slug = page_meta.get("slug")
        fname = slugify(slug) if slug else filename \
            .replace(".html", "") \
            .replace(".md", "") \
            .replace(".jade", "")

        if page_meta.get("pretty_url") is False:
            dest_file = os.path.join(filepath_base, "%s.html" % fname)
        else:
            dest_dir = filepath_base
            if filename not in ["index.html", "index.md", "index.jade"]:
                dest_dir = os.path.join(filepath_base, fname)
            dest_file = os.path.join(dest_dir, "index.html")

        url = "/" + dest_file.replace("index.html", "")
        return dest_file, url
1261047
def clean_slug(self):
        
        self.instance._old_slug = self.instance.slug
        new_slug = self.cleaned_data['slug']
        if not isinstance(self.instance, Link) and new_slug != "/":
            new_slug = clean_slashes(self.cleaned_data['slug'])
        return new_slug
1268899
def reconstruct_uri(environ):
    
    uri = environ.get('SCRIPT_NAME', '') + environ['PATH_INFO']
    if environ.get('QUERY_STRING'):
        uri += '?' + environ['QUERY_STRING']
    return uri