| Conditions | 5 |
| Total Lines | 21 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | # -*- coding: utf-8 -*- |
||
| 8 | def encode_requests_password(word): |
||
| 9 | """ |
||
| 10 | Convert the string to bytes (readable by the server) |
||
| 11 | |||
| 12 | :param word: input string |
||
| 13 | :returns: bytes with appropriate encoding |
||
| 14 | """ |
||
| 15 | if isinstance(word, bytes): |
||
| 16 | return word |
||
| 17 | else: |
||
| 18 | ret = word |
||
| 19 | if six.PY2: |
||
| 20 | if isinstance(word, unicode): |
||
|
|
|||
| 21 | # trick to work with tricks in requests lib |
||
| 22 | ret = word.encode('utf-8').decode('latin-1') |
||
| 23 | else: |
||
| 24 | try: |
||
| 25 | ret = bytes(word, 'ascii') |
||
| 26 | except UnicodeEncodeError: |
||
| 27 | ret = bytes(word, 'utf-8') |
||
| 28 | return ret |
||
| 29 | |||
| 48 |