Changeset 331
- Timestamp:
- 12/29/08 18:21:43 (4 years ago)
- Location:
- pyyaml/trunk
- Files:
-
- 6 edited
- 1 copied
-
ext/_yaml.h (modified) (1 diff)
-
ext/_yaml.pyx (modified) (8 diffs)
-
lib3/yaml/__init__.py (modified) (2 diffs)
-
lib3/yaml/cyaml.py (copied) (copied from pyyaml/trunk/lib/yaml/cyaml.py) (4 diffs)
-
setup.py (modified) (4 diffs)
-
tests/lib3/test_structure.py (modified) (2 diffs)
-
tests/lib3/test_yaml_ext.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
pyyaml/trunk/ext/_yaml.h
r205 r331 2 2 #include <yaml.h> 3 3 4 #if PY_MAJOR_VERSION >= 3 5 6 #define PyString_CheckExact PyBytes_CheckExact 7 #define PyString_AS_STRING PyBytes_AS_STRING 8 #define PyString_GET_SIZE PyBytes_GET_SIZE 9 #define PyString_FromStringAndSize PyBytes_FromStringAndSize 10 11 #endif -
pyyaml/trunk/ext/_yaml.pyx
r310 r331 252 252 253 253 def __init__(self, stream): 254 cdef is_readable 254 255 if yaml_parser_initialize(&self.parser) == 0: 255 256 raise MemoryError 256 257 self.parsed_event.type = YAML_NO_EVENT 257 if hasattr(stream, 'read'): 258 is_readable = 1 259 try: 260 stream.read 261 except AttributeError: 262 is_readable = 0 263 if is_readable: 258 264 self.stream = stream 259 265 try: … … 358 364 encoding = None 359 365 if token.data.stream_start.encoding == YAML_UTF8_ENCODING: 360 encoding = "utf-8"366 encoding = u"utf-8" 361 367 elif token.data.stream_start.encoding == YAML_UTF16LE_ENCODING: 362 encoding = "utf-16-le"368 encoding = u"utf-16-le" 363 369 elif token.data.stream_start.encoding == YAML_UTF16BE_ENCODING: 364 encoding = "utf-16-be"370 encoding = u"utf-16-be" 365 371 return StreamStartToken(start_mark, end_mark, encoding) 366 372 elif token.type == YAML_STREAM_END_TOKEN: 367 373 return StreamEndToken(start_mark, end_mark) 368 374 elif token.type == YAML_VERSION_DIRECTIVE_TOKEN: 369 return DirectiveToken( "YAML",375 return DirectiveToken(u"YAML", 370 376 (token.data.version_directive.major, 371 377 token.data.version_directive.minor), 372 378 start_mark, end_mark) 373 379 elif token.type == YAML_TAG_DIRECTIVE_TOKEN: 374 return DirectiveToken("TAG", 375 (token.data.tag_directive.handle, 376 token.data.tag_directive.prefix), 380 handle = PyUnicode_DecodeUTF8(token.data.tag_directive.handle, 381 strlen(token.data.tag_directive.handle), 'strict') 382 prefix = PyUnicode_DecodeUTF8(token.data.tag_directive.prefix, 383 strlen(token.data.tag_directive.prefix), 'strict') 384 return DirectiveToken(u"TAG", (handle, prefix), 377 385 start_mark, end_mark) 378 386 elif token.type == YAML_DOCUMENT_START_TOKEN: … … 871 879 parser = <CParser>data 872 880 value = parser.stream.read(size) 881 if PyUnicode_CheckExact(value) != 0: 882 value = PyUnicode_AsUTF8String(value) 873 883 if PyString_CheckExact(value) == 0: 874 884 raise TypeError("a string value is expected") … … 895 905 cdef int last_alias_id 896 906 cdef int closed 907 cdef int decode_output 897 908 898 909 def __init__(self, stream, canonical=None, indent=None, width=None, … … 902 913 raise MemoryError 903 914 self.stream = stream 915 self.decode_output = 1 916 try: 917 stream.encoding 918 except AttributeError: 919 self.decode_output = 0 904 920 yaml_emitter_set_output(&self.emitter, output_handler, <void *>self) 905 921 if canonical is not None: … … 1217 1233 if self.anchors[node] is None: 1218 1234 self.last_alias_id = self.last_alias_id+1 1219 self.anchors[node] = "id%03d" % self.last_alias_id1235 self.anchors[node] = u"id%03d" % self.last_alias_id 1220 1236 else: 1221 1237 self.anchors[node] = None … … 1246 1262 anchor = NULL 1247 1263 if anchor_object is not None: 1248 anchor = PyString_AS_STRING( anchor_object)1264 anchor = PyString_AS_STRING(PyUnicode_AsUTF8String(anchor_object)) 1249 1265 if node in self.serialized_nodes: 1250 1266 if yaml_alias_event_initialize(&event, anchor) == 0: … … 1358 1374 cdef CEmitter emitter 1359 1375 emitter = <CEmitter>data 1360 value = PyString_FromStringAndSize(buffer, size) 1376 if emitter.decode_output == 0: 1377 value = PyString_FromStringAndSize(buffer, size) 1378 else: 1379 value = PyUnicode_DecodeUTF8(buffer, size, 'strict') 1361 1380 emitter.stream.write(value) 1362 1381 return 1 -
pyyaml/trunk/lib3/yaml/__init__.py
r328 r331 1 2 __version__ = '3.08'3 __with_libyaml__ = False4 1 5 2 from .error import * … … 11 8 from .loader import * 12 9 from .dumper import * 10 11 __version__ = '3.08' 12 try: 13 from .cyaml import * 14 __with_libyaml__ = True 15 except ImportError: 16 __with_libyaml__ = False 13 17 14 18 import io -
pyyaml/trunk/lib3/yaml/cyaml.py
r223 r331 5 5 from _yaml import CParser, CEmitter 6 6 7 from constructor import *7 from .constructor import * 8 8 9 from serializer import *10 from representer import *9 from .serializer import * 10 from .representer import * 11 11 12 from resolver import *12 from .resolver import * 13 13 14 14 class CBaseLoader(CParser, BaseConstructor, BaseResolver): … … 42 42 version=None, tags=None): 43 43 CEmitter.__init__(self, stream, canonical=canonical, 44 indent=indent, width=width, 44 indent=indent, width=width, encoding=encoding, 45 45 allow_unicode=allow_unicode, line_break=line_break, 46 46 explicit_start=explicit_start, explicit_end=explicit_end, … … 59 59 version=None, tags=None): 60 60 CEmitter.__init__(self, stream, canonical=canonical, 61 indent=indent, width=width, 61 indent=indent, width=width, encoding=encoding, 62 62 allow_unicode=allow_unicode, line_break=line_break, 63 63 explicit_start=explicit_start, explicit_end=explicit_end, … … 76 76 version=None, tags=None): 77 77 CEmitter.__init__(self, stream, canonical=canonical, 78 indent=indent, width=width, 78 indent=indent, width=width, encoding=encoding, 79 79 allow_unicode=allow_unicode, line_break=line_break, 80 80 explicit_start=explicit_start, explicit_end=explicit_end, -
pyyaml/trunk/setup.py
r330 r331 74 74 sys.modules['distutils.command.build_ext'].Extension = _Extension 75 75 76 try: 77 from Pyrex.Distutils import Extension as _Extension 78 from Pyrex.Distutils import build_ext as _build_ext 79 with_pyrex = True 80 except ImportError: 81 with_pyrex = False 76 with_pyrex = None 77 if sys.version_info[0] < 3: 78 try: 79 from Cython.Distutils.extension import Extension as _Extension 80 from Cython.Distutils import build_ext as _build_ext 81 with_pyrex = 'cython' 82 except ImportError: 83 try: 84 from Pyrex.Distutils import Extension as _Extension 85 from Pyrex.Distutils import build_ext as _build_ext 86 with_pyrex = 'pyrex' 87 except ImportError: 88 pass 82 89 83 90 … … 168 175 filenames = [] 169 176 for ext in self.extensions: 170 if with_pyrex :177 if with_pyrex == 'pyrex': 171 178 self.pyrex_sources(ext.sources, ext) 179 elif with_pyrex == 'cython': 180 self.cython_sources(ext.sources, ext) 172 181 for filename in ext.sources: 173 182 filenames.append(filename) … … 198 207 if not with_ext: 199 208 continue 200 if with_pyrex :209 if with_pyrex == 'pyrex': 201 210 ext.sources = self.pyrex_sources(ext.sources, ext) 211 elif with_pyrex == 'cython': 212 ext.sources = self.cython_sources(ext.sources, ext) 202 213 self.build_extension(ext) 203 214 … … 298 309 if __name__ == '__main__': 299 310 300 if sys.version_info[0] < 3: 301 302 setup( 303 name=NAME, 304 version=VERSION, 305 description=DESCRIPTION, 306 long_description=LONG_DESCRIPTION, 307 author=AUTHOR, 308 author_email=AUTHOR_EMAIL, 309 license=LICENSE, 310 platforms=PLATFORMS, 311 url=URL, 312 download_url=DOWNLOAD_URL, 313 classifiers=CLASSIFIERS, 314 315 package_dir={'': 'lib'}, 316 packages=['yaml'], 317 ext_modules=[ 318 Extension('_yaml', ['ext/_yaml.pyx'], 319 'libyaml', "LibYAML bindings", LIBYAML_CHECK, 320 libraries=['yaml']), 321 ], 322 323 distclass=Distribution, 324 cmdclass={ 325 'build_ext': build_ext, 326 'bdist_rpm': bdist_rpm, 327 'test': test, 328 }, 329 ) 330 331 else: 332 333 setup( 334 name=NAME, 335 version=VERSION, 336 description=DESCRIPTION, 337 long_description=LONG_DESCRIPTION, 338 author=AUTHOR, 339 author_email=AUTHOR_EMAIL, 340 license=LICENSE, 341 platforms=PLATFORMS, 342 url=URL, 343 download_url=DOWNLOAD_URL, 344 classifiers=CLASSIFIERS, 345 346 package_dir={'': 'lib3'}, 347 packages=['yaml'], 348 349 cmdclass={ 350 'test': test, 351 }, 352 ) 353 311 package_dir = { 312 '2': 'lib', 313 } 314 315 setup( 316 name=NAME, 317 version=VERSION, 318 description=DESCRIPTION, 319 long_description=LONG_DESCRIPTION, 320 author=AUTHOR, 321 author_email=AUTHOR_EMAIL, 322 license=LICENSE, 323 platforms=PLATFORMS, 324 url=URL, 325 download_url=DOWNLOAD_URL, 326 classifiers=CLASSIFIERS, 327 328 package_dir={'': {2: 'lib', 3: 'lib3'}[sys.version_info[0]]}, 329 packages=['yaml'], 330 ext_modules=[ 331 Extension('_yaml', ['ext/_yaml.pyx'], 332 'libyaml', "LibYAML bindings", LIBYAML_CHECK, 333 libraries=['yaml']), 334 ], 335 336 distclass=Distribution, 337 338 cmdclass={ 339 'build_ext': build_ext, 340 'bdist_rpm': bdist_rpm, 341 'test': test, 342 }, 343 ) 344 -
pyyaml/trunk/tests/lib3/test_structure.py
r330 r331 140 140 def construct_mapping(self, node): 141 141 pairs = self.construct_pairs(node) 142 pairs.sort( )142 pairs.sort(key=(lambda i: str(i))) 143 143 return pairs 144 144 def construct_undefined(self, node): … … 156 156 def construct_mapping(self, node): 157 157 pairs = self.construct_pairs(node) 158 pairs.sort( )158 pairs.sort(key=(lambda i: str(i))) 159 159 return pairs 160 160 def construct_undefined(self, node): -
pyyaml/trunk/tests/lib3/test_yaml_ext.py
r330 r331 253 253 if not isinstance(collection, dict): 254 254 collection = vars(collection) 255 keys = collection.keys() 256 keys.sort() 257 for key in keys: 255 for key in sorted(collection): 258 256 value = collection[key] 259 257 if isinstance(value, types.FunctionType) and hasattr(value, 'unittest'): 260 258 functions.append(wrap_ext_function(value)) 261 259 for function in functions: 262 assert function. unittest_namenot in globals()263 globals()[function. unittest_name] = function260 assert function.__name__ not in globals() 261 globals()[function.__name__] = function 264 262 265 263 import test_tokens, test_structure, test_errors, test_resolver, test_constructor, \
Note: See TracChangeset
for help on using the changeset viewer.
