Changeset 49 for trunk/lib

Show
Ignore:
Timestamp:
02/19/06 03:10:24 (6 years ago)
Author:
xi
Message:

Fix segfault under Python2.3.

Support for complex numbers.

Add /usr/local to the search path.

Location:
trunk/lib/syck
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/syck/dumpers.py

    r36 r49  
    144144        return _syck.Scalar(value, tag="tag:yaml.org,2002:float") 
    145145 
     146    def represent_complex(self, object): 
     147        if object.real != 0.0: 
     148            value = '%s+%sj' % (repr(object.real), repr(object.imag)) 
     149        else: 
     150            value = '%sj' % repr(object.imag) 
     151        return _syck.Scalar(value, tag="tag:python.yaml.org,2002:complex") 
     152 
    146153    def represent_sets_Set(self, object): 
    147154        return _syck.Seq(list(object), tag="tag:yaml.org,2002:set") 
     
    165172    represent_function = represent_type 
    166173    represent_builtin_function_or_method = represent_type 
     174 
     175    def represent_module(self, object): 
     176        return _syck.Scalar('', tag="tag:python.yaml.org,2002:module:"+object.__name__) 
    167177 
    168178    def represent_instance(self, object): 
  • trunk/lib/syck/loaders.py

    r36 r49  
    1313 
    1414try: 
    15     import sets 
    16 except ImportError: 
    17     class _sets: 
    18         def Set(self, items): 
     15    Set = set 
     16except: 
     17    try: 
     18        from sets import Set 
     19    except ImportError: 
     20        def Set(items): 
    1921            set = {} 
    2022            for items in items: 
    2123                set[items] = None 
    2224            return set 
    23     sets = _sets() 
    2425 
    2526import _syck 
     
    288289 
    289290    def construct_set(self, node): 
    290         return sets.Set(node.value) 
     291        return Set(node.value) 
    291292 
    292293    def construct_python_none(self, node): 
     
    304305    def construct_python_float(self, node): 
    305306        return float(node.value) 
     307 
     308    def construct_python_complex(self, node): 
     309        return complex(node.value) 
    306310 
    307311    def construct_python_str(self, node): 
     
    359363        return self.find_python_object(node) 
    360364 
     365    def construct_python_module(self, node): 
     366        module_name = node.tag.split(':')[3] 
     367        __import__(module_name) 
     368        return sys.modules[module_name] 
     369 
    361370    def construct_python_object(self, node): 
    362371        cls = self.find_python_object(node)