Ignore:
Timestamp:
01/08/12 11:17:27 (8 years ago)
Author:
mnagni
Message:

Fixed a bug in objectEncoding

File:
1 edited

Legend:

Unmodified
Added
Removed
  • mauRepo/MolesManager/trunk/src/MolesManager/djencoder.py

    r8433 r8480  
    55''' 
    66from json.encoder import JSONEncoder 
    7 from MolesManager.forms.date import methodsWithDecorator 
    87import re 
    98import logging 
     9import inspect 
    1010 
    1111class DJEncoder(JSONEncoder): 
     
    5050                #return {} 
    5151            else: 
    52                 self.__markers[id(value)] = value 
    5352                if isinstance(value, str) or isinstance(value, unicode):                     
    5453                    self.__markers[id(value)] = escapeForJSON(value) 
     
    5655                    self.__markers[id(value)] = value 
    5756        return d 
     57 
     58def methodsWithDecorator(cls, decoratorName): 
     59    #if type(cls).__name__ == 'type' or type(cls).__name__ == 'instancemetho': 
     60    #    return  
     61    sourcelines = inspect.getsourcelines(cls)[0] 
     62    for i,line in enumerate(sourcelines): 
     63        line = line.strip() 
     64        if line.split('(')[0].strip() == '@'+decoratorName: # leaving a bit out 
     65            nextLine = sourcelines[i+1] 
     66            name = nextLine.split('def')[1].split('(')[0].strip() 
     67            yield(name) 
    5868 
    5969def encodeToJSON(toEncode): 
Note: See TracChangeset for help on using the changeset viewer.