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)
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)
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)
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'
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)
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)