Changeset 235


Ignore:
Timestamp:
12/08/06 10:36:53 (8 years ago)
Author:
xi
Message:

Use the types module instead of constructing type objects by hand. Fix #41. Thanks to v.haisman@… for the patch.

Location:
pyyaml/trunk/lib/yaml
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pyyaml/trunk/lib/yaml/constructor.py

    r234 r235  
    1313    from sets import Set as set 
    1414 
    15 import binascii, re, sys 
     15import binascii, re, sys, types 
    1616 
    1717class ConstructorError(MarkedYAMLError): 
     
    3737        if self.check_node(): 
    3838            return self.construct_document(self.get_node()) 
    39  
    40     def g(): yield None 
    41     generator_type = type(g()) 
    42     del g 
    4339 
    4440    def construct_document(self, node): 
     
    9288        else: 
    9389            data = constructor(self, tag_suffix, node) 
    94         if isinstance(data, self.generator_type): 
     90        if isinstance(data, types.GeneratorType): 
    9591            generator = data 
    9692            data = generator.next() 
  • pyyaml/trunk/lib/yaml/parser.py

    r222 r235  
    292292                    end_mark = token.end_mark 
    293293                    anchor = token.value 
    294             if tag is not None and tag != u'!': 
     294            if tag is not None: 
    295295                handle, suffix = tag 
    296296                if handle is not None: 
  • pyyaml/trunk/lib/yaml/representer.py

    r225 r235  
    1313    from sets import Set as set 
    1414 
    15 import sys, copy_reg 
     15import sys, copy_reg, types 
    1616 
    1717class RepresenterError(YAMLError): 
     
    3636        self.object_keeper = [] 
    3737        self.alias_key = None 
    38  
    39     class C: pass 
    40     c = C() 
    41     def f(): pass 
    42     def g(): yield None 
    43     classobj_type = type(C) 
    44     instance_type = type(c) 
    45     function_type = type(f) 
    46     generator_type = type(g()) 
    47     builtin_function_type = type(abs) 
    48     module_type = type(sys) 
    49     del C, c, f, g 
    5038 
    5139    def get_classobj_bases(self, cls): 
     
    6957            self.object_keeper.append(data) 
    7058        data_types = type(data).__mro__ 
    71         if type(data) is self.instance_type: 
     59        if type(data) is types.InstanceType: 
    7260            data_types = self.get_classobj_bases(data.__class__)+list(data_types) 
    7361        if data_types[0] in self.yaml_representers: 
     
    472460        Representer.represent_name) 
    473461 
    474 Representer.add_representer(Representer.classobj_type, 
     462Representer.add_representer(types.ClassType, 
    475463        Representer.represent_name) 
    476464 
    477 Representer.add_representer(Representer.function_type, 
     465Representer.add_representer(types.FunctionType, 
    478466        Representer.represent_name) 
    479467 
    480 Representer.add_representer(Representer.builtin_function_type, 
     468Representer.add_representer(types.BuiltinFunctionType, 
    481469        Representer.represent_name) 
    482470 
    483 Representer.add_representer(Representer.module_type, 
     471Representer.add_representer(types.ModuleType, 
    484472        Representer.represent_module) 
    485473 
    486 Representer.add_multi_representer(Representer.instance_type, 
     474Representer.add_multi_representer(types.InstanceType, 
    487475        Representer.represent_instance) 
    488476 
Note: See TracChangeset for help on using the changeset viewer.