Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(8)  |  Call(6)  |  Derive(0)  |  Import(2)
Is the opposite of decode_for_json
    

        def encode_after_json(value):
    """ Is the opposite of decode_for_json
    """
    # there should not be any encoded strings
    if isinstance(value, str):
        value = unicode(value)

    # unicode
    if isinstance(value, unicode):
        encoding, nval = unicode(value).split(':', 1)
        if encoding == u'unicode':
            return nval

        else:
            return nval.encode(encoding)

    # lists, tuples, sets
    elif type(value) in (list, tuple, set):
        nval = []
        for sval in value:
            nval.append(encode_after_json(sval))
        if isinstance(value, tuple):
            return tuple(nval)
        elif isinstance(value, set):
            return set(nval)
        else:
            return nval

    # OOBTree
    elif isinstance(value, dict) and \
            value.get('utf8:publisher-wrapper', False) \
            and value.get('utf8:type', None) == 'utf8:OOBTree':
        return OOBTree(value.get('utf8:value'))

    # PortletAssignmentSettings
    elif isinstance(value, dict) and \
            value.get('utf8:publisher-wrapper', False) \
            and value.get('utf8:type', None) == \
            'utf8:PortletAssignmentSettings':
        settings = PortletAssignmentSettings()
        for key, val in value.get('utf8:value').items():
            settings[key] = val
        return settings

    # python datetime
    elif isinstance(value, dict) and \
            value.get('publisher-wrapper', False) \
            and value.get('type', None) == 'datetime':
        return datetime.strptime(value.get('value'), ISOFORMAT)

    # zope datetime
    elif isinstance(value, dict) and \
            value.get('publisher-wrapper', False) \
            and value.get('type', None) == 'DateTime':
        return DateTime(value.get('value'))

    # dicts
    elif isinstance(value, dict):
        nval = {}
        for key, sval in value.items():
            key = encode_after_json(key)
            sval = encode_after_json(sval)
            nval[key] = sval
        return nval

    # other types
    else:
        return value
        


src/f/t/ftw.publisher.receiver-2.0.2/ftw/publisher/receiver/decoder.py   ftw.publisher.receiver(Download)
from StringIO import StringIO
from ftw.publisher.core import states
from ftw.publisher.core.utils import encode_after_json
from ftw.publisher.receiver import getLogger
import base64
        except Exception, e:
            raise states.DecodeError(str(e))
        data = encode_after_json(data)
        return data
 

src/f/t/ftw.publisher.sender-2.2.0/ftw/publisher/sender/tests/test_extractor.py   ftw.publisher.sender(Download)
from Products.PloneTestCase.ptc import PloneTestCase
from ftw.publisher.core.interfaces import IDataCollector
from ftw.publisher.core.utils import encode_after_json
from ftw.publisher.sender.extractor import Extractor
from ftw.publisher.sender.tests.layer import Layer
        # decode from json
        data = json.loads(jsondata)
        data = encode_after_json(data)
        self.assertTrue('description' in data['field_data_adapter'])
        self.assertTrue('excludeFromNav' in data['field_data_adapter'])
        # decode from json
        data = json.loads(jsondata)
        data = encode_after_json(data)
        self.assertTrue('description' not in data['field_data_adapter'])
        self.assertTrue('excludeFromNav' not in data['field_data_adapter'])

src/f/t/ftw.publisher.core-2.4.0/ftw/publisher/core/tests/test_utils.py   ftw.publisher.core(Download)
 
        transport_data = json.dumps(utils.decode_for_json(data))
        result_data = utils.encode_after_json(json.loads(transport_data))
        return result_data
 

src/f/t/ftw.publisher.core-2.4.0/ftw/publisher/core/tests/test_portlet_adapter.py   ftw.publisher.core(Download)
        # set the data on the folder2
        data = json.loads(jsondata)
        data = utils.encode_after_json(data)
        adapter2 = getAdapter(self.layer['folder2'], IDataCollector,
                              name="portlet_data_adapter")

src/f/t/ftw.publisher.core-2.4.0/ftw/publisher/core/tests/test_dexterity.py   ftw.publisher.core(Download)
        if json:
            data = loads(data)
            data = utils.encode_after_json(data)
 
        return collector.setData(data, metadata or {})