escaping

How to read from a JSON file with unescaped backslashes?

◇◆丶佛笑我妖孽 提交于 2019-12-12 16:17:43
问题 I have a JSON file that contains a connection string: abc.json { "host":"1.2.3.4", "user":"abc", "passwd":"s&]\yz$&u42/", "dbname":"sample", "port":2341 } Here's my Python script which tries to read the data: import psycopg2 as pg dbconn = "C:\abc.json" with open(dbconn) as conn_file: conn = json.load(conn_file) It gives me this error: json.decoder.JSONDecodeError: Invalid \escape: line 4 column 16 (char 53) How can I fix this error? 回答1: Your file is not valid: there's no such escape

Jinja2 filter to convert custom markup to html

拜拜、爱过 提交于 2019-12-12 16:01:36
问题 Having the autoescape property on (I want to keep it that way), I want user to be able to enter some custom markup, to have the opportunity to format text. For example, [s][/s] will be translated into <strong></strong> . I believe the right way to do this is to write the custom Jinja2 filter. But the following doesn't work: @app.template_filter() @evalcontextfilter def mark2html(eval_ctx, value): result = escape(value).replace('[s]','<strong>') if eval_ctx.autoescape: result = Markup(result)

Puppet - Escaping YAML variables for Hiera

对着背影说爱祢 提交于 2019-12-12 13:59:06
问题 I have a pretty simple requirement, but I've tried every escape sequence I can think of, but can't get the output needed. I need to litterally output into a file: %{VAR} Here's my YAML file: myclass::outputstuff: - Heres a litteral var %{VAR} - Heres something else %{SOMETHING} And my template.erb: <%= @outputstuff.each do | ostuff | -%> <%= ostuff -%> <% end -%> But it like this, it outputs: Heres a litteral var Heres something else If I add a percent sign like %%{VAR} , as advised by other

Is there a better way to double escape (or escape twice) user input in BASH than calling printf twice?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 13:53:20
问题 This script will read an old and a new value from the user and then use sed to find and replace them in a file. For example if I entered T T z and B B z it would look for T\ T\ z in the file and replace with B\ B\ z. It works but I've been trying to make this more concise. I don't have any need for the intermediate variables $ESC_OLD_PW and $ESC_NEW_PW. Is there a more sensible way to do this? #!/bin/bash read -sp "Old:" OLD_PW && echo read -sp "New:" NEW_PW && echo # Add escape characters to

How can I decode a URL escape string in C#? [duplicate]

早过忘川 提交于 2019-12-12 11:26:31
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: how to decode url param with c# I want to change all those %20 ect. to spaces ect. 回答1: HttpUtility.UrlDecode(String) and HttpUtility.UrlEncodeUnicode(String) 回答2: Use Server.UrlDecode(string); 来源: https://stackoverflow.com/questions/3792458/how-can-i-decode-a-url-escape-string-in-c

Why must backslashes in string literals be escaped in C++?

China☆狼群 提交于 2019-12-12 11:25:13
问题 I want to declare the same regex pattern for both languages. For TCL I do this set pattern "\d\s\S" but for C++ I have to do this for the same pattern boost::regex pattern("\\d\\s\\S"); otherwise C++ compiler will tell us the following: warning C4129: 'd' : unrecognized character escape sequence so why TCL don't try to find \d \s \S escape symbols and just ignores \ -s but C++ tries and sucks? P.S. PHP works as TCL as I remeber. 回答1: This is just how C++ and PHP differ; in PHP, the character

Unescaping strings in c# using string.Replace?

巧了我就是萌 提交于 2019-12-12 10:59:28
问题 I have a collection of strings within a checkListBox and I convert this collection into a List<string> . During this conversion I can only imagine the strings are escaped due to them being in the below format: <category title="FOO"> This then becomes "<category title=\"FOO\"> I need to unescape these strings for comparison, and I've tried something like s.Replace(@"\""", @""""); <-------- trying to replace all \" with " Is this even possible? And if so what's the correct way of removing

VT100 ANSI escape sequences: getting screen size, conditional ANSI

青春壹個敷衍的年華 提交于 2019-12-12 10:55:24
问题 When I resizing on terminal, it keeps full screen. I guess, there's someway that can find out what screen size the terminal is. How can I do that in VT100? With , when I list folder, it shows folder in blue color. (or let's say different color) But, if you save output into a text file ( ls > out.txt ), you don't see any ANSI code but plain text. However, if you try ( vi > out.txt ), you will see ANSI code. How does know that? Thank you 回答1: Programs (such as vi ) which automatically adjust to

Escaping a string with quotes in Laravel

青春壹個敷衍的年華 提交于 2019-12-12 10:44:36
问题 I would like to insert the content of an excel file into my database. I simply use a raw query to achieve this. The controller function public function uploadExcel() { $filename = Input::file('import_file')->getRealPath(); $file = fopen($filename, "r"); $count = 0; while (($emapData = fgetcsv($file, 10000, "\t")) !== FALSE) { $count++; if($count>1) { DB::statement("INSERT INTO `members` ( member_title, member_first_name, member_name_affix, member_last_name, member_private_address, member

substitute single backslash in R

烈酒焚心 提交于 2019-12-12 10:42:57
问题 I have read some questions and answers on this topic in stack overflow but still don't know how to solve this problem: My purpose is to transform the file directory strings in windows explorer to the form which is recognizable in R, e.g. C:\Users\Public needs to be transformed to C:/Users/Public, basically the single back slash should be substituted with the forward slash. However the R couldn't store the original string "C:\Users\Public" because the \U and \P are deemed to be escape