eval

clojure - eval code in different namespace

≯℡__Kan透↙ 提交于 2019-12-03 17:50:14
问题 I'm coding something like REPL Server. Request from users evaluates in such function: (defn execute [request] (str (try (eval (read-string request)) (catch Exception e (.getLocalizedMessage e))))) Each client in separate thread. But they have the same namespace. How can I run code in dynamic created namespace ? So when new client connected, I want to create new namespace and to run client handling loop code there. Or maybe it's possible to run (eval ..) in other namespace ? Thanks. upd.

JavaScript template library that doesn't use eval/new Function

断了今生、忘了曾经 提交于 2019-12-03 17:07:03
问题 Google Chrome extensions using manifest_version: 2 are restricted from using eval or new Function . All of the JavaScript templating libraries I checked (mustachejs, underscorejs, jQuery template, hoganjs, etc) use new Function . Are there any that are fairly mature and supported that don't use either? Info about the security restrictions. 回答1: It turns out that mustachejs added new Function recently and using tag 0.4.2 doesn't have it. It the API is slightly different with Mustache.to_html

How do you know to use Container.DataItem when data binding in ASP.NET? Is there a reference?

让人想犯罪 __ 提交于 2019-12-03 16:29:25
Is there a reference for data binding? I've seen a bunch of different ways to data bind things, but I've never found a reference. Is there one? I know there are Bind and Eval, but when does Container.DataItem come into play? Are there other "hidden" objects and methods available? Or is Container.DataItem the object that is being used here? Jeff Sternal when does Container.DataItem come into play? From the first link below (paraphrasing slightly): "Container.DataItem is a runtime alias for the DataItem for this specific item in a bound list." Are there other "hidden" objects and methods

Node.JS vm.runInNewContext() vs require() and eval()

耗尽温柔 提交于 2019-12-03 13:42:28
Is vm.runInNewContext considered black magic like eval ? Is there a significant performance difference between require and reading a file and using vm to run it or is the the same under the hood (if you implemented caching etc and just wanted to add some variables to the context) Jan Jongboom runInNewContext is not meant to be used as a replacement of require or eval , but instead as a way to create a sandbox environment where you can safely run other scripts. Disadvantages are that it's slow (creation takes ~10 ms.) and takes up a couple megabytes. So no, don't use it as a require replacement

including js files with html and node.js

寵の児 提交于 2019-12-03 13:36:45
I am performing messaging via websockets between a HTML5 client and server running on node.js. Naturally I chose JSON as the message format and as such created common javascript code, defining the various message content types and transformation operations. The javascript code is shared between both projects. I created my web client as one git project and my server as another git project. Partly because I am using phonegap to build a webkit based client for various touch based environments. It's also a nice separation of the various logic. To share the common code I created a separate project

eval

半城伤御伤魂 提交于 2019-12-03 13:29:40
eval() 函数用来执行一个字符串表达式,并返回表达式的值。 即实现list,tuple,dict与str之间的转化。 语法 以下是 eval() 方法的语法: eval(expression[, globals[, locals]]) eval(expression, globals=None, locals=None) 参数 expression -- 表达式。 globals -- 变量作用域,全局命名空间,如果被提供,则必须是一个字典对象。 locals -- 变量作用域,局部命名空间,如果被提供,可以是任何映射对象。 globals和locals参数是可选的,如果提供了globals参数,那么它必须是dictionary类型;如果提供了locals参数,那么它可以是任意的map对象。 python的全局名字空间存储在一个叫globals()的dict对象中;局部名字空间存储在一个叫locals()的dict对象中。我们可以用print (locals())来查看该函数体内的所有变量名和变量值。 返回值 返回表达式计算结果。 实例 #返回表达式的值 >>> x = 7 >>> eval ( ' 3 * x ' ) 21 >>> eval ( ' pow(2,2) ' ) 4 >>> eval ( ' 2 + 2 ' ) 4 >>> n = 81 >>> eval ( "

How do you do a python 'eval' only within an object context?

自作多情 提交于 2019-12-03 13:10:10
Is it possible to do something like c = MyObj() c.eval("func1(42)+func2(24)") in Python..i.e. have func1() and func2() be evaluated within the scope of the object 'c' (if they were member functions within that class definition)? I can't do a simple parsing, since for my application the eval strings can become arbitrarily complicated. I guess doing some magic with the ast module might do the trick, but due to the dirth of literature on ast, I'm not sure where to look: import ast class MyTransformer(ast.NodeTransformer): def visit_Name(self, node): # do a generic_visit so that child nodes are

Is there a way to secure strings for Python's eval?

泪湿孤枕 提交于 2019-12-03 12:08:50
There are many questions on SO about using Python's eval on insecure strings (eg.: Security of Python's eval() on untrusted strings? , Python: make eval safe ). The unanimous answer is that this is a bad idea. However, I found little information on which strings can be considered safe (if any). Now I'm wondering if there is a definition of "safe strings" available (eg.: a string that only contains lower case ascii chars or any of the signs +-*/()). The exploits I found generally relied on either of _.,:[]'" or the like. Can such an approach be secure (for use in a graph painting web

Is JSON.parse() really safer than eval() when web page and ajax call come from same server?

我只是一个虾纸丫 提交于 2019-12-03 11:56:15
问题 I get that JSON.parse() prevents an attacker from injecting javascript into the response since a JSON parser is just a text parser, not a script parser so please don't close this is a dup of all the other questions that talk about that. This is a different question. If an attacker can hijaack your Ajax call and put javascript into the Ajax call aren't they just as likely to be able to hijack your actual webpage and put arbitrary javascript into your page from which they could accomplish the

数独

核能气质少年 提交于 2019-12-03 11:38:29
  这两天一直在研究数独,但是并没有研究透彻,由于时间的原因,暂时研究终止。期间一共写出了一个大方法,一个小方法。小方法还待优化。 注意一点:输入数据后,先执行一次"up"命令,更新一下每个棋盘格的可选数字,才可执行"m1"或"m2"的操作。 代码就如下所示: class shuDu: # 一道待解决的数独题 cBoard =[ [6,0,0,0,0,0,5,8,0], [5,2,0,9,0,0,6,0,0], [0,0,0,0,5,0,0,0,3], [2,0,0,8,3,0,0,0,0], [0,0,6,1,0,9,3,0,0], [0,0,0,0,7,6,0,0,9], [8,0,0,0,4,0,0,0,0], [0,0,2,0,0,5,0,1,7], [0,6,1,0,0,0,0,0,4] ] check = {} #可用数字字典 def refresh(self): print(self.cBoard) print("Refresh over") def show(self): print("==========================") for i in range(0,9): for j in range(0,9): num = ['-','-','-','-','-','-','-','-','-'] if((i,j) in self.check):