pyfsd ¶
Root package of PyFSD.
Attributes:
Name | Type | Description |
---|---|---|
__version__ | str | Version of PyFSD. |
__main__ ¶
PyFSD entrypoint.
db_tables ¶
PyFSD database tables.
Attributes:
Name | Type | Description |
---|---|---|
metadata | MetaData | SQLAlchemy metadata. |
users_table | Table | Table used to store user info. |
Note
These databases were initialized in pyfsd.main.main
define ¶
PyFSD -- pyfsd.define package.
Most definition and utils.
broadcast ¶
The core of PyFSD broadcast system -- broadcast checker.
Attributes:
Name | Type | Description |
---|---|---|
BroadcastChecker | Type of a broadcast checker, used in pyfsd.factory.client.ClientFactory.broadcast. |
Example
ClientFactory.broadcast(..., check_func=at_checker)
all_ATC_checker ¶
A broadcast checker which only broadcast to ATC.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
to_client | Client | The dest client. | required |
Returns:
Type | Description |
---|---|
bool | The check result (send message to to_client or not). |
Source code in src/pyfsd/define/broadcast.py
124 125 126 127 128 129 130 131 132 133 |
|
all_pilot_checker ¶
A broadcast checker which only broadcast to pilot.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
to_client | Client | The dest client. | required |
Returns:
Type | Description |
---|---|
bool | The check result (send message to to_client or not). |
Source code in src/pyfsd/define/broadcast.py
136 137 138 139 140 141 142 143 144 145 |
|
at_checker ¶
A broadcast checker which checks visual range when dest startswith @.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_client | Optional[Client] | The from client. | required |
to_client | Client | The dest client. | required |
Returns:
Type | Description |
---|---|
bool | The check result (send message to to_client or not). |
Source code in src/pyfsd/define/broadcast.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
broadcast_checkers ¶
broadcast_checkers(*checkers: BroadcastChecker) -> BroadcastChecker
Create a set of broadcast.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
checkers | BroadcastChecker | The broadcast checkers. | () |
Returns:
Type | Description |
---|---|
BroadcastChecker | The broadcast checker. |
Source code in src/pyfsd/define/broadcast.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
broadcast_message_checker ¶
A broadcast checker which checks visual range while broadcasting message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_client | Optional[Client] | The from client. | required |
to_client | Client | The dest client. | required |
Returns:
Type | Description |
---|---|
bool | The check result (send message to to_client or not). |
Source code in src/pyfsd/define/broadcast.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
broadcast_position_checker ¶
A broadcast checker which checks visual range while broadcasting position.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_client | Optional[Client] | The from client. | required |
to_client | Client | The dest client. | required |
Returns:
Type | Description |
---|---|
bool | The check result (send message to to_client or not). |
Source code in src/pyfsd/define/broadcast.py
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 |
|
create_broadcast_range_checker ¶
create_broadcast_range_checker(visual_range: int) -> BroadcastChecker
Create a broadcast checker which checks visual range.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
visual_range | int | Visual range. | required |
Returns:
Type | Description |
---|---|
BroadcastChecker | The broadcast checker. |
Source code in src/pyfsd/define/broadcast.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
is_multicast ¶
Determine if dest callsign is multicast sign.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
callsign | str | The dest callsign. | required |
Returns:
Type | Description |
---|---|
bool | Is multicast or not. |
Source code in src/pyfsd/define/broadcast.py
166 167 168 169 170 171 172 173 174 175 |
|
check_dict ¶
Tools to perform runtime TypedDict type check.
It can be used to perform config check. Only TypedDict, Literal, NotRequired, Union, List and Dict are supported.
Attributes:
Name | Type | Description |
---|---|---|
DictStructure | Type of a object describes structure of a dict, can be TypedDict or dict. | |
TypeHint | Type of a type hint. |
Examples:
>>> list(check_simple_type(1, Union[int, str]))
[]
>>> list(check_simple_type(b"imbytes", Union[int, str]))
[VerifyTypeError('object', typing.Union[int, str], b'imbytes')]
>>> list(check_dict({ "a": 1 }, TypedDict("A", { "a": int })))
[]
>>> list(check_dict({ "a": "imstr" }, TypedDict("A", { "a": int })))
[VerifyTypeError("dict['a']", <class 'int'>, 'imstr')]
VerifyKeyError ¶
Bases: KeyError
A exception describes a missing or extra key in a dict.
Attributes:
Name | Type | Description |
---|---|---|
dict_name | str | The dict name. |
key | Hashable | The key name. |
type | Literal['missing', 'extra'] | Type of error, a missing or extra key found. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dict_name | str | The dict name. | required |
key | Hashable | The key name. | required |
type_ | Literal['missing', 'extra'] | Type of error, a missing or extra key found. | required |
Source code in src/pyfsd/define/check_dict.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
|
__eq__ ¶
Return self==other.
Source code in src/pyfsd/define/check_dict.py
191 192 193 194 195 196 197 |
|
__str__ ¶
__str__() -> str
Format a VerifyKeyError to string.
Returns:
Type | Description |
---|---|
str | The formatted string, includes name, error type |
Source code in src/pyfsd/define/check_dict.py
183 184 185 186 187 188 189 |
|
VerifyTypeError ¶
Bases: TypeError
A exception describes a value does not match specified type.
Attributes:
Name | Type | Description |
---|---|---|
name | str | The name of this value. |
excepted | TypeHint | The expected type. |
actually | object | The actually value. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | str | The name of the value. | required |
excepted | TypeHint | The expected type. | required |
actually | object | The actually value. | required |
Source code in src/pyfsd/define/check_dict.py
114 115 116 117 118 119 120 121 122 123 124 125 |
|
__eq__ ¶
Check if another object equals to this ConfigTypeError.
Returns:
Type | Description |
---|---|
bool | Equals or not. |
Source code in src/pyfsd/define/check_dict.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
__str__ ¶
__str__() -> str
Format a VerifyTypeError to string.
Returns:
Type | Description |
---|---|
str | The formatted string, includes name, expected type and actually value |
Source code in src/pyfsd/define/check_dict.py
127 128 129 130 131 132 133 134 135 136 |
|
assert_dict ¶
assert_dict(dict_obj: dict, structure: DictStructure, *, name: str = 'dict', allow_extra_keys: bool = False) -> None
Wrapper of check_dict, which raises once an error is generated.
Check type of a dict accord TypedDict.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dict_obj | dict | The dict to be checked. | required |
structure | DictStructure | Expected type. | required |
name | str | Name of the dict. | 'dict' |
allow_extra_keys | bool | Allow extra keys in dict_obj or not. | False |
Raises:
Type | Description |
---|---|
VerifyTypeError | When found type error. |
VerifyKeyError | When found a type error about key. |
TypeError | When an unsupported/invalid type passed. |
Source code in src/pyfsd/define/check_dict.py
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 |
|
assert_simple_type ¶
Wrapper of check_simple_type, but raise first error.
Simple runtime type checker, supports Union, Literal, List, Dict.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj | object | The object to be verified. | required |
typ | TypeHint | The expected type. Union, Literal, List, Dict or runtime checkable type | required |
name | str | Name of the object. | 'object' |
Raises:
Type | Description |
---|---|
VerifyTypeError | When a type error detected. |
TypeError | When an unsupported type is specified. |
Source code in src/pyfsd/define/check_dict.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
|
check_dict ¶
check_dict(dict_obj: dict, structure: DictStructure, *, name: str = 'dict', allow_extra_keys: bool = False) -> Iterable[Union[VerifyTypeError, VerifyKeyError]]
Check type of a dict accord TypedDict.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dict_obj | dict | The dict to be checked. | required |
structure | DictStructure | Expected type. | required |
name | str | Name of the dict. | 'dict' |
allow_extra_keys | bool | Allow extra keys in dict_obj or not. | False |
Yields:
Type | Description |
---|---|
Iterable[Union[VerifyTypeError, VerifyKeyError]] | Detected type error, in VerifyTypeError / VerifyKeyError |
Raises:
Type | Description |
---|---|
TypeError | When an unsupported/invalid type passed. |
Examples:
>>> class AType(TypedDict):
... a: int
...
>>> list(check_dict({ "a": 114514 }, AType, allow_extra_keys=False))
[]
>>> list(check_dict({ "a": "" }, AType, allow_extra_keys=False, name="mything"))
[VerifyTypeError("mything['a']", <class 'int'>, '')]
>>> list(check_dict({}, AType))
[VerifyKeyError('dict', 'a', 'missing')]
>>> list(check_dict(
... { "a": 114514, "b": 1919810 },
... AType,
... allow_extra_keys=True
... ))
[]
>>> list(check_dict(
... { "a": 114514, "b": 1919810 },
... AType,
... allow_extra_keys=False
... ))
[VerifyKeyError('dict', 'b', 'extra')]
Source code in src/pyfsd/define/check_dict.py
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 |
|
check_simple_type ¶
check_simple_type(obj: object, typ: TypeHint, name: str = 'object') -> Iterable[VerifyTypeError]
Simple runtime type checker, supports Union, Literal, List, Dict.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj | object | The object to be verified. | required |
typ | TypeHint | The expected type. Union, Literal, List, Dict or runtime checkable type | required |
name | str | Name of the object. | 'object' |
Yields:
Type | Description |
---|---|
Iterable[VerifyTypeError] | When a type error was detected. |
Raises:
Type | Description |
---|---|
TypeError | When an unsupported type is specified. |
Source code in src/pyfsd/define/check_dict.py
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 |
|
explain_type ¶
explain_type(typ: TypeHint) -> str
Explain a type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
typ | TypeHint | The type to be explained. | required |
Returns:
Type | Description |
---|---|
str | Description of the type. |
Raises:
Type | Description |
---|---|
TypeError | When an unsupported/invalid type passed. |
Source code in src/pyfsd/define/check_dict.py
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 |
|
lookup_required ¶
Yields all required key in a TypedDict.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
structure | DictStructure | The type structure, TypedDict or dict. | required |
Yields:
Type | Description |
---|---|
Iterable[Hashable] | Keys that are required, str normally. |
Source code in src/pyfsd/define/check_dict.py
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 |
|
errors ¶
FSD client protocol errors.
FSDClientError ¶
Bases: IntEnum
Errno constants.
__str__ ¶
__str__() -> str
Return the error string.
Source code in src/pyfsd/define/errors.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
packet ¶
Utilities to deal with FSD packet.
Attributes:
Name | Type | Description |
---|---|---|
CLIENT_USED_COMMAND | list[FSDClientCommand] | All possibly command can be issued by user in protocol 9. |
SPLIT_SIGN | CompatibleString | FSD client packet's split sign. |
CompatibleString ¶
CompatibleString(value: str)
Helper to deal with bytes and str.
Too hard to describe, please see examples section.
Examples:
>>> str1 = CompatibleString("1234")
>>> assert str1 + "test" == "1234test"
>>> assert str1 + b"test" == b"1234test"
>>> assert str1 + CompatibleString("test") == CompatibleString("1234test")
>>> assert "1" in str1
>>> assert b"2" in str1
>>> assert CompatibleString("3") in str1
Attributes:
Name | Type | Description |
---|---|---|
string | str | The original ascii-only str. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value | str | The original ascii-only str. | required |
Raises:
Type | Description |
---|---|
ValueError | When the value contains non-ascii characters. |
Source code in src/pyfsd/define/packet.py
53 54 55 56 57 58 59 60 61 62 63 64 |
|
__add__ ¶
__add__(other: _T_str) -> _T_str
Return self+other.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other | _T_str | str, bytes or CompatibleString. | required |
Source code in src/pyfsd/define/packet.py
195 196 197 198 199 200 201 202 203 204 205 206 207 |
|
__bytes__ ¶
__bytes__() -> bytes
Convert this CompatibleString into bytes.
Source code in src/pyfsd/define/packet.py
86 87 88 |
|
__complex__ ¶
__complex__() -> complex
Return complex(self.string).
Source code in src/pyfsd/define/packet.py
82 83 84 |
|
__contains__ ¶
Return part in self.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
part | object | str, bytes or CompatibleString. | required |
Source code in src/pyfsd/define/packet.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
|
__eq__ ¶
Return self == value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value | object | str, bytes or CompatibleString. | required |
Source code in src/pyfsd/define/packet.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
__float__ ¶
__float__() -> float
Return float(self.string).
Source code in src/pyfsd/define/packet.py
78 79 80 |
|
__ge__ ¶
Return self >= value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value | object | str, bytes or CompatibleString. | required |
Source code in src/pyfsd/define/packet.py
156 157 158 159 160 161 162 163 164 165 166 167 168 |
|
__getitem__ ¶
__getitem__(index: Union[int, slice]) -> CompatibleString
Return self[index].
Source code in src/pyfsd/define/packet.py
191 192 193 |
|
__getnewargs__ ¶
Return self.string in tuple, for pickle.
Source code in src/pyfsd/define/packet.py
94 95 96 |
|
__gt__ ¶
Return self > value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value | object | str, bytes or CompatibleString. | required |
Source code in src/pyfsd/define/packet.py
142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
__hash__ ¶
__hash__() -> int
Return hash(self.string).
Source code in src/pyfsd/define/packet.py
90 91 92 |
|
__int__ ¶
__int__() -> int
Return int(self.string).
Source code in src/pyfsd/define/packet.py
74 75 76 |
|
__le__ ¶
Return self <= value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value | object | str, bytes or CompatibleString. | required |
Source code in src/pyfsd/define/packet.py
128 129 130 131 132 133 134 135 136 137 138 139 140 |
|
__len__ ¶
__len__() -> int
Return len(self).
Source code in src/pyfsd/define/packet.py
187 188 189 |
|
__lt__ ¶
Return self < value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value | object | str, bytes or CompatibleString. | required |
Source code in src/pyfsd/define/packet.py
114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
__mod__ ¶
__mod__(args: Union[tuple, object]) -> CompatibleString
Return self % args.
Source code in src/pyfsd/define/packet.py
231 232 233 |
|
__mul__ ¶
__mul__(n: int) -> CompatibleString
Return self * n.
Source code in src/pyfsd/define/packet.py
223 224 225 |
|
__radd__ ¶
__radd__(other: _T_str) -> _T_str
Return other+self.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other | _T_str | str, bytes or CompatibleString. | required |
Source code in src/pyfsd/define/packet.py
209 210 211 212 213 214 215 216 217 218 219 220 221 |
|
__repr__ ¶
__repr__() -> str
Return the canonical string representation.
Source code in src/pyfsd/define/packet.py
70 71 72 |
|
__rmod__ ¶
__rmod__(template: _T_str) -> _T_str
Return template % self.
Source code in src/pyfsd/define/packet.py
235 236 237 238 239 240 241 242 243 244 245 |
|
__rmul__ ¶
__rmul__(n: int) -> CompatibleString
Return n * self.
Source code in src/pyfsd/define/packet.py
227 228 229 |
|
__str__ ¶
__str__() -> str
Return str(self).
Source code in src/pyfsd/define/packet.py
66 67 68 |
|
as_type ¶
Convert this CompatibleString into specified type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_ | type[AnyStr] | literally str or bytes. | required |
Source code in src/pyfsd/define/packet.py
247 248 249 250 251 252 253 254 255 256 257 |
|
FSDClientCommand ¶
FSDClientCommand(value: str)
Bases: CompatibleString
, Enum
FSD client command.
Source code in src/pyfsd/define/packet.py
53 54 55 56 57 58 59 60 61 62 63 64 |
|
break_packet ¶
break_packet(packet: AnyStr, possibly_commands: Iterable[AnyStr]) -> tuple[Optional[AnyStr], tuple[AnyStr, ...]]
break_packet(packet: AnyStr, possibly_commands: Iterable[FSDClientCommand]) -> tuple[Optional[FSDClientCommand], tuple[AnyStr, ...]]
break_packet(packet: AnyStr, possibly_commands: Iterable[Union[AnyStr, FSDClientCommand]]) -> tuple[Optional[Union[AnyStr, FSDClientCommand]], tuple[AnyStr, ...]]
Break a packet into command and parts.
#APzzzzzzzzzzzz1:zzzzzzz3:zzzzzzz4
[^][^^^^^^^^^^^] [^^^^^^] [^^^^^^]
command parts[0] parts[1] parts[2]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
packet | AnyStr | The original packet. | required |
possibly_commands | Iterable[Union[AnyStr, FSDClientCommand]] | All possibly commands. This function will check if packet starts with one of possibly commands then split it out. | required |
Returns:
Type | Description |
---|---|
tuple[Optional[Union[AnyStr, FSDClientCommand]], tuple[AnyStr, ...]] | tuple[command or None, tuple[every_part, ...]] |
Source code in src/pyfsd/define/packet.py
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 |
|
join_lines ¶
Join lines together.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lines | AnyStr | The lines. | () |
newline | bool | Append '\r\n' to every line or not. | True |
Returns:
Type | Description |
---|---|
AnyStr | The result. |
Source code in src/pyfsd/define/packet.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
|
make_packet ¶
make_packet(*parts: Union[AnyStr, FSDClientCommand]) -> AnyStr
Join parts together and add split sign between every two parts.
Source code in src/pyfsd/define/packet.py
297 298 299 300 301 302 303 304 |
|
simulation ¶
This module simulates some feature in C++ like integer overflow.
utils ¶
Collection of tools that are used frequently.
Attributes:
Name | Type | Description |
---|---|---|
task_keeper | TaskKeeper | Helper to keep your asyncio.Task's strong reference and cancel it when PyFSD is shutting down. |
mustdone_task_keeper | TaskKeeper | Similar to task_keeper, but PyFSD will await them before stop. |
MRand ¶
Python implementation of FSD MRand.
Note
This class does not simulate int32 overflow. See also: pyfsd.define.simulation.Int32MRand
Attributes:
Name | Type | Description |
---|---|---|
mrandseed | int | Random seed. |
__call__ ¶
__call__() -> int
Generate a random number.
Source code in src/pyfsd/define/utils.py
239 240 241 242 243 244 245 |
|
TaskKeeper ¶
TaskKeeper()
Helper to keep strong reference of running asyncio.Tasks.
Note
You're advised not to create new instance and use pyfsd.define.utils.task_keeper instead.
Source code in src/pyfsd/define/utils.py
262 263 264 |
|
add ¶
add(task: Task) -> None
Add a task that to be kept.
Source code in src/pyfsd/define/utils.py
271 272 273 274 |
|
cancel_all ¶
cancel_all() -> None
Cancel all tasks.
Source code in src/pyfsd/define/utils.py
266 267 268 269 |
|
assert_no_duplicate ¶
Assert nothing duplicated in a iterable object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator | Iterable[Hashable] | The iterable object. | required |
Raises:
Type | Description |
---|---|
AssertionError | When a duplicated value detected |
Source code in src/pyfsd/define/utils.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
|
asyncify ¶
Decorator to patch a sync function to become async by execute it in thread.
Examples:
>>> @asyncify
>>> def blocking_func():
... sleep(100) # Blocking call
...
>>> async def another_func():
... await blocking_func() # Not blocking anymore
Source code in src/pyfsd/define/utils.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
|
calc_distance ¶
calc_distance(from_position: Position, to_position: Position, unit: Unit = NAUTICAL_MILES) -> float
Calculate the distance from one point to another point.
A wrapper of haversine since it's not typed well
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_position | Position | The first point. | required |
to_position | Position | The second point. | required |
unit | Unit | Unit of the distance, nm by default. | NAUTICAL_MILES |
Returns:
Type | Description |
---|---|
float | The distance. |
Source code in src/pyfsd/define/utils.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
is_callsign_valid ¶
Check if a callsign is valid or not.
Source code in src/pyfsd/define/utils.py
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 |
|
is_empty_iterable ¶
Check if a iterable object is empty.
Source code in src/pyfsd/define/utils.py
154 155 156 157 158 159 160 161 |
|
iter_callable ¶
Yields all callable attribute in a object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj | object | The object. | required |
ignore_private | bool | Don't yield attributes which name starts with '_'. | True |
Yields:
Type | Description |
---|---|
Iterable[Callable] | Callable attributes. |
Source code in src/pyfsd/define/utils.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|
iterables ¶
Iterate multiple iterable objects at once.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterators | Iterable | Iterable objects. | () |
Yields:
Type | Description |
---|---|
Iterable | Iterate result. |
Source code in src/pyfsd/define/utils.py
172 173 174 175 176 177 178 179 180 181 182 |
|
str_to_float ¶
Convert a str or bytes into float.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string | Union[str, bytes] | The string to be converted. | required |
default_value | float | Default value when convert failed. | 0.0 |
Returns:
Type | Description |
---|---|
float | The float number. |
Source code in src/pyfsd/define/utils.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
str_to_int ¶
Convert a str or bytes into int.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string | Union[str, bytes] | The string to be converted. | required |
default_value | int | Default value when convert failed. | 0 |
Returns:
Type | Description |
---|---|
int | The int. |
Source code in src/pyfsd/define/utils.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
dependencies ¶
PyFSD dependencies container.
Container ¶
Bases: DeclarativeContainer
PyFSD dependencies container.
Attributes:
Name | Type | Description |
---|---|---|
config | RootPyFSDConfigProvider | The root config. |
db_engine | Singleton[AsyncEngine] | sqlalchemy database engine. |
plugin_manager | Singleton[PluginManager] | Plugin manager. |
metar_manager | Singleton[MetarManager] | Metar manager. |
client_factory | Singleton[ClientFactory] | Client protocol factory, which stores clients and do something else. |
RootPyFSDConfigProvider ¶
Bases: Configuration
Customized providers.Configuration with correct type annotation.
from_dict ¶
from_dict(options: RootPyFSDConfig, *, required: bool = False) -> None
Load configuration from dict.
Source code in src/pyfsd/dependencies.py
19 20 21 22 23 24 25 26 |
|
factory ¶
PyFSD protocol factories.
client ¶
Protocol factory -- client.
ClientFactory ¶
ClientFactory(motd: bytes, blacklist: list[str], metar_manager: MetarManager, plugin_manager: PluginManager, db_engine: AsyncEngine)
Factory of ClientProtocol.
Attributes:
Name | Type | Description |
---|---|---|
clients | dict[bytes, Client] | All clients, Dict[callsign(bytes), Client] |
heartbeat_task | Task[NoReturn] | None | Task to send heartbeat to clients. |
motd | list[bytes] | The Message Of The Day. |
blacklist | list[str] | IP blacklist. |
metar_manager | MetarManager | The metar manager. |
plugin_manager | PluginManager | The plugin manager. |
db_engine | AsyncEngine | Async sqlalchemy engine. |
password_hasher | PasswordHasher | Argon2 password hasher. |
Source code in src/pyfsd/factory/client.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
__call__ ¶
__call__() -> ClientProtocol
Create a ClientProtocol instance.
Source code in src/pyfsd/factory/client.py
112 113 114 |
|
broadcast ¶
broadcast(*lines: bytes, check_func: BroadcastChecker = lambda _, __: True, auto_newline: bool = True, from_client: Optional[Client] = None) -> bool
Broadcast a message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lines | bytes | Lines to be broadcasted. | () |
check_func | BroadcastChecker | Function to check if message should be sent to a client. | lambda _, __: True |
auto_newline | bool | Auto put newline marker between lines or not. | True |
from_client | Optional[Client] | Where the message from. | None |
Return
Lines sent to at least one client or not.
Source code in src/pyfsd/factory/client.py
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 |
|
check_auth async
¶
Check if password and username is correct.
Source code in src/pyfsd/factory/client.py
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 |
|
get_heartbeat_task ¶
Get heartbeat task.
Source code in src/pyfsd/factory/client.py
87 88 89 90 91 92 93 94 95 96 97 98 |
|
heartbeat ¶
heartbeat() -> None
Send heartbeat to clients.
Source code in src/pyfsd/factory/client.py
100 101 102 103 104 105 106 107 108 109 110 |
|
remove_all_clients ¶
remove_all_clients() -> None
Remove all clients.
Source code in src/pyfsd/factory/client.py
215 216 217 218 |
|
send_to ¶
Send lines to a specified client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
callsign | bytes | The client's callsign. | required |
lines | bytes | Lines to be broadcasted. | () |
auto_newline | bool | Auto put newline marker between lines or not. | True |
Returns:
Type | Description |
---|---|
bool | Is there a client called {callsign} (and is message sent or not). |
Source code in src/pyfsd/factory/client.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
|
main ¶
Run PyFSD.
Attributes:
Name | Type | Description |
---|---|---|
DEFAULT_CONFIG | str | Default config of PyFSD. |
PyFSDDatabaseConfig ¶
Bases: TypedDict
PyFSD database config.
Attributes:
Name | Type | Description |
---|---|---|
url | str | The database url, see SQLALchemy docs. |
launch async
¶
launch(config: RootPyFSDConfig, *, wait_all_tasks_done: bool = True) -> None
Launch PyFSD.
Source code in src/pyfsd/main.py
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 |
|
main ¶
main() -> None
Main function of PyFSD.
Source code in src/pyfsd/main.py
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 |
|
metar ¶
PyFSD -- Metar fetch & parse module.
fetch ¶
Metar fetcher defines.
Attributes:
Name | Type | Description |
---|---|---|
MetarInfoDict | Type of a dict that describes all airports' metar. | |
CronFetcher | Type of cron mode metar fetcher. | |
OnceFetcher | Type of once mode metar fetcher. |
noaa_fetch_all async
¶
Fetch all airports' metar from NOAA.
Source code in src/pyfsd/metar/fetch.py
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 |
|
noaa_fetch_once async
¶
noaa_fetch_once(_: object, icao: str) -> Optional[WeatherProfile]
Fetch single airport's metar from NOAA.
Source code in src/pyfsd/metar/fetch.py
41 42 43 44 45 46 47 48 49 50 51 |
|
manager ¶
PyFSD metar manager.
MetarManager ¶
MetarManager(config: Union[dict, PyFSDMetarConfig])
The PyFSD metar manager.
Attributes:
Name | Type | Description |
---|---|---|
fetchers | MetarFetchers | All registered fetchers. |
used_fetchers | MetarFetchers | Fetchers that we're going to use. |
metar_cache | MetarInfoDict | Metars fetched in cron mode. |
config | Union[dict, PyFSDMetarConfig] | pyfsd.metar section of config. |
cron_time | Optional[float] | Interval time between every two cron fetch. None if not in cron mode. |
cron_task | Optional[Task[NoReturn]] | Task to perform cron metar cache. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config | Union[dict, PyFSDMetarConfig] | pyfsd.metar section of config. | required |
Source code in src/pyfsd/metar/manager.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
cache_metar async
¶
cache_metar() -> None
Perform a cron fetch.
Raises:
Type | Description |
---|---|
RuntimeError | if not in cron mode. |
Source code in src/pyfsd/metar/manager.py
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 |
|
check_fetchers ¶
check_fetchers() -> None
Check if all specified metar fetchers in config is already here.
Source code in src/pyfsd/metar/manager.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
|
fetch async
¶
fetch(icao: str, *, ignore_case: bool = True) -> WeatherProfile | None
Try to fetch metar.
If in cron mode, we'll try to get metar from cron cache (generated by a cron fetcher). If specified airport not found in cache and config['fallback_once']
is True, we'll try to fetch from once fetchers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
icao | str | ICAO of the airport. | required |
ignore_case | bool | Ignore ICAO case. | True |
Source code in src/pyfsd/metar/manager.py
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 |
|
fetch_once async
¶
fetch_once(icao: str, *, ignore_case: bool = True) -> WeatherProfile | None
Try to fetch metar from once fetchers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
icao | str | ICAO of the airport. | required |
ignore_case | bool | Ignore ICAO case. | True |
Returns:
Type | Description |
---|---|
WeatherProfile | None | The parsed Metar or None if nothing fetched. |
Source code in src/pyfsd/metar/manager.py
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 |
|
get_cron_task ¶
Get cron fetching task.
Raises:
Type | Description |
---|---|
RuntimeError | if not in cron mode. |
Source code in src/pyfsd/metar/manager.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
register_cron_fetcher ¶
register_cron_fetcher(name: str, fetcher: CF) -> CF
Register a cron mode fetcher.
Source code in src/pyfsd/metar/manager.py
106 107 108 109 110 111 |
|
register_once_fetcher ¶
register_once_fetcher(name: str, fetcher: OF) -> OF
Register a once mode fetcher.
Source code in src/pyfsd/metar/manager.py
113 114 115 116 117 118 |
|
PyFSDMetarConfig ¶
Bases: TypedDict
PyFSD metar config.
Attributes:
Name | Type | Description |
---|---|---|
mode | Literal['cron', 'once'] | Mode to fetch metar. once means fetch at once when client request metar, cron means cache all airports' metar every specified interval. |
fallback_once | NotRequired[bool] | If specified airport not found in cron metar, fetch by once or not. Will be ignored if not in cron mode. |
fetchers | list | Enabled metar fetchers. |
cron_time | NotRequired[Union[float, int]] | The cron mode's specified interval. (see mode) |
suppress_metar_parser_warning ¶
suppress_metar_parser_warning() -> None
Suppress metar parser's warnings.
Source code in src/pyfsd/metar/manager.py
59 60 61 |
|
profile ¶
fsd/wprofile implemented in Python.
CloudLayer dataclass
¶
This dataclass describes a cloud layer.
TempLayer dataclass
¶
This dataclass describes a temperature layer.
Attributes:
Name | Type | Description |
---|---|---|
temp | int | The temperature. |
WeatherProfile dataclass
¶
WeatherProfile(metar: str, creation: int = lambda: int(time())(), name: Optional[str] = None, season: int = 0, active: bool = False, dew_point: int = 0, visibility: float = 15.0, barometer: int = 2950, winds: tuple[WindLayer, WindLayer, WindLayer, WindLayer] = lambda: (WindLayer(-1, -1), WindLayer(10400, 2500), WindLayer(22600, 10400), WindLayer(90000, 20700))(), temps: tuple[TempLayer, TempLayer, TempLayer, TempLayer] = lambda: (TempLayer(100), TempLayer(10000), TempLayer(18000), TempLayer(35000))(), clouds: tuple[CloudLayer, CloudLayer] = lambda: (CloudLayer(-1, -1), CloudLayer(-1, -1))(), tstorm: CloudLayer = lambda: CloudLayer(-1, -1)(), skip_parse: InitVar[bool] = False)
Profile of weather.
Attributes:
Name | Type | Description |
---|---|---|
metar | str | Original METAR. |
creation | int | Create time of the profile. |
name | Optional[str] | Metar station. |
season | int | Season of the metar's time. |
active | bool | The profile is activate or not. |
dew_point | int | Dew point. |
visibility | float | Visibility, in MI (maybe) |
barometer | int | Barometer. |
__post_init__ ¶
__post_init__(skip_parse: bool) -> None
Call feed_metar conditionally.
Source code in src/pyfsd/metar/profile.py
169 170 171 172 |
|
clone ¶
clone() -> WeatherProfile
Clone myself.
Source code in src/pyfsd/metar/profile.py
174 175 176 |
|
feed_metar ¶
feed_metar() -> None
Parse metar.
Note
I don't know what does ceiling or floor stands for, these code are heavily based on FSD.
Source code in src/pyfsd/metar/profile.py
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 |
|
fix ¶
fix(position: Position) -> None
Fix this profile at a point.
Source code in src/pyfsd/metar/profile.py
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 |
|
WindLayer dataclass
¶
get_now_variation cached
¶
Get current variation.
Source code in src/pyfsd/metar/profile.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
get_season ¶
Get season by month.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
month | int | The month. | required |
swap | bool | Swap spring and autumn or not. | required |
Returns:
Name | Type | Description |
---|---|---|
season | int | The season. Note it starts from 0. |
Source code in src/pyfsd/metar/profile.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
get_variation ¶
Get variation.
Source code in src/pyfsd/metar/profile.py
54 55 56 57 58 59 |
|
object ¶
PyFSD objects.
client ¶
Client object's dataclasses.
Client dataclass
¶
Client(is_controller: bool, callsign: bytes, rating: int, cid: str, protocol: int, realname: bytes, sim_type: int, transport: Transport, position: Position = (0, 0), transponder: int = 0, altitude: int = 0, ground_speed: int = 0, frequency: int = 0, facility_type: int = 0, visual_range: int = 40, flags: int = 0, pbh: int = 0, flight_plan: Optional[FlightPlan] = None, sector: Optional[bytes] = None, ident_flag: Optional[bytes] = None, start_time: int = lambda: int(time())(), last_updated: int = lambda: int(time())())
This dataclass stores a client.
get_range ¶
get_range() -> int
Get visual range.
Source code in src/pyfsd/object/client.py
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 |
|
update_ATC_position ¶
update_ATC_position(frequency: int, facility_type: int, visual_range: int, lat: float, lon: float, altitude: int) -> None
Update ATC position.
Source code in src/pyfsd/object/client.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
update_pilot_position ¶
update_pilot_position(mode: bytes, transponder: int, lat: float, lon: float, altitdue: int, groundspeed: int, pbh: int, flags: int) -> None
Update pilot position.
Source code in src/pyfsd/object/client.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|
update_plan ¶
update_plan(plan_type: bytes, aircraft: bytes, tascruise: int, dep_airport: bytes, dep_time: int, act_dep_time: int, alt: bytes, dest_airport: bytes, hrs_enroute: int, min_enroute: int, hrs_fuel: int, min_fuel: int, alt_airport: bytes, remarks: bytes, route: bytes) -> int
Update flight plan.
Source code in src/pyfsd/object/client.py
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 |
|
FlightPlan dataclass
¶
FlightPlan(revision: int, type: bytes, aircraft: bytes, tascruise: int, dep_airport: bytes, dep_time: int, act_dep_time: int, alt: bytes, dest_airport: bytes, hrs_enroute: int, min_enroute: int, hrs_fuel: int, min_fuel: int, alt_airport: bytes, remarks: bytes, route: bytes)
This dataclass describes a flight plan.
Attributes:
Name | Type | Description |
---|---|---|
type | bytes | b"I" => IFR, b"V" => VFR |
plugin ¶
PyFSD plugin architecture.
Attributes:
Name | Type | Description |
---|---|---|
API_LEVEL | tuple[int, int] | Current PyFSD plugin api level, (major, minor). If changes will break something, major is increased, otherwise minor. |
EventResult | event handle result for handleable events. |
Plugin ¶
Base class of a PyFSD plugin.
Attributes:
Name | Type | Description |
---|---|---|
name | str | Name of this plugin. |
api | tuple[int, int] | API level of this plugin. See |
version | tuple[int, str] | int and human readable version of this plugin. |
expected_config | Union[type[TypedDict], dict, None] | Configuration structure description, in dict or TypedDict, which is structure parameter of pyfsd.define.check_dict function. use None to disable config check. |
__eq__ ¶
Check if this plugin equals to another one.
Source code in src/pyfsd/plugin/__init__.py
85 86 87 88 89 90 91 92 93 94 95 |
|
__hash__ ¶
__hash__() -> int
Return hash of this plugin.
Source code in src/pyfsd/plugin/__init__.py
80 81 82 83 |
|
__repr__ ¶
__repr__() -> str
Return the canonical string representation of this plugin.
Source code in src/pyfsd/plugin/__init__.py
97 98 99 |
|
setup async
¶
setup() -> Optional[EventListenersDict]
Setup this plugin.
Returns:
Type | Description |
---|---|
Optional[EventListenersDict] | A dict that stores event listeners. See |
Source code in src/pyfsd/plugin/__init__.py
101 102 103 104 105 106 107 |
|
PluginHandledEventResult ¶
PreventEvent ¶
Bases: BaseException
Prevent a PyFSD plugin event.
Attributes:
Name | Type | Description |
---|---|---|
result | dict | The event result reported by plugin. |
Source code in src/pyfsd/plugin/__init__.py
49 50 51 52 53 |
|
PyFSDHandledEventResult ¶
SimplePlugin dataclass
¶
SimplePlugin(name: str, api: tuple[int, int], version: tuple[int, str], expected_config: Union[type[TypedDict], dict, None], listeners: EventListenersDict = lambda: {'auditers': {}, 'handlers': {}}())
Bases: Plugin
Create a simple plugin by decorators.
Attributes:
Name | Type | Description |
---|---|---|
listeners | EventListenersDict | Event listeners. |
audit ¶
Add a event auditer for specified event.
Source code in src/pyfsd/plugin/__init__.py
156 157 158 159 160 161 162 163 164 165 |
|
handle ¶
Add a event handler for specified event.
Source code in src/pyfsd/plugin/__init__.py
145 146 147 148 149 150 151 152 153 154 |
|
setup async
¶
setup() -> EventListenersDict
Return listeners registered by self.handle() and self.audit() before.
Source code in src/pyfsd/plugin/__init__.py
139 140 141 142 143 |
|
setuper ¶
setuper(setuper: C) -> C
Set setuper.
Source code in src/pyfsd/plugin/__init__.py
167 168 169 170 171 172 |
|
StubPlugin dataclass
¶
collect ¶
Tools to collect PyFSD plugins.
iter_submodules ¶
iter_submodules(path: Iterable[str], name: str, error_handler: Optional[Callable[[str], None]] = None) -> Iterable[ModuleType]
Yields {name}'s submodules on path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path | Iterable[str] | search path, like package.path | required |
name | str | package name, like package.name | required |
error_handler | Optional[Callable[[str], None]] | Handler that will be called because of uncaught exception | None |
Returns:
Type | Description |
---|---|
Iterable[ModuleType] | Submodules. |
Source code in src/pyfsd/plugin/collect.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
manager ¶
PyFSD plugin manager.
how the plugin architecture works:
Assume your plugin registered a handler and an auditer:
async def setup():
return {
"handler": {"some_event": (self.handle_sth,)},
"auditer": {"some_event": (self.audit_sth,)},
}
If this event is handleable, then somewhere of PyFSD will call
PluginManager.trigger_event_handlers("some_event", ...)
So handler in your plugin got called:
def handle_sth(...) -> None: pass
If the handler prevented the event by raise PreventEvent
, then this event won't be passed to other plugins and PyFSD won't handle the event too.
Later after this event processed (handled by PyFSD or prevented by one plugin), PyFSD'll call PluginManager.trigger_event_auditers("some_event", ...)
, so auditer in your plugin got called:
def audit_sth(..) -> None: pass
PluginManager ¶
PyFSD Plugin manager.
Attributes:
Name | Type | Description |
---|---|---|
all_plugins | Optional[tuple[Plugin, ...]] | All collected plugin files. |
sorted_plugins | Optional[SortedPlugins] | Plugins sorted with event name which it audits or handles. |
awaitable_services | Optional[SortedPlugins] | Registered awaitable services. |
__repr__ ¶
__repr__() -> str
Return the canonical string representation.
Source code in src/pyfsd/plugin/manager.py
354 355 356 357 358 359 360 |
|
__str__ ¶
__str__() -> str
Return all plugins' name.
Source code in src/pyfsd/plugin/manager.py
362 363 364 365 366 |
|
pick_plugins async
¶
pick_plugins(plugin_config_root: dict) -> None
Pick all plugins into self.all_plugins & self.sorted_plugins.
Source code in src/pyfsd/plugin/manager.py
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 |
|
plugins_count ¶
plugins_count() -> int
Get count of plugins.
Source code in src/pyfsd/plugin/manager.py
368 369 370 |
|
sort_pyfsd_plugins ¶
sort_pyfsd_plugins(plugins_handlers: dict[Plugin, EventListenersDict]) -> None
Sort PyFSD plugins into self.pyfsd_plugins.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
plugins_handlers | dict[Plugin, EventListenersDict] | {"plugin_name": | required |
Source code in src/pyfsd/plugin/manager.py
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 |
|
trigger_event_auditers async
¶
Trigger a audit event and call auditers from plugins.
Source code in src/pyfsd/plugin/manager.py
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 |
|
trigger_event_auditers_nonblock ¶
Trigger a audit event and call auditers from plugins, not blocking.
Source code in src/pyfsd/plugin/manager.py
343 344 345 346 347 348 349 350 351 352 |
|
trigger_event_handlers async
¶
trigger_event_handlers(event_name: str, args: Iterable, kwargs: Mapping) -> PluginHandledEventResult | None
Trigger a handle event and call handlers from plugins.
Source code in src/pyfsd/plugin/manager.py
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 |
|
SortedPlugins ¶
Bases: TypedDict
A dict that stores PyFSD plugins that can handle specified events.
Attributes:
Name | Type | Description |
---|---|---|
auditers | dict[str, tuple[tuple[Plugin, Callable[..., Awaitable]], ...]] | { "event name": (( |
handlers | dict[str, tuple[tuple[Plugin, Callable[..., Awaitable]], ...]] | { "event name": (( |
brief_path ¶
Shorten filepath to relative one if it's under current working directory.
Source code in src/pyfsd/plugin/manager.py
102 103 104 105 106 |
|
deal_exception ¶
deal_exception(name: str) -> None
Handle exceptions when importing plugins.
Source code in src/pyfsd/plugin/manager.py
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 |
|
plugins ¶
Package of PyFSD Plugins.
protocol ¶
PyFSD protocols.
LineProtocol ¶
Bases: LineReceiver
Protocol to deal with lines.
Attributes:
Name | Type | Description |
---|---|---|
buffer | bytes | Buffer used to store a line's data. |
delimiter | bytes | Line delimiter. |
buffer_size_exceed ¶
buffer_size_exceed(length: int) -> None
Kill when line length exceed max length.
Source code in src/pyfsd/protocol/__init__.py
69 70 71 |
|
connection_made ¶
connection_made(transport: Transport) -> None
Save transport after the connection was made.
Source code in src/pyfsd/protocol/__init__.py
64 65 66 |
|
send_line ¶
send_line(line: bytes) -> None
Send line to client.
Source code in src/pyfsd/protocol/__init__.py
73 74 75 |
|
send_lines ¶
Send lines to client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lines | bytes | Lines to be sent. | () |
auto_newline | bool | Insert newline between every two line or not. | True |
together | bool | Send lines together or not. | True |
Source code in src/pyfsd/protocol/__init__.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
LineReceiver ¶
Bases: Protocol
Line receiver.
Attributes:
Name | Type | Description |
---|---|---|
buffer | bytes | Buffer used to store a line's data. |
delimiter | bytes | Line delimiter. |
max_length | bytes | Max acceptable line length. Set it to -1 to allow infinite |
buffer_size_exceed abstractmethod
¶
buffer_size_exceed(length: int) -> None
Called when buffer exceed max size.
Source code in src/pyfsd/protocol/__init__.py
33 34 35 36 |
|
data_received ¶
data_received(data: bytes) -> None
Handle data and call line_received as soon as we received a line.
Source code in src/pyfsd/protocol/__init__.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
client ¶
PyFSD client protocol.
ClientProtocol ¶
ClientProtocol(factory: ClientFactory)
Bases: LineProtocol
PyFSD client protocol.
Attributes:
Name | Type | Description |
---|---|---|
factory | ClientFactory | The client protocol factory. |
timeout_killer | ClientFactory | Helper to disconnect when timeout. |
transport | Transport | Asyncio transport. |
client | Optional[Client] | The client info. None before |
tasks | Optional[Client] | Processing handle_line tasks. |
Source code in src/pyfsd/protocol/client.py
156 157 158 159 160 161 162 163 |
|
buffer_size_exceed ¶
buffer_size_exceed(length: int) -> None
Called when client exceed max buffer size.
Source code in src/pyfsd/protocol/client.py
260 261 262 263 264 265 266 267 |
|
connection_lost ¶
connection_lost(exc: Optional[BaseException] = None) -> None
Handle connection lost.
Source code in src/pyfsd/protocol/client.py
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 |
|
connection_made ¶
connection_made(transport: Transport) -> None
Initialize something after the connection is made.
Source code in src/pyfsd/protocol/client.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
|
get_description ¶
get_description() -> str
Get text description of this client.
Source code in src/pyfsd/protocol/client.py
278 279 280 281 282 283 284 285 286 |
|
handle_ATC_position_update ¶
Handle ATC position update request.
Source code in src/pyfsd/protocol/client.py
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 |
|
handle_acars async
¶
Handle acars request.
Source code in src/pyfsd/protocol/client.py
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 |
|
handle_add_client async
¶
Handle add client request.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
packet | tuple[bytes, ...] | The packet. | required |
is_AA | bool | True if this packet is #AA (add atc), else #AP | required |
Source code in src/pyfsd/protocol/client.py
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 |
|
handle_cast ¶
handle_cast(packet: tuple[bytes, ...], command: FSDClientCommand, *, require_parts: int = 2, multicast_able: bool = True, custom_at_checker: Optional[BroadcastChecker] = None) -> HandleResult
Handle a (multi/uni)cast request.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
packet | tuple[bytes, ...] | format: | required |
command | FSDClientCommand | The packet's command. | required |
require_parts | int | How many parts required. | 2 |
multicast_able | bool | to_callsign can be multicast sign or not. if not multicast_able and to_callsign is multicast sign, this function will send nothing and exit with False, False. | True |
custom_at_checker | Optional[BroadcastChecker] | Custom checker used when to_callsign is | None |
Source code in src/pyfsd/protocol/client.py
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 |
|
handle_client_query ¶
Handle $CQ request.
Source code in src/pyfsd/protocol/client.py
889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 |
|
handle_kill ¶
Handle kill request.
Source code in src/pyfsd/protocol/client.py
956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 |
|
handle_line async
¶
handle_line(byte_line: bytes) -> HandleResult
Handle a line.
Source code in src/pyfsd/protocol/client.py
1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 |
|
handle_line_worker_func async
¶
handle_line_worker_func() -> None
Worker processes line.
Source code in src/pyfsd/protocol/client.py
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 |
|
handle_pilot_position_update ¶
Handle pilot position update request.
Source code in src/pyfsd/protocol/client.py
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 |
|
handle_plan ¶
Handle plan update request.
Source code in src/pyfsd/protocol/client.py
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 |
|
handle_remove_client ¶
Handle remove client request.
Source code in src/pyfsd/protocol/client.py
579 580 581 582 583 584 585 |
|
handle_server_ping ¶
Handle server ping request.
Source code in src/pyfsd/protocol/client.py
789 790 791 792 793 794 795 796 797 798 799 800 |
|
handle_weather async
¶
Handle weather request.
Source code in src/pyfsd/protocol/client.py
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 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 |
|
kill_after_1sec ¶
kill_after_1sec() -> None
Kill this client after 1 second by kill_func.
Source code in src/pyfsd/protocol/client.py
269 270 271 272 273 274 275 276 |
|
line_received ¶
line_received(line: bytes) -> None
Handle a line.
Source code in src/pyfsd/protocol/client.py
217 218 219 220 |
|
multicast ¶
multicast(to_limiter: str, *lines: bytes, custom_at_checker: Optional[BroadcastChecker] = None) -> bool
Multicast lines.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
to_limiter | str | Dest limiter. | required |
lines | bytes | lines to be sent. | () |
custom_at_checker | Optional[BroadcastChecker] | Custom checker used when to_limiter is | None |
Returns:
Type | Description |
---|---|
bool | Lines sent to at least client or not. |
Raises:
Type | Description |
---|---|
NotImplementedError | When an unsupported to_limiter specified. |
Source code in src/pyfsd/protocol/client.py
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 |
|
reset_timeout_killer ¶
reset_timeout_killer() -> None
Reset timeout killer.
Source code in src/pyfsd/protocol/client.py
288 289 290 291 292 293 294 295 296 297 298 299 |
|
send_error ¶
send_error(errno: FSDClientError, *, env: bytes = b'', fatal: bool = False) -> None
Send an error to client.
$ERserver:(callsign):(errno):(env):error_text
Parameters:
Name | Type | Description | Default |
---|---|---|---|
errno | FSDClientError | The error to be sent. | required |
env | bytes | The error env. | b'' |
fatal | bool | Disconnect after the error is sent or not. | False |
Source code in src/pyfsd/protocol/client.py
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 |
|
send_motd ¶
send_motd() -> None
Send motd to client.
Source code in src/pyfsd/protocol/client.py
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
|
check_packet ¶
check_packet(require_parts: int, callsign_position: int = 0, *, check_callsign: bool = True, need_login: bool = True) -> Callable[[Callable[Concatenate[_T_ClientProtocol, tuple[bytes, ...], P], Union[Awaitable[HandleResult], HandleResult]]], Callable[Concatenate[_T_ClientProtocol, tuple[bytes, ...], P], Awaitable[HandleResult]]]
Create a decorator to auto check packet format and ensure awaitable.
Designed for ClientProtocol's handlers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
require_parts | int | How many parts required. | required |
callsign_position | int | Which part contains callsign, used when (need_login and check_callsign). For example: Here parts[0] is the callsign, so | 0 |
need_login | bool | Need self.client is not None (logined) or not. | True |
check_callsign | bool | Check packet[callsign_position] == self.client.callsign or not. | True |
Source code in src/pyfsd/protocol/client.py
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 |
|
setup_logger ¶
Logger configurer.
PyFSDLoggerConfig ¶
Bases: TypedDict
PyFSD logger config.
Attributes:
Name | Type | Description |
---|---|---|
handlers | dict[str, Union[dict, HandlerConfig]] | See dictConfig. |
loggers | dict[str, Union[dict, HandlerConfig]] | See dictConfig. |
include_extra | NotRequired[bool] | Print log's extra or not. |
extract_record | NotRequired[bool] | Extract thread and process names and add them to the event dict. |
TimeFormatConfig ¶
Bases: TypedDict
Config of time formatter.
Attributes document comes from structlog.processors.TimeStamper.
Attributes:
Name | Type | Description |
---|---|---|
fmt | Optional[str] | strftime format string, or "iso" for ISO 8601, or "timestamp" for a UNIX timestamp. |
utc | bool | Whether timestamp should be in UTC or local time. |
key | str | Target key in event_dict for added timestamps. |
make_filtering_stdlib_bound_logger ¶
Create a new BoundLogger that only logs min_level or higher.
Source code in src/pyfsd/setup_logger.py
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 |
|
setup_logger ¶
setup_logger(config: PyFSDLoggerConfig, *, finalize: bool = False) -> None
Setup logger with config.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config | PyFSDLoggerConfig | logger config. | required |
finalize | bool | make loggers fit finalizing phrase of cpython. | False |
Source code in src/pyfsd/setup_logger.py
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 |
|
utils ¶
PyFSD CLI utilities.
import_users ¶
A tool used to convert users database in other format into PyFSD's format.
main ¶
main() -> None
Main function of the tool.
Source code in src/pyfsd/utils/import_users/__init__.py
20 21 22 23 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 |
|
__main__ ¶
Entrypoint of pyfsd.utils.import_users.
formats ¶
User database formats.
Attributes:
Name | Type | Description |
---|---|---|
User | description of a user, (callsign, password, rating) | |
formats | dict[str, Format] | All registered formats. |
CFCSIMFSDFormat ¶
User database format of cfcsim modified fsd.
read_all staticmethod
¶
Read all users.
Source code in src/pyfsd/utils/import_users/formats.py
54 55 56 57 58 59 60 61 62 |
|
FSDTextFormat ¶
User database format of original fsd.
read_all staticmethod
¶
Read all users.
Source code in src/pyfsd/utils/import_users/formats.py
70 71 72 73 74 75 76 77 78 79 |
|
Format ¶
Bases: Protocol
Format of user database.
Attributes:
Name | Type | Description |
---|---|---|
argon2_hashed | bool | Password hashed by argon2 or not. |
read_all ¶
Read all users from database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename | str | The filename of the database. | required |
Source code in src/pyfsd/utils/import_users/formats.py
24 25 26 27 28 29 30 |
|
PyFSDFormat ¶
User database format of PyFSD.
read_all staticmethod
¶
Read all users.
Source code in src/pyfsd/utils/import_users/formats.py
38 39 40 41 42 43 44 45 46 |
|