[issue43910] cgi.parse_header does not handle escaping correctly

2021-04-22 Thread Mark Gordon


Change by Mark Gordon :


--
keywords: +patch
pull_requests: +24236
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/25519

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43910] cgi.parse_header does not handle escaping correctly

2021-04-22 Thread Mark Gordon


New submission from Mark Gordon :

cgi.parse_header incorrectly handles unescaping of quoted-strings

Note that you can find the related RFCs to how HTTP encodes the Content-Type 
header at https://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html and further 
discussion on how quoted-string is defined at 
https://greenbytes.de/tech/webdav/draft-ietf-httpbis-p1-messaging-16.html#rfc.section.3.2.1.p.3.

The way parse_header is written it has no context to be able to tell if a 
backslash is escaping a double quote or if the backslash is actually the 
escaped character and the double quote is free-standing, unescaped. For this 
reason it fails to parse values that have a backslash literal at the end. e.g. 
the following Content-Type will fail to be parsed

a/b; foo="moo\\"; bar=baz

Example run on current cpython master demonstrating the bug:

Python 3.10.0a7+ (heads/master:660592f67c, Apr 21 2021, 22:51:04) [GCC 9.3.0] 
on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cgi
>>> query = 'a; foo="moo"; bar=cow' 
>>> print(query)
a; foo="moo\\"; bar=cow
>>> cgi.parse_header(query)
('a', {'foo': '"moo"; bar=cow'})

--
components: Library (Lib)
messages: 391580
nosy: msg555
priority: normal
severity: normal
status: open
title: cgi.parse_header does not handle escaping correctly
type: behavior
versions: Python 3.10

___
Python tracker 
<https://bugs.python.org/issue43910>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Escaping confusion with Python 3 + MySQL

2020-04-21 Thread moorthy . rs
On Sunday, March 26, 2017 at 7:55:09 PM UTC+5:30, Νίκος Βέργος wrote:
> Τη Κυριακή, 26 Μαρτίου 2017 - 5:19:27 μ.μ. UTC+3, ο χρήστης Ian έγραψε:
> 
> > You need to change the placeholders back. The poster who told you to
> > replace them was misinformed.
> 
> okey altered them back to
> 
> cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, 
> browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%%s%" 
> ''', 
>   
>   
>   
> (pID, domain, ref, location, 
> useros, browser, lastvisit, domain) )
> 
> but now the problem is how to exact;y type the Where HOST like "%%%"
> 
> I MEAN HOW TO DIFFERENTIATE '%S' FROM LITERAL '%' character.

Hi ,

I have fixed this issue on other way 

you can declare variables like below and pass same to the query with strings.

per1="%%%"

you can assign this string (WHERE host LIKE "%%s%" ,per1) to avoid this issue.

same way i resolved my query execution on cursor execute.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue38294] Documentation on 3.6->3.7 re.escape no longer escaping "/" or ":" should be obvious

2019-10-15 Thread Ned Deily

Ned Deily  added the comment:


New changeset ae41f629e187e1f0cf4d62f5a7b181c64da26466 by Ned Deily (Ricardo 
Bánffy) in branch '3.7':
[3.7] bpo-38294: Add list of no-longer-escaped chars to re.escape 
documentation. (GH-16442) (GH-16647)
https://github.com/python/cpython/commit/ae41f629e187e1f0cf4d62f5a7b181c64da26466


--
nosy: +ned.deily

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38294] Documentation on 3.6->3.7 re.escape no longer escaping "/" or ":" should be obvious

2019-10-09 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Thank you for your contribution Ricardo!

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38294] Documentation on 3.6->3.7 re.escape no longer escaping "/" or ":" should be obvious

2019-10-08 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:


New changeset 43f5c0c4d0a608c04c3978adb45117f3943203b7 by Serhiy Storchaka 
(Ricardo Bánffy) in branch '3.7':
[3.7] bpo-38294: Add list of no-longer-escaped chars to re.escape 
documentation. (GH-16442) (GH-16647)
https://github.com/python/cpython/commit/43f5c0c4d0a608c04c3978adb45117f3943203b7


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38294] Documentation on 3.6->3.7 re.escape no longer escaping "/" or ":" should be obvious

2019-10-08 Thread Ricardo Bánffy

Change by Ricardo Bánffy :


--
pull_requests: +16230
pull_request: https://github.com/python/cpython/pull/16647

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38294] Documentation on 3.6->3.7 re.escape no longer escaping "/" or ":" should be obvious

2019-10-07 Thread miss-islington


miss-islington  added the comment:


New changeset b731fc521cf78e53268e35777d836ca80e7ab305 by Miss Islington (bot) 
in branch '3.8':
bpo-38294: Add list of no-longer-escaped chars to re.escape documentation. 
(GH-16442)
https://github.com/python/cpython/commit/b731fc521cf78e53268e35777d836ca80e7ab305


--
nosy: +miss-islington

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38294] Documentation on 3.6->3.7 re.escape no longer escaping "/" or ":" should be obvious

2019-10-07 Thread miss-islington


Change by miss-islington :


--
pull_requests: +16212
pull_request: https://github.com/python/cpython/pull/16626

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38294] Documentation on 3.6->3.7 re.escape no longer escaping "/" or ":" should be obvious

2019-10-07 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:


New changeset 15ae75d660befe643ed42eb2707a557cea97256c by Serhiy Storchaka 
(Ricardo Bánffy) in branch 'master':
bpo-38294: Add list of no-longer-escaped chars to re.escape documentation. 
(GH-16442)
https://github.com/python/cpython/commit/15ae75d660befe643ed42eb2707a557cea97256c


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38294] Documentation on 3.6->3.7 re.escape no longer escaping "/" or ":" should be obvious

2019-10-01 Thread Ricardo Bánffy

Change by Ricardo Bánffy :


--
title: re.escape no longer escapes "/" or ":" -> Documentation on 3.6->3.7 
re.escape no longer escaping "/" or ":" should be obvious

___
Python tracker 
<https://bugs.python.org/issue38294>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21018] [patch] added missing documentation about escaping characters for configparser

2019-09-10 Thread Julien Palard


Julien Palard  added the comment:


New changeset 5cf8155bbd2c65572295b26e96c221763b3322f0 by Julien Palard (Miss 
Islington (bot)) in branch '3.8':
bpo-21018: added missing documentation about escaping characters for 
configparser (GH-6137) (GH-15846)
https://github.com/python/cpython/commit/5cf8155bbd2c65572295b26e96c221763b3322f0


--

___
Python tracker 
<https://bugs.python.org/issue21018>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21018] [patch] added missing documentation about escaping characters for configparser

2019-09-10 Thread Julien Palard


Julien Palard  added the comment:


New changeset 122bbf7f8ac2cef4368e3601af593a027dc62ccf by Julien Palard (Miss 
Islington (bot)) in branch '3.7':
bpo-21018: added missing documentation about escaping characters for 
configparser (GH-6137) (GH-15845)
https://github.com/python/cpython/commit/122bbf7f8ac2cef4368e3601af593a027dc62ccf


--

___
Python tracker 
<https://bugs.python.org/issue21018>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21018] [patch] added missing documentation about escaping characters for configparser

2019-09-10 Thread Julien Palard


Julien Palard  added the comment:

Thanks!

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21018] [patch] added missing documentation about escaping characters for configparser

2019-09-10 Thread miss-islington


Change by miss-islington :


--
pull_requests: +15492
pull_request: https://github.com/python/cpython/pull/15846

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21018] [patch] added missing documentation about escaping characters for configparser

2019-09-10 Thread miss-islington


Change by miss-islington :


--
pull_requests: +15491
pull_request: https://github.com/python/cpython/pull/15845

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21018] [patch] added missing documentation about escaping characters for configparser

2019-09-10 Thread Julien Palard


Julien Palard  added the comment:


New changeset 9a94093189417a6b59d6c80cc5544630c8aa by Julien Palard (Arun 
Persaud) in branch 'master':
bpo-21018: added missing documentation about escaping characters for 
configparser (GH-6137)
https://github.com/python/cpython/commit/9a94093189417a6b59d6c80cc5544630c8aa


--
nosy: +mdk

___
Python tracker 
<https://bugs.python.org/issue21018>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36246] csv.writer lineterminator affects csv escaping

2019-03-15 Thread flow2k


flow2k  added the comment:

Okay, thanks for pointing to the doc. I did not expect the line termination to 
affect escaping, but I can see why these may be related. 

Per your comment, I've added quoting=csv.QUOTE_NONNUMERIC. Instead of Excel, I 
am using Gdocs, and this escaping enables Gsheets to ingest it.

Closing the issue...

--
stage:  -> resolved
status: pending -> closed

___
Python tracker 
<https://bugs.python.org/issue36246>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36246] csv.writer lineterminator affects csv escaping

2019-03-08 Thread Martin Panter

Martin Panter  added the comment:

This is the result that I see:

>>> output = StringIO()
>>> csv.writer(output, lineterminator='\n').writerow(["Whoa!\rNewlines!"])
16
>>> output.getvalue()
'Whoa!\rNewlines!\n'

For comparison, this is the result with CRLF terminators (the default):

>>> output = StringIO()
>>> csv.writer(output, lineterminator='\r\n').writerow(["Whoa!\rNewlines!"])
19
>>> output.getvalue()
'"Whoa!\rNewlines!"\r\n'

Is it a problem that the line terminator determines whether the CR is quoted or 
not? I believe the default policy is “excel”, which happens to use 
QUOTE_MINIMAL. This behaviour is documented: 
.

--
nosy: +martin.panter
resolution:  -> not a bug
status: open -> pending

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36246] csv.writer lineterminator affects csv escaping

2019-03-08 Thread flow2k


New submission from flow2k :

output = io.StringIO()
csvData = [1, 2, 'a', 'He said "what do you mean?"', "Whoa!\rNewlines!"]
writer = csv.writer(output,lineterminator='\n')
writer.writerow(csvData)
print(repr(output.getvalue())) #does not escape \r as expected

--
messages: 337537
nosy: flow2k
priority: normal
severity: normal
status: open
title: csv.writer lineterminator affects csv escaping
type: behavior
versions: Python 3.7

___
Python tracker 
<https://bugs.python.org/issue36246>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21018] [patch] added missing documentation about escaping characters for configparser

2019-02-15 Thread Cheryl Sabella


Change by Cheryl Sabella :


--
versions:  -Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35613] Escaping string containing invalid characters as per XML

2018-12-29 Thread Ned Deily


Ned Deily  added the comment:

This question has come up before.  See Issue13648 where it was pointed out that 
null characters "are forbidden both in raw form *and* in escaped form. So even 
if they get escaped, they *still* will lead to errors. So there is no point in 
escaping them."

--
nosy: +ned.deily
resolution:  -> duplicate
stage:  -> resolved
status: open -> closed
superseder:  -> xml.sax.saxutils.escape does not escapes \x00

___
Python tracker 
<https://bugs.python.org/issue35613>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35613] Escaping string containing invalid characters as per XML

2018-12-29 Thread Devika Sondhi


New submission from Devika Sondhi :

As per XML 1.0 and 1.1 specs, the null character is treated as invalid in an 
XML doc. (https://en.wikipedia.org/wiki/Valid_characters_in_XML)
Shouldn't invalid xml characters be omitted while escaping?
The current behavior(tested on Python 3.7) is as follows:

>>> from xml.sax.saxutils import escape
>>> escape("a\u\u0001\u0008\u000b\u000c\u000e\u001fb")
'a\x00\x01\x08\x0b\x0c\x0e\x1fb'

--
messages: 332716
nosy: Devika Sondhi
priority: normal
severity: normal
status: open
title: Escaping string containing invalid characters as per XML
versions: Python 3.7

___
Python tracker 
<https://bugs.python.org/issue35613>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34304] clarification on escaping \d in regular expressions

2018-08-01 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

If you want to replace %d with literal \d, you need to repeat the backslash 4 
times:

pattern = re.sub('%d', 'd+', pattern)

or use a raw string literal and repeat the backslash 2 times:

pattern = re.sub('%d', r'\\d+', pattern)

Since the backslash has a special meaning in the replacement pattern, it needs 
to be escaped with a backslash, i.e. duplicated. But since it has a special 
meaning in Python string literals, every of these backslashes needs to be 
escaped with a backslash in a non-raw string literal, i.e. repeated 4 times.

Python 3.6 is more lenient. It keeps a backslash if it is followed by a 
character which doesn't compound a known escape sequences in a replacement 
string. But it emits a deprecation warning, which you can see when run Python 
with corresponding -W option.

$ python3.6 -Wa -c 'import re; print(re.sub("%d", "\d+", "DBMS_NAME: string(%d) 
%s"))'
:1: DeprecationWarning: invalid escape sequence \d
/usr/lib/python3.6/re.py:191: DeprecationWarning: bad escape \d
  return _compile(pattern, flags).sub(repl, string, count)
DBMS_NAME: string(\d+) %s

$ python3.6 -Wa -c 'import re; print(re.sub("%d", "\\d+", "DBMS_NAME: 
string(%d) %s"))'
/usr/lib/python3.6/re.py:191: DeprecationWarning: bad escape \d
  return _compile(pattern, flags).sub(repl, string, count)
DBMS_NAME: string(\d+) %s

$ python3.6 -Wa -c 'import re; print(re.sub("%d", "\\\d+", "DBMS_NAME: 
string(%d) %s"))'
:1: DeprecationWarning: invalid escape sequence \d
DBMS_NAME: string(\d+) %s

$ python3.6 -Wa -c 'import re; print(re.sub("%d", "d+", "DBMS_NAME: 
string(%d) %s"))'
DBMS_NAME: string(\d+) %s

Here "invalid escape sequence \d" is generated by the Python parser, "bad 
escape \d" is generated by the RE engine.

--
nosy: +serhiy.storchaka
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34304] clarification on escaping \d in regular expressions

2018-08-01 Thread Karthikeyan Singaravelan

Karthikeyan Singaravelan  added the comment:

The reported behavior is reproducible in master as well as of ea68d83933 but 
not on 3.6.0. I couldn't bisect to the exact commit between 3.7.0 and 3.6.0 
where this change was introduced though. I can also see some deprecation 
warnings as below while running the script : 

➜  cpython git:(master) ./python.exe ../backups/bpo34034.py
../backups/bpo34034.py:4: DeprecationWarning: invalid escape sequence \[
  sym = ['\[','\]','\(','\)']
../backups/bpo34034.py:4: DeprecationWarning: invalid escape sequence \]
  sym = ['\[','\]','\(','\)']
../backups/bpo34034.py:4: DeprecationWarning: invalid escape sequence \(
  sym = ['\[','\]','\(','\)']
../backups/bpo34034.py:4: DeprecationWarning: invalid escape sequence \)
  sym = ['\[','\]','\(','\)']
../backups/bpo34034.py:15: DeprecationWarning: invalid escape sequence \(
  result=re.match("DBMS_NAME python4: string\(\d+\) .*?", "DBMS_NAME python4: 
string(8) \"DB2/NT64\" ")
DBMS_NAME: string(%d) %s
DBMS_NAME: string(%d) %s
DBMS_NAME: string\(%d) %s
DBMS_NAME: string\(%d\) %s
DBMS_NAME: string\(%d\) .*?
Traceback (most recent call last):
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/sre_parse.py", 
line 1045, in parse_template
this = chr(ESCAPES[this][1])
KeyError: '\\d'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "../backups/bpo34034.py", line 11, in 
pattern = re.sub('%d', '\\d+', pattern)
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/re.py", line 
192, in sub
return _compile(pattern, flags).sub(repl, string, count)
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/re.py", line 
309, in _subx
template = _compile_repl(template, pattern)
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/re.py", line 
300, in _compile_repl
return sre_parse.parse_template(repl, pattern)
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/sre_parse.py", 
line 1048, in parse_template
raise s.error('bad escape %s' % this, len(this))
re.error: bad escape \d at position 0


Thanks

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34304] clarification on escaping \d in regular expressions

2018-08-01 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +xtreak

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34304] clarification on escaping \d in regular expressions

2018-07-31 Thread Saba Kauser


New submission from Saba Kauser :

Hello,

I have a program that works well upto python 3.6 but fails with python 3.7.

import re

pattern="DBMS_NAME: string(%d) %s"
sym = ['\[','\]','\(','\)']
for chr in sym:
  pattern = re.sub(chr, '\\' + chr, pattern)
  print(pattern)
  
pattern=re.sub('%s','.*?',pattern)
print(pattern)
pattern = re.sub('%d', '\\d+', pattern) 
print(pattern)
result=re.match(pattern, "DBMS_NAME: string(8) \"DB2/NT64\" ")
print(result)
result=re.match("DBMS_NAME python4: string\(\d+\) .*?", "DBMS_NAME python4: 
string(8) \"DB2/NT64\" ")
print(result)

expected output:
DBMS_NAME: string(%d) %s
DBMS_NAME: string(%d) %s
DBMS_NAME: string\(%d) %s
DBMS_NAME: string\(%d\) %s
DBMS_NAME: string\(%d\) .*?
DBMS_NAME: string\(\d+\) .*?



However, the below statement execution fails with python 3.7:
pattern = re.sub('%d', '\\d+', pattern) 

DBMS_NAME: string(%d) %s
DBMS_NAME: string(%d) %s
DBMS_NAME: string\(%d) %s
DBMS_NAME: string\(%d\) %s
DBMS_NAME: string\(%d\) .*?
Traceback (most recent call last):
  File 
"c:\users\skauser\appdata\local\programs\python\python37\lib\sre_parse.py", 
line 1021, in parse_template
this = chr(ESCAPES[this][1])
KeyError: '\\d'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "pattern.txt", line 11, in 
pattern = re.sub('%d', '\\d+', pattern)
  File "c:\users\skauser\appdata\local\programs\python\python37\lib\re.py", 
line 192, in sub
return _compile(pattern, flags).sub(repl, string, count)
  File "c:\users\skauser\appdata\local\programs\python\python37\lib\re.py", 
line 309, in _subx
template = _compile_repl(template, pattern)
  File "c:\users\skauser\appdata\local\programs\python\python37\lib\re.py", 
line 300, in _compile_repl
return sre_parse.parse_template(repl, pattern)
  File 
"c:\users\skauser\appdata\local\programs\python\python37\lib\sre_parse.py", 
line 1024, in parse_template
raise s.error('bad escape %s' % this, len(this))
re.error: bad escape \d at position 0

if I change the statement to have 3 backslash like 
pattern = re.sub('%d', '\\\d+', pattern) 

I can correctly generate correct regular expression.

Can you please comment if this has changed in python 3.7 and we need to escape 
'd' in '\d' as well ?

Thank you!

--
components: Regular Expressions
messages: 322842
nosy: ezio.melotti, mrabarnett, sabakauser
priority: normal
severity: normal
status: open
title: clarification on escaping \d in regular expressions
type: behavior
versions: Python 3.7

___
Python tracker 
<https://bugs.python.org/issue34304>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21018] [patch] added missing documentation about escaping characters for configparser

2018-03-17 Thread Arun Persaud

Arun Persaud  added the comment:

created github PR #6137. Hope everything is in the correct format.

Arun

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21018] [patch] added missing documentation about escaping characters for configparser

2018-03-17 Thread Roundup Robot

Change by Roundup Robot :


--
pull_requests: +5894

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21018] [patch] added missing documentation about escaping characters for configparser

2018-03-16 Thread Arun Persaud

Arun Persaud  added the comment:

> @Arun.Persaud, would you be interested in converting your patch to a Github 
> pull request?

sure, I'll give it a try.

Arun

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21018] [patch] added missing documentation about escaping characters for configparser

2018-03-12 Thread Cheryl Sabella

Cheryl Sabella  added the comment:

@Arun.Persaud, would you be interested in converting your patch to a Github 
pull request?

--
nosy: +csabella
versions: +Python 3.7, Python 3.8 -Python 3.5

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: String escaping utility for Python (was: Rawest raw string literals)

2017-04-23 Thread Mikhail V
On 23 April 2017 at 05:03, MRAB  wrote:
> On 2017-04-22 23:30, Mikhail V wrote:
>>
>> On 20 April 2017 at 23:54, MRAB  wrote:
>> > On 2017-04-20 22:03, Mikhail V wrote:
>> >>
>> >> On 20 April 2017 at 22:43, Random832  wrote:
>> >>> [snip]
>> >>>
>> >>> The best solution I can think of is to have a text editor designed to
>> >>> parse a string literal, spawn a nested editor with the unescaped
>> >>> contents of that string literal, and then re-escape it back to place
>> >>> in
>> >>> the code. If we had that, then we wouldn't even need raw strings.
>> >>
>> >>
>> >> Yes exactly, it would be cool to have such a satellite app
>> >> which can escape and unescape strings according to rules.
>> >> And which can also convert unicode literals to their ascii
>> >> analogues and back on the fly, this would very useful
>> >> for programming.
>> >> Probably it is a good idea to even include such thing
>> >> in Python package. So it would be a small standalone app
>> >> running parallel with text editor making it to copy paste strings.
>> >>
>> > I'm sure it's possible in, say, Emacs.
>> >
>> > The editor that I use (EditPad Pro) can call external tools, so I could:
>> >
>> > 1. Select the string literal (easy when it is syntax-aware, so I can
>> > select
>> > all of the literal with 2 keypresses).
>> >
>> > 2. Call the external tool (1 keypress), to open, say, a simple tkinter
>> > app.
>> >
>> > 3. Edit the unescaped text (unescape with ast.literal_eval, re-escape
>> > with
>> > 'ascii').
>> >
>> > 4. Close the external tool, and the selection is replaced.
>>
>> I have done a quick google search and could not find
>> such utility for Python.
>>
>> I am very interested in having such utility.
>> And I think it would be fair that such utility
>> should be made by the Python team so that
>> all syntax nuances will be correctly implemented.
>>
>> The purpose is simple: reduce manual work to escape special
>> characters in string literals (and escape non-ASCII characters).
>>
>> Simple usage scenario:
>> - I have a long command-line string in some text editor.
>> - Copy this string and paste into the utility edit box
>> - In the second edit box same string with escaped characters
>>appears (i.e tab becomes \t, etc)
>> - Further, if I edit the text in the second edit box,
>>an unescaped string appears in the first box.
>>
>> Possible toggle options, e.g. :
>> - 'asciify' non-ascii characters
>>
>> It could be not only useful to eliminate boilerplate typing,
>> but also a great way to learn string rules for Python learners.
>>
> Here's a very simple tkinter GUI app. It only goes one way (plain to escaped
> (asciified)), but it shows what's possible with very little code.
>
>
> #! python3.6
> # -*- coding: utf-8 -*-
> import tkinter as tk
>
> class App(tk.Tk):
> def __init__(self):
> tk.Tk.__init__(self)
> self.title('Escaper')
>
> tk.Label(self, text='Plain string').pack()
>
> self.plain_box = tk.Text(self)
> self.plain_box.pack()
> self.plain_box.focus()
>
> tk.Label(self, text='Escaped string').pack()
>
> self.escaped_box = tk.Text(self)
> self.escaped_box.pack()
>
> self.after(100, self.on_tick)
>
> def on_tick(self):
> plain_string = self.plain_box.get('1.0', 'end')[ : -1]
>
> escaped_string = ascii(plain_string)
>
> self.escaped_box.delete('1.0', 'end')
> self.escaped_box.insert('1.0', escaped_string)
>
> self.after(100, self.on_tick)
>
> App().mainloop()
>

Thank you for sharing! Works fine on Win 7.
So that is what I mean, even such simple app is
uncomparably better that any workarounds and already
covers most cases.
Unfortunately I am not proficient in tkinter so I hope
that will gain some support from other folks and then
could be pinned somewhere and be accessible for
everyone.


Mikhail
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: String escaping utility for Python (was: Rawest raw string literals)

2017-04-22 Thread MRAB

On 2017-04-22 23:30, Mikhail V wrote:

On 20 April 2017 at 23:54, MRAB  wrote:
> On 2017-04-20 22:03, Mikhail V wrote:
>>
>> On 20 April 2017 at 22:43, Random832  wrote:
>>> [snip]
>>>
>>> The best solution I can think of is to have a text editor designed to
>>> parse a string literal, spawn a nested editor with the unescaped
>>> contents of that string literal, and then re-escape it back to place in
>>> the code. If we had that, then we wouldn't even need raw strings.
>>
>>
>> Yes exactly, it would be cool to have such a satellite app
>> which can escape and unescape strings according to rules.
>> And which can also convert unicode literals to their ascii
>> analogues and back on the fly, this would very useful
>> for programming.
>> Probably it is a good idea to even include such thing
>> in Python package. So it would be a small standalone app
>> running parallel with text editor making it to copy paste strings.
>>
> I'm sure it's possible in, say, Emacs.
>
> The editor that I use (EditPad Pro) can call external tools, so I could:
>
> 1. Select the string literal (easy when it is syntax-aware, so I can select
> all of the literal with 2 keypresses).
>
> 2. Call the external tool (1 keypress), to open, say, a simple tkinter app.
>
> 3. Edit the unescaped text (unescape with ast.literal_eval, re-escape with
> 'ascii').
>
> 4. Close the external tool, and the selection is replaced.

I have done a quick google search and could not find
such utility for Python.

I am very interested in having such utility.
And I think it would be fair that such utility
should be made by the Python team so that
all syntax nuances will be correctly implemented.

The purpose is simple: reduce manual work to escape special
characters in string literals (and escape non-ASCII characters).

Simple usage scenario:
- I have a long command-line string in some text editor.
- Copy this string and paste into the utility edit box
- In the second edit box same string with escaped characters
   appears (i.e tab becomes \t, etc)
- Further, if I edit the text in the second edit box,
   an unescaped string appears in the first box.

Possible toggle options, e.g. :
- 'asciify' non-ascii characters

It could be not only useful to eliminate boilerplate typing,
but also a great way to learn string rules for Python learners.

Here's a very simple tkinter GUI app. It only goes one way (plain to 
escaped (asciified)), but it shows what's possible with very little code.



#! python3.6
# -*- coding: utf-8 -*-
import tkinter as tk

class App(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self.title('Escaper')

tk.Label(self, text='Plain string').pack()

self.plain_box = tk.Text(self)
self.plain_box.pack()
self.plain_box.focus()

tk.Label(self, text='Escaped string').pack()

self.escaped_box = tk.Text(self)
self.escaped_box.pack()

self.after(100, self.on_tick)

def on_tick(self):
plain_string = self.plain_box.get('1.0', 'end')[ : -1]

escaped_string = ascii(plain_string)

self.escaped_box.delete('1.0', 'end')
self.escaped_box.insert('1.0', escaped_string)

self.after(100, self.on_tick)

App().mainloop()

--
https://mail.python.org/mailman/listinfo/python-list


Re: String escaping utility for Python (was: Rawest raw string literals)

2017-04-22 Thread Chris Angelico
On Sun, Apr 23, 2017 at 12:30 PM, eryk sun  wrote:
> The X terminals that I've used make it easy to copy text to the
> clipboard. For Windows, it's a pain prior to Windows 10 since the
> legacy console only does rectangular selection. The Windows 10 console
> does line-wrapped selection.

This is true, but if you're using Python for simple text manipulation
as I suggest here, rectangular selection is usually fine. At worst,
you have to rejoin the lines after you paste.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: String escaping utility for Python (was: Rawest raw string literals)

2017-04-22 Thread eryk sun
On Sun, Apr 23, 2017 at 2:06 AM, Mikhail V  wrote:
>
> But are you joking, right? Even if it worked, how can this be convinient,
> e.g. in console one cannot even select and copy paste easily.

The X terminals that I've used make it easy to copy text to the
clipboard. For Windows, it's a pain prior to Windows 10 since the
legacy console only does rectangular selection. The Windows 10 console
does line-wrapped selection.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: String escaping utility for Python (was: Rawest raw string literals)

2017-04-22 Thread Chris Angelico
On Sun, Apr 23, 2017 at 12:06 PM, Mikhail V  wrote:
> Don't know, all I see is "SyntaxError: invalid syntax" if I paste
> there some text.
> Try to paste e.g. this:
> "ffmpeg -i "D:\VIDEO\exp\intro.mp4" -vf "crop=1280:720:0:40,
> scale=640:360" -pix_fmt yuv420p  "D:\ART\0MASTER_UMST\yt_pico.mp4""

Oh. I should have said that my example was for Python 3. If you're
using Python 2, use raw_input() instead. Or just switch to Python 3.

> But are you joking, right? Even if it worked, how can this be convinient,
> e.g. in console one cannot even select and copy paste easily.

Get a better console. Even in Windows, the default console is fully
capable of copying and pasting text, but you can do better than the
default. On every Linux desktop I've used, the console is beautifully
easy to use (GNOME, LXDE, Mate, Xfce, and probably a few others as
well).

> Probably one can make a python script which takes clipboard contents
> then place the conversion result back to clipboard.
> Like:
> - copy some text to clipboard
> - run the script, which replace the clipboard contents with result
> - paste text
>
> I haven't tried that, but even this would be very inconvenient and
> limited in comparison
> to a GUI utility.

You can do that too if you want to. I don't know how you'd do that
with tkinter, but it ought to be possible, and then you wouldn't need
any third party libraries.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: String escaping utility for Python (was: Rawest raw string literals)

2017-04-22 Thread Mikhail V
On 23 April 2017 at 02:33, Chris Angelico  wrote:
> On Sun, Apr 23, 2017 at 10:19 AM, Mikhail V  wrote:
>> On 23 April 2017 at 00:48, Chris Angelico  wrote:
>>> On Sun, Apr 23, 2017 at 8:30 AM, Mikhail V  wrote:
 The purpose is simple: reduce manual work to escape special
 characters in string literals (and escape non-ASCII characters).

 Simple usage scenario:
 - I have a long command-line string in some text editor.
 - Copy this string and paste into the utility edit box
 - In the second edit box same string with escaped characters
   appears (i.e tab becomes \t, etc)
 - Further, if I edit the text in the second edit box,
   an unescaped string appears in the first box.
>>>
>>> Easy.
>>>
>> input()
>>> This string has "quotes" of 'various' «styles», and \backslashes\ too.
>>> 'This string has "quotes" of \'various\' «styles», and \\backslashes\\ too.'
>>>
>>> The repr of a string does pretty much everything you want. If you want
>>> a nice GUI, you can easily put one together that uses repr() to escape
>>> and ast.literal_eval() to unescape.
>>
>> I am sorry, could you elaborate what have you shown here?
>> So in Python console I can become escaped string, but what
>> commands do you use? I never use Python console actually :/
>
> You type "input()" at the Python console, then type the string you
> want. It will be echoed back in representation form, with everything
> correctly escaped.
>
>> And yes the idea is to have a nice GUI. And the idea is exactly opposite
>> to "everyone let's roll an own tool". Obviously I can spend day
>> or two and create such a tool, e.g. with PyQt.
>> But since the task is very common and quite unambiguos I think it is
>> a good reason for a standard official tool.
>
> Or you could spend two seconds firing up the Python REPL, which has
> all the tools you need right there :)
>

Don't know, all I see is "SyntaxError: invalid syntax" if I paste
there some text.
Try to paste e.g. this:
"ffmpeg -i "D:\VIDEO\exp\intro.mp4" -vf "crop=1280:720:0:40,
scale=640:360" -pix_fmt yuv420p  "D:\ART\0MASTER_UMST\yt_pico.mp4""

But are you joking, right? Even if it worked, how can this be convinient,
e.g. in console one cannot even select and copy paste easily.

Probably one can make a python script which takes clipboard contents
then place the conversion result back to clipboard.
Like:
- copy some text to clipboard
- run the script, which replace the clipboard contents with result
- paste text

I haven't tried that, but even this would be very inconvenient and
limited in comparison
to a GUI utility.


Mikhail
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: String escaping utility for Python (was: Rawest raw string literals)

2017-04-22 Thread Chris Angelico
On Sun, Apr 23, 2017 at 10:19 AM, Mikhail V  wrote:
> On 23 April 2017 at 00:48, Chris Angelico  wrote:
>> On Sun, Apr 23, 2017 at 8:30 AM, Mikhail V  wrote:
>>> The purpose is simple: reduce manual work to escape special
>>> characters in string literals (and escape non-ASCII characters).
>>>
>>> Simple usage scenario:
>>> - I have a long command-line string in some text editor.
>>> - Copy this string and paste into the utility edit box
>>> - In the second edit box same string with escaped characters
>>>   appears (i.e tab becomes \t, etc)
>>> - Further, if I edit the text in the second edit box,
>>>   an unescaped string appears in the first box.
>>
>> Easy.
>>
> input()
>> This string has "quotes" of 'various' «styles», and \backslashes\ too.
>> 'This string has "quotes" of \'various\' «styles», and \\backslashes\\ too.'
>>
>> The repr of a string does pretty much everything you want. If you want
>> a nice GUI, you can easily put one together that uses repr() to escape
>> and ast.literal_eval() to unescape.
>
> I am sorry, could you elaborate what have you shown here?
> So in Python console I can become escaped string, but what
> commands do you use? I never use Python console actually :/

You type "input()" at the Python console, then type the string you
want. It will be echoed back in representation form, with everything
correctly escaped.

> And yes the idea is to have a nice GUI. And the idea is exactly opposite
> to "everyone let's roll an own tool". Obviously I can spend day
> or two and create such a tool, e.g. with PyQt.
> But since the task is very common and quite unambiguos I think it is
> a good reason for a standard official tool.

Or you could spend two seconds firing up the Python REPL, which has
all the tools you need right there :)

>>> PS:
>>> Also I remember now about the python-ideas thread
>>> on entering unicode characters with decimals instead of
>>> hex values. It was met somewhat negatively but then it turned out
>>> that in recent Python version it can be done with f-strings.
>>> E.g. a string :
>>>
>>> s="абв"
>>> one can write as:
>>> s = f"{1072:c}{1073:c}{1074:c}"
>>> instead of traditional hex:
>>> "\u0430\u0431\u0432"
>>>
>>> It was told however this is not normal usage.
>>> Still I find it very helpful, so if this is correct syntax, I'd
>>> personally find such a conversion option also very useful.
>>
>> Most of the world finds the hex form MUCH more logical, since Unicode
>> is built around 16s and 256s and such. Please don't proliferate more
>> messes - currently, the only place I can think of where decimal is
>> supported is HTML character entities, and hex is equally supported
>> there.
>>
>> Of course, the best way to represent most non-ASCII characters is as
>> themselves - s="абв" from your example. The main exception is
>> combining characters and related incomplete forms, such as this table
>> of diacritical marks more-or-less lifted from an app of mine:
>>
>> {
>> "\\`":"\u0300","\\'":"\u0301","\\^":"\u0302","\\~":"\u0303",
>> "\\-":"\u0304","\\@":"\u0306","\\.":"\u0307","\\\"":"\u0308",
>> "\\o":"\u030A","\\=":"\u030B","\\v":"\u030C","\\<":"\u0326",
>> "\\,":"\u0327","\\k":"\u0328",
>> }
>>
>> All of them are in the 03xx range. Much easier than pointing out that
>> they're in the range 768 to 879. Please stick to hex.
>
> I don't insist on decimals, I want to use decimals for my own pleasure
> in own projects, may I?
> And don't worry in my whole life I will not produce so many software
> that will significantly increase the 'messes'.
> (Anyway I've got used already to decimals somehow, ord(char), etc.,
> so for me it's too late for the ugly hex)

Will your projects ever be shared with anyone else? If so, please use
the standard. In your own projects, you're welcome to shoot yourself
in the foot, but I'm not going to help you. I'm going to encourage hex
for Unicode.

It's not too late for you to adjust your mind to the standard. And I
strongly recommend it. There are good reasons for hex, and the sooner
you change, the easier it'll be.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: String escaping utility for Python (was: Rawest raw string literals)

2017-04-22 Thread Mikhail V
On 23 April 2017 at 00:48, Chris Angelico  wrote:
> On Sun, Apr 23, 2017 at 8:30 AM, Mikhail V  wrote:
>> The purpose is simple: reduce manual work to escape special
>> characters in string literals (and escape non-ASCII characters).
>>
>> Simple usage scenario:
>> - I have a long command-line string in some text editor.
>> - Copy this string and paste into the utility edit box
>> - In the second edit box same string with escaped characters
>>   appears (i.e tab becomes \t, etc)
>> - Further, if I edit the text in the second edit box,
>>   an unescaped string appears in the first box.
>
> Easy.
>
 input()
> This string has "quotes" of 'various' «styles», and \backslashes\ too.
> 'This string has "quotes" of \'various\' «styles», and \\backslashes\\ too.'
>
> The repr of a string does pretty much everything you want. If you want
> a nice GUI, you can easily put one together that uses repr() to escape
> and ast.literal_eval() to unescape.

I am sorry, could you elaborate what have you shown here?
So in Python console I can become escaped string, but what
commands do you use? I never use Python console actually :/

And yes the idea is to have a nice GUI. And the idea is exactly opposite
to "everyone let's roll an own tool". Obviously I can spend day
or two and create such a tool, e.g. with PyQt.
But since the task is very common and quite unambiguos I think it is
a good reason for a standard official tool.


>
>> PS:
>> Also I remember now about the python-ideas thread
>> on entering unicode characters with decimals instead of
>> hex values. It was met somewhat negatively but then it turned out
>> that in recent Python version it can be done with f-strings.
>> E.g. a string :
>>
>> s="абв"
>> one can write as:
>> s = f"{1072:c}{1073:c}{1074:c}"
>> instead of traditional hex:
>> "\u0430\u0431\u0432"
>>
>> It was told however this is not normal usage.
>> Still I find it very helpful, so if this is correct syntax, I'd
>> personally find such a conversion option also very useful.
>
> Most of the world finds the hex form MUCH more logical, since Unicode
> is built around 16s and 256s and such. Please don't proliferate more
> messes - currently, the only place I can think of where decimal is
> supported is HTML character entities, and hex is equally supported
> there.
>
> Of course, the best way to represent most non-ASCII characters is as
> themselves - s="абв" from your example. The main exception is
> combining characters and related incomplete forms, such as this table
> of diacritical marks more-or-less lifted from an app of mine:
>
> {
> "\\`":"\u0300","\\'":"\u0301","\\^":"\u0302","\\~":"\u0303",
> "\\-":"\u0304","\\@":"\u0306","\\.":"\u0307","\\\"":"\u0308",
> "\\o":"\u030A","\\=":"\u030B","\\v":"\u030C","\\<":"\u0326",
> "\\,":"\u0327","\\k":"\u0328",
> }
>
> All of them are in the 03xx range. Much easier than pointing out that
> they're in the range 768 to 879. Please stick to hex.

I don't insist on decimals, I want to use decimals for my own pleasure
in own projects, may I?
And don't worry in my whole life I will not produce so many software
that will significantly increase the 'messes'.
(Anyway I've got used already to decimals somehow, ord(char), etc.,
so for me it's too late for the ugly hex)


Mikhail
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: String escaping utility for Python (was: Rawest raw string literals)

2017-04-22 Thread Chris Angelico
On Sun, Apr 23, 2017 at 8:30 AM, Mikhail V  wrote:
> The purpose is simple: reduce manual work to escape special
> characters in string literals (and escape non-ASCII characters).
>
> Simple usage scenario:
> - I have a long command-line string in some text editor.
> - Copy this string and paste into the utility edit box
> - In the second edit box same string with escaped characters
>   appears (i.e tab becomes \t, etc)
> - Further, if I edit the text in the second edit box,
>   an unescaped string appears in the first box.

Easy.

>>> input()
This string has "quotes" of 'various' «styles», and \backslashes\ too.
'This string has "quotes" of \'various\' «styles», and \\backslashes\\ too.'

The repr of a string does pretty much everything you want. If you want
a nice GUI, you can easily put one together that uses repr() to escape
and ast.literal_eval() to unescape.

> PS:
> Also I remember now about the python-ideas thread
> on entering unicode characters with decimals instead of
> hex values. It was met somewhat negatively but then it turned out
> that in recent Python version it can be done with f-strings.
> E.g. a string :
>
> s="абв"
> one can write as:
> s = f"{1072:c}{1073:c}{1074:c}"
> instead of traditional hex:
> "\u0430\u0431\u0432"
>
> It was told however this is not normal usage.
> Still I find it very helpful, so if this is correct syntax, I'd
> personally find such a conversion option also very useful.

Most of the world finds the hex form MUCH more logical, since Unicode
is built around 16s and 256s and such. Please don't proliferate more
messes - currently, the only place I can think of where decimal is
supported is HTML character entities, and hex is equally supported
there.

Of course, the best way to represent most non-ASCII characters is as
themselves - s="абв" from your example. The main exception is
combining characters and related incomplete forms, such as this table
of diacritical marks more-or-less lifted from an app of mine:

{
"\\`":"\u0300","\\'":"\u0301","\\^":"\u0302","\\~":"\u0303",
"\\-":"\u0304","\\@":"\u0306","\\.":"\u0307","\\\"":"\u0308",
"\\o":"\u030A","\\=":"\u030B","\\v":"\u030C","\\<":"\u0326",
"\\,":"\u0327","\\k":"\u0328",
}

All of them are in the 03xx range. Much easier than pointing out that
they're in the range 768 to 879. Please stick to hex.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


String escaping utility for Python (was: Rawest raw string literals)

2017-04-22 Thread Mikhail V
On 20 April 2017 at 23:54, MRAB  wrote:
> On 2017-04-20 22:03, Mikhail V wrote:
>>
>> On 20 April 2017 at 22:43, Random832  wrote:
>>> [snip]
>>>
>>> The best solution I can think of is to have a text editor designed to
>>> parse a string literal, spawn a nested editor with the unescaped
>>> contents of that string literal, and then re-escape it back to place in
>>> the code. If we had that, then we wouldn't even need raw strings.
>>
>>
>> Yes exactly, it would be cool to have such a satellite app
>> which can escape and unescape strings according to rules.
>> And which can also convert unicode literals to their ascii
>> analogues and back on the fly, this would very useful
>> for programming.
>> Probably it is a good idea to even include such thing
>> in Python package. So it would be a small standalone app
>> running parallel with text editor making it to copy paste strings.
>>
> I'm sure it's possible in, say, Emacs.
>
> The editor that I use (EditPad Pro) can call external tools, so I could:
>
> 1. Select the string literal (easy when it is syntax-aware, so I can select
> all of the literal with 2 keypresses).
>
> 2. Call the external tool (1 keypress), to open, say, a simple tkinter app.
>
> 3. Edit the unescaped text (unescape with ast.literal_eval, re-escape with
> 'ascii').
>
> 4. Close the external tool, and the selection is replaced.

I have done a quick google search and could not find
such utility for Python.

I am very interested in having such utility.
And I think it would be fair that such utility
should be made by the Python team so that
all syntax nuances will be correctly implemented.

The purpose is simple: reduce manual work to escape special
characters in string literals (and escape non-ASCII characters).

Simple usage scenario:
- I have a long command-line string in some text editor.
- Copy this string and paste into the utility edit box
- In the second edit box same string with escaped characters
  appears (i.e tab becomes \t, etc)
- Further, if I edit the text in the second edit box,
  an unescaped string appears in the first box.

Possible toggle options, e.g. :
- 'asciify' non-ascii characters

It could be not only useful to eliminate boilerplate typing,
but also a great way to learn string rules for Python learners.


PS:
Also I remember now about the python-ideas thread
on entering unicode characters with decimals instead of
hex values. It was met somewhat negatively but then it turned out
that in recent Python version it can be done with f-strings.
E.g. a string :

s="абв"
one can write as:
s = f"{1072:c}{1073:c}{1074:c}"
instead of traditional hex:
"\u0430\u0431\u0432"

It was told however this is not normal usage.
Still I find it very helpful, so if this is correct syntax, I'd
personally find such a conversion option also very useful.


Mikhail
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-27 Thread Jussi Piitulainen
Gregory Ewing writes:

> Νίκος Βέργος wrote:
>
>> Its still a mystery to em whay this fails syntactically when at the
>> same time INSERT works like that.
>
> I don't think *anyone* understands why SQL was designed with
> INSERT and UPDATE having completely different syntaxes.
> But it was, and we have to live with it.

A story I heard is that IBM had two competing teams working to design a
database system. One team understood programming languages. The other
team understood storage system layouts. The latter team won, and their
system grew up to be SQL.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-27 Thread Gregory Ewing

Νίκος Βέργος wrote:


Its still a mystery to em whay this fails syntactically when at the same time
INSERT works like that.


I don't think *anyone* understands why SQL was designed with
INSERT and UPDATE having completely different syntaxes.
But it was, and we have to live with it.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-27 Thread Νίκος Βέργος
Thank you very much Johann.

i was using print(update wuery here) and i was seeing that print was able
to parser the query and that consused me as to why execute wont do the same
since with print all values was gettign substituted.

of course pymysql doesnt behave the same with print but until i fugure that
out cost me lots of time.

Στις Δευ, 27 Μαρ 2017 στις 10:52 π.μ., ο/η Johann Spies <
johann.sp...@gmail.com> έγραψε:

> Νίκος,
>
> I am glad that you solved the problem.
>
> I am not using mysql but postgresql.  When I get a problem using python to
> communicate with the database, one of my first steps will be to determine
> whether the error is a python (maybe psycopg-related) related error or a
> database error.  What I do then is to use the string python is sending to
> the database and try to run that on the commandline interface to the
> database (psgl) or something like pgadmin3.  Mysql have similar tools.
>
> Once you have determined that it a database related problem, it should be
> easy to sort it out on that side.  If it works on the database the rest of
> the problem should be solved on the python side.
>
> Maybe this approach would have saved you some time.
>
> Regards
> Johann
> --
> Because experiencing your loyal love is better than life itself,
> my lips will praise you.  (Psalm 63:3)
>
-- 
What is now proved was at first only imagined!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-27 Thread Johann Spies
Νίκος,

I am glad that you solved the problem.

I am not using mysql but postgresql.  When I get a problem using python to
communicate with the database, one of my first steps will be to determine
whether the error is a python (maybe psycopg-related) related error or a
database error.  What I do then is to use the string python is sending to
the database and try to run that on the commandline interface to the
database (psgl) or something like pgadmin3.  Mysql have similar tools.

Once you have determined that it a database related problem, it should be
easy to sort it out on that side.  If it works on the database the rest of
the problem should be solved on the python side.

Maybe this approach would have saved you some time.

Regards
Johann
-- 
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Νίκος Βέργος
Τη Δευτέρα, 27 Μαρτίου 2017 - 6:00:34 π.μ. UTC+3, ο χρήστης Chris Angelico 
έγραψε:
> On Mon, Mar 27, 2017 at 1:52 PM, Νίκος Βέργος  wrote:
> > Its NOT that i have not read it exactly, but for some strange reason i was 
> > under the belief that the way i had syntactically typed the UPDATE query 
> > was correctly and more consistent and similar to thr INSERT query and it 
> > was prefered to me over the other one.
> >
> > UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) 
> > VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s"
> >
> > Its still a mystery to em whay this fails syntactically when at the same 
> > time INSERT works like that.
> >
> > We give each columnn a specific value i don't see why it must only be 
> > written as UPDATE visitors SET a=1, b=2, c=3 ... WHERE host LIKE %s.
> >
> > i knew that would work, but the first way although proven syntactically 
> > wrong seems so right .
> 
> It'd be even more logical to write:
> 
> UPDATE visitors INCREMENT visits WHERE host CONTAINS %s;
> 
> I should just use that syntax, and if it doesn't work, I'm going to
> post onto a mailing list until it magically starts working. It's NOT
> that I haven't read the docs - I'm just going to wilfully ignore them.
> 
> Okay, I'm done now.
> 
> ChrisA

Okey i have taken my lesson.
I should have written it as the doc suggested instead of being persistent on 
finding what was worng in the way i had written it
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Chris Angelico
On Mon, Mar 27, 2017 at 1:52 PM, Νίκος Βέργος  wrote:
> Its NOT that i have not read it exactly, but for some strange reason i was 
> under the belief that the way i had syntactically typed the UPDATE query was 
> correctly and more consistent and similar to thr INSERT query and it was 
> prefered to me over the other one.
>
> UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) 
> VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s"
>
> Its still a mystery to em whay this fails syntactically when at the same time 
> INSERT works like that.
>
> We give each columnn a specific value i don't see why it must only be written 
> as UPDATE visitors SET a=1, b=2, c=3 ... WHERE host LIKE %s.
>
> i knew that would work, but the first way although proven syntactically wrong 
> seems so right .

It'd be even more logical to write:

UPDATE visitors INCREMENT visits WHERE host CONTAINS %s;

I should just use that syntax, and if it doesn't work, I'm going to
post onto a mailing list until it magically starts working. It's NOT
that I haven't read the docs - I'm just going to wilfully ignore them.

Okay, I'm done now.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Νίκος Βέργος
Τη Δευτέρα, 27 Μαρτίου 2017 - 5:43:01 π.μ. UTC+3, ο χρήστης Chris Angelico 
έγραψε:
> On Mon, Mar 27, 2017 at 1:39 PM, Νίκος Βέργος  wrote:
> >> MariaDB / MySQL shows part of your SQL from where they failed to parse.
> >> In your case, your MariaDB can't parse from '('
> >> LIKE clause is not problem for this issue?
> >
> > Yes indeed it is.
> > I was just so sure that UPDATE was working like INSERT and i was persistent 
> > that the WHERE LIKE clause was cauing this.
> >
> > I'am still surprised that:
> >> mysql> update test_update set (b, c) values (4, 5) where a = 1;
> >
> > is failign to parse. It just seems so undoubtly straightforward and correct 
> > syntactically.
> 
> So when people told you to read the docs, what did you do, exactly?
> 
> ChrisA

Its NOT that i have not read it exactly, but for some strange reason i was 
under the belief that the way i had syntactically typed the UPDATE query was 
correctly and more consistent and similar to thr INSERT query and it was 
prefered to me over the other one.

UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) 
VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s"

Its still a mystery to em whay this fails syntactically when at the same time 
INSERT works like that.

We give each columnn a specific value i don't see why it must only be written 
as UPDATE visitors SET a=1, b=2, c=3 ... WHERE host LIKE %s.

i knew that would work, but the first way although proven syntactically wrong 
seems so right .
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Chris Angelico
On Mon, Mar 27, 2017 at 1:39 PM, Νίκος Βέργος  wrote:
>> MariaDB / MySQL shows part of your SQL from where they failed to parse.
>> In your case, your MariaDB can't parse from '('
>> LIKE clause is not problem for this issue?
>
> Yes indeed it is.
> I was just so sure that UPDATE was working like INSERT and i was persistent 
> that the WHERE LIKE clause was cauing this.
>
> I'am still surprised that:
>> mysql> update test_update set (b, c) values (4, 5) where a = 1;
>
> is failign to parse. It just seems so undoubtly straightforward and correct 
> syntactically.

So when people told you to read the docs, what did you do, exactly?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Νίκος Βέργος
Τη Δευτέρα, 27 Μαρτίου 2017 - 2:27:31 π.μ. UTC+3, ο χρήστης INADA Naoki έγραψε:
> > i dont have to update table set column1 = this value, column2=that value and
> > so on
> 
> Why do you think so?  Did you really read the manual?
> 
> mysql> create table test_update (a int primary key, b int, c int);
> Query OK, 0 rows affected (0.02 sec)
> 
> mysql> insert into test_update values (1, 2, 3);
> Query OK, 1 row affected (0.00 sec)
> 
> mysql> update test_update set (b, c) values (4, 5) where a = 1;
> ERROR 1064 (42000): You have an error in your SQL syntax; check the
> manual that corresponds to your MySQL server version for the right
> syntax to use near '(b, c) values (4, 5) where a = 1' at line 1
> 
> mysql> update test_update set b=4, c=5 where a = 1;
> Query OK, 1 row affected (0.01 sec)
> Rows matched: 1  Changed: 1  Warnings: 0
> 
> >
> > It's just when the LIKE clause jumps in that is causing all this trouble
> 
> Your MariaDB said:
> 
> > check the manual that corresponds to your MariaDB server version for the 
> > right syntax to use near '(pagesID, host, ...
> 
> MariaDB / MySQL shows part of your SQL from where they failed to parse.
> In your case, your MariaDB can't parse from '('
> LIKE clause is not problem for this issue?

Yes indeed it is.
I was just so sure that UPDATE was working like INSERT and i was persistent 
that the WHERE LIKE clause was cauing this.

I'am still surprised that:
> mysql> update test_update set (b, c) values (4, 5) where a = 1;

is failign to parse. It just seems so undoubtly straightforward and correct 
syntactically.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Steve D'Aprano
On Mon, 27 Mar 2017 07:13 am, Νίκος Βέργος wrote:

> OMG!!! It actually worked!
> 
> Can't believe that 3 days in a row i have tried everything concerning
> string manipulation and mysql escaping nd the error was the UPDATE
> itself

You tried everything except what we told you, over and over and over again:

READ THE MANUAL.

The error message told you it was a SQL syntax error, but no, you insisted
that you knew better, and refused to do what the error message said.

So you wasted three days due to your own stubbornness and laziness.

I have no sympathy for your self-inflicted problems.




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread INADA Naoki
> i dont have to update table set column1 = this value, column2=that value and
> so on

Why do you think so?  Did you really read the manual?

mysql> create table test_update (a int primary key, b int, c int);
Query OK, 0 rows affected (0.02 sec)

mysql> insert into test_update values (1, 2, 3);
Query OK, 1 row affected (0.00 sec)

mysql> update test_update set (b, c) values (4, 5) where a = 1;
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near '(b, c) values (4, 5) where a = 1' at line 1

mysql> update test_update set b=4, c=5 where a = 1;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

>
> It's just when the LIKE clause jumps in that is causing all this trouble

Your MariaDB said:

> check the manual that corresponds to your MariaDB server version for the 
> right syntax to use near '(pagesID, host, ...

MariaDB / MySQL shows part of your SQL from where they failed to parse.
In your case, your MariaDB can't parse from '('
LIKE clause is not problem for this issue?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread breamoreboy
On Sunday, March 26, 2017 at 8:33:49 PM UTC+1, Νίκος Βέργος wrote:
> Τη Κυριακή, 26 Μαρτίου 2017 - 10:23:27 μ.μ. UTC+3, ο χρήστης 
> bream...@gmail.com έγραψε:
> > On Sunday, March 26, 2017 at 4:11:54 PM UTC+1, Νίκος Βέργος wrote:
> > > Τη Κυριακή, 26 Μαρτίου 2017 - 5:49:00 μ.μ. UTC+3, ο χρήστης Ian έγραψε:
> > > 
> > > > The database wrapper won't do substitution into the middle of a string
> > > > like that. Either concatenate the literal %'s on in the SQL statement
> > > > or add them to the string before you pass it in, i.e. '%' + domain +
> > > > '%' or '%%%s%%' % domain or '%{}%'.format(domain).
> > > 
> > > I just tried:
> > > 
> > > domain = '.'.join( host.split('.')[-2:] )
> > > domain = '%' + domain + '%'
> > > 
> > > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, 
> > > browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s" 
> > > ''', 
> > >   
> > >   
> > >   
> > > (pID, domain, ref, 
> > > location, useros, browser, lastvisit, domain) )
> > > 
> > > 
> > > and i received no error in the error_log but
> > > ProgrammingError(1064, "You have an error in your SQL syntax; check the 
> > > manual that corresponds to your MariaDB server version for the right 
> > > syntax to use near '(pagesID, host, ref, location, useros, browser, 
> > > visits) VALUES (1, '%cyta.gr%', ' at line 1")
> > > 
> > > which you can see at http://superhost.gr
> > > 
> > > You said somethign about concatenating the literal % in the SQL to which 
> > > i didnt actually i understand how to implement.
> > 
> > I knew that I had a sense of deja vu about this 
> > https://mail.python.org/pipermail/python-list/2013-June/649809.html
> > 
> > Kindest regards.
> > 
> > Mark Lawrence
> 
> Since i'm incopetent as you suggest i'am show us your level of skills and 
> expertise and provide a solution, otherwise you are also what you claim of me.

*plonk*
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread breamoreboy
On Sunday, March 26, 2017 at 4:11:54 PM UTC+1, Νίκος Βέργος wrote:
> Τη Κυριακή, 26 Μαρτίου 2017 - 5:49:00 μ.μ. UTC+3, ο χρήστης Ian έγραψε:
> 
> > The database wrapper won't do substitution into the middle of a string
> > like that. Either concatenate the literal %'s on in the SQL statement
> > or add them to the string before you pass it in, i.e. '%' + domain +
> > '%' or '%%%s%%' % domain or '%{}%'.format(domain).
> 
> I just tried:
> 
> domain = '.'.join( host.split('.')[-2:] )
> domain = '%' + domain + '%'
> 
> cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, 
> browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s" 
> ''', 
>   
>   
>   
> (pID, domain, ref, location, 
> useros, browser, lastvisit, domain) )
> 
> 
> and i received no error in the error_log but
> ProgrammingError(1064, "You have an error in your SQL syntax; check the 
> manual that corresponds to your MariaDB server version for the right syntax 
> to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES 
> (1, '%cyta.gr%', ' at line 1")
> 
> which you can see at http://superhost.gr
> 
> You said somethign about concatenating the literal % in the SQL to which i 
> didnt actually i understand how to implement.

I knew that I had a sense of deja vu about this 
https://mail.python.org/pipermail/python-list/2013-June/649809.html

Kindest regards.

Mark Lawrence
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Νίκος Βέργος
Τη Κυριακή, 26 Μαρτίου 2017 - 11:59:21 μ.μ. UTC+3, ο χρήστης Larry Hudson 
έγραψε:
> On 03/26/2017 01:21 AM, Νίκος Βέργος wrote:
> > print('''UPDATE visitors SET (pagesID, host, ref, location, useros, 
> > browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE 
> > "%s"''', (pID, domain, ref, location, useros, browser, lastvisit, domain) )
> >
> > prints out:
> >
> > UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) 
> > VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s" (1, 'cyta.gr', 
> > 'Άμεση Πρόσβαση', 'Greece', 'Windows', 'Chrome', '17-03-24 22:04:24', 
> > 'cyta.gr')
> >
> > How should i write the cursor.execute in order to be parsed properly?
> > As i have it now %s does not get substituted.
> 
> You don't get the substitution because you're missing a %.
> 
> Change:
>  ... LIKE "%s"''', (pID, ...
> To:
>  ... LIKE "%s"''' % (pID, ...
> 
> -- 
>   -=- Larry -=-

No, i have tried it many times. 
It fails and is prone to sql injection within a cursor execute.

As i understood i can have UPDATE syntax be as similar to INSERT like

(pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, 
%s, %s, %s)

each column needs to be set respectively as column1 = value1, column2 = value 2 
and so on.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Larry Hudson via Python-list

On 03/26/2017 01:21 AM, Νίκος Βέργος wrote:

print('''UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) 
VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s"''', (pID, domain, ref, 
location, useros, browser, lastvisit, domain) )

prints out:

UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, 
%s, %s, %s, %s, %s, %s) WHERE host LIKE "%s" (1, 'cyta.gr', 'Άμεση Πρόσβαση', 
'Greece', 'Windows', 'Chrome', '17-03-24 22:04:24', 'cyta.gr')

How should i write the cursor.execute in order to be parsed properly?
As i have it now %s does not get substituted.


You don't get the substitution because you're missing a %.

Change:
... LIKE "%s"''', (pID, ...
To:
... LIKE "%s"''' % (pID, ...

--
 -=- Larry -=-
--
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Νίκος Βέργος
Τη Κυριακή, 26 Μαρτίου 2017 - 11:05:34 μ.μ. UTC+3, ο χρήστης Νίκος Βέργος 
έγραψε:
> Τη Κυριακή, 26 Μαρτίου 2017 - 10:56:07 μ.μ. UTC+3, ο χρήστης Chris Angelico 
> έγραψε:
> > On Mon, Mar 27, 2017 at 6:33 AM, Νίκος Βέργος <me.on@gmail.com> wrote:
> > > Since i'm incopetent as you suggest i'am show us your level of skills and 
> > > expertise and provide a solution, otherwise you are also what you claim 
> > > of me.
> > 
> > It's not his problem. An expert does not have to provide solutions to
> > prove his expertise, unless s/he is suffering from severe self-image
> > problems. Someone who's getting paid to host other people's web sites,
> > on the other hand, needs to solve the problems that come up.
> > 
> > ChrisA
> 
> Okey although i beleive my UPDATE query to be correct i'll now try this:
> 
> cur.execute('''UPDATE visitors SET pagesID=%s, host=%s, ref=%s, location=%s, 
> useros=%s, browser=%s, visits=%s WHERE host LIKE %s''', (pID, domain, ref, 
> location, useros, browser, lastvisit, domain_query) )

OMG!!! It actually worked!

Can't believe that 3 days in a row i have tried everything concerning string 
manipulation and mysql escaping nd the error was the UPDATE itself

OMG!!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Νίκος Βέργος
Τη Κυριακή, 26 Μαρτίου 2017 - 10:56:07 μ.μ. UTC+3, ο χρήστης Chris Angelico 
έγραψε:
> On Mon, Mar 27, 2017 at 6:33 AM, Νίκος Βέργος  wrote:
> > Since i'm incopetent as you suggest i'am show us your level of skills and 
> > expertise and provide a solution, otherwise you are also what you claim of 
> > me.
> 
> It's not his problem. An expert does not have to provide solutions to
> prove his expertise, unless s/he is suffering from severe self-image
> problems. Someone who's getting paid to host other people's web sites,
> on the other hand, needs to solve the problems that come up.
> 
> ChrisA

Okey although i beleive my UPDATE query to be correct i'll now try this:

cur.execute('''UPDATE visitors SET pagesID=%s, host=%s, ref=%s, location=%s, 
useros=%s, browser=%s, visits=%s WHERE host LIKE %s''', (pID, domain, ref, 
location, useros, browser, lastvisit, domain_query) )
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Chris Angelico
On Mon, Mar 27, 2017 at 6:33 AM, Νίκος Βέργος  wrote:
> Since i'm incopetent as you suggest i'am show us your level of skills and 
> expertise and provide a solution, otherwise you are also what you claim of me.

It's not his problem. An expert does not have to provide solutions to
prove his expertise, unless s/he is suffering from severe self-image
problems. Someone who's getting paid to host other people's web sites,
on the other hand, needs to solve the problems that come up.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Νίκος Βέργος
Τη Κυριακή, 26 Μαρτίου 2017 - 10:23:27 μ.μ. UTC+3, ο χρήστης bream...@gmail.com 
έγραψε:
> On Sunday, March 26, 2017 at 4:11:54 PM UTC+1, Νίκος Βέργος wrote:
> > Τη Κυριακή, 26 Μαρτίου 2017 - 5:49:00 μ.μ. UTC+3, ο χρήστης Ian έγραψε:
> > 
> > > The database wrapper won't do substitution into the middle of a string
> > > like that. Either concatenate the literal %'s on in the SQL statement
> > > or add them to the string before you pass it in, i.e. '%' + domain +
> > > '%' or '%%%s%%' % domain or '%{}%'.format(domain).
> > 
> > I just tried:
> > 
> > domain = '.'.join( host.split('.')[-2:] )
> > domain = '%' + domain + '%'
> > 
> > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, 
> > browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s" 
> > ''', 
> > 
> > 
> > 
> > (pID, domain, ref, 
> > location, useros, browser, lastvisit, domain) )
> > 
> > 
> > and i received no error in the error_log but
> > ProgrammingError(1064, "You have an error in your SQL syntax; check the 
> > manual that corresponds to your MariaDB server version for the right syntax 
> > to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES 
> > (1, '%cyta.gr%', ' at line 1")
> > 
> > which you can see at http://superhost.gr
> > 
> > You said somethign about concatenating the literal % in the SQL to which i 
> > didnt actually i understand how to implement.
> 
> I knew that I had a sense of deja vu about this 
> https://mail.python.org/pipermail/python-list/2013-June/649809.html
> 
> Kindest regards.
> 
> Mark Lawrence

Since i'm incopetent as you suggest i'am show us your level of skills and 
expertise and provide a solution, otherwise you are also what you claim of me.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Νίκος Βέργος
Τη Κυριακή, 26 Μαρτίου 2017 - 10:04:31 μ.μ. UTC+3, ο χρήστης Chris Angelico 
έγραψε:
> On Mon, Mar 27, 2017 at 5:52 AM, Νίκος Βέργος  wrote:
> > Τη Κυριακή, 26 Μαρτίου 2017 - 9:32:13 μ.μ. UTC+3, ο χρήστης Chris Angelico 
> > έγραψε:
> >> On Mon, Mar 27, 2017 at 4:54 AM, Νίκος Βέργος  wrote:
> >> > Τη Κυριακή, 26 Μαρτίου 2017 - 8:06:07 μ.μ. UTC+3, ο χρήστης INADA Naoki 
> >> > έγραψε:
> >> >> Read my mail again.
> >> >>
> >> >> > This error came from MySQL.  If there are no logs in error_log, it's
> >> >> > your configuration issue.
> >> >>
> >> >> > See https://dev.mysql.com/doc/refman/5.7/en/update.html for Update
> >> >> > statement syntax.
> >> >
> >> > I cannot understand where the error is.
> >> > Could you how it to me please?
> >>
> >> Are people paying you to run their servers, and you're not even
> >> prepared to spend a few minutes reading the documentation before
> >> firing another post to a newsgroup/mailing list with thousands of
> >> participants? (Actually, I have no idea how many people read
> >> python-list/clp - 10K? 100K? 1M?)
> >>
> >> ChrisA
> >
> > So the answer is within that url link and i cannot see it?!
> >
> > Give me a hint!
> 
> You cannot see it? Why not - are you unable to access the web? Then
> track down the equivalent local documentation. I don't have MySQL or
> MariaDB installed here, but with PostgreSQL, I can fire up the CLI and
> get documentation on SQL commands.
> 
> So no, I won't give you a hint until you get a clue.
> 
> ChrisA

I can see it Chris, but i just cannot "see" it.

If i remove the WHERE LIKE clause statement executes properly.

Its when adding the clause that does not interpolated correctly.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Chris Angelico
On Mon, Mar 27, 2017 at 5:52 AM, Νίκος Βέργος  wrote:
> Τη Κυριακή, 26 Μαρτίου 2017 - 9:32:13 μ.μ. UTC+3, ο χρήστης Chris Angelico 
> έγραψε:
>> On Mon, Mar 27, 2017 at 4:54 AM, Νίκος Βέργος  wrote:
>> > Τη Κυριακή, 26 Μαρτίου 2017 - 8:06:07 μ.μ. UTC+3, ο χρήστης INADA Naoki 
>> > έγραψε:
>> >> Read my mail again.
>> >>
>> >> > This error came from MySQL.  If there are no logs in error_log, it's
>> >> > your configuration issue.
>> >>
>> >> > See https://dev.mysql.com/doc/refman/5.7/en/update.html for Update
>> >> > statement syntax.
>> >
>> > I cannot understand where the error is.
>> > Could you how it to me please?
>>
>> Are people paying you to run their servers, and you're not even
>> prepared to spend a few minutes reading the documentation before
>> firing another post to a newsgroup/mailing list with thousands of
>> participants? (Actually, I have no idea how many people read
>> python-list/clp - 10K? 100K? 1M?)
>>
>> ChrisA
>
> So the answer is within that url link and i cannot see it?!
>
> Give me a hint!

You cannot see it? Why not - are you unable to access the web? Then
track down the equivalent local documentation. I don't have MySQL or
MariaDB installed here, but with PostgreSQL, I can fire up the CLI and
get documentation on SQL commands.

So no, I won't give you a hint until you get a clue.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Νίκος Βέργος
Τη Κυριακή, 26 Μαρτίου 2017 - 8:58:55 μ.μ. UTC+3, ο χρήστης alister έγραψε:
> On Sun, 26 Mar 2017 07:43:51 -0700, Νίκος Βέργος wrote:
> 
> > Τη Κυριακή, 26 Μαρτίου 2017 - 5:38:57 μ.μ. UTC+3, ο χρήστης alister
> > έγραψε:
> >> On Sun, 26 Mar 2017 07:24:49 -0700, Νίκος Βέργος wrote:
> >> 
> >> > Τη Κυριακή, 26 Μαρτίου 2017 - 5:19:27 μ.μ. UTC+3, ο χρήστης Ian
> >> > έγραψε:
> >> > 
> >> >> You need to change the placeholders back. The poster who told you to
> >> >> replace them was misinformed.
> >> > 
> >> > okey altered them back to
> >> > 
> >> > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location,
> >> > useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE
> >> > host LIKE "%%s%" ''',
> >> > 
> >> > 
> >> (pID, domain, ref, location, useros,
> >> > 
> >> > 
> >> browser, lastvisit, domain) )
> >> > 
> >> > but now the problem is how to exact;y type the Where HOST like "%%%"
> >> > 
> >> > I MEAN HOW TO DIFFERENTIATE '%S' FROM LITERAL '%' character.
> >> 
> >> 
> >> as a quick thought (untested) it is probably best to have %s as your
> >> parameter for the Like clause & ad the sql wild-cards (% symbols) to
> >> the data you pass in as I think the expansion of %s adds quote marks
> >> which will certainly cause the sql parser issues.
> > 
> > How do you propose writing that cur.execute statement Alister?
> 
> 
> cur.execute('''UPDATE visitors SET (pagesID, host, ref, location,
> >> > useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE
> >> > host LIKE %s '''
> 
> but you will need to amend the data  you pass so that the last element 
> has the surrounding % characters .
> 
> 
> -- 
> T-1's congested due to porn traffic to the news server.

i have done so ith 3 different ways to prepare the string before sending it as 
an argument to update query as i mentioned in a previous post.

Unfortunately all 3 ways weren't able to make the query work.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Νίκος Βέργος
Τη Κυριακή, 26 Μαρτίου 2017 - 9:32:13 μ.μ. UTC+3, ο χρήστης Chris Angelico 
έγραψε:
> On Mon, Mar 27, 2017 at 4:54 AM, Νίκος Βέργος  wrote:
> > Τη Κυριακή, 26 Μαρτίου 2017 - 8:06:07 μ.μ. UTC+3, ο χρήστης INADA Naoki 
> > έγραψε:
> >> Read my mail again.
> >>
> >> > This error came from MySQL.  If there are no logs in error_log, it's
> >> > your configuration issue.
> >>
> >> > See https://dev.mysql.com/doc/refman/5.7/en/update.html for Update
> >> > statement syntax.
> >
> > I cannot understand where the error is.
> > Could you how it to me please?
> 
> Are people paying you to run their servers, and you're not even
> prepared to spend a few minutes reading the documentation before
> firing another post to a newsgroup/mailing list with thousands of
> participants? (Actually, I have no idea how many people read
> python-list/clp - 10K? 100K? 1M?)
> 
> ChrisA

So the answer is within that url link and i cannot see it?!

Give me a hint!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread breamoreboy
On Sunday, March 26, 2017 at 3:11:50 PM UTC+1, Ian wrote:
> On Sun, Mar 26, 2017 at 7:39 AM, MeV wrote:
> > On Sunday, March 26, 2017 at 6:34:30 AM UTC-7, Νίκος Βέργος wrote:
> >> with import cgitb; cgitb.enable()
> >>
> >> ProgrammingError(1064, "You have an error in your SQL syntax; check the 
> >> manual that corresponds to your MariaDB server version for the right 
> >> syntax to use near '(pagesID, host, ref, location, useros, browser, 
> >> visits) VALUES (1, 'cyta.gr', '' at line 1")
> >>
> >> that is all i get form error. error_log doesnt produce errors when iam 
> >> trying
> >>
> >> cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, 
> >> browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE %s''',
> >>
> >>
> >>
> >>  (pID, domain, ref, 
> >> location, useros, browser, lastvisit, domain) )
> >>
> >> WHY the valued aren't getting substituted wi the aeguments i give it in to 
> >> work with?
> >
> > The % construct is Python 2 and no longer supported in Python 3. You should 
> > read up on the "{}" and format method.
> >
> > https://docs.python.org/3/tutorial/inputoutput.html#fancier-output-formatting
> 
> Rubbish, it works just fine in Python 3:
> 
> Python 3.6.0 (default, Jan  1 2017, 22:51:19)
> [GCC 5.4.0 20160609] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> '%s %s' % ('Hello', 'world')
> 'Hello world'
> 
> And contrary to popular belief, it's not even deprecated (although use
> of the newer format method is encouraged). What's more, in this case
> it's part of the PEP 249 DBAPI specification:
> https://www.python.org/dev/peps/pep-0249/#paramstyle. As far as I know
> pymysql and DBAPI libraries in general don't even accept "{}".

There was quite a chat about the issue of deprecated or not 
http://www.gossamer-threads.com/lists/python/dev/969817

Kindest regards.

Mark Lawrence.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Chris Angelico
On Mon, Mar 27, 2017 at 4:54 AM, Νίκος Βέργος  wrote:
> Τη Κυριακή, 26 Μαρτίου 2017 - 8:06:07 μ.μ. UTC+3, ο χρήστης INADA Naoki 
> έγραψε:
>> Read my mail again.
>>
>> > This error came from MySQL.  If there are no logs in error_log, it's
>> > your configuration issue.
>>
>> > See https://dev.mysql.com/doc/refman/5.7/en/update.html for Update
>> > statement syntax.
>
> I cannot understand where the error is.
> Could you how it to me please?

Are people paying you to run their servers, and you're not even
prepared to spend a few minutes reading the documentation before
firing another post to a newsgroup/mailing list with thousands of
participants? (Actually, I have no idea how many people read
python-list/clp - 10K? 100K? 1M?)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread alister
On Sun, 26 Mar 2017 07:43:51 -0700, Νίκος Βέργος wrote:

> Τη Κυριακή, 26 Μαρτίου 2017 - 5:38:57 μ.μ. UTC+3, ο χρήστης alister
> έγραψε:
>> On Sun, 26 Mar 2017 07:24:49 -0700, Νίκος Βέργος wrote:
>> 
>> > Τη Κυριακή, 26 Μαρτίου 2017 - 5:19:27 μ.μ. UTC+3, ο χρήστης Ian
>> > έγραψε:
>> > 
>> >> You need to change the placeholders back. The poster who told you to
>> >> replace them was misinformed.
>> > 
>> > okey altered them back to
>> > 
>> > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location,
>> > useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE
>> > host LIKE "%%s%" ''',
>> > 
>> > 
>> (pID, domain, ref, location, useros,
>> > 
>> > 
>> browser, lastvisit, domain) )
>> > 
>> > but now the problem is how to exact;y type the Where HOST like "%%%"
>> > 
>> > I MEAN HOW TO DIFFERENTIATE '%S' FROM LITERAL '%' character.
>> 
>> 
>> as a quick thought (untested) it is probably best to have %s as your
>> parameter for the Like clause & ad the sql wild-cards (% symbols) to
>> the data you pass in as I think the expansion of %s adds quote marks
>> which will certainly cause the sql parser issues.
> 
> How do you propose writing that cur.execute statement Alister?


cur.execute('''UPDATE visitors SET (pagesID, host, ref, location,
>> > useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE
>> > host LIKE %s '''

but you will need to amend the data  you pass so that the last element 
has the surrounding % characters .


-- 
T-1's congested due to porn traffic to the news server.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Νίκος Βέργος
Τη Κυριακή, 26 Μαρτίου 2017 - 8:06:07 μ.μ. UTC+3, ο χρήστης INADA Naoki έγραψε:
> Read my mail again.
> 
> > This error came from MySQL.  If there are no logs in error_log, it's
> > your configuration issue.
> 
> > See https://dev.mysql.com/doc/refman/5.7/en/update.html for Update
> > statement syntax.

I cannot understand where the error is.
Could you how it to me please?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Νίκος Βέργος
I do not see why my UPDATE fails.

cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros,
browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s)''') works

i dont have to update table set column1 = this value, column2=that value
and so on

It's just when the LIKE clause jumps in that is causing all this trouble

How would you write it?!

Στις Κυρ, 26 Μαρ 2017 στις 8:05 μ.μ., ο/η INADA Naoki <
songofaca...@gmail.com> έγραψε:

> Read my mail again.
>
> > This error came from MySQL.  If there are no logs in error_log, it's
> > your configuration issue.
>
> > See https://dev.mysql.com/doc/refman/5.7/en/update.html for Update
> > statement syntax.
>
-- 
What is now proved was at first only imagined!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread INADA Naoki
Read my mail again.

> This error came from MySQL.  If there are no logs in error_log, it's
> your configuration issue.

> See https://dev.mysql.com/doc/refman/5.7/en/update.html for Update
> statement syntax.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Νίκος Βέργος
Any ideas on how to make progress on that?

After all its just an UPDATE with a WHERE clause?!
Do you also think is DBI related issue?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Joel Goldstick
On Sun, Mar 26, 2017 at 11:48 AM, Νίκος Βέργος  wrote:
> Τη Κυριακή, 26 Μαρτίου 2017 - 6:39:01 μ.μ. UTC+3, ο χρήστης Steve D'Aprano 
> έγραψε:
>> On Mon, 27 Mar 2017 02:11 am, Νίκος Βέργος wrote:
>>
>> > I just tried:
>> >
>> > domain = '.'.join( host.split('.')[-2:] )
>> > domain = '%' + domain + '%'
>> >
>> > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros,
>> > browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s"
>> > ''', (pID, domain, ref, location, useros, browser, lastvisit, domain) )
>> >
>> > and i received no error in the error_log but
>> > ProgrammingError(1064, "You have an error in your SQL syntax; check the
>> > manual that corresponds to your MariaDB server version for the right
>> > syntax to use near '(pagesID, host, ref, location, useros, browser,
>> > visits) VALUES (1, '%cyta.gr%', ' at line 1")
>>
>> Start by following the instructions given:
>>
>> check the manual that corresponds to your MariaDB server version
>> for the right syntax to use
>>
>> just like the error message tells you to do.
>>
>> Are you sure that the domain needs to have leading and trailing percentage
>> signs? "%cyta.gr%" instead of "cyta.gr"?
>>
>> Are you sure that the LIKE clause needs double quotes?
>>
>> LIKE "%s"
>>
>> Perhaps MariaDB requires single quotes:
>>
>> LIKE '%s'
>>
>> or perhaps no quotes at all:
>>
>> LIKE %s
>>
>>
>> But I'm just guessing, because I haven't read the MariaDB manual. You should
>> do so.
>>
>>
>> > which you can see at http://superhost.gr
>>
>> Ah, Nikos, its been a long time! I thought I recognised your style of
>> posting.

Not long enough!
>
>
> Howdy Steve!
> Yes its me and yes its have been a long time! How are you?!
>
> Yeap still trying to make my webiste better and better every day.
>
> As for MariaDB i tried with single/double/no_quoting at all and it still 
> produces
> ProgrammingError(1064, "You have an error in your SQL syntax; check the 
> manual that corresponds to your MariaDB server version for the right syntax 
> to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES 
> (1, 'cyta.gr', '' at line 1")
>
> I think that Ian Kelly is right and it has soemthign to do with the databse 
> wrapper not substituting properly the actual string contain in the LIKE 
> clause between the double quotes.
>
> Perhaps i need to change pymysql with some other database interface or there 
> is something other than that?
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Νίκος Βέργος
Currently to avoid any misinformations my code looks as follows:

domain = '.'.join( host.split('.')[-2:] )
domain_query = '%%%s' % domain

cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, 
browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE %s''', 
(pID, domain, ref, location, useros, browser, lastvisit, domain_query) )

which as i saiddisplays no error in the error_log output just the 

ProgrammingError(1064, "You have an error in your SQL syntax; check the manual 
that corresponds to your MariaDB server version for the right syntax to use 
near '(pagesID, host, ref, location, useros, browser, visits) VALUES (1, 
'cyta.gr', '' at line 1")

and i'am totally stuck.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Chris Angelico
On Mon, Mar 27, 2017 at 2:48 AM, Νίκος Βέργος  wrote:
>> > which you can see at http://superhost.gr
>>
>> Ah, Nikos, its been a long time! I thought I recognised your style of
>> posting.
>
>
> Howdy Steve!
> Yes its me and yes its have been a long time! How are you?!
>

Irony lost.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Νίκος Βέργος
Τη Κυριακή, 26 Μαρτίου 2017 - 6:39:01 μ.μ. UTC+3, ο χρήστης Steve D'Aprano 
έγραψε:
> On Mon, 27 Mar 2017 02:11 am, Νίκος Βέργος wrote:
> 
> > I just tried:
> > 
> > domain = '.'.join( host.split('.')[-2:] )
> > domain = '%' + domain + '%'
> > 
> > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros,
> > browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s"
> > ''', (pID, domain, ref, location, useros, browser, lastvisit, domain) )
> > 
> > and i received no error in the error_log but
> > ProgrammingError(1064, "You have an error in your SQL syntax; check the
> > manual that corresponds to your MariaDB server version for the right
> > syntax to use near '(pagesID, host, ref, location, useros, browser,
> > visits) VALUES (1, '%cyta.gr%', ' at line 1")
> 
> Start by following the instructions given:
> 
> check the manual that corresponds to your MariaDB server version 
> for the right syntax to use
> 
> just like the error message tells you to do.
> 
> Are you sure that the domain needs to have leading and trailing percentage
> signs? "%cyta.gr%" instead of "cyta.gr"?
> 
> Are you sure that the LIKE clause needs double quotes?
> 
> LIKE "%s"
> 
> Perhaps MariaDB requires single quotes:
> 
> LIKE '%s'
> 
> or perhaps no quotes at all:
> 
> LIKE %s
> 
> 
> But I'm just guessing, because I haven't read the MariaDB manual. You should
> do so.
> 
> 
> > which you can see at http://superhost.gr
> 
> Ah, Nikos, its been a long time! I thought I recognised your style of
> posting.


Howdy Steve!
Yes its me and yes its have been a long time! How are you?!

Yeap still trying to make my webiste better and better every day.

As for MariaDB i tried with single/double/no_quoting at all and it still 
produces 
ProgrammingError(1064, "You have an error in your SQL syntax; check the manual 
that corresponds to your MariaDB server version for the right syntax to use 
near '(pagesID, host, ref, location, useros, browser, visits) VALUES (1, 
'cyta.gr', '' at line 1")

I think that Ian Kelly is right and it has soemthign to do with the databse 
wrapper not substituting properly the actual string contain in the LIKE clause 
between the double quotes.

Perhaps i need to change pymysql with some other database interface or there is 
something other than that?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Νίκος Βέργος
Τη Κυριακή, 26 Μαρτίου 2017 - 6:28:12 μ.μ. UTC+3, ο χρήστης Chris Angelico 
έγραψε:
> On Mon, Mar 27, 2017 at 2:11 AM, Νίκος Βέργος  wrote:
> > Τη Κυριακή, 26 Μαρτίου 2017 - 5:49:00 μ.μ. UTC+3, ο χρήστης Ian έγραψε:
> >
> >> The database wrapper won't do substitution into the middle of a string
> >> like that. Either concatenate the literal %'s on in the SQL statement
> >> or add them to the string before you pass it in, i.e. '%' + domain +
> >> '%' or '%%%s%%' % domain or '%{}%'.format(domain).
> >
> > I just tried:
> >
> > domain = '.'.join( host.split('.')[-2:] )
> > domain = '%' + domain + '%'
> >
> > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, 
> > browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s" 
> > ''',
> > 
> > 
> > 
> > (pID, domain, ref, 
> > location, useros, browser, lastvisit, domain) )
> >
> >
> > and i received no error in the error_log but
> > ProgrammingError(1064, "You have an error in your SQL syntax; check the 
> > manual that corresponds to your MariaDB server version for the right syntax 
> > to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES 
> > (1, '%cyta.gr%', ' at line 1")
> >
> > which you can see at http://superhost.gr
> >
> > You said somethign about concatenating the literal % in the SQL to which i 
> > didnt actually i understand how to implement.
> 
> Stop panicking.
> 
> Stop just trying one thing very quickly, getting an error message, and
> firing a post back to this list.
> 
> Slow down and read the messages you are getting.
> 
> You have already been told about UPDATE queries not using this syntax,
> and the error message is referring to that. You have an error in your
> SQL syntax; **check the manual**.

> This is the same problem that you had the last time you were here on
> this list - you had a different email address then, and I can't
> remember what name you were going by, but I won't quickly forget
> superhost.gr, which at the moment looks like Geocities found a new
> domain name.
> 
> ChrisA

I'am reading all the answers and trying everything mentioned.

As for the SQL syntax i dont see where the error is.
I use many UPDATE statements within my scripts in exactyly the same why i have 
been showing them to you.
The only UPDATE is failing is this one with the LIKE clause.

I think that Ian's is correct saying that the substitution is ain't done as we 
intend form the database wrapper which is PyMYSQL.

And last but not least it would be nice if you actually made a contributing 
comment regarding to my questions(which bothers me 3 days in a row by now) 
instead of making ironic remarks related to how my website looks like 
aesthitically to you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Steve D'Aprano
On Mon, 27 Mar 2017 02:11 am, Νίκος Βέργος wrote:

> I just tried:
> 
> domain = '.'.join( host.split('.')[-2:] )
> domain = '%' + domain + '%'
> 
> cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros,
> browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s"
> ''', (pID, domain, ref, location, useros, browser, lastvisit, domain) )
> 
> and i received no error in the error_log but
> ProgrammingError(1064, "You have an error in your SQL syntax; check the
> manual that corresponds to your MariaDB server version for the right
> syntax to use near '(pagesID, host, ref, location, useros, browser,
> visits) VALUES (1, '%cyta.gr%', ' at line 1")

Start by following the instructions given:

check the manual that corresponds to your MariaDB server version 
for the right syntax to use

just like the error message tells you to do.

Are you sure that the domain needs to have leading and trailing percentage
signs? "%cyta.gr%" instead of "cyta.gr"?

Are you sure that the LIKE clause needs double quotes?

LIKE "%s"

Perhaps MariaDB requires single quotes:

LIKE '%s'

or perhaps no quotes at all:

LIKE %s


But I'm just guessing, because I haven't read the MariaDB manual. You should
do so.


> which you can see at http://superhost.gr

Ah, Nikos, its been a long time! I thought I recognised your style of
posting.




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Chris Angelico
On Mon, Mar 27, 2017 at 2:11 AM, Νίκος Βέργος  wrote:
> Τη Κυριακή, 26 Μαρτίου 2017 - 5:49:00 μ.μ. UTC+3, ο χρήστης Ian έγραψε:
>
>> The database wrapper won't do substitution into the middle of a string
>> like that. Either concatenate the literal %'s on in the SQL statement
>> or add them to the string before you pass it in, i.e. '%' + domain +
>> '%' or '%%%s%%' % domain or '%{}%'.format(domain).
>
> I just tried:
>
> domain = '.'.join( host.split('.')[-2:] )
> domain = '%' + domain + '%'
>
> cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, 
> browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s" ''',
>   
>   
>   
>   (pID, domain, ref, location, 
> useros, browser, lastvisit, domain) )
>
>
> and i received no error in the error_log but
> ProgrammingError(1064, "You have an error in your SQL syntax; check the 
> manual that corresponds to your MariaDB server version for the right syntax 
> to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES 
> (1, '%cyta.gr%', ' at line 1")
>
> which you can see at http://superhost.gr
>
> You said somethign about concatenating the literal % in the SQL to which i 
> didnt actually i understand how to implement.

Stop panicking.

Stop just trying one thing very quickly, getting an error message, and
firing a post back to this list.

Slow down and read the messages you are getting.

You have already been told about UPDATE queries not using this syntax,
and the error message is referring to that. You have an error in your
SQL syntax; **check the manual**.

This is the same problem that you had the last time you were here on
this list - you had a different email address then, and I can't
remember what name you were going by, but I won't quickly forget
superhost.gr, which at the moment looks like Geocities found a new
domain name.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Νίκος Βέργος
domain = '.'.join( host.split('.')[-2:] )

domain = '%' + domain + '%' 
domain = '%%%s%%' % domain 
domain = '%{}%'.format(domain)

cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, 
browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s" ''', 



(pID, domain, ref, location, useros, 
browser, lastvisit, domain) )

i just tried both of these 3 ways and the database wrapper failed on all of 
them respectively.

they gave no error_log output though just the usual
ProgrammingError(1064, .)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Νίκος Βέργος
Τη Κυριακή, 26 Μαρτίου 2017 - 5:49:00 μ.μ. UTC+3, ο χρήστης Ian έγραψε:

> The database wrapper won't do substitution into the middle of a string
> like that. Either concatenate the literal %'s on in the SQL statement
> or add them to the string before you pass it in, i.e. '%' + domain +
> '%' or '%%%s%%' % domain or '%{}%'.format(domain).

I just tried:

domain = '.'.join( host.split('.')[-2:] )
domain = '%' + domain + '%'

cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, 
browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s" ''', 



(pID, domain, ref, location, useros, 
browser, lastvisit, domain) )


and i received no error in the error_log but
ProgrammingError(1064, "You have an error in your SQL syntax; check the manual 
that corresponds to your MariaDB server version for the right syntax to use 
near '(pagesID, host, ref, location, useros, browser, visits) VALUES (1, 
'%cyta.gr%', ' at line 1")

which you can see at http://superhost.gr

You said somethign about concatenating the literal % in the SQL to which i 
didnt actually i understand how to implement.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Ian Kelly
On Sun, Mar 26, 2017 at 8:24 AM, Νίκος Βέργος  wrote:
> Τη Κυριακή, 26 Μαρτίου 2017 - 5:19:27 μ.μ. UTC+3, ο χρήστης Ian έγραψε:
>
>> You need to change the placeholders back. The poster who told you to
>> replace them was misinformed.
>
> okey altered them back to
>
> cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, 
> browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%%s%" 
> ''',
>   
>   
>   
>   (pID, domain, ref, location, 
> useros, browser, lastvisit, domain) )
>
> but now the problem is how to exact;y type the Where HOST like "%%%"
>
> I MEAN HOW TO DIFFERENTIATE '%S' FROM LITERAL '%' character.

The database wrapper won't do substitution into the middle of a string
like that. Either concatenate the literal %'s on in the SQL statement
or add them to the string before you pass it in, i.e. '%' + domain +
'%' or '%%%s%%' % domain or '%{}%'.format(domain).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Νίκος Βέργος
I see thank you for pointing that out.

Now i'm receiving no error in error_log but when i'm running the script

it displays this:

ProgrammingError(1064, "You have an error in your SQL syntax; check the
manual that corresponds to your MariaDB server version for the right syntax
to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES
(1, 'cyta.gr', '' at line 1")

How to test this further?

Στις Κυρ, 26 Μαρ 2017 στις 5:38 μ.μ., ο/η INADA Naoki <
songofaca...@gmail.com> έγραψε:

> I used space only for readability.  It's not required.
>
> >>> '%%%s%%' % (42,)
> '%42%'
>
> On Sun, Mar 26, 2017 at 11:35 PM, Νίκος Βέργος 
> wrote:
> > i have tried that 2 days ago.
> >
> > Problem is that you maintained space before and after '%s'  which wont
> work
> > within like
> >
> > How would you type it without space as in "%%s%" ?
> >
> > Στις Κυρ, 26 Μαρ 2017 στις 5:32 μ.μ., ο/η INADA Naoki
> >  έγραψε:
> >>
> >> > I MEAN HOW TO DIFFERENTIATE '%S' FROM LITERAL '%' character.
> >> >
> >>
> >> >>> '%% %s %%s' % (42,)
> >> '% 42 %s'
> >>
> >> Use %%
> >
> > --
> > What is now proved was at first only imagined!
>
-- 
What is now proved was at first only imagined!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Steve D'Aprano
On Mon, 27 Mar 2017 12:52 am, Νίκος Βέργος wrote:

> cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros,
> browser, visits) VALUES ({}, {}, {}, {}, {}, {}, {}) WHERE host LIKE
> "{}"'''.format(pID, domain, ref, location, useros, browser, lastvisit,
> domain) )
> 
> Same kind of output in the error-log even with this attempt.


Don't do that! Even if you fix the SQL errors, this is vulnerable to code
injection attacks. If the caller can fool you into using a specially-made
string for any of those parameters (pID, domain, ref, ...) they can execute
any SQL code they like, without your knowledge.

https://xkcd.com/327/

http://www.explainxkcd.com/wiki/index.php/Little_Bobby_Tables


See also:

http://bobby-tables.com/



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Νίκος Βέργος
i have tried that 2 days ago.

Problem is that you maintained space before and after '%s'  which wont work
within like

How would you type it without space as in "%%s%" ?

Στις Κυρ, 26 Μαρ 2017 στις 5:32 μ.μ., ο/η INADA Naoki <
songofaca...@gmail.com> έγραψε:

> > I MEAN HOW TO DIFFERENTIATE '%S' FROM LITERAL '%' character.
> >
>
> >>> '%% %s %%s' % (42,)
> '% 42 %s'
>
> Use %%
>
-- 
What is now proved was at first only imagined!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Steve D'Aprano
On Mon, 27 Mar 2017 01:24 am, Νίκος Βέργος wrote:


> I MEAN HOW TO DIFFERENTIATE '%S' FROM LITERAL '%' character.

Use %% for a literal percent character.


py> '%s %% %s' % ('hello', 'world')
'hello % world'



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Νίκος Βέργος
Τη Κυριακή, 26 Μαρτίου 2017 - 5:38:57 μ.μ. UTC+3, ο χρήστης alister έγραψε:
> On Sun, 26 Mar 2017 07:24:49 -0700, Νίκος Βέργος wrote:
> 
> > Τη Κυριακή, 26 Μαρτίου 2017 - 5:19:27 μ.μ. UTC+3, ο χρήστης Ian έγραψε:
> > 
> >> You need to change the placeholders back. The poster who told you to
> >> replace them was misinformed.
> > 
> > okey altered them back to
> > 
> > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location,
> > useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host
> > LIKE "%%s%" ''',
> > 
>   
>   
>   
> 
> (pID, domain, ref, location, useros,
> > 
>   
>   
>   
> 
> browser, lastvisit, domain) )
> > 
> > but now the problem is how to exact;y type the Where HOST like "%%%"
> > 
> > I MEAN HOW TO DIFFERENTIATE '%S' FROM LITERAL '%' character.
> 
> 
> as a quick thought (untested) it is probably best to have %s as your 
> parameter for the Like clause & ad the sql wild-cards (% symbols) to the 
> data you pass in as I think the expansion of %s adds quote marks which 
> will certainly cause the sql parser issues.

How do you propose writing that cur.execute statement Alister?

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread alister
On Sun, 26 Mar 2017 07:24:49 -0700, Νίκος Βέργος wrote:

> Τη Κυριακή, 26 Μαρτίου 2017 - 5:19:27 μ.μ. UTC+3, ο χρήστης Ian έγραψε:
> 
>> You need to change the placeholders back. The poster who told you to
>> replace them was misinformed.
> 
> okey altered them back to
> 
> cur.execute('''UPDATE visitors SET (pagesID, host, ref, location,
> useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host
> LIKE "%%s%" ''',
> 




(pID, domain, ref, location, useros,
> 




browser, lastvisit, domain) )
> 
> but now the problem is how to exact;y type the Where HOST like "%%%"
> 
> I MEAN HOW TO DIFFERENTIATE '%S' FROM LITERAL '%' character.


as a quick thought (untested) it is probably best to have %s as your 
parameter for the Like clause & ad the sql wild-cards (% symbols) to the 
data you pass in as I think the expansion of %s adds quote marks which 
will certainly cause the sql parser issues.
  


-- 
'Charity ain't giving people what you wants to give, it's giving people 
what they need to get.'
(Hogfather)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread INADA Naoki
I used space only for readability.  It's not required.

>>> '%%%s%%' % (42,)
'%42%'

On Sun, Mar 26, 2017 at 11:35 PM, Νίκος Βέργος  wrote:
> i have tried that 2 days ago.
>
> Problem is that you maintained space before and after '%s'  which wont work
> within like
>
> How would you type it without space as in "%%s%" ?
>
> Στις Κυρ, 26 Μαρ 2017 στις 5:32 μ.μ., ο/η INADA Naoki
>  έγραψε:
>>
>> > I MEAN HOW TO DIFFERENTIATE '%S' FROM LITERAL '%' character.
>> >
>>
>> >>> '%% %s %%s' % (42,)
>> '% 42 %s'
>>
>> Use %%
>
> --
> What is now proved was at first only imagined!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread INADA Naoki
> I MEAN HOW TO DIFFERENTIATE '%S' FROM LITERAL '%' character.
>

>>> '%% %s %%s' % (42,)
'% 42 %s'

Use %%
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Νίκος Βέργος
Τη Κυριακή, 26 Μαρτίου 2017 - 5:19:27 μ.μ. UTC+3, ο χρήστης Ian έγραψε:

> You need to change the placeholders back. The poster who told you to
> replace them was misinformed.

okey altered them back to

cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, 
browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%%s%" 
''', 



(pID, domain, ref, location, useros, 
browser, lastvisit, domain) )

but now the problem is how to exact;y type the Where HOST like "%%%"

I MEAN HOW TO DIFFERENTIATE '%S' FROM LITERAL '%' character.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Ian Kelly
On Sun, Mar 26, 2017 at 8:07 AM, Νίκος Βέργος  wrote:
> Τη Κυριακή, 26 Μαρτίου 2017 - 5:04:27 μ.μ. UTC+3, ο χρήστης INADA Naoki This 
> error came from MySQL.  If there are no logs in error_log, it's
>> your configuration issue.
>>
>> See https://dev.mysql.com/doc/refman/5.7/en/update.html for Update
>> statement syntax.
>
> cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, 
> browser, visits) VALUES ({}, {}, {}, {}, {}, {}, {}) WHERE host LIKE 
> "%{}%"'''.format(pID, domain, ref, location, useros, browser, lastvisit, 
> domain) )
>
> output of error-log:

You need to change the placeholders back. The poster who told you to
replace them was misinformed.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Ian Kelly
On Sun, Mar 26, 2017 at 7:39 AM, MeV  wrote:
> On Sunday, March 26, 2017 at 6:34:30 AM UTC-7, Νίκος Βέργος wrote:
>> with import cgitb; cgitb.enable()
>>
>> ProgrammingError(1064, "You have an error in your SQL syntax; check the 
>> manual that corresponds to your MariaDB server version for the right syntax 
>> to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES 
>> (1, 'cyta.gr', '' at line 1")
>>
>> that is all i get form error. error_log doesnt produce errors when iam trying
>>
>> cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, 
>> browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE %s''',
>>  
>>  
>>  
>>(pID, domain, ref, location, 
>> useros, browser, lastvisit, domain) )
>>
>> WHY the valued aren't getting substituted wi the aeguments i give it in to 
>> work with?
>
> The % construct is Python 2 and no longer supported in Python 3. You should 
> read up on the "{}" and format method.
>
> https://docs.python.org/3/tutorial/inputoutput.html#fancier-output-formatting

Rubbish, it works just fine in Python 3:

Python 3.6.0 (default, Jan  1 2017, 22:51:19)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> '%s %s' % ('Hello', 'world')
'Hello world'

And contrary to popular belief, it's not even deprecated (although use
of the newer format method is encouraged). What's more, in this case
it's part of the PEP 249 DBAPI specification:
https://www.python.org/dev/peps/pep-0249/#paramstyle. As far as I know
pymysql and DBAPI libraries in general don't even accept "{}".
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Νίκος Βέργος
Τη Κυριακή, 26 Μαρτίου 2017 - 5:04:27 μ.μ. UTC+3, ο χρήστης INADA Naoki This 
error came from MySQL.  If there are no logs in error_log, it's
> your configuration issue.
> 
> See https://dev.mysql.com/doc/refman/5.7/en/update.html for Update
> statement syntax.

cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, 
browser, visits) VALUES ({}, {}, {}, {}, {}, {}, {}) WHERE host LIKE 
"%{}%"'''.format(pID, domain, ref, location, useros, browser, lastvisit, 
domain) ) 

output of error-log:

[code] 
[Sun Mar 26 16:45:50.940077 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215: Error in sys.excepthook: 
[Sun Mar 26 16:45:50.940126 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215: Traceback (most recent call last): 
[Sun Mar 26 16:45:50.940151 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215:   File "/usr/local/lib/python3.5/cgitb.py", line 
268, in __call__ 
[Sun Mar 26 16:45:50.940166 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215: self.handle((etype, evalue, etb)) 
[Sun Mar 26 16:45:50.940189 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215:   File "/usr/local/lib/python3.5/cgitb.py", line 
273, in handle 
[Sun Mar 26 16:45:50.940200 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215: self.file.write(reset()) 
[Sun Mar 26 16:45:50.940220 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215: ValueError: underlying buffer has been detached 
[Sun Mar 26 16:45:50.940225 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215: 
[Sun Mar 26 16:45:50.940235 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215: Original exception was: 
[Sun Mar 26 16:45:50.940249 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215: Traceback (most recent call last): 
[Sun Mar 26 16:45:50.940265 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215:   File "metrites.py", line 355, in  
[Sun Mar 26 16:45:50.940298 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215: (pID, domain, ref, location, useros, 
browser, lastvisit, domain) ) 
[Sun Mar 26 16:45:50.940329 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215:   File 
"/usr/local/lib/python3.5/site-packages/pymysql/cursors.py", line 144, in 
execute 
[Sun Mar 26 16:45:50.940343 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215: query = self.mogrify(query, args) 
[Sun Mar 26 16:45:50.940379 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215:   File 
"/usr/local/lib/python3.5/site-packages/pymysql/cursors.py", line 135, in 
mogrify 
[Sun Mar 26 16:45:50.940398 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215: query = query % self._escape_args(args, 
conn) 
[Sun Mar 26 16:45:50.940420 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215: TypeError: not all arguments converted during 
string formatting 
[/code]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Frank Millman
"Νίκος Βέργος"  wrote in message 
news:8c5f0443-c61b-4059-8d6f-576152d59...@googlegroups.com...




cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, 
browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE 
%s''',

(pID, domain, ref, location, useros, browser, lastvisit, domain) )

As if i have a syntactical error in someplace which i'am faling to see or 
PyMySQL wants special treatment regarding escaping special characters.




I don't know MySQL, but for most RDBMS's, the construction you show only 
works for INSERT statements.


For UPDATE, you usually have to say -
   UPDATE {table} SET col_1 = val_1, col_2 = val_2 WHERE col_3 = val_3 ...

Frank Millman


--
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread INADA Naoki
On Sun, Mar 26, 2017 at 10:34 PM, Νίκος Βέργος  wrote:
> with import cgitb; cgitb.enable()
>
> ProgrammingError(1064, "You have an error in your SQL syntax; check the 
> manual that corresponds to your MariaDB server version for the right syntax 
> to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES 
> (1, 'cyta.gr', '' at line 1")
>
> that is all i get form error. error_log doesnt produce errors when iam trying
>

This error came from MySQL.  If there are no logs in error_log, it's
your configuration issue.

See https://dev.mysql.com/doc/refman/5.7/en/update.html for Update
statement syntax.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Νίκος Βέργος
cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, 
browser, visits) VALUES ({}, {}, {}, {}, {}, {}, {}) WHERE host LIKE 
"{}"'''.format(pID, domain, ref, location, useros, browser, lastvisit, domain) )

Same kind of output in the error-log even with this attempt.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Νίκος Βέργος
Τη Κυριακή, 26 Μαρτίου 2017 - 4:39:44 μ.μ. UTC+3, ο χρήστης MeV έγραψε:
> On Sunday, March 26, 2017 at 6:34:30 AM UTC-7, Νίκος Βέργος wrote:
> > with import cgitb; cgitb.enable()
> > 
> > ProgrammingError(1064, "You have an error in your SQL syntax; check the 
> > manual that corresponds to your MariaDB server version for the right syntax 
> > to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES 
> > (1, 'cyta.gr', '' at line 1")
> > 
> > that is all i get form error. error_log doesnt produce errors when iam 
> > trying
> > 
> > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, 
> > browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE %s''', 
> > 
> > 
> > 
> > (pID, domain, ref, 
> > location, useros, browser, lastvisit, domain) )
> > 
> > WHY the valued aren't getting substituted wi the aeguments i give it in to 
> > work with?
> 
> The % construct is Python 2 and no longer supported in Python 3. You should 
> read up on the "{}" and format method.
> 
> https://docs.python.org/3/tutorial/inputoutput.html#fancier-output-formatting

[code]
cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, 
browser, visits) VALUES ({}, {}, {}, {}, {}, {}, {}) WHERE host LIKE "{}"''', 



(pID, domain, ref, location, useros, 
browser, lastvisit, domain) )
[/code]

now has the following response inside error_log

[code]
[Sun Mar 26 16:45:50.940077 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215: Error in sys.excepthook:
[Sun Mar 26 16:45:50.940126 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215: Traceback (most recent call last):
[Sun Mar 26 16:45:50.940151 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215:   File "/usr/local/lib/python3.5/cgitb.py", line 
268, in __call__
[Sun Mar 26 16:45:50.940166 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215: self.handle((etype, evalue, etb))
[Sun Mar 26 16:45:50.940189 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215:   File "/usr/local/lib/python3.5/cgitb.py", line 
273, in handle
[Sun Mar 26 16:45:50.940200 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215: self.file.write(reset())
[Sun Mar 26 16:45:50.940220 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215: ValueError: underlying buffer has been detached
[Sun Mar 26 16:45:50.940225 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215: 
[Sun Mar 26 16:45:50.940235 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215: Original exception was:
[Sun Mar 26 16:45:50.940249 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215: Traceback (most recent call last):
[Sun Mar 26 16:45:50.940265 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215:   File "metrites.py", line 355, in 
[Sun Mar 26 16:45:50.940298 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215: (pID, domain, ref, location, useros, 
browser, lastvisit, domain) )
[Sun Mar 26 16:45:50.940329 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215:   File 
"/usr/local/lib/python3.5/site-packages/pymysql/cursors.py", line 144, in 
execute
[Sun Mar 26 16:45:50.940343 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215: query = self.mogrify(query, args)
[Sun Mar 26 16:45:50.940379 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215:   File 
"/usr/local/lib/python3.5/site-packages/pymysql/cursors.py", line 135, in 
mogrify
[Sun Mar 26 16:45:50.940398 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215: query = query % self._escape_args(args, conn)
[Sun Mar 26 16:45:50.940420 2017] [cgi:error] [pid 2337] [client 
178.59.182.161:13755] AH01215: TypeError: not all arguments converted during 
string formatting
[/code]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Νίκος Βέργος
Τη Κυριακή, 26 Μαρτίου 2017 - 4:39:44 μ.μ. UTC+3, ο χρήστης MeV έγραψε:
> On Sunday, March 26, 2017 at 6:34:30 AM UTC-7, Νίκος Βέργος wrote:
> > with import cgitb; cgitb.enable()
> > 
> > ProgrammingError(1064, "You have an error in your SQL syntax; check the 
> > manual that corresponds to your MariaDB server version for the right syntax 
> > to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES 
> > (1, 'cyta.gr', '' at line 1")
> > 
> > that is all i get form error. error_log doesnt produce errors when iam 
> > trying
> > 
> > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, 
> > browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE %s''', 
> > 
> > 
> > 
> > (pID, domain, ref, 
> > location, useros, browser, lastvisit, domain) )
> > 
> > WHY the valued aren't getting substituted wi the aeguments i give it in to 
> > work with?
> 
> The % construct is Python 2 and no longer supported in Python 3. You should 
> read up on the "{}" and format method.
> 
> https://docs.python.org/3/tutorial/inputoutput.html#fancier-output-formatting

Even with '{}' instead of '%s' iam still receiving similar errors.
And lathough iam using '%s' up until now substituting worked okey.

its htis where LIKE clause that is only failing.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Νίκος Βέργος
Ths is the whole snippert i'am trying so you can see what i'm tryong to do.

[code]
# if bot is contained in hostname update all previous database 
bot hostname entries with current bot hostname
for bot in bots:
if bot in host:
domain = '.'.join( host.split('.')[-2:] )

cur.execute('''UPDATE visitors SET (pagesID, 
host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, 
%s) WHERE host LIKE %s''', 



(pID, domain, ref, location, useros, 
browser, lastvisit, domain) )
if cur.rowcount():
botfound = True
break
[/code]

As if i have a syntactical error in someplace which i'am faling to see or 
PyMySQL wants special treatment regarding escaping special characters.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread MeV
On Sunday, March 26, 2017 at 6:34:30 AM UTC-7, Νίκος Βέργος wrote:
> with import cgitb; cgitb.enable()
> 
> ProgrammingError(1064, "You have an error in your SQL syntax; check the 
> manual that corresponds to your MariaDB server version for the right syntax 
> to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES 
> (1, 'cyta.gr', '' at line 1")
> 
> that is all i get form error. error_log doesnt produce errors when iam trying
> 
> cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, 
> browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE %s''', 
>   
>   
>   
> (pID, domain, ref, location, 
> useros, browser, lastvisit, domain) )
> 
> WHY the valued aren't getting substituted wi the aeguments i give it in to 
> work with?

The % construct is Python 2 and no longer supported in Python 3. You should 
read up on the "{}" and format method.

https://docs.python.org/3/tutorial/inputoutput.html#fancier-output-formatting
-- 
https://mail.python.org/mailman/listinfo/python-list


  1   2   3   4   5   >