LXML xpath extension library for ipaddress
Project description
LXML Extension Library for IP address
This library contains LXML extension functions that wrap the Python ipaddress library.
With this library in place, you can do XPath expressions to find IP items within our XML data. For example:
from lxml import etree
from lxml_xpath_ipaddress import ip_ns
# given "config" is an LXML XML structure, you can run the XPath to find all IPv4 network items:
config = etree.parse('tests/config.xml')
items = config.xpath('//*[ip:ip4-net(.)', namespaces=ip_ns)
print(items[0].text)
# >>> 10.10.0.0/16
# Find all items that are in either the 172.18/16 or 101.10.201/24 subnets
items = config.xpath('//*[ip:in-subnet(., "172.18.0.0/16") or ip:in-subnet(., "10.10.201.0/24")]',
namespaces=ip_ns)
print(items[0].text)
# >>> 172.18.1.1
Install
$ pip install lxml-xpath-ipaddress
LXML Extension Functions
Either IPv4 or IPv6
- ip-any(value)
- ip-net(value)
- ip-host(value)
IPv4
- ip4-any(value)
- ip4-net(value)
- ip4-host(value)
IPv6
- ip6-any(value)
- ip6-net(value)
- ip6-host(value)
Subnet Checking
- in-subnet(value, subnet-string)
Python Functions
The library contains these functions as general purpose functions as well, so that they can be used in other applications. See the module doc-strings for use.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file lxml-xpath-ipaddress-0.2.0.tar.gz
.
File metadata
- Download URL: lxml-xpath-ipaddress-0.2.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0db34d6d4277c243cf9cf750434b7d30f3c3dfff53b82f4f2f849b9d00a77be8 |
|
MD5 | 37eb270c828cd227fed2a292c52fb526 |
|
BLAKE2b-256 | d53895de062ae456792bd8ece586b1d648f305167a0705320ed53cae631522d1 |
File details
Details for the file lxml_xpath_ipaddress-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: lxml_xpath_ipaddress-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 181445ce60bf6f9eb8bc1594d287577122af60bc31f7c7c59d7bc3240347ea21 |
|
MD5 | 5ddec8f6cc83922124f6a708769469c4 |
|
BLAKE2b-256 | 3430ab0c1dc10730c4bb6dadfbd7a52309d932f73195e7259c0c4656d91700d1 |