Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/karpetrosyan/rfcparser
Rfcparser is a Python tool that makes it easy to parse common RFC syntaxes. Rfcparser takes a raw string as input, parses, validates, and returns Python objects to simplify the processing of RFC syntaxes.
https://github.com/karpetrosyan/rfcparser
parsing rfc validator
Last synced: about 1 month ago
JSON representation
Rfcparser is a Python tool that makes it easy to parse common RFC syntaxes. Rfcparser takes a raw string as input, parses, validates, and returns Python objects to simplify the processing of RFC syntaxes.
- Host: GitHub
- URL: https://github.com/karpetrosyan/rfcparser
- Owner: karpetrosyan
- License: mit
- Created: 2023-01-27T13:04:56.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-02-18T18:15:20.000Z (over 1 year ago)
- Last Synced: 2024-10-08T00:41:29.772Z (about 1 month ago)
- Topics: parsing, rfc, validator
- Language: Python
- Homepage:
- Size: 67.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NOTE: Merged with [aioreq](https://github.com/karosis88/aioreq)
# Rfcparser
Rfcparser is a Python tool that makes it easy to parse common RFC syntaxes. Rfcparser takes a raw string as input, parses, validates, and returns Python objects to simplify the processing of RFC syntaxes.## Overview
This library uses grammar parsing mechanism to effectively parse various RFC syntaxes and make the information accessible in a usable format.### Examples
This is how **RFC 3986** defines URI syntax
```
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]hier-part = "//" authority path-abempty
/ path-absolute
/ path-rootless
/ path-emptyURI-reference = URI / relative-ref
absolute-URI = scheme ":" hier-part [ "?" query ]
...
```
This is how **rfcparser** does
```
uri : scheme ":" hier_part [ "?" query ] [ "#" fragment ]
hier_part : "//" authority path_abempty
| path_absolute
| path_rootless
| path_empty
uri_reference : uri | relative_refabsolute_uri : scheme ":" hier_part [ "?" query ]
...
```---
This is how **RFC 1034** defines domain syntax
```
::= | " "
::= | "."
::= [ [ ] ]
::= |
::= | "-"
::= |
::= any one of the 52 alphabetic characters A through Z in
upper case and a through z in lower case
```This is how **rfcparser** does
```
domain : subdomain | " "
subdomain : _label | subdomain "." _label
_label : _letter [ [ _ldh_str ] _let_dig ]
_ldh_str : _let_dig_hyp | _let_dig_hyp _ldh_str
_let_dig_hyp : _let_dig | "-"
_let_dig : _letter | DIGIT
_letter : /[a-zA-Z]/%import .rfc5234_core.DIGIT
```## Installing
```
$ pip install rfcparser
```
or```
$ git clone https://github.com/karosis88/rfcparser.git
$ pip install ./rfcparser
```## Usage
Examples and detailed instructions on how to use the Rfcparser library to parse RFC syntaxes.In most cases, you will primarily use the 'core' module, which offers a convenient interface for parsing your raw input string
``` python
>>> from rfcparser import core```
Rfcparser offers a specific class for each grammar, with a class name following the pattern of "`PREFIX PARSER RFC-NUMBER`"
Fortunately, most modern IDEs now offer autocompletion, which will assist you in locating the parser classes you need to use.
### URI parsing
``` python
>>> uri = "https://login:[email protected]:1010/path?name=test#fr"
>>> parsed_uri = core.UriParser3986().parse(uri)```
With Rfcparser, you now have access to a 'parsed_uri' that is not just a plain string, but rather a Python object. This makes it easier to work with the URI, and you don't need to worry about compatibility issues with other applications as the library parses syntaxes according to the latest RFC standards.
``` python
>>> parsed_uri.scheme
'https'
>>> parsed_uri.userinfo
'login:password'
>>> parsed_uri.ip
'127.0.0.1'
>>> parsed_uri.port
1010
>>> parsed_uri.path
'/path'
>>> parsed_uri.query
{'name': 'test'}
>>> parsed_uri.fragment
'fr'```
### Date-Time parser
``` python
>>> date_str = "Tue, 07-Feb-2023 13:20:04 GMT"
>>> parsed_date = core.DateParser6265().parse(date_str)
>>> type(parsed_date)>>> parsed_date.day
7```