Merge pull request #3754 from jtraglia/add-0x-quotes
Encode zero-length hex-strings with quotes
This commit is contained in:
commit
60343aeeaa
|
@ -65,7 +65,14 @@ def get_default_yaml():
|
||||||
def _represent_none(self, _):
|
def _represent_none(self, _):
|
||||||
return self.represent_scalar('tag:yaml.org,2002:null', 'null')
|
return self.represent_scalar('tag:yaml.org,2002:null', 'null')
|
||||||
|
|
||||||
|
def _represent_str(self, data):
|
||||||
|
if data.startswith("0x"):
|
||||||
|
# Without this, a zero-byte hex string is represented without quotes.
|
||||||
|
return self.represent_scalar('tag:yaml.org,2002:str', data, style="'")
|
||||||
|
return self.represent_str(data)
|
||||||
|
|
||||||
yaml.representer.add_representer(type(None), _represent_none)
|
yaml.representer.add_representer(type(None), _represent_none)
|
||||||
|
yaml.representer.add_representer(str, _represent_str)
|
||||||
|
|
||||||
return yaml
|
return yaml
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue