Code Monkey home page Code Monkey logo

ada-python's Introduction

ada-url

This is ada_url, a Python library for parsing and joining URLs.

WHATWG URL compliance

Unlike the standard library's urllib.parse module, this library is compliant with the WHATWG URL spec.

urlstring = "https://www.GOoglé.com/./path/../path2/"

import ada_url

# prints www.xn--googl-fsa.com,
# the correctly parsed domain name according to WHATWG
print(ada_url.URL(urlstring).hostname)
# prints /path2/
# the correctly parsed pathname according to WHATWG
print(ada_url.URL(urlstring).pathname)

import urllib

#prints www.googlé.com
print(urllib.parse.urlparse(urlstring).hostname)
#prints /./path/../path2/
print(urllib.parse.urlparse(urlstring).path)

Examples

This package exposes a URL class that is intended to match the one described in the WHATWG URL spec.

>>> import ada_url
>>> ada_url.URL('https://example.org/path/../file.txt') as urlobj:
>>> urlobj.host = 'example.com'
>>> new_url = urlobj.href
>>> new_url
'https://example.com/file.txt'

It also provides some higher level functions for parsing and manipulating URLs.

>>> import ada_url
>>> ada_url.check_url('https://example.org')
True
>>> ada_url.join_url(
    'https://example.org/dir/child.txt', '../parent.txt'
)
'https://example.org/parent.txt'
>>> ada_url.normalize_url('https://example.org/dir/../parent.txt')
'https://example.org/parent.txt'
>>> ada_url.parse_url('https://user:[email protected]:80/api?q=1#2')
{
    'href': 'https://user:[email protected]:80/api?q=1#2',
    'username': 'user',
    'password': 'pass',
    'protocol': 'https:',
    'host': 'example.org:80',
    'port': '80',
    'hostname': 'example.org',
    'pathname': '/api',
    'search': '?q=1',
    'hash': '#2'
}
>>> ada_url.replace_url('http://example.org:80', protocol='https:')
'https://example.org/'

You can find more documentation at Read the Docs.

ada-python's People

Contributors

anonrig avatar bbayles avatar lemire avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.