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