A minimal HTTP server in python. It sends a JSON Hello World for GET requests, and echoes back JSON for POST requests.
python server.py 8009
Starting httpd on port 8009...
curl http://localhost:8009
{"received": "ok", "hello": "world"}
| #!/usr/bin/env python | |
| # encoding: utf-8 | |
| from pprint import pformat, pprint | |
| import logging | |
| class PasswordMaskingFilter(logging.Filter): | |
| """Demonstrate how to filter sensitive data:""" |
| # e.g. Convert 4261160822 to 65020.10102 | |
| def convert_ASPLAIN_to_ASDOT(as_number): | |
| if not(isinstance(as_number, int)) or as_number < 0 or as_number > 4294967295: | |
| raise Exception('Invalid AS Number: must be int, must be greater than or equal to 0 and less than or equal to 4294967295') | |
| return '{}.{}'.format(as_number // 65536, as_number % 65536) | |
| # e.g. Convert 65020.10102 to 4261160822 | |
| def convert_ASDOT_to_ASPLAIN(as_dot_number): | |
| if not(isinstance(as_dot_number, str)) or as_dot_number.count('.') != 1: |
| # https://gist.github.com/althonos/6914b896789d3f2078d1e6237642c35c | |
| [metadata] | |
| name = {name} | |
| version = file: {name}/_version.txt | |
| author = Martin Larralde | |
| author-email = [email protected] | |
| home-page = https://github.com/althonos/{name} | |
| description = {description} | |
| long-description = file: README.md |
| pip install -r requirements.txt | |
| Requirement already satisfied: hvac==0.9.5 in ./venv/lib/python3.7/site-packages (from -r requirements.txt (line 1)) (0.9.5) | |
| Collecting nornir==3.0.0 | |
| Downloading nornir-3.0.0-py3-none-any.whl (29 kB) | |
| Requirement already satisfied: requests==2.22.0 in ./venv/lib/python3.7/site-packages (from -r requirements.txt (line 3)) (2.22.0) | |
| Requirement already satisfied: genie==20.4.1 in ./venv/lib/python3.7/site-packages (from -r requirements.txt (line 4)) (20.4.1) | |
| Requirement already satisfied: pyats in ./venv/lib/python3.7/site-packages (from -r requirements.txt (line 5)) (20.2.1) | |
| Requirement already satisfied: py-zabbix==1.1.5 in ./venv/lib/python3.7/site-packages (from -r requirements.txt (line 6)) (1.1.5) | |
| Requirement already satisfied: pytest==5.4.1 in ./venv/lib/python3.7/site-packages (from -r requirements.txt (line 7)) (5.4.1) | |
| Requirement already satisfied: genie.libs.parser==20.4 in ./venv/lib/python3.7/site-packages (from -r requirements.txt (line 8)) (20.4) |
| #=======================================================================# | |
| # extract_data.py # | |
| #=======================================================================# | |
| # usage: extract_data.py [-h] [-i INPUT_DIR] [-o OUTPUT_DIR] | |
| # | |
| # This program extracts provision numbers from a set of documents. | |
| # | |
| # optional arguments: | |
| # -h, --help show this help message and exit | |
| # -i INPUT_DIR, --input_dir INPUT_DIR |
A minimal HTTP server in python. It sends a JSON Hello World for GET requests, and echoes back JSON for POST requests.
python server.py 8009
Starting httpd on port 8009...
curl http://localhost:8009
{"received": "ok", "hello": "world"}
| The MIT License (MIT) | |
| Copyright (c) 2013 Michael E. Cotterell | |
| Permission is hereby granted, free of charge, to any person obtaining a copy | |
| of this software and associated documentation files (the "Software"), to deal | |
| in the Software without restriction, including without limitation the rights | |
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| copies of the Software, and to permit persons to whom the Software is | |
| furnished to do so, subject to the following conditions: |
| POST /InStock HTTP/1.1 | |
| Host: www.example.org | |
| Content-Type: application/soap+xml; charset=utf-8 | |
| Content-Length: nnn | |
| <?xml version="1.0"?> | |
| <soap:Envelope | |
| xmlns:soap="http://www.w3.org/2001/12/soap-envelope" | |
| soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> |
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| import re | |
| from tornado.web import RequestHandler, Application | |
| from tornado.websocket import WebSocketHandler | |
| from tornado.ioloop import IOLoop | |
| import socket | |
| import threading | |
| import Queue |
| #!/usr/bin/env python2 | |
| """ | |
| Other Repositories of python-ping | |
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
| * https://github.com/l4m3rx/python-ping supports Python2 and Python3 | |
| * https://bitbucket.org/delroth/python-ping |