API
Provides tools for working with Gopher maps.
GopherItem
A class for holding an item in the Gopher map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The line of text from the Gopher map. |
required |
|
bool
|
Whether to be strict about parsing the Gopher item. |
False
|
Raises:
| Type | Description |
|---|---|
NoFields
|
If the line is missing a tab character and strict mode is enabled. |
UnknownItemType
|
If the item type is unknown and strict mode is enabled. |
GopherMap
A class for parsing and holding a Gopher map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The text of the Gopher map. |
required |
|
bool
|
Whether to be strict about parsing the Gopher map. |
False
|
has_error
cached
property
has_error: bool
Whether the Gopher map contains an error item.
Raises:
| Type | Description |
|---|---|
EmptyMap
|
If the map is empty and strict mode is enabled. |
NoFields
|
If the line is missing a tab character and strict mode is enabled. |
UnknownItemType
|
If the item type is unknown and strict mode is enabled. |
Note
The mentioned exceptions will be raised on accessing this
property, if in strict mode. If you wish to check for errors
without raising exceptions, use the is_likely_error class
method, to test instead.
items
cached
property
items: tuple[GopherItem, ...]
The list of Gopher items in the map.
Raises:
| Type | Description |
|---|---|
EmptyMap
|
If the map is empty and strict mode is enabled. |
NoFields
|
If the line is missing a tab character and strict mode is enabled. |
UnknownItemType
|
If the item type is unknown and strict mode is enabled. |
is_likely_a_map
classmethod
GopherMapError
Bases: Exception
Base class for Gopher map errors.
ItemType
Bases: StrEnum
An enumeration for the different types of Gopher items.
AUDIO
class-attribute
instance-attribute
AUDIO = 's'
An audio file.
BINARY
class-attribute
instance-attribute
BINARY = '9'
A binary file.
BINHEX
class-attribute
instance-attribute
BINHEX = '4'
A BinHexed file.
CSO
class-attribute
instance-attribute
CSO = '2'
A CSO phone book.
DOCUMENT
class-attribute
instance-attribute
DOCUMENT = 'd'
A document file.
DOS_FILE
class-attribute
instance-attribute
DOS_FILE = '5'
A DOS file.
ERROR
class-attribute
instance-attribute
ERROR = '3'
An error message.
GIF
class-attribute
instance-attribute
GIF = 'g'
A GIF image.
HTML
class-attribute
instance-attribute
HTML = 'h'
An HTML file.
IMAGE
class-attribute
instance-attribute
IMAGE = 'I'
An image file.
INDEX_SEARCH
class-attribute
instance-attribute
INDEX_SEARCH = '7'
An index search.
INFO
class-attribute
instance-attribute
INFO = 'i'
An informational message.
MENU
class-attribute
instance-attribute
MENU = '1'
A menu.
PDF
class-attribute
instance-attribute
PDF = 'P'
A PDF file.
TELNET
class-attribute
instance-attribute
TELNET = '8'
A telnet session.
TEXT
class-attribute
instance-attribute
TEXT = '0'
A text file.
UNKNOWN
class-attribute
instance-attribute
UNKNOWN = 'unknown'
An unknown type.
UUENCODED
class-attribute
instance-attribute
UUENCODED = '6'
A uuencoded file.
XML
class-attribute
instance-attribute
XML = 'X'
An XML file.
mime_type
property
mime_type: str
Get the MIME type for the item type.
Note
This is a best-effort mapping and may not be accurate for all item types.