modify __repr__ for Request and update readme

This commit is contained in:
Hedy Li 2021-07-26 15:13:59 +08:00
parent 5fcce53a23
commit 9da535413a
Signed by: hedy
GPG Key ID: B51B5A8D1B176372
3 changed files with 8 additions and 4 deletions

View File

@ -19,7 +19,9 @@ Try it in the REPL:
>>> import spartan
>>> req = spartan.Request("spartan.mozz.us")
>>> req
<Request spartan.mozz.us:300 / 0>
Request(host='spartan.mozz.us', port=300, path='/') data-length=0
>>> print(res)
'spartan.mozz.us / 0'
>>> res = req.send()
>>> res
2 text/gemini
@ -37,7 +39,7 @@ pip3 install spartan-py
## API
- `Request(host: str, port: int = 300, path: str = "/", data: str = "")`
- `.send() -> Response` - send the request
- `send() -> Response` - send the request
- `__repr__()`
- `__str__()`
- `Response(socket)`
@ -45,6 +47,8 @@ pip3 install spartan-py
- `close()` - close the socket
- `.status` - status code
- `.meta` - meta string for the status
- `.file` - socket file
- `.request` - the Request object for this response
- `__repr__()`
- `__str__()`
- `Status` - statuses

View File

@ -1,6 +1,6 @@
[tool.poetry]
name = "spartan-py"
version = "0.2.8"
version = "0.2.9"
description = "Library for spartan protocol"
authors = ["Hedy Li <hedy@tilde.cafe>"]
packages = [

View File

@ -13,7 +13,7 @@ class Request:
self.data = data
def __repr__(self):
return f"<Request {self.host} (port {self.port}) {self.path} {len(self.data)}>"
return f"Request(host='{self.host}', port={self.port}, path='{self.path}') data-length={len(self.data)}"
def __str__(self):
return f"{self.host} {self.path} {len(self.data)}"