Source

pyyaml / lib / yaml / __init__.py

Diff from to

lib/yaml/__init__.py

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