-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #637 from Bidaya0/dongtai_engine/filter
Dongtai engine/filter
- Loading branch information
Showing
5 changed files
with
49 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from http.client import parse_headers | ||
#Request{method=GET, url=http://www.baidu.com/, tag=null} | ||
|
||
class JavaObjects: | ||
|
||
def __init__(self, objects_classname, objects_attrs): | ||
self.objects_classname = objects_classname | ||
self.objects_attrs = objects_attrs | ||
for name, value in objects_attrs: | ||
setattr(self, name, value) | ||
|
||
def __str__(self): | ||
attrs_string = ', '.join( | ||
[f'{name}={value}' for name, value in self.objects_attrs]) | ||
return f"{self.objects_classname}{{{attrs_string}}}" | ||
|
||
|
||
def parse_java_objects(objects_string: str): | ||
objects_classname = objects_string[:objects_string.index('{')] | ||
objects_attrstring = objects_string[objects_string.index('{'):] | ||
objects_attrs = [ | ||
attr.split('=', 2) | ||
for attr in objects_attrstring.strip('{}').split(', ') | ||
] | ||
return JavaObjects(objects_classname, objects_attrs) | ||
|
||
from io import BytesIO | ||
from tempfile import TemporaryFile | ||
def parse_headers_dict_from_bytes(header_bytes: str) -> dict: | ||
with TemporaryFile() as fp: | ||
fp.write(header_bytes) | ||
fp.seek(0) | ||
return dict(parse_headers(fp)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters