Skip to content

API

Provides tools for working with Gopher maps.

GopherItem

GopherItem(line: str, strict: bool = False)

A class for holding an item in the Gopher map.

Parameters:

Name Type Description Default

line

str

The line of text from the Gopher map.

required

strict

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.

display_text property

display_text: str

The display text of the Gopher item.

host property

host: str

The host of the Gopher item.

port property

port: int

The port of the Gopher item.

raw property

raw: str

The raw text of the Gopher item.

selector property

selector: str

The selector of the Gopher item.

type property

type: ItemType

The type of the Gopher item.

__repr__

__repr__() -> str

Return a string representation of the Gopher item.

GopherMap

GopherMap(map_text: str, strict: bool = False)

A class for parsing and holding a Gopher map.

Parameters:

Name Type Description Default

map_text

str

The text of the Gopher map.

required

strict

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.

raw property

raw: str

The raw text of the Gopher map.

is_likely_a_map classmethod

is_likely_a_map(text: str) -> bool

Determine if the text is likely a valid Gopher map.

Parameters:

Name Type Description Default

text

str

The text of the Gopher map.

required

Returns:

Type Description
bool

True if the text is likely a valid Gopher map, False otherwise.

is_likely_error classmethod

is_likely_error(text: str) -> bool

Determine if the text is likely a Gopher error message.

Parameters:

Name Type Description Default

text

str

The text to test.

required

Returns:

Type Description
bool

True if the text is likely a Gopher error message, False otherwise.

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 = '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.