Ejemplo n.º 1
0
#!/usr/bin/env python
import warnings as _warnings
_warnings.resetwarnings()
_warnings.filterwarnings('error')

from tdi.tools import javascript
try:
    javascript.SimpleJSON([]).as_json()
except ImportError:
    class json(object):
        def __init__(self, val):
            pass
        def as_json(self, **kw):
            return u'[1,2,3,4]'
    javascript.SimpleJSON = json

# BEGIN INCLUDE
from tdi.tools import javascript

script = u'''
var a = __var__;
var b = '__str__';
'''.strip()
print javascript.replace(script, dict(
    var=javascript.SimpleJSON([1, 2, 3, 4]),
    str=u'my "string"'
))
Ejemplo n.º 2
0
_warnings.filterwarnings('error')

import re as _re

from tdi.tools import javascript

json = javascript.LiteralJSON(u'{"name": "Andr\xe9"}')
script = u"""
var count = __a__;
var name = '__b__';
var param = __c__;
var notreplaced = '__d__';
var with_ = '__foo_bar__';
""".strip()
x = javascript.replace(script, dict(
    a=10, b=u'__c__', c=json, foo_bar=u'Andr\xe9',
))
print type(x).__name__
print x.encode('utf-8')

json = javascript.LiteralJSON(u'{"name": "Andr\xe9"}')
script = u"""
var count = __a__;
var name = '__b__';
var param = __c__;
var notreplaced = '__d__';
var with_ = '__foo_bar__';
""".strip()
x = javascript.replace(script, dict(
    a=10, b=u'__c__', c=json, foo_bar=u'Andr\xe9',
), encoding='utf-8')