1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00

rename List class to _List for documentation purposes

This commit is contained in:
Kelly Brazil
2024-02-12 15:05:44 -08:00
parent f1177a2606
commit 8ead7e4835
4 changed files with 26 additions and 26 deletions

View File

@ -33,7 +33,7 @@ Schema:
"maximum_height": integer,
"devices": [
{
"modes": [
"resolution_modes": [
{
"resolution_width": integer,
"resolution_height": integer,
@ -82,7 +82,7 @@ Examples:
"maximum_height": 32767,
"devices": [
{
"modes": [
"resolution_modes": [
{
"resolution_width": 1920,
"resolution_height": 1080,
@ -143,7 +143,7 @@ Examples:
"maximum_height": 32767,
"devices": [
{
"modes": [
"resolution_modes": [
{
"resolution_width": 1920,
"resolution_height": 1080,
@ -199,7 +199,7 @@ Examples:
### parse
```python
def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict
def parse(data: str, raw: bool = False, quiet: bool = False) -> Response
```
Main text parsing function
@ -219,4 +219,4 @@ Compatibility: linux, darwin, cygwin, aix, freebsd
Source: [`jc/parsers/xrandr.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/xrandr.py)
Version 1.4 by Kevin Lyter (code (at) lyterk.com)
Version 2.0 by Kevin Lyter (code (at) lyterk.com)

View File

@ -354,7 +354,7 @@ class LineType(Enum):
Invalid = 6
class Line:
class _Line:
"""Provide metadata about line to make handling it more simple across fn boundaries"""
def __init__(self, s: str, t: LineType, m: Match):
@ -363,7 +363,7 @@ class Line:
self.m = m
@classmethod
def categorize(cls, line: str) -> "Line":
def categorize(cls, line: str) -> "_Line":
"""Iterate through line char by char to see what type of line it is. Apply regexes for more distinctness. Save the regexes and return them for later processing."""
i = 0
tab_count = 0
@ -410,7 +410,7 @@ class Line:
raise Exception(f"Line could not be categorized: '{line}'")
def _parse_screen(line: Line) -> Screen:
def _parse_screen(line: _Line) -> Screen:
d = line.m.groupdict()
screen: Screen = {"devices": []} # type: ignore # Will be populated, but not immediately.
@ -420,7 +420,7 @@ def _parse_screen(line: Line) -> Screen:
return screen
def _parse_device(line: Line) -> Device:
def _parse_device(line: _Line) -> Device:
matches = line.m.groupdict()
device: Device = {
@ -450,7 +450,7 @@ def _parse_device(line: Line) -> Device:
return device
def _parse_resolution_mode(line: Line) -> ResolutionMode:
def _parse_resolution_mode(line: _Line) -> ResolutionMode:
frequencies: List[Frequency] = []
d = line.m.groupdict()
@ -483,7 +483,7 @@ def _parse_resolution_mode(line: Line) -> ResolutionMode:
return mode
def _parse_props(index: int, line: Line, lines: List[str]) -> Tuple[int, Props]:
def _parse_props(index: int, line: _Line, lines: List[str]) -> Tuple[int, Props]:
tmp_props: Dict[str, List[str]] = {}
key = ""
while index <= len(lines):
@ -504,7 +504,7 @@ def _parse_props(index: int, line: Line, lines: List[str]) -> Tuple[int, Props]:
break
index += 1
try:
line = Line.categorize(lines[index])
line = _Line.categorize(lines[index])
except:
pass
@ -545,7 +545,7 @@ def parse(data: str, raw: bool = False, quiet: bool = False) -> Response:
result: Response = {"screens": []}
if jc.utils.has_data(data):
while index < len(lines):
line = Line.categorize(lines[index])
line = _Line.categorize(lines[index])
if line.t == LineType.Screen:
screen = _parse_screen(line)
result["screens"].append(screen)

View File

@ -1,4 +1,4 @@
.TH jc 1 2024-02-10 1.25.1 "JSON Convert"
.TH jc 1 2024-02-12 1.25.1 "JSON Convert"
.SH NAME
\fBjc\fP \- JSON Convert JSONifies the output of many CLI tools, file-types,
and strings

View File

@ -6,7 +6,7 @@ from typing import Optional
from jc.parsers.xrandr import (
Device,
Edid,
Line,
_Line,
LineType,
ResolutionMode,
Response,
@ -71,16 +71,16 @@ class XrandrTests(unittest.TestCase):
prop_value = " 00ffffffffffff0006af3d5700000000"
invalid = ""
self.assertEqual(LineType.Device, Line.categorize(base).t)
self.assertEqual(LineType.ResolutionMode, Line.categorize(resolution_mode).t)
self.assertEqual(LineType.PropKey, Line.categorize(prop_key).t)
self.assertEqual(LineType.PropValue, Line.categorize(prop_value).t)
self.assertEqual(LineType.Device, _Line.categorize(base).t)
self.assertEqual(LineType.ResolutionMode, _Line.categorize(resolution_mode).t)
self.assertEqual(LineType.PropKey, _Line.categorize(prop_key).t)
self.assertEqual(LineType.PropValue, _Line.categorize(prop_value).t)
with self.assertRaises(Exception):
Line.categorize(invalid)
_Line.categorize(invalid)
def test_screens(self):
sample = "Screen 0: minimum 8 x 8, current 1920 x 1080, maximum 32767 x 32767"
line = Line.categorize(sample)
line = _Line.categorize(sample)
actual: Optional[Screen] = _parse_screen(line)
self.assertIsNotNone(actual)
@ -100,7 +100,7 @@ class XrandrTests(unittest.TestCase):
sample = (
"Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 16384 x 16384"
)
line = Line.categorize(sample)
line = _Line.categorize(sample)
actual = _parse_screen(line)
if actual:
self.assertEqual(320, actual["minimum_width"])
@ -110,7 +110,7 @@ class XrandrTests(unittest.TestCase):
def test_device(self):
# regex101 sample link for tests/edits https://regex101.com/r/3cHMv3/1
sample = "eDP1 connected primary 1920x1080+0+0 left (normal left inverted right x axis y axis) 310mm x 170mm"
line = Line.categorize(sample)
line = _Line.categorize(sample)
actual: Optional[Device] = _parse_device(line)
expected = {
@ -143,7 +143,7 @@ class XrandrTests(unittest.TestCase):
def test_device_with_reflect(self):
sample = "VGA-1 connected primary 1920x1080+0+0 left X and Y axis (normal left inverted right x axis y axis) 310mm x 170mm"
line = Line.categorize(sample)
line = _Line.categorize(sample)
actual: Optional[Device] = _parse_device(line)
expected = {
@ -177,7 +177,7 @@ class XrandrTests(unittest.TestCase):
"resolution_height": 1080,
"is_high_resolution": False,
}
line = Line.categorize(sample_1)
line = _Line.categorize(sample_1)
actual: Optional[ResolutionMode] = _parse_resolution_mode(line)
self.assertIsNotNone(actual)
@ -187,7 +187,7 @@ class XrandrTests(unittest.TestCase):
self.assertEqual(v, actual[k], f"mode regex failed on {k}")
sample_2 = " 1920x1080i 60.00 50.00 59.94"
line = Line.categorize(sample_2)
line = _Line.categorize(sample_2)
actual: Optional[ResolutionMode] = _parse_resolution_mode(line)
self.assertIsNotNone(actual)
if actual: