eval

clojure - eval code in different namespace

一个人想着一个人 提交于 2019-12-03 06:30:34
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. Solved! Execute function: (defn execute "evaluates s-forms" ([request] (execute request *ns*)) ([request

<%# Eval(“State”) %> or <%# DataBinder.Eval(Container.DataItem, “state”)%>

心不动则不痛 提交于 2019-12-03 06:22:53
问题 What is the difference between having <%# Eval("State") %> in your aspx page, versus having <%# DataBinder.Eval(Container.DataItem, "State") %> in your aspx page? 回答1: Eval("State") is a simplified form of the DataBinder.Eval(Container.DataItem, "State") syntax. It only works inside of data-bound template controls. For more info, see the MSDN documentation. 回答2: There is no difference. The "Eval" method is just a shortcut for the DataBinder.Eval(Container.DataItem, "blah") method. 回答3: There

python convert a string to arguments list

点点圈 提交于 2019-12-03 06:14:43
Can I convert a string to arguments list in python? def func(**args): for a in args: print a, args[a] func(a=2, b=3) # I want the following work like above code s='a=2, b=3' func(s) I know: list can, just use *list, but list can't have an element like: a=2 and eval can only evaluate expression which would be like: def func2(*args): for a in args: print a list1=[1,2,3] func2(*list1) func2(*eval('1,2,3')) You could massage the input string into a dictionary and then call your function with that, e.g. >>> x='a=2, b=3' >>> args = dict(e.split('=') for e in x.split(', ')) >>> f(**args) a 2 b 3 You

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

给你一囗甜甜゛ 提交于 2019-12-03 05:58:40
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 . 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 instead of Mustache.render and there are likely some performance reduction. I opened an issue to potentially

Use of variables like %{buildDir} in QtCreator kit settings in Qt5

百般思念 提交于 2019-12-03 05:51:02
问题 In this documentation (under section "Specifying a Custom Executable to Run") I noticed that there is mention of what looks like a variable %{buildDir} in the field "Working directory". I have struggled for a while now to find documentation for this feature. I would like to know first of all is there documentation for this somewhere? . Secondary questions: What other variables are available? In which fields can they be used? Can I access variables that I created in my project's .pro file? Are

Read a config file in BASH without using “source”

断了今生、忘了曾经 提交于 2019-12-03 05:06:44
问题 I'm attempting to read a config file that is formatted as follows: USER = username TARGET = arrows I realize that if I got rid of the spaces, I could simply source the config file, but for security reasons I'm trying to avoid that. I know there is a way to read the config file line by line. I think the process is something like: Read lines into an array Filter out all of the lines that start with # search for the variable names in the array After that I'm lost. Any and all help would be

How can I detect I'm inside an eval() call?

China☆狼群 提交于 2019-12-03 05:00:55
问题 Does there exist a string s such that (new Function(s))(); and eval(s); behave differently? I'm trying to "detect" how a string is being evaluated. 回答1: Check for the arguments object. If it exists, you're in the function. If it doesn't it has been eval ed. Note that you'll have to put the check for arguments in a try...catch block like this: var s = 'try {document.writeln(arguments ? "Function" : "Eval") } catch(e) { document.writeln("Eval!") }'; (new Function(s))(); eval(s); Demo Solution

Why does gmail use eval?

守給你的承諾、 提交于 2019-12-03 03:58:58
问题 This question suggests that using eval is a bad practice and many other questions suggest that it is 'evil'. An answer to the question suggests that using eval() could be helpful in one of these cases: Evaluate code received from a remote server. (Say you want to make a site that can be remotely controlled by sending JavaScript code to it?) Evaluate user-written code. Without eval, you can't program, for example, an online editor/REPL. Creating functions of arbitrary length dynamically

Using ast and whitelists to make python's eval() safe?

匆匆过客 提交于 2019-12-03 03:46:16
OK. I know the experts have spoken and you should not ever use python's eval() on untrusted data, ever. I'm not smarter than the rest of the world, and shouldn't even try this. But! I'm going to, anyhow. My basic problem is that I'm looking to write a little calculator evaluator program that'll take untrusted input, using a subset of python's syntax. I know: use ply or pyparsing and write a parser and there we go. Screwing around with passing globals and locals to eval() will not do the trick. All the approaches I've seen (and been leery about) try to enumerate evil. Here, I'm trying to

Why I can call 'print' from 'eval'

▼魔方 西西 提交于 2019-12-03 03:18:17
For code: #!/usr/bin/python src = """ print '!!!' import os """ obj = compile(src, '', 'exec') eval(obj, {'__builtins__': False}) I get output: !!! Traceback (most recent call last): File "./test.py", line 9, in <module> eval(obj, {'__builtins__': False}) File "", line 3, in <module> ImportError: __import__ not found Both 'print' and 'import' are language construct. Why does 'eval' restrict using of 'import' but doesn't restrict 'print'? P.S. I'm using python 2.6 UPDATE: Question is not "Why does import not work?" but "Why does print work?" Are there some architecture restrictions or something