Skip to content

Commit

Permalink
Merge pull request #12 from enthought/py3_support
Browse files Browse the repository at this point in the history
Py3 support
  • Loading branch information
cournape committed Feb 24, 2014
2 parents c853e5b + e680d62 commit 3456047
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ language: python

python:
- "2.7"
- "3.2"
- "3.3"

before_install:
- sudo add-apt-repository ppa:ubuntu-wine/ppa -y
Expand Down
12 changes: 9 additions & 3 deletions scripts/run_tests_wine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ set -e

export DISPLAY=:99.0

PYTHON="c:/Python27/python.exe"
COVERAGE="c:/Python27/Scripts/coverage.exe"
if [ "${TRAVIS_PYTHON_VERSION}" = "2.7" ]; then
COVERAGE="c:/Python27/Scripts/coverage.exe"
elif [ "${TRAVIS_PYTHON_VERSION}" = "3.2" ]; then
COVERAGE="c:/Python32/Scripts/coverage.exe"
elif [ "${TRAVIS_PYTHON_VERSION}" = "3.3" ]; then
COVERAGE="c:/Python33/Scripts/coverage.exe"
else
exit 1;
fi

wine ${PYTHON} -m nose.core win32ctypes
wine ${COVERAGE} erase
wine ${COVERAGE} run -m nose.core win32ctypes
wine ${COVERAGE} report --include=win32ctypes*
36 changes: 29 additions & 7 deletions scripts/setup_tests_wine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,41 @@ set -e

export DISPLAY=:99.0

PYTHON="c:/Python27/python.exe"
EASY_INSTALL="c:/Python27/Scripts/easy_install.exe"
PIP="c:/Python27/Scripts/pip.exe"
if [ "${TRAVIS_PYTHON_VERSION}" = "2.7" ]; then
PYTHON_MSI="python-2.7.6.msi"
PYTHON_URL="http://www.python.org/ftp/python/2.7.6/${PYTHON_MSI}"
PYTHON="c:/Python27/python.exe"
EASY_INSTALL="c:/Python27/Scripts/easy_install.exe"
PIP="c:/Python27/Scripts/pip.exe"
elif [ "${TRAVIS_PYTHON_VERSION}" = "3.2" ]; then
PYTHON_MSI="python-3.2.5.msi"
PYTHON_URL="http://www.python.org/ftp/python/3.2.5/${PYTHON_MSI}"
PYTHON="c:/Python32/python.exe"
EASY_INSTALL="c:/Python32/Scripts/easy_install.exe"
PIP="c:/Python32/Scripts/pip.exe"
elif [ "${TRAVIS_PYTHON_VERSION}" = "3.3" ]; then
PYTHON_MSI="python-3.3.4.msi"
PYTHON_URL="http://www.python.org/ftp/python/3.3.4/${PYTHON_MSI}"
PYTHON="c:/Python33/python.exe"
EASY_INSTALL="c:/Python33/Scripts/easy_install.exe"
PIP="c:/Python33/Scripts/pip.exe"
else
echo "Python ${TRAVIS_PYTHON_VERSION} not supported."
exit 1;
fi

wget http://www.python.org/ftp/python/2.7.6/python-2.7.6.msi
wine msiexec /i python-2.7.6.msi /qn
PYWIN32_EXE="pywin32-218.win32-py${TRAVIS_PYTHON_VERSION}.exe"
PYWIN32_URL="http://sourceforge.net/projects/pywin32/files/pywin32/Build%20218/pywin32-218.win32-py${TRAVIS_PYTHON_VERSION}.exe/download"

wget ${PYTHON_URL}
wine msiexec /i ${PYTHON_MSI} /qn

wget https://pypi.python.org/packages/source/s/setuptools/setuptools-2.2.tar.gz
tar xf setuptools-2.2.tar.gz
(cd setuptools-2.2 && wine ${PYTHON} setup.py install)

wine ${EASY_INSTALL} nose coverage

wget http://sourceforge.net/projects/pywin32/files/pywin32/Build%20218/pywin32-218.win32-py2.7.exe/download -O pywin32-218.win32-py2.7.exe
wget ${PYWIN32_URL} -O ${PYWIN32_EXE}

wine ${EASY_INSTALL} pywin32-218.win32-py2.7.exe
wine ${EASY_INSTALL} ${PYWIN32_EXE}
12 changes: 9 additions & 3 deletions win32ctypes/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from ctypes import pythonapi, POINTER, c_void_p, py_object
from ctypes.wintypes import BYTE, UINT

from .compat import PY3
from ._util import function_factory

PPy_UNICODE = c_void_p
Expand All @@ -29,9 +30,14 @@

LPBYTE = POINTER(BYTE)

_PyString_FromStringAndSize = function_factory(
pythonapi.PyString_FromStringAndSize,
return_type=py_object)
if PY3:
_PyBytes_FromStringAndSize = function_factory(
pythonapi.PyBytes_FromStringAndSize,
return_type=py_object)
else:
_PyBytes_FromStringAndSize = function_factory(
pythonapi.PyString_FromStringAndSize,
return_type=py_object)

_GetACP = function_factory(
kernel32.GetACP,
Expand Down
4 changes: 2 additions & 2 deletions win32ctypes/_win32cred.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
from __future__ import absolute_import

import ctypes
from ctypes import POINTER, Structure
from ctypes import POINTER, Structure, c_void_p, c_wchar_p
from ctypes.wintypes import (
BOOL, DWORD, FILETIME, c_void_p, c_wchar_p, LPCWSTR)
BOOL, DWORD, FILETIME, LPCWSTR)

from ._common import LPBYTE
from ._util import function_factory, check_zero, check_zero_factory
Expand Down
19 changes: 19 additions & 0 deletions win32ctypes/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sys

if sys.version_info[0] >= 3:
PY3 = True
PY2 = False
else:
PY3 = False
PY2 = True

if PY3:
def is_unicode(s):
return isinstance(s, str)

unicode = str
else:
def is_unicode(s):
return isinstance(s, unicode)

unicode = unicode
2 changes: 1 addition & 1 deletion win32ctypes/tests/test_win32cred.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_write_simple(self):

self.assertEqual(res["Type"], CRED_TYPE_GENERIC)
self.assertEqual(
unicode(res["CredentialBlob"], encoding='utf-16'),
res["CredentialBlob"].decode(encoding='utf-16'),
password)
self.assertEqual(res["UserName"], username)
self.assertEqual(res["TargetName"], target)
Expand Down
4 changes: 2 additions & 2 deletions win32ctypes/win32api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from __future__ import absolute_import

from ._common import _PyString_FromStringAndSize
from ._common import _PyBytes_FromStringAndSize
from . import _win32api

LOAD_LIBRARY_AS_DATAFILE = 0x2
Expand Down Expand Up @@ -61,7 +61,7 @@ def LoadResource(hModule, type_, name, language):
size = _win32api._SizeofResource(hModule, hrsrc)
hglob = _win32api._LoadResource(hModule, hrsrc)
pointer = _win32api._LockResource(hglob)
return _PyString_FromStringAndSize(pointer, size)
return _PyBytes_FromStringAndSize(pointer, size)


def FreeLibrary(hModule):
Expand Down
7 changes: 4 additions & 3 deletions win32ctypes/win32cred.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

import ctypes

from ._common import _PyString_FromStringAndSize, _GetACP
from ._common import _PyBytes_FromStringAndSize, _GetACP
from .compat import is_unicode, unicode
from . import _win32cred

CRED_TYPE_GENERIC = 0x1
Expand Down Expand Up @@ -103,7 +104,7 @@ def CredRead(TargetName, Type):
if key != 'CredentialBlob':
credential[key] = getattr(c_creds, key)
else:
blob = _PyString_FromStringAndSize(
blob = _PyBytes_FromStringAndSize(
c_creds.CredentialBlob, c_creds.CredentialBlobSize)
credential['CredentialBlob'] = blob
return credential
Expand Down Expand Up @@ -132,7 +133,7 @@ def _make_blob(password):
Credentials.
"""
if isinstance(password, unicode):
if is_unicode(password):
return password
else:
code_page = _GetACP()
Expand Down

0 comments on commit 3456047

Please sign in to comment.