Notebooks >> Scripts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

287 lines
11 KiB

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# furl\n",
"\n",
"[Github](https://github.com/gruns/furl)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" % Total % Received % Xferd Average Speed Time Time Time Current\n",
" Dload Upload Total Spent Left Speed\n",
" 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 185.199.109.133:443...\n",
"* Connected to raw.githubusercontent.com (185.199.109.133) port 443 (#0)\n",
"* ALPN, offering h2\n",
"* ALPN, offering http/1.1\n",
"* CAfile: /etc/ssl/certs/ca-certificates.crt\n",
"* CApath: /etc/ssl/certs\n",
"* TLSv1.0 (OUT), TLS header, Certificate Status (22):\n",
"} [5 bytes data]\n",
"* TLSv1.3 (OUT), TLS handshake, Client hello (1):\n",
"} [512 bytes data]\n",
"* TLSv1.2 (IN), TLS header, Certificate Status (22):\n",
"{ [5 bytes data]\n",
"* TLSv1.3 (IN), TLS handshake, Server hello (2):\n",
"{ [122 bytes data]\n",
"* TLSv1.2 (IN), TLS header, Finished (20):\n",
"{ [5 bytes data]\n",
"* TLSv1.2 (IN), TLS header, Supplemental data (23):\n",
"{ [5 bytes data]\n",
"* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):\n",
"{ [19 bytes data]\n",
"* TLSv1.2 (IN), TLS header, Supplemental data (23):\n",
"{ [5 bytes data]\n",
"* TLSv1.3 (IN), TLS handshake, Certificate (11):\n",
"{ [3051 bytes data]\n",
"* TLSv1.2 (IN), TLS header, Supplemental data (23):\n",
"{ [5 bytes data]\n",
"* TLSv1.3 (IN), TLS handshake, CERT verify (15):\n",
"{ [264 bytes data]\n",
"* TLSv1.2 (IN), TLS header, Supplemental data (23):\n",
"{ [5 bytes data]\n",
"* TLSv1.3 (IN), TLS handshake, Finished (20):\n",
"{ [52 bytes data]\n",
"* TLSv1.2 (OUT), TLS header, Finished (20):\n",
"} [5 bytes data]\n",
"* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):\n",
"} [1 bytes data]\n",
"* TLSv1.2 (OUT), TLS header, Supplemental data (23):\n",
"} [5 bytes data]\n",
"* TLSv1.3 (OUT), TLS handshake, Finished (20):\n",
"} [52 bytes data]\n",
"* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384\n",
"* ALPN, server accepted to use h2\n",
"* Server certificate:\n",
"* subject: C=US; ST=California; L=San Francisco; O=GitHub, Inc.; CN=*.github.io\n",
"* start date: Mar 18 00:00:00 2022 GMT\n",
"* expire date: Mar 21 23:59:59 2023 GMT\n",
"* subjectAltName: host \"raw.githubusercontent.com\" matched cert's \"*.githubusercontent.com\"\n",
"* issuer: C=US; O=DigiCert Inc; CN=DigiCert TLS RSA SHA256 2020 CA1\n",
"* SSL certificate verify ok.\n",
"* Using HTTP2, server supports multiplexing\n",
"* Connection state changed (HTTP/2 confirmed)\n",
"* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0\n",
"* TLSv1.2 (OUT), TLS header, Supplemental data (23):\n",
"} [5 bytes data]\n",
"* TLSv1.2 (OUT), TLS header, Supplemental data (23):\n",
"} [5 bytes data]\n",
"* TLSv1.2 (OUT), TLS header, Supplemental data (23):\n",
"} [5 bytes data]\n",
"* Using Stream ID: 1 (easy handle 0x559fdfac8e80)\n",
"* TLSv1.2 (OUT), TLS header, Supplemental data (23):\n",
"} [5 bytes data]\n",
"> GET /gruns/furl/master/README.md HTTP/2\n",
"> Host: raw.githubusercontent.com\n",
"> user-agent: curl/7.81.0\n",
"> accept: */*\n",
"> \n",
"* TLSv1.2 (IN), TLS header, Supplemental data (23):\n",
"{ [5 bytes data]\n",
"* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):\n",
"{ [193 bytes data]\n",
"* TLSv1.2 (IN), TLS header, Supplemental data (23):\n",
"{ [5 bytes data]\n",
"* TLSv1.2 (OUT), TLS header, Supplemental data (23):\n",
"} [5 bytes data]\n",
"* TLSv1.2 (IN), TLS header, Supplemental data (23):\n",
"{ [5 bytes data]\n",
"* TLSv1.2 (IN), TLS header, Supplemental data (23):\n",
"{ [5 bytes data]\n",
"< HTTP/2 200 \n",
"< cache-control: max-age=300\n",
"< content-security-policy: default-src 'none'; style-src 'unsafe-inline'; sandbox\n",
"< content-type: text/plain; charset=utf-8\n",
"< etag: \"a422674a44f080e982c2757a03c7a6085f6de3a85731442a2f14785510ef12e2\"\n",
"< strict-transport-security: max-age=31536000\n",
"< x-content-type-options: nosniff\n",
"< x-frame-options: deny\n",
"< x-xss-protection: 1; mode=block\n",
"< x-github-request-id: 5F04:63F8:20E44:3B90F:62F2032B\n",
"< accept-ranges: bytes\n",
"< date: Tue, 09 Aug 2022 06:48:11 GMT\n",
"< via: 1.1 varnish\n",
"< x-served-by: cache-iah17220-IAH\n",
"< x-cache: MISS\n",
"< x-cache-hits: 0\n",
"< x-timer: S1660027691.995129,VS0,VE126\n",
"< vary: Authorization,Accept-Encoding,Origin\n",
"< access-control-allow-origin: *\n",
"< x-fastly-request-id: 3ae1114575f72aef60b2af9ef7e0d60266073cbb\n",
"< expires: Tue, 09 Aug 2022 06:53:11 GMT\n",
"< source-age: 0\n",
"< content-length: 23922\n",
"< \n",
"{ [885 bytes data]\n",
"* TLSv1.2 (IN), TLS header, Supplemental data (23):\n",
"{ [5 bytes data]\n",
"* TLSv1.2 (IN), TLS header, Supplemental data (23):\n",
"{ [5 bytes data]\n",
"* TLSv1.2 (IN), TLS header, Supplemental data (23):\n",
"{ [5 bytes data]\n",
"* TLSv1.2 (IN), TLS header, Supplemental data (23):\n",
"{ [5 bytes data]\n",
"* TLSv1.2 (IN), TLS header, Supplemental data (23):\n",
"{ [5 bytes data]\n",
"* TLSv1.2 (IN), TLS header, Supplemental data (23):\n",
"{ [5 bytes data]\n",
"* TLSv1.2 (IN), TLS header, Supplemental data (23):\n",
"{ [5 bytes data]\n",
"* TLSv1.2 (IN), TLS header, Supplemental data (23):\n",
"{ [5 bytes data]\n",
"* TLSv1.2 (IN), TLS header, Supplemental data (23):\n",
"{ [5 bytes data]\n",
"* TLSv1.2 (IN), TLS header, Supplemental data (23):\n",
"{ [5 bytes data]\n",
"* TLSv1.2 (IN), TLS header, Supplemental data (23):\n",
"{ [5 bytes data]\n",
"* TLSv1.2 (IN), TLS header, Supplemental data (23):\n",
"{ [5 bytes data]\n",
"* TLSv1.2 (IN), TLS header, Supplemental data (23):\n",
"{ [5 bytes data]\n",
"* TLSv1.2 (IN), TLS header, Supplemental data (23):\n",
"{ [5 bytes data]\n",
"* TLSv1.2 (IN), TLS header, Supplemental data (23):\n",
"{ [5 bytes data]\n",
"* TLSv1.2 (IN), TLS header, Supplemental data (23):\n",
"{ [5 bytes data]\n",
"* TLSv1.2 (IN), TLS header, Supplemental data (23):\n",
"{ [5 bytes data]\n",
"100 23922 100 23922 0 0 76972 0 --:--:-- --:--:-- --:--:-- 77167\n",
"* Connection #0 to host raw.githubusercontent.com left intact\n"
]
}
],
"source": [
"# Retrieve Decumentation\n",
"\n",
"!curl -fLvo readme.md https://raw.githubusercontent.com/gruns/furl/master/README.md"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Defaulting to user installation because normal site-packages is not writeable\n",
"Collecting furl\n",
" Downloading furl-2.1.3-py2.py3-none-any.whl (20 kB)\n",
"Requirement already satisfied: six>=1.8.0 in /usr/lib/python3/dist-packages (from furl) (1.16.0)\n",
"Collecting orderedmultidict>=1.0.1\n",
" Downloading orderedmultidict-1.0.1-py2.py3-none-any.whl (11 kB)\n",
"Installing collected packages: orderedmultidict, furl\n",
"Successfully installed furl-2.1.3 orderedmultidict-1.0.1\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"%pip install furl"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Function: URL Deconstructor\n",
"\n",
"Takes a URL, chops it up into all the little pieces, returns as a JSON dictionary"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'fragment': {'encoded': 'scheme-username-password-host-port-network-location-and-origin',\n",
" 'path': {'encoded': 'scheme-username-password-host-port-network-location-and-origin',\n",
" 'isabsolute': False,\n",
" 'isdir': False,\n",
" 'isfile': True,\n",
" 'segments': ['scheme-username-password-host-port-network-location-and-origin']},\n",
" 'query': {'encoded': '', 'params': []},\n",
" 'separator': True},\n",
" 'host': 'github.com',\n",
" 'host_encoded': 'github.com',\n",
" 'netloc': 'github.com',\n",
" 'origin': 'https://github.com',\n",
" 'password': None,\n",
" 'path': {'encoded': '/gruns/furl',\n",
" 'isabsolute': True,\n",
" 'isdir': False,\n",
" 'isfile': True,\n",
" 'segments': ['gruns', 'furl']},\n",
" 'port': 443,\n",
" 'query': {'encoded': '', 'params': []},\n",
" 'scheme': 'https',\n",
" 'url': 'https://github.com/gruns/furl#scheme-username-password-host-port-network-location-and-origin',\n",
" 'username': None}\n"
]
}
],
"source": [
"from furl import furl\n",
"import pprint\n",
"\n",
"url = 'https://github.com/gruns/furl#scheme-username-password-host-port-network-location-and-origin'\n",
"\n",
"f = furl(url)\n",
"\n",
"result = f.asdict()\n",
"\n",
"pprint.pprint(result)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.8.10 64-bit",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.4"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}