Skip to content

Commit

Permalink
Merge pull request #78 from libsese/fix-yaml
Browse files Browse the repository at this point in the history
fix-yaml
  • Loading branch information
SHIINASAMA authored Sep 28, 2024
2 parents 3af5ecd + 38c19db commit 2d11713
Show file tree
Hide file tree
Showing 10 changed files with 176 additions and 135 deletions.
12 changes: 11 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
black==24.8.0
certifi==2024.8.30
charset-normalizer==3.3.2
click==8.1.7
colorama==0.4.6
colorlog==6.8.2
gcovr==7.2
idna==3.10
Jinja2==3.1.4
lxml==5.2.1
MarkupSafe==2.1.5
mypy-extensions==1.0.0
packaging==24.1
pathspec==0.12.1
platformdirs==4.3.6
Pygments==2.17.2
PyYAML==6.0.1
requests==2.32.3
six==1.16.0
urllib3==2.2.3
websocket-client==1.7.0
requests==2.32.3
13 changes: 6 additions & 7 deletions scripts/base_conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,31 @@ def encode(num, alphabet=BASE62):
num, rem = divmod(num, base)
arr.append(alphabet[rem])
arr.reverse()
return ''.join(arr)
return "".join(arr)


def decode(string, alphabet=BASE62):
base = len(alphabet)
strlen = len(string)
num = 0

idx = 0
for char in string:
power = (strlen - (idx + 1))
num += alphabet.index(char) * (base ** power)
power = strlen - (idx + 1)
num += alphabet.index(char) * (base**power)
idx += 1

return num


class ConvTest(unittest.TestCase):
def test_decode_integer(self):
res = decode('ftXl')
res = decode("ftXl")
self.assertEqual(res, 7562611)

def test_encode_buffer(self):
res = encode(7562611)
self.assertEqual(res, 'ftXl')
self.assertEqual(res, "ftXl")


if __name__ == '__main__':
if __name__ == "__main__":
unittest.main()
44 changes: 22 additions & 22 deletions scripts/change_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,57 @@

# 测试当前目录
def test_root_path(path: str):
fileA = open(path + 'FileA.txt', 'wt')
fileB = open(path + 'FileB.txt', 'a')
fileA.write('Hello')
fileA = open(path + "FileA.txt", "wt")
fileB = open(path + "FileB.txt", "a")
fileA.write("Hello")
fileB.close()
fileA.close()
shutil.copyfile(path + 'FileA.txt', path + 'FileC.txt')
os.rename(path + 'FileB.txt', path + 'FileD.txt')
shutil.copyfile(path + "FileA.txt", path + "FileC.txt")
os.rename(path + "FileB.txt", path + "FileD.txt")


# 测试子目录
def test_sub_path(path: str):
subdir = path + 'subdir/'
subdir = path + "subdir/"
os.makedirs(subdir)
subA = open(subdir + 'subA.txt', 'wt')
subB = open(subdir + 'subB.txt', 'a')
subA.write('hello')
subA = open(subdir + "subA.txt", "wt")
subB = open(subdir + "subB.txt", "a")
subA.write("hello")
subB.close()
subA.close()


# 拷贝子目录文件至根目录
# copy $src/subA.txt to $dst/FileE.txt
def test_copy_cross_path(src: str, dst: str):
shutil.copyfile(src + 'subA.txt', dst + 'FileE.txt')
shutil.copyfile(src + "subA.txt", dst + "FileE.txt")


# 清理
def cleanup(path: str):
os.remove(path + 'FileA.txt')
os.remove(path + 'FileC.txt')
os.remove(path + 'FileD.txt')
os.remove(path + 'FileE.txt')
os.remove(path + 'subdir/' + 'subA.txt')
os.remove(path + 'subdir/' + 'subB.txt')
os.rmdir(path + 'subdir')
os.remove(path + "FileA.txt")
os.remove(path + "FileC.txt")
os.remove(path + "FileD.txt")
os.remove(path + "FileE.txt")
os.remove(path + "subdir/" + "subA.txt")
os.remove(path + "subdir/" + "subB.txt")
os.rmdir(path + "subdir")


def main():
# path = 'C:/temp/'
# path = '/tmp/'
path = sys.argv[1]
if not os.path.exists(path):
print('creating test dir')
print("creating test dir")
os.mkdir(path)
print('changing files')
print("changing files")
test_root_path(path)
test_sub_path(path)
test_copy_cross_path(path + 'subdir/', path)
test_copy_cross_path(path + "subdir/", path)
cleanup(path)
print('done')
print("done")


if __name__ == '__main__':
if __name__ == "__main__":
main()
8 changes: 4 additions & 4 deletions scripts/do_http2_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@


def on_nt(p: int):
conn = HTTPConnection('127.0.0.1', p)
conn.request('GET', '/')
conn = HTTPConnection("127.0.0.1", p)
conn.request("GET", "/")
resp = conn.getresponse()
print(resp.status)
print(resp.headers)
print(resp.read())


def on_unix(p: int):
os.system('curl --http2 http://127.0.0.1:{} -v -s'.format(p))
os.system("curl --http2 http://127.0.0.1:{} -v -s".format(p))


port = int(sys.argv[1])
if os.name == 'nt':
if os.name == "nt":
on_nt(port)
else:
on_unix(port)
2 changes: 1 addition & 1 deletion scripts/do_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ def test(port: str):
ws.close()


if __name__ == '__main__':
if __name__ == "__main__":
p = sys.argv[1]
test(p)
Loading

0 comments on commit 2d11713

Please sign in to comment.