Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop 2.7 support #550

Merged
merged 7 commits into from Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions .appveyor.yml
Expand Up @@ -14,10 +14,6 @@ environment:
PYYAML_TEST_GROUP: all

# matrix:
# - PYTHON_VER: Python27
# - PYTHON_VER: Python27-x64
# - PYTHON_VER: Python35
# - PYTHON_VER: Python35-x64
# - PYTHON_VER: Python36
# - PYTHON_VER: Python36-x64
# - PYTHON_VER: Python37
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/ci.yaml
Expand Up @@ -118,7 +118,6 @@ jobs:
strategy:
matrix:
cfg:
- { platform: manylinux1, arch: x86_64, python_tag: cp27-cp27mu }
- { platform: manylinux1, arch: x86_64, python_tag: cp36-cp36m }
- { platform: manylinux1, arch: x86_64, python_tag: cp37-cp37m }
- { platform: manylinux1, arch: x86_64, python_tag: cp38-cp38 }
Expand Down Expand Up @@ -217,7 +216,6 @@ jobs:
arch:
- x86_64
python_tag:
- cp27*
- cp36*
- cp37*
- cp38*
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -2,7 +2,6 @@
/dist/*
/build/*
/lib/PyYAML.egg-info/*
/lib3/PyYAML.egg-info/*
/wheelhouse/*
/yaml/_yaml.c
MANIFEST
Expand Down
3 changes: 0 additions & 3 deletions MANIFEST.in
@@ -1,10 +1,7 @@
include CHANGES README LICENSE Makefile pyproject.toml setup.py
recursive-include lib/yaml *.py
recursive-include lib/_yaml *.py
recursive-include lib3/yaml *.py
recursive-include lib3/_yaml *.py
recursive-include examples *.py *.cfg *.yaml
recursive-include tests/data *
recursive-include tests/lib *.py
recursive-include tests/lib3 *.py
recursive-include yaml *
40 changes: 18 additions & 22 deletions lib/yaml/__init__.py
@@ -1,21 +1,21 @@

from error import *
from .error import *

from tokens import *
from events import *
from nodes import *
from .tokens import *
from .events import *
from .nodes import *

from loader import *
from dumper import *
from .loader import *
from .dumper import *

__version__ = '5.4.1'

try:
from cyaml import *
from .cyaml import *
__with_libyaml__ = True
except ImportError:
__with_libyaml__ = False

import io

#------------------------------------------------------------------------------
# Warnings control
Expand Down Expand Up @@ -200,8 +200,7 @@ def emit(events, stream=None, Dumper=Dumper,
"""
getvalue = None
if stream is None:
from StringIO import StringIO
stream = StringIO()
stream = io.StringIO()
getvalue = stream.getvalue
dumper = Dumper(stream, canonical=canonical, indent=indent, width=width,
allow_unicode=allow_unicode, line_break=line_break)
Expand All @@ -216,7 +215,7 @@ def emit(events, stream=None, Dumper=Dumper,
def serialize_all(nodes, stream=None, Dumper=Dumper,
canonical=None, indent=None, width=None,
allow_unicode=None, line_break=None,
encoding='utf-8', explicit_start=None, explicit_end=None,
encoding=None, explicit_start=None, explicit_end=None,
version=None, tags=None):
"""
Serialize a sequence of representation trees into a YAML stream.
Expand All @@ -225,10 +224,9 @@ def serialize_all(nodes, stream=None, Dumper=Dumper,
getvalue = None
if stream is None:
if encoding is None:
from StringIO import StringIO
stream = io.StringIO()
else:
from cStringIO import StringIO
stream = StringIO()
stream = io.BytesIO()
getvalue = stream.getvalue
dumper = Dumper(stream, canonical=canonical, indent=indent, width=width,
allow_unicode=allow_unicode, line_break=line_break,
Expand All @@ -255,7 +253,7 @@ def dump_all(documents, stream=None, Dumper=Dumper,
default_style=None, default_flow_style=False,
canonical=None, indent=None, width=None,
allow_unicode=None, line_break=None,
encoding='utf-8', explicit_start=None, explicit_end=None,
encoding=None, explicit_start=None, explicit_end=None,
version=None, tags=None, sort_keys=True):
"""
Serialize a sequence of Python objects into a YAML stream.
Expand All @@ -264,10 +262,9 @@ def dump_all(documents, stream=None, Dumper=Dumper,
getvalue = None
if stream is None:
if encoding is None:
from StringIO import StringIO
stream = io.StringIO()
else:
from cStringIO import StringIO
stream = StringIO()
stream = io.BytesIO()
getvalue = stream.getvalue
dumper = Dumper(stream, default_style=default_style,
default_flow_style=default_flow_style,
Expand Down Expand Up @@ -399,13 +396,12 @@ def __init__(cls, name, bases, kwds):

cls.yaml_dumper.add_representer(cls, cls.to_yaml)

class YAMLObject(object):
class YAMLObject(metaclass=YAMLObjectMetaclass):
"""
An object that can dump itself to a YAML stream
and load itself from a YAML stream.
"""

__metaclass__ = YAMLObjectMetaclass
__slots__ = () # no direct instantiation, so allow immutable subclasses

yaml_loader = [Loader, FullLoader, UnsafeLoader]
Expand All @@ -414,18 +410,18 @@ class YAMLObject(object):
yaml_tag = None
yaml_flow_style = None

@classmethod
def from_yaml(cls, loader, node):
"""
Convert a representation node to a Python object.
"""
return loader.construct_yaml_object(node, cls)
from_yaml = classmethod(from_yaml)

@classmethod
def to_yaml(cls, dumper, data):
"""
Convert a Python object to a representation node.
"""
return dumper.represent_yaml_object(cls.yaml_tag, data, cls,
flow_style=cls.yaml_flow_style)
to_yaml = classmethod(to_yaml)

18 changes: 9 additions & 9 deletions lib/yaml/composer.py
@@ -1,14 +1,14 @@

__all__ = ['Composer', 'ComposerError']

from error import MarkedYAMLError
from events import *
from nodes import *
from .error import MarkedYAMLError
from .events import *
from .nodes import *

class ComposerError(MarkedYAMLError):
pass

class Composer(object):
class Composer:

def __init__(self):
self.anchors = {}
Expand Down Expand Up @@ -66,14 +66,14 @@ def compose_node(self, parent, index):
anchor = event.anchor
if anchor not in self.anchors:
raise ComposerError(None, None, "found undefined alias %r"
% anchor.encode('utf-8'), event.start_mark)
% anchor, event.start_mark)
return self.anchors[anchor]
event = self.peek_event()
anchor = event.anchor
if anchor is not None:
if anchor in self.anchors:
raise ComposerError("found duplicate anchor %r; first occurrence"
% anchor.encode('utf-8'), self.anchors[anchor].start_mark,
% anchor, self.anchors[anchor].start_mark,
"second occurrence", event.start_mark)
self.descend_resolver(parent, index)
if self.check_event(ScalarEvent):
Expand All @@ -88,7 +88,7 @@ def compose_node(self, parent, index):
def compose_scalar_node(self, anchor):
event = self.get_event()
tag = event.tag
if tag is None or tag == u'!':
if tag is None or tag == '!':
tag = self.resolve(ScalarNode, event.value, event.implicit)
node = ScalarNode(tag, event.value,
event.start_mark, event.end_mark, style=event.style)
Expand All @@ -99,7 +99,7 @@ def compose_scalar_node(self, anchor):
def compose_sequence_node(self, anchor):
start_event = self.get_event()
tag = start_event.tag
if tag is None or tag == u'!':
if tag is None or tag == '!':
tag = self.resolve(SequenceNode, None, start_event.implicit)
node = SequenceNode(tag, [],
start_event.start_mark, None,
Expand All @@ -117,7 +117,7 @@ def compose_sequence_node(self, anchor):
def compose_mapping_node(self, anchor):
start_event = self.get_event()
tag = start_event.tag
if tag is None or tag == u'!':
if tag is None or tag == '!':
tag = self.resolve(MappingNode, None, start_event.implicit)
node = MappingNode(tag, [],
start_event.start_mark, None,
Expand Down