예제 #1
0
파일: base.py 프로젝트: pombredanne/syn-1
    def estr(self, **kwargs):
        '''Should return a string that can eval into an equivalent object'''
        if hasmethod(self.obj, '_estr'):
            return escape_for_eval(self.obj._estr(**kwargs))

        objstr = escape_for_eval(quote_string(str(self.obj)))
        return '{}({})'.format(get_typename(self.obj), objstr)
예제 #2
0
 def estr(self, **kwargs):
     parts = [
         "{}: {}".format(estr(key, **kwargs), estr(value, **kwargs))
         for key, value in self.obj.items()
     ]
     ret = '{' + ', '.join(parts) + '}'
     ret = '{}({})'.format(get_typename(self.obj), ret)
     return escape_for_eval(ret)
예제 #3
0
 def estr(self, **kwargs):
     parts = [estr(item, **kwargs) for item in self.obj]
     ret = '[' + ', '.join(parts) + ']'
     ret = '{}({})'.format(get_typename(self.obj), ret)
     return escape_for_eval(ret)
예제 #4
0
파일: set.py 프로젝트: mbodenhamer/syn
 def estr(self, **kwargs):
     parts = [estr(item, **kwargs) for item in self.obj]
     ret = '[' + ', '.join(parts) + ']'
     ret = '{}({})'.format(get_typename(self.obj), ret)
     return escape_for_eval(ret)
예제 #5
0
def test_escape_for_eval():
    from syn.base_utils import escape_for_eval

    assert escape_for_eval('abc') == 'abc'
    assert escape_for_eval('\n') == '\\n'
    assert escape_for_eval('b\\a') == 'b\\\\a'
예제 #6
0
파일: test_str.py 프로젝트: mbodenhamer/syn
def test_escape_for_eval():
    from syn.base_utils import escape_for_eval

    assert escape_for_eval('abc') == 'abc'
    assert escape_for_eval('\n') == '\\n'
    assert escape_for_eval('b\\a') == 'b\\\\a'
예제 #7
0
파일: mapping.py 프로젝트: mbodenhamer/syn
 def estr(self, **kwargs):
     parts = ["{}: {}".format(estr(key, **kwargs), estr(value, **kwargs))
              for key, value in self.obj.items()]
     ret = '{' + ', '.join(parts) + '}'
     ret = '{}({})'.format(get_typename(self.obj), ret)
     return escape_for_eval(ret)
예제 #8
0
 def estr(self, **kwargs):
     encoding = kwargs.get('encoding', 'utf-8')
     objstr = escape_for_eval(quote_string(self.obj.encode(encoding)))
     objstr += '.decode("{}")'.format(encoding)
     return '{}({})'.format(get_typename(self.obj), objstr)