escaping

Python 3: How do I get a string literal representation of a byte string?

こ雲淡風輕ζ 提交于 2019-12-09 16:41:03
问题 In Python 3, how do I interpolate a byte string into a regular string and get the same behavior as Python 2 (i.e.: get just the escape codes without the b prefix or double backslashes)? e.g.: Python 2.7: >>> x = u'\u041c\u0438\u0440'.encode('utf-8') >>> str(x) '\xd0\x9c\xd0\xb8\xd1\x80' >>> 'x = %s' % x 'x = \xd0\x9c\xd0\xb8\xd1\x80' Python 3.3: >>> x = u'\u041c\u0438\u0440'.encode('utf-8') >>> str(x) "b'\\xd0\\x9c\\xd0\\xb8\\xd1\\x80'" >>> 'x = %s' % x "x = b'\\xd0\\x9c\\xd0\\xb8\\xd1\\x80'"

How to do MySQL IN clauses using Zend DB?

試著忘記壹切 提交于 2019-12-09 16:28:33
问题 I'm trying to fetch rows that are in an array of integers that I have using Zend Framework 1.11. $this->dbSelect ->from($table_prefix . 'product_link') ->joinLeft($table_prefix . 'product_link_name', $table_prefix . 'product_link.product_link_name_ref_id = ' . $table_prefix . 'product_link_name.product_link_name_id') ->where('product_ref_id IN (?)', implode(', ', $product_ids)); When I use the __toString() method of $this->dbSelect , I get SELECT `phc_distrib_product_link`.*, `phc_distrib

string escape into XML-Attribute

杀马特。学长 韩版系。学妹 提交于 2019-12-09 15:39:41
问题 I had a look at string escape into XML and found it very useful. I would like to do a similar thing: Escape a string to be used in an XML-Attribute. The string may contain \r\n. The XmlWriter class produces something like \r\n -> The solution I'm currently using includes the XmlWriter and a StringBuilder and is rather ugly. Any hints? Edit1: Sorry to disappoint LarsH, buy my first approach was public static string XmlEscapeAttribute(string unescaped) { XmlDocument doc = new XmlDocument();

Why do I need two slashes in Java Regex to find a “+” symbol?

时光总嘲笑我的痴心妄想 提交于 2019-12-09 15:34:38
问题 Just something I don't understand the full meaning behind. I understand that I need to escape any special meaning characters if I want to find them using regex. And I also read somewhere that you need to escape the backslash in Java if it's inside a String literal. My question though is if I "escape" the backslash, doesn't it lose its meaning? So then it wouldn't be able to escape the following plus symbol? Throws an error (but shouldn't it work since that's how you escape those special

Is there a way to package bash shell scripts with AppleScriptObjC app on MacOSX with Xcode?

梦想与她 提交于 2019-12-09 14:03:35
问题 I am trying to automate three or four bash shell scripts using AppleScriptObjC as a wrapper. This will give me a friendly gui front end to select data files etc., and the convenient text file manipulating and processing of several bash scripts. Everything works (I can press my buttons and run the shell scripts) except I can't figure out how to make things semi-portable. I would like to have a single app or package that I could distribute to others, with the needed script files somehow

How to properly escape strings when manually building SQL queries in SQLAlchemy?

怎甘沉沦 提交于 2019-12-09 11:13:50
问题 I am using SQLAlchemy to connect to different databases in Python, but not with the ORM support as this cannot be implemented due to several reasons. Mainly I do build a complex SQL query using things like sql += "AND fieldname = '%s'" % myvar In my case is not a problem of SQL injection as the data is always from a trusted source but even if the source is trusted it could contain characters that could break the query like ' , % or _ . Mainly, I need to escape them, and I wonder if there is

escaping inside html tag attribute value

拈花ヽ惹草 提交于 2019-12-09 08:27:37
问题 I am having trouble understanding how escaping works inside html tag attribute values that are javascript. I was lead to believe that you should always escape & ' " < > . So for javascript as an attribute value I tried: <a href="javascript:alert(&apos;Hello&apos;);"></a> It doesn't work. However: <a href="javascript:alert('Hello');"></a> and <a href="javascript:alert('Hello');"></a> does work in all browsers! Now I am totally confused. If all my attribute values are enclosed in double quotes,

How to escape parenthesis in grep

白昼怎懂夜的黑 提交于 2019-12-09 04:59:19
问题 I want to grep for a function call 'init()' in all JavaScript files in a directory. How do I do this using grep? Particularly, how do I escape parenthesis, () ? 回答1: It depends. If you use regular grep, you don't escape: echo '(foo)'|grep '(fo*)' You actually have to escape if you want to use the parentheses as grouping. If you use extended regular expressions, you do escape: echo '(foo)'|grep -E '\(fo*\)' 回答2: If you want to search for exactly the string "init()" then use fgrep "init()" or

Is Oracle's EXTRACT function breaking the NOENTITYESCAPING in the XMLELEMENT?

女生的网名这么多〃 提交于 2019-12-09 03:16:27
问题 Oracle 11g. I figured out that if I add NOENTITYESCAPING to the XMLELEMENT function, it nicely turns off entity escaping. However, when I then pass the result to EXTRACT the escaping seems to come back again. select xmlelement(NOENTITYESCAPING e,id,'->') from (select level as id from dual connect by level < 6) XMLELEMENT(NOENTITYESCAPINGE,ID,'->') --------------------------------------- <E>1-></E> <E>2-></E> <E>3-></E> <E>4-></E> <E>5-></E> Now, adding EXTRACT : select xmlelement

How to escape quotes when inserting into database with PHP

三世轮回 提交于 2019-12-09 03:01:24
问题 I'm quite new to PHP so sorry if sounds such an easy problem... :) I'm having an error message when inserting content which contains quotes into my db. here's what I tried trying to escape the quotes but didn't work: $con = mysql_connect("localhost","xxxx","xxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("test", $con); $nowdate = date('d-m-Y') $title = sprintf($_POST[title], mysql_real_escape_string($_POST[title])); $body = sprintf($_POST[body], mysql_real