Mageia Bugzilla – Attachment 10898 Details for
Bug 23242
python-yaml new security issue CVE-2017-18342
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
New Account
|
Forgot Password
Series of tests from online tutorial
yamltests.py (text/plain), 2.85 KB, created by
Len Lawrence
on 2019-04-01 20:41:54 CEST
(
hide
)
Description:
Series of tests from online tutorial
Filename:
MIME Type:
Creator:
Len Lawrence
Created:
2019-04-01 20:41:54 CEST
Size:
2.85 KB
patch
obsolete
>#!/usr/bin env python > >import yaml > >doc = yaml.safe_load(""" > - Hesperiidae > - Papilionidae > - Apatelodidae > - Epiplemidae > """) > >print( "** test 1" ) >print( doc ) >print( "\n--------------------------------------------" ) > >mixed = yaml.load( """ > none: [~, null] > bool: [true, false, on, off] > int: 42 > float: 3.14159 > list: [LITE, RES_ACID, SUS_DEXT] > dict: {hp: 13, sp: 5} > """, Loader=yaml.FullLoader ) > >print( "** test 2" ) >print( mixed ) >print( "\n--------------------------------------------" ) > >class Hero: > def __init__( self, name, hp, sp ): > self.name = name > self.hp = hp > self.sp = sp > def __repr__( self ): > return "%s(name=%r, hp=%r, sp=%r)" % ( > self.__class__.__name__, self.name, self.hp, self.sp ) > >objecttest = yaml.load( """ > !!python/object:__main__.Hero > name: Welthyr Syxgon > hp: 1200 > sp: 0 > """, Loader=yaml.FullLoader ) > >print( "** test 3" ) >print( objecttest ) >print( "\n--------------------------------------------" ) >print( "** test 4" ) >print( yaml.dump( {'name': 'Silenthand Olleander', 'race': 'Human', > 'traits': ['ONE_HAND', 'ONE_EYE']} ) ) >print( "\n--------------------------------------------" ) >print( "** test 5" ) >print( yaml.dump( [1,2,3], explicit_start=True ) ) >print( " " ) >print( yaml.dump_all( [1,2,3], explicit_start=True ) ) >print( "\n--------------------------------------------" ) > >class Hero: > def __init__(self, name, hp, sp): > self.name = name > self.hp = hp > self.sp = sp > def __repr__(self): > return "%s(name=%r, hp=%r, sp=%r)" % ( > self.__class__.__name__, self.name, self.hp, self.sp) > >print( "** test 6" ) >print( yaml.dump( Hero("Galain Ysseleg", hp=-3, sp=2) ) ) >print( "\n--------------------------------------------" ) >print( "** test 7" ) >print( "# Examples of output formatting:" ) > >print( yaml.dump(range(20)) ) >print( yaml.dump(range(20), width=50, indent=4) ) >print( yaml.dump(range(5), canonical=True) ) >print( yaml.dump(range(5), default_flow_style=False) ) >print( yaml.dump(range(5), default_flow_style=True, default_style='"') ) >print( "\n--------------------------------------------" ) > >print( "Test 8 fails - have not figured out why\n" ) > >class Monster(yaml.YAMLObject): > yaml_tag = u'!Monster' > def __init__(self, name, hp, ac, attacks): > self.name = name > self.hp = hp > self.ac = ac > self.attacks = attacks > def __repr__(self): > return "%s(name=%r, hp=%r, ac=%r, attacks=%r)" % ( > self.__class__.__name__, self.name, self.hp, self.ac, self.attacks) > >print( "** test 8" ) >print( yaml.dump( Monster( > name='Cave lizard', hp=[3,6], ac=16, attacks=['BITE','HURT']) ) ) > >spider = yaml.load( """ > --- !Monster > name: Cave spider > hp: [2,6] # 2d6 > ac: 16 > attacks: [BITE, HURT] > """, Loader=yaml.FullLoader ) > > >
#!/usr/bin env python import yaml doc = yaml.safe_load(""" - Hesperiidae - Papilionidae - Apatelodidae - Epiplemidae """) print( "** test 1" ) print( doc ) print( "\n--------------------------------------------" ) mixed = yaml.load( """ none: [~, null] bool: [true, false, on, off] int: 42 float: 3.14159 list: [LITE, RES_ACID, SUS_DEXT] dict: {hp: 13, sp: 5} """, Loader=yaml.FullLoader ) print( "** test 2" ) print( mixed ) print( "\n--------------------------------------------" ) class Hero: def __init__( self, name, hp, sp ): self.name = name self.hp = hp self.sp = sp def __repr__( self ): return "%s(name=%r, hp=%r, sp=%r)" % ( self.__class__.__name__, self.name, self.hp, self.sp ) objecttest = yaml.load( """ !!python/object:__main__.Hero name: Welthyr Syxgon hp: 1200 sp: 0 """, Loader=yaml.FullLoader ) print( "** test 3" ) print( objecttest ) print( "\n--------------------------------------------" ) print( "** test 4" ) print( yaml.dump( {'name': 'Silenthand Olleander', 'race': 'Human', 'traits': ['ONE_HAND', 'ONE_EYE']} ) ) print( "\n--------------------------------------------" ) print( "** test 5" ) print( yaml.dump( [1,2,3], explicit_start=True ) ) print( " " ) print( yaml.dump_all( [1,2,3], explicit_start=True ) ) print( "\n--------------------------------------------" ) class Hero: def __init__(self, name, hp, sp): self.name = name self.hp = hp self.sp = sp def __repr__(self): return "%s(name=%r, hp=%r, sp=%r)" % ( self.__class__.__name__, self.name, self.hp, self.sp) print( "** test 6" ) print( yaml.dump( Hero("Galain Ysseleg", hp=-3, sp=2) ) ) print( "\n--------------------------------------------" ) print( "** test 7" ) print( "# Examples of output formatting:" ) print( yaml.dump(range(20)) ) print( yaml.dump(range(20), width=50, indent=4) ) print( yaml.dump(range(5), canonical=True) ) print( yaml.dump(range(5), default_flow_style=False) ) print( yaml.dump(range(5), default_flow_style=True, default_style='"') ) print( "\n--------------------------------------------" ) print( "Test 8 fails - have not figured out why\n" ) class Monster(yaml.YAMLObject): yaml_tag = u'!Monster' def __init__(self, name, hp, ac, attacks): self.name = name self.hp = hp self.ac = ac self.attacks = attacks def __repr__(self): return "%s(name=%r, hp=%r, ac=%r, attacks=%r)" % ( self.__class__.__name__, self.name, self.hp, self.ac, self.attacks) print( "** test 8" ) print( yaml.dump( Monster( name='Cave lizard', hp=[3,6], ac=16, attacks=['BITE','HURT']) ) ) spider = yaml.load( """ --- !Monster name: Cave spider hp: [2,6] # 2d6 ac: 16 attacks: [BITE, HURT] """, Loader=yaml.FullLoader )
View Attachment As Raw
Actions:
View
Attachments on
bug 23242
:
10897
| 10898