File: notations.py

package info (click to toggle)
python-xmlschema 4.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 5,208 kB
  • sloc: python: 39,174; xml: 1,282; makefile: 36
file content (51 lines) | stat: -rw-r--r-- 1,576 bytes parent folder | download
1
2
3
4
5
6
7
8
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
#
# Copyright (c), 2016-2020, SISSA (International School for Advanced Studies).
# All rights reserved.
# This file is distributed under the terms of the MIT License.
# See the file 'LICENSE' in the root directory of the present
# distribution, or http://opensource.org/licenses/MIT.
#
# @author Davide Brunato <brunato@sissa.it>
#
from typing import Optional

from xmlschema.names import XSD_NOTATION
from xmlschema.translation import gettext as _
from xmlschema.utils.qnames import get_qname

from .xsdbase import XsdComponent


class XsdNotation(XsdComponent):
    """
    Class for XSD *notation* declarations.

    ..  <notation
          id = ID
          name = NCName
          public = token
          system = anyURI
          {any attributes with non-schema namespace}...>
          Content: (annotation?)
        </notation>
    """
    _ADMITTED_TAGS = XSD_NOTATION,

    def _parse(self) -> None:
        if self.parent is not None:
            self.parse_error(_("a notation declaration must be global"))
        try:
            self.name = get_qname(self.target_namespace, self.elem.attrib['name'])
        except KeyError:
            self.parse_error(_("a notation must have a 'name' attribute"))

        if 'public' not in self.elem.attrib and 'system' not in self.elem.attrib:
            self.parse_error(_("a notation must have a 'public' or a 'system' attribute"))

    @property
    def public(self) -> Optional[str]:
        return self.elem.get('public')

    @property
    def system(self) -> Optional[str]:
        return self.elem.get('system')