Config Handler
Config
SmartMixin.Config
Config is a class that represents a Clash YAML configuration. It can be initialized with a URL, a YAML string, a file, or a dictionary (YAML representation).
Source code in SmartMixin/handler.py
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 |
|
DICT
property
writable
Get the dictionary representation of the configuration.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
Dictionary representation of the configuration. |
Proxies
property
writable
Proxies: list[Proxy]
ProxyGroups
property
writable
ProxyGroups: list[ProxyGroup]
Get all proxygroups.
Returns:
Type | Description |
---|---|
list[ProxyGroup]
|
list[ProxyGroup]: List of all proxygroups. |
Rules
property
writable
Rules: list[Rule]
YAML
property
writable
Get the YAML representation of the configuration.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
YAML representation of the configuration. |
__getattr__
Get an attribute of the configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__name |
str
|
Name of the attribute. |
required |
Returns:
Type | Description |
---|---|
The value of the attribute. |
Source code in SmartMixin/handler.py
__init__
__init__(Url: str = None, YAML: str = None, File: TextIOWrapper = None, DICT: dict = None, UA: str = Clash('1.11.0')) -> None
Initialize the Config with a URL, a YAML string, a file, or a dictionary (YAML representation).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
Url |
str
|
URL to fetch the configuration from. Defaults to None. |
None
|
YAML |
str
|
YAML string representing the configuration. Defaults to None. |
None
|
File |
TextIOWrapper
|
File containing the configuration. Defaults to None. |
None
|
DICT |
dict
|
Dictionary representing the configuration. Defaults to None. |
None
|
UA |
str
|
User-agent string for the request. Defaults to Default("1.11.0"). |
Clash('1.11.0')
|
Raises:
Type | Description |
---|---|
ValueError
|
If none of Url, YAML, File, or DICT are provided. |
Source code in SmartMixin/handler.py
__setattr__
Rewrite the setattr method to intercept attribute assignments and store them in the _meta dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__name |
str
|
Name of the attribute. |
required |
__value |
Value of the attribute. |
required |
Source code in SmartMixin/handler.py
getProxies
getProxies(groups: bool = False, embedded: bool = False) -> list[Proxy]
Get all proxies, optionally including proxygroups and embedded proxies.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
groups |
bool
|
Whether to include proxygroups. Defaults to False. |
False
|
embedded |
bool
|
Whether to include embedded proxies. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
list[Proxy]
|
list[Proxy]: List of Proxy objects. |
Source code in SmartMixin/handler.py
mixin
Mix additional configuration from a YAML string or a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
YAML |
str
|
YAML string representing additional configuration. Defaults to None. |
None
|
DICT |
dict
|
Dictionary representing additional configuration. Defaults to None. |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
If neither YAML nor DICT is provided. |
Source code in SmartMixin/handler.py
User-Agent Helper
SmartMixin.Stash
module-attribute
SmartMixin.ClashforWindows
module-attribute
Proxy
SmartMixin.Proxy
Proxy is a class that represents a proxy defined in the Clash YAML configuration. It has properties like name and DICT. The class can be initialized with either a YAML string or a dictionary (YAML representation).
Source code in SmartMixin/handler.py
9 10 11 12 13 14 15 16 17 18 19 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 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 |
|
name
property
writable
Get the name of the proxy.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The name of the proxy. |
BATCH
Create a list of Proxy objects from a YAML string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
YAML |
str
|
A string representing multiple proxies in YAML format. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the YAML string does not represent a list of proxies. |
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
A list of Proxy objects. |
Source code in SmartMixin/handler.py
__init__
Initialize the Proxy object with either a dictionary or a YAML string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
DICT |
dict
|
A dictionary representing a proxy. Defaults to None. |
None
|
YAML |
str
|
A string representing a proxy in YAML format. Defaults to None. |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
If both DICT and YAML are None. |
Source code in SmartMixin/handler.py
__repr__
Get a string representation of the proxy.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A string representation of the proxy. |
delete
Delete the proxy from its proxygroup. If globally is True, the proxy is removed from the configuration file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
globally |
bool
|
If True, the proxy is removed from the configuration file. |
False
|
Source code in SmartMixin/handler.py
Embedded Proxy
ProxyGroup
SmartMixin.ProxyGroup
ProxyGroup is a class that represents a proxygroup defined in the Clash YAML configuration. It has properties like name, proxies, and DICT. The class can be initialized with either a dictionary (YAML representation) or a YAML string.
Source code in SmartMixin/handler.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 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 |
|
DICT
property
writable
Get the dictionary representation of the proxygroup.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
The dictionary representation of the proxygroup. |
name
property
writable
Get the name of the proxygroup.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The name of the proxygroup. |
proxies
property
writable
proxies: list[Proxy]
Get the list of proxies in the proxygroup.
Returns:
Type | Description |
---|---|
list[Proxy]
|
list[Proxy]: The list of proxies in the proxygroup. |
BATCH
Create a list of ProxyGroup objects from a YAML string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
YAML |
str
|
A string representing multiple proxygroups in YAML format. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the YAML string does not represent a list of proxygroups. |
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
A list of ProxyGroup objects. |
Source code in SmartMixin/handler.py
__init__
Initialize the ProxyGroup with either a dictionary or a YAML string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
DICT |
dict
|
A dictionary representing a proxygroup. Defaults to None. |
None
|
YAML |
str
|
A string representing a proxygroup in YAML format. Defaults to None. |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
If both DICT and YAML are None. |
Source code in SmartMixin/handler.py
__repr__
Get a string representation of the proxygroup.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A string representation of the proxygroup. |
delete
Delete the proxygroup. If a policy is provided, all rules with the proxygroup's name as their policy will be updated to use the provided policy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
policy |
str
|
The new policy for rules that use the proxygroup's name as their policy. |
None
|
Source code in SmartMixin/handler.py
Rule
SmartMixin.Rule
Rule is a class that represents a rule defined in the Clash YAML configuration. It has properties like type, argument, policy, and no_resolve. The class can be initialized with either a YAML string or individual properties.
Source code in SmartMixin/handler.py
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 |
|
YAML
property
writable
Get the YAML representation of the rule.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The YAML representation of the rule. |
no_resolve
property
writable
Get the no_resolve property of the rule.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the rule should not be resolved, False otherwise. |
BATCH
Create a list of Rule objects from a YAML string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
YAML |
str
|
A string representing multiple rules in YAML format. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the YAML string does not represent a list of rules. |
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
A list of Rule objects. |
Source code in SmartMixin/handler.py
__init__
__init__(YAML: str = None, type: str = None, argument: str = None, policy: str = None, no_resolve: bool = False) -> None
Initialize the Rule object with either a YAML string or individual properties.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
YAML |
str
|
A string representing a rule in YAML format. Defaults to None. |
None
|
type |
str
|
The type of the rule. Defaults to None. For example, "DOMAIN". |
None
|
argument |
str
|
The argument of the rule. Defaults to None. For example, "example.com". |
None
|
policy |
str
|
The policy of the rule. Defaults to None. For example, "DIRECT". |
None
|
no_resolve |
bool
|
A flag indicating whether the rule should be resolved. |
False
|
Raises:
Type | Description |
---|---|
ValueError
|
If both YAML and individual properties are None. |
Source code in SmartMixin/handler.py
__repr__
Get a string representation of the rule.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A string representation of the rule. |