[issue41945] http.cookies.SimpleCookie.parse error after [keys] or some JSON data values

2022-01-04 Thread Jan Novak


Jan Novak  added the comment:

New examples with the structured data.

Problems are with quotes and spaces inside { or [

cookie-script.com set those cookie data:
CookieScriptConsent={"action":"accept","categories":"[\\"performance\\"]"}

Python loads only cookies before that JSON structure

>>> from http.cookies import SimpleCookie
>>> ck = SimpleCookie()
>>> ck.load('id=12345; 
>>> CookieScriptConsent={"action":"accept","categories":"[\\"performance\\"]"}; 
>>> something="not loaded"')
>>> print(ck)
Set-Cookie: id=12345

This works:
>>> ck.load('id=12345; complex_data={1:[1,2]}; something="loaded"')
>>> print(ck)
Set-Cookie: complex_data={1:[1,2]}
Set-Cookie: id=12345
Set-Cookie: something="loaded"

This not works:
>>> ck.load('id=12345; complex_data={1:[1, 2]}; something="not loaded"')
>>> print(ck)
Set-Cookie: complex_data={1:[1,
Set-Cookie: id=12345

Conclusion:
Parsing JSON like cookie objects works, except quotes and without spaces. 

Exist some new RFC with JSON data support?
How implementation/support/solution in diferent languages?
Exist another Python library which support cookie with JSON data?

--
title: http.cookies.SimpleCookie.parse error after [keys] -> 
http.cookies.SimpleCookie.parse error after [keys] or some JSON data values
versions: +Python 3.10 -Python 3.7

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



[issue34931] os.path.splitext with more dots

2022-01-03 Thread Jan Novak


Jan Novak  added the comment:

It is interesting that pathlib.Path works fine:

>>> pathlib.Path('jpg').suffix
'.jpg'
>>> pathlib.Path('path/jpg').suffix
'.jpg'

--

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



[issue34931] os.path.splitext with more dots

2022-01-03 Thread Jan Novak


Jan Novak  added the comment:

Thank you all for discussion and partial solution in latest Python versions and 
extending documentation.

For the future development of Python the initial question remains.
How to easy detect extensions for each file with standard python library 
function. Without programing own function to fix it.

Filenames with more dots could exist both in Unix and Windows worlds.
Nobody can't say (for example web app users). Please not use those files.

Python 3.10.1
Works fine:
>>> os.path.splitext('.some.jpg')
('.some', '.jpg')
>>> os.path.splitext('..some.jpg')
('..some', '.jpg')

Not usable:
>>> os.path.splitext('jpg')
('jpg', '')

There are some possible ways:
- new parametr
- new function
- change backward compatibility
- stay buggy forever

Thank you

--
status: closed -> open
versions: +Python 3.10

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



[issue41945] http.cookies.SimpleCookie.parse error after [keys]

2020-11-05 Thread Jan Novak


Jan Novak  added the comment:

Possible patch, load parts one by one:

http_cookie = 'id=12345; [object Object]=data; something=not_loaded'
for cookie_key in http_cookie.split(';'):
  c.load(cookie_key)

print c
Set-Cookie: id=12345
Set-Cookie: something=not_loaded

--

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



[issue41945] http.cookies.SimpleCookie.parse error after [keys]

2020-10-05 Thread Jan Novak


New submission from Jan Novak :

If brackets [] are around cookie name,
next cookie names are not loaded.

try:
  import http.cookies as Cookie
except ImportError:
  import Cookie
c = Cookie.SimpleCookie()
c.load('id=12345; [object Object]=data; something=not loaded')
print(c)

Note:
It could cause big problems with session etc.
We found that Chrome/Edge starts to save and send this type of cookies for some 
(couple) users. The origin of that [object Object]=... cookies are probably 
some implementation of
https://cookiepedia.co.uk/cookies/euconsent
and errors somewhere in external javascripts or browsers?

Related issues:
https://bugs.python.org/issue41695
https://bugs.python.org/issue27674

The same problem occures in P3.7, P2.7, six.moves.http_cookies etc.

I know RFT says that cookie-name can't use brackets.
But you can set them to browser cookies.

RFC 6265:
set-cookie-header = "Set-Cookie:" SP set-cookie-string
 set-cookie-string = cookie-pair *( ";" SP cookie-av )
 cookie-pair   = cookie-name "=" cookie-value
 cookie-name   = token
 token = 

RFC 2616:
token  = 1*
   separators = "(" | ")" | "<" | ">" | "@"
  | "," | ";" | ":" | "\" | <">
  | "/" | "[" | "]" | "?" | "="
  | "{" | "}" | SP | HT

--
components: Library (Lib)
messages: 378041
nosy: xnovakj
priority: normal
severity: normal
status: open
title: http.cookies.SimpleCookie.parse error after [keys]
type: behavior
versions: Python 3.7

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



[issue34931] os.path.splitext with more dots

2018-10-29 Thread Jan Novak


Jan Novak  added the comment:

Yes, dot behaviour is well documented.

But splitext() is a function to split name and extension, not take care about 
hidden files.

Hidden files starting with dot is Unix like system feature.
https://en.wikipedia.org/wiki/Hidden_file_and_hidden_directory

Hidden files could have also extension.
Try for example create/rename .somename.jpg file in Ubuntu.
It is normal image with .jpg extension. You could open it etc.

You can't use standard python splitext() function to detect extension.

I know that change this standard python function is probably imposible due to 
backward compatibility. Bud extend it with new parameter could be possible. The 
change in 2007 was unfortunate/incomplete.

--

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



[issue34931] os.path.splitext with more dots

2018-10-08 Thread Jan Novak


New submission from Jan Novak :

There are some old tickets about changing splitext() in 2007:
https://bugs.python.org/issue1115886
https://bugs.python.org/issue1681842

Present python documentation:
Leading periods on the basename are ignored; splitext('.cshrc') returns 
('.cshrc', '').
Changed in version 2.6: Earlier versions could produce an empty root when the 
only period was the first character.

But nobody take care about more than one dots:
For example this possible corect filenames:

>>> os.path.splitext('jpg')
('jpg', '')

So present function is insuficient (buggy) to use to detect right extension.
Maybe new parameter would be helpfull for that?
Like parameter "preserve_dotfiles" discussed in 2007.

And what to do with the wrong '.', '..', '...', ... filenames?

--
messages: 327346
nosy: xnovakj
priority: normal
severity: normal
status: open
title: os.path.splitext with more dots
type: behavior

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



[issue1379416] email.Header encode() unicode P2.6

2009-03-23 Thread Jan Novak

Jan Novak xnov...@users.sourceforge.net added the comment:

I made some new tests in P2.6.1

 import email.charset

 c=email.charset.Charset('utf-8')
 print c.input_charset, type(c.input_charset)
utf-8 type 'unicode'
 print c.output_charset, type(c.output_charset)
utf-8 type 'str'

but

 c=email.charset.Charset('iso-8859-2')
 print c.input_charset, type(c.input_charset)
iso-8859-2 type 'unicode'
 print c.output_charset, type(c.output_charset)
iso-8859-2 type 'unicode'

but if you use alias latin-2 it's OK

 c=email.charset.Charset('latin-2')
 print c.input_charset, type(c.input_charset)
iso-8859-2 type 'str'
 print c.output_charset, type(c.output_charset)
iso-8859-2 type 'str'
 

Error is here for unicode input-charset:
self.input_charset-conv-self.output_charset

module email/charset.py line 219

if not conv:
conv = self.input_charset

for the charsets where aren't output conversions

CHARSETS = {
# inputheader enc  body enc output conv
'iso-8859-1':  (QP,QP,  None),
'iso-8859-2':  (QP,QP,  None),

and if you don't use alias

ALIASES = {
'latin_1': 'iso-8859-1',
'latin-1': 'iso-8859-1',
'latin_2': 'iso-8859-2',
'latin-2': 'iso-8859-2',

But the realy source of this error is on line 208
 input_charset = unicode(input_charset, 'ascii')

because this construction returns unicode

 print type(unicode('iso-8859-2','ascii'))
type 'unicode'

--
title: email.Header encode() unicode P2.3xP2.4 - email.Header encode() unicode 
P2.6

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1379416
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com