-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
executable file
·176 lines (132 loc) · 4.48 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/env python3
import os
import sys
import time
import resource
import json
import gc
from ctypes import *
from reliq import *
from memory_profiler import profile
from functools import lru_cache
html_data = None
with open("index.html", "r") as f:
html_data = f.read()
# cat /proc/$(pidof python3)/status | grep ^VmRSS
# watch -n 0.2 ps -vp '$(pidof python)'
def trace(x1, x2, x3):
pass
sys.settrace(trace)
class rstr:
def __init__(
self, string, size=0, selfallocated=False
):
if isinstance(string, str):
string = string.encode("utf-8")
if isinstance(string, bytes):
if size == 0:
size = len(string)
self.size = size
self.data = create_string_buffer(string)
def __str__(self):
string = self.string
if isinstance(string, c_void_p):
string = string_at(string, self.size).decode()
return string.decode()
def __del__(self):
pass
# print("str type {}".format(type(self.string)))
# print("str type str {}".format(id(self.string)))
class nstr:
def __init__(self, html):
self.data = rstr(html, len(html))
@profile
def run():
ob = html_data
for j in range(1,10):
x = reliq(ob)
for i in range(1,50):
x.search("div; a")
type(x.search("noone"))
def run2():
for i in range(0, 1):
run()
print(sum(sys.getsizeof(i) for i in gc.get_objects()))
#input("start")
run2()
gc.collect()
print(sum(sys.getsizeof(i) for i in gc.get_objects()))
#input("end")
rq = reliq(html_data)
x = rq.filter('ul')
assert len(x.self()) == 4
assert len(x.children()) == 48
assert len(x.descendants()) == 152
assert len(x.full()) == 156
assert x[0].starttag() == "<ul>"
assert x[0].endtag() == "</ul>"
assert x[0].endtag(True) == "/ul"
assert x[0].starttag(raw=True) == b"<ul>"
assert x[0].endtag(raw=True) == b"</ul>"
assert x[0].endtag(True,raw=True) == b"/ul"
t = x[1].attribs()
assert len(t.keys()) == 1 or t['href'] != '/index.html'
t = x[1].attribs(raw=True)
assert len(t.keys()) == 1 or t[b'href'] != b'/index.html'
assert x[1].attribsl() == 1
assert rq[1].text_count() == 139
assert rq[1].tag_count() == 147
assert rq[1].comment_count() == 2
assert rq[1].desc() == 288
assert rq[1].lvl() == 0
assert x[1].lvl() == 1
assert x[1].insides() == "<li>🏡 Home</li>"
assert x[1].tag() == "a"
assert x[1].insides(raw=True) == b"<li>\xf0\x9f\x8f\xa1 Home</li>"
assert x[1].tag(raw=True) == b"a"
assert rq[0].type() in reliq.Type.comment
assert rq[1].type() in reliq.Type.tag
assert rq[2].type() in reliq.Type.textempty
assert rq[2].type() in reliq.Type.textall
assert rq[2].type() not in reliq.Type.text
assert rq[0].insides() == "DOCTYPE HTML"
assert rq[2].insides() == None
assert rq[0].insides(raw=True) == b"DOCTYPE HTML"
assert rq[2].insides(raw=True) == None
x = rq.filter('ul',True)
assert x[0][0].insides() == "<li>🏡 Home</li>"
assert x[1].attribs()['href'] == '/index.html'
assert x[0][0].insides(raw=True) == b"<li>\xf0\x9f\x8f\xa1 Home</li>"
assert x[1].attribs(raw=True)[b'href'] == b'/index.html'
assert len(x[0].children()) == 9
assert len(x[0].self()) == 1
assert len(x[0].descendants()) == 31
assert len(x[0].full()) == 32
assert len(x[0]) == 31
assert len(x[1]) == 2
assert len(x[2]) == 1
assert len(rq[0]) == 0
assert len(rq[1]) == 288
assert x[2].text() == "🏡 Home"
assert x[3].text() == "🏡 Home"
assert x[2].text(raw=True) == b"\xf0\x9f\x8f\xa1 Home"
assert x[3].text(raw=True) == b"\xf0\x9f\x8f\xa1 Home"
assert rq[253].text() == "BTC: () bc1qw5w6pxsk3aj324tmqrhhpmpfprxcfxe6qhetuv"
assert rq[253].text(True) == "BTC: (QR) bc1qw5w6pxsk3aj324tmqrhhpmpfprxcfxe6qhetuv"
assert len(rq[1].text(True)) == 2117
assert rq[253].text(raw=True) == b"BTC: () bc1qw5w6pxsk3aj324tmqrhhpmpfprxcfxe6qhetuv"
assert rq[253].text(True,raw=True) == b"BTC: (QR) bc1qw5w6pxsk3aj324tmqrhhpmpfprxcfxe6qhetuv"
assert reliq.decode('loop & < ⃛ Ô') == "loop & < ⃛⃛ Ô"
assert reliq.decode('loop & < ⃛ Ô',raw=True) == b"loop & < \xe2\x83\x9b\xe2\x83\x9b \xc3\x94"
reliq.expr('li')
reliq.expr(b'li')
try:
reliq.expr('li @self')
except reliq.ScriptError as e:
pass
else:
assert False
assert rq.search(r'ul; [0] img | "%(src)v"') == "pix/git.svg"
assert rq.search(rb'ul; [0] img | "%(src)v"') == "pix/git.svg"
assert rq.search(r'ul; [0] img | "%(src)v"',raw=True) == b"pix/git.svg"
assert rq.json('.r a c@[0]; { .name @ | "%Di" trim, .link @ | "%(href)v" } |')['r'][18]['link'] == 'pix/xmr.png'