| 506 | type = TEXT |
| 507 | |
| 508 | def __init__(self, *args, **kwargs): |
| 509 | args = list(args) |
| 510 | |
| 511 | # parse types according to |
| 512 | # https://www.postgresql.org/docs/current/textsearch-controls.html#TEXTSEARCH-HEADLINE |
| 513 | if len(args) < 2: |
| 514 | # invalid args; don't do anything |
| 515 | has_regconfig = False |
| 516 | elif ( |
| 517 | isinstance(args[1], elements.ColumnElement) |
| 518 | and args[1].type._type_affinity is types.TSQUERY |
| 519 | ): |
| 520 | # tsquery is second argument, no regconfig argument |
| 521 | has_regconfig = False |
| 522 | else: |
| 523 | has_regconfig = True |
| 524 | |
| 525 | if has_regconfig: |
| 526 | initial_arg = coercions.expect( |
| 527 | roles.ExpressionElementRole, |
| 528 | args.pop(0), |
| 529 | apply_propagate_attrs=self, |
| 530 | name=getattr(self, "name", None), |
| 531 | type_=types.REGCONFIG, |
| 532 | ) |
| 533 | initial_arg = [initial_arg] |
| 534 | else: |
| 535 | initial_arg = [] |
| 536 | |
| 537 | addtl_args = [ |
| 538 | coercions.expect( |
| 539 | roles.ExpressionElementRole, |
| 540 | c, |
| 541 | name=getattr(self, "name", None), |
| 542 | apply_propagate_attrs=self, |
| 543 | ) |
| 544 | for c in args |
| 545 | ] |
| 546 | super().__init__(*(initial_arg + addtl_args), **kwargs) |