From 1c628953c71f2e2f0cd01d643ca239e23c2e15cc Mon Sep 17 00:00:00 2001 From: Anthon van der Neut Date: Thu, 15 Aug 2019 21:45:20 +0200 Subject: move YAML directive info to scanner for TAG parsing of 1.2 URI 1.2 URI can contain the "#" character, but parsing for nodes didn't necessarily make the 1.2 version available in time fixes issue #301 *When this change indeed resolves your problem, please **Close** this issue*. *(You can do so using the WorkFlow pull-down (close to the top right of this page))* --- parser.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'parser.py') diff --git a/parser.py b/parser.py index 566d13a..10deaa8 100644 --- a/parser.py +++ b/parser.py @@ -109,7 +109,6 @@ class Parser(object): # type: () -> None # Reset the state attributes (to clear self-references) self.current_event = None - self.yaml_version = None self.tag_handles = {} # type: Dict[Any, Any] self.states = [] # type: List[Any] self.marks = [] # type: List[Any] @@ -269,12 +268,12 @@ class Parser(object): def process_directives(self): # type: () -> Any - self.yaml_version = None + yaml_version = None self.tag_handles = {} while self.scanner.check_token(DirectiveToken): token = self.scanner.get_token() if token.name == u'YAML': - if self.yaml_version is not None: + if yaml_version is not None: raise ParserError( None, None, 'found duplicate YAML directive', token.start_mark ) @@ -286,7 +285,7 @@ class Parser(object): 'found incompatible YAML document (version 1.* is ' 'required)', token.start_mark, ) - self.yaml_version = token.value + yaml_version = token.value elif token.name == u'TAG': handle, prefix = token.value if handle in self.tag_handles: @@ -295,11 +294,11 @@ class Parser(object): ) self.tag_handles[handle] = prefix if bool(self.tag_handles): - value = self.yaml_version, self.tag_handles.copy() # type: Any + value = yaml_version, self.tag_handles.copy() # type: Any else: - value = self.yaml_version, None + value = yaml_version, None if self.loader is not None and hasattr(self.loader, 'tags'): - self.loader.version = self.yaml_version + self.loader.version = yaml_version if self.loader.tags is None: self.loader.tags = {} for k in self.tag_handles: -- cgit v1.2.1