refspy.models.syntax

Data object for reference character separators.

The Symbol object is used in instances of refspy.language.Language to store the different symbol conventions used in the EU countries and internationally. For example, 1:2,4-5 (INTL) == 1,2.4-5 (EURO).

It also stores matching characters that should be considered equivalent when matching.

Attributes:
  • name: e.g. 'International'
  • abbrev: e.g. 'intl'
  • colon: ':' in English
  • comma: ',' in English
  • dash: '-' in English
  • semicolon: ';' in English
  • format_colon: ':' in English
  • format_comma: "," in English
  • format_dash: "–" in English (EN_DASH)
  • format_semicolon: ";" in English
  • match_colons: ":." in English
  • match_commas: "," in English
  • match_dashes: "–-" in English (incl. EN_DASH)
  • match_semicolons: ";" in English
 1"""
 2Data object for reference character separators.
 3
 4The Symbol object is used in instances of `refspy.language.Language`
 5to store the different symbol conventions used in the EU countries
 6and internationally. For example, `1:2,4-5 (INTL) == 1,2.4-5 (EURO)`.
 7
 8It also stores matching characters that should be considered equivalent when
 9matching.
10
11Attributes:
12    name: e.g. 'International'
13    abbrev: e.g. 'intl'
14    colon: ':' in English
15    comma: ',' in English
16    dash: '-' in English
17    semicolon: ';' in English
18    format_colon: ':' in English
19    format_comma: "," in English
20    format_dash: "–" in English (EN_DASH)
21    format_semicolon: ";" in English
22    match_colons: ":." in English
23    match_commas: "," in English
24    match_dashes: "–-" in English (incl. EN_DASH)
25    match_semicolons: ";" in English
26"""
27
28from pydantic import BaseModel
29
30from refspy.utils import string_together
31
32
33class Syntax(BaseModel):
34    name: str
35    abbrev: str
36    colon: str
37    comma: str
38    dash: str
39    semicolon: str
40    format_colon: str
41    format_comma: str
42    format_dash: str
43    format_semicolon: str
44    match_colons: str
45    match_commas: str
46    match_dashes: str
47    match_semicolons: str
48
49
50def syntax_label(syntax: Syntax) -> str:
51    def bracket(chars):
52        return f"[{chars}]" if len(chars) > 1 else chars
53
54    return string_together(
55        "c",
56        bracket(syntax.match_colons),
57        "v",
58        bracket(syntax.match_commas),
59        "v",
60        syntax.dash,  # <-- no point showing EM_DASH, EN_DASH, etc.
61        "v",
62        bracket(syntax.match_semicolons),
63        " (",
64        syntax.abbrev,
65        ")",
66    )
class Syntax(pydantic.main.BaseModel):
34class Syntax(BaseModel):
35    name: str
36    abbrev: str
37    colon: str
38    comma: str
39    dash: str
40    semicolon: str
41    format_colon: str
42    format_comma: str
43    format_dash: str
44    format_semicolon: str
45    match_colons: str
46    match_commas: str
47    match_dashes: str
48    match_semicolons: str

!!! abstract "Usage Documentation" Models

A base class for creating Pydantic models.

Attributes:
  • __class_vars__: The names of the class variables defined on the model.
  • __private_attributes__: Metadata about the private attributes of the model.
  • __signature__: The synthesized __init__ [Signature][inspect.Signature] of the model.
  • __pydantic_complete__: Whether model building is completed, or if there are still undefined fields.
  • __pydantic_core_schema__: The core schema of the model.
  • __pydantic_custom_init__: Whether the model has a custom __init__ function.
  • __pydantic_decorators__: Metadata containing the decorators defined on the model. This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.
  • __pydantic_generic_metadata__: A dictionary containing metadata about generic Pydantic models. The origin and args items map to the [__origin__][genericalias.__origin__] and [__args__][genericalias.__args__] attributes of [generic aliases][types-genericalias], and the parameter item maps to the __parameter__ attribute of generic classes.
  • __pydantic_parent_namespace__: Parent namespace of the model, used for automatic rebuilding of models.
  • __pydantic_post_init__: The name of the post-init method for the model, if defined.
  • __pydantic_root_model__: Whether the model is a [RootModel][pydantic.root_model.RootModel].
  • __pydantic_serializer__: The pydantic-core SchemaSerializer used to dump instances of the model.
  • __pydantic_validator__: The pydantic-core SchemaValidator used to validate instances of the model.
  • __pydantic_fields__: A dictionary of field names and their corresponding [FieldInfo][pydantic.fields.FieldInfo] objects.
  • __pydantic_computed_fields__: A dictionary of computed field names and their corresponding [ComputedFieldInfo][pydantic.fields.ComputedFieldInfo] objects.
  • __pydantic_extra__: A dictionary containing extra values, if [extra][pydantic.config.ConfigDict.extra] is set to 'allow'.
  • __pydantic_fields_set__: The names of fields explicitly set during instantiation.
  • __pydantic_private__: Values of private attributes set on the model instance.
name: str
abbrev: str
colon: str
comma: str
dash: str
semicolon: str
format_colon: str
format_comma: str
format_dash: str
format_semicolon: str
match_colons: str
match_commas: str
match_dashes: str
match_semicolons: str
model_config: ClassVar[pydantic.config.ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

def syntax_label(syntax: Syntax) -> str:
51def syntax_label(syntax: Syntax) -> str:
52    def bracket(chars):
53        return f"[{chars}]" if len(chars) > 1 else chars
54
55    return string_together(
56        "c",
57        bracket(syntax.match_colons),
58        "v",
59        bracket(syntax.match_commas),
60        "v",
61        syntax.dash,  # <-- no point showing EM_DASH, EN_DASH, etc.
62        "v",
63        bracket(syntax.match_semicolons),
64        " (",
65        syntax.abbrev,
66        ")",
67    )