Browse Source
Fix yaml.load() calls
Before PyYaml < 6, the following warning is issued:
./patacrep/patacrep/songbook/__init__.py:29:
YAMLLoadWarning: calling yaml.load() without Loader=... is
deprecated, as the default Loader is unsafe. Please read
https://msg.pyyaml.org/load for full details.
With PyYaml >= 6, the program crashes.
pull/272/head
Laurent Stacul
3 years ago
No known key found for this signature in database
GPG Key ID: 6A8B84A864DECF73
8 changed files with
10 additions and
10 deletions
patacrep/build.py
patacrep/content/__init__.py
patacrep/content/include.py
patacrep/songbook/__init__.py
patacrep/templates.py
setup.py
test/test_book/test_compilation.py
test/test_content/test_content.py
@ -380,6 +380,6 @@ def config_model(key):
"""
model_path = pkg_datapath ( ' templates ' , ' songbook_model.yml ' )
with encoding . open_read ( model_path ) as model_file :
data = yaml . load ( model_file )
data = yaml . safe_ load( model_file )
return data . get ( key , { } )
@ -238,7 +238,7 @@ def validate_parser_argument(raw_schema):
Will raise ` ContentError ` if the schema is not respected .
"""
schema = Rx . make_schema ( yaml . load ( raw_schema ) )
schema = Rx . make_schema ( yaml . safe_ load( raw_schema ) )
def wrap ( parse ) :
""" Wrap the parse function """
@ -74,7 +74,7 @@ def parse(keyword, config, argument):
filepath ,
encoding = config [ ' book ' ] [ ' encoding ' ]
) as content_file :
new_content = yaml . load ( content_file )
new_content = yaml . safe_ load( content_file )
except Exception as error : # pylint: disable=broad-except
new_contentlist . append_error ( ContentError (
keyword = " include " ,
@ -26,13 +26,13 @@ def open_songbook(filename):
try :
with patacrep . encoding . open_read ( filename ) as songbook_file :
user_songbook = yaml . load ( songbook_file )
user_songbook = yaml . safe_ load( songbook_file )
if ' encoding ' in user_songbook . get ( ' book ' , [ ] ) :
with encoding . open_read (
filename ,
encoding = user_songbook [ ' book ' ] [ ' encoding ' ]
) as songbook_file :
user_songbook = yaml . load ( songbook_file )
user_songbook = yaml . safe_ load( songbook_file )
except Exception as error : # pylint: disable=broad-except
raise patacrep . errors . SongbookError ( str ( error ) )
@ -240,7 +240,7 @@ class TexBookRenderer(Renderer):
variables [ templatename ] = { }
for variables_string in match :
try :
variables [ templatename ] . update ( yaml . load ( variables_string ) )
variables [ templatename ] . update ( yaml . safe_ load( variables_string ) )
except ValueError as exception :
raise errors . TemplateError (
exception ,
@ -53,7 +53,7 @@ setup(
packages = find_packages ( exclude = [ " test* " ] ) ,
license = " GPLv2 or any later version " ,
install_requires = [
" argdispatch " , " unidecode " , " jinja2 " , " ply " , " pyyaml " ,
" argdispatch " , " unidecode " , " jinja2 " , " ply " , " pyyaml==5.4.1 " ,
] ,
entry_points = {
' console_scripts ' : [
@ -166,7 +166,7 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
""" Compile songbook " on the fly " : without a physical songbook file. """
with open ( base + " .yaml " , mode = " r " , encoding = " utf8 " ) as sbfile :
sbyaml = yaml . load ( sbfile )
sbyaml = yaml . safe_ load( sbfile )
outputdir = os . path . dirname ( base )
outputname = os . path . basename ( base )
@ -47,7 +47,7 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
""" Test that `base.source` produces the correct file list """
sourcename = " {} .source " . format ( base )
with open ( sourcename , mode = " r " , encoding = " utf8 " ) as sourcefile :
sbcontent = yaml . load ( sourcefile )
sbcontent = yaml . safe_ load( sourcefile )
outputdir = os . path . dirname ( base )
config = cls . _generate_config ( sbcontent , outputdir , base )
@ -60,7 +60,7 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
if not os . path . exists ( controlname ) :
raise Exception ( " Missing control: " + str ( controlname ) . replace ( " ' " , ' " ' ) )
with open ( controlname , mode = " r " , encoding = " utf8 " ) as controlfile :
controllist = yaml . load ( controlfile )
controllist = yaml . safe_ load( controlfile )
self . assertEqual ( controllist , sourcelist )