| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# |
| 3 |
# libcaca Colour ASCII-Art library |
| 4 |
# Python language bindings |
| 5 |
# Copyright (c) 2010 Alex Foulon <[email protected]> |
| 6 |
# All Rights Reserved |
| 7 |
# |
| 8 |
# This library is free software. It comes without any warranty, to |
| 9 |
# the extent permitted by applicable law. You can redistribute it |
| 10 |
# and/or modify it under the terms of the Do What the Fuck You Want |
| 11 |
# to Public License, Version 2, as published by Sam Hocevar. See |
| 12 |
# http://www.wtfpl.net/ for more details. |
| 13 |
# |
| 14 |
|
| 15 |
""" Libcaca Python bindings """ |
| 16 |
|
| 17 |
#standard modules |
| 18 |
import locale |
| 19 |
import sys |
| 20 |
import ctypes |
| 21 |
from ctypes.util import find_library |
| 22 |
|
| 23 |
if find_library('caca') is not None: |
| 24 |
_lib = ctypes.cdll.LoadLibrary(find_library('caca')) |
| 25 |
else: |
| 26 |
raise ImportError( |
| 27 |
"Can't find shared library, you need to install libcaca in your path !") |
| 28 |
|
| 29 |
#functions to handle string/bytes in python3+ |
| 30 |
if sys.version_info[0:2] >= (3, 0): |
| 31 |
_PYTHON3 = True |
| 32 |
else: |
| 33 |
_PYTHON3 = False |
| 34 |
|
| 35 |
def _str_to_bytes(the_string): |
| 36 |
""" Translate string to bytes type for python 3. |
| 37 |
""" |
| 38 |
return bytes(the_string, locale.getlocale()[1]) |
| 39 |
|
| 40 |
def _bytes_to_str(the_bytes): |
| 41 |
""" Translate bytes to string type for python 3. |
| 42 |
""" |
| 43 |
return the_bytes.decode(locale.getlocale()[1]) |
| 44 |
|
| 45 |
from .common import * |
| 46 |
|