Module vpe.channels

Development of channel support.

Channel

class vpe.channels.Channel(...)
Channel(
        net_address: str,
        drop: Optional[str] = None,
        noblock: Optional[bool] = None,
        waittime: Optional[int] = None,

Pythonic wrapper around a Vim channel.

Parameters

net_address

A network address of the form hostname:port.

drop

When to drop messages. Must be ‘auto’ or ‘never’.

noblock

Set to true to prevent blocking on on write operations.

waittime

Time to wait for a connection to succeed.

timeout_ms

Time to wait for blocking request.

Attributes

open

True if the channel is currently open.

vch: VimChannel:

The underlying VimChannel object.

Properties

property is_open bool

Test whether the channel is open.

Methods

close() None

Close the channel.

Related vim function = ch_close.

close_in() None

Close the input part of the channel.

Related vim function = ch_info.

connect()

If necessary, try to connect.

getbufnr(what: str) int

Get the number of the buffer thas is being used for what.

Related vim function = ch_getbufnr.

Parameters

what: str

The type of use. One of ‘err’, ‘out’ or an empty string.

info() dict

Get information about the channel.

Related vim function = ch_info.

Return value

A dictionary of information.

log(msg: str) None

Write a message to the channel log file (if open).

Related vim function = ch_log. Note that this always provides the channel argument.

Parameters

msg: str

The message to add to the log file.

on_close()

Handler for when channel is closed.

Not invoked when the close method is used.

Needs to be over-ridden in a subclass.

on_connect()

Handler for a new outgoing connection.

May be over-ridden in a subclass.

on_message(message: str)

Handler for messages not explicitly handled by read methods.

Needs to be over-ridden in a subclass.

The contents of message depend on the type of the channel. Note that for a raw channel, this is invoked when any amount of the input data stream has been received. It is up to the application code to buffer and decode the stream’s contents.

Parameters

message: str

The received message. This is always a string, even for raw channels. Vim replaces any NUL chracters with newlines, so pure binary messages cannot be handled using on_message.

read(timeout_ms: Optional[int] = None)

Read any available input.

send(message: Union[str, bytes]) None

Send a message to the server.

Related vim function = ch_sendraw.

Parameters

message: typing.Union[str, bytes]

The message to send to the server. A bytes value is converted to a Latin-1 string before sending.

settimeout(timeout_ms: Optional[int] = None)

Set the default teimout for the channel.

Related vim function = ch_setoptions.

Parameters

timeout_ms: typing.Optional[int]

Time to wait for blocking request.

status(part: Optional[str] = None) str

Get information about the channel.

Related vim function = ch_status.

Parameters

part: typing.Optional[str]

Which part of the channel to query; ‘err’ or ‘out’.

Return value

One of the strings ‘fail’, ‘open’, ‘buffered’ or ‘closed’.

JSChannel

class vpe.channels.JSChannel(...)
JSChannel(
        net_address: str,
        drop: Optional[str] = None,
        noblock: Optional[bool] = None,
        waittime: Optional[int] = None,

Pythonic wrapper around a Vim channel in javascript mode.

JsonChannel

class vpe.channels.JsonChannel(...)
JsonChannel(
        net_address: str,
        drop: Optional[str] = None,
        noblock: Optional[bool] = None,
        waittime: Optional[int] = None,

Pythonic wrapper around a Vim channel in json mode.

NLChannel

class vpe.channels.NLChannel(...)
NLChannel(
        net_address: str,
        drop: Optional[str] = None,
        noblock: Optional[bool] = None,
        waittime: Optional[int] = None,

Pythonic wrapper for a newline based channel.

RawChannel

class vpe.channels.RawChannel(...)
RawChannel(
        net_address: str,
        drop: Optional[str] = None,
        noblock: Optional[bool] = None,
        waittime: Optional[int] = None,

Pythonic wrapper for a raw channel.

SyncChannel

class vpe.channels.SyncChannel(...)
SyncChannel(
        net_address: str,
        drop: Optional[str] = None,
        noblock: Optional[bool] = None,
        waittime: Optional[int] = None,

Pythonic wrapper around a “json” or “js” channel.

Methods

evalexpr(expr: Any, timeout_ms: Optional[int] = None) Any

Evaluate an expression on the server.

Related vim function = ch_evalexpr.

Parameters

expr: typing.Any

The expression to send to the server for evaluation.

timeout_ms: typing.Optional[int]

Max time to wait for a response. This overrides the timeout_ms given at construction time.

sendexpr(...)
sendexpr(
        expr: Union[None, int, float, str, bool, List[Any], Dict[str, Any]]

Send an expression to the server.

Related vim function = ch_sendexpr.

Parameters

expr: typing.Union[NoneType, int, float, str, bool, typing.List[typing.Any], typing.Dict[str, typing.Any]]

The expression to send to the server.

VimChannel

class vpe.channels.VimChannel(varname: str)

Simple proxy for a Channel.

This manages keeping the underlying Vim channel object alive, by storing it in a global Vim variable.

Parameters

varname

The name of the a vim variable currently referencing the Channel.

Attributes

varname

The name of a Vim variable holding a reference to the underlying Vim channel object. This is provided for debugging purposes.

Properties

property chid

The ID for this channel.

property closed

True of the channel could not be opened or has been closed.

property info

Get the information for a channel.

Methods

close()

Mark as closed and release the underlying reference variable.