Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different behaviours with <class str> between v3.1.2 and v3.2.2 #57204

Closed
VinsS mannequin opened this issue Sep 16, 2011 · 2 comments
Closed

Different behaviours with <class str> between v3.1.2 and v3.2.2 #57204

VinsS mannequin opened this issue Sep 16, 2011 · 2 comments

Comments

@VinsS
Copy link
Mannequin

VinsS mannequin commented Sep 16, 2011

BPO 12995
Nosy @benjaminp

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2011-09-16.18:07:33.770>
created_at = <Date 2011-09-16.17:50:13.929>
labels = ['invalid', 'expert-unicode']
title = 'Different behaviours with <class str> between v3.1.2 and v3.2.2'
updated_at = <Date 2011-09-16.18:07:33.763>
user = 'https://bugs.python.org/VinsS'

bugs.python.org fields:

activity = <Date 2011-09-16.18:07:33.763>
actor = 'benjamin.peterson'
assignee = 'none'
closed = True
closed_date = <Date 2011-09-16.18:07:33.770>
closer = 'benjamin.peterson'
components = ['Unicode']
creation = <Date 2011-09-16.17:50:13.929>
creator = 'VinsS'
dependencies = []
files = []
hgrepos = []
issue_num = 12995
keywords = []
message_count = 2.0
messages = ['144143', '144145']
nosy_count = 2.0
nosy_names = ['benjamin.peterson', 'VinsS']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue12995'
versions = []

@VinsS
Copy link
Mannequin Author

VinsS mannequin commented Sep 16, 2011

Hi,

Trying this code:

------------------------------

# -- coding: utf-8 --

import os
import sys
import platform

print('\nPython version: ', sys.version.split()[0])
print(platform.platform())

paths = ['/home/vincent/image.jpg', '/home/vincent/àéèîö.jpg']

for path in paths:
    print('\n', type(path))
    try:
        print(path)
    except UnicodeEncodeError as why:
        print('print > {0}'.format(why))
    try:
        if not os.path.exists(path):
            print('File not found!')
        else:
            print('File exists')
    except UnicodeEncodeError as why:
        print('os.path.exist > {0}'.format(why))
    try:
        stats = os.stat(path)
        print(stats.st_atime)
    except UnicodeEncodeError as why:
        print('os.stat > {0}'.format(why))
    try:
        f = open(path, 'b')
        f.close()
    except Exception as why:
        print('open > {0}'.format(why))

on python 3.1.2:

------------------------------------
vincent@tiemoko:~/Python/oqapy/devel$ python3 test_string.py

Python version: 3.1.2
Linux-2.6.32-33-generic-i686-with-Ubuntu-10.04-lucid

<class 'str'>
/home/vincent/image.jpg
File exists
1316179838.94
open > Must have exactly one of read/write/append mode

<class 'str'>
/home/vincent/àéèîö.jpg
File exists
1316179838.81
open > Must have exactly one of read/write/append mode
vincent@tiemoko:~/Python/oqapy/devel$

------------------------------------------------

on python 3.2.2:

------------------------------------------------
[vincent@myhost ~]$ python test_string.py

Python version: 3.2.2
Linux-3.0-ARCH-x86_64-Pentium-R-Dual-Core_CPU_T4500@_2.30GHz-with-glibc2.2.5
<class 'str'>
/home/vincent/image.jpg
File exists
1316187109.6772401
open > Must have exactly one of read/write/append mode and at most one plus
<class 'str'>
print > 'ascii' codec can't encode characters in position 14-18: ordinal not in range(128)
os.path.exist > 'ascii' codec can't encode characters in position 14-18: ordinal not in range(128)
os.stat > 'ascii' codec can't encode characters in position 14-18: ordinal not in range(128)
open > 'ascii' codec can't encode characters in position 14-18: ordinal not in range(128)
[vincent@myhost ~]$

-------------------------------------------------------------------

Any 'path = path.decode('utf-8')', 'encode(bhla)', 'sys.getfilesystemencoding()', 'magic_transform(abracadabra)'
don't change anythings.

Thanks for yours advice.

vince

@VinsS VinsS mannequin added the topic-unicode label Sep 16, 2011
@benjaminp
Copy link
Contributor

This is because how the filesystem encoding is determined has changed. You probably need to explicity discover how non-ascii characters like those in '/home/vincent/àéèîö.jpg' are encoded in your filesystem.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant