API Reference
gophient
- Python library to browse the Gopherspace.
Its code is separated into submodules
gophient.const
- Constant values likeSEPARATOR
orTYPES
.gophient.exc
- Exceptions that derive fromGopherError
.gophient.types
- This submodule contains everything you usually work with.
types
gophient.types
- Types that implement the main logic.
Gopher
Gopher client.
Initialize a client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout |
int
|
Socket timeout |
10
|
encoding |
str
|
Packet encoding |
'utf-8'
|
Source code in gophient/types.py
parse_response
Parse the server response.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resp |
ResponseType
|
Server response |
required |
Returns:
Type | Description |
---|---|
Union[List[Item], ResponseType]
|
A list of |
Source code in gophient/types.py
request
Request an address.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
host |
str
|
Server domain or IP address |
required |
path |
str
|
Request path |
'/'
|
port |
int
|
Server port |
70
|
query |
RequestType
|
Query |
''
|
Returns:
Type | Description |
---|---|
Union[list[Item], bytes]
|
A list of |
Source code in gophient/types.py
Item
dataclass
Item of a server response.
host
class-attribute
instance-attribute
The IP address or the domain name of a server that this item is pointing to.
path
class-attribute
instance-attribute
The path on a server that this item is pointing to.
port
class-attribute
instance-attribute
The port of a server that this item is pointing to.
pretty_type
class-attribute
instance-attribute
The human-readable item type. Possible values are const.TYPES
values.
raw_type
class-attribute
instance-attribute
The item type. Possible values are const.TYPES
keys.
__str__
Return a string representation of Item
.
Returns:
Type | Description |
---|---|
str
|
str |
Source code in gophient/types.py
follow
Follow the link.
Returns:
Type | Description |
---|---|
Union[List[Item], bytes]
|
A list of |
merge_messages
Merge two informational messages.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
item |
Item
|
Item |
required |
Raises:
Type | Description |
---|---|
TypeMismatchError
|
Can't merge items with wrong types |
Source code in gophient/types.py
parse
classmethod
Parse a raw ByteString
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client |
Gopher
|
Related client |
required |
raw |
ByteString
|
Data to parse |
required |
Returns:
Type | Description |
---|---|
Union[Item, None]
|
Union[Item, None] |
Source code in gophient/types.py
exc
gophient.exc
- Client exceptions.
GopherError
Bases: Exception
Base exception for gophient
.
TypeMismatchError
Bases: GopherError
Items' types mismatch.
Initialize an exception.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
got |
str
|
Item type |
required |
expected |
str
|
Expected type |
required |