Reference
Bases: ABC
Abstract class representing a messagable target.
Source code in hoist/_messages.py
message(msg, data=None, replying=None, listeners=None)
async
abstractmethod
Send a message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
msg |
str
|
Message content. |
required |
data |
Optional[Payload]
|
Payload to include with the message. |
None
|
replying |
Optional[Message]
|
Message to reply to. |
None
|
listeners |
Optional[MessageListeners]
|
Extra listeners to include. |
None
|
Returns:
Type | Description |
---|---|
Message
|
Created message. |
Source code in hoist/_messages.py
message_later(msg=None, data=None, replying=None)
async
Send a message after the context has finished.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
msg |
Optional[str]
|
Message content. |
None
|
data |
Optional[Payload]
|
Payload to include with the message. |
None
|
replying |
Optional[Message]
|
Message to reply to. |
None
|
Source code in hoist/_messages.py
pend_message(msg=None, data=None, replying=None)
async
Get a message to be sent later.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
msg |
Optional[str]
|
Message content. |
None
|
data |
Optional[Payload]
|
Payload to include with the message. |
None
|
replying |
Optional[Message]
|
Message to reply to. |
None
|
Source code in hoist/_messages.py
Base class for handling message listening.
Source code in hoist/_messages.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
|
create_message(conn, data)
async
Build a message from a payload.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conn |
BaseMessagable
|
Messagable connection target. |
required |
data |
Payload
|
Payload to create the message from. |
required |
Source code in hoist/_messages.py
create_or_lookup(conn, content, message_data, id, replying, *, listeners=None)
async
Create a new message wtih the specified ID, or look it up if it already exists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conn |
BaseMessagable
|
Messagable connection target. |
required |
content |
str
|
Message content. |
required |
message_data |
Payload
|
Payload to include with the message. |
required |
id |
int
|
ID of the message: |
required |
replying |
Optional[Union[Message, dict]]
|
Message that the target is replying to. |
required |
listeners |
Optional[MessageListeners]
|
Extra message listeners. |
None
|
Returns:
Type | Description |
---|---|
Message
|
Created message. |
Source code in hoist/_messages.py
current_id()
property
lookup(id)
async
Lookup a message by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id |
int
|
ID of the message to lookup. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
Message ID does not exist. |
Source code in hoist/_messages.py
message_listeners()
writable
property
new_message(conn, content, message_data, replying, *, id=None, listeners=None)
async
Create a new message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conn |
BaseMessagable
|
Messagable connection target. |
required |
content |
str
|
Message content. |
required |
message_data |
Payload
|
Payload to include with the message. |
required |
id |
Optional[int]
|
ID of the message: |
None
|
replying |
Optional[Union[Message, dict]]
|
Message that the target is replying to. |
required |
listeners |
Optional[MessageListeners]
|
Extra message listeners. |
None
|
Returns:
Type | Description |
---|---|
Message
|
Created message. |
Raises:
Type | Description |
---|---|
ValueError
|
Message ID is already in use. |
Source code in hoist/_messages.py
receive(message=None, parameter=None)
Add a listener for message receiving.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message |
Optional[Union[str, Tuple[str, ...]]]
|
Message to listen for. |
None
|
parameter |
Optional[Union[Schema, T]]
|
Parameter type to use. |
None
|
Source code in hoist/_messages.py
Server
Bases: MessageListener
Class for handling a server.
Source code in hoist/server.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 |
|
__init__(token=None, *, default_token_len=25, default_token_choices=ascii_letters, hide_token=False, login_func=_base_login, log_level=None, minimum_version=None, extra_operations=None, unsupported_operations=None, supported_operations=None, extra_listeners=None, fancy=None, disable_builtins=False)
Constructor for Server
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token |
Optional[str]
|
Token to use on the server. |
None
|
default_token_len |
int
|
Length of autogenerated token. |
25
|
default_token_choices |
SupportsLenAndGetItem[str]
|
Choices to use for the autogenerated token. |
ascii_letters
|
hide_token |
bool
|
Should the token be hidden from the startup message. |
False
|
login_func |
LoginFunc
|
Function to use to handles logins to the server. |
_base_login
|
minimum_version |
Optional[VersionLike]
|
Minimum version of Hoist required to connect. |
None
|
extra_operations |
Optional[Operations]
|
Extra operations to include on the server. |
None
|
unsupported_operations |
Optional[Sequence[str]]
|
Operations not supported by the server. |
None
|
supported_operations |
Optional[Sequence[str]]
|
Operations supported by the server. |
None
|
extra_listeners |
Optional[MessageListeners]
|
Extra message listeners. |
None
|
fancy |
Optional[bool]
|
Should the server run in fancy mode. |
None
|
disable_builtins |
bool
|
Should all builtin operations be disabled. |
False
|
Source code in hoist/server.py
broadcast(message, payload=None)
async
Send a message to all connections.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message |
str
|
Message to send. |
required |
payload |
Optional[Payload]
|
Payload to include. |
None
|
Example
Source code in hoist/server.py
close()
Close the server.
Raises:
Type | Description |
---|---|
ServerNotStartedError
|
Server is not started. |
Source code in hoist/server.py
fancy()
property
operation(name)
Add a function for an operation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
Name of the operation. |
required |
Source code in hoist/server.py
running()
property
start(*, host='0.0.0.0', port=5000, fancy=None)
Start the server.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
host |
str
|
Where to host the server. |
'0.0.0.0'
|
port |
int
|
Port to put the server on. |
5000
|
fancy |
Optional[bool]
|
Should the server run in fancy mode. When |
None
|
Raises:
Type | Description |
---|---|
AlreadyInUseError
|
Server is already running. |
RuntimeError
|
Attempted to start the server from a running event loop. |
Source code in hoist/server.py
stop()
supported_operations()
property
token()
property
Connection
Bases: BaseMessagable
, MessageListener
Class handling a connection to a server.
Source code in hoist/client.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
|
__init__(url, token=None, *, loop=None, session=None, extra_listeners=None, minimum_version=None)
Constructor for Connection
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
UrlLike
|
URL to connect to. |
required |
token |
Optional[str]
|
Token to connect with. |
None
|
loop |
Optional[asyncio.AbstractEventLoop]
|
Event loop to use. |
None
|
session |
Optional[aiohttp.ClientSession]
|
|
None
|
extra_listeners |
Optional[MessageListeners]
|
Extra message listeners. |
None
|
minimum_version |
Optional[VersionLike]
|
Minimum version required to connect to the server. |
None
|
Source code in hoist/client.py
close()
async
Close the connection.
Source code in hoist/client.py
close_sync()
Close the client synchronously.
Source code in hoist/client.py
closed()
property
connect(token=None)
async
Open the connection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token |
Optional[str]
|
Token to connect with. When |
None
|
Raises:
Type | Description |
---|---|
AlreadyConnectedError
|
Already connected to the server. |
ServerConnectError
|
Something went wrong when connecting. |
ValueError
|
Both the |
Source code in hoist/client.py
connected()
property
get(url)
async
message(msg, data=None, replying=None, listeners=None)
async
Send a message to the server.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
msg |
str
|
Content of the message. |
required |
data |
Optional[Payload]
|
Payload to include with the message. |
None
|
replying |
Optional[Message]
|
Message object to reply to. |
None
|
listeners |
Optional[MessageListeners]
|
Message listeners to add before dispatching. |
None
|
Returns:
Type | Description |
---|---|
Message
|
Created message. |
Raises:
Type | Description |
---|---|
NotConnectedError
|
Not connected to the server. |
Source code in hoist/client.py
opened()
property
operation(name, payload=None, **payload_json)
async
Execute an operation on the server.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
Name of the operation to execute. |
required |
payload |
Optional[Payload]
|
Payload to send. |
None
|
Raises:
Type | Description |
---|---|
NotConnectedError
|
Not connected to the server. |
ValueError
|
Specified operation is not valid. |
ServerResponseError
|
Arbitrary server response error. |
Source code in hoist/client.py
print(text)
async
read(path)
async
token()
property
connect(token, url='http://localhost:5000', **kwargs)
async
Connect to a Hoist server.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token |
str
|
Token to use when connecting. |
required |
url |
UrlLike
|
Target server URL. |
'http://localhost:5000'
|
Source code in hoist/utils.py
connect_directly(token, url='http://localhost:5000', **kwargs)
async
Connect to a Hoist server without a context manager.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token |
str
|
Token to use when connecting. |
required |
url |
UrlLike
|
Target server URL. |
'http://localhost:5000'
|
Source code in hoist/utils.py
connect_with(token, url='http://localhost:5000', **kwargs)
Call a function with the connection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token |
str
|
Token to use when connecting. |
required |
url |
UrlLike
|
Target server URL. |
'http://localhost:5000'
|
Source code in hoist/utils.py
debug(*, trace=False, enable_uvicorn=False)
Enable debug logging.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trace |
Union[bool, str]
|
Should debug tracing should be enabled. |
False
|
enable_uvicorn |
bool
|
Should uvicorn logs be enabled. |
False
|
Source code in hoist/utils.py
main(func)
Run a main async function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
Callable[[], Coroutine[Any, Any, Any]]
|
Function to call. |
required |
Source code in hoist/utils.py
serve(token=None, server=None, *, host='0.0.0.0', port=5000, **kwargs)
Serve a Hoist server.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token |
Optional[str]
|
Token to use on the server. |
None
|
server |
Optional[Server]
|
Existing server to use. |
None
|
host |
str
|
Where to host the server. |
'0.0.0.0'
|
port |
int
|
What port to put the server on. |
5000
|
Source code in hoist/utils.py
start(token=None, server=None, *, host='0.0.0.0', port=5000, fancy=False, **kwargs)
Start a Hoist server.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token |
Optional[str]
|
Token to use on the server. |
None
|
server |
Optional[Server]
|
Existing server to use. |
None
|
host |
str
|
Where to host the server. |
'0.0.0.0'
|
port |
int
|
What port to put the server on. |
5000
|
fancy |
bool
|
Whether fancy output should be enabled. |
False
|
Returns:
Type | Description |
---|---|
Server
|
Started server object. |
Source code in hoist/utils.py
AlreadyConnectedError
AlreadyInUseError
BadContentError
ClientError
CloseSocket
InternalServerError
InvalidOperationError
InvalidVersionError
NotConnectedError
SchemaValidationError
Bases: Exception
Schema validation failed.
Source code in hoist/exceptions.py
current()
property
format_current()
format_needed()
Format the needed type.
ServerConnectError
ServerLoginError
ServerNotStartedError
BaseMessage
Bases: MessageListener
, ABC
Base class for handling a message.
Source code in hoist/message.py
__init__(conn, msg, *, data=None, replying=None)
Construct for BaseMessage
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conn |
BaseMessagable
|
Messagable connection target. |
required |
msg |
str
|
Content of the message. |
required |
data |
Optional[Payload]
|
Payload included with the message. |
None
|
replying |
Optional[Message]
|
Message object that the current one is replying to. |
None
|
Source code in hoist/message.py
content()
property
data()
property
replying()
property
to_dict(convert_replies=True)
abstractmethod
Convert the message to a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
convert_replies |
bool
|
Should message objects under |
True
|
Returns:
Type | Description |
---|---|
dict
|
The created |
Source code in hoist/message.py
Message
Bases: BaseMessage
Object handling a message.
Source code in hoist/message.py
id()
property
reply(msg, data=None)
async
Reply to the current message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
msg |
str
|
Content to reply with. |
required |
data |
Optional[Payload]
|
Payload to include in the reply. |
None
|
Returns:
Type | Description |
---|---|
Message
|
Created message. |
Source code in hoist/message.py
PendingMessage
Bases: BaseMessage
Object handling a message that has not yet been sent to the server.