From 565db70aa32124cfa29fe475c29ecb0a2c7b7a67 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Fri, 19 Jun 2015 12:10:56 +0100 Subject: [PATCH 01/43] Remove support for Python releases older than 2.6 --- setup.py | 138 ++++--------------------------------------------------- 1 file changed, 8 insertions(+), 130 deletions(-) diff --git a/setup.py b/setup.py index 8d2e4043..4eb3d34c 100755 --- a/setup.py +++ b/setup.py @@ -26,13 +26,10 @@ from distutils import core, dir_util, file_util from distutils.core import Extension from distutils.util import get_platform -from distutils.command.build_ext import build_ext -import glob -import os import sys -if sys.version[0:1] == '1': - raise RuntimeError("pyscard requires Python 2.x to build.") +if sys.version_info[0:2] < (2, 6): + raise RuntimeError("pyscard requires Python 2.6+ to build.") if 'win32' == get_platform(): platform__cc_defines = [('WIN32', '100')] @@ -61,27 +58,6 @@ platform_extra_compile_args = [] platform_extra_link_args = [] -# -# Mac OS X Tiger has python 2.3 preinstalled -# get_platform() returns a string similar to 'darwin-8.11.1-i386' with -# python 2.3 -# if python 2.5 is installed, get_platform() returns a string similar to -# 'macosx-10.3-fat' -elif 'darwin' in get_platform() \ - or 'macosx-10.3' in get_platform() \ - or 'macosx-10.4' in get_platform(): - platform__cc_defines = [('PCSCLITE', '1'), - ('__APPLE__', '1'), - ('__TIGER__', '1')] - platform_swig_opts = ['-DPCSCLITE', '-D__APPLE__', '-D__TIGER__'] - platform_sources = [] - platform_libraries = [] - platform_include_dirs = [] - platform_extra_compile_args = ['-v', '-framework', 'PCSC', - '-arch', 'i386', '-arch', - 'ppc', '-ggdb', '-O0'] - platform_extra_link_args = ['-arch', 'i386', '-arch', 'ppc', '-ggdb'] - # # Mac OS X Lion (and above), python 2.7 # PowerPC is no more supported, x86_64 is new @@ -116,23 +92,6 @@ '-arch', 'x86_64', '-ggdb'] platform_extra_link_args = ['-arch', 'i386', '-arch', 'x86_64', '-ggdb'] -# -# Mac OS X Leopard has python 2.5 preinstalled -# get_platform() returns a string similar to 'macosx-10.5-i386' -# -elif 'macosx-10.5' in get_platform(): - platform__cc_defines = [('PCSCLITE', '1'), - ('__APPLE__', '1'), - ('__LEOPARD__', '1')] - platform_swig_opts = ['-DPCSCLITE', '-D__APPLE__', '-D__LEOPARD__'] - platform_sources = [] - platform_libraries = [] - platform_include_dirs = [] - platform_extra_compile_args = ['-v', '-framework', 'PCSC', - '-arch', 'i386', - '-arch', 'ppc', '-ggdb', '-O0'] - platform_extra_link_args = ['-arch', 'i386', '-arch', 'ppc', '-ggdb'] -# # Other (GNU/Linux, etc.) # else: @@ -145,65 +104,6 @@ platform_extra_link_args = [] # ['-ggdb'] -class _pyscardBuildExt(build_ext): - '''Specialization of build_ext to enable swig_opts - for python 2.3 distutils''' -if sys.version_info < (2, 4): - - # This copy of swig_sources is from Python 2.3. - # This is to add support of swig_opts for Python 2.3 distutils - # (in particular for MacOS X darwin that comes with Python 2.3) - - def swig_sources(self, sources): - - """Walk the list of source files in 'sources', looking for SWIG - interface (.i) files. Run SWIG on all that are found, and - return a modified 'sources' list with SWIG source files replaced - by the generated C (or C++) files. - """ - - new_sources = [] - swig_sources = [] - swig_targets = {} - - # XXX this drops generated C/C++ files into the source tree, which - # is fine for developers who want to distribute the generated - # source -- but there should be an option to put SWIG output in - # the temp dir. - - if self.swig_cpp: - target_ext = '.cpp' - else: - target_ext = '.c' - - for source in sources: - (base, ext) = os.path.splitext(source) - if ext == ".i": # SWIG interface file - new_sources.append(base + target_ext) - swig_sources.append(source) - swig_targets[source] = new_sources[-1] - else: - new_sources.append(source) - - if not swig_sources: - return new_sources - - swig = self.find_swig() - swig_cmd = [swig, "-python"] - if self.swig_cpp: - swig_cmd.append("-c++") - - swig_cmd += platform_swig_opts - - for source in swig_sources: - target = swig_targets[source] - self.announce("swigging %s to %s" % (source, target)) - self.spawn(swig_cmd + ["-o", target, source]) - - return new_sources - - build_ext.swig_sources = swig_sources - kw = {'name': "pyscard", 'version': "1.6.16", 'description': "Smartcard module for Python.", @@ -248,13 +148,7 @@ def swig_sources(self, sources): swig_opts=['-outdir', 'smartcard/scard'] \ + platform_swig_opts)], - 'cmdclass': {'build_ext': _pyscardBuildExt}, - } - -# If we're running >Python 2.3, add extra information -if hasattr(core, 'setup_keywords'): - if 'classifiers' in core.setup_keywords: - kw['classifiers'] = [ + 'classifiers': [ 'Development Status :: 1.6.16 - Release', 'License :: GNU LESSER GENERAL PUBLIC LICENSE', 'Intended Audience :: Developers', @@ -262,28 +156,12 @@ def swig_sources(self, sources): 'Operating System :: Microsoft :: Windows', 'Topic :: Security :: Smartcards', ] - if 'download_url' in core.setup_keywords: - kw['download_url'] = ('http://sourceforge.net/projects/pyscard/' - '%s-%s.zip' % (kw['name'], kw['version'])) + } +# FIXME Sourceforge downloads are unauthenticated, migrate to PyPI +kw['download_url'] = ('http://sourceforge.net/projects/%(name)s/files' + '/%(name)s/%(name)s%%20%(version)s' + '/%(name)s-%(version)s.tar.gz/download' % kw) pyscard_dist = core.setup(**kw) - -# Python 2.3 distutils does not support package_data -# copy manually package_data -if sys.version_info < (2, 4): - from distutils.util import convert_path - from glob import glob - if "install" in sys.argv: - targetdir = pyscard_dist.command_obj['install'].install_purelib - package_data = kw['package_data'] - files = [] - for directory in package_data: - for pattern in package_data[directory]: - filelist = glob(os.path.join(directory, convert_path(pattern))) - files.extend([fn for fn in filelist if fn not in files]) - for file in files: - newdir = os.path.dirname(file) - dir_util.mkpath(os.path.join(targetdir, newdir)) - file_util.copy_file(file, os.path.join(targetdir, file)) From ac3eb3154e1338439f0c4b2e1b57a3ad2b335e1f Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Fri, 19 Jun 2015 13:02:42 +0100 Subject: [PATCH 02/43] Consolidate build platform logic This also fixes Mac OS X Lion options being selected on Snow Leopard - due to misordered of elif blocks. --- setup.py | 41 +++++++---------------------------------- 1 file changed, 7 insertions(+), 34 deletions(-) diff --git a/setup.py b/setup.py index 4eb3d34c..ea86fa1d 100755 --- a/setup.py +++ b/setup.py @@ -31,7 +31,7 @@ if sys.version_info[0:2] < (2, 6): raise RuntimeError("pyscard requires Python 2.6+ to build.") -if 'win32' == get_platform(): +if get_platform() in ('win32', 'win-amd64'): platform__cc_defines = [('WIN32', '100')] platform_swig_opts = ['-DWIN32'] platform_sources = ['smartcard/scard/scard.rc'] @@ -40,15 +40,6 @@ platform_extra_compile_args = [] platform_extra_link_args = [] -elif 'win-amd64' == get_platform(): - platform__cc_defines = [('WIN32', '100')] - platform_swig_opts = ['-DWIN32'] - platform_sources = ['smartcard/scard/scard.rc'] - platform_libraries = ['winscard'] - platform_include_dirs = [] - platform_extra_compile_args = [] - platform_extra_link_args = [] - elif 'cygwin-' in get_platform(): platform__cc_defines = [('WIN32', '100')] platform_swig_opts = ['-DWIN32'] @@ -58,33 +49,15 @@ platform_extra_compile_args = [] platform_extra_link_args = [] -# -# Mac OS X Lion (and above), python 2.7 -# PowerPC is no more supported, x86_64 is new -# -# x86_64 and i386 -# elif 'macosx-10.' in get_platform(): + if 'macosx-10.6' in get_platform(): + macosx_define = '__LEOPARD__' # Snow Leopard, Python 2.6 + else: + macosx_define = '__LION__' # Lion (and above), Python 2.7 platform__cc_defines = [('PCSCLITE', '1'), ('__APPLE__', '1'), - ('__LION__', '1')] - platform_swig_opts = ['-DPCSCLITE', '-D__APPLE__', '-D__LION__'] - platform_sources = [] - platform_libraries = [] - platform_include_dirs = [] - platform_extra_compile_args = ['-v', '-arch', 'i386', - '-arch', 'x86_64', '-ggdb'] - platform_extra_link_args = ['-arch', 'i386', '-arch', 'x86_64', '-ggdb'] - -# -# Mac OS X Snow Leopard, python 2.6 -# PowerPC is no more supported, x86_64 is new -# -elif 'macosx-10.6' in get_platform(): - platform__cc_defines = [('PCSCLITE', '1'), - ('__APPLE__', '1'), - ('__LEOPARD__', '1')] - platform_swig_opts = ['-DPCSCLITE', '-D__APPLE__', '-D__LEOPARD__'] + (macosx_define, '1')] + platform_swig_opts = ['-DPCSCLITE', '-D__APPLE__', '-D' + macosx_define] platform_sources = [] platform_libraries = [] platform_include_dirs = [] From 3bca937a2cd892312e0eb34725a13327057772db Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Fri, 19 Jun 2015 13:07:56 +0100 Subject: [PATCH 03/43] Standardise Trove classifiers, declare OS & Python support --- setup.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index ea86fa1d..c3d333e4 100755 --- a/setup.py +++ b/setup.py @@ -122,11 +122,16 @@ 'smartcard/scard'] \ + platform_swig_opts)], 'classifiers': [ - 'Development Status :: 1.6.16 - Release', - 'License :: GNU LESSER GENERAL PUBLIC LICENSE', + 'Development Status :: 5 - Release', + 'License :: OSI Approved :: GNU Lesser General Public License v2 ' + 'or later (LGPLv2+)', 'Intended Audience :: Developers', 'Operating System :: Unix', 'Operating System :: Microsoft :: Windows', + 'Operating System :: MacOS X', + 'Programming Language :: Python :: 2.6', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 2 :: Only', 'Topic :: Security :: Smartcards', ] } From 119b0f22af28d4d6a36b35d2a4d31958d0e556be Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Fri, 19 Jun 2015 13:12:10 +0100 Subject: [PATCH 04/43] Correct package declarations, include smartcard.pyro --- setup.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index c3d333e4..8a128750 100755 --- a/setup.py +++ b/setup.py @@ -87,12 +87,13 @@ 'license': 'GNU LESSER GENERAL PUBLIC LICENSE', 'platforms': ['linux', 'win32'], 'packages': ["smartcard", - "smartcard/pcsc", - "smartcard/reader", - "smartcard/scard", - "smartcard/sw", - "smartcard/util", - "smartcard/wx", + "smartcard.pcsc", + "smartcard.pyro", + "smartcard.reader", + "smartcard.scard", + "smartcard.sw", + "smartcard.util", + "smartcard.wx", ], 'package_dir': {"": "."}, 'package_data': { From a72aa555c8e7847e1266593def6f5e8fe91668db Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Fri, 19 Jun 2015 13:13:11 +0100 Subject: [PATCH 05/43] Switch from distutils to setuptools --- setup.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 8a128750..e2046d2b 100755 --- a/setup.py +++ b/setup.py @@ -23,11 +23,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from distutils import core, dir_util, file_util -from distutils.core import Extension from distutils.util import get_platform import sys +from setuptools import setup, Extension + + if sys.version_info[0:2] < (2, 6): raise RuntimeError("pyscard requires Python 2.6+ to build.") @@ -142,5 +143,5 @@ '/%(name)s/%(name)s%%20%(version)s' '/%(name)s-%(version)s.tar.gz/download' % kw) -pyscard_dist = core.setup(**kw) +setup(**kw) From 20c77ff247a88550d9989b0adf21d4f85eb40fc9 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Fri, 19 Jun 2015 13:14:55 +0100 Subject: [PATCH 06/43] Add gitignore for build artefacts --- .gitignore | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..fb32a717 --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +*.pyc +*.pyo +*.pyd +*.so + +build/ +dist/ +env/ +sdist/ +*.egg-info/ + +MANIFEST + +# Generated by SWIG +smartcard/scard/scard.py +smartcard/scard/scard_wrap.c From 7d366458f90a6089aa28e6fd73adf71a4ec0797b Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Fri, 19 Jun 2015 17:25:01 +0100 Subject: [PATCH 07/43] Initial attempt at CI builds on Windows, using appveyor.com Instructions at https://packaging.python.org/en/latest/appveyor.html --- appveyor.yml | 56 ++++++++++++++++++++++ appveyor/install.ps1 | 85 ++++++++++++++++++++++++++++++++++ appveyor/run_with_compiler.cmd | 47 +++++++++++++++++++ 3 files changed, 188 insertions(+) create mode 100644 appveyor.yml create mode 100644 appveyor/install.ps1 create mode 100644 appveyor/run_with_compiler.cmd diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 00000000..1e54cab6 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,56 @@ +environment: + + global: + # SDK v7.0 MSVC Express 2008's SetEnv.cmd script will fail if the + # /E:ON and /V:ON options are not enabled in the batch script intepreter + # See: http://stackoverflow.com/a/13751649/163740 + WITH_COMPILER: "cmd /E:ON /V:ON /C .\\appveyor\\run_with_compiler.cmd" + + matrix: + - PYTHON: "C:\\Python27" + PYTHON_VERSION: "2.7.8" + PYTHON_ARCH: "32" + + #- PYTHON: "C:\\Python33" + # PYTHON_VERSION: "3.3.5" + # PYTHON_ARCH: "32" + + #- PYTHON: "C:\\Python34" + # PYTHON_VERSION: "3.4.1" + # PYTHON_ARCH: "32" + + - PYTHON: "C:\\Python27-x64" + PYTHON_VERSION: "2.7.8" + PYTHON_ARCH: "64" + WINDOWS_SDK_VERSION: "v7.0" + + #- PYTHON: "C:\\Python33-x64" + # PYTHON_VERSION: "3.3.5" + # PYTHON_ARCH: "64" + WINDOWS_SDK_VERSION: "v7.1" + + #- PYTHON: "C:\\Python34-x64" + # PYTHON_VERSION: "3.4.1" + # PYTHON_ARCH: "64" + # WINDOWS_SDK_VERSION: "v7.1" + +init: + - "ECHO %PYTHON% %PYTHON_VERSION% %PYTHON_ARCH%" + +install: + - "powershell appveyor\\install.ps1" + +build: off + +test_script: + #- "%WITH_COMPILER% %PYTHON%/python setup.py test" + - echo Skipped + +after_test: + - "%WITH_COMPILER% %PYTHON%/python setup.py bdist_wheel" + +artifacts: + - path: dist\* + +#on_success: +# - TODO: upload the content of dist/*.whl to a public wheelhouse diff --git a/appveyor/install.ps1 b/appveyor/install.ps1 new file mode 100644 index 00000000..3f056282 --- /dev/null +++ b/appveyor/install.ps1 @@ -0,0 +1,85 @@ +# Sample script to install Python and pip under Windows +# Authors: Olivier Grisel and Kyle Kastner +# License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/ + +$BASE_URL = "https://www.python.org/ftp/python/" +$GET_PIP_URL = "https://bootstrap.pypa.io/get-pip.py" +$GET_PIP_PATH = "C:\get-pip.py" + + +function DownloadPython ($python_version, $platform_suffix) { + $webclient = New-Object System.Net.WebClient + $filename = "python-" + $python_version + $platform_suffix + ".msi" + $url = $BASE_URL + $python_version + "/" + $filename + + $basedir = $pwd.Path + "\" + $filepath = $basedir + $filename + if (Test-Path $filename) { + Write-Host "Reusing" $filepath + return $filepath + } + + # Download and retry up to 5 times in case of network transient errors. + Write-Host "Downloading" $filename "from" $url + $retry_attempts = 3 + for($i=0; $i -lt $retry_attempts; $i++){ + try { + $webclient.DownloadFile($url, $filepath) + break + } + Catch [Exception]{ + Start-Sleep 1 + } + } + Write-Host "File saved at" $filepath + return $filepath +} + + +function InstallPython ($python_version, $architecture, $python_home) { + Write-Host "Installing Python" $python_version "for" $architecture "bit architecture to" $python_home + if (Test-Path $python_home) { + Write-Host $python_home "already exists, skipping." + return $false + } + if ($architecture -eq "32") { + $platform_suffix = "" + } else { + $platform_suffix = ".amd64" + } + $filepath = DownloadPython $python_version $platform_suffix + Write-Host "Installing" $filepath "to" $python_home + $args = "/qn /i $filepath TARGETDIR=$python_home" + Write-Host "msiexec.exe" $args + Start-Process -FilePath "msiexec.exe" -ArgumentList $args -Wait -Passthru + Write-Host "Python $python_version ($architecture) installation complete" + return $true +} + + +function InstallPip ($python_home) { + $pip_path = $python_home + "/Scripts/pip.exe" + $python_path = $python_home + "/python.exe" + if (-not(Test-Path $pip_path)) { + Write-Host "Installing pip..." + $webclient = New-Object System.Net.WebClient + $webclient.DownloadFile($GET_PIP_URL, $GET_PIP_PATH) + Write-Host "Executing:" $python_path $GET_PIP_PATH + Start-Process -FilePath "$python_path" -ArgumentList "$GET_PIP_PATH" -Wait -Passthru + } else { + Write-Host "pip already installed." + } +} + +function InstallPackage ($python_home, $pkg) { + $pip_path = $python_home + "/Scripts/pip.exe" + & $pip_path install $pkg +} + +function main () { + InstallPython $env:PYTHON_VERSION $env:PYTHON_ARCH $env:PYTHON + InstallPip $env:PYTHON + InstallPackage $env:PYTHON wheel +} + +main diff --git a/appveyor/run_with_compiler.cmd b/appveyor/run_with_compiler.cmd new file mode 100644 index 00000000..3a472bc8 --- /dev/null +++ b/appveyor/run_with_compiler.cmd @@ -0,0 +1,47 @@ +:: To build extensions for 64 bit Python 3, we need to configure environment +:: variables to use the MSVC 2010 C++ compilers from GRMSDKX_EN_DVD.iso of: +:: MS Windows SDK for Windows 7 and .NET Framework 4 (SDK v7.1) +:: +:: To build extensions for 64 bit Python 2, we need to configure environment +:: variables to use the MSVC 2008 C++ compilers from GRMSDKX_EN_DVD.iso of: +:: MS Windows SDK for Windows 7 and .NET Framework 3.5 (SDK v7.0) +:: +:: 32 bit builds do not require specific environment configurations. +:: +:: Note: this script needs to be run with the /E:ON and /V:ON flags for the +:: cmd interpreter, at least for (SDK v7.0) +:: +:: More details at: +:: https://github.com/cython/cython/wiki/64BitCythonExtensionsOnWindows +:: http://stackoverflow.com/a/13751649/163740 +:: +:: Author: Olivier Grisel +:: License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/ +@ECHO OFF + +SET COMMAND_TO_RUN=%* +SET WIN_SDK_ROOT=C:\Program Files\Microsoft SDKs\Windows + +SET MAJOR_PYTHON_VERSION="%PYTHON_VERSION:~0,1%" +IF %MAJOR_PYTHON_VERSION% == "2" ( + SET WINDOWS_SDK_VERSION="v7.0" +) ELSE IF %MAJOR_PYTHON_VERSION% == "3" ( + SET WINDOWS_SDK_VERSION="v7.1" +) ELSE ( + ECHO Unsupported Python version: "%MAJOR_PYTHON_VERSION%" + EXIT 1 +) + +IF "%PYTHON_ARCH%"=="64" ( + ECHO Configuring Windows SDK %WINDOWS_SDK_VERSION% for Python %MAJOR_PYTHON_VERSION% on a 64 bit architecture + SET DISTUTILS_USE_SDK=1 + SET MSSdk=1 + "%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Setup\WindowsSdkVer.exe" -q -version:%WINDOWS_SDK_VERSION% + "%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Bin\SetEnv.cmd" /x64 /release + ECHO Executing: %COMMAND_TO_RUN% + call %COMMAND_TO_RUN% || EXIT 1 +) ELSE ( + ECHO Using default MSVC build environment for 32 bit architecture + ECHO Executing: %COMMAND_TO_RUN% + call %COMMAND_TO_RUN% || EXIT 1 +) From 7b0005e99776fb15c133c92274db46ddbd4332b0 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Fri, 19 Jun 2015 17:26:23 +0100 Subject: [PATCH 08/43] Missing comment --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 1e54cab6..23a245f3 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -27,7 +27,7 @@ environment: #- PYTHON: "C:\\Python33-x64" # PYTHON_VERSION: "3.3.5" # PYTHON_ARCH: "64" - WINDOWS_SDK_VERSION: "v7.1" + # WINDOWS_SDK_VERSION: "v7.1" #- PYTHON: "C:\\Python34-x64" # PYTHON_VERSION: "3.4.1" From 88c556cb3ac253e9732939e04ae164b40c0f17be Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Fri, 19 Jun 2015 19:25:52 +0100 Subject: [PATCH 09/43] Download and install Swig in CI build --- appveyor.yml | 4 ++++ appveyor/install.ps1 | 33 +++++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 23a245f3..624011fd 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,6 +5,9 @@ environment: # /E:ON and /V:ON options are not enabled in the batch script intepreter # See: http://stackoverflow.com/a/13751649/163740 WITH_COMPILER: "cmd /E:ON /V:ON /C .\\appveyor\\run_with_compiler.cmd" + SWIG: "C:\\swigwin-3.0.5" + SWIG_VERSION: "3.0.5" + SWIG_SHA256: "12b4e1905124f26f4f6970e23948238166aeb44001fa4ee5c1fd6bbbb7d981f4" matrix: - PYTHON: "C:\\Python27" @@ -47,6 +50,7 @@ test_script: - echo Skipped after_test: + - SET PATH=%SWIG%;%PATH% - "%WITH_COMPILER% %PYTHON%/python setup.py bdist_wheel" artifacts: diff --git a/appveyor/install.ps1 b/appveyor/install.ps1 index 3f056282..8e6a84ab 100644 --- a/appveyor/install.ps1 +++ b/appveyor/install.ps1 @@ -5,12 +5,10 @@ $BASE_URL = "https://www.python.org/ftp/python/" $GET_PIP_URL = "https://bootstrap.pypa.io/get-pip.py" $GET_PIP_PATH = "C:\get-pip.py" +$SWIG_BASE_URL = "http://prdownloads.sourceforge.net/swig/" - -function DownloadPython ($python_version, $platform_suffix) { +function DownloadFile ($url, $filename) { $webclient = New-Object System.Net.WebClient - $filename = "python-" + $python_version + $platform_suffix + ".msi" - $url = $BASE_URL + $python_version + "/" + $filename $basedir = $pwd.Path + "\" $filepath = $basedir + $filename @@ -35,6 +33,19 @@ function DownloadPython ($python_version, $platform_suffix) { return $filepath } +function DownloadPython ($python_version, $platform_suffix) { + $filename = "python-" + $python_version + $platform_suffix + ".msi" + $url = $BASE_URL + $python_version + "/" + $filename + $filepath = DownloadFile $url $filename + return $filepath +} + +function DownloadSwig ($swig_version) { + $filename = "swigwin-" + $swig_version + ".zip" + $url = $SWIG_BASE_URL + $filename + $filepath = DownloadFile $url $filename + return $filepath +} function InstallPython ($python_version, $architecture, $python_home) { Write-Host "Installing Python" $python_version "for" $architecture "bit architecture to" $python_home @@ -56,6 +67,19 @@ function InstallPython ($python_version, $architecture, $python_home) { return $true } +function InstallSwig ($swig_version, $swig_home, $python_home) { + Write-Host "Installing Swig" $swig_version "to" $swig_home + if (Test-Path $swig_home) { + Write-Host $swig_home "already exists, skipping." + return $false + } + $filepath = DownloadSwig $swig_version + Write-Host "Unzipping" $filepath "to" $swig_home + $python_path = $python_home + "/python.exe" + $args = "-m zipfile -e $filepath C:/" + Write-Host "Executing:" $python_path $args + Start-Process -FilePath "$python_path" -ArgumentList $args -Wait -Passthru +} function InstallPip ($python_home) { $pip_path = $python_home + "/Scripts/pip.exe" @@ -78,6 +102,7 @@ function InstallPackage ($python_home, $pkg) { function main () { InstallPython $env:PYTHON_VERSION $env:PYTHON_ARCH $env:PYTHON + InstallSwig $env:SWIG_VERSION $env:SWIG $env:PYTHON InstallPip $env:PYTHON InstallPackage $env:PYTHON wheel } From af2c0e0ddef3101e90196af03db5e8d7e1461c2f Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Sat, 20 Jun 2015 15:33:39 +0100 Subject: [PATCH 10/43] First attempt at Travis CI --- .travis.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..d3bc8cba --- /dev/null +++ b/.travis.yml @@ -0,0 +1,11 @@ +language: python +python: + - "2.6" + - "2.7" + +install: + - apt-get install -y libpcsclite-dev swig + - pip install wheel + +script: + - python setup.py bdist_wheel From 31241d9f72c6dc550caa7636976043c4da95b760 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Sat, 20 Jun 2015 15:46:28 +0100 Subject: [PATCH 11/43] Correct travis dependcy installation Based on http://docs.travis-ci.com/user/installing-dependencies/ --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d3bc8cba..5ce5354c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,11 @@ python: - "2.6" - "2.7" -install: +before_install: + - apt-get update -qq - apt-get install -y libpcsclite-dev swig + +install: - pip install wheel script: From 17feb6cd35a59b2cff3ddc8540caa894466b3cf7 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Sat, 20 Jun 2015 15:56:57 +0100 Subject: [PATCH 12/43] sudo helps when running apt-get --- .travis.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5ce5354c..ef1955a3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,13 @@ language: python +sudo: required + python: - "2.6" - "2.7" before_install: - - apt-get update -qq - - apt-get install -y libpcsclite-dev swig + - sudo apt-get update -qq + - sudo apt-get install -y libpcsclite-dev swig install: - pip install wheel From cae946718485bf325883ce6d5ce8a43f76220d84 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Mon, 22 Jun 2015 10:02:46 +0100 Subject: [PATCH 13/43] gitignore the config generated by the test suite --- .gitignore | 3 +++ smartcard/test/configcheck.py | 2 ++ 2 files changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index fb32a717..54d3aa03 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,6 @@ MANIFEST # Generated by SWIG smartcard/scard/scard.py smartcard/scard/scard_wrap.c + +# Generated by test suite +smartcard/test/local_config.py diff --git a/smartcard/test/configcheck.py b/smartcard/test/configcheck.py index 0b916b5f..d7a6b339 100755 --- a/smartcard/test/configcheck.py +++ b/smartcard/test/configcheck.py @@ -45,6 +45,8 @@ def checklocalconfig(): f = open('local_config.py', 'r') except IOError: print 'local_config.py not found; generating local_config.py...' + else: + f.close() # generate local configuration f = open('local_config.py', 'w+') From 370427c985a51cf26c7750745dfd15af2b0053fb Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Mon, 22 Jun 2015 14:29:54 +0100 Subject: [PATCH 14/43] Remove all but two uses of 'except:' & 'except Exception:' The remaining instance will now print a full traceback. This should improve on with https://sourceforge.net/p/pyscard/bugs/8/, or at least make it easier to solve --- smartcard/CardMonitoring.py | 12 ++---- .../Examples/framework/sample_MonitorCards.py | 8 +--- .../sample_MonitorCardsAndTransmit.py | 8 +--- .../framework/sample_MonitorReaders.py | 8 +--- .../framework/sample_TransmitCardObserver.py | 6 +-- smartcard/Examples/scard-api/sample_getATR.py | 14 +++--- .../Examples/scard-api/sample_getAttrib.py | 14 +++--- .../scard-api/sample_listInterfaces.py | 20 ++++----- smartcard/Examples/simple/selectDF_TELECOM.py | 4 -- smartcard/Examples/simple/simpleAPDU.py | 5 +-- smartcard/Examples/wx/pcscdiag/pcscdiag.py | 2 +- smartcard/ReaderMonitoring.py | 4 +- smartcard/System.py | 10 ++--- smartcard/doc/user-guide.rst | 43 ++++++++----------- smartcard/pyro/server/RemoteReaderServer.py | 2 +- smartcard/scard/__init__.py | 7 ++- smartcard/sw/ErrorCheckingChain.py | 16 +++---- smartcard/test/framework/testcase_ATR.py | 2 +- smartcard/test/framework/testcase_Card.py | 2 +- .../test/framework/testcase_CardConnection.py | 2 +- .../test/framework/testcase_CardMonitor.py | 2 +- .../test/framework/testcase_CardRequest.py | 2 +- .../test/framework/testcase_CardService.py | 2 +- smartcard/test/framework/testcase_CardType.py | 2 +- .../test/framework/testcase_ErrorChecking.py | 2 +- .../test/framework/testcase_readermonitor.py | 2 +- smartcard/test/framework/testcase_readers.py | 2 +- .../testcase_pcscreadergroups.py | 9 ++-- smartcard/test/scard/testcase_getatr.py | 2 +- smartcard/test/scard/testcase_getattrib.py | 2 +- smartcard/test/scard/testcase_locatecards.py | 2 +- smartcard/test/scard/testcase_readergroups.py | 2 +- smartcard/test/scard/testcase_transaction.py | 2 +- smartcard/util/__init__.py | 6 +-- 34 files changed, 92 insertions(+), 136 deletions(-) diff --git a/smartcard/CardMonitoring.py b/smartcard/CardMonitoring.py index 12076824..e0273a93 100644 --- a/smartcard/CardMonitoring.py +++ b/smartcard/CardMonitoring.py @@ -28,9 +28,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from sys import exc_info from threading import Thread, Event from time import sleep +import traceback from smartcard.System import readers from smartcard.Exceptions import CardRequestTimeoutException @@ -186,15 +186,9 @@ def run(self): pass except AttributeError: pass - except: - try: - import sys - print sys.exc_info()[1] - print sys.exc_info()[2] - print sys.exc_info()[0] - except: - pass + # FIXME Tighten the exceptions caught by this block + traceback.print_exc() # stop the thread by signaling stopEvent def stop(self): diff --git a/smartcard/Examples/framework/sample_MonitorCards.py b/smartcard/Examples/framework/sample_MonitorCards.py index 860d9547..c7a1bb5d 100755 --- a/smartcard/Examples/framework/sample_MonitorCards.py +++ b/smartcard/Examples/framework/sample_MonitorCards.py @@ -24,7 +24,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from sys import stdin, exc_info +import sys from time import sleep from smartcard.CardMonitoring import CardMonitor, CardObserver @@ -44,7 +44,7 @@ def update(self, observable, (addedcards, removedcards)): for card in removedcards: print "-Removed: ", toHexString(card.atr) -try: +if __name__ == '__main__': print "Insert or remove a smartcard in the system." print "This program will exit in 10 seconds" print "" @@ -58,10 +58,6 @@ def update(self, observable, (addedcards, removedcards)): # monitor will poll forever... cardmonitor.deleteObserver(cardobserver) - import sys if 'win32' == sys.platform: print 'press Enter to continue' sys.stdin.read(1) - -except: - print exc_info()[0], ':', exc_info()[1] diff --git a/smartcard/Examples/framework/sample_MonitorCardsAndTransmit.py b/smartcard/Examples/framework/sample_MonitorCardsAndTransmit.py index 8aa93645..5180a466 100755 --- a/smartcard/Examples/framework/sample_MonitorCardsAndTransmit.py +++ b/smartcard/Examples/framework/sample_MonitorCardsAndTransmit.py @@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from sys import stdin, exc_info +import sys from time import sleep from smartcard.CardConnectionObserver import ConsoleCardConnectionObserver @@ -63,7 +63,7 @@ def update(self, observable, (addedcards, removedcards)): for card in removedcards: print "-Removed: ", toHexString(card.atr) -try: +if __name__ == '__main__': print "Insert or remove a SIM card in the system." print "This program will exit in 60 seconds" print "" @@ -77,10 +77,6 @@ def update(self, observable, (addedcards, removedcards)): # monitor will poll forever... cardmonitor.deleteObserver(selectobserver) - import sys if 'win32' == sys.platform: print 'press Enter to continue' sys.stdin.read(1) - -except: - print exc_info()[0], ':', exc_info()[1] diff --git a/smartcard/Examples/framework/sample_MonitorReaders.py b/smartcard/Examples/framework/sample_MonitorReaders.py index 178b6a87..49e22b4b 100755 --- a/smartcard/Examples/framework/sample_MonitorReaders.py +++ b/smartcard/Examples/framework/sample_MonitorReaders.py @@ -24,7 +24,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from sys import stdin, exc_info +import sys from time import sleep from smartcard.ReaderMonitoring import ReaderMonitor, ReaderObserver @@ -40,7 +40,7 @@ def update(self, observable, (addedreaders, removedreaders)): print "Added readers", addedreaders print "Removed readers", removedreaders -try: +if __name__ == '__main__': print "Add or remove a smartcard reader to the system." print "This program will exit in 10 seconds" print "" @@ -54,10 +54,6 @@ def update(self, observable, (addedreaders, removedreaders)): # monitor will poll forever... readermonitor.deleteObserver(readerobserver) - import sys if 'win32' == sys.platform: print 'press Enter to continue' sys.stdin.read(1) - -except: - print exc_info()[0], ':', exc_info()[1] diff --git a/smartcard/Examples/framework/sample_TransmitCardObserver.py b/smartcard/Examples/framework/sample_TransmitCardObserver.py index efa83a1c..80b6dc9a 100755 --- a/smartcard/Examples/framework/sample_TransmitCardObserver.py +++ b/smartcard/Examples/framework/sample_TransmitCardObserver.py @@ -24,7 +24,6 @@ along with pyscard; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from sys import stdin, exc_info from time import sleep from smartcard.CardMonitoring import CardMonitor, CardObserver @@ -57,7 +56,7 @@ def update(self, observable, (addedcards, removedcards)): if card in self.cards: self.cards.remove(card) -try: +if __name__ == '__main__': print "Insert or remove a smartcard in the system." print "This program will exit in 100 seconds" print "" @@ -66,6 +65,3 @@ def update(self, observable, (addedcards, removedcards)): cardmonitor.addObserver(cardobserver) sleep(100) - -except: - print exc_info()[0], ':', exc_info()[1] diff --git a/smartcard/Examples/scard-api/sample_getATR.py b/smartcard/Examples/scard-api/sample_getATR.py index ec7fd59b..cba2f258 100755 --- a/smartcard/Examples/scard-api/sample_getATR.py +++ b/smartcard/Examples/scard-api/sample_getATR.py @@ -26,10 +26,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ +import sys + from smartcard.scard import * import smartcard.util -try: +if __name__ == '__main__': hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER) if hresult != SCARD_S_SUCCESS: raise error( @@ -86,10 +88,6 @@ SCardGetErrorMessage(hresult)) print 'Released context.' -except Exception, e: - print e - -import sys -if 'win32' == sys.platform: - print 'press Enter to continue' - sys.stdin.read(1) + if 'win32' == sys.platform: + print 'press Enter to continue' + sys.stdin.read(1) diff --git a/smartcard/Examples/scard-api/sample_getAttrib.py b/smartcard/Examples/scard-api/sample_getAttrib.py index a9470b93..7b19c62a 100755 --- a/smartcard/Examples/scard-api/sample_getAttrib.py +++ b/smartcard/Examples/scard-api/sample_getAttrib.py @@ -27,6 +27,8 @@ """ import struct +import sys + from smartcard.scard import * import smartcard.util @@ -91,7 +93,7 @@ def printAttribute(attrib, value): print apply(struct.pack, ['<' + 'B' * len(value)] + value) -try: +if __name__ == '__main__': hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER) if hresult != SCARD_S_SUCCESS: raise error( @@ -150,10 +152,6 @@ def printAttribute(attrib, value): SCardGetErrorMessage(hresult)) print 'Released context.' -except Exception, e: - print e - -import sys -if 'win32' == sys.platform: - print 'press Enter to continue' - sys.stdin.read(1) + if 'win32' == sys.platform: + print 'press Enter to continue' + sys.stdin.read(1) diff --git a/smartcard/Examples/scard-api/sample_listInterfaces.py b/smartcard/Examples/scard-api/sample_listInterfaces.py index d5611f14..6289b8b7 100755 --- a/smartcard/Examples/scard-api/sample_listInterfaces.py +++ b/smartcard/Examples/scard-api/sample_listInterfaces.py @@ -26,6 +26,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ +import sys + import platform from smartcard.scard import * import smartcard.guid @@ -42,7 +44,7 @@ znewcardSecGuid = \ smartcard.guid.strToGUID('{EB7F69EA-BA20-47d0-8C50-11CFDEB63BBE}') - try: + def main(): hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER) if hresult != SCARD_S_SUCCESS: raise scard.error( @@ -108,15 +110,13 @@ SCardGetErrorMessage(hresult)) print 'Released context.' - except error: - import sys - print sys.exc_info()[0], ':', sys.exc_info()[1] - elif 'pcsclite' == resourceManager: - print 'SCardListInterfaces not supported by pcsc lite' + def main(): + print 'SCardListInterfaces not supported by pcsc lite' -import sys -if 'win32' == sys.platform: - print 'press Enter to continue' - sys.stdin.read(1) +if __name__ == '__main__': + main() + if 'win32' == sys.platform: + print 'press Enter to continue' + sys.stdin.read(1) diff --git a/smartcard/Examples/simple/selectDF_TELECOM.py b/smartcard/Examples/simple/selectDF_TELECOM.py index ce88ccd3..5050f52a 100755 --- a/smartcard/Examples/simple/selectDF_TELECOM.py +++ b/smartcard/Examples/simple/selectDF_TELECOM.py @@ -65,10 +65,6 @@ except CardRequestTimeoutException: print 'time-out: no card inserted during last 10s' -except: - import sys - print sys.exc_info()[1] - import sys if 'win32' == sys.platform: print 'press Enter to continue' diff --git a/smartcard/Examples/simple/simpleAPDU.py b/smartcard/Examples/simple/simpleAPDU.py index 1d8512f4..38233132 100755 --- a/smartcard/Examples/simple/simpleAPDU.py +++ b/smartcard/Examples/simple/simpleAPDU.py @@ -32,7 +32,7 @@ 0x18, 0xFF] GET_TIME = [0x80, 0x38, 0x00, 0xA0] -try: +if __name__ == '__main__': # get all the available readers r = readers() print "Available readers: ", r @@ -51,6 +51,3 @@ data, sw1, sw2 = connection.transmit(GET_TIME) print "Get Time: %02X %02X" % (sw1, sw2) - -except: - print sys.exc_info()[1] diff --git a/smartcard/Examples/wx/pcscdiag/pcscdiag.py b/smartcard/Examples/wx/pcscdiag/pcscdiag.py index e4fbed9e..77881286 100755 --- a/smartcard/Examples/wx/pcscdiag/pcscdiag.py +++ b/smartcard/Examples/wx/pcscdiag/pcscdiag.py @@ -34,7 +34,7 @@ # wxPython GUI modules (http://www.wxpython.org) try: import wx -except: +except ImportError: print 'You need wxpython (http://www.wxpython.org) ' + \ 'to run this sample from the source code!' print 'press a key to continue' diff --git a/smartcard/ReaderMonitoring.py b/smartcard/ReaderMonitoring.py index 0d9da5dc..62aab450 100644 --- a/smartcard/ReaderMonitoring.py +++ b/smartcard/ReaderMonitoring.py @@ -28,9 +28,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from sys import exc_info from threading import Thread, Event, enumerate from time import sleep +import traceback import smartcard.System from smartcard.Exceptions import ListReadersException @@ -183,6 +183,8 @@ def run(self): self.stopEvent.wait(self.period) except Exception, e: + # FIXME Tighten the exceptions caught by this block + traceback.print_exc() # Most likely raised during interpreter shutdown due # to unclean exit which failed to remove all observers. # To solve this, we set the stop event and pass the diff --git a/smartcard/System.py b/smartcard/System.py index 27970d15..d6a20ca3 100644 --- a/smartcard/System.py +++ b/smartcard/System.py @@ -60,10 +60,6 @@ def listReaders(): if __name__ == '__main__': - try: - print readers() - print readers(['SCard$DefaultReaders']) - print readergroups() - except: - import sys - print sys.exc_info()[1] + print readers() + print readers(['SCard$DefaultReaders']) + print readergroups() diff --git a/smartcard/doc/user-guide.rst b/smartcard/doc/user-guide.rst index 7a890a20..b7f801df 100644 --- a/smartcard/doc/user-guide.rst +++ b/smartcard/doc/user-guide.rst @@ -1199,30 +1199,26 @@ To monitor reader insertion/removal, simply add the observer to the .. sourcecode:: python - from sys import stdin, exc_info + from sys import stdin from time import sleep from smartcard.ReaderMonitoring import ReaderMonitor, ReaderObserver - try: - print "Add or remove a smartcard reader to the system." - print "This program will exit in 10 seconds" - print "" - readermonitor = ReaderMonitor() - readerobserver = printobserver() - readermonitor.addObserver( readerobserver ) - - sleep(10) + print "Add or remove a smartcard reader to the system." + print "This program will exit in 10 seconds" + print "" + readermonitor = ReaderMonitor() + readerobserver = printobserver() + readermonitor.addObserver( readerobserver ) - # don't forget to remove observer, or the - # monitor will poll forever... - readermonitor.deleteObserver(readerobserver) + sleep(10) - print 'press Enter to continue' - stdin.readline() + # don't forget to remove observer, or the + # monitor will poll forever... + readermonitor.deleteObserver(readerobserver) - except error: - print exc_info()[0], ': ', exc_info()[1] + print 'press Enter to continue' + stdin.readline() Smart Cards *********** @@ -1261,13 +1257,12 @@ card observer to the `CardMonitor for card in removedcards: print "-Removed: ", toHexString( card.atr ) - try: - print "Insert or remove a smartcard in the system." - print "This program will exit in 10 seconds" - print "" - cardmonitor = CardMonitor() - cardobserver = printobserver() - cardmonitor.addObserver( cardobserver ) + print "Insert or remove a smartcard in the system." + print "This program will exit in 10 seconds" + print "" + cardmonitor = CardMonitor() + cardobserver = printobserver() + cardmonitor.addObserver( cardobserver ) Sending APDUs to a Smart Card Obtained from Card Monitoring diff --git a/smartcard/pyro/server/RemoteReaderServer.py b/smartcard/pyro/server/RemoteReaderServer.py index 06db9b1e..f29096de 100644 --- a/smartcard/pyro/server/RemoteReaderServer.py +++ b/smartcard/pyro/server/RemoteReaderServer.py @@ -26,7 +26,7 @@ try: import Pyro.core import Pyro.naming -except: +except ImportError: print 'You need pyro (python remote objects) ' + \ 'at http://www.xs4all.nl/~irmen/pyro3/' import sys diff --git a/smartcard/scard/__init__.py b/smartcard/scard/__init__.py index 596417c8..e1a9ffb7 100644 --- a/smartcard/scard/__init__.py +++ b/smartcard/scard/__init__.py @@ -1,4 +1,3 @@ -try: - from scard import * -except: - from smartcard.scard._scard import * +from __future__ import absolute_import + +from smartcard.scard.scard import * diff --git a/smartcard/sw/ErrorCheckingChain.py b/smartcard/sw/ErrorCheckingChain.py index d8c0a5ad..77123d54 100644 --- a/smartcard/sw/ErrorCheckingChain.py +++ b/smartcard/sw/ErrorCheckingChain.py @@ -23,9 +23,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from sys import exc_info - - class ErrorCheckingChain(object): """The error checking chain is a list of response apdu status word (sw1, sw2) error check strategies. Each strategy in the chain is @@ -76,11 +73,14 @@ def __call__(self, data, sw1, sw2): """Called to test data, sw1 and sw2 for error on the chain.""" try: self.strategy(data, sw1, sw2) - except: - # if exception is filtered, return - for exception in self.excludes: - if exception == exc_info()[0]: - return + except tuple(self.excludes) as exc: + # The following addtional filter may look redundant, it isn't.s + # It checks that type(exc) is *equal* to any of self.excludes, + # rather than equal-or-subclass to any of self.excludes. + # This is to keep backward compatibility with the behaviour of + # pyscard <= 1.6.16. + if type(exc) in self.excludes: + return # otherwise reraise exception raise diff --git a/smartcard/test/framework/testcase_ATR.py b/smartcard/test/framework/testcase_ATR.py index b64de568..03dbbe55 100755 --- a/smartcard/test/framework/testcase_ATR.py +++ b/smartcard/test/framework/testcase_ATR.py @@ -38,7 +38,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/framework/testcase_Card.py b/smartcard/test/framework/testcase_Card.py index c8b25b41..6ea594b1 100755 --- a/smartcard/test/framework/testcase_Card.py +++ b/smartcard/test/framework/testcase_Card.py @@ -39,7 +39,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/framework/testcase_CardConnection.py b/smartcard/test/framework/testcase_CardConnection.py index 526d5d18..5120297e 100755 --- a/smartcard/test/framework/testcase_CardConnection.py +++ b/smartcard/test/framework/testcase_CardConnection.py @@ -39,7 +39,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/framework/testcase_CardMonitor.py b/smartcard/test/framework/testcase_CardMonitor.py index 2365926d..bea14870 100755 --- a/smartcard/test/framework/testcase_CardMonitor.py +++ b/smartcard/test/framework/testcase_CardMonitor.py @@ -41,7 +41,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/framework/testcase_CardRequest.py b/smartcard/test/framework/testcase_CardRequest.py index 55463fdd..10826621 100755 --- a/smartcard/test/framework/testcase_CardRequest.py +++ b/smartcard/test/framework/testcase_CardRequest.py @@ -39,7 +39,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader, expectedReaderForATR -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/framework/testcase_CardService.py b/smartcard/test/framework/testcase_CardService.py index a5bcd10d..a11bd591 100755 --- a/smartcard/test/framework/testcase_CardService.py +++ b/smartcard/test/framework/testcase_CardService.py @@ -38,7 +38,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/framework/testcase_CardType.py b/smartcard/test/framework/testcase_CardType.py index 0afaa6ee..293afb64 100755 --- a/smartcard/test/framework/testcase_CardType.py +++ b/smartcard/test/framework/testcase_CardType.py @@ -39,7 +39,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/framework/testcase_ErrorChecking.py b/smartcard/test/framework/testcase_ErrorChecking.py index 6463fca9..fb4c4f9d 100755 --- a/smartcard/test/framework/testcase_ErrorChecking.py +++ b/smartcard/test/framework/testcase_ErrorChecking.py @@ -49,7 +49,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/framework/testcase_readermonitor.py b/smartcard/test/framework/testcase_readermonitor.py index 3536aefb..d767d230 100755 --- a/smartcard/test/framework/testcase_readermonitor.py +++ b/smartcard/test/framework/testcase_readermonitor.py @@ -41,7 +41,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/framework/testcase_readers.py b/smartcard/test/framework/testcase_readers.py index 5e531e29..a0f674fa 100755 --- a/smartcard/test/framework/testcase_readers.py +++ b/smartcard/test/framework/testcase_readers.py @@ -38,7 +38,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/frameworkpcsc/testcase_pcscreadergroups.py b/smartcard/test/frameworkpcsc/testcase_pcscreadergroups.py index cf9a0218..bc53bcac 100755 --- a/smartcard/test/frameworkpcsc/testcase_pcscreadergroups.py +++ b/smartcard/test/frameworkpcsc/testcase_pcscreadergroups.py @@ -38,7 +38,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() @@ -54,11 +54,8 @@ class testcase_readergroups(unittest.TestCase): def setUp(self): groups = PCSCReaderGroups().instance - try: - groups.remove('Pinpad$Readers') - groups.remove('Biometric$Readers') - except: - pass + groups.remove('Pinpad$Readers') + groups.remove('Biometric$Readers') def testcase_add(self): """Test for groups=groups+newgroups""" diff --git a/smartcard/test/scard/testcase_getatr.py b/smartcard/test/scard/testcase_getatr.py index 45541a21..f3c0ee6a 100755 --- a/smartcard/test/scard/testcase_getatr.py +++ b/smartcard/test/scard/testcase_getatr.py @@ -39,7 +39,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/scard/testcase_getattrib.py b/smartcard/test/scard/testcase_getattrib.py index d73c2168..6f9735e1 100755 --- a/smartcard/test/scard/testcase_getattrib.py +++ b/smartcard/test/scard/testcase_getattrib.py @@ -40,7 +40,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/scard/testcase_locatecards.py b/smartcard/test/scard/testcase_locatecards.py index fc25ad9e..b78cad3c 100755 --- a/smartcard/test/scard/testcase_locatecards.py +++ b/smartcard/test/scard/testcase_locatecards.py @@ -39,7 +39,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/scard/testcase_readergroups.py b/smartcard/test/scard/testcase_readergroups.py index b2e18349..5bf6bb93 100755 --- a/smartcard/test/scard/testcase_readergroups.py +++ b/smartcard/test/scard/testcase_readergroups.py @@ -38,7 +38,7 @@ try: from local_config import expectedReaders -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/scard/testcase_transaction.py b/smartcard/test/scard/testcase_transaction.py index eb811320..a6315222 100755 --- a/smartcard/test/scard/testcase_transaction.py +++ b/smartcard/test/scard/testcase_transaction.py @@ -38,7 +38,7 @@ try: from local_config import expectedATRs, expectedReaders -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/util/__init__.py b/smartcard/util/__init__.py index 743d83d1..8d9edf5b 100644 --- a/smartcard/util/__init__.py +++ b/smartcard/util/__init__.py @@ -95,14 +95,14 @@ def toBytes(bytestring): \"3B6500009C11010103\" or \"3B6500 009C1101 0103\" """ - from struct import unpack + import struct import re packedstring = ''.join(re.split('\W+', bytestring)) try: return reduce(lambda x, y: x + [int(y, 16)], - unpack('2s' * (len(packedstring) / 2), + struct.unpack('2s' * (len(packedstring) / 2), packedstring), []) - except: + except (struct.error, ValueError): raise TypeError('not a string representing a list of bytes') From bedaf6859a3a40c90f4116939fa88f299852d205 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Mon, 22 Jun 2015 14:49:36 +0100 Subject: [PATCH 15/43] Commit convert docstring examples to doctest syntax --- smartcard/guid.py | 13 +++++- smartcard/util/__init__.py | 93 ++++++++++++++++++++++---------------- 2 files changed, 65 insertions(+), 41 deletions(-) diff --git a/smartcard/guid.py b/smartcard/guid.py index dba4a50f..c8715a72 100644 --- a/smartcard/guid.py +++ b/smartcard/guid.py @@ -32,7 +32,11 @@ def strToGUID(s): - """Converts a GUID string into a list of bytes.""" + """Converts a GUID string into a list of bytes. + + >>> strToGUID('{AD4F1667-EA75-4124-84D4-641B3B197C65}') + [103, 22, 79, 173, 117, 234, 36, 65, 132, 212, 100, 27, 59, 25, 124, 101] + """ l = [] for i in unpack('x' + '2s' * 4 + 'x' + '2s2sx' * 3 + '2s' * 6 + 'x', s): l += [int(i, 16)] @@ -43,7 +47,12 @@ def strToGUID(s): def GUIDToStr(g): - """Converts a GUID sequence of bytes into a string.""" + """Converts a GUID sequence of bytes into a string. + + >>> GUIDToStr([103,22,79,173, 117,234, 36,65, + ... 132, 212, 100, 27, 59, 25, 124, 101]) + '{AD4F1667-EA75-4124-84D4-641B3B197C65}' + """ zr = [] for i in xrange(len(g)): zr.append(g[map[i]]) diff --git a/smartcard/util/__init__.py b/smartcard/util/__init__.py index 8d9edf5b..2a8233a8 100644 --- a/smartcard/util/__init__.py +++ b/smartcard/util/__init__.py @@ -37,13 +37,13 @@ def padd(bytelist, length, padding='FF'): padding: padding value (default is 0xff) returns the padded bytelist - example: - padd(toBytes(\"3B 65 00 00 9C 11 01 01 03\"), 16) returns - [0x3B, 0x65, 0, 0, 0x9C, 0x11, 1, 1, 3, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] - padd(toBytes(\"3B 65 00 00 9C 11 01 01 03\"), 8) returns [ - 0x3B, 0x65, 0, 0, 0x9C, 0x11, 1, 1, 3 ] + >>> padd([59, 101, 0, 0, 156, 17, 1, 1, 3], 16) + [59, 101, 0, 0, 156, 17, 1, 1, 3, 255, 255, 255, 255, 255, 255, 255] + >>> padd([59, 101, 0, 0, 156, 17, 1, 1, 3], 12, '80') + [59, 101, 0, 0, 156, 17, 1, 1, 3, 128, 128, 128] + >>> padd([59, 101, 0, 0, 156, 17, 1, 1, 3], 8) + [59, 101, 0, 0, 156, 17, 1, 1, 3] """ if len(bytelist) < length: @@ -62,9 +62,8 @@ def toASCIIBytes(stringtoconvert): toASCIIBytes() is the reverse of toASCIIString() - example: - toASCIIBytes("Number 101") returns - [ 0x4E, 0x75, 0x6D, 0x62, 0x65, 0x72, 0x20, 0x31, 0x30, 0x31 ] + >>> toASCIIBytes("Number 101") + [78, 117, 109, 98, 101, 114, 32, 49, 48, 49] """ return map(ord, list(stringtoconvert)) @@ -79,10 +78,8 @@ def toASCIIString(bytelist): toASCIIString() is the reverse of toASCIIBytes() - example: - - toASCIIString([0x4E,0x75,0x6D,0x62,0x65,0x72,0x20,0x31,0x30,0x31]) - returns "Number 101") + >>> toASCIIString([0x4E,0x75,0x6D,0x62,0x65,0x72,0x20,0x31,0x30,0x31]) + 'Number 101' """ return ''.join(map(chr, bytelist)) @@ -91,9 +88,14 @@ def toASCIIString(bytelist): def toBytes(bytestring): """Returns a list of bytes from a byte string - bytestring: a byte string such as \"3B 65 00 00 9C 11 01 01 03\" or - \"3B6500009C11010103\" or - \"3B6500 009C1101 0103\" + bytestring: a byte string + + >>> toBytes("3B 65 00 00 9C 11 01 01 03") + [59, 101, 0, 0, 156, 17, 1, 1, 3] + >>> toBytes("3B6500009C11010103") + [59, 101, 0, 0, 156, 17, 1, 1, 3] + >>> toBytes("3B6500 009C1101 0103") + [59, 101, 0, 0, 156, 17, 1, 1, 3] """ import struct import re @@ -156,9 +158,8 @@ def toGSM3_38Bytes(stringtoconvert): returns a list of bytes - example: - toGSM3_38Bytes("@ùPascal") returns - [ 0x00, 0x06, 0x50, 0x61, 0x73, 0x63, 0x61, 0x6C ] + >>> toGSM3_38Bytes("@ùPascal") + [0, 6, 80, 97, 115, 99, 97, 108] """ bytes = [] @@ -185,26 +186,20 @@ def toHexString(bytes=[], format=0): UPPERCASE: use 0X before bytes (need HEX) PACK: remove blanks - example: - bytes = [ 0x3B, 0x65, 0x00, 0x00, 0x9C, 0x11, 0x01, 0x01, 0x03 ] - - toHexString(bytes) returns 3B 65 00 00 9C 11 01 01 03 - - toHexString(bytes, COMMA) returns 3B, 65, 00, 00, 9C, 11, 01, 01, 03 - - toHexString(bytes, HEX) returns - 0x3B 0x65 0x00 0x00 0x9C 0x11 0x01 0x01 0x03 - - toHexString(bytes, HEX | COMMA) returns - 0x3B, 0x65, 0x00, 0x00, 0x9C, 0x11, 0x01, 0x01, 0x03 - - toHexString(bytes, PACK) returns 3B6500009C11010103 - - toHexString(bytes, HEX | UPPERCASE) returns - 0X3B 0X65 0X00 0X00 0X9C 0X11 0X01 0X01 0X03 - - toHexString(bytes, HEX | UPPERCASE | COMMA) returns - 0X3B, 0X65, 0X00, 0X00, 0X9C, 0X11, 0X01, 0X01, 0X03 + >>> vals = [0x3B, 0x65, 0x00, 0x00, 0x9C, 0x11, 0x01, 0x01, 0x03] + >>> toHexString(vals) + '3B 65 00 00 9C 11 01 01 03' + >>> toHexString(vals, COMMA) + '3B, 65, 00, 00, 9C, 11, 01, 01, 03' + >>> toHexString(vals, HEX) + '0x3B 0x65 0x00 0x00 0x9C 0x11 0x01 0x01 0x03' + >>> toHexString(vals, HEX | COMMA) + '0x3B, 0x65, 0x00, 0x00, 0x9C, 0x11, 0x01, 0x01, 0x03' + >>> toHexString(vals, PACK) + >>> toHexString(vals, HEX | UPPERCASE) + '0X3B 0X65 0X00 0X00 0X9C 0X11 0X01 0X01 0X03' + >>> toHexString(vals, HEX | UPPERCASE | COMMA) + '0X3B, 0X65, 0X00, 0X00, 0X9C, 0X11, 0X01, 0X01, 0X03' """ from string import rstrip @@ -234,14 +229,24 @@ def toHexString(bytes=[], format=0): [""] + bytes)), ',') +# FIXME This appears to duplicate toASCIIString() def HexListToBinString(hexlist): + """ + >>> HexListToBinString([78, 117, 109, 98, 101, 114, 32, 49, 48, 49]) + 'Number 101' + """ binstring = "" for byte in hexlist: binstring = binstring + chr(eval('0x%x' % byte)) return binstring +# FIXME This appears to duplicate to ASCIIBytes() def BinStringToHexList(binstring): + """ + >>> BinStringToHexList("Number 101") + [78, 117, 109, 98, 101, 114, 32, 49, 48, 49] + """ hexlist = [] for byte in binstring: hexlist = hexlist + [ord(byte)] @@ -249,8 +254,18 @@ def BinStringToHexList(binstring): def hl2bs(hexlist): + """An alias for HexListToBinString + + >>> hl2bs([78, 117, 109, 98, 101, 114, 32, 49, 48, 49]) + 'Number 101' + """ return HexListToBinString(hexlist) def bs2hl(binstring): + """An alias for BinStringToHexList + + >>> bs2hl("Number 101") + [78, 117, 109, 98, 101, 114, 32, 49, 48, 49] + """ return BinStringToHexList(binstring) From 7479bf1598a45df4d5821a4c6db0411d60d5e11e Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Mon, 22 Jun 2015 15:24:15 +0100 Subject: [PATCH 16/43] Add default pylint config --- .pylintrc | 390 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 390 insertions(+) create mode 100644 .pylintrc diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 00000000..884c8520 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,390 @@ +[MASTER] + +# Specify a configuration file. +#rcfile= + +# Python code to execute, usually for sys.path manipulation such as +# pygtk.require(). +#init-hook= + +# Profiled execution. +profile=no + +# Add files or directories to the blacklist. They should be base names, not +# paths. +ignore=CVS + +# Pickle collected data for later comparisons. +persistent=yes + +# List of plugins (as comma separated values of python modules names) to load, +# usually to register additional checkers. +load-plugins= + +# Deprecated. It was used to include message's id in output. Use --msg-template +# instead. +include-ids=no + +# Deprecated. It was used to include symbolic ids of messages in output. Use +# --msg-template instead. +symbols=no + +# Use multiple processes to speed up Pylint. +jobs=1 + +# Allow loading of arbitrary C extensions. Extensions are imported into the +# active Python interpreter and may run arbitrary code. +unsafe-load-any-extension=no + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code +extension-pkg-whitelist= + +# Allow optimization of some AST trees. This will activate a peephole AST +# optimizer, which will apply various small optimizations. For instance, it can +# be used to obtain the result of joining multiple strings with the addition +# operator. Joining a lot of strings can lead to a maximum recursion error in +# Pylint and this flag can prevent that. It has one side effect, the resulting +# AST will be different than the one from reality. +optimize-ast=no + + +[MESSAGES CONTROL] + +# Only show warnings with the listed confidence levels. Leave empty to show +# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED +confidence= + +# Enable the message, report, category or checker with the given id(s). You can +# either give multiple identifier separated by comma (,) or put this option +# multiple time. See also the "--disable" option for examples. +#enable= + +# Disable the message, report, category or checker with the given id(s). You +# can either give multiple identifiers separated by comma (,) or put this +# option multiple times (only on the command line, not in the configuration +# file where it should appear only once).You can also use "--disable=all" to +# disable everything first and then reenable specific checks. For example, if +# you want to run only the similarities checker, you can use "--disable=all +# --enable=similarities". If you want to run only the classes checker, but have +# no Warning level messages displayed, use"--disable=all --enable=classes +# --disable=W" +disable=E1608,W1627,E1601,E1603,E1602,E1605,E1604,E1607,E1606,W1621,W1620,W1623,W1622,W1625,W1624,W1609,W1608,W1607,W1606,W1605,W1604,W1603,W1602,W1601,W1639,W1640,I0021,W1638,I0020,W1618,W1619,W1630,W1626,W1637,W1634,W1635,W1610,W1611,W1612,W1613,W1614,W1615,W1616,W1617,W1632,W1633,W0704,W1628,W1629,W1636 + + +[REPORTS] + +# Set the output format. Available formats are text, parseable, colorized, msvs +# (visual studio) and html. You can also give a reporter class, eg +# mypackage.mymodule.MyReporterClass. +output-format=text + +# Put messages in a separate file for each module / package specified on the +# command line instead of printing them on stdout. Reports (if any) will be +# written in a file name "pylint_global.[txt|html]". +files-output=no + +# Tells whether to display a full report or only the messages +reports=yes + +# Python expression which should return a note less than 10 (10 is the highest +# note). You have access to the variables errors warning, statement which +# respectively contain the number of errors / warnings messages and the total +# number of statements analyzed. This is used by the global evaluation report +# (RP0004). +evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) + +# Add a comment according to your evaluation note. This is used by the global +# evaluation report (RP0004). +comment=no + +# Template used to display messages. This is a python new-style format string +# used to format the message information. See doc for all details +#msg-template= + + +[SIMILARITIES] + +# Minimum lines number of a similarity. +min-similarity-lines=4 + +# Ignore comments when computing similarities. +ignore-comments=yes + +# Ignore docstrings when computing similarities. +ignore-docstrings=yes + +# Ignore imports when computing similarities. +ignore-imports=no + + +[LOGGING] + +# Logging modules to check that the string format arguments are in logging +# function parameter format +logging-modules=logging + + +[VARIABLES] + +# Tells whether we should check for unused import in __init__ files. +init-import=no + +# A regular expression matching the name of dummy variables (i.e. expectedly +# not used). +dummy-variables-rgx=_$|dummy + +# List of additional names supposed to be defined in builtins. Remember that +# you should avoid to define new builtins when possible. +additional-builtins= + +# List of strings which can identify a callback function by name. A callback +# name must start or end with one of those strings. +callbacks=cb_,_cb + + +[SPELLING] + +# Spelling dictionary name. Available dictionaries: none. To make it working +# install python-enchant package. +spelling-dict= + +# List of comma separated words that should not be checked. +spelling-ignore-words= + +# A path to a file that contains private dictionary; one word per line. +spelling-private-dict-file= + +# Tells whether to store unknown words to indicated private dictionary in +# --spelling-private-dict-file option instead of raising a message. +spelling-store-unknown-words=no + + +[FORMAT] + +# Maximum number of characters on a single line. +max-line-length=100 + +# Regexp for a line that is allowed to be longer than the limit. +ignore-long-lines=^\s*(# )??$ + +# Allow the body of an if to be on the same line as the test if there is no +# else. +single-line-if-stmt=no + +# List of optional constructs for which whitespace checking is disabled +no-space-check=trailing-comma,dict-separator + +# Maximum number of lines in a module +max-module-lines=1000 + +# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 +# tab). +indent-string=' ' + +# Number of spaces of indent required inside a hanging or continued line. +indent-after-paren=4 + +# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. +expected-line-ending-format= + + +[MISCELLANEOUS] + +# List of note tags to take in consideration, separated by a comma. +notes=FIXME,XXX,TODO + + +[BASIC] + +# Required attributes for module, separated by a comma +required-attributes= + +# List of builtins function names that should not be used, separated by a comma +bad-functions=map,filter,input + +# Good variable names which should always be accepted, separated by a comma +good-names=i,j,k,ex,Run,_ + +# Bad variable names which should always be refused, separated by a comma +bad-names=foo,bar,baz,toto,tutu,tata + +# Colon-delimited sets of names that determine each other's naming style when +# the name regexes allow several styles. +name-group= + +# Include a hint for the correct naming format with invalid-name +include-naming-hint=no + +# Regular expression matching correct function names +function-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Naming hint for function names +function-name-hint=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression matching correct variable names +variable-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Naming hint for variable names +variable-name-hint=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression matching correct constant names +const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ + +# Naming hint for constant names +const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$ + +# Regular expression matching correct attribute names +attr-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Naming hint for attribute names +attr-name-hint=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression matching correct argument names +argument-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Naming hint for argument names +argument-name-hint=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression matching correct class attribute names +class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ + +# Naming hint for class attribute names +class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ + +# Regular expression matching correct inline iteration names +inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ + +# Naming hint for inline iteration names +inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$ + +# Regular expression matching correct class names +class-rgx=[A-Z_][a-zA-Z0-9]+$ + +# Naming hint for class names +class-name-hint=[A-Z_][a-zA-Z0-9]+$ + +# Regular expression matching correct module names +module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ + +# Naming hint for module names +module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ + +# Regular expression matching correct method names +method-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Naming hint for method names +method-name-hint=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match function or class names that do +# not require a docstring. +no-docstring-rgx=__.*__ + +# Minimum line length for functions/classes that require docstrings, shorter +# ones are exempt. +docstring-min-length=-1 + + +[TYPECHECK] + +# Tells whether missing members accessed in mixin class should be ignored. A +# mixin class is detected if its name ends with "mixin" (case insensitive). +ignore-mixin-members=yes + +# List of module names for which member attributes should not be checked +# (useful for modules/projects where namespaces are manipulated during runtime +# and thus existing member attributes cannot be deduced by static analysis +ignored-modules= + +# List of classes names for which member attributes should not be checked +# (useful for classes with attributes dynamically set). +ignored-classes=SQLObject + +# When zope mode is activated, add a predefined set of Zope acquired attributes +# to generated-members. +zope=no + +# List of members which are set dynamically and missed by pylint inference +# system, and so shouldn't trigger E0201 when accessed. Python regular +# expressions are accepted. +generated-members=REQUEST,acl_users,aq_parent + + +[CLASSES] + +# List of interface methods to ignore, separated by a comma. This is used for +# instance to not check methods defines in Zope's Interface base class. +ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by + +# List of method names used to declare (i.e. assign) instance attributes. +defining-attr-methods=__init__,__new__,setUp + +# List of valid names for the first argument in a class method. +valid-classmethod-first-arg=cls + +# List of valid names for the first argument in a metaclass class method. +valid-metaclass-classmethod-first-arg=mcs + +# List of member names, which should be excluded from the protected access +# warning. +exclude-protected=_asdict,_fields,_replace,_source,_make + + +[DESIGN] + +# Maximum number of arguments for function / method +max-args=5 + +# Argument names that match this expression will be ignored. Default to name +# with leading underscore +ignored-argument-names=_.* + +# Maximum number of locals for function / method body +max-locals=15 + +# Maximum number of return / yield for function / method body +max-returns=6 + +# Maximum number of branch for function / method body +max-branches=12 + +# Maximum number of statements in function / method body +max-statements=50 + +# Maximum number of parents for a class (see R0901). +max-parents=7 + +# Maximum number of attributes for a class (see R0902). +max-attributes=7 + +# Minimum number of public methods for a class (see R0903). +min-public-methods=2 + +# Maximum number of public methods for a class (see R0904). +max-public-methods=20 + + +[IMPORTS] + +# Deprecated modules which should not be used, separated by a comma +deprecated-modules=regsub,TERMIOS,Bastion,rexec + +# Create a graph of every (i.e. internal and external) dependencies in the +# given file (report RP0402 must not be disabled) +import-graph= + +# Create a graph of external dependencies in the given file (report RP0402 must +# not be disabled) +ext-import-graph= + +# Create a graph of internal dependencies in the given file (report RP0402 must +# not be disabled) +int-import-graph= + + +[EXCEPTIONS] + +# Exceptions that will emit a warning when being caught. Defaults to +# "Exception" +overgeneral-exceptions=Exception From 7b25b21f5621dc71a4da6bd77dd5f5aef40e942b Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Mon, 22 Jun 2015 17:24:05 +0100 Subject: [PATCH 17/43] Customize pylintrc --- .pylintrc | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/.pylintrc b/.pylintrc index 884c8520..37d7b471 100644 --- a/.pylintrc +++ b/.pylintrc @@ -12,7 +12,7 @@ profile=no # Add files or directories to the blacklist. They should be base names, not # paths. -ignore=CVS +ignore=CVS,CardNames.py,scard.py # Pickle collected data for later comparisons. persistent=yes @@ -21,14 +21,6 @@ persistent=yes # usually to register additional checkers. load-plugins= -# Deprecated. It was used to include message's id in output. Use --msg-template -# instead. -include-ids=no - -# Deprecated. It was used to include symbolic ids of messages in output. Use -# --msg-template instead. -symbols=no - # Use multiple processes to speed up Pylint. jobs=1 @@ -218,16 +210,16 @@ name-group= include-naming-hint=no # Regular expression matching correct function names -function-rgx=[a-z_][a-z0-9_]{2,30}$ +function-rgx=[a-z_][a-zA-Z0-9_]{2,30}$ # Naming hint for function names -function-name-hint=[a-z_][a-z0-9_]{2,30}$ +function-name-hint=[a-z_][a-zA-Z0-9_]{2,30}$ # Regular expression matching correct variable names -variable-rgx=[a-z_][a-z0-9_]{2,30}$ +variable-rgx=[a-z_][a-zA-Z0-9_]{1,30}$ # Naming hint for variable names -variable-name-hint=[a-z_][a-z0-9_]{2,30}$ +variable-name-hint=[a-z_][a-zA-Z0-9_]{1,30}$ # Regular expression matching correct constant names const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ @@ -236,22 +228,22 @@ const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$ # Regular expression matching correct attribute names -attr-rgx=[a-z_][a-z0-9_]{2,30}$ +attr-rgx=[A-Za-z_][A-Za-z0-9_]{1,30}$ # Naming hint for attribute names -attr-name-hint=[a-z_][a-z0-9_]{2,30}$ +attr-name-hint=[A-Za-z_][A-Za-z0-9_]{1,30}$ # Regular expression matching correct argument names -argument-rgx=[a-z_][a-z0-9_]{2,30}$ +argument-rgx=[a-z_][A-Za-z0-9_]{2,30}$ # Naming hint for argument names -argument-name-hint=[a-z_][a-z0-9_]{2,30}$ +argument-name-hint=[a-z_][A-Za-z0-9_]{2,30}$ # Regular expression matching correct class attribute names -class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ +class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{1,30}|(__.*__))$ # Naming hint for class attribute names -class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ +class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{1,30}|(__.*__))$ # Regular expression matching correct inline iteration names inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ @@ -266,16 +258,16 @@ class-rgx=[A-Z_][a-zA-Z0-9]+$ class-name-hint=[A-Z_][a-zA-Z0-9]+$ # Regular expression matching correct module names -module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ +module-rgx=([A-Za-z_][A-Za-z0-9_]*)$ # Naming hint for module names -module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ +module-name-hint=([A-Za-z_][A-Za-z0-9_]*)$ # Regular expression matching correct method names -method-rgx=[a-z_][a-z0-9_]{2,30}$ +method-rgx=[a-z_][A-Za-z0-9_]{2,30}$ # Naming hint for method names -method-name-hint=[a-z_][a-z0-9_]{2,30}$ +method-name-hint=[a-z_][A-Za-z0-9_]{2,30}$ # Regular expression which should only match function or class names that do # not require a docstring. From e1bba4b5cc6c700dc52f15078b559eb49df161ba Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Mon, 22 Jun 2015 18:18:43 +0100 Subject: [PATCH 18/43] Fix most major pylint errors and warnings 5 undefined variables remain unfixed, they appear to be missing `smartcard.scard.scard` exports ``` ************* Module smartcard.pcsc.PCSCReader E: 67,22: Undefined variable 'SCardIntroduceReader' (undefined-variable) E: 70,22: Undefined variable 'SCardAddReaderToGroup' (undefined- variable) E: 85,22: Undefined variable 'SCardRemoveReaderFromGroup' (undefined- variable) ************* Module smartcard.pcsc.PCSCReaderGroups E: 66,22: Undefined variable 'SCardIntroduceReaderGroup' (undefined- variable) E: 90,22: Undefined variable 'SCardForgetReaderGroup' (undefined- variable) ``` --- smartcard/Card.py | 1 - smartcard/CardConnection.py | 2 -- smartcard/CardMonitoring.py | 4 ---- smartcard/CardService.py | 1 - smartcard/CardType.py | 1 + smartcard/ClassLoader.py | 4 ---- smartcard/ExclusiveConnectCardConnection.py | 1 - smartcard/ExclusiveTransmitCardConnection.py | 2 -- smartcard/Observer.py | 2 +- smartcard/PassThruCardService.py | 1 - smartcard/ReaderMonitoring.py | 4 +--- smartcard/Session.py | 6 ------ smartcard/guid.py | 1 - smartcard/pcsc/PCSCCardConnection.py | 5 ++--- smartcard/pcsc/PCSCPart10.py | 4 ++-- smartcard/pyro/PyroReader.py | 3 +-- smartcard/pyro/server/PyroDaemon.py | 4 ++-- smartcard/pyro/server/PyroEventServer.py | 1 - smartcard/pyro/server/RemoteCardConnection.py | 3 --- smartcard/pyro/server/RemoteReaderServer.py | 4 ---- smartcard/reader/ReaderGroups.py | 3 --- smartcard/sw/ErrorChecker.py | 2 +- smartcard/util/__init__.py | 5 +---- smartcard/wx/APDUHexValidator.py | 2 +- smartcard/wx/CardAndReaderTreePanel.py | 4 ++-- smartcard/wx/ReaderToolbar.py | 4 ++-- smartcard/wx/SimpleSCardAppFrame.py | 7 ++++--- 27 files changed, 21 insertions(+), 60 deletions(-) diff --git a/smartcard/Card.py b/smartcard/Card.py index b82fad52..a261c744 100644 --- a/smartcard/Card.py +++ b/smartcard/Card.py @@ -21,7 +21,6 @@ along with pyscard; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from smartcard.Exceptions import CardConnectionException, NoCardException from smartcard.reader.Reader import Reader from smartcard.System import readers from smartcard.util import toHexString diff --git a/smartcard/CardConnection.py b/smartcard/CardConnection.py index 607185e0..15bb52b2 100644 --- a/smartcard/CardConnection.py +++ b/smartcard/CardConnection.py @@ -24,8 +24,6 @@ """ from smartcard.CardConnectionEvent import CardConnectionEvent -from smartcard.Exceptions import SmartcardException -from smartcard.Observer import Observer from smartcard.Observer import Observable diff --git a/smartcard/CardMonitoring.py b/smartcard/CardMonitoring.py index e0273a93..30991e30 100644 --- a/smartcard/CardMonitoring.py +++ b/smartcard/CardMonitoring.py @@ -32,12 +32,9 @@ from time import sleep import traceback -from smartcard.System import readers -from smartcard.Exceptions import CardRequestTimeoutException from smartcard.Observer import Observer from smartcard.Observer import Observable -from smartcard.CardType import AnyCardType from smartcard.CardRequest import CardRequest _START_ON_DEMAND_ = False @@ -216,7 +213,6 @@ def __getattr__(self, name): if __name__ == "__main__": - from smartcard.CardMonitoring import CardMonitor print 'insert or remove cards in the next 10 seconds' # a simple card observer that prints added/removed cards diff --git a/smartcard/CardService.py b/smartcard/CardService.py index b310f19a..0a2cf27a 100644 --- a/smartcard/CardService.py +++ b/smartcard/CardService.py @@ -30,7 +30,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from smartcard.Exceptions import SmartcardException from smartcard.scard import * diff --git a/smartcard/CardType.py b/smartcard/CardType.py index 722a1cd1..d88ad047 100644 --- a/smartcard/CardType.py +++ b/smartcard/CardType.py @@ -21,6 +21,7 @@ along with pyscard; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ +from smartcard.Exceptions import InvalidATRMaskLengthException from smartcard.System import readers from smartcard.util import toHexString diff --git a/smartcard/ClassLoader.py b/smartcard/ClassLoader.py index 3b232152..3cc59c56 100644 --- a/smartcard/ClassLoader.py +++ b/smartcard/ClassLoader.py @@ -9,10 +9,6 @@ License: PSF license (http://docs.python.org/license.html). """ -import sys -import types - - def get_mod(modulePath): """Import a module.""" return __import__(modulePath, globals(), locals(), ['']) diff --git a/smartcard/ExclusiveConnectCardConnection.py b/smartcard/ExclusiveConnectCardConnection.py index 8d1f0cbf..ee3524ce 100644 --- a/smartcard/ExclusiveConnectCardConnection.py +++ b/smartcard/ExclusiveConnectCardConnection.py @@ -21,7 +21,6 @@ along with pyscard; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from smartcard.CardConnection import CardConnection from smartcard.CardConnectionDecorator import CardConnectionDecorator from smartcard.Exceptions import CardConnectionException from smartcard.scard import SCardConnect, SCardDisconnect diff --git a/smartcard/ExclusiveTransmitCardConnection.py b/smartcard/ExclusiveTransmitCardConnection.py index bbffa4da..ca836373 100644 --- a/smartcard/ExclusiveTransmitCardConnection.py +++ b/smartcard/ExclusiveTransmitCardConnection.py @@ -21,13 +21,11 @@ along with pyscard; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from smartcard.CardConnection import CardConnection from smartcard.CardConnectionDecorator import CardConnectionDecorator from smartcard.Exceptions import CardConnectionException from smartcard.scard import SCardBeginTransaction, SCardEndTransaction from smartcard.scard import SCARD_LEAVE_CARD from smartcard.scard import SCardGetErrorMessage -from smartcard.pcsc import PCSCCardConnection import smartcard.pcsc diff --git a/smartcard/Observer.py b/smartcard/Observer.py index b5f2b4ca..ce1d94fc 100644 --- a/smartcard/Observer.py +++ b/smartcard/Observer.py @@ -19,7 +19,7 @@ class Observer(object): - def update(observable, arg): + def update(self, observable, arg): '''Called when the observed object is modified. You call an Observable object's notifyObservers method to notify all the diff --git a/smartcard/PassThruCardService.py b/smartcard/PassThruCardService.py index d22a48a3..25715354 100644 --- a/smartcard/PassThruCardService.py +++ b/smartcard/PassThruCardService.py @@ -53,7 +53,6 @@ def supports(cardname): SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02] DF_TELECOM = [0x7F, 0x10] from smartcard.System import readers - from smartcard.CardConnection import CardConnection cc = readers()[0].createConnection() cs = PassThruCardService(cc) cs.connection.connect() diff --git a/smartcard/ReaderMonitoring.py b/smartcard/ReaderMonitoring.py index 62aab450..cebcb07c 100644 --- a/smartcard/ReaderMonitoring.py +++ b/smartcard/ReaderMonitoring.py @@ -28,12 +28,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from threading import Thread, Event, enumerate +from threading import Thread, Event from time import sleep import traceback import smartcard.System -from smartcard.Exceptions import ListReadersException from smartcard.Observer import Observer from smartcard.Observer import Observable from smartcard.Synchronization import * @@ -196,7 +195,6 @@ def stop(self): self.join() if __name__ == "__main__": - from smartcard.ReaderMonitoring import ReaderMonitor print 'insert or remove readers in the next 20 seconds' # a simple reader observer that prints added/removed readers diff --git a/smartcard/Session.py b/smartcard/Session.py index a700eddb..78515999 100644 --- a/smartcard/Session.py +++ b/smartcard/Session.py @@ -24,7 +24,6 @@ """ from smartcard.Exceptions import InvalidReaderException, NoReadersException -from smartcard.CardConnection import CardConnection from smartcard.PassThruCardService import PassThruCardService from smartcard.System import readers @@ -110,8 +109,3 @@ def getATR(self): def __repr__(self): """Returns a string representation of the session.""" return "" % self.readerName - - -if __name__ == '__main__': - """Small sample illustrating the use of Session.py.""" - pass diff --git a/smartcard/guid.py b/smartcard/guid.py index c8715a72..497f25bf 100644 --- a/smartcard/guid.py +++ b/smartcard/guid.py @@ -60,7 +60,6 @@ def GUIDToStr(g): if __name__ == "__main__": """Small sample illustrating the use of guid.py.""" - import smartcard.guid dummycardguid1 = strToGUID('{AD4F1667-EA75-4124-84D4-641B3B197C65}') print dummycardguid1 print GUIDToStr(dummycardguid1) diff --git a/smartcard/pcsc/PCSCCardConnection.py b/smartcard/pcsc/PCSCCardConnection.py index 08ea84a9..fee3234b 100644 --- a/smartcard/pcsc/PCSCCardConnection.py +++ b/smartcard/pcsc/PCSCCardConnection.py @@ -25,7 +25,6 @@ from smartcard.CardConnection import CardConnection from smartcard.Exceptions import (CardConnectionException, NoCardException, SmartcardException) -from smartcard.Observer import Observable from smartcard.scard import * @@ -240,8 +239,8 @@ def doGetAttrib(self, attribId): """Small sample illustrating the use of CardConnection.""" SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02] DF_TELECOM = [0x7F, 0x10] - from smartcard.pcsc.PCSCReader import readers - cc = readers()[0].createConnection() + from smartcard.pcsc.PCSCReader import PCSCReader + cc = PCSCReader.readers()[0].createConnection() cc.connect() print "%r %x %x" % cc.transmit(SELECT + DF_TELECOM) diff --git a/smartcard/pcsc/PCSCPart10.py b/smartcard/pcsc/PCSCPart10.py index 927bc3a1..dbd99985 100644 --- a/smartcard/pcsc/PCSCPart10.py +++ b/smartcard/pcsc/PCSCPart10.py @@ -227,8 +227,8 @@ def getTlvProperties(cardConnection, featureList=None, controlCode=None): if __name__ == '__main__': """Small sample illustrating the use of PCSCPart10.""" - from smartcard.pcsc.PCSCReader import readers - cc = readers()[0].createConnection() + from smartcard.pcsc.PCSCReader import PCSCReader + cc = PCSCReader.readers()[0].createConnection() cc.connect(mode=SCARD_SHARE_DIRECT) #print cc.control( CM_IOCTL_GET_FEATURE_REQUEST ) diff --git a/smartcard/pyro/PyroReader.py b/smartcard/pyro/PyroReader.py index 7023cc89..a6fe396f 100644 --- a/smartcard/pyro/PyroReader.py +++ b/smartcard/pyro/PyroReader.py @@ -25,9 +25,8 @@ import Pyro.core import Pyro.naming -from smartcard.Exceptions import CardConnectionException, NoCardException +from smartcard.Exceptions import NoCardException from smartcard.reader.Reader import Reader -from smartcard.reader.ReaderFactory import ReaderFactory class PyroReader(Reader): diff --git a/smartcard/pyro/server/PyroDaemon.py b/smartcard/pyro/server/PyroDaemon.py index 89b5d1ae..90eac204 100644 --- a/smartcard/pyro/server/PyroDaemon.py +++ b/smartcard/pyro/server/PyroDaemon.py @@ -85,8 +85,8 @@ def __init__(self): Thread.__init__(self) self.setDaemon(True) self.setName('smartcard.pyro.server.PyroDaemonThread') - self.daemon = PyroDaemon() + self._daemon = PyroDaemon() def run(self): """Starts Pyro daemon.""" - self.daemon.start() + self._daemon.start() diff --git a/smartcard/pyro/server/PyroEventServer.py b/smartcard/pyro/server/PyroEventServer.py index 90c4d998..2503e082 100644 --- a/smartcard/pyro/server/PyroEventServer.py +++ b/smartcard/pyro/server/PyroEventServer.py @@ -92,7 +92,6 @@ def __call__(self, signame, sf): if __name__ == '__main__': - import sys from smartcard.pyro.server.PyroNameServer import PyroNameServer pn = PyroNameServer(sys.argv[1:]) pn.start() diff --git a/smartcard/pyro/server/RemoteCardConnection.py b/smartcard/pyro/server/RemoteCardConnection.py index 9df373ee..2b092b7c 100644 --- a/smartcard/pyro/server/RemoteCardConnection.py +++ b/smartcard/pyro/server/RemoteCardConnection.py @@ -26,10 +26,7 @@ import Pyro.core import Pyro.naming -from smartcard.CardConnection import CardConnection from smartcard.CardConnectionDecorator import CardConnectionDecorator -from smartcard.Exceptions import CardConnectionException, NoCardException -from smartcard.Observer import Observable class RemoteCardConnection(CardConnectionDecorator, Pyro.core.ObjBase): diff --git a/smartcard/pyro/server/RemoteReaderServer.py b/smartcard/pyro/server/RemoteReaderServer.py index f29096de..f3e715fe 100644 --- a/smartcard/pyro/server/RemoteReaderServer.py +++ b/smartcard/pyro/server/RemoteReaderServer.py @@ -32,10 +32,6 @@ import sys sys.exit() -import signal -import time - -import smartcard.System from smartcard.reader.Reader import Reader from smartcard.ReaderMonitoring import ReaderMonitor, ReaderObserver from smartcard.pyro.server.RemoteCardConnection import RemoteCardConnection diff --git a/smartcard/reader/ReaderGroups.py b/smartcard/reader/ReaderGroups.py index 4e6cfbc1..64475944 100644 --- a/smartcard/reader/ReaderGroups.py +++ b/smartcard/reader/ReaderGroups.py @@ -67,9 +67,6 @@ def __onremoveitem__(self, item): def __iter__(self): return ulist.__iter__(self) - def next(self): - return ulist.__next__(self) - # # abstract methods implemented in subclasses # diff --git a/smartcard/sw/ErrorChecker.py b/smartcard/sw/ErrorChecker.py index d29f0478..1296ff22 100644 --- a/smartcard/sw/ErrorChecker.py +++ b/smartcard/sw/ErrorChecker.py @@ -36,7 +36,7 @@ class ErrorChecker(object): pattern. """ - def __call__(data, sw1, sw2): + def __call__(self, data, sw1, sw2): """Called to test data, sw1 and sw2 for error. @param data: apdu response data diff --git a/smartcard/util/__init__.py b/smartcard/util/__init__.py index 2a8233a8..68fe0ba6 100644 --- a/smartcard/util/__init__.py +++ b/smartcard/util/__init__.py @@ -99,7 +99,7 @@ def toBytes(bytestring): """ import struct import re - packedstring = ''.join(re.split('\W+', bytestring)) + packedstring = ''.join(re.split(r'\W+', bytestring)) try: return reduce(lambda x, y: x + [int(y, 16)], struct.unpack('2s' * (len(packedstring) / 2), @@ -204,9 +204,6 @@ def toHexString(bytes=[], format=0): from string import rstrip - for byte in tuple(bytes): - pass - if type(bytes) is not list: raise TypeError('not a list of bytes') diff --git a/smartcard/wx/APDUHexValidator.py b/smartcard/wx/APDUHexValidator.py index dd090ddf..4e16ceb6 100644 --- a/smartcard/wx/APDUHexValidator.py +++ b/smartcard/wx/APDUHexValidator.py @@ -48,7 +48,7 @@ def Clone(self): def Validate(self, win): tc = self.GetWindow() - val = tc.GetValue() + value = tc.GetValue() if not apduregexp.match(value): return False diff --git a/smartcard/wx/CardAndReaderTreePanel.py b/smartcard/wx/CardAndReaderTreePanel.py index 0841ec1d..8106ef9f 100644 --- a/smartcard/wx/CardAndReaderTreePanel.py +++ b/smartcard/wx/CardAndReaderTreePanel.py @@ -408,9 +408,9 @@ def __init__(self, parent, appstyle, clientpanel): def OnDestroy(self, event): """Called on panel destruction.""" # deregister observers - if hasattr(self, cardmonitor): + if hasattr(self, 'cardmonitor'): self.cardmonitor.deleteObserver(self.cardtreecardobserver) - if hasattr(self, readermonitor): + if hasattr(self, 'readermonitor'): self.readermonitor.deleteObserver(self.readertreereaderobserver) self.cardmonitor.deleteObserver(self.readertreecardobserver) event.Skip() diff --git a/smartcard/wx/ReaderToolbar.py b/smartcard/wx/ReaderToolbar.py index 946dfab0..fd353be8 100644 --- a/smartcard/wx/ReaderToolbar.py +++ b/smartcard/wx/ReaderToolbar.py @@ -77,12 +77,12 @@ def __init__(self, parent): bmpReader = wx.Bitmap(ICO_READER, wx.BITMAP_TYPE_ICO) else: bmpReader = wx.ArtProvider_GetBitmap( - wx.ART_HELP_BOOK, wx.ART_OTHER, isz) + wx.ART_HELP_BOOK, wx.ART_OTHER, tsize) if None != ICO_SMARTCARD: bmpCard = wx.Bitmap(ICO_SMARTCARD, wx.BITMAP_TYPE_ICO) else: bmpCard = wx.ArtProvider_GetBitmap( - wx.ART_HELP_BOOK, wx.ART_OTHER, isz) + wx.ART_HELP_BOOK, wx.ART_OTHER, tsize) self.readercombobox = ReaderComboBox(self) # create and add controls diff --git a/smartcard/wx/SimpleSCardAppFrame.py b/smartcard/wx/SimpleSCardAppFrame.py index cd5166cc..193c8a56 100644 --- a/smartcard/wx/SimpleSCardAppFrame.py +++ b/smartcard/wx/SimpleSCardAppFrame.py @@ -26,10 +26,11 @@ import os.path import wx + import smartcard.wx -import APDUTracerPanel -import CardAndReaderTreePanel -import ReaderToolbar +from smartcard.wx import APDUTracerPanel +from smartcard.wx import CardAndReaderTreePanel +from smartcard.wx import ReaderToolbar import smartcard from smartcard.wx.SimpleSCardAppEventObserver import \ From 568d577996ef33d168108f0698d8ae215fc72c3c Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Tue, 23 Jun 2015 11:00:40 +0100 Subject: [PATCH 19/43] Consolidate Changelog, LICENSE, README etc into root dir. Delete PKG-INFO PKG-INFO and included in the sdist package each time setup.py is run. Storing it in source control is redundant. --- smartcard/ACKS => ACKS | 0 smartcard/ChangeLog => ChangeLog | 0 MANIFEST.in | 8 +- PKG-INFO | 20 -- smartcard/TODO => TODO | 0 setup.py | 7 - smartcard/LICENSE | 457 ------------------------------- smartcard/README | 431 ----------------------------- 8 files changed, 3 insertions(+), 920 deletions(-) rename smartcard/ACKS => ACKS (100%) rename smartcard/ChangeLog => ChangeLog (100%) delete mode 100644 PKG-INFO rename smartcard/TODO => TODO (100%) delete mode 100644 smartcard/LICENSE delete mode 100644 smartcard/README diff --git a/smartcard/ACKS b/ACKS similarity index 100% rename from smartcard/ACKS rename to ACKS diff --git a/smartcard/ChangeLog b/ChangeLog similarity index 100% rename from smartcard/ChangeLog rename to ChangeLog diff --git a/MANIFEST.in b/MANIFEST.in index c1378422..51c32b48 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,11 +1,9 @@ include LICENSE include MANIFEST.in include README -include smartcard/ACKS -include smartcard/ChangeLog -include smartcard/LICENSE -include smartcard/README -include smartcard/TODO +include ACKS +include ChangeLog +include TODO include smartcard/scard/gemalto.ver include smartcard/scard/helpers.c include smartcard/scard/helpers.h diff --git a/PKG-INFO b/PKG-INFO deleted file mode 100644 index 76dd1a23..00000000 --- a/PKG-INFO +++ /dev/null @@ -1,20 +0,0 @@ -Metadata-Version: 1.0 -Name: pyscard -Version: 1.6.16 -Summary: Smartcard module for Python. -Home-page: http://pyscard.sourceforge.net/ -Author: Jean-Daniel Aussel -Author-email: aussel.jean-daniel@gemalto.com -License: GNU LESSER GENERAL PUBLIC LICENSE -Download-URL: http://sourceforge.net/projects/pyscard/ -Description: Smartcard package for Python -Platform: linux -Platform: win32 -Platform: Mac OSX -Classifier: Development Status :: 1.6.16 - Release -Classifier: License :: GNU LESSER GENERAL PUBLIC LICENSE -Classifier: Intended Audience :: Developers -Classifier: Operating System :: Unix -Classifier: Operating System :: Microsoft :: Windows -Classifier: Operating System :: MacOS :: MacOS X -Classifier: Topic :: Security :: Smartcards diff --git a/smartcard/TODO b/TODO similarity index 100% rename from smartcard/TODO rename to TODO diff --git a/setup.py b/setup.py index e2046d2b..784be39e 100755 --- a/setup.py +++ b/setup.py @@ -98,13 +98,6 @@ ], 'package_dir': {"": "."}, 'package_data': { - "smartcard": [ - "ACKS", - "ChangeLog", - "LICENSE", - "README", - "TODO", - ], "smartcard/wx": ["resources/*.ico"], }, diff --git a/smartcard/LICENSE b/smartcard/LICENSE deleted file mode 100644 index 4ef74084..00000000 --- a/smartcard/LICENSE +++ /dev/null @@ -1,457 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - diff --git a/smartcard/README b/smartcard/README deleted file mode 100644 index 7e0c7bb9..00000000 --- a/smartcard/README +++ /dev/null @@ -1,431 +0,0 @@ -------------------------------------------------------------------------------- -pyscard smartcard library for python -------------------------------------------------------------------------------- -http://pyscard.sourceforge.net/ -------------------------------------------------------------------------------- - -Copyright 2001-2012 gemalto -Author: Jean-Daniel Aussel, mailto:jean-daniel.aussel@gemalto.com - -This file is part of pyscard. - -pyscard is free software; you can redistribute it and/or modify it under -the terms of the GNU Lesser General Public License as published by the -Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -pyscard is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with pyscard; if not, write to the Free Software Foundation, Inc., -51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -------------------------------------------------------------------------------- -Last update : pyscard 1.6.16 (Decembre 2012) -------------------------------------------------------------------------------- - -pyscard is a python module adding smart cards support to python. - -It consists of the smartcard.scard module, an extension module wrapping -Windows smart card base components (also known as PCSC) on Windows, and -PCSC lite on linux and Mac OS X Tiger, and of the smartcard module, a -python framework with objects wrapping PCSC API. - - -------------------------------------------------------------------------------- -Documentation -------------------------------------------------------------------------------- - -All documentation is provided in the smartcard/doc directory of the -source distribution. Examples are provided in the smartcard/Examples -directory of the source distribution. The binary distribution does not -include any documentation, tests scripts or examples. - - -------------------------------------------------------------------------------- -Installation -------------------------------------------------------------------------------- - -The pyscard library is packaged using the standard distutils python -module. - -Installation on windows ------------------------ - -Installing on windows from the binary distribution --------------------------------------------------- - -1. download the binary msi installer or self-executable installer -2. execute the installer - -The binary msi installer and self-executable installer are packaged for -a specific version of python, and have name similar to -pyscard-1.6.16.win32-py2.5.msi and pyscard-1.6.16.win32-py2.5.exe for -python 2.5. - - -Installing on windows from the source distribution ---------------------------------------------------- - -1. you will need swig 1.3.31 from http://www.swig.org, and a C compiler. - -By default, Visual Studio 2003 is required for building the c language -wrapper for python 2.5, and Visual Studio .Net or VisualC++ 6 for python -2.4. You might use another release by fiddling with the -python/Lib/distutils/msvccompiler.py file that detects the compiler. - -2. download the source distribution - -The source distribution is available as pyscard-1.6.16.zip for windows, -and pyscard-1.6.16.tar.gz for linux. - -3. unzip the source distribution, open a console and type the following: - -setup.py build_ext install - -This will build pyscard and install it in the site-packages directory of -your python distribution, e.g. c:\python25\Lib\site-packages\smartcard. - -This install procedure does not install the documentation, examples or test -files. - -Installation on linux: ----------------------- - -Installing on linux from the binary distribution: -------------------------------------------------- - -1. download the binary distribution - -The binary distribution is either an archive file or a rpm file, with -names similar to pyscard-1.6.16-1.i386.rpm for the rpm distribution, or -pyscard-1.6.16.linux-i686.tar.gz for the archive distribution. - -2. untar the binary distribution - -With root privilege from a terminal, extract the archive from /, or -install the rpm. - -Installing on linux from the source distribution ------------------------------------------------- - -1. you will need gcc, swig 1.3.31 (http://www.swig.org), and pcsc-lite -(http://pcsclite.alioth.debian.org/) - -2. download the source distribution - -The source distribution is available as pyscard-1.6.16.zip or -pyscard-1.6.16.tar.gz. - -3. untar the source distribution - -4. from a terminal with root privileges, type the following: - -/usr/bin/python setup.py build_ext install - -This will build pyscard and install it in the site-packages directory of -your python distribution, e.g. -/usr/lib/python2.4/site-packages/smartcard. - -Installation on Max OS X Tiger: --------------------------------- - -The Mac OS X Tiger support is experimental on pyscard 1.6.16. It was -developed and tested on a i386 MacBook Pro. Please drop me a mail if you -succeed on a ppc MacBook. - -Installing on Mac OS X Tiger from the binary distribution: ----------------------------------------------------- - -1. download the binary distribution - -The binary distribution is an archive file, with a name similar to -pyscard-1.6.16-py-2.3-macosx10.4.mpkg or -pyscard-1.6.16-py-2.5-macosx10.4.mpkg. - -2. Open the package and proceed with installation. - -Python 2.3 is pre-installed, so install -pyscard-1.6.16-py-2.3-macosx10.4.mpkg if you did not install another -release of python. - -Install pyscard-1.6.16-py-2.5-macosx10.4.mpkg if you installed python 2.5. - -Installing on Mac OS X Tiger from the source distribution ----------------------------------------------------------- - -1. you will need swig 1.3.31 (http://www.swig.org); gcc and pcsc-lite -are available out of the box on Max OS X Tiger - -2. download the source distribution - -The source distribution is available as pyscard-1.6.16.zip or -pyscard-1.6.16.tar.gz. - -3. untar or unzip the source distribution - -4. from a terminal, type the following: - -sudo python setup.py build_ext install - -This will build pyscard and install it in the site-packages directory of -your python distribution, e.g. -/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/lib/site-packages/smartcard - - -Installation on Max OS X Leopard: ---------------------------------- - -Installing on Mac OS X Leopard from the binary distribution: ----------------------------------------------------- - -1. download the binary distribution - -The binary distribution is an archive file, with a name similar to -pyscard-1.6.16-py-2.5-macosx10.5.mpkg. - -2. Open the package and proceed with installation. - -Installing on Mac OS X Leopard from the source distribution ------------------------------------------------------------- - -1. you will need swig 1.3.31 (http://www.swig.org); gcc and pcsc-lite -are available out of the box on Max OS X Leopard - -2. download the source distribution - -The source distribution is available as pyscard-1.6.16.zip or -pyscard-1.6.16.tar.gz. - -3. untar or unzip the source distribution - -4. from a terminal, type the following: - -sudo python setup.py build_ext install - -This will build pyscard and install it in the site-packages directory of -your python distribution, e.g. -/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.3/lib/site-packages/smartcard - - -Installation on Max OS X Lion: ------------------------------- - -Installing on Mac OS X Lion from the binary distribution: ----------------------------=====------------------------- - -1. download the binary distribution - -The binary distribution is an archive file, with a name similar to -pyscard-1.6.16-py-2.7-macosx10.7.mpkg. - -2. Open the package and proceed with installation. - -Installing on Mac OS X Lion from the source distribution --------------------------------------------------------- - -1. you will need swig 2.0.4 (http://www.swig.org) and Xcode -(http://developer.apple.com/xcode/); -pcsc-lite is available out of the box on Max OS X Leopard - -2. download the source distribution - -The source distribution is available as pyscard-1.6.16.zip or -pyscard-1.6.16.tar.gz. - -3. untar or unzip the source distribution - -4. from a terminal, type the following: - -sudo python setup.py build_ext install - -This will build pyscard and install it in the site-packages directory of -your python distribution, e.g. /Library/Python/2.7/lib/site-packages/smartcard - - -------------------------------------------------------------------------------- -Developer documentation, unit tests and examples -------------------------------------------------------------------------------- -The developer documentation is in the smartcard/doc directory of the -source distribution. - -Examples are located in the smartcard/Examples directory, and the pyunit -unit tests in the smartcard/test directory. - -------------------------------------------------------------------------------- -Build instructions for packagers -------------------------------------------------------------------------------- - -Building a binary distribution for Windows ------------------------------------------- - -To build a binary distribution from the source distribution, you will -need a C compiler and swig 1.3.31 (same requirements as for installing -from the source distribution). - -In the root directory of the source distribution, execute the following -command in a console: - -setup.py build_ext bdist_msi -setup.py build_ext bdist_wininst - -This will build the msi installer and self-executable installer in the -dist directory, with names similar to pyscard-1.6.16.win32-py2.5.msi and -pyscard-1.6.16.win32-py2.5.exe for python 2.5, and -pyscard-1.6.16.win32-py2.4.msi and pyscard-1.6.16.win32-py2.4.exe for -python 2.4. - -Building a binary distribution for linux ----------------------------------------- - -To build a binary distribution from the source distribution, you will -need gcc, swig 1.3.31 and pcsc-lite (same requirements as for installing -from the source distribution). - -In the root directory of the source distribution, execute the following -command in a terminal: - -/usr/bin/python setup.py build_ext bdist - -This will build a package similar to pyscard-1.6.16.linux-i686.tar.gz -containing a tree - -Building a rpm distribution for linux ----------------------------------------- - -To build a rpm distribution from the source distribution, you will need -gcc, swig 1.3.31 and pcsc-lite (same requirements as for installing from -the source distribution). - -In the root directory of the source distribution, execute the following -command in a terminal: - -/usr/bin/python setup.py build bdist_rpm - -If you have rpm 4.1 or above, you will need to add the -%_unpackaged_files_terminate_build 0 options to the /etc/rpm/macros file, -e.g.: - -echo "%_unpackaged_files_terminate_build 0" >> /etc/rpm/macros - -This will build in the dist directory a binary distribution with a name -similar to pyscard-1.6.16-1.i386.rpm. - -Building a binary distribution for Mac OS X Tiger -------------------------------------------------- - -To build a binary distribution from the source distribution, you will -need swig 1.3.31 (same requirements as for installing from the source -distribution) and bdist_mpkg 0.4.3 -(http://cheeseshop.python.org/pypi/bdist_mpkg/). - - -If you are using the pre-installed python 2.3 distribution, in the root -directory of the source distribution, i.e. in the src directory, execute -the following commands in a terminal: - -python setup.py build_ext -/System/Library/Frameworks/Python.Framework/Versions/2.3/bin/bdist_mpkg setup.py - -This will build package pyscard-1.6.16-py-2.3-macosx10.4.mpkg. - -If you are using python 2.5, in the root directory of the source distribution, -i.e. in the src directory, execute the following commands in a terminal: - -python setup.py build_ext -/Library/Frameworks/Python.Framework/Versions/2.5/bin/bdist_mpkg setup.py - -This will build package pyscard-1.6.16-py-2.6-macosx10.4.mpkg. - - -Building a binary distribution for Mac OS X Lion -------------------------------------------------- - -To build a binary distribution from the source distribution, you will -need swig 2.0.4 and Xcode (same requirements as for installing from the source -distribution) and bdist_mpkg 0.4.4 (http://pypi.python.org/pypi/bdist_mpkg/). - -Install bdist_mpkg by executing the bdist_mpkg setup.py script with -build and install as arguments, i.e. from the root directory of the -bdist_mpkg source distribution enter: python setup.py build install. - -From the root directory of the pyscard source distribution, -i.e. in the src directory, execute the following commands in a terminal: - -python setup.py build_ext -bdist_mpkg setup.py - -This will build package pyscard-1.6.16-py-2.7-macosx10.7.mpkg in the dist -directory. - -Building a binary distribution for Mac OS X Leopard ---------------------------------------------------- - -To build a binary distribution from the source distribution, you will -need swig 1.3.31 (same requirements as for installing from the source -distribution) and bdist_mpkg 0.4.3 -(http://cheeseshop.python.org/pypi/bdist_mpkg/). - -Apply the following patch to tools.py of bdist_mpkg package: - -===== patch start === -diff -rNu bdist_mpkg-0.4.3/bdist_mpkg/tools.py bdist_mpkg-0.4.3.leopard/bdist_mpkg/tools.py ---- bdist_mpkg-0.4.3/bdist_mpkg/tools.py 2006-07-09 00:39:00.000000000 -0400 -+++ bdist_mpkg-0.4.3.leopard/bdist_mpkg/tools.py 2008-08-21 07:43:35.000000000 -0400 -@@ -79,15 +79,12 @@ - yield os.path.join(root, fn) - - def get_gid(name, _cache={}): -- if not _cache: -- for line in os.popen('/usr/bin/nidump group .'): -- fields = line.split(':') -- if len(fields) >= 3: -- _cache[fields[0]] = int(fields[2]) -- try: -- return _cache[name] -- except KeyError: -- raise ValueError('group %s not found' % (name,)) -+ for line in os.popen("dscl . -read /Groups/" + name + " PrimaryGroupID"): -+ fields = [f.strip() for f in line.split(':')] -+ if fields[0] == "PrimaryGroupID": -+ return fields[1] -+ -+ raise ValueError('group %s not found' % (name,)) -===== patch end ======== - -This patch is required since Mac OS X Leopard does not have the nidump -command any more. - -Install bdist_mpkg by executing the bdist_mpkg setup.py script with -build and install as arguments, i.e. from the root directory of the -bdist_mpkg source distribution enter: python setup.py build install. - -For python 2.5, from the root directory of the pyscard source -distribution, i.e. in the src directory, execute the following commands -in a terminal: - -python setup.py build_ext -/Library/Frameworks/Python.Framework/Versions/2.5/Extras/bin/bdist_mpkg setup.py - -This will build package pyscard-1.6.16-py-2.5-macosx10.5.mpkg. - -For python 2.6, from the root directory of the pyscard source distribution, -i.e. in the src directory, execute the following commands in a terminal: - -python setup.py build_ext -/Library/Frameworks/Python.framework/Versions/2.6/bin/bdist_mpkg setup.py - -This will build package pyscard-1.6.16-py-2.6-macosx10.5.mpkg. - -------------------------------------------------------------------------------- -Issue Tracking -------------------------------------------------------------------------------- -If you encounter a bug, please report it in the SourceForge bug tracker at - http://sourceforge.net/tracker/?group_id=196342&atid=957072 - https://sourceforge.net/tracker/?group_id=196342&atid=957072 - - --jda From 5c50b3f7276c9172ad674e79b9014360cfad22e4 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Tue, 23 Jun 2015 11:10:59 +0100 Subject: [PATCH 20/43] Remove code supporting OS X Tiger --- .../Examples/scard-api/sample_control.py | 3 +- .../Examples/scard-api/sample_getAttrib.py | 103 +++++++++-------- smartcard/scard/PcscDefs.i | 5 - smartcard/scard/scard.i | 108 ------------------ smartcard/scard/winscarddll.c | 30 +---- smartcard/scard/winscarddll.h | 20 ---- .../test/framework/testcase_CardConnection.py | 19 ++- 7 files changed, 61 insertions(+), 227 deletions(-) diff --git a/smartcard/Examples/scard-api/sample_control.py b/smartcard/Examples/scard-api/sample_control.py index 87a11a9a..911dffb9 100755 --- a/smartcard/Examples/scard-api/sample_control.py +++ b/smartcard/Examples/scard-api/sample_control.py @@ -72,8 +72,7 @@ for i in xrange(len(response)): r += "%c" % response[i] print 'SCARD_ATTR_VENDOR_NAME:', r - elif 'pcsclite' == resourceManager and \ - not 'pcsclite-tiger' == resourceManagerSubType: + elif 'pcsclite' == resourceManager: # get firmware on Gemplus readers hresult, response = SCardControl( hcard, diff --git a/smartcard/Examples/scard-api/sample_getAttrib.py b/smartcard/Examples/scard-api/sample_getAttrib.py index 7b19c62a..01ef61d1 100755 --- a/smartcard/Examples/scard-api/sample_getAttrib.py +++ b/smartcard/Examples/scard-api/sample_getAttrib.py @@ -32,58 +32,57 @@ from smartcard.scard import * import smartcard.util -if 'pcsclite-tiger' == resourceManagerSubType: - attributes = {} -else: - attributes = { - SCARD_ATTR_ATR_STRING: 'SCARD_ATTR_ATR_STRING', - SCARD_ATTR_CHANNEL_ID: 'SCARD_ATTR_CHANNEL_ID', - SCARD_ATTR_CHARACTERISTICS: 'SCARD_ATTR_CHARACTERISTICS', - SCARD_ATTR_CURRENT_BWT: 'SCARD_ATTR_CURRENT_BWT', - SCARD_ATTR_CURRENT_CLK: 'SCARD_ATTR_CURRENT_CLK', - SCARD_ATTR_CURRENT_CWT: 'SCARD_ATTR_CURRENT_CWT', - SCARD_ATTR_CURRENT_D: 'SCARD_ATTR_CURRENT_D', - SCARD_ATTR_CURRENT_EBC_ENCODING: 'SCARD_ATTR_CURRENT_EBC_ENCODING', - SCARD_ATTR_CURRENT_F: 'SCARD_ATTR_CURRENT_F', - SCARD_ATTR_CURRENT_IFSC: 'SCARD_ATTR_CURRENT_IFSC', - SCARD_ATTR_CURRENT_IFSD: 'SCARD_ATTR_CURRENT_IFSD', - SCARD_ATTR_CURRENT_IO_STATE: 'SCARD_ATTR_CURRENT_IO_STATE', - SCARD_ATTR_CURRENT_N: 'SCARD_ATTR_CURRENT_N', - SCARD_ATTR_CURRENT_PROTOCOL_TYPE: 'SCARD_ATTR_CURRENT_PROTOCOL_TYPE', - SCARD_ATTR_CURRENT_W: 'SCARD_ATTR_CURRENT_W', - SCARD_ATTR_DEFAULT_CLK: 'SCARD_ATTR_DEFAULT_CLK', - SCARD_ATTR_DEFAULT_DATA_RATE: 'SCARD_ATTR_DEFAULT_DATA_RATE', - SCARD_ATTR_DEVICE_FRIENDLY_NAME_A: 'SCARD_ATTR_DEVICE_FRIENDLY_NAME_A', - SCARD_ATTR_DEVICE_FRIENDLY_NAME_W: 'SCARD_ATTR_DEVICE_FRIENDLY_NAME_W', - SCARD_ATTR_DEVICE_IN_USE: 'SCARD_ATTR_DEVICE_IN_USE', - SCARD_ATTR_DEVICE_SYSTEM_NAME_A: 'SCARD_ATTR_DEVICE_SYSTEM_NAME_A', - SCARD_ATTR_DEVICE_SYSTEM_NAME_W: 'SCARD_ATTR_DEVICE_SYSTEM_NAME_W', - SCARD_ATTR_DEVICE_UNIT: 'SCARD_ATTR_DEVICE_UNIT', - SCARD_ATTR_ESC_AUTHREQUEST: 'SCARD_ATTR_ESC_AUTHREQUEST', - SCARD_ATTR_ESC_CANCEL: 'SCARD_ATTR_ESC_CANCEL', - SCARD_ATTR_ESC_RESET: 'SCARD_ATTR_ESC_RESET', - SCARD_ATTR_EXTENDED_BWT: 'SCARD_ATTR_EXTENDED_BWT', - SCARD_ATTR_ICC_INTERFACE_STATUS: 'SCARD_ATTR_ICC_INTERFACE_STATUS', - SCARD_ATTR_ICC_PRESENCE: 'SCARD_ATTR_ICC_PRESENCE', - SCARD_ATTR_ICC_TYPE_PER_ATR: 'SCARD_ATTR_ICC_TYPE_PER_ATR', - SCARD_ATTR_MAXINPUT: 'SCARD_ATTR_MAXINPUT', - SCARD_ATTR_MAX_CLK: 'SCARD_ATTR_MAX_CLK', - SCARD_ATTR_MAX_DATA_RATE: 'SCARD_ATTR_MAX_DATA_RATE', - SCARD_ATTR_MAX_IFSD: 'SCARD_ATTR_MAX_IFSD', - SCARD_ATTR_POWER_MGMT_SUPPORT: 'SCARD_ATTR_POWER_MGMT_SUPPORT', - SCARD_ATTR_SUPRESS_T1_IFS_REQUEST: 'SCARD_ATTR_SUPRESS_T1_IFS_REQUEST', - SCARD_ATTR_USER_AUTH_INPUT_DEVICE: 'SCARD_ATTR_USER_AUTH_INPUT_DEVICE', - SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE: \ - 'SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE', - SCARD_ATTR_VENDOR_IFD_SERIAL_NO: 'SCARD_ATTR_VENDOR_IFD_SERIAL_NO', - SCARD_ATTR_VENDOR_IFD_TYPE: 'SCARD_ATTR_VENDOR_IFD_TYPE', - SCARD_ATTR_VENDOR_IFD_VERSION: 'SCARD_ATTR_VENDOR_IFD_VERSION', - SCARD_ATTR_VENDOR_NAME: 'SCARD_ATTR_VENDOR_NAME'} - if 'pcsclite' == resourceManager: - extra_attributes = { - SCARD_ATTR_ASYNC_PROTOCOL_TYPES: 'SCARD_ATTR_ASYNC_PROTOCOL_TYPES', - SCARD_ATTR_SYNC_PROTOCOL_TYPES: 'SCARD_ATTR_SYNC_PROTOCOL_TYPES'} - attributes.update(extra_attributes) +attributes = { + SCARD_ATTR_ATR_STRING: 'SCARD_ATTR_ATR_STRING', + SCARD_ATTR_CHANNEL_ID: 'SCARD_ATTR_CHANNEL_ID', + SCARD_ATTR_CHARACTERISTICS: 'SCARD_ATTR_CHARACTERISTICS', + SCARD_ATTR_CURRENT_BWT: 'SCARD_ATTR_CURRENT_BWT', + SCARD_ATTR_CURRENT_CLK: 'SCARD_ATTR_CURRENT_CLK', + SCARD_ATTR_CURRENT_CWT: 'SCARD_ATTR_CURRENT_CWT', + SCARD_ATTR_CURRENT_D: 'SCARD_ATTR_CURRENT_D', + SCARD_ATTR_CURRENT_EBC_ENCODING: 'SCARD_ATTR_CURRENT_EBC_ENCODING', + SCARD_ATTR_CURRENT_F: 'SCARD_ATTR_CURRENT_F', + SCARD_ATTR_CURRENT_IFSC: 'SCARD_ATTR_CURRENT_IFSC', + SCARD_ATTR_CURRENT_IFSD: 'SCARD_ATTR_CURRENT_IFSD', + SCARD_ATTR_CURRENT_IO_STATE: 'SCARD_ATTR_CURRENT_IO_STATE', + SCARD_ATTR_CURRENT_N: 'SCARD_ATTR_CURRENT_N', + SCARD_ATTR_CURRENT_PROTOCOL_TYPE: 'SCARD_ATTR_CURRENT_PROTOCOL_TYPE', + SCARD_ATTR_CURRENT_W: 'SCARD_ATTR_CURRENT_W', + SCARD_ATTR_DEFAULT_CLK: 'SCARD_ATTR_DEFAULT_CLK', + SCARD_ATTR_DEFAULT_DATA_RATE: 'SCARD_ATTR_DEFAULT_DATA_RATE', + SCARD_ATTR_DEVICE_FRIENDLY_NAME_A: 'SCARD_ATTR_DEVICE_FRIENDLY_NAME_A', + SCARD_ATTR_DEVICE_FRIENDLY_NAME_W: 'SCARD_ATTR_DEVICE_FRIENDLY_NAME_W', + SCARD_ATTR_DEVICE_IN_USE: 'SCARD_ATTR_DEVICE_IN_USE', + SCARD_ATTR_DEVICE_SYSTEM_NAME_A: 'SCARD_ATTR_DEVICE_SYSTEM_NAME_A', + SCARD_ATTR_DEVICE_SYSTEM_NAME_W: 'SCARD_ATTR_DEVICE_SYSTEM_NAME_W', + SCARD_ATTR_DEVICE_UNIT: 'SCARD_ATTR_DEVICE_UNIT', + SCARD_ATTR_ESC_AUTHREQUEST: 'SCARD_ATTR_ESC_AUTHREQUEST', + SCARD_ATTR_ESC_CANCEL: 'SCARD_ATTR_ESC_CANCEL', + SCARD_ATTR_ESC_RESET: 'SCARD_ATTR_ESC_RESET', + SCARD_ATTR_EXTENDED_BWT: 'SCARD_ATTR_EXTENDED_BWT', + SCARD_ATTR_ICC_INTERFACE_STATUS: 'SCARD_ATTR_ICC_INTERFACE_STATUS', + SCARD_ATTR_ICC_PRESENCE: 'SCARD_ATTR_ICC_PRESENCE', + SCARD_ATTR_ICC_TYPE_PER_ATR: 'SCARD_ATTR_ICC_TYPE_PER_ATR', + SCARD_ATTR_MAXINPUT: 'SCARD_ATTR_MAXINPUT', + SCARD_ATTR_MAX_CLK: 'SCARD_ATTR_MAX_CLK', + SCARD_ATTR_MAX_DATA_RATE: 'SCARD_ATTR_MAX_DATA_RATE', + SCARD_ATTR_MAX_IFSD: 'SCARD_ATTR_MAX_IFSD', + SCARD_ATTR_POWER_MGMT_SUPPORT: 'SCARD_ATTR_POWER_MGMT_SUPPORT', + SCARD_ATTR_SUPRESS_T1_IFS_REQUEST: 'SCARD_ATTR_SUPRESS_T1_IFS_REQUEST', + SCARD_ATTR_USER_AUTH_INPUT_DEVICE: 'SCARD_ATTR_USER_AUTH_INPUT_DEVICE', + SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE: + 'SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE', + SCARD_ATTR_VENDOR_IFD_SERIAL_NO: 'SCARD_ATTR_VENDOR_IFD_SERIAL_NO', + SCARD_ATTR_VENDOR_IFD_TYPE: 'SCARD_ATTR_VENDOR_IFD_TYPE', + SCARD_ATTR_VENDOR_IFD_VERSION: 'SCARD_ATTR_VENDOR_IFD_VERSION', + SCARD_ATTR_VENDOR_NAME: 'SCARD_ATTR_VENDOR_NAME', + } +if 'pcsclite' == resourceManager: + extra_attributes = { + SCARD_ATTR_ASYNC_PROTOCOL_TYPES: 'SCARD_ATTR_ASYNC_PROTOCOL_TYPES', + SCARD_ATTR_SYNC_PROTOCOL_TYPES: 'SCARD_ATTR_SYNC_PROTOCOL_TYPES', + } + attributes.update(extra_attributes) def printAttribute(attrib, value): diff --git a/smartcard/scard/PcscDefs.i b/smartcard/scard/PcscDefs.i index a96d6481..5e4459b5 100644 --- a/smartcard/scard/PcscDefs.i +++ b/smartcard/scard/PcscDefs.i @@ -348,10 +348,5 @@ typedef enum %constant unsigned long SCARD_P_SHUTDOWN = 0x80100018 ; // Infinite timeout -// on Mac OS X Tiger, a 0xffffffff infinite time-out causes a random crash upon SCardGetStatusChange return -#ifdef __TIGER__ -%constant unsigned long INFINITE = 4320000 ; -#else // !__TIGER__ %constant unsigned long INFINITE = 0x7FFFFFFF ; -#endif // __TIGER__ diff --git a/smartcard/scard/scard.i b/smartcard/scard/scard.i index ebf6458a..8d783319 100644 --- a/smartcard/scard/scard.i +++ b/smartcard/scard/scard.i @@ -106,24 +106,6 @@ provides mapping for the following API functions: - SCardStatus - SCardTransmit -On Mac OS X Tiger with PCSC lite, the smartcard.scard module provides -mapping for the following API functions: - - - SCardBeginTransaction - - SCardCancel - - SCardConnect - - SCardControl - - SCardDisconnect - - SCardEndTransaction - - SCardEstablishContext - - SCardGetStatusChange - - SCardListReaders - - SCardListReaderGroups - - SCardReconnect - - SCardReleaseContext - - SCardStatus - - SCardTransmit - The following PCSC smart card functions are not wrapped by the scard module on any platform: @@ -371,10 +353,6 @@ SCARDRETCODE _RemoveReaderFromGroup( #endif // WIN32 -// -// These functions are not available on Max OS X Tiger -// -#ifndef __TIGER__ /////////////////////////////////////////////////////////////////////////////// static SCARDRETCODE _IsValidContext(SCARDCONTEXT hcontext) { @@ -413,35 +391,9 @@ static SCARDRETCODE _SetAttrib(SCARDHANDLE hcard, SCARDDWORDARG dwAttrId, BYTELI lRetCode = (mySCardSetAttrib)(hcard, dwAttrId, pbl->ab, pbl->cBytes); return lRetCode; } -#endif // !__TIGER__ -// -// SCardControl does not have the same prototype on Mac OS X Tiger -// -#ifdef __TIGER__ - /////////////////////////////////////////////////////////////////////////////// - static SCARDRETCODE _Control( - SCARDHANDLE hcard, - BYTELIST* pblSendBuffer, - BYTELIST* pblRecvBuffer - ) - { - SCARDRETCODE lRet; - - pblRecvBuffer->ab = (unsigned char*)mem_Malloc(MAX_BUFFER_SIZE_EXTENDED*sizeof(unsigned char)); - pblRecvBuffer->cBytes = MAX_BUFFER_SIZE_EXTENDED; - - lRet = (mySCardControl)( - hcard, - pblSendBuffer->ab, - pblSendBuffer->cBytes, - pblRecvBuffer->ab, - &pblRecvBuffer->cBytes); - return lRet; - } -#else // !__TIGER__ /////////////////////////////////////////////////////////////////////////////// static SCARDRETCODE _Control( SCARDHANDLE hcard, @@ -465,7 +417,6 @@ static SCARDRETCODE _SetAttrib(SCARDHANDLE hcard, SCARDDWORDARG dwAttrId, BYTELI &pblRecvBuffer->cBytes); return lRet; } -#endif // __TIGER__ /////////////////////////////////////////////////////////////////////////////// static SCARDRETCODE _BeginTransaction(SCARDHANDLE hcard) @@ -519,20 +470,6 @@ static SCARDRETCODE _EstablishContext(SCARDDWORDARG dwScope, SCARDCONTEXT* phCon { long lRet; lRet = (mySCardEstablishContext)(dwScope, NULL, NULL, phContext); - - #ifdef __TIGER__ - // SCardReleaseContext on Mac OS X Tiger fails if SCardConnect is not called with an established - // context, even on a dummy reader - if (SCARD_S_SUCCESS==lRet) - { - SCARDHANDLE hcard; - SCARDDWORDARG dwarg; - (mySCardConnectA)(*phContext, "dummy-reader", SCARD_SHARE_SHARED, - SCARD_PROTOCOL_ANY, &hcard, &dwarg); - } - #endif // __TIGER__ - - return lRet; } /////////////////////////////////////////////////////////////////////////////// @@ -1248,13 +1185,6 @@ SCARDRETCODE _RemoveReaderFromGroup( #endif // WIN32 - -// -// These functions are not available on Max OS X Tiger -// -// -#ifndef __TIGER__ - /////////////////////////////////////////////////////////////////////////////// %define DOCSTRING_ISVALIDCONTEXT " @@ -1508,41 +1438,7 @@ SCARDRETCODE _RemoveReaderFromGroup( %rename(SCardSetAttrib) _SetAttrib(SCARDHANDLE hcard, SCARDDWORDARG dwAttrId, BYTELIST* ATTRIBUTESIN); SCARDRETCODE _SetAttrib(SCARDHANDLE hcard, SCARDDWORDARG dwAttrId, BYTELIST* ATTRIBUTESIN); -#endif // !__TIGER__ - - -// -// SCardControl does not have the same prototype on Mac OS X Tiger -// -#ifdef __TIGER__ - /////////////////////////////////////////////////////////////////////////////// - %define DOCSTRING_CONTROL - " - This function sends a control command to the reader connected to by - SCardConnect(). It returns a result and the control response. - from smartcard.scard import * - hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER) - hresult, hcard, dwActiveProtocol = SCardConnect( - hcontext, 'SchlumbergerSema Reflex USB v.2 0', SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0) - CMD = [ 42, 0x12, 0x34] - hresult, response = SCardControl(hcard, CMD) - if hresult != SCARD_S_SUCCESS: - raise error, 'Failed to control: ' + SCardGetErrorMessage(hresult) - " - %enddef - %feature("docstring") DOCSTRING_CONTROL; - %rename(SCardControl) _Control( - SCARDHANDLE hcard, - BYTELIST* INBUFFER, - BYTELIST* OUTBUFFER - ); - SCARDRETCODE _Control( - SCARDHANDLE hcard, - BYTELIST* INBUFFER, - BYTELIST* OUTBUFFER - ); -#else // !__TIGER__ /////////////////////////////////////////////////////////////////////////////// %define DOCSTRING_CONTROL " @@ -1573,7 +1469,6 @@ SCARDRETCODE _RemoveReaderFromGroup( BYTELIST* INBUFFER, BYTELIST* OUTBUFFER ); -#endif // __TIGER__ /////////////////////////////////////////////////////////////////////////////// @@ -2080,9 +1975,6 @@ def SCardLocateCards(hcontext, cardnames, readerstates): #ifdef PCSCLITE %constant char* resourceManager = "pcsclite" ; #ifdef __APPLE__ - #ifdef __TIGER__ - %constant char* resourceManagerSubType = "pcsclite-tiger" ; - #endif //__TIGER__ #ifdef __LEOPARD__ %constant char* resourceManagerSubType = "pcsclite-leopard" ; #endif //__LEOPARD__ diff --git a/smartcard/scard/winscarddll.c b/smartcard/scard/winscarddll.c index af412095..dfb40e51 100644 --- a/smartcard/scard/winscarddll.c +++ b/smartcard/scard/winscarddll.c @@ -228,10 +228,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA SCARDSTATE mySCardState = _defaultSCARDSTATE; #endif // WIN32 -// -// These functions are not available on Max OS X Tiger -// -#ifndef __TIGER__ static WINSCARDAPI SCARDRETCODE WINAPI _defaultSCARDISVALIDCONTEXT( IN SCARDCONTEXT hContext) @@ -275,23 +271,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA SCARDGETATTRIB mySCardGetAttrib = _defaultSCARDGETATTRIB; SCARDSETATTRIB mySCardSetAttrib = _defaultSCARDSETATTRIB; -#endif // !__TIGER__ - -// -// SCardControl does not have the same prototype on Mac OS X Tiger -// -#ifdef __TIGER__ - static WINSCARDAPI SCARDRETCODE - WINAPI _defaultSCARDCONTROL( - IN SCARDHANDLE hCard, - IN const unsigned char* lpInBuffer, - IN SCARDDWORDARG nInBufferSize, - OUT unsigned char* lpOutBuffer, - IN OUT SCARDDWORDARG* lpBytesReturned) - { - return SCARD_E_NO_SERVICE; - } -#else // !__TIGER__ static WINSCARDAPI SCARDRETCODE WINAPI _defaultSCARDCONTROL( IN SCARDHANDLE hCard, @@ -312,7 +291,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA return SCARD_E_NO_SERVICE; } -#endif // __TIGER__ #ifdef PCSCLITE /////////////////////////////////////////////////////////////////////////////// @@ -774,18 +752,12 @@ long winscard_init(void) #ifndef __APPLE__ GETPROCADDRESS( SCARDCONTROL, SCardControl, SCardControl ); #else // !__APPLE__ - #ifdef __TIGER__ - GETPROCADDRESS( SCARDCONTROL, SCardControl, SCardControl ); - #else // ! __TIGER__ - GETPROCADDRESS( SCARDCONTROL, SCardControl, SCardControl132 ); - #endif // __TIGER__ + GETPROCADDRESS( SCARDCONTROL, SCardControl, SCardControl132 ); #endif // __APPLE__ - #ifndef __TIGER__ SILENTGETPROCADDRESS( SCARDISVALIDCONTEXT , SCardIsValidContext , SCardIsValidContext ); GETPROCADDRESS( SCARDGETATTRIB , SCardGetAttrib , SCardGetAttrib ); GETPROCADDRESS( SCARDSETATTRIB , SCardSetAttrib , SCardSetAttrib ); - #endif myg_prgSCardT0Pci = dlsym( handle, "g_rgSCardT0Pci" ); myg_prgSCardT1Pci = dlsym( handle, "g_rgSCardT1Pci" ); diff --git a/smartcard/scard/winscarddll.h b/smartcard/scard/winscarddll.h index 89e7ba56..ebbd415a 100644 --- a/smartcard/scard/winscarddll.h +++ b/smartcard/scard/winscarddll.h @@ -189,11 +189,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #endif // WIN32 - -// -// These functions are not available on Max OS X Tiger -// -#ifndef __TIGER__ typedef WINSCARDAPI SCARDRETCODE (WINAPI *SCARDISVALIDCONTEXT)( IN SCARDCONTEXT hContext); @@ -215,21 +210,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA extern SCARDISVALIDCONTEXT mySCardIsValidContext; extern SCARDGETATTRIB mySCardGetAttrib; extern SCARDSETATTRIB mySCardSetAttrib; -#endif // !__TIGER__ - -// -// SCardControl does not have the same prototype on Mac OS X Tiger -// -#ifdef __TIGER__ - typedef WINSCARDAPI SCARDRETCODE - (WINAPI *SCARDCONTROL)( - IN SCARDHANDLE hCard, - IN const unsigned char* lpInBuffer, - IN SCARDDWORDARG nInBufferSize, - OUT unsigned char* lpOutBuffer, - IN OUT SCARDDWORDARG* lpBytesReturned); -#else // !__TIGER__ typedef WINSCARDAPI SCARDRETCODE (WINAPI *SCARDCONTROL)( IN SCARDHANDLE hCard, @@ -239,7 +220,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA OUT LPVOID lpOutBuffer, IN SCARDDWORDARG nOutBufferSize, OUT SCARDDWORDARG* lpBytesReturned); -#endif // __TIGER__ diff --git a/smartcard/test/framework/testcase_CardConnection.py b/smartcard/test/framework/testcase_CardConnection.py index 5120297e..4a9abbd5 100755 --- a/smartcard/test/framework/testcase_CardConnection.py +++ b/smartcard/test/framework/testcase_CardConnection.py @@ -94,17 +94,14 @@ def testcase_CardConnectionT1inConnect(self): for reader in readers(): cc = reader.createConnection() - # on Mac OS X Tiger, trying to connect - # with T=1 protocol does not except - if not 'pcsclite-tiger' == resourceManagerSubType: - if [] != expectedATRinReader[str(reader)]: - # should fail since the test card does not support T1 - self.assertRaises( - CardConnectionException, - cc.connect, - CardConnection.T1_protocol) - else: - self.assertRaises(NoCardException, cc.connect) + if [] != expectedATRinReader[str(reader)]: + # should fail since the test card does not support T1 + self.assertRaises( + CardConnectionException, + cc.connect, + CardConnection.T1_protocol) + else: + self.assertRaises(NoCardException, cc.connect) cc.disconnect() def testcase_CardConnectionT1inTransmit(self): From fdadf6e6e15948d75f70ec35fea382dda98c30f0 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Tue, 23 Jun 2015 11:47:15 +0100 Subject: [PATCH 21/43] Reformat functions/attributes supported by `smartcard.scard` as tables --- smartcard/scard/scard.i | 398 +++++++++++++++------------------------- 1 file changed, 149 insertions(+), 249 deletions(-) diff --git a/smartcard/scard/scard.i b/smartcard/scard/scard.i index 8d783319..b5f38b7e 100644 --- a/smartcard/scard/scard.i +++ b/smartcard/scard/scard.i @@ -47,73 +47,53 @@ Introduction The smartcard.scard module is a Python wrapper around PCSC smart card base services. On Windows, the wrapper is performed around the smart card base -components winscard library. On linux, the wrapper is performed around -PCSC-lite library. - - -On Windows using the smart card base components, the smartcard.scard -module provides mapping for the following API functions: - - - SCardAddReaderToGroup - - SCardBeginTransaction - - SCardCancel - - SCardConnect - - SCardControl - - SCardDisconnect - - SCardEndTransaction - - SCardEstablishContext - - SCardForgetCardType - - SCardForgetReader - - SCardForgetReaderGroup - - SCardGetAttrib - - SCardGetCardTypeProviderName - - SCardGetErrorMessage - - SCardGetStatusChange - - SCardIntroduceCardType - - SCardIntroduceReader - - SCardIntroduceReaderGroup - - SCardIsValidContext - - SCardListInterfaces - - SCardListCards - - SCardListReaders - - SCardListReaderGroups - - SCardLocateCards - - SCardReconnect - - SCardReleaseContext - - SCardRemoveReaderFromGroup - - SCardSetAttrib - - SCardStatus - - SCardTransmit - -On linux or Mac OS X Leopard with PCSC lite, the smartcard.scard module -provides mapping for the following API functions: - - - SCardBeginTransaction - - SCardCancel - - SCardConnect - - SCardControl - - SCardDisconnect - - SCardEndTransaction - - SCardEstablishContext - - SCardGetAttrib - - SCardGetStatusChange - - SCardIsValidContext - - SCardListReaders - - SCardListReaderGroups - - SCardReconnect - - SCardReleaseContext - - SCardSetAttrib - - SCardStatus - - SCardTransmit - -The following PCSC smart card functions are not wrapped by the scard -module on any platform: - - - GetOpenCardName - - SCardFreeMemory - - SCardGetProviderId - - SCardSetCartTypeProviderName - - SCardUIDlgSelectCard +components winscard library. On linux and OS X, the wrapper is performed +around the PCSC-lite library. + + +The smartcard.scard module provides mapping for the following API functions, +depending on the Operating System: + +=============================== ======= ======= +Function Windows Linux + OS X +=============================== ======= ======= +GetOpenCardName +SCardAddReaderToGroup Y +SCardBeginTransaction Y Y +SCardCancel Y Y +SCardConnect Y Y +SCardControl Y Y +SCardDisconnect Y Y +SCardEndTransaction Y Y +SCardEstablishConteYt Y Y +SCardForgetCardType Y +SCardForgetReader Y +SCardForgetReaderGroup Y +SCardFreeMemory +SCardGetAttrib Y Y +SCardGetCardTypeProviderName Y +SCardGetErrorMessage Y +SCardGetProviderId +SCardGetStatusChange Y Y +SCardIntroduceCardType Y +SCardIntroduceReader Y +SCardIntroduceReaderGroup Y +SCardIsValidConteYt Y Y +SCardListCards Y +SCardListInterfaces Y +SCardListReaderGroups Y Y +SCardListReaders Y Y +SCardLocateCards Y +SCardReconnect Y Y +SCardReleaseConteYt Y Y +SCardRemoveReaderFromGroup Y +SCardSetAttrib Y Y +SCardSetCartTypeProviderName +SCardStatus Y Y +SCardTransmit Y Y +SCardUIDlgSelectCard +=============================== ======= ======= Comments, bug reports, improvements welcome. @@ -1211,97 +1191,57 @@ SCARDRETCODE _RemoveReaderFromGroup( This function get an attribute from the IFD Handler. - For PCSC lite, the list of possible attributes is: - - * SCARD_ATTR_ASYNC_PROTOCOL_TYPES - * SCARD_ATTR_ATR_STRING - * SCARD_ATTR_CHANNEL_ID - * SCARD_ATTR_CHARACTERISTICS - * SCARD_ATTR_CURRENT_BWT - * SCARD_ATTR_CURRENT_CLK - * SCARD_ATTR_CURRENT_CWT - * SCARD_ATTR_CURRENT_D - * SCARD_ATTR_CURRENT_EBC_ENCODING - * SCARD_ATTR_CURRENT_F - * SCARD_ATTR_CURRENT_IFSC - * SCARD_ATTR_CURRENT_IFSD - * SCARD_ATTR_CURRENT_IO_STATE - * SCARD_ATTR_CURRENT_N - * SCARD_ATTR_CURRENT_PROTOCOL_TYPE - * SCARD_ATTR_CURRENT_W - * SCARD_ATTR_DEFAULT_CLK - * SCARD_ATTR_DEFAULT_DATA_RATE - * SCARD_ATTR_DEVICE_FRIENDLY_NAME_A - * SCARD_ATTR_DEVICE_FRIENDLY_NAME_W - * SCARD_ATTR_DEVICE_IN_USE - * SCARD_ATTR_DEVICE_SYSTEM_NAME_A - * SCARD_ATTR_DEVICE_SYSTEM_NAME_W - * SCARD_ATTR_DEVICE_UNIT - * SCARD_ATTR_ESC_AUTHREQUEST - * SCARD_ATTR_ESC_CANCEL - * SCARD_ATTR_ESC_RESET - * SCARD_ATTR_EXTENDED_BWT - * SCARD_ATTR_ICC_INTERFACE_STATUS - * SCARD_ATTR_ICC_PRESENCE - * SCARD_ATTR_ICC_TYPE_PER_ATR - * SCARD_ATTR_MAX_CLK - * SCARD_ATTR_MAX_DATA_RATE - * SCARD_ATTR_MAX_IFSD - * SCARD_ATTR_MAXINPUT - * SCARD_ATTR_POWER_MGMT_SUPPORT - * SCARD_ATTR_SUPRESS_T1_IFS_REQUEST - * SCARD_ATTR_SYNC_PROTOCOL_TYPES - * SCARD_ATTR_USER_AUTH_INPUT_DEVICE - * SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE - * SCARD_ATTR_VENDOR_IFD_SERIAL_NO - * SCARD_ATTR_VENDOR_IFD_TYPE - * SCARD_ATTR_VENDOR_IFD_VERSION - * SCARD_ATTR_VENDOR_NAME - - For Windows Resource Manager, the list of possible attributes is: - - * SCARD_ATTR_VENDOR_NAME - * SCARD_ATTR_VENDOR_IFD_TYPE - * SCARD_ATTR_VENDOR_IFD_VERSION - * SCARD_ATTR_VENDOR_IFD_SERIAL_NO - * SCARD_ATTR_CHANNEL_ID - * SCARD_ATTR_DEFAULT_CLK - * SCARD_ATTR_MAX_CLK - * SCARD_ATTR_DEFAULT_DATA_RATE - * SCARD_ATTR_MAX_DATA_RATE - * SCARD_ATTR_MAX_IFSD - * SCARD_ATTR_POWER_MGMT_SUPPORT - * SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE - * SCARD_ATTR_USER_AUTH_INPUT_DEVICE - * SCARD_ATTR_CHARACTERISTICS - * SCARD_ATTR_CURRENT_PROTOCOL_TYPE - * SCARD_ATTR_CURRENT_CLK - * SCARD_ATTR_CURRENT_F - * SCARD_ATTR_CURRENT_D - * SCARD_ATTR_CURRENT_N - * SCARD_ATTR_CURRENT_W - * SCARD_ATTR_CURRENT_IFSC - * SCARD_ATTR_CURRENT_IFSD - * SCARD_ATTR_CURRENT_BWT - * SCARD_ATTR_CURRENT_CWT - * SCARD_ATTR_CURRENT_EBC_ENCODING - * SCARD_ATTR_EXTENDED_BWT - * SCARD_ATTR_ICC_PRESENCE - * SCARD_ATTR_ICC_INTERFACE_STATUS - * SCARD_ATTR_CURRENT_IO_STATE - * SCARD_ATTR_ATR_STRING - * SCARD_ATTR_ICC_TYPE_PER_ATR - * SCARD_ATTR_ESC_RESET - * SCARD_ATTR_ESC_CANCEL - * SCARD_ATTR_ESC_AUTHREQUEST - * SCARD_ATTR_MAXINPUT - * SCARD_ATTR_DEVICE_UNIT - * SCARD_ATTR_DEVICE_IN_USE - * SCARD_ATTR_DEVICE_FRIENDLY_NAME_A - * SCARD_ATTR_DEVICE_SYSTEM_NAME_A - * SCARD_ATTR_DEVICE_FRIENDLY_NAME_W - * SCARD_ATTR_DEVICE_SYSTEM_NAME_W - * SCARD_ATTR_SUPRESS_T1_IFS_REQUEST + The possible attributes are: + + ======================================== ======= ======= + Attribute Windows PSCS + lite + ======================================== ======= ======= + SCARD_ATTR_ASYNC_PROTOCOL_TYPES Y + SCARD_ATTR_ATR_STRING Y Y + SCARD_ATTR_CHANNEL_ID Y Y + SCARD_ATTR_CHARACTERISTICS Y Y + SCARD_ATTR_CURRENT_BWT Y Y + SCARD_ATTR_CURRENT_CLK Y Y + SCARD_ATTR_CURRENT_CWT Y Y + SCARD_ATTR_CURRENT_D Y Y + SCARD_ATTR_CURRENT_EBC_ENCODING Y Y + SCARD_ATTR_CURRENT_F Y Y + SCARD_ATTR_CURRENT_IFSC Y Y + SCARD_ATTR_CURRENT_IFSD Y Y + SCARD_ATTR_CURRENT_IO_STATE Y Y + SCARD_ATTR_CURRENT_N Y Y + SCARD_ATTR_CURRENT_PROTOCOL_TYPE Y Y + SCARD_ATTR_CURRENT_W Y Y + SCARD_ATTR_DEFAULT_CLK Y Y + SCARD_ATTR_DEFAULT_DATA_RATE Y Y + SCARD_ATTR_DEVICE_FRIENDLY_NAME_A Y Y + SCARD_ATTR_DEVICE_FRIENDLY_NAME_W Y Y + SCARD_ATTR_DEVICE_IN_USE Y Y + SCARD_ATTR_DEVICE_SYSTEM_NAME_A Y Y + SCARD_ATTR_DEVICE_SYSTEM_NAME_W Y Y + SCARD_ATTR_DEVICE_UNIT Y Y + SCARD_ATTR_ESC_AUTHREQUEST Y Y + SCARD_ATTR_ESC_CANCEL Y Y + SCARD_ATTR_ESC_RESET Y Y + SCARD_ATTR_EXTENDED_BWT Y Y + SCARD_ATTR_ICC_INTERFACE_STATUS Y Y + SCARD_ATTR_ICC_PRESENCE Y Y + SCARD_ATTR_ICC_TYPE_PER_ATR Y Y + SCARD_ATTR_MAXINPUT Y Y + SCARD_ATTR_MAX_CLK Y Y + SCARD_ATTR_MAX_DATA_RATE Y Y + SCARD_ATTR_MAX_IFSD Y Y + SCARD_ATTR_POWER_MGMT_SUPPORT Y Y + SCARD_ATTR_SUPRESS_T1_IFS_REQUEST Y Y + SCARD_ATTR_SYNC_PROTOCOL_TYPES Y + SCARD_ATTR_USER_AUTH_INPUT_DEVICE Y Y + SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE Y Y + SCARD_ATTR_VENDOR_IFD_SERIAL_NO Y Y + SCARD_ATTR_VENDOR_IFD_TYPE Y Y + SCARD_ATTR_VENDOR_IFD_VERSION Y Y + SCARD_ATTR_VENDOR_NAME Y Y + ======================================== ======= ======= Not all the dwAttrId values listed above may be implemented in the IFD Handler you are using. And some dwAttrId values not listed here may be @@ -1329,97 +1269,57 @@ SCARDRETCODE _RemoveReaderFromGroup( attributes are supported by all readers nor can they be set at all times. - For PCSC lite, the list of possible attributes is: - - * SCARD_ATTR_ASYNC_PROTOCOL_TYPES - * SCARD_ATTR_ATR_STRING - * SCARD_ATTR_CHANNEL_ID - * SCARD_ATTR_CHARACTERISTICS - * SCARD_ATTR_CURRENT_BWT - * SCARD_ATTR_CURRENT_CLK - * SCARD_ATTR_CURRENT_CWT - * SCARD_ATTR_CURRENT_D - * SCARD_ATTR_CURRENT_EBC_ENCODING - * SCARD_ATTR_CURRENT_F - * SCARD_ATTR_CURRENT_IFSC - * SCARD_ATTR_CURRENT_IFSD - * SCARD_ATTR_CURRENT_IO_STATE - * SCARD_ATTR_CURRENT_N - * SCARD_ATTR_CURRENT_PROTOCOL_TYPE - * SCARD_ATTR_CURRENT_W - * SCARD_ATTR_DEFAULT_CLK - * SCARD_ATTR_DEFAULT_DATA_RATE - * SCARD_ATTR_DEVICE_FRIENDLY_NAME_A - * SCARD_ATTR_DEVICE_FRIENDLY_NAME_W - * SCARD_ATTR_DEVICE_IN_USE - * SCARD_ATTR_DEVICE_SYSTEM_NAME_A - * SCARD_ATTR_DEVICE_SYSTEM_NAME_W - * SCARD_ATTR_DEVICE_UNIT - * SCARD_ATTR_ESC_AUTHREQUEST - * SCARD_ATTR_ESC_CANCEL - * SCARD_ATTR_ESC_RESET - * SCARD_ATTR_EXTENDED_BWT - * SCARD_ATTR_ICC_INTERFACE_STATUS - * SCARD_ATTR_ICC_PRESENCE - * SCARD_ATTR_ICC_TYPE_PER_ATR - * SCARD_ATTR_MAX_CLK - * SCARD_ATTR_MAX_DATA_RATE - * SCARD_ATTR_MAX_IFSD - * SCARD_ATTR_MAXINPUT - * SCARD_ATTR_POWER_MGMT_SUPPORT - * SCARD_ATTR_SUPRESS_T1_IFS_REQUEST - * SCARD_ATTR_SYNC_PROTOCOL_TYPES - * SCARD_ATTR_USER_AUTH_INPUT_DEVICE - * SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE - * SCARD_ATTR_VENDOR_IFD_SERIAL_NO - * SCARD_ATTR_VENDOR_IFD_TYPE - * SCARD_ATTR_VENDOR_IFD_VERSION - * SCARD_ATTR_VENDOR_NAME - - For Windows Resource Manager, the list of possible attributes is: - - * SCARD_ATTR_VENDOR_NAME - * SCARD_ATTR_VENDOR_IFD_TYPE - * SCARD_ATTR_VENDOR_IFD_VERSION - * SCARD_ATTR_VENDOR_IFD_SERIAL_NO - * SCARD_ATTR_CHANNEL_ID - * SCARD_ATTR_DEFAULT_CLK - * SCARD_ATTR_MAX_CLK - * SCARD_ATTR_DEFAULT_DATA_RATE - * SCARD_ATTR_MAX_DATA_RATE - * SCARD_ATTR_MAX_IFSD - * SCARD_ATTR_POWER_MGMT_SUPPORT - * SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE - * SCARD_ATTR_USER_AUTH_INPUT_DEVICE - * SCARD_ATTR_CHARACTERISTICS - * SCARD_ATTR_CURRENT_PROTOCOL_TYPE - * SCARD_ATTR_CURRENT_CLK - * SCARD_ATTR_CURRENT_F - * SCARD_ATTR_CURRENT_D - * SCARD_ATTR_CURRENT_N - * SCARD_ATTR_CURRENT_W - * SCARD_ATTR_CURRENT_IFSC - * SCARD_ATTR_CURRENT_IFSD - * SCARD_ATTR_CURRENT_BWT - * SCARD_ATTR_CURRENT_CWT - * SCARD_ATTR_CURRENT_EBC_ENCODING - * SCARD_ATTR_EXTENDED_BWT - * SCARD_ATTR_ICC_PRESENCE - * SCARD_ATTR_ICC_INTERFACE_STATUS - * SCARD_ATTR_CURRENT_IO_STATE - * SCARD_ATTR_ATR_STRING - * SCARD_ATTR_ICC_TYPE_PER_ATR - * SCARD_ATTR_ESC_RESET - * SCARD_ATTR_ESC_CANCEL - * SCARD_ATTR_ESC_AUTHREQUEST - * SCARD_ATTR_MAXINPUT - * SCARD_ATTR_DEVICE_UNIT - * SCARD_ATTR_DEVICE_IN_USE - * SCARD_ATTR_DEVICE_FRIENDLY_NAME_A - * SCARD_ATTR_DEVICE_SYSTEM_NAME_A - * SCARD_ATTR_DEVICE_FRIENDLY_NAME_W - * SCARD_ATTR_DEVICE_SYSTEM_NAME_W - * SCARD_ATTR_SUPRESS_T1_IFS_REQUEST + The possible attributes are: + + ======================================== ======= ======= + Attribute Windows PSCS + lite + ======================================== ======= ======= + SCARD_ATTR_ASYNC_PROTOCOL_TYPES Y + SCARD_ATTR_ATR_STRING Y Y + SCARD_ATTR_CHANNEL_ID Y Y + SCARD_ATTR_CHARACTERISTICS Y Y + SCARD_ATTR_CURRENT_BWT Y Y + SCARD_ATTR_CURRENT_CLK Y Y + SCARD_ATTR_CURRENT_CWT Y Y + SCARD_ATTR_CURRENT_D Y Y + SCARD_ATTR_CURRENT_EBC_ENCODING Y Y + SCARD_ATTR_CURRENT_F Y Y + SCARD_ATTR_CURRENT_IFSC Y Y + SCARD_ATTR_CURRENT_IFSD Y Y + SCARD_ATTR_CURRENT_IO_STATE Y Y + SCARD_ATTR_CURRENT_N Y Y + SCARD_ATTR_CURRENT_PROTOCOL_TYPE Y Y + SCARD_ATTR_CURRENT_W Y Y + SCARD_ATTR_DEFAULT_CLK Y Y + SCARD_ATTR_DEFAULT_DATA_RATE Y Y + SCARD_ATTR_DEVICE_FRIENDLY_NAME_A Y Y + SCARD_ATTR_DEVICE_FRIENDLY_NAME_W Y Y + SCARD_ATTR_DEVICE_IN_USE Y Y + SCARD_ATTR_DEVICE_SYSTEM_NAME_A Y Y + SCARD_ATTR_DEVICE_SYSTEM_NAME_W Y Y + SCARD_ATTR_DEVICE_UNIT Y Y + SCARD_ATTR_ESC_AUTHREQUEST Y Y + SCARD_ATTR_ESC_CANCEL Y Y + SCARD_ATTR_ESC_RESET Y Y + SCARD_ATTR_EXTENDED_BWT Y Y + SCARD_ATTR_ICC_INTERFACE_STATUS Y Y + SCARD_ATTR_ICC_PRESENCE Y Y + SCARD_ATTR_ICC_TYPE_PER_ATR Y Y + SCARD_ATTR_MAXINPUT Y Y + SCARD_ATTR_MAX_CLK Y Y + SCARD_ATTR_MAX_DATA_RATE Y Y + SCARD_ATTR_MAX_IFSD Y Y + SCARD_ATTR_POWER_MGMT_SUPPORT Y Y + SCARD_ATTR_SUPRESS_T1_IFS_REQUEST Y Y + SCARD_ATTR_SYNC_PROTOCOL_TYPES Y + SCARD_ATTR_USER_AUTH_INPUT_DEVICE Y Y + SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE Y Y + SCARD_ATTR_VENDOR_IFD_SERIAL_NO Y Y + SCARD_ATTR_VENDOR_IFD_TYPE Y Y + SCARD_ATTR_VENDOR_IFD_VERSION Y Y + SCARD_ATTR_VENDOR_NAME Y Y + ======================================== ======= ======= Not all the dwAttrId values listed above may be implemented in the IFD Handler you are using. And some dwAttrId values not listed here may be From 2fb346a33c7c16827cb571b3ba76db038618ca8e Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Tue, 23 Jun 2015 11:49:03 +0100 Subject: [PATCH 22/43] Consolidate the project version in setup.py, bump to 1.7.0 --- ChangeLog | 6 + README | 217 ++++++++---------------------------- setup.py | 17 ++- smartcard/__init__.py | 2 - smartcard/scard/gemalto.ver | 8 +- 5 files changed, 69 insertions(+), 181 deletions(-) diff --git a/ChangeLog b/ChangeLog index 14381447..ea498a40 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +1.7.0 (TBD) +=========== + * dropped support for Python 2.5 and earlier (Alex Willmer) + * dropped support for OS X 10.5 (Leopard) and earlier (Alex Willmer) + + 1.6.16 (December 2014) =================== * added support for windows 64bit amd64 (Jean-Daniel Aussel) diff --git a/README b/README index 7e0c7bb9..5eee0277 100644 --- a/README +++ b/README @@ -23,15 +23,11 @@ You should have received a copy of the GNU Lesser General Public License along with pyscard; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -------------------------------------------------------------------------------- -Last update : pyscard 1.6.16 (Decembre 2012) -------------------------------------------------------------------------------- - pyscard is a python module adding smart cards support to python. It consists of the smartcard.scard module, an extension module wrapping Windows smart card base components (also known as PCSC) on Windows, and -PCSC lite on linux and Mac OS X Tiger, and of the smartcard module, a +PCSC lite on linux and OS X, and of the smartcard module, a python framework with objects wrapping PCSC API. @@ -63,24 +59,22 @@ Installing on windows from the binary distribution The binary msi installer and self-executable installer are packaged for a specific version of python, and have name similar to -pyscard-1.6.16.win32-py2.5.msi and pyscard-1.6.16.win32-py2.5.exe for -python 2.5. +pyscard-1.7..win32-py2.7.msi and pyscard-1.7..win32-py2.7.exe. Installing on windows from the source distribution --------------------------------------------------- -1. you will need swig 1.3.31 from http://www.swig.org, and a C compiler. +1. you will need swig from (http://www.swig.org), and a C compiler. -By default, Visual Studio 2003 is required for building the c language -wrapper for python 2.5, and Visual Studio .Net or VisualC++ 6 for python -2.4. You might use another release by fiddling with the -python/Lib/distutils/msvccompiler.py file that detects the compiler. +Visual Studio 2008 is required for building the C language wrapper. You can +download Microsoft Visual C++ Compiler for Python 2.7 +(http://aka.ms/vcpython27). 2. download the source distribution -The source distribution is available as pyscard-1.6.16.zip for windows, -and pyscard-1.6.16.tar.gz for linux. +The source distribution is available as pyscard-1.7..zip for windows, +and pyscard-1.7..tar.gz for linux. 3. unzip the source distribution, open a console and type the following: @@ -101,8 +95,8 @@ Installing on linux from the binary distribution: 1. download the binary distribution The binary distribution is either an archive file or a rpm file, with -names similar to pyscard-1.6.16-1.i386.rpm for the rpm distribution, or -pyscard-1.6.16.linux-i686.tar.gz for the archive distribution. +names similar to pyscard-1.7.-1.i386.rpm for the rpm distribution, or +pyscard-1.7..linux-i686.tar.gz for the archive distribution. 2. untar the binary distribution @@ -112,13 +106,13 @@ install the rpm. Installing on linux from the source distribution ------------------------------------------------ -1. you will need gcc, swig 1.3.31 (http://www.swig.org), and pcsc-lite +1. you will need gcc, swig (http://www.swig.org), and pcsc-lite (http://pcsclite.alioth.debian.org/) 2. download the source distribution -The source distribution is available as pyscard-1.6.16.zip or -pyscard-1.6.16.tar.gz. +The source distribution is available as pyscard-1.7..zip or +pyscard-1.7..tar.gz. 3. untar the source distribution @@ -128,42 +122,31 @@ pyscard-1.6.16.tar.gz. This will build pyscard and install it in the site-packages directory of your python distribution, e.g. -/usr/lib/python2.4/site-packages/smartcard. - -Installation on Max OS X Tiger: --------------------------------- +/usr/lib/python2.7/site-packages/smartcard. -The Mac OS X Tiger support is experimental on pyscard 1.6.16. It was -developed and tested on a i386 MacBook Pro. Please drop me a mail if you -succeed on a ppc MacBook. +Installation on Max OS X Snow Leopard: +-------------------------------------- -Installing on Mac OS X Tiger from the binary distribution: ----------------------------------------------------- +Installing on Mac OS X Snow Leopard from the binary distribution: +----------------------------------------------------------------- 1. download the binary distribution The binary distribution is an archive file, with a name similar to -pyscard-1.6.16-py-2.3-macosx10.4.mpkg or -pyscard-1.6.16-py-2.5-macosx10.4.mpkg. +pyscard-1.7.-py-2.6-macosx10.6.mpkg. 2. Open the package and proceed with installation. -Python 2.3 is pre-installed, so install -pyscard-1.6.16-py-2.3-macosx10.4.mpkg if you did not install another -release of python. +Installing on Mac OS X Snow Leopard from the source distribution +---------------------------------------------------------------- -Install pyscard-1.6.16-py-2.5-macosx10.4.mpkg if you installed python 2.5. - -Installing on Mac OS X Tiger from the source distribution ----------------------------------------------------------- - -1. you will need swig 1.3.31 (http://www.swig.org); gcc and pcsc-lite -are available out of the box on Max OS X Tiger +1. you will need swig (http://www.swig.org); gcc and pcsc-lite +are available out of the box on Max OS X Snow Leopard 2. download the source distribution -The source distribution is available as pyscard-1.6.16.zip or -pyscard-1.6.16.tar.gz. +The source distribution is available as pyscard-1.7..zip or +pyscard-1.7..tar.gz. 3. untar or unzip the source distribution @@ -173,42 +156,7 @@ sudo python setup.py build_ext install This will build pyscard and install it in the site-packages directory of your python distribution, e.g. -/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/lib/site-packages/smartcard - - -Installation on Max OS X Leopard: ---------------------------------- - -Installing on Mac OS X Leopard from the binary distribution: ----------------------------------------------------- - -1. download the binary distribution - -The binary distribution is an archive file, with a name similar to -pyscard-1.6.16-py-2.5-macosx10.5.mpkg. - -2. Open the package and proceed with installation. - -Installing on Mac OS X Leopard from the source distribution ------------------------------------------------------------- - -1. you will need swig 1.3.31 (http://www.swig.org); gcc and pcsc-lite -are available out of the box on Max OS X Leopard - -2. download the source distribution - -The source distribution is available as pyscard-1.6.16.zip or -pyscard-1.6.16.tar.gz. - -3. untar or unzip the source distribution - -4. from a terminal, type the following: - -sudo python setup.py build_ext install - -This will build pyscard and install it in the site-packages directory of -your python distribution, e.g. -/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.3/lib/site-packages/smartcard +/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.3/lib/site-packages/smartcard Installation on Max OS X Lion: @@ -220,21 +168,21 @@ Installing on Mac OS X Lion from the binary distribution: 1. download the binary distribution The binary distribution is an archive file, with a name similar to -pyscard-1.6.16-py-2.7-macosx10.7.mpkg. +pyscard-1.7.-py-2.7-macosx10.7.mpkg. 2. Open the package and proceed with installation. Installing on Mac OS X Lion from the source distribution -------------------------------------------------------- -1. you will need swig 2.0.4 (http://www.swig.org) and Xcode +1. you will need swig (http://www.swig.org) and Xcode (http://developer.apple.com/xcode/); -pcsc-lite is available out of the box on Max OS X Leopard +pcsc-lite is available out of the box on Max OS X 2. download the source distribution -The source distribution is available as pyscard-1.6.16.zip or -pyscard-1.6.16.tar.gz. +The source distribution is available as pyscard-1.7..zip or +pyscard-1.7..tar.gz. 3. untar or unzip the source distribution @@ -263,7 +211,7 @@ Building a binary distribution for Windows ------------------------------------------ To build a binary distribution from the source distribution, you will -need a C compiler and swig 1.3.31 (same requirements as for installing +need a C compiler and swig (same requirements as for installing from the source distribution). In the root directory of the source distribution, execute the following @@ -273,16 +221,14 @@ setup.py build_ext bdist_msi setup.py build_ext bdist_wininst This will build the msi installer and self-executable installer in the -dist directory, with names similar to pyscard-1.6.16.win32-py2.5.msi and -pyscard-1.6.16.win32-py2.5.exe for python 2.5, and -pyscard-1.6.16.win32-py2.4.msi and pyscard-1.6.16.win32-py2.4.exe for -python 2.4. +dist directory, with names similar to pyscard-1.7..win32-py2.7.msi and +pyscard-1.7..win32-py2.7.exe. Building a binary distribution for linux ---------------------------------------- To build a binary distribution from the source distribution, you will -need gcc, swig 1.3.31 and pcsc-lite (same requirements as for installing +need gcc, swig and pcsc-lite (same requirements as for installing from the source distribution). In the root directory of the source distribution, execute the following @@ -290,14 +236,14 @@ command in a terminal: /usr/bin/python setup.py build_ext bdist -This will build a package similar to pyscard-1.6.16.linux-i686.tar.gz +This will build a package similar to pyscard-1.7..linux-i686.tar.gz containing a tree Building a rpm distribution for linux ---------------------------------------- To build a rpm distribution from the source distribution, you will need -gcc, swig 1.3.31 and pcsc-lite (same requirements as for installing from +gcc, swig and pcsc-lite (same requirements as for installing from the source distribution). In the root directory of the source distribution, execute the following @@ -312,41 +258,14 @@ e.g.: echo "%_unpackaged_files_terminate_build 0" >> /etc/rpm/macros This will build in the dist directory a binary distribution with a name -similar to pyscard-1.6.16-1.i386.rpm. - -Building a binary distribution for Mac OS X Tiger -------------------------------------------------- - -To build a binary distribution from the source distribution, you will -need swig 1.3.31 (same requirements as for installing from the source -distribution) and bdist_mpkg 0.4.3 -(http://cheeseshop.python.org/pypi/bdist_mpkg/). - - -If you are using the pre-installed python 2.3 distribution, in the root -directory of the source distribution, i.e. in the src directory, execute -the following commands in a terminal: - -python setup.py build_ext -/System/Library/Frameworks/Python.Framework/Versions/2.3/bin/bdist_mpkg setup.py - -This will build package pyscard-1.6.16-py-2.3-macosx10.4.mpkg. - -If you are using python 2.5, in the root directory of the source distribution, -i.e. in the src directory, execute the following commands in a terminal: - -python setup.py build_ext -/Library/Frameworks/Python.Framework/Versions/2.5/bin/bdist_mpkg setup.py - -This will build package pyscard-1.6.16-py-2.6-macosx10.4.mpkg. - +similar to pyscard-1.7.-1.i386.rpm. Building a binary distribution for Mac OS X Lion ------------------------------------------------- To build a binary distribution from the source distribution, you will -need swig 2.0.4 and Xcode (same requirements as for installing from the source -distribution) and bdist_mpkg 0.4.4 (http://pypi.python.org/pypi/bdist_mpkg/). +need swig and Xcode (same requirements as for installing from the source +distribution) and bdist_mpkg 0.5.0+ (http://pypi.python.org/pypi/bdist_mpkg/). Install bdist_mpkg by executing the bdist_mpkg setup.py script with build and install as arguments, i.e. from the root directory of the @@ -358,74 +277,32 @@ i.e. in the src directory, execute the following commands in a terminal: python setup.py build_ext bdist_mpkg setup.py -This will build package pyscard-1.6.16-py-2.7-macosx10.7.mpkg in the dist +This will build package pyscard-1.7.-py-2.7-macosx10.7.mpkg in the dist directory. -Building a binary distribution for Mac OS X Leopard ---------------------------------------------------- +Building a binary distribution for Mac OS X Snow Leopard +-------------------------------------------------------- To build a binary distribution from the source distribution, you will -need swig 1.3.31 (same requirements as for installing from the source -distribution) and bdist_mpkg 0.4.3 -(http://cheeseshop.python.org/pypi/bdist_mpkg/). - -Apply the following patch to tools.py of bdist_mpkg package: - -===== patch start === -diff -rNu bdist_mpkg-0.4.3/bdist_mpkg/tools.py bdist_mpkg-0.4.3.leopard/bdist_mpkg/tools.py ---- bdist_mpkg-0.4.3/bdist_mpkg/tools.py 2006-07-09 00:39:00.000000000 -0400 -+++ bdist_mpkg-0.4.3.leopard/bdist_mpkg/tools.py 2008-08-21 07:43:35.000000000 -0400 -@@ -79,15 +79,12 @@ - yield os.path.join(root, fn) - - def get_gid(name, _cache={}): -- if not _cache: -- for line in os.popen('/usr/bin/nidump group .'): -- fields = line.split(':') -- if len(fields) >= 3: -- _cache[fields[0]] = int(fields[2]) -- try: -- return _cache[name] -- except KeyError: -- raise ValueError('group %s not found' % (name,)) -+ for line in os.popen("dscl . -read /Groups/" + name + " PrimaryGroupID"): -+ fields = [f.strip() for f in line.split(':')] -+ if fields[0] == "PrimaryGroupID": -+ return fields[1] -+ -+ raise ValueError('group %s not found' % (name,)) -===== patch end ======== - -This patch is required since Mac OS X Leopard does not have the nidump -command any more. +need swig (same requirements as for installing from the source +distribution) and bdist_mpkg 0.5.0+ (https://pypi.python.org/pypi/bdist_mpkg). Install bdist_mpkg by executing the bdist_mpkg setup.py script with build and install as arguments, i.e. from the root directory of the bdist_mpkg source distribution enter: python setup.py build install. -For python 2.5, from the root directory of the pyscard source -distribution, i.e. in the src directory, execute the following commands -in a terminal: - -python setup.py build_ext -/Library/Frameworks/Python.Framework/Versions/2.5/Extras/bin/bdist_mpkg setup.py - -This will build package pyscard-1.6.16-py-2.5-macosx10.5.mpkg. - For python 2.6, from the root directory of the pyscard source distribution, i.e. in the src directory, execute the following commands in a terminal: python setup.py build_ext /Library/Frameworks/Python.framework/Versions/2.6/bin/bdist_mpkg setup.py -This will build package pyscard-1.6.16-py-2.6-macosx10.5.mpkg. +This will build package pyscard-1.7.-py-2.6-macosx10.6.mpkg. ------------------------------------------------------------------------------- Issue Tracking ------------------------------------------------------------------------------- If you encounter a bug, please report it in the SourceForge bug tracker at - http://sourceforge.net/tracker/?group_id=196342&atid=957072 - https://sourceforge.net/tracker/?group_id=196342&atid=957072 - + https://sourceforge.net/p/pyscard/bugs/ -jda diff --git a/setup.py b/setup.py index 784be39e..385b9832 100755 --- a/setup.py +++ b/setup.py @@ -78,8 +78,13 @@ platform_extra_link_args = [] # ['-ggdb'] +VERSION_INFO = (1, 7, 0, 0) +VERSION_STR = '%i.%i.%i' % VERSION_INFO[:3] +VERSION_ALT = '%i,%01i,%01i,%04i' % VERSION_INFO + + kw = {'name': "pyscard", - 'version': "1.6.16", + 'version': VERSION_STR, 'description': "Smartcard module for Python.", 'author': "Jean-Daniel Aussel", 'author_email': "aussel.jean-daniel@gemalto.com", @@ -103,7 +108,10 @@ # the _scard.pyd extension to build 'ext_modules': [Extension("smartcard.scard._scard", - define_macros=platform__cc_defines, + define_macros=[ + ('VER_PRODUCTVERSION', VERSION_ALT), + ('VER_PRODUCTVERSION_STR', VERSION_STR)] + + platform__cc_defines, include_dirs=['smartcard/scard/'] \ + platform_include_dirs, sources=["smartcard/scard/helpers.c", @@ -116,6 +124,11 @@ swig_opts=['-outdir', 'smartcard/scard'] \ + platform_swig_opts)], + 'extras_require': { + 'Gui': ['wxPython'], + 'Pyro': ['Pyro'], + }, + 'classifiers': [ 'Development Status :: 5 - Release', 'License :: OSI Approved :: GNU Lesser General Public License v2 ' diff --git a/smartcard/__init__.py b/smartcard/__init__.py index 08a91c85..24c01627 100644 --- a/smartcard/__init__.py +++ b/smartcard/__init__.py @@ -4,8 +4,6 @@ access smartcards and readers. __author__ = "gemalto http://www.gemalto.com" -__date__ = "May 2010" -__version__ = "1.6.16" Copyright 2001-2012 gemalto Author: Jean-Daniel Aussel, mailto:jean-daniel.aussel@gemalto.com diff --git a/smartcard/scard/gemalto.ver b/smartcard/scard/gemalto.ver index e5cdedec..9969407c 100644 --- a/smartcard/scard/gemalto.ver +++ b/smartcard/scard/gemalto.ver @@ -15,18 +15,12 @@ #define VER_PRODUCTNAME_STR "Smart Cards Sofware Development Tools" #endif -#ifndef VER_PRODUCTVERSION -#define VER_PRODUCTVERSION 1,06,16,0010 -#endif +/* VER_PRODUCTVERSION and VER_PRODUCTVERSION_STR are provided by setup.py */ #ifndef VER_FILEVERSION #define VER_FILEVERSION VER_PRODUCTVERSION #endif -#ifndef VER_PRODUCTVERSION_STR -#define VER_PRODUCTVERSION_STR "1.6.16" -#endif - #ifndef VER_FILEFLAGSMASK #define VER_FILEFLAGSMASK (VS_FF_DEBUG | VS_FF_PRERELEASE) #endif From 2d0018b3b0a8392357a3c8f80ff54c47814f2f25 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Sun, 28 Jun 2015 17:18:05 +0100 Subject: [PATCH 23/43] Build Windows .exe and .msi installers --- appveyor.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index 624011fd..515b92b5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -52,6 +52,8 @@ test_script: after_test: - SET PATH=%SWIG%;%PATH% - "%WITH_COMPILER% %PYTHON%/python setup.py bdist_wheel" + - "%WITH_COMPILER% %PYTHON%/python setup.py bdist_wininst" + - "%WITH_COMPILER% %PYTHON%/python setup.py bdist_msi" artifacts: - path: dist\* From 4b639d3a1260910840e7fc9eeda82fc0b9ffc413 Mon Sep 17 00:00:00 2001 From: Ludovic Rousseau Date: Fri, 26 Jun 2015 17:32:23 +0200 Subject: [PATCH 24/43] README.md: Add a Continuous Integration status Add travis-ci status icon --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 62cdac7a..f83761f1 100644 --- a/README.md +++ b/README.md @@ -14,3 +14,7 @@ Samples ------- High level API samples: See http://pyscard.sourceforge.net/pyscard-framework.html#framework-samples Low level API samples: See http://pyscard.sourceforge.net/pyscard-wrapper.html#wrapper-samples + +Continuous Integration status +----------------------------- +tracis-ci: ![tracis-ci](https://travis-ci.org/LudovicRousseau/pyscard.svg "travis-ci") From 86589a9e7c72f569e5dd7f7972797c4f664a41b4 Mon Sep 17 00:00:00 2001 From: Ludovic Rousseau Date: Fri, 26 Jun 2015 18:35:29 +0200 Subject: [PATCH 25/43] README.md: Add AppVeyor icon AppVeyor is a Continuous Integration build system for Windows. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f83761f1..ad5810d5 100644 --- a/README.md +++ b/README.md @@ -18,3 +18,5 @@ Low level API samples: See http://pyscard.sourceforge.net/pyscard-wrapper.html#w Continuous Integration status ----------------------------- tracis-ci: ![tracis-ci](https://travis-ci.org/LudovicRousseau/pyscard.svg "travis-ci") + +AppVeyor: [![Build status](https://ci.appveyor.com/api/projects/status/c97dsaodpcwkm0ra?svg=true)](https://ci.appveyor.com/project/LudovicRousseau/pyscard) From 907ffa21d9facc341f1abffccff2c021a821d434 Mon Sep 17 00:00:00 2001 From: Ludovic Rousseau Date: Fri, 26 Jun 2015 18:40:00 +0200 Subject: [PATCH 26/43] README.md: Update travis-ci link The travis-ci icon now links to the project on travis-ci.org --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ad5810d5..8fad2f5d 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,6 @@ Low level API samples: See http://pyscard.sourceforge.net/pyscard-wrapper.html#w Continuous Integration status ----------------------------- -tracis-ci: ![tracis-ci](https://travis-ci.org/LudovicRousseau/pyscard.svg "travis-ci") +tracis-ci: [![tracis-ci](https://travis-ci.org/LudovicRousseau/pyscard.svg "travis-ci")](https://travis-ci.org/LudovicRousseau/pyscard) AppVeyor: [![Build status](https://ci.appveyor.com/api/projects/status/c97dsaodpcwkm0ra?svg=true)](https://ci.appveyor.com/project/LudovicRousseau/pyscard) From 0897480ca2be328693a2dea0ba15cc7255f0e7a7 Mon Sep 17 00:00:00 2001 From: Ludovic Rousseau Date: Fri, 26 Jun 2015 18:42:19 +0200 Subject: [PATCH 27/43] README.md: Correct Travis CI capitalisation The real name is "Travis CI" --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8fad2f5d..e32c9027 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,6 @@ Low level API samples: See http://pyscard.sourceforge.net/pyscard-wrapper.html#w Continuous Integration status ----------------------------- -tracis-ci: [![tracis-ci](https://travis-ci.org/LudovicRousseau/pyscard.svg "travis-ci")](https://travis-ci.org/LudovicRousseau/pyscard) +Tracis CI: [![Tracis CI](https://travis-ci.org/LudovicRousseau/pyscard.svg "Travis CI")](https://travis-ci.org/LudovicRousseau/pyscard) AppVeyor: [![Build status](https://ci.appveyor.com/api/projects/status/c97dsaodpcwkm0ra?svg=true)](https://ci.appveyor.com/project/LudovicRousseau/pyscard) From d0b74159de966201775d6fdf231e8221c71b8277 Mon Sep 17 00:00:00 2001 From: Ludovic Rousseau Date: Fri, 26 Jun 2015 19:16:25 +0200 Subject: [PATCH 28/43] README.md: fix typo in Travis name --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e32c9027..862d0caa 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,6 @@ Low level API samples: See http://pyscard.sourceforge.net/pyscard-wrapper.html#w Continuous Integration status ----------------------------- -Tracis CI: [![Tracis CI](https://travis-ci.org/LudovicRousseau/pyscard.svg "Travis CI")](https://travis-ci.org/LudovicRousseau/pyscard) +Travis CI: [![Travis CI](https://travis-ci.org/LudovicRousseau/pyscard.svg "Travis CI")](https://travis-ci.org/LudovicRousseau/pyscard) AppVeyor: [![Build status](https://ci.appveyor.com/api/projects/status/c97dsaodpcwkm0ra?svg=true)](https://ci.appveyor.com/project/LudovicRousseau/pyscard) From d552dbab1259f292b43139df678d3969d5a883c0 Mon Sep 17 00:00:00 2001 From: Ludovic Rousseau Date: Sat, 27 Jun 2015 17:15:00 +0200 Subject: [PATCH 29/43] configcheck.py: close file after use Do not forget to close the file handle when the file can be open correctly. --- smartcard/test/configcheck.py | 1 + 1 file changed, 1 insertion(+) diff --git a/smartcard/test/configcheck.py b/smartcard/test/configcheck.py index d7a6b339..59398c71 100755 --- a/smartcard/test/configcheck.py +++ b/smartcard/test/configcheck.py @@ -46,6 +46,7 @@ def checklocalconfig(): except IOError: print 'local_config.py not found; generating local_config.py...' else: + print 'regenerating local_config.py...' f.close() # generate local configuration From 734c8e604129cdcf79cd040e5a98ca62a5e3e075 Mon Sep 17 00:00:00 2001 From: Ludovic Rousseau Date: Sat, 27 Jun 2015 18:07:20 +0200 Subject: [PATCH 30/43] Release 1.7.0 --- ChangeLog | 7 ++++++- smartcard/doc/conf.py | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index ea498a40..a8a9d9a6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,12 @@ -1.7.0 (TBD) +1.7.0 (June 2015) =========== + * PCSCCardConnection: Fix a problem with mode=SCARD_SHARE_DIRECT + * add suppport of cygwin as a build plateform + * Fix a problem with Windows Remote Desktop + * Switch from distutils to setuptools * dropped support for Python 2.5 and earlier (Alex Willmer) * dropped support for OS X 10.5 (Leopard) and earlier (Alex Willmer) + * minot bugs fixed 1.6.16 (December 2014) diff --git a/smartcard/doc/conf.py b/smartcard/doc/conf.py index 3193fa66..a0fd0da2 100644 --- a/smartcard/doc/conf.py +++ b/smartcard/doc/conf.py @@ -50,9 +50,9 @@ # built documents. # # The short X.Y version. -version = '1.6.16' +version = '1.7.0' # The full version, including alpha/beta/rc tags. -release = '1.6.16' +release = '1.7.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. From e30f9f8753c5307b0dd12a9796b13676cdc61f0d Mon Sep 17 00:00:00 2001 From: Ludovic Rousseau Date: Sat, 27 Jun 2015 18:33:58 +0200 Subject: [PATCH 31/43] ChangeLog: fix typos and reformat Use spaces instead of tabs --- ChangeLog | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index a8a9d9a6..236b7146 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,12 +1,12 @@ 1.7.0 (June 2015) =========== - * PCSCCardConnection: Fix a problem with mode=SCARD_SHARE_DIRECT - * add suppport of cygwin as a build plateform - * Fix a problem with Windows Remote Desktop - * Switch from distutils to setuptools + * PCSCCardConnection: Fix a problem with mode=SCARD_SHARE_DIRECT + * add support of cygwin as a build platform + * Fix a problem with Windows Remote Desktop + * Switch from distutils to setuptools * dropped support for Python 2.5 and earlier (Alex Willmer) * dropped support for OS X 10.5 (Leopard) and earlier (Alex Willmer) - * minot bugs fixed + * minor bugs fixed 1.6.16 (December 2014) From cd82b304d778c54eeba5c825c0457bcb0378bf0f Mon Sep 17 00:00:00 2001 From: Ludovic Rousseau Date: Sun, 28 Jun 2015 19:24:19 +0200 Subject: [PATCH 32/43] setup.py: fix classifiers to conform to pypi Some values have been renamed or removed. --- setup.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 385b9832..118619a9 100755 --- a/setup.py +++ b/setup.py @@ -130,17 +130,17 @@ }, 'classifiers': [ - 'Development Status :: 5 - Release', + 'Development Status :: 5 - Production/Stable', 'License :: OSI Approved :: GNU Lesser General Public License v2 ' 'or later (LGPLv2+)', 'Intended Audience :: Developers', 'Operating System :: Unix', 'Operating System :: Microsoft :: Windows', - 'Operating System :: MacOS X', + 'Operating System :: MacOS :: MacOS X', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 2 :: Only', - 'Topic :: Security :: Smartcards', + 'Topic :: Security ', ] } From 06a3a92640a6d35de2971da27b523a61a07fd14e Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Fri, 19 Jun 2015 12:10:56 +0100 Subject: [PATCH 33/43] Remove support for Python releases older than 2.6 --- setup.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/setup.py b/setup.py index 118619a9..e03b6ed1 100755 --- a/setup.py +++ b/setup.py @@ -26,7 +26,12 @@ from distutils.util import get_platform import sys +<<<<<<< HEAD from setuptools import setup, Extension +======= +if sys.version_info[0:2] < (2, 6): + raise RuntimeError("pyscard requires Python 2.6+ to build.") +>>>>>>> Remove support for Python releases older than 2.6 if sys.version_info[0:2] < (2, 6): @@ -50,6 +55,15 @@ platform_extra_compile_args = [] platform_extra_link_args = [] +<<<<<<< HEAD +======= +# +# Mac OS X Lion (and above), python 2.7 +# PowerPC is no more supported, x86_64 is new +# +# x86_64 and i386 +# +>>>>>>> Remove support for Python releases older than 2.6 elif 'macosx-10.' in get_platform(): if 'macosx-10.6' in get_platform(): macosx_define = '__LEOPARD__' # Snow Leopard, Python 2.6 @@ -124,6 +138,7 @@ swig_opts=['-outdir', 'smartcard/scard'] \ + platform_swig_opts)], +<<<<<<< HEAD 'extras_require': { 'Gui': ['wxPython'], 'Pyro': ['Pyro'], @@ -133,6 +148,11 @@ 'Development Status :: 5 - Production/Stable', 'License :: OSI Approved :: GNU Lesser General Public License v2 ' 'or later (LGPLv2+)', +======= + 'classifiers': [ + 'Development Status :: 1.6.16 - Release', + 'License :: GNU LESSER GENERAL PUBLIC LICENSE', +>>>>>>> Remove support for Python releases older than 2.6 'Intended Audience :: Developers', 'Operating System :: Unix', 'Operating System :: Microsoft :: Windows', @@ -143,11 +163,22 @@ 'Topic :: Security ', ] } +<<<<<<< HEAD +======= + +# FIXME Sourceforge downloads are unauthenticated, migrate to PyPI +kw['download_url'] = ('http://sourceforge.net/projects/%(name)s/files' + '/%(name)s/%(name)s%%20%(version)s' + '/%(name)s-%(version)s.tar.gz/download' % kw) +>>>>>>> Remove support for Python releases older than 2.6 # FIXME Sourceforge downloads are unauthenticated, migrate to PyPI kw['download_url'] = ('http://sourceforge.net/projects/%(name)s/files' '/%(name)s/%(name)s%%20%(version)s' '/%(name)s-%(version)s.tar.gz/download' % kw) +<<<<<<< HEAD setup(**kw) +======= +>>>>>>> Remove support for Python releases older than 2.6 From 7eee76778ae5ea8c9e9244d999e523ab164252f8 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Fri, 19 Jun 2015 13:02:42 +0100 Subject: [PATCH 34/43] Consolidate build platform logic This also fixes Mac OS X Lion options being selected on Snow Leopard - due to misordered of elif blocks. --- setup.py | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/setup.py b/setup.py index e03b6ed1..556fefa0 100755 --- a/setup.py +++ b/setup.py @@ -26,13 +26,11 @@ from distutils.util import get_platform import sys -<<<<<<< HEAD from setuptools import setup, Extension -======= + + if sys.version_info[0:2] < (2, 6): raise RuntimeError("pyscard requires Python 2.6+ to build.") ->>>>>>> Remove support for Python releases older than 2.6 - if sys.version_info[0:2] < (2, 6): raise RuntimeError("pyscard requires Python 2.6+ to build.") @@ -55,15 +53,6 @@ platform_extra_compile_args = [] platform_extra_link_args = [] -<<<<<<< HEAD -======= -# -# Mac OS X Lion (and above), python 2.7 -# PowerPC is no more supported, x86_64 is new -# -# x86_64 and i386 -# ->>>>>>> Remove support for Python releases older than 2.6 elif 'macosx-10.' in get_platform(): if 'macosx-10.6' in get_platform(): macosx_define = '__LEOPARD__' # Snow Leopard, Python 2.6 @@ -138,7 +127,6 @@ swig_opts=['-outdir', 'smartcard/scard'] \ + platform_swig_opts)], -<<<<<<< HEAD 'extras_require': { 'Gui': ['wxPython'], 'Pyro': ['Pyro'], @@ -148,11 +136,6 @@ 'Development Status :: 5 - Production/Stable', 'License :: OSI Approved :: GNU Lesser General Public License v2 ' 'or later (LGPLv2+)', -======= - 'classifiers': [ - 'Development Status :: 1.6.16 - Release', - 'License :: GNU LESSER GENERAL PUBLIC LICENSE', ->>>>>>> Remove support for Python releases older than 2.6 'Intended Audience :: Developers', 'Operating System :: Unix', 'Operating System :: Microsoft :: Windows', @@ -163,22 +146,11 @@ 'Topic :: Security ', ] } -<<<<<<< HEAD -======= - -# FIXME Sourceforge downloads are unauthenticated, migrate to PyPI -kw['download_url'] = ('http://sourceforge.net/projects/%(name)s/files' - '/%(name)s/%(name)s%%20%(version)s' - '/%(name)s-%(version)s.tar.gz/download' % kw) ->>>>>>> Remove support for Python releases older than 2.6 # FIXME Sourceforge downloads are unauthenticated, migrate to PyPI kw['download_url'] = ('http://sourceforge.net/projects/%(name)s/files' '/%(name)s/%(name)s%%20%(version)s' '/%(name)s-%(version)s.tar.gz/download' % kw) -<<<<<<< HEAD setup(**kw) -======= ->>>>>>> Remove support for Python releases older than 2.6 From 578da23e87731d871141edfa0526ce0b7028bfb0 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Fri, 19 Jun 2015 13:07:56 +0100 Subject: [PATCH 35/43] Standardise Trove classifiers, declare OS & Python support --- setup.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/setup.py b/setup.py index 556fefa0..118619a9 100755 --- a/setup.py +++ b/setup.py @@ -29,9 +29,6 @@ from setuptools import setup, Extension -if sys.version_info[0:2] < (2, 6): - raise RuntimeError("pyscard requires Python 2.6+ to build.") - if sys.version_info[0:2] < (2, 6): raise RuntimeError("pyscard requires Python 2.6+ to build.") From bb11fd6d91dae88ee12e14f3d25206b9537a3e79 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Fri, 19 Jun 2015 13:14:55 +0100 Subject: [PATCH 36/43] Add gitignore for build artefacts --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 54d3aa03..1f05ea3a 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ smartcard/scard/scard_wrap.c # Generated by test suite smartcard/test/local_config.py + From 4baa14d7182dde572ffd68ee4db69bb4fb16711f Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Mon, 22 Jun 2015 14:29:54 +0100 Subject: [PATCH 37/43] Remove all but two uses of 'except:' & 'except Exception:' The remaining instance will now print a full traceback. This should improve on with https://sourceforge.net/p/pyscard/bugs/8/, or at least make it easier to solve --- smartcard/CardMonitoring.py | 12 ++---- .../Examples/framework/sample_MonitorCards.py | 8 +--- .../sample_MonitorCardsAndTransmit.py | 8 +--- .../framework/sample_MonitorReaders.py | 8 +--- .../framework/sample_TransmitCardObserver.py | 6 +-- smartcard/Examples/scard-api/sample_getATR.py | 14 +++--- .../Examples/scard-api/sample_getAttrib.py | 14 +++--- .../scard-api/sample_listInterfaces.py | 20 ++++----- smartcard/Examples/simple/selectDF_TELECOM.py | 4 -- smartcard/Examples/simple/simpleAPDU.py | 5 +-- smartcard/Examples/wx/pcscdiag/pcscdiag.py | 2 +- smartcard/ReaderMonitoring.py | 4 +- smartcard/System.py | 10 ++--- smartcard/doc/user-guide.rst | 43 ++++++++----------- smartcard/pyro/server/RemoteReaderServer.py | 2 +- smartcard/scard/__init__.py | 7 ++- smartcard/sw/ErrorCheckingChain.py | 16 +++---- smartcard/test/framework/testcase_ATR.py | 2 +- smartcard/test/framework/testcase_Card.py | 2 +- .../test/framework/testcase_CardConnection.py | 2 +- .../test/framework/testcase_CardMonitor.py | 2 +- .../test/framework/testcase_CardRequest.py | 2 +- .../test/framework/testcase_CardService.py | 2 +- smartcard/test/framework/testcase_CardType.py | 2 +- .../test/framework/testcase_ErrorChecking.py | 2 +- .../test/framework/testcase_readermonitor.py | 2 +- smartcard/test/framework/testcase_readers.py | 2 +- .../testcase_pcscreadergroups.py | 9 ++-- smartcard/test/scard/testcase_getatr.py | 2 +- smartcard/test/scard/testcase_getattrib.py | 2 +- smartcard/test/scard/testcase_locatecards.py | 2 +- smartcard/test/scard/testcase_readergroups.py | 2 +- smartcard/test/scard/testcase_transaction.py | 2 +- smartcard/util/__init__.py | 6 +-- 34 files changed, 92 insertions(+), 136 deletions(-) diff --git a/smartcard/CardMonitoring.py b/smartcard/CardMonitoring.py index 12076824..e0273a93 100644 --- a/smartcard/CardMonitoring.py +++ b/smartcard/CardMonitoring.py @@ -28,9 +28,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from sys import exc_info from threading import Thread, Event from time import sleep +import traceback from smartcard.System import readers from smartcard.Exceptions import CardRequestTimeoutException @@ -186,15 +186,9 @@ def run(self): pass except AttributeError: pass - except: - try: - import sys - print sys.exc_info()[1] - print sys.exc_info()[2] - print sys.exc_info()[0] - except: - pass + # FIXME Tighten the exceptions caught by this block + traceback.print_exc() # stop the thread by signaling stopEvent def stop(self): diff --git a/smartcard/Examples/framework/sample_MonitorCards.py b/smartcard/Examples/framework/sample_MonitorCards.py index 860d9547..c7a1bb5d 100755 --- a/smartcard/Examples/framework/sample_MonitorCards.py +++ b/smartcard/Examples/framework/sample_MonitorCards.py @@ -24,7 +24,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from sys import stdin, exc_info +import sys from time import sleep from smartcard.CardMonitoring import CardMonitor, CardObserver @@ -44,7 +44,7 @@ def update(self, observable, (addedcards, removedcards)): for card in removedcards: print "-Removed: ", toHexString(card.atr) -try: +if __name__ == '__main__': print "Insert or remove a smartcard in the system." print "This program will exit in 10 seconds" print "" @@ -58,10 +58,6 @@ def update(self, observable, (addedcards, removedcards)): # monitor will poll forever... cardmonitor.deleteObserver(cardobserver) - import sys if 'win32' == sys.platform: print 'press Enter to continue' sys.stdin.read(1) - -except: - print exc_info()[0], ':', exc_info()[1] diff --git a/smartcard/Examples/framework/sample_MonitorCardsAndTransmit.py b/smartcard/Examples/framework/sample_MonitorCardsAndTransmit.py index 8aa93645..5180a466 100755 --- a/smartcard/Examples/framework/sample_MonitorCardsAndTransmit.py +++ b/smartcard/Examples/framework/sample_MonitorCardsAndTransmit.py @@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from sys import stdin, exc_info +import sys from time import sleep from smartcard.CardConnectionObserver import ConsoleCardConnectionObserver @@ -63,7 +63,7 @@ def update(self, observable, (addedcards, removedcards)): for card in removedcards: print "-Removed: ", toHexString(card.atr) -try: +if __name__ == '__main__': print "Insert or remove a SIM card in the system." print "This program will exit in 60 seconds" print "" @@ -77,10 +77,6 @@ def update(self, observable, (addedcards, removedcards)): # monitor will poll forever... cardmonitor.deleteObserver(selectobserver) - import sys if 'win32' == sys.platform: print 'press Enter to continue' sys.stdin.read(1) - -except: - print exc_info()[0], ':', exc_info()[1] diff --git a/smartcard/Examples/framework/sample_MonitorReaders.py b/smartcard/Examples/framework/sample_MonitorReaders.py index 178b6a87..49e22b4b 100755 --- a/smartcard/Examples/framework/sample_MonitorReaders.py +++ b/smartcard/Examples/framework/sample_MonitorReaders.py @@ -24,7 +24,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from sys import stdin, exc_info +import sys from time import sleep from smartcard.ReaderMonitoring import ReaderMonitor, ReaderObserver @@ -40,7 +40,7 @@ def update(self, observable, (addedreaders, removedreaders)): print "Added readers", addedreaders print "Removed readers", removedreaders -try: +if __name__ == '__main__': print "Add or remove a smartcard reader to the system." print "This program will exit in 10 seconds" print "" @@ -54,10 +54,6 @@ def update(self, observable, (addedreaders, removedreaders)): # monitor will poll forever... readermonitor.deleteObserver(readerobserver) - import sys if 'win32' == sys.platform: print 'press Enter to continue' sys.stdin.read(1) - -except: - print exc_info()[0], ':', exc_info()[1] diff --git a/smartcard/Examples/framework/sample_TransmitCardObserver.py b/smartcard/Examples/framework/sample_TransmitCardObserver.py index efa83a1c..80b6dc9a 100755 --- a/smartcard/Examples/framework/sample_TransmitCardObserver.py +++ b/smartcard/Examples/framework/sample_TransmitCardObserver.py @@ -24,7 +24,6 @@ along with pyscard; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from sys import stdin, exc_info from time import sleep from smartcard.CardMonitoring import CardMonitor, CardObserver @@ -57,7 +56,7 @@ def update(self, observable, (addedcards, removedcards)): if card in self.cards: self.cards.remove(card) -try: +if __name__ == '__main__': print "Insert or remove a smartcard in the system." print "This program will exit in 100 seconds" print "" @@ -66,6 +65,3 @@ def update(self, observable, (addedcards, removedcards)): cardmonitor.addObserver(cardobserver) sleep(100) - -except: - print exc_info()[0], ':', exc_info()[1] diff --git a/smartcard/Examples/scard-api/sample_getATR.py b/smartcard/Examples/scard-api/sample_getATR.py index ec7fd59b..cba2f258 100755 --- a/smartcard/Examples/scard-api/sample_getATR.py +++ b/smartcard/Examples/scard-api/sample_getATR.py @@ -26,10 +26,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ +import sys + from smartcard.scard import * import smartcard.util -try: +if __name__ == '__main__': hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER) if hresult != SCARD_S_SUCCESS: raise error( @@ -86,10 +88,6 @@ SCardGetErrorMessage(hresult)) print 'Released context.' -except Exception, e: - print e - -import sys -if 'win32' == sys.platform: - print 'press Enter to continue' - sys.stdin.read(1) + if 'win32' == sys.platform: + print 'press Enter to continue' + sys.stdin.read(1) diff --git a/smartcard/Examples/scard-api/sample_getAttrib.py b/smartcard/Examples/scard-api/sample_getAttrib.py index 1834e9cd..01ef61d1 100755 --- a/smartcard/Examples/scard-api/sample_getAttrib.py +++ b/smartcard/Examples/scard-api/sample_getAttrib.py @@ -27,6 +27,8 @@ """ import struct +import sys + from smartcard.scard import * import smartcard.util @@ -90,7 +92,7 @@ def printAttribute(attrib, value): print apply(struct.pack, ['<' + 'B' * len(value)] + value) -try: +if __name__ == '__main__': hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER) if hresult != SCARD_S_SUCCESS: raise error( @@ -149,10 +151,6 @@ def printAttribute(attrib, value): SCardGetErrorMessage(hresult)) print 'Released context.' -except Exception, e: - print e - -import sys -if 'win32' == sys.platform: - print 'press Enter to continue' - sys.stdin.read(1) + if 'win32' == sys.platform: + print 'press Enter to continue' + sys.stdin.read(1) diff --git a/smartcard/Examples/scard-api/sample_listInterfaces.py b/smartcard/Examples/scard-api/sample_listInterfaces.py index d5611f14..6289b8b7 100755 --- a/smartcard/Examples/scard-api/sample_listInterfaces.py +++ b/smartcard/Examples/scard-api/sample_listInterfaces.py @@ -26,6 +26,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ +import sys + import platform from smartcard.scard import * import smartcard.guid @@ -42,7 +44,7 @@ znewcardSecGuid = \ smartcard.guid.strToGUID('{EB7F69EA-BA20-47d0-8C50-11CFDEB63BBE}') - try: + def main(): hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER) if hresult != SCARD_S_SUCCESS: raise scard.error( @@ -108,15 +110,13 @@ SCardGetErrorMessage(hresult)) print 'Released context.' - except error: - import sys - print sys.exc_info()[0], ':', sys.exc_info()[1] - elif 'pcsclite' == resourceManager: - print 'SCardListInterfaces not supported by pcsc lite' + def main(): + print 'SCardListInterfaces not supported by pcsc lite' -import sys -if 'win32' == sys.platform: - print 'press Enter to continue' - sys.stdin.read(1) +if __name__ == '__main__': + main() + if 'win32' == sys.platform: + print 'press Enter to continue' + sys.stdin.read(1) diff --git a/smartcard/Examples/simple/selectDF_TELECOM.py b/smartcard/Examples/simple/selectDF_TELECOM.py index ce88ccd3..5050f52a 100755 --- a/smartcard/Examples/simple/selectDF_TELECOM.py +++ b/smartcard/Examples/simple/selectDF_TELECOM.py @@ -65,10 +65,6 @@ except CardRequestTimeoutException: print 'time-out: no card inserted during last 10s' -except: - import sys - print sys.exc_info()[1] - import sys if 'win32' == sys.platform: print 'press Enter to continue' diff --git a/smartcard/Examples/simple/simpleAPDU.py b/smartcard/Examples/simple/simpleAPDU.py index 1d8512f4..38233132 100755 --- a/smartcard/Examples/simple/simpleAPDU.py +++ b/smartcard/Examples/simple/simpleAPDU.py @@ -32,7 +32,7 @@ 0x18, 0xFF] GET_TIME = [0x80, 0x38, 0x00, 0xA0] -try: +if __name__ == '__main__': # get all the available readers r = readers() print "Available readers: ", r @@ -51,6 +51,3 @@ data, sw1, sw2 = connection.transmit(GET_TIME) print "Get Time: %02X %02X" % (sw1, sw2) - -except: - print sys.exc_info()[1] diff --git a/smartcard/Examples/wx/pcscdiag/pcscdiag.py b/smartcard/Examples/wx/pcscdiag/pcscdiag.py index e4fbed9e..77881286 100755 --- a/smartcard/Examples/wx/pcscdiag/pcscdiag.py +++ b/smartcard/Examples/wx/pcscdiag/pcscdiag.py @@ -34,7 +34,7 @@ # wxPython GUI modules (http://www.wxpython.org) try: import wx -except: +except ImportError: print 'You need wxpython (http://www.wxpython.org) ' + \ 'to run this sample from the source code!' print 'press a key to continue' diff --git a/smartcard/ReaderMonitoring.py b/smartcard/ReaderMonitoring.py index 0d9da5dc..62aab450 100644 --- a/smartcard/ReaderMonitoring.py +++ b/smartcard/ReaderMonitoring.py @@ -28,9 +28,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from sys import exc_info from threading import Thread, Event, enumerate from time import sleep +import traceback import smartcard.System from smartcard.Exceptions import ListReadersException @@ -183,6 +183,8 @@ def run(self): self.stopEvent.wait(self.period) except Exception, e: + # FIXME Tighten the exceptions caught by this block + traceback.print_exc() # Most likely raised during interpreter shutdown due # to unclean exit which failed to remove all observers. # To solve this, we set the stop event and pass the diff --git a/smartcard/System.py b/smartcard/System.py index 27970d15..d6a20ca3 100644 --- a/smartcard/System.py +++ b/smartcard/System.py @@ -60,10 +60,6 @@ def listReaders(): if __name__ == '__main__': - try: - print readers() - print readers(['SCard$DefaultReaders']) - print readergroups() - except: - import sys - print sys.exc_info()[1] + print readers() + print readers(['SCard$DefaultReaders']) + print readergroups() diff --git a/smartcard/doc/user-guide.rst b/smartcard/doc/user-guide.rst index 7a890a20..b7f801df 100644 --- a/smartcard/doc/user-guide.rst +++ b/smartcard/doc/user-guide.rst @@ -1199,30 +1199,26 @@ To monitor reader insertion/removal, simply add the observer to the .. sourcecode:: python - from sys import stdin, exc_info + from sys import stdin from time import sleep from smartcard.ReaderMonitoring import ReaderMonitor, ReaderObserver - try: - print "Add or remove a smartcard reader to the system." - print "This program will exit in 10 seconds" - print "" - readermonitor = ReaderMonitor() - readerobserver = printobserver() - readermonitor.addObserver( readerobserver ) - - sleep(10) + print "Add or remove a smartcard reader to the system." + print "This program will exit in 10 seconds" + print "" + readermonitor = ReaderMonitor() + readerobserver = printobserver() + readermonitor.addObserver( readerobserver ) - # don't forget to remove observer, or the - # monitor will poll forever... - readermonitor.deleteObserver(readerobserver) + sleep(10) - print 'press Enter to continue' - stdin.readline() + # don't forget to remove observer, or the + # monitor will poll forever... + readermonitor.deleteObserver(readerobserver) - except error: - print exc_info()[0], ': ', exc_info()[1] + print 'press Enter to continue' + stdin.readline() Smart Cards *********** @@ -1261,13 +1257,12 @@ card observer to the `CardMonitor for card in removedcards: print "-Removed: ", toHexString( card.atr ) - try: - print "Insert or remove a smartcard in the system." - print "This program will exit in 10 seconds" - print "" - cardmonitor = CardMonitor() - cardobserver = printobserver() - cardmonitor.addObserver( cardobserver ) + print "Insert or remove a smartcard in the system." + print "This program will exit in 10 seconds" + print "" + cardmonitor = CardMonitor() + cardobserver = printobserver() + cardmonitor.addObserver( cardobserver ) Sending APDUs to a Smart Card Obtained from Card Monitoring diff --git a/smartcard/pyro/server/RemoteReaderServer.py b/smartcard/pyro/server/RemoteReaderServer.py index 06db9b1e..f29096de 100644 --- a/smartcard/pyro/server/RemoteReaderServer.py +++ b/smartcard/pyro/server/RemoteReaderServer.py @@ -26,7 +26,7 @@ try: import Pyro.core import Pyro.naming -except: +except ImportError: print 'You need pyro (python remote objects) ' + \ 'at http://www.xs4all.nl/~irmen/pyro3/' import sys diff --git a/smartcard/scard/__init__.py b/smartcard/scard/__init__.py index 596417c8..e1a9ffb7 100644 --- a/smartcard/scard/__init__.py +++ b/smartcard/scard/__init__.py @@ -1,4 +1,3 @@ -try: - from scard import * -except: - from smartcard.scard._scard import * +from __future__ import absolute_import + +from smartcard.scard.scard import * diff --git a/smartcard/sw/ErrorCheckingChain.py b/smartcard/sw/ErrorCheckingChain.py index d8c0a5ad..77123d54 100644 --- a/smartcard/sw/ErrorCheckingChain.py +++ b/smartcard/sw/ErrorCheckingChain.py @@ -23,9 +23,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from sys import exc_info - - class ErrorCheckingChain(object): """The error checking chain is a list of response apdu status word (sw1, sw2) error check strategies. Each strategy in the chain is @@ -76,11 +73,14 @@ def __call__(self, data, sw1, sw2): """Called to test data, sw1 and sw2 for error on the chain.""" try: self.strategy(data, sw1, sw2) - except: - # if exception is filtered, return - for exception in self.excludes: - if exception == exc_info()[0]: - return + except tuple(self.excludes) as exc: + # The following addtional filter may look redundant, it isn't.s + # It checks that type(exc) is *equal* to any of self.excludes, + # rather than equal-or-subclass to any of self.excludes. + # This is to keep backward compatibility with the behaviour of + # pyscard <= 1.6.16. + if type(exc) in self.excludes: + return # otherwise reraise exception raise diff --git a/smartcard/test/framework/testcase_ATR.py b/smartcard/test/framework/testcase_ATR.py index b64de568..03dbbe55 100755 --- a/smartcard/test/framework/testcase_ATR.py +++ b/smartcard/test/framework/testcase_ATR.py @@ -38,7 +38,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/framework/testcase_Card.py b/smartcard/test/framework/testcase_Card.py index c8b25b41..6ea594b1 100755 --- a/smartcard/test/framework/testcase_Card.py +++ b/smartcard/test/framework/testcase_Card.py @@ -39,7 +39,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/framework/testcase_CardConnection.py b/smartcard/test/framework/testcase_CardConnection.py index 082cc420..4a9abbd5 100755 --- a/smartcard/test/framework/testcase_CardConnection.py +++ b/smartcard/test/framework/testcase_CardConnection.py @@ -39,7 +39,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/framework/testcase_CardMonitor.py b/smartcard/test/framework/testcase_CardMonitor.py index 2365926d..bea14870 100755 --- a/smartcard/test/framework/testcase_CardMonitor.py +++ b/smartcard/test/framework/testcase_CardMonitor.py @@ -41,7 +41,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/framework/testcase_CardRequest.py b/smartcard/test/framework/testcase_CardRequest.py index 55463fdd..10826621 100755 --- a/smartcard/test/framework/testcase_CardRequest.py +++ b/smartcard/test/framework/testcase_CardRequest.py @@ -39,7 +39,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader, expectedReaderForATR -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/framework/testcase_CardService.py b/smartcard/test/framework/testcase_CardService.py index a5bcd10d..a11bd591 100755 --- a/smartcard/test/framework/testcase_CardService.py +++ b/smartcard/test/framework/testcase_CardService.py @@ -38,7 +38,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/framework/testcase_CardType.py b/smartcard/test/framework/testcase_CardType.py index 0afaa6ee..293afb64 100755 --- a/smartcard/test/framework/testcase_CardType.py +++ b/smartcard/test/framework/testcase_CardType.py @@ -39,7 +39,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/framework/testcase_ErrorChecking.py b/smartcard/test/framework/testcase_ErrorChecking.py index 6463fca9..fb4c4f9d 100755 --- a/smartcard/test/framework/testcase_ErrorChecking.py +++ b/smartcard/test/framework/testcase_ErrorChecking.py @@ -49,7 +49,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/framework/testcase_readermonitor.py b/smartcard/test/framework/testcase_readermonitor.py index 3536aefb..d767d230 100755 --- a/smartcard/test/framework/testcase_readermonitor.py +++ b/smartcard/test/framework/testcase_readermonitor.py @@ -41,7 +41,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/framework/testcase_readers.py b/smartcard/test/framework/testcase_readers.py index 5e531e29..a0f674fa 100755 --- a/smartcard/test/framework/testcase_readers.py +++ b/smartcard/test/framework/testcase_readers.py @@ -38,7 +38,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/frameworkpcsc/testcase_pcscreadergroups.py b/smartcard/test/frameworkpcsc/testcase_pcscreadergroups.py index cf9a0218..bc53bcac 100755 --- a/smartcard/test/frameworkpcsc/testcase_pcscreadergroups.py +++ b/smartcard/test/frameworkpcsc/testcase_pcscreadergroups.py @@ -38,7 +38,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() @@ -54,11 +54,8 @@ class testcase_readergroups(unittest.TestCase): def setUp(self): groups = PCSCReaderGroups().instance - try: - groups.remove('Pinpad$Readers') - groups.remove('Biometric$Readers') - except: - pass + groups.remove('Pinpad$Readers') + groups.remove('Biometric$Readers') def testcase_add(self): """Test for groups=groups+newgroups""" diff --git a/smartcard/test/scard/testcase_getatr.py b/smartcard/test/scard/testcase_getatr.py index 45541a21..f3c0ee6a 100755 --- a/smartcard/test/scard/testcase_getatr.py +++ b/smartcard/test/scard/testcase_getatr.py @@ -39,7 +39,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/scard/testcase_getattrib.py b/smartcard/test/scard/testcase_getattrib.py index d73c2168..6f9735e1 100755 --- a/smartcard/test/scard/testcase_getattrib.py +++ b/smartcard/test/scard/testcase_getattrib.py @@ -40,7 +40,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/scard/testcase_locatecards.py b/smartcard/test/scard/testcase_locatecards.py index fc25ad9e..b78cad3c 100755 --- a/smartcard/test/scard/testcase_locatecards.py +++ b/smartcard/test/scard/testcase_locatecards.py @@ -39,7 +39,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/scard/testcase_readergroups.py b/smartcard/test/scard/testcase_readergroups.py index b2e18349..5bf6bb93 100755 --- a/smartcard/test/scard/testcase_readergroups.py +++ b/smartcard/test/scard/testcase_readergroups.py @@ -38,7 +38,7 @@ try: from local_config import expectedReaders -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/scard/testcase_transaction.py b/smartcard/test/scard/testcase_transaction.py index eb811320..a6315222 100755 --- a/smartcard/test/scard/testcase_transaction.py +++ b/smartcard/test/scard/testcase_transaction.py @@ -38,7 +38,7 @@ try: from local_config import expectedATRs, expectedReaders -except: +except ImportError: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/util/__init__.py b/smartcard/util/__init__.py index 873a9ceb..2a8233a8 100644 --- a/smartcard/util/__init__.py +++ b/smartcard/util/__init__.py @@ -97,14 +97,14 @@ def toBytes(bytestring): >>> toBytes("3B6500 009C1101 0103") [59, 101, 0, 0, 156, 17, 1, 1, 3] """ - from struct import unpack + import struct import re packedstring = ''.join(re.split('\W+', bytestring)) try: return reduce(lambda x, y: x + [int(y, 16)], - unpack('2s' * (len(packedstring) / 2), + struct.unpack('2s' * (len(packedstring) / 2), packedstring), []) - except: + except (struct.error, ValueError): raise TypeError('not a string representing a list of bytes') From b64ec04adb382275e481d9f41fd4acecd270a1d9 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Mon, 22 Jun 2015 18:18:43 +0100 Subject: [PATCH 38/43] Fix most major pylint errors and warnings 5 undefined variables remain unfixed, they appear to be missing `smartcard.scard.scard` exports ``` ************* Module smartcard.pcsc.PCSCReader E: 67,22: Undefined variable 'SCardIntroduceReader' (undefined-variable) E: 70,22: Undefined variable 'SCardAddReaderToGroup' (undefined- variable) E: 85,22: Undefined variable 'SCardRemoveReaderFromGroup' (undefined- variable) ************* Module smartcard.pcsc.PCSCReaderGroups E: 66,22: Undefined variable 'SCardIntroduceReaderGroup' (undefined- variable) E: 90,22: Undefined variable 'SCardForgetReaderGroup' (undefined- variable) ``` --- smartcard/Card.py | 1 - smartcard/CardConnection.py | 2 -- smartcard/CardMonitoring.py | 4 ---- smartcard/CardService.py | 1 - smartcard/CardType.py | 1 + smartcard/ClassLoader.py | 4 ---- smartcard/ExclusiveConnectCardConnection.py | 1 - smartcard/ExclusiveTransmitCardConnection.py | 2 -- smartcard/Observer.py | 2 +- smartcard/PassThruCardService.py | 1 - smartcard/ReaderMonitoring.py | 4 +--- smartcard/Session.py | 6 ------ smartcard/guid.py | 1 - smartcard/pcsc/PCSCCardConnection.py | 1 - smartcard/pyro/PyroReader.py | 3 +-- smartcard/pyro/server/PyroDaemon.py | 4 ++-- smartcard/pyro/server/PyroEventServer.py | 1 - smartcard/pyro/server/RemoteCardConnection.py | 3 --- smartcard/pyro/server/RemoteReaderServer.py | 4 ---- smartcard/reader/ReaderGroups.py | 3 --- smartcard/sw/ErrorChecker.py | 2 +- smartcard/util/__init__.py | 5 +---- smartcard/wx/APDUHexValidator.py | 2 +- smartcard/wx/CardAndReaderTreePanel.py | 4 ++-- smartcard/wx/ReaderToolbar.py | 4 ++-- smartcard/wx/SimpleSCardAppFrame.py | 7 ++++--- 26 files changed, 17 insertions(+), 56 deletions(-) diff --git a/smartcard/Card.py b/smartcard/Card.py index b82fad52..a261c744 100644 --- a/smartcard/Card.py +++ b/smartcard/Card.py @@ -21,7 +21,6 @@ along with pyscard; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from smartcard.Exceptions import CardConnectionException, NoCardException from smartcard.reader.Reader import Reader from smartcard.System import readers from smartcard.util import toHexString diff --git a/smartcard/CardConnection.py b/smartcard/CardConnection.py index 607185e0..15bb52b2 100644 --- a/smartcard/CardConnection.py +++ b/smartcard/CardConnection.py @@ -24,8 +24,6 @@ """ from smartcard.CardConnectionEvent import CardConnectionEvent -from smartcard.Exceptions import SmartcardException -from smartcard.Observer import Observer from smartcard.Observer import Observable diff --git a/smartcard/CardMonitoring.py b/smartcard/CardMonitoring.py index e0273a93..30991e30 100644 --- a/smartcard/CardMonitoring.py +++ b/smartcard/CardMonitoring.py @@ -32,12 +32,9 @@ from time import sleep import traceback -from smartcard.System import readers -from smartcard.Exceptions import CardRequestTimeoutException from smartcard.Observer import Observer from smartcard.Observer import Observable -from smartcard.CardType import AnyCardType from smartcard.CardRequest import CardRequest _START_ON_DEMAND_ = False @@ -216,7 +213,6 @@ def __getattr__(self, name): if __name__ == "__main__": - from smartcard.CardMonitoring import CardMonitor print 'insert or remove cards in the next 10 seconds' # a simple card observer that prints added/removed cards diff --git a/smartcard/CardService.py b/smartcard/CardService.py index b310f19a..0a2cf27a 100644 --- a/smartcard/CardService.py +++ b/smartcard/CardService.py @@ -30,7 +30,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from smartcard.Exceptions import SmartcardException from smartcard.scard import * diff --git a/smartcard/CardType.py b/smartcard/CardType.py index 722a1cd1..d88ad047 100644 --- a/smartcard/CardType.py +++ b/smartcard/CardType.py @@ -21,6 +21,7 @@ along with pyscard; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ +from smartcard.Exceptions import InvalidATRMaskLengthException from smartcard.System import readers from smartcard.util import toHexString diff --git a/smartcard/ClassLoader.py b/smartcard/ClassLoader.py index 3b232152..3cc59c56 100644 --- a/smartcard/ClassLoader.py +++ b/smartcard/ClassLoader.py @@ -9,10 +9,6 @@ License: PSF license (http://docs.python.org/license.html). """ -import sys -import types - - def get_mod(modulePath): """Import a module.""" return __import__(modulePath, globals(), locals(), ['']) diff --git a/smartcard/ExclusiveConnectCardConnection.py b/smartcard/ExclusiveConnectCardConnection.py index 8d1f0cbf..ee3524ce 100644 --- a/smartcard/ExclusiveConnectCardConnection.py +++ b/smartcard/ExclusiveConnectCardConnection.py @@ -21,7 +21,6 @@ along with pyscard; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from smartcard.CardConnection import CardConnection from smartcard.CardConnectionDecorator import CardConnectionDecorator from smartcard.Exceptions import CardConnectionException from smartcard.scard import SCardConnect, SCardDisconnect diff --git a/smartcard/ExclusiveTransmitCardConnection.py b/smartcard/ExclusiveTransmitCardConnection.py index bbffa4da..ca836373 100644 --- a/smartcard/ExclusiveTransmitCardConnection.py +++ b/smartcard/ExclusiveTransmitCardConnection.py @@ -21,13 +21,11 @@ along with pyscard; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from smartcard.CardConnection import CardConnection from smartcard.CardConnectionDecorator import CardConnectionDecorator from smartcard.Exceptions import CardConnectionException from smartcard.scard import SCardBeginTransaction, SCardEndTransaction from smartcard.scard import SCARD_LEAVE_CARD from smartcard.scard import SCardGetErrorMessage -from smartcard.pcsc import PCSCCardConnection import smartcard.pcsc diff --git a/smartcard/Observer.py b/smartcard/Observer.py index b5f2b4ca..ce1d94fc 100644 --- a/smartcard/Observer.py +++ b/smartcard/Observer.py @@ -19,7 +19,7 @@ class Observer(object): - def update(observable, arg): + def update(self, observable, arg): '''Called when the observed object is modified. You call an Observable object's notifyObservers method to notify all the diff --git a/smartcard/PassThruCardService.py b/smartcard/PassThruCardService.py index d22a48a3..25715354 100644 --- a/smartcard/PassThruCardService.py +++ b/smartcard/PassThruCardService.py @@ -53,7 +53,6 @@ def supports(cardname): SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02] DF_TELECOM = [0x7F, 0x10] from smartcard.System import readers - from smartcard.CardConnection import CardConnection cc = readers()[0].createConnection() cs = PassThruCardService(cc) cs.connection.connect() diff --git a/smartcard/ReaderMonitoring.py b/smartcard/ReaderMonitoring.py index 62aab450..cebcb07c 100644 --- a/smartcard/ReaderMonitoring.py +++ b/smartcard/ReaderMonitoring.py @@ -28,12 +28,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from threading import Thread, Event, enumerate +from threading import Thread, Event from time import sleep import traceback import smartcard.System -from smartcard.Exceptions import ListReadersException from smartcard.Observer import Observer from smartcard.Observer import Observable from smartcard.Synchronization import * @@ -196,7 +195,6 @@ def stop(self): self.join() if __name__ == "__main__": - from smartcard.ReaderMonitoring import ReaderMonitor print 'insert or remove readers in the next 20 seconds' # a simple reader observer that prints added/removed readers diff --git a/smartcard/Session.py b/smartcard/Session.py index a700eddb..78515999 100644 --- a/smartcard/Session.py +++ b/smartcard/Session.py @@ -24,7 +24,6 @@ """ from smartcard.Exceptions import InvalidReaderException, NoReadersException -from smartcard.CardConnection import CardConnection from smartcard.PassThruCardService import PassThruCardService from smartcard.System import readers @@ -110,8 +109,3 @@ def getATR(self): def __repr__(self): """Returns a string representation of the session.""" return "" % self.readerName - - -if __name__ == '__main__': - """Small sample illustrating the use of Session.py.""" - pass diff --git a/smartcard/guid.py b/smartcard/guid.py index c8715a72..497f25bf 100644 --- a/smartcard/guid.py +++ b/smartcard/guid.py @@ -60,7 +60,6 @@ def GUIDToStr(g): if __name__ == "__main__": """Small sample illustrating the use of guid.py.""" - import smartcard.guid dummycardguid1 = strToGUID('{AD4F1667-EA75-4124-84D4-641B3B197C65}') print dummycardguid1 print GUIDToStr(dummycardguid1) diff --git a/smartcard/pcsc/PCSCCardConnection.py b/smartcard/pcsc/PCSCCardConnection.py index 9842cfe9..c770f9ec 100644 --- a/smartcard/pcsc/PCSCCardConnection.py +++ b/smartcard/pcsc/PCSCCardConnection.py @@ -25,7 +25,6 @@ from smartcard.CardConnection import CardConnection from smartcard.Exceptions import (CardConnectionException, NoCardException, SmartcardException) -from smartcard.Observer import Observable from smartcard.scard import * diff --git a/smartcard/pyro/PyroReader.py b/smartcard/pyro/PyroReader.py index 7023cc89..a6fe396f 100644 --- a/smartcard/pyro/PyroReader.py +++ b/smartcard/pyro/PyroReader.py @@ -25,9 +25,8 @@ import Pyro.core import Pyro.naming -from smartcard.Exceptions import CardConnectionException, NoCardException +from smartcard.Exceptions import NoCardException from smartcard.reader.Reader import Reader -from smartcard.reader.ReaderFactory import ReaderFactory class PyroReader(Reader): diff --git a/smartcard/pyro/server/PyroDaemon.py b/smartcard/pyro/server/PyroDaemon.py index 89b5d1ae..90eac204 100644 --- a/smartcard/pyro/server/PyroDaemon.py +++ b/smartcard/pyro/server/PyroDaemon.py @@ -85,8 +85,8 @@ def __init__(self): Thread.__init__(self) self.setDaemon(True) self.setName('smartcard.pyro.server.PyroDaemonThread') - self.daemon = PyroDaemon() + self._daemon = PyroDaemon() def run(self): """Starts Pyro daemon.""" - self.daemon.start() + self._daemon.start() diff --git a/smartcard/pyro/server/PyroEventServer.py b/smartcard/pyro/server/PyroEventServer.py index 90c4d998..2503e082 100644 --- a/smartcard/pyro/server/PyroEventServer.py +++ b/smartcard/pyro/server/PyroEventServer.py @@ -92,7 +92,6 @@ def __call__(self, signame, sf): if __name__ == '__main__': - import sys from smartcard.pyro.server.PyroNameServer import PyroNameServer pn = PyroNameServer(sys.argv[1:]) pn.start() diff --git a/smartcard/pyro/server/RemoteCardConnection.py b/smartcard/pyro/server/RemoteCardConnection.py index 9df373ee..2b092b7c 100644 --- a/smartcard/pyro/server/RemoteCardConnection.py +++ b/smartcard/pyro/server/RemoteCardConnection.py @@ -26,10 +26,7 @@ import Pyro.core import Pyro.naming -from smartcard.CardConnection import CardConnection from smartcard.CardConnectionDecorator import CardConnectionDecorator -from smartcard.Exceptions import CardConnectionException, NoCardException -from smartcard.Observer import Observable class RemoteCardConnection(CardConnectionDecorator, Pyro.core.ObjBase): diff --git a/smartcard/pyro/server/RemoteReaderServer.py b/smartcard/pyro/server/RemoteReaderServer.py index f29096de..f3e715fe 100644 --- a/smartcard/pyro/server/RemoteReaderServer.py +++ b/smartcard/pyro/server/RemoteReaderServer.py @@ -32,10 +32,6 @@ import sys sys.exit() -import signal -import time - -import smartcard.System from smartcard.reader.Reader import Reader from smartcard.ReaderMonitoring import ReaderMonitor, ReaderObserver from smartcard.pyro.server.RemoteCardConnection import RemoteCardConnection diff --git a/smartcard/reader/ReaderGroups.py b/smartcard/reader/ReaderGroups.py index 4e6cfbc1..64475944 100644 --- a/smartcard/reader/ReaderGroups.py +++ b/smartcard/reader/ReaderGroups.py @@ -67,9 +67,6 @@ def __onremoveitem__(self, item): def __iter__(self): return ulist.__iter__(self) - def next(self): - return ulist.__next__(self) - # # abstract methods implemented in subclasses # diff --git a/smartcard/sw/ErrorChecker.py b/smartcard/sw/ErrorChecker.py index d29f0478..1296ff22 100644 --- a/smartcard/sw/ErrorChecker.py +++ b/smartcard/sw/ErrorChecker.py @@ -36,7 +36,7 @@ class ErrorChecker(object): pattern. """ - def __call__(data, sw1, sw2): + def __call__(self, data, sw1, sw2): """Called to test data, sw1 and sw2 for error. @param data: apdu response data diff --git a/smartcard/util/__init__.py b/smartcard/util/__init__.py index 2a8233a8..68fe0ba6 100644 --- a/smartcard/util/__init__.py +++ b/smartcard/util/__init__.py @@ -99,7 +99,7 @@ def toBytes(bytestring): """ import struct import re - packedstring = ''.join(re.split('\W+', bytestring)) + packedstring = ''.join(re.split(r'\W+', bytestring)) try: return reduce(lambda x, y: x + [int(y, 16)], struct.unpack('2s' * (len(packedstring) / 2), @@ -204,9 +204,6 @@ def toHexString(bytes=[], format=0): from string import rstrip - for byte in tuple(bytes): - pass - if type(bytes) is not list: raise TypeError('not a list of bytes') diff --git a/smartcard/wx/APDUHexValidator.py b/smartcard/wx/APDUHexValidator.py index dd090ddf..4e16ceb6 100644 --- a/smartcard/wx/APDUHexValidator.py +++ b/smartcard/wx/APDUHexValidator.py @@ -48,7 +48,7 @@ def Clone(self): def Validate(self, win): tc = self.GetWindow() - val = tc.GetValue() + value = tc.GetValue() if not apduregexp.match(value): return False diff --git a/smartcard/wx/CardAndReaderTreePanel.py b/smartcard/wx/CardAndReaderTreePanel.py index 0841ec1d..8106ef9f 100644 --- a/smartcard/wx/CardAndReaderTreePanel.py +++ b/smartcard/wx/CardAndReaderTreePanel.py @@ -408,9 +408,9 @@ def __init__(self, parent, appstyle, clientpanel): def OnDestroy(self, event): """Called on panel destruction.""" # deregister observers - if hasattr(self, cardmonitor): + if hasattr(self, 'cardmonitor'): self.cardmonitor.deleteObserver(self.cardtreecardobserver) - if hasattr(self, readermonitor): + if hasattr(self, 'readermonitor'): self.readermonitor.deleteObserver(self.readertreereaderobserver) self.cardmonitor.deleteObserver(self.readertreecardobserver) event.Skip() diff --git a/smartcard/wx/ReaderToolbar.py b/smartcard/wx/ReaderToolbar.py index 946dfab0..fd353be8 100644 --- a/smartcard/wx/ReaderToolbar.py +++ b/smartcard/wx/ReaderToolbar.py @@ -77,12 +77,12 @@ def __init__(self, parent): bmpReader = wx.Bitmap(ICO_READER, wx.BITMAP_TYPE_ICO) else: bmpReader = wx.ArtProvider_GetBitmap( - wx.ART_HELP_BOOK, wx.ART_OTHER, isz) + wx.ART_HELP_BOOK, wx.ART_OTHER, tsize) if None != ICO_SMARTCARD: bmpCard = wx.Bitmap(ICO_SMARTCARD, wx.BITMAP_TYPE_ICO) else: bmpCard = wx.ArtProvider_GetBitmap( - wx.ART_HELP_BOOK, wx.ART_OTHER, isz) + wx.ART_HELP_BOOK, wx.ART_OTHER, tsize) self.readercombobox = ReaderComboBox(self) # create and add controls diff --git a/smartcard/wx/SimpleSCardAppFrame.py b/smartcard/wx/SimpleSCardAppFrame.py index cd5166cc..193c8a56 100644 --- a/smartcard/wx/SimpleSCardAppFrame.py +++ b/smartcard/wx/SimpleSCardAppFrame.py @@ -26,10 +26,11 @@ import os.path import wx + import smartcard.wx -import APDUTracerPanel -import CardAndReaderTreePanel -import ReaderToolbar +from smartcard.wx import APDUTracerPanel +from smartcard.wx import CardAndReaderTreePanel +from smartcard.wx import ReaderToolbar import smartcard from smartcard.wx.SimpleSCardAppEventObserver import \ From 3e2f200b54d20ba03a769acf9b442fe261043e72 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Mon, 29 Jun 2015 10:48:26 +0100 Subject: [PATCH 39/43] Revert differences to upstream@81bfc15 --- .gitignore | 1 - smartcard/Card.py | 1 + smartcard/CardConnection.py | 2 + smartcard/CardMonitoring.py | 16 +++++-- smartcard/CardService.py | 1 + smartcard/CardType.py | 1 - smartcard/ClassLoader.py | 4 ++ .../Examples/framework/sample_MonitorCards.py | 8 +++- .../sample_MonitorCardsAndTransmit.py | 8 +++- .../framework/sample_MonitorReaders.py | 8 +++- .../framework/sample_TransmitCardObserver.py | 6 ++- smartcard/Examples/scard-api/sample_getATR.py | 14 +++--- .../Examples/scard-api/sample_getAttrib.py | 14 +++--- .../scard-api/sample_listInterfaces.py | 20 ++++----- smartcard/Examples/simple/selectDF_TELECOM.py | 4 ++ smartcard/Examples/simple/simpleAPDU.py | 5 ++- smartcard/Examples/wx/pcscdiag/pcscdiag.py | 2 +- smartcard/ExclusiveConnectCardConnection.py | 1 + smartcard/ExclusiveTransmitCardConnection.py | 2 + smartcard/Observer.py | 2 +- smartcard/PassThruCardService.py | 1 + smartcard/ReaderMonitoring.py | 8 ++-- smartcard/Session.py | 6 +++ smartcard/System.py | 10 +++-- smartcard/doc/user-guide.rst | 43 +++++++++++-------- smartcard/guid.py | 1 + smartcard/pcsc/PCSCCardConnection.py | 1 + smartcard/pyro/PyroReader.py | 3 +- smartcard/pyro/server/PyroDaemon.py | 4 +- smartcard/pyro/server/PyroEventServer.py | 1 + smartcard/pyro/server/RemoteCardConnection.py | 3 ++ smartcard/pyro/server/RemoteReaderServer.py | 6 ++- smartcard/reader/ReaderGroups.py | 3 ++ smartcard/scard/__init__.py | 7 +-- smartcard/sw/ErrorChecker.py | 2 +- smartcard/sw/ErrorCheckingChain.py | 16 +++---- smartcard/test/framework/testcase_ATR.py | 2 +- smartcard/test/framework/testcase_Card.py | 2 +- .../test/framework/testcase_CardConnection.py | 2 +- .../test/framework/testcase_CardMonitor.py | 2 +- .../test/framework/testcase_CardRequest.py | 2 +- .../test/framework/testcase_CardService.py | 2 +- smartcard/test/framework/testcase_CardType.py | 2 +- .../test/framework/testcase_ErrorChecking.py | 2 +- .../test/framework/testcase_readermonitor.py | 2 +- smartcard/test/framework/testcase_readers.py | 2 +- .../testcase_pcscreadergroups.py | 9 ++-- smartcard/test/scard/testcase_getatr.py | 2 +- smartcard/test/scard/testcase_getattrib.py | 2 +- smartcard/test/scard/testcase_locatecards.py | 2 +- smartcard/test/scard/testcase_readergroups.py | 2 +- smartcard/test/scard/testcase_transaction.py | 2 +- smartcard/util/__init__.py | 11 +++-- smartcard/wx/APDUHexValidator.py | 2 +- smartcard/wx/CardAndReaderTreePanel.py | 4 +- smartcard/wx/ReaderToolbar.py | 4 +- smartcard/wx/SimpleSCardAppFrame.py | 7 ++- 57 files changed, 192 insertions(+), 110 deletions(-) diff --git a/.gitignore b/.gitignore index 1f05ea3a..54d3aa03 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,3 @@ smartcard/scard/scard_wrap.c # Generated by test suite smartcard/test/local_config.py - diff --git a/smartcard/Card.py b/smartcard/Card.py index a261c744..b82fad52 100644 --- a/smartcard/Card.py +++ b/smartcard/Card.py @@ -21,6 +21,7 @@ along with pyscard; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ +from smartcard.Exceptions import CardConnectionException, NoCardException from smartcard.reader.Reader import Reader from smartcard.System import readers from smartcard.util import toHexString diff --git a/smartcard/CardConnection.py b/smartcard/CardConnection.py index 15bb52b2..607185e0 100644 --- a/smartcard/CardConnection.py +++ b/smartcard/CardConnection.py @@ -24,6 +24,8 @@ """ from smartcard.CardConnectionEvent import CardConnectionEvent +from smartcard.Exceptions import SmartcardException +from smartcard.Observer import Observer from smartcard.Observer import Observable diff --git a/smartcard/CardMonitoring.py b/smartcard/CardMonitoring.py index 30991e30..12076824 100644 --- a/smartcard/CardMonitoring.py +++ b/smartcard/CardMonitoring.py @@ -28,13 +28,16 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ +from sys import exc_info from threading import Thread, Event from time import sleep -import traceback +from smartcard.System import readers +from smartcard.Exceptions import CardRequestTimeoutException from smartcard.Observer import Observer from smartcard.Observer import Observable +from smartcard.CardType import AnyCardType from smartcard.CardRequest import CardRequest _START_ON_DEMAND_ = False @@ -183,9 +186,15 @@ def run(self): pass except AttributeError: pass + except: - # FIXME Tighten the exceptions caught by this block - traceback.print_exc() + try: + import sys + print sys.exc_info()[1] + print sys.exc_info()[2] + print sys.exc_info()[0] + except: + pass # stop the thread by signaling stopEvent def stop(self): @@ -213,6 +222,7 @@ def __getattr__(self, name): if __name__ == "__main__": + from smartcard.CardMonitoring import CardMonitor print 'insert or remove cards in the next 10 seconds' # a simple card observer that prints added/removed cards diff --git a/smartcard/CardService.py b/smartcard/CardService.py index 0a2cf27a..b310f19a 100644 --- a/smartcard/CardService.py +++ b/smartcard/CardService.py @@ -30,6 +30,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ +from smartcard.Exceptions import SmartcardException from smartcard.scard import * diff --git a/smartcard/CardType.py b/smartcard/CardType.py index d88ad047..722a1cd1 100644 --- a/smartcard/CardType.py +++ b/smartcard/CardType.py @@ -21,7 +21,6 @@ along with pyscard; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from smartcard.Exceptions import InvalidATRMaskLengthException from smartcard.System import readers from smartcard.util import toHexString diff --git a/smartcard/ClassLoader.py b/smartcard/ClassLoader.py index 3cc59c56..3b232152 100644 --- a/smartcard/ClassLoader.py +++ b/smartcard/ClassLoader.py @@ -9,6 +9,10 @@ License: PSF license (http://docs.python.org/license.html). """ +import sys +import types + + def get_mod(modulePath): """Import a module.""" return __import__(modulePath, globals(), locals(), ['']) diff --git a/smartcard/Examples/framework/sample_MonitorCards.py b/smartcard/Examples/framework/sample_MonitorCards.py index c7a1bb5d..860d9547 100755 --- a/smartcard/Examples/framework/sample_MonitorCards.py +++ b/smartcard/Examples/framework/sample_MonitorCards.py @@ -24,7 +24,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -import sys +from sys import stdin, exc_info from time import sleep from smartcard.CardMonitoring import CardMonitor, CardObserver @@ -44,7 +44,7 @@ def update(self, observable, (addedcards, removedcards)): for card in removedcards: print "-Removed: ", toHexString(card.atr) -if __name__ == '__main__': +try: print "Insert or remove a smartcard in the system." print "This program will exit in 10 seconds" print "" @@ -58,6 +58,10 @@ def update(self, observable, (addedcards, removedcards)): # monitor will poll forever... cardmonitor.deleteObserver(cardobserver) + import sys if 'win32' == sys.platform: print 'press Enter to continue' sys.stdin.read(1) + +except: + print exc_info()[0], ':', exc_info()[1] diff --git a/smartcard/Examples/framework/sample_MonitorCardsAndTransmit.py b/smartcard/Examples/framework/sample_MonitorCardsAndTransmit.py index 5180a466..8aa93645 100755 --- a/smartcard/Examples/framework/sample_MonitorCardsAndTransmit.py +++ b/smartcard/Examples/framework/sample_MonitorCardsAndTransmit.py @@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -import sys +from sys import stdin, exc_info from time import sleep from smartcard.CardConnectionObserver import ConsoleCardConnectionObserver @@ -63,7 +63,7 @@ def update(self, observable, (addedcards, removedcards)): for card in removedcards: print "-Removed: ", toHexString(card.atr) -if __name__ == '__main__': +try: print "Insert or remove a SIM card in the system." print "This program will exit in 60 seconds" print "" @@ -77,6 +77,10 @@ def update(self, observable, (addedcards, removedcards)): # monitor will poll forever... cardmonitor.deleteObserver(selectobserver) + import sys if 'win32' == sys.platform: print 'press Enter to continue' sys.stdin.read(1) + +except: + print exc_info()[0], ':', exc_info()[1] diff --git a/smartcard/Examples/framework/sample_MonitorReaders.py b/smartcard/Examples/framework/sample_MonitorReaders.py index 49e22b4b..178b6a87 100755 --- a/smartcard/Examples/framework/sample_MonitorReaders.py +++ b/smartcard/Examples/framework/sample_MonitorReaders.py @@ -24,7 +24,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -import sys +from sys import stdin, exc_info from time import sleep from smartcard.ReaderMonitoring import ReaderMonitor, ReaderObserver @@ -40,7 +40,7 @@ def update(self, observable, (addedreaders, removedreaders)): print "Added readers", addedreaders print "Removed readers", removedreaders -if __name__ == '__main__': +try: print "Add or remove a smartcard reader to the system." print "This program will exit in 10 seconds" print "" @@ -54,6 +54,10 @@ def update(self, observable, (addedreaders, removedreaders)): # monitor will poll forever... readermonitor.deleteObserver(readerobserver) + import sys if 'win32' == sys.platform: print 'press Enter to continue' sys.stdin.read(1) + +except: + print exc_info()[0], ':', exc_info()[1] diff --git a/smartcard/Examples/framework/sample_TransmitCardObserver.py b/smartcard/Examples/framework/sample_TransmitCardObserver.py index 80b6dc9a..efa83a1c 100755 --- a/smartcard/Examples/framework/sample_TransmitCardObserver.py +++ b/smartcard/Examples/framework/sample_TransmitCardObserver.py @@ -24,6 +24,7 @@ along with pyscard; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ +from sys import stdin, exc_info from time import sleep from smartcard.CardMonitoring import CardMonitor, CardObserver @@ -56,7 +57,7 @@ def update(self, observable, (addedcards, removedcards)): if card in self.cards: self.cards.remove(card) -if __name__ == '__main__': +try: print "Insert or remove a smartcard in the system." print "This program will exit in 100 seconds" print "" @@ -65,3 +66,6 @@ def update(self, observable, (addedcards, removedcards)): cardmonitor.addObserver(cardobserver) sleep(100) + +except: + print exc_info()[0], ':', exc_info()[1] diff --git a/smartcard/Examples/scard-api/sample_getATR.py b/smartcard/Examples/scard-api/sample_getATR.py index cba2f258..ec7fd59b 100755 --- a/smartcard/Examples/scard-api/sample_getATR.py +++ b/smartcard/Examples/scard-api/sample_getATR.py @@ -26,12 +26,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -import sys - from smartcard.scard import * import smartcard.util -if __name__ == '__main__': +try: hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER) if hresult != SCARD_S_SUCCESS: raise error( @@ -88,6 +86,10 @@ SCardGetErrorMessage(hresult)) print 'Released context.' - if 'win32' == sys.platform: - print 'press Enter to continue' - sys.stdin.read(1) +except Exception, e: + print e + +import sys +if 'win32' == sys.platform: + print 'press Enter to continue' + sys.stdin.read(1) diff --git a/smartcard/Examples/scard-api/sample_getAttrib.py b/smartcard/Examples/scard-api/sample_getAttrib.py index 01ef61d1..1834e9cd 100755 --- a/smartcard/Examples/scard-api/sample_getAttrib.py +++ b/smartcard/Examples/scard-api/sample_getAttrib.py @@ -27,8 +27,6 @@ """ import struct -import sys - from smartcard.scard import * import smartcard.util @@ -92,7 +90,7 @@ def printAttribute(attrib, value): print apply(struct.pack, ['<' + 'B' * len(value)] + value) -if __name__ == '__main__': +try: hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER) if hresult != SCARD_S_SUCCESS: raise error( @@ -151,6 +149,10 @@ def printAttribute(attrib, value): SCardGetErrorMessage(hresult)) print 'Released context.' - if 'win32' == sys.platform: - print 'press Enter to continue' - sys.stdin.read(1) +except Exception, e: + print e + +import sys +if 'win32' == sys.platform: + print 'press Enter to continue' + sys.stdin.read(1) diff --git a/smartcard/Examples/scard-api/sample_listInterfaces.py b/smartcard/Examples/scard-api/sample_listInterfaces.py index 6289b8b7..d5611f14 100755 --- a/smartcard/Examples/scard-api/sample_listInterfaces.py +++ b/smartcard/Examples/scard-api/sample_listInterfaces.py @@ -26,8 +26,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -import sys - import platform from smartcard.scard import * import smartcard.guid @@ -44,7 +42,7 @@ znewcardSecGuid = \ smartcard.guid.strToGUID('{EB7F69EA-BA20-47d0-8C50-11CFDEB63BBE}') - def main(): + try: hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER) if hresult != SCARD_S_SUCCESS: raise scard.error( @@ -110,13 +108,15 @@ def main(): SCardGetErrorMessage(hresult)) print 'Released context.' + except error: + import sys + print sys.exc_info()[0], ':', sys.exc_info()[1] + elif 'pcsclite' == resourceManager: - def main(): - print 'SCardListInterfaces not supported by pcsc lite' + print 'SCardListInterfaces not supported by pcsc lite' -if __name__ == '__main__': - main() - if 'win32' == sys.platform: - print 'press Enter to continue' - sys.stdin.read(1) +import sys +if 'win32' == sys.platform: + print 'press Enter to continue' + sys.stdin.read(1) diff --git a/smartcard/Examples/simple/selectDF_TELECOM.py b/smartcard/Examples/simple/selectDF_TELECOM.py index 5050f52a..ce88ccd3 100755 --- a/smartcard/Examples/simple/selectDF_TELECOM.py +++ b/smartcard/Examples/simple/selectDF_TELECOM.py @@ -65,6 +65,10 @@ except CardRequestTimeoutException: print 'time-out: no card inserted during last 10s' +except: + import sys + print sys.exc_info()[1] + import sys if 'win32' == sys.platform: print 'press Enter to continue' diff --git a/smartcard/Examples/simple/simpleAPDU.py b/smartcard/Examples/simple/simpleAPDU.py index 38233132..1d8512f4 100755 --- a/smartcard/Examples/simple/simpleAPDU.py +++ b/smartcard/Examples/simple/simpleAPDU.py @@ -32,7 +32,7 @@ 0x18, 0xFF] GET_TIME = [0x80, 0x38, 0x00, 0xA0] -if __name__ == '__main__': +try: # get all the available readers r = readers() print "Available readers: ", r @@ -51,3 +51,6 @@ data, sw1, sw2 = connection.transmit(GET_TIME) print "Get Time: %02X %02X" % (sw1, sw2) + +except: + print sys.exc_info()[1] diff --git a/smartcard/Examples/wx/pcscdiag/pcscdiag.py b/smartcard/Examples/wx/pcscdiag/pcscdiag.py index 77881286..e4fbed9e 100755 --- a/smartcard/Examples/wx/pcscdiag/pcscdiag.py +++ b/smartcard/Examples/wx/pcscdiag/pcscdiag.py @@ -34,7 +34,7 @@ # wxPython GUI modules (http://www.wxpython.org) try: import wx -except ImportError: +except: print 'You need wxpython (http://www.wxpython.org) ' + \ 'to run this sample from the source code!' print 'press a key to continue' diff --git a/smartcard/ExclusiveConnectCardConnection.py b/smartcard/ExclusiveConnectCardConnection.py index ee3524ce..8d1f0cbf 100644 --- a/smartcard/ExclusiveConnectCardConnection.py +++ b/smartcard/ExclusiveConnectCardConnection.py @@ -21,6 +21,7 @@ along with pyscard; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ +from smartcard.CardConnection import CardConnection from smartcard.CardConnectionDecorator import CardConnectionDecorator from smartcard.Exceptions import CardConnectionException from smartcard.scard import SCardConnect, SCardDisconnect diff --git a/smartcard/ExclusiveTransmitCardConnection.py b/smartcard/ExclusiveTransmitCardConnection.py index ca836373..bbffa4da 100644 --- a/smartcard/ExclusiveTransmitCardConnection.py +++ b/smartcard/ExclusiveTransmitCardConnection.py @@ -21,11 +21,13 @@ along with pyscard; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ +from smartcard.CardConnection import CardConnection from smartcard.CardConnectionDecorator import CardConnectionDecorator from smartcard.Exceptions import CardConnectionException from smartcard.scard import SCardBeginTransaction, SCardEndTransaction from smartcard.scard import SCARD_LEAVE_CARD from smartcard.scard import SCardGetErrorMessage +from smartcard.pcsc import PCSCCardConnection import smartcard.pcsc diff --git a/smartcard/Observer.py b/smartcard/Observer.py index ce1d94fc..b5f2b4ca 100644 --- a/smartcard/Observer.py +++ b/smartcard/Observer.py @@ -19,7 +19,7 @@ class Observer(object): - def update(self, observable, arg): + def update(observable, arg): '''Called when the observed object is modified. You call an Observable object's notifyObservers method to notify all the diff --git a/smartcard/PassThruCardService.py b/smartcard/PassThruCardService.py index 25715354..d22a48a3 100644 --- a/smartcard/PassThruCardService.py +++ b/smartcard/PassThruCardService.py @@ -53,6 +53,7 @@ def supports(cardname): SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02] DF_TELECOM = [0x7F, 0x10] from smartcard.System import readers + from smartcard.CardConnection import CardConnection cc = readers()[0].createConnection() cs = PassThruCardService(cc) cs.connection.connect() diff --git a/smartcard/ReaderMonitoring.py b/smartcard/ReaderMonitoring.py index cebcb07c..0d9da5dc 100644 --- a/smartcard/ReaderMonitoring.py +++ b/smartcard/ReaderMonitoring.py @@ -28,11 +28,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from threading import Thread, Event +from sys import exc_info +from threading import Thread, Event, enumerate from time import sleep -import traceback import smartcard.System +from smartcard.Exceptions import ListReadersException from smartcard.Observer import Observer from smartcard.Observer import Observable from smartcard.Synchronization import * @@ -182,8 +183,6 @@ def run(self): self.stopEvent.wait(self.period) except Exception, e: - # FIXME Tighten the exceptions caught by this block - traceback.print_exc() # Most likely raised during interpreter shutdown due # to unclean exit which failed to remove all observers. # To solve this, we set the stop event and pass the @@ -195,6 +194,7 @@ def stop(self): self.join() if __name__ == "__main__": + from smartcard.ReaderMonitoring import ReaderMonitor print 'insert or remove readers in the next 20 seconds' # a simple reader observer that prints added/removed readers diff --git a/smartcard/Session.py b/smartcard/Session.py index 78515999..a700eddb 100644 --- a/smartcard/Session.py +++ b/smartcard/Session.py @@ -24,6 +24,7 @@ """ from smartcard.Exceptions import InvalidReaderException, NoReadersException +from smartcard.CardConnection import CardConnection from smartcard.PassThruCardService import PassThruCardService from smartcard.System import readers @@ -109,3 +110,8 @@ def getATR(self): def __repr__(self): """Returns a string representation of the session.""" return "" % self.readerName + + +if __name__ == '__main__': + """Small sample illustrating the use of Session.py.""" + pass diff --git a/smartcard/System.py b/smartcard/System.py index d6a20ca3..27970d15 100644 --- a/smartcard/System.py +++ b/smartcard/System.py @@ -60,6 +60,10 @@ def listReaders(): if __name__ == '__main__': - print readers() - print readers(['SCard$DefaultReaders']) - print readergroups() + try: + print readers() + print readers(['SCard$DefaultReaders']) + print readergroups() + except: + import sys + print sys.exc_info()[1] diff --git a/smartcard/doc/user-guide.rst b/smartcard/doc/user-guide.rst index b7f801df..7a890a20 100644 --- a/smartcard/doc/user-guide.rst +++ b/smartcard/doc/user-guide.rst @@ -1199,26 +1199,30 @@ To monitor reader insertion/removal, simply add the observer to the .. sourcecode:: python - from sys import stdin + from sys import stdin, exc_info from time import sleep from smartcard.ReaderMonitoring import ReaderMonitor, ReaderObserver - print "Add or remove a smartcard reader to the system." - print "This program will exit in 10 seconds" - print "" - readermonitor = ReaderMonitor() - readerobserver = printobserver() - readermonitor.addObserver( readerobserver ) + try: + print "Add or remove a smartcard reader to the system." + print "This program will exit in 10 seconds" + print "" + readermonitor = ReaderMonitor() + readerobserver = printobserver() + readermonitor.addObserver( readerobserver ) - sleep(10) + sleep(10) - # don't forget to remove observer, or the - # monitor will poll forever... - readermonitor.deleteObserver(readerobserver) + # don't forget to remove observer, or the + # monitor will poll forever... + readermonitor.deleteObserver(readerobserver) - print 'press Enter to continue' - stdin.readline() + print 'press Enter to continue' + stdin.readline() + + except error: + print exc_info()[0], ': ', exc_info()[1] Smart Cards *********** @@ -1257,12 +1261,13 @@ card observer to the `CardMonitor for card in removedcards: print "-Removed: ", toHexString( card.atr ) - print "Insert or remove a smartcard in the system." - print "This program will exit in 10 seconds" - print "" - cardmonitor = CardMonitor() - cardobserver = printobserver() - cardmonitor.addObserver( cardobserver ) + try: + print "Insert or remove a smartcard in the system." + print "This program will exit in 10 seconds" + print "" + cardmonitor = CardMonitor() + cardobserver = printobserver() + cardmonitor.addObserver( cardobserver ) Sending APDUs to a Smart Card Obtained from Card Monitoring diff --git a/smartcard/guid.py b/smartcard/guid.py index 497f25bf..c8715a72 100644 --- a/smartcard/guid.py +++ b/smartcard/guid.py @@ -60,6 +60,7 @@ def GUIDToStr(g): if __name__ == "__main__": """Small sample illustrating the use of guid.py.""" + import smartcard.guid dummycardguid1 = strToGUID('{AD4F1667-EA75-4124-84D4-641B3B197C65}') print dummycardguid1 print GUIDToStr(dummycardguid1) diff --git a/smartcard/pcsc/PCSCCardConnection.py b/smartcard/pcsc/PCSCCardConnection.py index c770f9ec..9842cfe9 100644 --- a/smartcard/pcsc/PCSCCardConnection.py +++ b/smartcard/pcsc/PCSCCardConnection.py @@ -25,6 +25,7 @@ from smartcard.CardConnection import CardConnection from smartcard.Exceptions import (CardConnectionException, NoCardException, SmartcardException) +from smartcard.Observer import Observable from smartcard.scard import * diff --git a/smartcard/pyro/PyroReader.py b/smartcard/pyro/PyroReader.py index a6fe396f..7023cc89 100644 --- a/smartcard/pyro/PyroReader.py +++ b/smartcard/pyro/PyroReader.py @@ -25,8 +25,9 @@ import Pyro.core import Pyro.naming -from smartcard.Exceptions import NoCardException +from smartcard.Exceptions import CardConnectionException, NoCardException from smartcard.reader.Reader import Reader +from smartcard.reader.ReaderFactory import ReaderFactory class PyroReader(Reader): diff --git a/smartcard/pyro/server/PyroDaemon.py b/smartcard/pyro/server/PyroDaemon.py index 90eac204..89b5d1ae 100644 --- a/smartcard/pyro/server/PyroDaemon.py +++ b/smartcard/pyro/server/PyroDaemon.py @@ -85,8 +85,8 @@ def __init__(self): Thread.__init__(self) self.setDaemon(True) self.setName('smartcard.pyro.server.PyroDaemonThread') - self._daemon = PyroDaemon() + self.daemon = PyroDaemon() def run(self): """Starts Pyro daemon.""" - self._daemon.start() + self.daemon.start() diff --git a/smartcard/pyro/server/PyroEventServer.py b/smartcard/pyro/server/PyroEventServer.py index 2503e082..90c4d998 100644 --- a/smartcard/pyro/server/PyroEventServer.py +++ b/smartcard/pyro/server/PyroEventServer.py @@ -92,6 +92,7 @@ def __call__(self, signame, sf): if __name__ == '__main__': + import sys from smartcard.pyro.server.PyroNameServer import PyroNameServer pn = PyroNameServer(sys.argv[1:]) pn.start() diff --git a/smartcard/pyro/server/RemoteCardConnection.py b/smartcard/pyro/server/RemoteCardConnection.py index 2b092b7c..9df373ee 100644 --- a/smartcard/pyro/server/RemoteCardConnection.py +++ b/smartcard/pyro/server/RemoteCardConnection.py @@ -26,7 +26,10 @@ import Pyro.core import Pyro.naming +from smartcard.CardConnection import CardConnection from smartcard.CardConnectionDecorator import CardConnectionDecorator +from smartcard.Exceptions import CardConnectionException, NoCardException +from smartcard.Observer import Observable class RemoteCardConnection(CardConnectionDecorator, Pyro.core.ObjBase): diff --git a/smartcard/pyro/server/RemoteReaderServer.py b/smartcard/pyro/server/RemoteReaderServer.py index f3e715fe..06db9b1e 100644 --- a/smartcard/pyro/server/RemoteReaderServer.py +++ b/smartcard/pyro/server/RemoteReaderServer.py @@ -26,12 +26,16 @@ try: import Pyro.core import Pyro.naming -except ImportError: +except: print 'You need pyro (python remote objects) ' + \ 'at http://www.xs4all.nl/~irmen/pyro3/' import sys sys.exit() +import signal +import time + +import smartcard.System from smartcard.reader.Reader import Reader from smartcard.ReaderMonitoring import ReaderMonitor, ReaderObserver from smartcard.pyro.server.RemoteCardConnection import RemoteCardConnection diff --git a/smartcard/reader/ReaderGroups.py b/smartcard/reader/ReaderGroups.py index 64475944..4e6cfbc1 100644 --- a/smartcard/reader/ReaderGroups.py +++ b/smartcard/reader/ReaderGroups.py @@ -67,6 +67,9 @@ def __onremoveitem__(self, item): def __iter__(self): return ulist.__iter__(self) + def next(self): + return ulist.__next__(self) + # # abstract methods implemented in subclasses # diff --git a/smartcard/scard/__init__.py b/smartcard/scard/__init__.py index e1a9ffb7..596417c8 100644 --- a/smartcard/scard/__init__.py +++ b/smartcard/scard/__init__.py @@ -1,3 +1,4 @@ -from __future__ import absolute_import - -from smartcard.scard.scard import * +try: + from scard import * +except: + from smartcard.scard._scard import * diff --git a/smartcard/sw/ErrorChecker.py b/smartcard/sw/ErrorChecker.py index 1296ff22..d29f0478 100644 --- a/smartcard/sw/ErrorChecker.py +++ b/smartcard/sw/ErrorChecker.py @@ -36,7 +36,7 @@ class ErrorChecker(object): pattern. """ - def __call__(self, data, sw1, sw2): + def __call__(data, sw1, sw2): """Called to test data, sw1 and sw2 for error. @param data: apdu response data diff --git a/smartcard/sw/ErrorCheckingChain.py b/smartcard/sw/ErrorCheckingChain.py index 77123d54..d8c0a5ad 100644 --- a/smartcard/sw/ErrorCheckingChain.py +++ b/smartcard/sw/ErrorCheckingChain.py @@ -23,6 +23,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ +from sys import exc_info + + class ErrorCheckingChain(object): """The error checking chain is a list of response apdu status word (sw1, sw2) error check strategies. Each strategy in the chain is @@ -73,14 +76,11 @@ def __call__(self, data, sw1, sw2): """Called to test data, sw1 and sw2 for error on the chain.""" try: self.strategy(data, sw1, sw2) - except tuple(self.excludes) as exc: - # The following addtional filter may look redundant, it isn't.s - # It checks that type(exc) is *equal* to any of self.excludes, - # rather than equal-or-subclass to any of self.excludes. - # This is to keep backward compatibility with the behaviour of - # pyscard <= 1.6.16. - if type(exc) in self.excludes: - return + except: + # if exception is filtered, return + for exception in self.excludes: + if exception == exc_info()[0]: + return # otherwise reraise exception raise diff --git a/smartcard/test/framework/testcase_ATR.py b/smartcard/test/framework/testcase_ATR.py index 03dbbe55..b64de568 100755 --- a/smartcard/test/framework/testcase_ATR.py +++ b/smartcard/test/framework/testcase_ATR.py @@ -38,7 +38,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except ImportError: +except: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/framework/testcase_Card.py b/smartcard/test/framework/testcase_Card.py index 6ea594b1..c8b25b41 100755 --- a/smartcard/test/framework/testcase_Card.py +++ b/smartcard/test/framework/testcase_Card.py @@ -39,7 +39,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except ImportError: +except: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/framework/testcase_CardConnection.py b/smartcard/test/framework/testcase_CardConnection.py index 4a9abbd5..082cc420 100755 --- a/smartcard/test/framework/testcase_CardConnection.py +++ b/smartcard/test/framework/testcase_CardConnection.py @@ -39,7 +39,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except ImportError: +except: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/framework/testcase_CardMonitor.py b/smartcard/test/framework/testcase_CardMonitor.py index bea14870..2365926d 100755 --- a/smartcard/test/framework/testcase_CardMonitor.py +++ b/smartcard/test/framework/testcase_CardMonitor.py @@ -41,7 +41,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except ImportError: +except: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/framework/testcase_CardRequest.py b/smartcard/test/framework/testcase_CardRequest.py index 10826621..55463fdd 100755 --- a/smartcard/test/framework/testcase_CardRequest.py +++ b/smartcard/test/framework/testcase_CardRequest.py @@ -39,7 +39,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader, expectedReaderForATR -except ImportError: +except: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/framework/testcase_CardService.py b/smartcard/test/framework/testcase_CardService.py index a11bd591..a5bcd10d 100755 --- a/smartcard/test/framework/testcase_CardService.py +++ b/smartcard/test/framework/testcase_CardService.py @@ -38,7 +38,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except ImportError: +except: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/framework/testcase_CardType.py b/smartcard/test/framework/testcase_CardType.py index 293afb64..0afaa6ee 100755 --- a/smartcard/test/framework/testcase_CardType.py +++ b/smartcard/test/framework/testcase_CardType.py @@ -39,7 +39,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except ImportError: +except: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/framework/testcase_ErrorChecking.py b/smartcard/test/framework/testcase_ErrorChecking.py index fb4c4f9d..6463fca9 100755 --- a/smartcard/test/framework/testcase_ErrorChecking.py +++ b/smartcard/test/framework/testcase_ErrorChecking.py @@ -49,7 +49,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except ImportError: +except: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/framework/testcase_readermonitor.py b/smartcard/test/framework/testcase_readermonitor.py index d767d230..3536aefb 100755 --- a/smartcard/test/framework/testcase_readermonitor.py +++ b/smartcard/test/framework/testcase_readermonitor.py @@ -41,7 +41,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except ImportError: +except: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/framework/testcase_readers.py b/smartcard/test/framework/testcase_readers.py index a0f674fa..5e531e29 100755 --- a/smartcard/test/framework/testcase_readers.py +++ b/smartcard/test/framework/testcase_readers.py @@ -38,7 +38,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except ImportError: +except: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/frameworkpcsc/testcase_pcscreadergroups.py b/smartcard/test/frameworkpcsc/testcase_pcscreadergroups.py index bc53bcac..cf9a0218 100755 --- a/smartcard/test/frameworkpcsc/testcase_pcscreadergroups.py +++ b/smartcard/test/frameworkpcsc/testcase_pcscreadergroups.py @@ -38,7 +38,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except ImportError: +except: print 'execute test suite first to generate the local_config.py file' sys.exit() @@ -54,8 +54,11 @@ class testcase_readergroups(unittest.TestCase): def setUp(self): groups = PCSCReaderGroups().instance - groups.remove('Pinpad$Readers') - groups.remove('Biometric$Readers') + try: + groups.remove('Pinpad$Readers') + groups.remove('Biometric$Readers') + except: + pass def testcase_add(self): """Test for groups=groups+newgroups""" diff --git a/smartcard/test/scard/testcase_getatr.py b/smartcard/test/scard/testcase_getatr.py index f3c0ee6a..45541a21 100755 --- a/smartcard/test/scard/testcase_getatr.py +++ b/smartcard/test/scard/testcase_getatr.py @@ -39,7 +39,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except ImportError: +except: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/scard/testcase_getattrib.py b/smartcard/test/scard/testcase_getattrib.py index 6f9735e1..d73c2168 100755 --- a/smartcard/test/scard/testcase_getattrib.py +++ b/smartcard/test/scard/testcase_getattrib.py @@ -40,7 +40,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except ImportError: +except: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/scard/testcase_locatecards.py b/smartcard/test/scard/testcase_locatecards.py index b78cad3c..fc25ad9e 100755 --- a/smartcard/test/scard/testcase_locatecards.py +++ b/smartcard/test/scard/testcase_locatecards.py @@ -39,7 +39,7 @@ try: from local_config import expectedATRs, expectedReaders from local_config import expectedReaderGroups, expectedATRinReader -except ImportError: +except: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/scard/testcase_readergroups.py b/smartcard/test/scard/testcase_readergroups.py index 5bf6bb93..b2e18349 100755 --- a/smartcard/test/scard/testcase_readergroups.py +++ b/smartcard/test/scard/testcase_readergroups.py @@ -38,7 +38,7 @@ try: from local_config import expectedReaders -except ImportError: +except: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/test/scard/testcase_transaction.py b/smartcard/test/scard/testcase_transaction.py index a6315222..eb811320 100755 --- a/smartcard/test/scard/testcase_transaction.py +++ b/smartcard/test/scard/testcase_transaction.py @@ -38,7 +38,7 @@ try: from local_config import expectedATRs, expectedReaders -except ImportError: +except: print 'execute test suite first to generate the local_config.py file' sys.exit() diff --git a/smartcard/util/__init__.py b/smartcard/util/__init__.py index 68fe0ba6..873a9ceb 100644 --- a/smartcard/util/__init__.py +++ b/smartcard/util/__init__.py @@ -97,14 +97,14 @@ def toBytes(bytestring): >>> toBytes("3B6500 009C1101 0103") [59, 101, 0, 0, 156, 17, 1, 1, 3] """ - import struct + from struct import unpack import re - packedstring = ''.join(re.split(r'\W+', bytestring)) + packedstring = ''.join(re.split('\W+', bytestring)) try: return reduce(lambda x, y: x + [int(y, 16)], - struct.unpack('2s' * (len(packedstring) / 2), + unpack('2s' * (len(packedstring) / 2), packedstring), []) - except (struct.error, ValueError): + except: raise TypeError('not a string representing a list of bytes') @@ -204,6 +204,9 @@ def toHexString(bytes=[], format=0): from string import rstrip + for byte in tuple(bytes): + pass + if type(bytes) is not list: raise TypeError('not a list of bytes') diff --git a/smartcard/wx/APDUHexValidator.py b/smartcard/wx/APDUHexValidator.py index 4e16ceb6..dd090ddf 100644 --- a/smartcard/wx/APDUHexValidator.py +++ b/smartcard/wx/APDUHexValidator.py @@ -48,7 +48,7 @@ def Clone(self): def Validate(self, win): tc = self.GetWindow() - value = tc.GetValue() + val = tc.GetValue() if not apduregexp.match(value): return False diff --git a/smartcard/wx/CardAndReaderTreePanel.py b/smartcard/wx/CardAndReaderTreePanel.py index 8106ef9f..0841ec1d 100644 --- a/smartcard/wx/CardAndReaderTreePanel.py +++ b/smartcard/wx/CardAndReaderTreePanel.py @@ -408,9 +408,9 @@ def __init__(self, parent, appstyle, clientpanel): def OnDestroy(self, event): """Called on panel destruction.""" # deregister observers - if hasattr(self, 'cardmonitor'): + if hasattr(self, cardmonitor): self.cardmonitor.deleteObserver(self.cardtreecardobserver) - if hasattr(self, 'readermonitor'): + if hasattr(self, readermonitor): self.readermonitor.deleteObserver(self.readertreereaderobserver) self.cardmonitor.deleteObserver(self.readertreecardobserver) event.Skip() diff --git a/smartcard/wx/ReaderToolbar.py b/smartcard/wx/ReaderToolbar.py index fd353be8..946dfab0 100644 --- a/smartcard/wx/ReaderToolbar.py +++ b/smartcard/wx/ReaderToolbar.py @@ -77,12 +77,12 @@ def __init__(self, parent): bmpReader = wx.Bitmap(ICO_READER, wx.BITMAP_TYPE_ICO) else: bmpReader = wx.ArtProvider_GetBitmap( - wx.ART_HELP_BOOK, wx.ART_OTHER, tsize) + wx.ART_HELP_BOOK, wx.ART_OTHER, isz) if None != ICO_SMARTCARD: bmpCard = wx.Bitmap(ICO_SMARTCARD, wx.BITMAP_TYPE_ICO) else: bmpCard = wx.ArtProvider_GetBitmap( - wx.ART_HELP_BOOK, wx.ART_OTHER, tsize) + wx.ART_HELP_BOOK, wx.ART_OTHER, isz) self.readercombobox = ReaderComboBox(self) # create and add controls diff --git a/smartcard/wx/SimpleSCardAppFrame.py b/smartcard/wx/SimpleSCardAppFrame.py index 193c8a56..cd5166cc 100644 --- a/smartcard/wx/SimpleSCardAppFrame.py +++ b/smartcard/wx/SimpleSCardAppFrame.py @@ -26,11 +26,10 @@ import os.path import wx - import smartcard.wx -from smartcard.wx import APDUTracerPanel -from smartcard.wx import CardAndReaderTreePanel -from smartcard.wx import ReaderToolbar +import APDUTracerPanel +import CardAndReaderTreePanel +import ReaderToolbar import smartcard from smartcard.wx.SimpleSCardAppEventObserver import \ From b01c51d5813ac3994571c2364d9d7d55c14e8a59 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Mon, 29 Jun 2015 12:52:23 +0100 Subject: [PATCH 40/43] Fix undefined variable errors found by pylint --- smartcard/wx/APDUHexValidator.py | 2 +- smartcard/wx/CardAndReaderTreePanel.py | 4 ++-- smartcard/wx/ReaderToolbar.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/smartcard/wx/APDUHexValidator.py b/smartcard/wx/APDUHexValidator.py index dd090ddf..4e16ceb6 100644 --- a/smartcard/wx/APDUHexValidator.py +++ b/smartcard/wx/APDUHexValidator.py @@ -48,7 +48,7 @@ def Clone(self): def Validate(self, win): tc = self.GetWindow() - val = tc.GetValue() + value = tc.GetValue() if not apduregexp.match(value): return False diff --git a/smartcard/wx/CardAndReaderTreePanel.py b/smartcard/wx/CardAndReaderTreePanel.py index 0841ec1d..8106ef9f 100644 --- a/smartcard/wx/CardAndReaderTreePanel.py +++ b/smartcard/wx/CardAndReaderTreePanel.py @@ -408,9 +408,9 @@ def __init__(self, parent, appstyle, clientpanel): def OnDestroy(self, event): """Called on panel destruction.""" # deregister observers - if hasattr(self, cardmonitor): + if hasattr(self, 'cardmonitor'): self.cardmonitor.deleteObserver(self.cardtreecardobserver) - if hasattr(self, readermonitor): + if hasattr(self, 'readermonitor'): self.readermonitor.deleteObserver(self.readertreereaderobserver) self.cardmonitor.deleteObserver(self.readertreecardobserver) event.Skip() diff --git a/smartcard/wx/ReaderToolbar.py b/smartcard/wx/ReaderToolbar.py index 946dfab0..fd353be8 100644 --- a/smartcard/wx/ReaderToolbar.py +++ b/smartcard/wx/ReaderToolbar.py @@ -77,12 +77,12 @@ def __init__(self, parent): bmpReader = wx.Bitmap(ICO_READER, wx.BITMAP_TYPE_ICO) else: bmpReader = wx.ArtProvider_GetBitmap( - wx.ART_HELP_BOOK, wx.ART_OTHER, isz) + wx.ART_HELP_BOOK, wx.ART_OTHER, tsize) if None != ICO_SMARTCARD: bmpCard = wx.Bitmap(ICO_SMARTCARD, wx.BITMAP_TYPE_ICO) else: bmpCard = wx.ArtProvider_GetBitmap( - wx.ART_HELP_BOOK, wx.ART_OTHER, isz) + wx.ART_HELP_BOOK, wx.ART_OTHER, tsize) self.readercombobox = ReaderComboBox(self) # create and add controls From 68f5f423cdb4f8c8de6365800d9e9c7b640ea27d Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Mon, 29 Jun 2015 12:53:38 +0100 Subject: [PATCH 41/43] Fix missing usage of raw string --- smartcard/util/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smartcard/util/__init__.py b/smartcard/util/__init__.py index 873a9ceb..0bd83106 100644 --- a/smartcard/util/__init__.py +++ b/smartcard/util/__init__.py @@ -99,7 +99,7 @@ def toBytes(bytestring): """ from struct import unpack import re - packedstring = ''.join(re.split('\W+', bytestring)) + packedstring = ''.join(re.split(r'\W+', bytestring)) try: return reduce(lambda x, y: x + [int(y, 16)], unpack('2s' * (len(packedstring) / 2), From b0f49f65793ed12270bb7ae186b2267f566c1d34 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Mon, 29 Jun 2015 12:54:35 +0100 Subject: [PATCH 42/43] Remove no-effect loop --- smartcard/util/__init__.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/smartcard/util/__init__.py b/smartcard/util/__init__.py index 0bd83106..463563a1 100644 --- a/smartcard/util/__init__.py +++ b/smartcard/util/__init__.py @@ -204,9 +204,6 @@ def toHexString(bytes=[], format=0): from string import rstrip - for byte in tuple(bytes): - pass - if type(bytes) is not list: raise TypeError('not a list of bytes') From 9ec8faefbc171f3c02e00a1fdfd935bf71ca9065 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Mon, 29 Jun 2015 13:04:48 +0100 Subject: [PATCH 43/43] Fix name clash between PyroDaemonThread and threading.Thread In Python 2.6 threading.Thread gained a boolean flag - daemon. https://docs.python.org/2/library/threading.html#threading.Thread.daemon This flag clashes with the daemon attribute of PyroDaemonThread and is likely to cause confusion --- smartcard/pyro/server/PyroDaemon.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/smartcard/pyro/server/PyroDaemon.py b/smartcard/pyro/server/PyroDaemon.py index 89b5d1ae..90eac204 100644 --- a/smartcard/pyro/server/PyroDaemon.py +++ b/smartcard/pyro/server/PyroDaemon.py @@ -85,8 +85,8 @@ def __init__(self): Thread.__init__(self) self.setDaemon(True) self.setName('smartcard.pyro.server.PyroDaemonThread') - self.daemon = PyroDaemon() + self._daemon = PyroDaemon() def run(self): """Starts Pyro daemon.""" - self.daemon.start() + self._daemon.start()