Commits

Matt Behrens committed 327ffae

better handling for the tz_aware_datetimes keywork argument

  • Participants
  • Parent commits d4be47e

Comments (0)

Files changed (4)

File lib/yaml/__init__.py

     finally:
         loader.dispose()
 
-def load(stream, Loader=Loader, tz_aware_datetimes=False):
+def load(stream, Loader=Loader, **kwargs):
     """
     Parse the first YAML document in a stream
     and produce the corresponding Python object.
     """
-    try:
-        loader = Loader(stream, tz_aware_datetimes=tz_aware_datetimes)
-    except TypeError:
-        loader = Loader(stream)
+    loader = Loader(stream, **kwargs)
     try:
         return loader.get_single_data()
     finally:
         loader.dispose()
 
-def load_all(stream, Loader=Loader, tz_aware_datetimes=False):
+def load_all(stream, Loader=Loader, **kwargs):
     """
     Parse all YAML documents in a stream
     and produce corresponding Python objects.
     """
-    try:
-        loader = Loader(stream, tz_aware_datetimes=tz_aware_datetimes)
-    except TypeError:
-        loader = Loader(stream)
+    loader = Loader(stream, **kwargs)
     try:
         while loader.check_data():
             yield loader.get_data()
     finally:
         loader.dispose()
 
-def safe_load(stream, tz_aware_datetimes=False):
+def safe_load(stream, **kwargs):
     """
     Parse the first YAML document in a stream
     and produce the corresponding Python object.
     Resolve only basic YAML tags.
     """
-    return load(stream, SafeLoader, tz_aware_datetimes=tz_aware_datetimes)
+    return load(stream, SafeLoader, **kwargs)
 
-def safe_load_all(stream, tz_aware_datetimes=False):
+def safe_load_all(stream, **kwargs):
     """
     Parse all YAML documents in a stream
     and produce corresponding Python objects.
     Resolve only basic YAML tags.
     """
-    return load_all(stream, SafeLoader, tz_aware_datetimes=tz_aware_datetimes)
+    return load_all(stream, SafeLoader, **kwargs)
 
 def emit(events, stream=None, Dumper=Dumper,
         canonical=None, indent=None, width=None,

File lib/yaml/loader.py

 
 class BaseLoader(Reader, Scanner, Parser, Composer, BaseConstructor, BaseResolver):
 
-    def __init__(self, stream, tz_aware_datetimes=False):
+    def __init__(self, stream):
         Reader.__init__(self, stream)
         Scanner.__init__(self)
         Parser.__init__(self)
         Scanner.__init__(self)
         Parser.__init__(self)
         Composer.__init__(self)
-        SafeConstructor.__init__(self, tz_aware_datetimes)
+        SafeConstructor.__init__(self, tz_aware_datetimes=tz_aware_datetimes)
         Resolver.__init__(self)
 
 class Loader(Reader, Scanner, Parser, Composer, Constructor, Resolver):
         Scanner.__init__(self)
         Parser.__init__(self)
         Composer.__init__(self)
-        Constructor.__init__(self, tz_aware_datetimes)
+        Constructor.__init__(self, tz_aware_datetimes=tz_aware_datetimes)
         Resolver.__init__(self)
 

File lib3/yaml/__init__.py

     finally:
         loader.dispose()
 
-def load(stream, Loader=Loader, tz_aware_datetimes=False):
+def load(stream, Loader=Loader, **kwargs):
     """
     Parse the first YAML document in a stream
     and produce the corresponding Python object.
     """
-    try:
-        loader = Loader(stream, tz_aware_datetimes=tz_aware_datetimes)
-    except TypeError:
-        loader = Loader(stream)
+    loader = Loader(stream, **kwargs)
     try:
         return loader.get_single_data()
     finally:
         loader.dispose()
 
-def load_all(stream, Loader=Loader, tz_aware_datetimes=False):
+def load_all(stream, Loader=Loader, **kwargs):
     """
     Parse all YAML documents in a stream
     and produce corresponding Python objects.
     """
-    try:
-        loader = Loader(stream, tz_aware_datetimes=tz_aware_datetimes)
-    except TypeError:
-        loader = Loader(stream)
+    loader = Loader(stream, **kwargs)
     try:
         while loader.check_data():
             yield loader.get_data()
     finally:
         loader.dispose()
 
-def safe_load(stream, tz_aware_datetimes=False):
+def safe_load(stream, **kwargs):
     """
     Parse the first YAML document in a stream
     and produce the corresponding Python object.
     Resolve only basic YAML tags.
     """
-    return load(stream, SafeLoader, tz_aware_datetimes=tz_aware_datetimes)
+    return load(stream, SafeLoader, **kwargs)
 
-def safe_load_all(stream, tz_aware_datetimes=False):
+def safe_load_all(stream, **kwargs):
     """
     Parse all YAML documents in a stream
     and produce corresponding Python objects.
     Resolve only basic YAML tags.
     """
-    return load_all(stream, SafeLoader, tz_aware_datetimes=tz_aware_datetimes)
+    return load_all(stream, SafeLoader, **kwargs)
 
 def emit(events, stream=None, Dumper=Dumper,
         canonical=None, indent=None, width=None,

File lib3/yaml/loader.py

 
 class BaseLoader(Reader, Scanner, Parser, Composer, BaseConstructor, BaseResolver):
 
-    def __init__(self, stream, tz_aware_datetimes=False):
+    def __init__(self, stream):
         Reader.__init__(self, stream)
         Scanner.__init__(self)
         Parser.__init__(self)
         Scanner.__init__(self)
         Parser.__init__(self)
         Composer.__init__(self)
-        SafeConstructor.__init__(self, tz_aware_datetimes)
+        SafeConstructor.__init__(self, tz_aware_datetimes=tz_aware_datetimes)
         Resolver.__init__(self)
 
 class Loader(Reader, Scanner, Parser, Composer, Constructor, Resolver):
         Scanner.__init__(self)
         Parser.__init__(self)
         Composer.__init__(self)
-        Constructor.__init__(self, tz_aware_datetimes)
+        Constructor.__init__(self, tz_aware_datetimes=tz_aware_datetimes)
         Resolver.__init__(self)