amitt001 / amitt001/delegator.py

feature_request(encoding): force UTF-8 for Windows users

オープン
#59 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る
question
主要言語
Python
スター
1.7k
フォーク
86
PR マージ指標
30日以内にマージされた PR はありません

説明

### 1. Summary

In my opinion, UTF-8 should be the default encoding for Windows users. If developers of delegator.py don't want to do this, it would be nice to have an option for UTF-8.

### 2. Argumentation

I don't understand, why needs [**these lines**](https://github.com/kennethreitz/delegator.py/blob/master/delegator.py#L80-L83) for Windows users.

```python
if sys.platform == 'win32':
default_encoding = locale.getdefaultlocale()[1]
if default_encoding is not None:
encoding = default_encoding
```

More about `locale.getdefaultlocale()`. I have English Windows and Russian language for non-unicode programs. Python interpreter output:

```python
>>> import locale
>>> locale.getdefaultlocale()
('en_US', 'cp1251')
```

[**I change my language for non-Unicode programs to English (United States)**](https://java.com/en/download/help/locale.xml) as [**recommend in this answer**](https://stackoverflow.com/a/11234956/5951529):

![English default](https://i.imgur.com/yCW2wSz.png)

I restart Windows → I open Python Interpreter again:

```python
>>> import locale
>>> locale.getdefaultlocale()
('en_US', 'cp1252')
```

Not UTF-8 again. The example shows that `locale.getdefaultlocale()` **can't set UTF-8 for Windows**.

### 3. Example

+ `SashaDelegator.py` (in UTF-8):

```python
import delegator

print(delegator.run('echo Саша Богиня!').out)

```

I run in console `python SashaDelegator.py`

### 4. Expected behavior

```text
Саша Богиня!
```

### 5. Actual behavior

```text
???? ??????!
```

[**This hack**](https://stackoverflow.com/a/34345136/5951529) also doesn't help.

```python
import _locale
import delegator

_locale._getdefaultlocale = (lambda *args: ['en_US', 'utf8'])

print(delegator.run('echo Саша Богиня!').out)
```

I get the same output.

And if I use hacks, I have problems with code quality tools.

### 6. Environment

+ Windows 10 Enterprise LTSB 64-bit EN
+ Python 3.7.0
+ delegator.py 0.1.0
+ PYTHONIOENCODING utf-8

Thanks.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。