Changeset 368
- Timestamp:
- 08/31/09 05:13:59 (4 years ago)
- Location:
- pyyaml/tags/3.09
- Files:
-
- 3 edited
-
ext/_yaml.pyx (modified) (1 diff)
-
tests/lib/test_input_output.py (modified) (2 diffs)
-
tests/lib3/test_input_output.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
pyyaml/tags/3.09/ext/_yaml.pyx
r361 r368 956 956 self.dump_unicode = 0 957 957 if PY_MAJOR_VERSION < 3: 958 if hasattr(stream, 'encoding'):958 if getattr3(stream, 'encoding', None): 959 959 self.dump_unicode = 1 960 960 else: -
pyyaml/tags/3.09/tests/lib/test_input_output.py
r335 r368 1 1 2 2 import yaml 3 import codecs, StringIO 3 import codecs, StringIO, tempfile, os, os.path 4 4 5 5 def _unicode_open(file, encoding, errors='strict'): … … 96 96 test_unicode_output.unittest = ['.unicode'] 97 97 98 def test_file_output(unicode_filename, verbose=False): 99 data = open(unicode_filename, 'rb').read().decode('utf-8') 100 handle, filename = tempfile.mkstemp() 101 os.close(handle) 102 try: 103 stream = StringIO.StringIO() 104 yaml.dump(data, stream, allow_unicode=True) 105 data1 = stream.getvalue() 106 stream = open(filename, 'wb') 107 yaml.dump(data, stream, allow_unicode=True) 108 stream.close() 109 data2 = open(filename, 'rb').read() 110 stream = open(filename, 'wb') 111 yaml.dump(data, stream, encoding='utf-16-le', allow_unicode=True) 112 stream.close() 113 data3 = open(filename, 'rb').read().decode('utf-16-le')[1:].encode('utf-8') 114 stream = _unicode_open(open(filename, 'wb'), 'utf-8') 115 yaml.dump(data, stream, allow_unicode=True) 116 stream.close() 117 data4 = open(filename, 'rb').read() 118 assert data1 == data2, (data1, data2) 119 assert data1 == data3, (data1, data3) 120 assert data1 == data4, (data1, data4) 121 finally: 122 if os.path.exists(filename): 123 os.unlink(filename) 124 125 test_file_output.unittest = ['.unicode'] 126 98 127 def test_unicode_transfer(unicode_filename, verbose=False): 99 128 data = open(unicode_filename, 'rb').read().decode('utf-8') -
pyyaml/tags/3.09/tests/lib3/test_input_output.py
r336 r368 1 1 2 2 import yaml 3 import codecs, io 3 import codecs, io, tempfile, os, os.path 4 4 5 5 def test_unicode_input(unicode_filename, verbose=False): … … 95 95 test_unicode_output.unittest = ['.unicode'] 96 96 97 def test_file_output(unicode_filename, verbose=False): 98 data = open(unicode_filename, 'rb').read().decode('utf-8') 99 handle, filename = tempfile.mkstemp() 100 os.close(handle) 101 try: 102 stream = io.StringIO() 103 yaml.dump(data, stream, allow_unicode=True) 104 data1 = stream.getvalue() 105 stream = io.BytesIO() 106 yaml.dump(data, stream, encoding='utf-16-le', allow_unicode=True) 107 data2 = stream.getvalue().decode('utf-16-le')[1:] 108 stream = open(filename, 'w', encoding='utf-16-le') 109 yaml.dump(data, stream, allow_unicode=True) 110 stream.close() 111 data3 = open(filename, 'r', encoding='utf-16-le').read() 112 stream = open(filename, 'wb') 113 yaml.dump(data, stream, encoding='utf-8', allow_unicode=True) 114 stream.close() 115 data4 = open(filename, 'r', encoding='utf-8').read() 116 assert data1 == data2, (data1, data2) 117 assert data1 == data3, (data1, data3) 118 assert data1 == data4, (data1, data4) 119 finally: 120 if os.path.exists(filename): 121 os.unlink(filename) 122 123 test_file_output.unittest = ['.unicode'] 124 97 125 def test_unicode_transfer(unicode_filename, verbose=False): 98 126 data = open(unicode_filename, 'rb').read().decode('utf-8')
Note: See TracChangeset
for help on using the changeset viewer.
