Compare commits

...

11 Commits

8 changed files with 218 additions and 23 deletions
Split View
  1. +2
    -3
      DEPENDENCIES
  2. +146
    -0
      build-windows/add_windows_libraries.py
  3. +3
    -1
      make.mak
  4. +25
    -17
      src/pEp/_pEp/message.cc
  5. +5
    -1
      src/pEp/_pEp/message.hh
  6. +4
    -1
      src/pEp/_pEp/pEpmodule.cc
  7. +21
    -0
      tests/test_blob.py
  8. +12
    -0
      tests/test_identity.py

+ 2
- 3
DEPENDENCIES View File

@ -1,6 +1,5 @@
# 1st Party Dependencies
## Prefer git tags instead of SHA hashes when possible.
libpEpAdapter=Release_2.1.17
pEpEngine=Release_2.1.23
sequoia=365d00a08bec6a5a48d48a7c7893d78c27092b59
libpEpAdapter=Release_2.1.21
pEpEngine=Release_2.1.41

+ 146
- 0
build-windows/add_windows_libraries.py View File

@ -0,0 +1,146 @@
import os
import re
import sys
import subprocess
import winreg
import zipfile as zf
from os.path import dirname
from os.path import join
def get_bindependencies(lib, debug=False):
"""Gets the pEp dependencies of a library"""
python_location = sys.exec_prefix
bindepend = join(python_location, 'Scripts', 'pyi-bindepend.exe')
output = subprocess.run([bindepend, lib], capture_output=True)
if os.path.isfile(lib):
yield lib
if len(output.stdout) > 0:
deps = parse_bindepend_output(output.stdout)
for dep in add_full_paths(deps, debug):
for d in get_bindependencies(dep):
yield d
def parse_bindepend_output(stdout):
"""Parses the output of pyi-bindepent and returns a list of file names"""
deps = []
if stdout == None:
return None
p = re.compile('(.*){(.*)}(.*)')
str_val = bytes.decode(stdout)
raw_val = p.findall(str_val)
if len(raw_val) == 0:
return deps
else:
libs = raw_val[0][1].replace(' ', '').split(',')
for lib in libs:
lib = lib.strip("'")
if not 'api' in lib:
deps.append(lib)
return deps
def get_pEp_install_location(debug=False):
"""Gets the location where pEp is installed"""
reg_path = "SOFTWARE\\Classes\\TypeLib\\{564A4350-419E-47F1-B0DF-6FCCF0CD0BBC}\\1.0\\0\\win32"
KeyName = None
regKey = None
try:
regKey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, reg_path, 0, winreg.KEY_READ)
# Keys: Description, FileName, FriendlyName, LoadBehavior
com_server, _ = winreg.QueryValueEx(regKey, KeyName)
except WindowsError as error:
print('Error getting install location: ' + error)
com_server = None
finally:
if winreg:
winreg.CloseKey(regKey)
location = os.path.dirname(com_server)
if debug:
location = location.strip('Release') + 'Debug'
return location
def get_boost_directories():
"""Gets the location of the boost libraries"""
for dir in [f.path for f in os.scandir(join(os.getcwd(), 'build-windows', 'packages')) if f.is_dir()]:
if 'boost.' in dir or 'boost_python' in dir or 'boost_locale' in dir:
yield join(dir, 'lib', 'native')
def add_full_paths(libs, debug=False):
"""Combines a list of libraries with a set of common directories. Returns a list of file names that exist on this machine"""
paths = [get_pEp_install_location(debug)] + [dir for dir in get_boost_directories()] + [p for p in os.environ['PATH'].split(';')]
paths = [p for p in paths if not "system32" in p.lower()]
full_paths = []
for lib in libs:
for p in paths:
test_path = join(p, lib)
if os.path.isfile(test_path) and not test_path.casefold() in (f.casefold for f in full_paths):
full_paths.append(test_path)
return full_paths
def main():
args = sys.argv
cwd = dirname(args[0])
del args[0]
# Check for debug build
debug = False
if len(args) > 0 and args[0] == '--debug':
debug = True
del args[0]
# Get the pEp wheel and extract the pEp Python library
dist_path = join(dirname(cwd), 'dist')
print('Dist path is: ' + dist_path)
pEp_python_library = None
if os.path.exists(dist_path):
for _, _, files in os.walk(dist_path):
for f in files:
if f[:3] == 'pEp' and f[-3:] == 'whl':
wheel_name = join(dist_path, f)
with zf.ZipFile(wheel_name, 'a') as wheel:
for archive_member in wheel.namelist():
if '_pEp' in archive_member and archive_member[-3:] == 'pyd':
wheel.extract(archive_member, path=dist_path)
pEp_python_library = join(dist_path, archive_member)
print('pEp Python library found and extracted to ' + pEp_python_library)
break
break
# Get all dependencies for the pEp Python library
if pEp_python_library == None:
raise FileNotFoundError('pEp Python library not found in ' + dist_path)
pEp_python_library = pEp_python_library.replace('/', '\\')
libs = []
for lib in get_bindependencies(pEp_python_library, debug):
if not lib.casefold() in (l.casefold for l in libs) and lib.casefold() != pEp_python_library.casefold():
print('Dependency found: ' + lib)
libs.append(lib)
# Copy dependencies into the wheel
with zf.ZipFile(wheel_name, 'a') as wheel:
for lib in libs:
filename = os.path.basename(lib)
arcname = 'pEp/' + filename
if not arcname in wheel.namelist():
wheel.write(filename=lib, arcname=arcname, compress_type=zf.ZIP_DEFLATED)
# Delete the temporarily extracted pEp Python library
if os.path.isfile(pEp_python_library):
os.remove(pEp_python_library)
dir = os.path.dirname(pEp_python_library)
if dir[-3:].lower() == 'pep' and os.path.isdir(dir):
os.rmdir(dir)
if __name__ == '__main__':
main()

+ 3
- 1
make.mak View File

@ -31,9 +31,11 @@ release: clean
CD..
PY -3.8-32 setup.py build_ext
PY -3.8-32 setup.py bdist_wheel
PY -3.8-32 build-windows/add_windows_libraries.py
#debug build
debug: clean
CD..
PY -3.8-32 setup.py build_ext --debug
PY -3.8-32 setup.py bdist_wheel
PY -3.8-32 setup.py bdist_wheel
PY -3.8-32 build-windows/add_windows_libraries.py --debug

+ 25
- 17
src/pEp/_pEp/message.cc View File

@ -34,24 +34,8 @@ namespace pEp {
if (!_bl)
throw bad_alloc();
Py_buffer src;
int result = PyObject_GetBuffer(data.ptr(), &src, PyBUF_CONTIG_RO);
if (result)
throw invalid_argument("need a contiguous buffer to read");
char *mem = (char *) malloc(src.len);
if (!mem) {
PyBuffer_Release(&src);
throw bad_alloc();
}
memcpy(mem, src.buf, src.len);
free(_bl->value);
_bl->size = src.len;
_bl->value = mem;
PyBuffer_Release(&src);
this->data(data);
this->mime_type(mime_type);
this->filename(filename);
}
@ -110,6 +94,30 @@ namespace pEp {
return PyBuffer_FillInfo(view, self, bl->value, bl->size, 0, flags);
}
object Message::Blob::data() {
return object(handle<>(PyBytes_FromString(_bl->value)));
}
void Message::Blob::data(object data) {
Py_buffer src;
int result = PyObject_GetBuffer(data.ptr(), &src, PyBUF_CONTIG_RO);
if (result)
throw invalid_argument("need a contiguous buffer to read");
char *mem = (char *) malloc(src.len);
if (!mem) {
PyBuffer_Release(&src);
throw bad_alloc();
}
memcpy(mem, src.buf, src.len);
free(_bl->value);
_bl->size = src.len;
_bl->value = mem;
PyBuffer_Release(&src);
}
string Message::Blob::decode(string encoding) {
if (encoding == "") {
string _mime_type = _bl->mime_type ? _bl->mime_type : "";


+ 5
- 1
src/pEp/_pEp/message.hh View File

@ -59,6 +59,10 @@ namespace pEp {
size_t size() { return _bl->size; }
object data();
void data(object data);
string decode(string encoding);
string decode() { return decode(""); }
@ -191,4 +195,4 @@ namespace pEp {
} /* namespace PythonAdapter */
} /* namespace pEp */
#endif /* MESSAGE_HH */
#endif /* MESSAGE_HH */

+ 4
- 1
src/pEp/_pEp/pEpmodule.cc View File

@ -399,7 +399,10 @@ namespace pEp {
"MIME type of object in Blob")
.add_property("filename", (string(Message::Blob::*)()) &Message::Blob::filename,
(void(Message::Blob::*)(string)) &Message::Blob::filename,
"filename of object in Blob");
"filename of object in Blob")
.add_property("data", (object(Message::Blob::*)()) &Message::Blob::data,
(void(Message::Blob::*)(object)) &Message::Blob::data,
"data of object in Blob");
((PyTypeObject *)(void *)blob_class.ptr())->tp_as_buffer = &Message::Blob::bp;


+ 21
- 0
tests/test_blob.py View File

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# This file is under GNU Affero General Public License 3.0
# see LICENSE.txt
"""Blob unit tests."""
import pytest
from . import constants
from . import model
def test_blob_data_constructor(pEp, model):
bdata = bytes('this is test data', 'utf-8')
b = pEp.Blob(bdata)
assert(b.data == bdata)
def test_blob_data_property(pEp, model):
b = pEp.Blob(b'dummy')
bdata = bytes('this is test data', 'utf-8')
b.data = bdata
assert(b.data == bdata)

+ 12
- 0
tests/test_identity.py View File

@ -29,6 +29,18 @@ def test_identity_constructor(pEp, model):
assert str(alice) == str(model.alice)
# Covers PYADPT-124
def test_identity_update_cpt(pEp,model):
bob = pEp.Identity(model.bob.addr, model.bob.name)
bob.update()
assert bob.address == model.bob.addr
assert bob.username == model.bob.name
assert bob.user_id == 'TOFU_bob@peptest.org'
assert bob.fpr == ''
assert bob.comm_type == 0
assert bob.lang == ''
# TODO:
# These here are actually plenty of individual tests
# Identity.update


Loading…
Cancel
Save