In the webapp2 URI routing there are some examples using webapp2.Route(r'/', handler='...'), and some aren't using r'/' -- so my question is, what is the R for, and should I be using it?
Also, if you use webapp2_extras.APIs you need to pass the config to the WSGIApplication(), is it possible to define the config lists elsewhere?
As in, is it possible to do config['webapp2_extras.API'] = ['option':'value'] in one file, then include that file inside your "router" and use the variable/list
Thanks in advance!!
Copied Here from Comment:
It defines a raw string. Please read docs docs.python.org/2/reference/lexical_analysis.html#literals paying special attention to raw strings. You may use a raw string to more easily define a regular expression as a literal string.
Related
I have a stored XCom expense_list that I want to convert into a Python variable
expense_variable (rather than passing it into a templated field). I tried to set the variable in my DAG, but the following code did not work.
expense_variable = "{{task_instance.xcom_pull(task_ids='expense_list')}}"
How can I convert the stored XCom expense_list into a Python variable expense_variable in Airflow? Is there a function or operator for this?
Recall that JINJA templating is a helpful feature provided by Airflow guys to ease our lives; and it doesn't mean we have to (or that we should use) JINJA templates everywhere, notwithstanding that we really can't.
Once again citing gotchas from Gtoonstra (that you seemed to have missed in previous answer)
Not all parameters in operators are templated, so you cannot use Jinja
templates everywhere. The Jinja templates only work for those fields
in operators where it’s listed in the template_fields list inside the
source file, like:
template_fields = ('audit_key', 'cycle_dtm')
In this particular case, there is no reason to pull XCOMs via JINJA template. You can simply refer to the docs that show how you can pull them via task_instance object obtained from context dict
expense_variable = context['task_instance'].xcom_pull(task_ids='expense_list')
I'm creating a route using the Java DSL in Camel.
I'd like to perform a text substitution without creating a new processor or bean.
I have this:
.setHeader(MY_THING,
constant(my_template.replace("{id1}", simple("${header.subs_val}").getText())))
If I don't add 'constant' I get type mismatch errors. If I don't put getText() on the simple() part, I get text mismatch answers. When I run my route, it replaces {id} with the literal ${header.subs_val} instead of fetching my value from the header. Yet if I take the quotes off, I get compile errors; Java doesn't know the ${...} syntax of course.
Deployment takes a few minutes, so experiments are expensive.
So, how can I just do a simple substitution. Nothing I am finding on the web actually seems to work.
EDIT - what is the template? Specifically, a string (it's a URL)
http://this/that/{id1}/another/thing
I've inherited some code, so I am unable to simply to(...) the URL and apply the special .tof() (??) formatting.
Interesting case!
If you place my_template in a header you could use a nested simple expression(Camel 2.9 onwards) like in the example below. I am also setting a value to subs_val for the example, but I suppose your header has already a value in the route.
.setHeader("my_template", constant("http://this/that/{id1}/another/thing"))
.setHeader("subs_val",constant("22"))
.setHeader("MY_THING",simple("${in.header.my_template.replaceAll(\"\\{id1.?\",${in.header.subs_val.toString()})}"))
After this step header MY_THING has the value http://this/that/22/another/thing.
1)In this example I could skip to_String() but I do not know what's the type of your header "subs_val" .
2) I tried first with replaceAll(\"\{id1\"}\") but it didn't work with } Probably this is a bug...Will look at it again. That's why in my regex I used .?
3) When you debug your application inside a processor, where the exchange is available you can use SimpleBuilder to evaluate a simple expression easily in your IDE, without having to restart your app
SimpleBuilder.simple("${in.header.url.replaceAll(\"\\{id1.?\",${in.header.subs_val.toString()})}").evaluate(exchange, String.class);
Hope it helped :)
sorry i was new here so this problem maybe simple.
anyone knows how to check variable content?
like xx($a);
then page shows all relate information about $a. Is CakePHP allowed to do that?
i setup a kit on my cakephp
You might be looking for either var_dump() or print_r()
You can use PHP built-in functions like
var_dump() - displays structured information about variable
print_r() - the same, but preformatted with some differences
get_defined_vars() - returns array with all defined variables
Or use true CakePHP-way
Debugger::dump() - It will print out all properties and methods (if any) of the supplied variable
For more convenience you may use CakePHP Debug Kit plugin, which provides nice toolbar and some useful tools for your purpose.
I'm using Jsoup to connect to a URL with a space in it but keep getting a URI syntax error. Any ideas on how deal with this?
Thanks!!
You should percent-encode URLs. Space is represented as %20.
Additionally, some characters/symbols are used as delimiters in URLs (&, ?, =, etc.) and thus they cannot be put in the URL unless they are meant as delimiters. For example, if you wanted to pass the string "1 &1" I would have to encode it as "1%20%261" or else it will not parse properly.
See http://en.wikipedia.org/wiki/Percent-encoding for more details.
URLs cannot have spaces, by RFC1738 (section 2.2): http://www.ietf.org/rfc/rfc1738.txt
For some additional background on how to handle this, see: http://www.w3schools.com/tags/ref_urlencode.asp
In particular, one mechanism for encoding URLs can be found at:
HTTP URL Address Encoding in Java
I have a binary file which has an ASCII metadata header. The elements are of the form "tag = value". Do you know of any Java libraries that will simplify extraction of this metadata.
Yes, you can use Properties. Its load and store methods use a format very similar to the one you described.