Skip to content

Commit 1f4f851

Browse files
authored
Merge pull request #38 from bgaifullin/master
Rewrote whole module on pure C
2 parents d7feedf + 2dda508 commit 1f4f851

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+4079
-1955
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@
1111
*.pyo
1212
*.egg*
1313
*.so
14-
*.c

.travis.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
dist: trusty
12
sudo: false
23
language: python
34
python:
45
- '2.7'
5-
- '3.3'
66
- '3.4'
7+
- '3.5'
78

89
addons:
910
apt:
@@ -16,6 +17,8 @@ addons:
1617
- pkg-config
1718

1819
install:
19-
- travis_retry pip install -e ".[test]"
20+
- travis_retry pip install -r requirements-test.txt
21+
- travis_retry pip install -e "."
22+
- pip list
2023

21-
script: py.test
24+
script: 'py.test tests'

MANIFEST.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
include src/*.h
2-
include src/xmlsec/*.pxd
1+
include src/*

README.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,29 @@
88

99
Check the [examples](https://github.com/mehcode/python-xmlsec/tree/master/tests/examples) to see various examples of signing and verifying using the library.
1010

11+
## Requirements
12+
- libxml2 >= 2.9.1
13+
- libxmlsec1 >= 1.2.14
14+
1115
## Install
1216

1317
### Pre-Install
1418

1519
#### Linux (Debian)
1620

1721
```sh
18-
apt-get install libxml2-dev libxmlsec1-dev
22+
apt-get install libxml2-dev libxmlsec1-dev libxmlsec1-opensssl
1923
```
20-
24+
25+
Note: There is no required version of libxml2 for ubuntu precise,
26+
so need to dowload and install it manually.
27+
```sh
28+
wget http://xmlsoft.org/sources/libxml2-2.9.1.tar.gz
29+
tar -xvf libxml2-2.9.1.tar.gz
30+
cd libxml2-2.9.1
31+
./configure && make && make install
32+
```
33+
2134
#### Linux (CentOS)
2235

2336
```sh
@@ -86,7 +99,8 @@ include the appropriate files from the libxml2 and libxmlsec1 libraries.
8699
This will download all dependencies required for running the unit tests.
87100

88101
```sh
89-
pip install -e ".[test]"
102+
pip install -r requirements-test.txt
103+
pip install -e "."
90104
```
91105

92106
### Running the test suite
@@ -96,9 +110,16 @@ include the appropriate files from the libxml2 and libxmlsec1 libraries.
96110
2. Run the unit tests.
97111

98112
```sh
99-
py.test
113+
py.test tests
100114
```
101115

116+
## Versions of python
117+
The following versions of python is supported
118+
- python2.7
119+
- python3.4
120+
- python3.5 (required libxmlsec1 >= 1.2.18 and libxml2 >= 2.9.1)
121+
- python3.6 (required libxmlsec1 >= 1.2.18 and libxml2 >= 2.9.1)
122+
102123
## License
103124

104125
Unless otherwise noted, all files contained within this project are liensed under the MIT opensource license. See the included file LICENSE or visit [opensource.org][] for more information.

requirements-test.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-r requirements.txt
2+
pytest

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pkgconfig
2+
lxml >= 3.0

setup.py

Lines changed: 52 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,87 @@
1-
#! /usr/bin/env python
2-
# -*- coding: utf-8 -*-
3-
# from __future__ import absolute_import, unicode_literals, division
4-
from os import path
5-
from pkgutil import get_importer
6-
from setuptools import setup, Extension
7-
from functools import wraps
1+
from __future__ import print_function
82

3+
import glob
4+
import os
5+
import pkgconfig
6+
from setuptools import setup
7+
from setuptools import Extension
8+
import sys
99

10-
def lazy(function):
10+
import lxml
1111

12-
@wraps(function)
13-
def wrapped(*args, **kwargs):
12+
__name__ = "xmlsec"
13+
__version__ = "1.0.1"
14+
__description__ = "Python bindings for the XML Security Library"
1415

15-
class LazyProxy(Extension):
16-
__arguments = dict()
1716

18-
def __init__(self, function, args, kwargs):
19-
self.__arguments["function"] = function
20-
self.__arguments["args"] = args
21-
self.__arguments["kwargs"] = kwargs
22-
self.__arguments["result"] = None
17+
def is_debug():
18+
return bool(os.getenv("PYXMLSEC_DEBUG"))
2319

24-
def __getattr__(self, item):
25-
if self.__arguments["result"] is None:
26-
self.__arguments["result"] = self.__arguments["function"](*self.__arguments["args"],
27-
**self.__arguments["kwargs"])
2820

29-
return getattr(self.__arguments["result"], item)
21+
macroses = [("MODULE_NAME", __name__), ("MODULE_VERSION", __version__), ("MODULE_DOC", __description__)]
22+
cflags = ["-g", "-std=c99", "-fno-strict-aliasing", "-Wno-error=declaration-after-statement", "-Werror=implicit-function-declaration"]
3023

31-
def __setattr__(self, name, value):
32-
if self.__arguments["result"] is None:
33-
self.__arguments["result"] = self.__arguments["function"](*self.__arguments["args"],
34-
**self.__arguments["kwargs"])
3524

36-
setattr(self.__arguments["result"], name, value)
25+
if is_debug():
26+
macroses.append(("PYXMLSEC_ENABLE_DEBUG", 1))
27+
cflags.extend(["-Wall", "-O0"])
28+
else:
29+
cflags.extend(["-Os"])
3730

38-
return LazyProxy(function, args, kwargs)
3931

40-
return wrapped
32+
config = pkgconfig.parse("xmlsec1")
4133

4234

43-
@lazy
44-
def make_extension(name, cython=True):
45-
from pkgconfig import parse
35+
def add_to_config(key, args):
36+
value = list(config.get(key, []))
37+
value.extend(args)
38+
config[key] = value
4639

47-
# Declare the crypto implementation.
48-
xmlsec_crypto = 'openssl'
4940

50-
# Process the `pkg-config` utility and discover include and library
51-
# directories.
52-
config = {}
53-
for lib in ['libxml-2.0', 'xmlsec1-%s' % xmlsec_crypto]:
54-
config.update(parse(lib))
41+
add_to_config('define_macros', macroses)
42+
add_to_config('include_dirs', lxml.get_include())
5543

56-
config['extra_compile_args'] = ['-DXMLSEC_CRYPTO_OPENSSL=1', '-DXMLSEC_NO_CRYPTO_DYNAMIC_LOADING=1']
44+
print(config, file=sys.stderr)
5745

58-
# List-ify config for setuptools.
59-
for key in config:
60-
config[key] = list(config[key])
6146

62-
if 'include_dirs' not in config:
63-
config['include_dirs'] = []
47+
def find_sources(path):
48+
return glob.glob(os.path.join(path, "*.c"))
6449

65-
# Add the source directories for inclusion.
66-
import lxml
67-
config['include_dirs'].insert(0, path.dirname(lxml.__file__))
68-
config['include_dirs'].insert(0, path.join(path.dirname(lxml.__file__), 'includes'))
69-
config['include_dirs'].insert(0, 'src')
70-
71-
# Resolve extension location from name.
72-
location = path.join('src', *name.split('.'))
73-
location += '.pyx' if cython else '.c'
74-
75-
# Create and return the extension.
76-
return Extension(name, [location], **config)
77-
78-
79-
# Navigate, import, and retrieve the metadata of the project.
80-
meta = get_importer('src/xmlsec').find_module('meta').load_module('meta')
8150

51+
_xmlsec = Extension(
52+
__name__,
53+
sources=find_sources("./src"),
54+
extra_compile_args=cflags,
55+
libraries=list(config.get('libraries', [])),
56+
library_dirs=list(config.get('library_dirs', [])),
57+
include_dirs=list(config.get('include_dirs', [])),
58+
define_macros=config['define_macros']
59+
)
8260

8361
setup(
84-
name='xmlsec',
85-
version=meta.version,
86-
description=meta.description,
62+
name=__name__,
63+
version=__version__,
64+
description=__description__,
65+
ext_modules=[_xmlsec],
66+
author="Ryan Leckey",
67+
author_email='[email protected]',
68+
maintainer='Bulat Gaifullin',
69+
maintainer_email='[email protected]',
70+
url='https://github.com/mehcode/python-xmlsec',
71+
download_url="https://github.com/mehcode/python-xmlsec/archive/v%s.tar.gz" % __version__,
72+
license='MIT',
73+
keywords=["xmlsec"],
8774
classifiers=[
8875
'Development Status :: 3 - Alpha',
8976
'Intended Audience :: Developers',
9077
'Intended Audience :: System Administrators',
9178
'License :: OSI Approved :: MIT License',
9279
'Operating System :: OS Independent',
93-
'Programming Language :: Cython',
80+
'Programming Language :: C',
9481
'Programming Language :: Python :: 2.7',
9582
'Programming Language :: Python :: 3',
9683
'Programming Language :: Python :: 3.3',
9784
'Programming Language :: Python :: 3.4',
9885
'Topic :: Text Processing :: Markup :: XML'
9986
],
100-
author='Ryan Leckey',
101-
author_email='[email protected]',
102-
url='https://github.com/mehcode/python-xmlsec',
103-
setup_requires=[
104-
'setuptools_cython',
105-
'pkgconfig',
106-
'lxml >= 3.0',
107-
],
108-
install_requires=[
109-
'lxml >= 3.0',
110-
],
111-
extras_require={
112-
'test': ['pytest']
113-
},
114-
package_dir={'xmlsec': 'src/xmlsec'},
115-
packages=['xmlsec'],
116-
ext_modules=[
117-
make_extension('xmlsec.constants'),
118-
make_extension('xmlsec.utils'),
119-
make_extension('xmlsec.tree'),
120-
make_extension('xmlsec.key'),
121-
make_extension('xmlsec.ds'),
122-
make_extension('xmlsec.enc'),
123-
make_extension('xmlsec.template'),
124-
]
12587
)

src/common.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) 2017 Ryan Leckey
2+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
4+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
5+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
6+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
7+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
8+
// SOFTWARE.
9+
10+
#ifndef __PYXMLSEC_COMMON_H__
11+
#define __PYXMLSEC_COMMON_H__
12+
13+
#include "debug.h"
14+
15+
#ifndef MODULE_NAME
16+
#define MODULE_NAME "xmlsec"
17+
#endif
18+
19+
#ifndef MODULE_DOC
20+
#define MODULE_DOC "The tiny python wrapper around xmlsec1 library."
21+
#endif
22+
23+
#define JOIN(X,Y) DO_JOIN1(X,Y)
24+
#define DO_JOIN1(X,Y) DO_JOIN2(X,Y)
25+
#define DO_JOIN2(X,Y) X##Y
26+
27+
#define DO_STRINGIFY(x) #x
28+
#define STRINGIFY(x) DO_STRINGIFY(x)
29+
30+
#endif //__PYXMLSEC_COMMON_H__

0 commit comments

Comments
 (0)