1
1
from typing import TypeVar
2
- import lazy_import
3
2
4
3
import json
5
4
6
- pydash = lazy_import .lazy_module ("pydash" )
7
- import phpserialize
5
+ import pydash
8
6
import regex as re
9
- from lxml import etree
10
7
from ..core import ChepyCore , ChepyDecorators
11
8
12
9
CodeTidyT = TypeVar ("CodeTidyT" , bound = "CodeTidy" )
@@ -27,7 +24,9 @@ def minify_json(self) -> CodeTidyT:
27
24
>>> c = Chepy("/path/to/file.json").load_file()
28
25
>>> print(c.minify_json())
29
26
"""
30
- self .state = json .dumps (json .loads (self ._convert_to_str ()), separators = (',' , ':' ))
27
+ self .state = json .dumps (
28
+ json .loads (self ._convert_to_str ()), separators = ("," , ":" )
29
+ )
31
30
return self
32
31
33
32
@ChepyDecorators .call_stack
@@ -47,56 +46,6 @@ def beautify_json(self, indent: int = 2) -> CodeTidyT:
47
46
self .state = json .dumps (json .loads (self ._convert_to_str ()), indent = indent )
48
47
return self
49
48
50
- @ChepyDecorators .call_stack
51
- def minify_xml (self ) -> CodeTidyT :
52
- """Minify XML string
53
-
54
- Returns:
55
- Chepy: The Chepy object.
56
-
57
- Examples:
58
- >>> c = Chepy("/path/to/file.xml").load_file()
59
- >>> print(c.minify_xml())
60
- """
61
- parser = etree .XMLParser (remove_blank_text = True )
62
- self .state = etree .tostring (
63
- etree .fromstring (self ._convert_to_bytes (), parser = parser )
64
- )
65
- return self
66
-
67
- @ChepyDecorators .call_stack
68
- def beautify_xml (self ) -> CodeTidyT :
69
- """Beautify compressed XML
70
-
71
- Returns:
72
- Chepy: The Chepy object.
73
-
74
- Examples:
75
- >>> c = Chepy("/path/to/file.xml").load_file()
76
- >>> print(c.beautify_json())
77
- """
78
- self .state = etree .tostring (
79
- etree .fromstring (self ._convert_to_bytes ()), pretty_print = True
80
- )
81
- return self
82
-
83
- @ChepyDecorators .call_stack
84
- def php_deserialize (self ) -> CodeTidyT :
85
- """Deserialize php to dict
86
-
87
- Deserializes PHP serialized data, outputting keyed arrays as a python dict.
88
-
89
- Returns:
90
- Chepy: The Chepy object.
91
-
92
- Examples:
93
- >>> c = Chepy('a:3:{i:1;s:6:"elem 1";i:2;s:6:"elem 2";i:3;s:7:" elem 3";}')
94
- >>> c.php_deserialize()
95
- {1: b'elem 1', 2: b'elem 2', 3: b' elem 3'}
96
- """
97
- self .state = phpserialize .loads (self ._convert_to_bytes ())
98
- return self
99
-
100
49
@ChepyDecorators .call_stack
101
50
def to_upper_case (self , by : str = "all" ) -> CodeTidyT :
102
51
"""Convert string to uppercase
0 commit comments