Skip to content

Commit 4026359

Browse files
committed
Formatting
1 parent e724e5a commit 4026359

File tree

5 files changed

+21
-35
lines changed

5 files changed

+21
-35
lines changed

tests/test_common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import pytest
44
import xmltodict
5-
from xmlrpcproto.common import Binary, py2xml, xml2py
65
from lxml import etree
76

7+
from xmlrpcproto.common import Binary, py2xml, xml2py
88

99
CASES = [
1010
(

xmlrpcproto/client.py

+6-22
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
11
from typing import Iterable, List, Union, cast
22

33
from lxml.builder import E
4-
from lxml.etree import _Element, XMLParser, fromstring, tostring
4+
from lxml.etree import XMLParser, _Element, fromstring, tostring
55

6-
from .common import (
7-
XmlRpcTypes,
8-
XmlRpcStructType,
9-
py2xml,
10-
validate_schema,
11-
xml2py,
12-
)
13-
from .exceptions import (
14-
ParseError,
15-
ServerError,
16-
XMLRPCSystemError,
17-
xml2py_exception,
18-
)
6+
from .common import XmlRpcStructType, XmlRpcTypes, py2xml, validate_schema, xml2py
7+
from .exceptions import ParseError, ServerError, XMLRPCSystemError, xml2py_exception
198

209

21-
def build_xml(
22-
method_name: str, *args: Iterable[XmlRpcTypes]
23-
) -> Union[str, bytes]:
10+
def build_xml(method_name: str, *args: Iterable[XmlRpcTypes]) -> Union[str, bytes]:
2411
return b'<?xml version="1.0"?>\n' + tostring(
2512
E(
2613
"methodCall",
@@ -34,9 +21,7 @@ def build_xml(
3421
)
3522

3623

37-
def parse_xml(
38-
body: bytes, method_name: str, *, huge_tree=False
39-
) -> XmlRpcTypes:
24+
def parse_xml(body: bytes, method_name: str, *, huge_tree=False) -> XmlRpcTypes:
4025
parser = XMLParser(huge_tree=huge_tree)
4126
response = fromstring(body, parser)
4227
if not validate_schema(response):
@@ -60,6 +45,5 @@ def parse_xml(
6045
)
6146

6247
raise ParseError(
63-
f'Respond body for method "{method_name}" '
64-
"not contains any response."
48+
f'Respond body for method "{method_name}" ' "not contains any response."
6549
)

xmlrpcproto/common.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from typing import Any, Dict, List, Union, cast
77

88
from lxml.builder import E
9-
from lxml.etree import _Element, RelaxNG
9+
from lxml.etree import RelaxNG, _Element
1010

1111
NoneType = type(None)
1212

@@ -117,9 +117,7 @@ def xml2datetime(value: _Element) -> datetime:
117117
pass
118118

119119
raise ValueError(
120-
"It's impossible to parse dataetime with formats {}".format(
121-
TIME_FORMATS
122-
)
120+
"It's impossible to parse dataetime with formats {}".format(TIME_FORMATS)
123121
)
124122

125123

@@ -131,13 +129,15 @@ def xml2struct(element: _Element) -> XmlRpcStructType:
131129

132130
def xml2array(element: _Element) -> XmlRpcArrayType:
133131
values = cast(List[_Element], element.xpath("./data/value"))
132+
print(element, values)
134133
return [xml2py(i) for i in values]
135134

135+
136136
def unwrap_value(element: _Element):
137137
try:
138138
value = next(element.iterchildren())
139139
except StopIteration:
140-
value = element.text or ''
140+
value = element.text or ""
141141
return xml2py(value)
142142

143143

xmlrpcproto/exceptions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from lxml.etree import _Element
21
from lxml.builder import E
2+
from lxml.etree import _Element
33

44
from .common import py2xml
55

xmlrpcproto/server.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
from typing import Union, List, Mapping, Tuple, cast
1+
from typing import List, Mapping, Tuple, Union, cast
2+
23
from lxml.builder import E
3-
from lxml.etree import _Element, XMLParser, fromstring, tostring
4+
from lxml.etree import XMLParser, _Element, fromstring, tostring
45

56
from .common import XmlRpcTypes, py2xml, validate_schema, xml2py
67

78

89
def format_success(result: XmlRpcTypes) -> _Element:
9-
return E(
10-
"methodResponse", E("params", E("param", E("value", py2xml(result))))
11-
)
10+
return E("methodResponse", E("params", E("param", E("value", py2xml(result)))))
1211

1312

1413
def format_error(exception: Exception) -> _Element:
@@ -24,12 +23,15 @@ def parse_xml(xml_string: bytes) -> _Element:
2423

2524

2625
def build_xml(tree: _Element) -> Union[str, bytes]:
27-
return b'<?xml version="1.0"?>\n' + tostring(tree, encoding="ASCII")
26+
s = b'<?xml version="1.0"?>\n' + tostring(tree, encoding="ASCII")
27+
print(s)
28+
return s
2829

2930

3031
def parse_reqeuest(
3132
body: bytes, headers: Mapping[str, str]
3233
) -> Tuple[str, List[XmlRpcTypes]]:
34+
print(body)
3335
if b"xml" not in headers.get(b"content-type", b""):
3436
raise ValueError()
3537

0 commit comments

Comments
 (0)