symmetries.py 651 B

1234567891011121314151617181920212223242526272829303132
  1. import six
  2. try:
  3. from urllib import urlencode as format_query
  4. except ImportError:
  5. from urllib.parse import urlencode as format_query
  6. try:
  7. from urlparse import urlparse as parse_url
  8. except ImportError:
  9. from urllib.parse import urlparse as parse_url
  10. try:
  11. memoryview = memoryview
  12. except NameError:
  13. memoryview = buffer
  14. def get_character(x, index):
  15. return chr(get_byte(x, index))
  16. def get_byte(x, index):
  17. return six.indexbytes(x, index)
  18. def encode_string(x):
  19. return x.encode('utf-8')
  20. def decode_string(x):
  21. try:
  22. return x.decode('utf-8')
  23. except UnicodeDecodeError:
  24. return x.decode('latin-1')