mirror of
https://github.com/simon987/hexlib.git
synced 2025-04-10 06:06:41 +00:00
Add random_word & random_phrase
This commit is contained in:
parent
595fbc71be
commit
30854c7f8b
466469
hexlib/data/words.txt
Normal file
466469
hexlib/data/words.txt
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
|
from io import BytesIO
|
||||||
|
from tarfile import TarFile, TarInfo
|
||||||
|
|
||||||
|
|
||||||
def ftw(path):
|
def ftw(path):
|
||||||
@ -6,3 +8,22 @@ def ftw(path):
|
|||||||
for file in files:
|
for file in files:
|
||||||
yield os.path.join(cur, file)
|
yield os.path.join(cur, file)
|
||||||
|
|
||||||
|
|
||||||
|
def add_bytes_to_tar(tar: TarFile, filename: str, data: bytes):
|
||||||
|
buf = BytesIO()
|
||||||
|
buf.write(data)
|
||||||
|
buf.flush()
|
||||||
|
buf.seek(0)
|
||||||
|
|
||||||
|
info = TarInfo(name=filename)
|
||||||
|
info.size = len(data)
|
||||||
|
tar.addfile(info, buf)
|
||||||
|
|
||||||
|
|
||||||
|
def add_buf_to_tar(tar: TarFile, filename: str, buf: BytesIO):
|
||||||
|
buf.flush()
|
||||||
|
buf.seek(0)
|
||||||
|
|
||||||
|
info = TarInfo(name=filename)
|
||||||
|
info.size = len(buf.getvalue())
|
||||||
|
tar.addfile(info, buf)
|
||||||
|
@ -1,4 +1,23 @@
|
|||||||
|
import os
|
||||||
import random
|
import random
|
||||||
|
from functools import lru_cache
|
||||||
|
|
||||||
|
|
||||||
|
@lru_cache
|
||||||
|
def _words():
|
||||||
|
with open(os.path.join(os.path.dirname(__file__), "data/words.txt")) as f:
|
||||||
|
return [line.strip().lower() for line in f]
|
||||||
|
|
||||||
|
|
||||||
|
def random_word():
|
||||||
|
return random.choice(_words())
|
||||||
|
|
||||||
|
|
||||||
|
def random_phrase(words=10, capitalize=True, suffix="."):
|
||||||
|
phrase = " ".join(random_word() for _ in range(words))
|
||||||
|
if capitalize:
|
||||||
|
phrase = phrase.capitalize()
|
||||||
|
return phrase + suffix
|
||||||
|
|
||||||
|
|
||||||
def fuzz(buf: bytes, n: int, width: int):
|
def fuzz(buf: bytes, n: int, width: int):
|
||||||
|
6
setup.py
6
setup.py
@ -2,11 +2,15 @@ from setuptools import setup
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="hexlib",
|
name="hexlib",
|
||||||
version="1.12",
|
version="1.13",
|
||||||
description="Misc utility methods",
|
description="Misc utility methods",
|
||||||
author="simon987",
|
author="simon987",
|
||||||
author_email="me@simon987.net",
|
author_email="me@simon987.net",
|
||||||
packages=["hexlib"],
|
packages=["hexlib"],
|
||||||
|
include_package_data=True,
|
||||||
|
package_data={"": [
|
||||||
|
"data/*"
|
||||||
|
]},
|
||||||
install_requires=[
|
install_requires=[
|
||||||
"ImageHash", "influxdb", "siphash", "python-dateutil", "redis", "ujson"
|
"ImageHash", "influxdb", "siphash", "python-dateutil", "redis", "ujson"
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user