15 Commits

11 changed files with 90 additions and 63 deletions
Split View
  1. +1
    -0
      .gitignore
  2. +1
    -1
      DEPENDENCIES
  3. +1
    -1
      build-windows/add_windows_libraries.py
  4. +0
    -31
      build-windows/pEpPythonAdapter.sln
  5. +11
    -6
      build-windows/pEpPythonAdapter.vcxproj
  6. +6
    -4
      make.mak
  7. +1
    -1
      setup.py
  8. +25
    -17
      src/pEp/_pEp/message.cc
  9. +5
    -1
      src/pEp/_pEp/message.hh
  10. +4
    -1
      src/pEp/_pEp/pEpmodule.cc
  11. +35
    -0
      tests/test_blob.py

+ 1
- 0
.gitignore View File

@ -24,6 +24,7 @@ build-windows/Release/
build-windows/packages/
build-windows/.vs/
build-windows/pEpPythonAdapter.vcxproj.*
.vscode/
launch.json
settings.json
# Default ignored files


+ 1
- 1
DEPENDENCIES View File

@ -2,4 +2,4 @@
## Prefer git tags instead of SHA hashes when possible.
libpEpAdapter=Release_2.1.21
pEpEngine=Release_2.1.39
pEpEngine=Release_2.1.49

+ 1
- 1
build-windows/add_windows_libraries.py View File

@ -67,7 +67,7 @@ def get_pEp_install_location(debug=False):
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()]:
for dir in [f.path for f in os.scandir(join(dirname(os.getcwd()), 'packages')) if f.is_dir()]:
if 'boost.' in dir or 'boost_python' in dir or 'boost_locale' in dir:
yield join(dir, 'lib', 'native')


+ 0
- 31
build-windows/pEpPythonAdapter.sln View File

@ -1,31 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31005.135
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pEpPythonAdapter", "pEpPythonAdapter.vcxproj", "{F7D4314B-C7BA-4117-9AE7-AC5C1492153D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F7D4314B-C7BA-4117-9AE7-AC5C1492153D}.Debug|x64.ActiveCfg = Debug|x64
{F7D4314B-C7BA-4117-9AE7-AC5C1492153D}.Debug|x64.Build.0 = Debug|x64
{F7D4314B-C7BA-4117-9AE7-AC5C1492153D}.Debug|x86.ActiveCfg = Debug|Win32
{F7D4314B-C7BA-4117-9AE7-AC5C1492153D}.Debug|x86.Build.0 = Debug|Win32
{F7D4314B-C7BA-4117-9AE7-AC5C1492153D}.Release|x64.ActiveCfg = Release|x64
{F7D4314B-C7BA-4117-9AE7-AC5C1492153D}.Release|x64.Build.0 = Release|x64
{F7D4314B-C7BA-4117-9AE7-AC5C1492153D}.Release|x86.ActiveCfg = Release|Win32
{F7D4314B-C7BA-4117-9AE7-AC5C1492153D}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B63BC9BA-EF76-4FB4-9126-29CBFAD9092C}
EndGlobalSection
EndGlobal

+ 11
- 6
build-windows/pEpPythonAdapter.vcxproj View File

@ -95,18 +95,23 @@
<None Include="..\setup.py" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\pEpEngine\build-windows\pEpEngine.vcxproj">
<Project>{146e69f8-e1da-456a-b048-6dd29d9acf6b}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="packages\boost.1.72.0.0\build\boost.targets" Condition="Exists('packages\boost.1.72.0.0\build\boost.targets')" />
<Import Project="packages\boost_locale-vc142.1.72.0.0\build\boost_locale-vc142.targets" Condition="Exists('packages\boost_locale-vc142.1.72.0.0\build\boost_locale-vc142.targets')" />
<Import Project="packages\boost_python38-vc142.1.72.0.0\build\boost_python38-vc142.targets" Condition="Exists('packages\boost_python38-vc142.1.72.0.0\build\boost_python38-vc142.targets')" />
<Import Project="..\..\packages\boost.1.72.0.0\build\boost.targets" Condition="Exists('..\..\packages\boost.1.72.0.0\build\boost.targets')" />
<Import Project="..\..\packages\boost_locale-vc142.1.72.0.0\build\boost_locale-vc142.targets" Condition="Exists('..\..\packages\boost_locale-vc142.1.72.0.0\build\boost_locale-vc142.targets')" />
<Import Project="..\..\packages\boost_python38-vc142.1.72.0.0\build\boost_python38-vc142.targets" Condition="Exists('..\..\packages\boost_python38-vc142.1.72.0.0\build\boost_python38-vc142.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('packages\boost.1.72.0.0\build\boost.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\boost.1.72.0.0\build\boost.targets'))" />
<Error Condition="!Exists('packages\boost_locale-vc142.1.72.0.0\build\boost_locale-vc142.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\boost_locale-vc142.1.72.0.0\build\boost_locale-vc142.targets'))" />
<Error Condition="!Exists('packages\boost_python38-vc142.1.72.0.0\build\boost_python38-vc142.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\boost_python38-vc142.1.72.0.0\build\boost_python38-vc142.targets'))" />
<Error Condition="!Exists('..\..\packages\boost.1.72.0.0\build\boost.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\boost.1.72.0.0\build\boost.targets'))" />
<Error Condition="!Exists('..\..\packages\boost_locale-vc142.1.72.0.0\build\boost_locale-vc142.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\boost_locale-vc142.1.72.0.0\build\boost_locale-vc142.targets'))" />
<Error Condition="!Exists('..\..\packages\boost_python38-vc142.1.72.0.0\build\boost_python38-vc142.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\boost_python38-vc142.1.72.0.0\build\boost_python38-vc142.targets'))" />
</Target>
</Project>

+ 6
- 4
make.mak View File

@ -1,6 +1,6 @@
# build dirs
BUILD_DIR = $(ProjectDir)..\build
DIST_DIR = $(ProjectDir)..\dist
BUILD_DIR = build
DIST_DIR = dist
# create wheel and egg package in dist
dist: dist-whl dist-egg
@ -31,11 +31,13 @@ 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
PY -3.8-32 build-windows\add_windows_libraries.py
COPY dist\pEp* ..\Release\
#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 build-windows/add_windows_libraries.py --debug
PY -3.8-32 build-windows\add_windows_libraries.py --debug
COPY dist\pEp* ..\Debug\

+ 1
- 1
setup.py View File

@ -60,7 +60,7 @@ class BuildExtCommand(build_ext):
return ret
def windowsGetBoostDirs(self):
for dir in [f.path for f in os.scandir(join(os.getcwd(), 'build-windows', 'packages')) if f.is_dir()]:
for dir in [f.path for f in os.scandir(join(os.path.dirname(os.getcwd()), 'packages')) if f.is_dir()]:
if 'boost.' in dir or 'boost_python' in dir or 'boost_locale' in dir:
yield join(dir, 'lib', 'native'), join(dir, 'lib', 'native', 'include')


+ 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_FromStringAndSize(_bl->value, _bl->size)));
}
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;


+ 35
- 0
tests/test_blob.py View File

@ -0,0 +1,35 @@
# -*- 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):
bdata = b'this is binary \x00\x01\xbb\xa7\xa4\xab test data'
b = pEp.Blob(bdata)
assert b.data == bdata
assert not b.mime_type
assert not b.filename
def test_blob_data_property(pEp):
bdata = b'this is binary \x00\x01\xbb\xa7\xa4\xab test data'
b = pEp.Blob(b'dummy')
b.data = bdata
assert b.data == bdata
assert not b.mime_type
assert not b.filename
def test_blob_data_property_keeps_other_fields(pEp):
bdata = b'this is binary \x00\x01\xbb\xa7\xa4\xab test data'
b = pEp.Blob(b'dummy', 'application/x-mydata', 'myfile.dat')
b.data = bdata
assert b.data == bdata
assert b.mime_type == 'application/x-mydata'
assert b.filename == 'myfile.dat'

Loading…
Cancel
Save