Articles tagged with Python

Python tricks

Inspect TLS certificates with requests

Use the snippet below to capture and inspect the certificates of a distant site and its chain with requests.

import requests

HTTPResponse = requests.packages.urllib3.response.HTTPResponse
orig_HTTPResponse__init__ = HTTPResponse.__init__
def new_HTTPResponse__init__(self, *args, **kwargs):
    orig_HTTPResponse__init__(self, *args, **kwargs …

Read more...

Timeout a function in python

You can use signals and a context manager to acheive this. The idea is to register a function that will raise an exeption when the alarm signal is received and schedule the alarm signal for the timeout.

import signal
from contextlib import contextmanager


@contextmanager
def timeout(time):
    # Register a function …

Read more...

Extraire toutes les images encodées en base64 d'un SVG

Récemment, j'ai eu besoin d'intégrer un SVG dans un template Aurelia. Malheureusement, il contenait beaucoup d'images et elles étaient toutes incluses au format base64. Cela rendait le fichier quasiment inutilisable avec de gros pâtés qui empêchent de voir le code utile et d'ajouter les attributs « Aurelia » (comme if.bind). Heureusement …

Lire la suite…