Skip to content

Commit b3a7b22

Browse files
Omit derived classes of BasicIo
The complications of dealing with compile options such as EXV_USE_CURL are not needed as the derived classes all have the same interface. ImageFactory.createIo() can be used to create an object of a BasicIo drived class if needed.
1 parent e8d2a9c commit b3a7b22

25 files changed

+1522
-18541
lines changed

CHANGELOG.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ You should have received a copy of the GNU General Public License
1616
along with this program. If not, see
1717
<http://www.gnu.org/licenses/>.
1818

19+
Changes in v0.17.0:
20+
1/ API change: derived classes of BasicIo are omitted from Python.
21+
1922
Changes in v0.16.3:
2023
1/ Binary wheels incorporate libexiv2 v0.28.2.
2124

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
python-exiv2 v\ 0.16.4
1+
python-exiv2 v\ 0.17.0
22
======================
33

44
python-exiv2 is a low level interface (or binding) to the exiv2_ C++ library.

src/doc/_templates/module.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@
1515
:top-classes: exiv2.value.Value
1616
{% endif %}
1717

18-
{% if fullname == "exiv2._basicio" %}
19-
.. inheritance-diagram:: {{ classes | join(" ") }}
20-
:top-classes: exiv2.basicio.BasicIo
21-
{% endif %}
22-
2318
{% if fullname in ["exiv2._datasets", "exiv2._metadatum", "exiv2._properties", "exiv2._tags"] %}
2419
.. inheritance-diagram:: exiv2.ExifKey exiv2.IptcKey exiv2.XmpKey
2520
:top-classes: exiv2.metadatum.Key

src/doc/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
exiv2 <= 0.16.4
1+
exiv2 <= 0.17.0
22
sphinx == 7.2.6
33
sphinx-rtd-theme == 2.0.0

src/interface/basicio.i

Lines changed: 49 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
%nothread;
2020

2121
#ifndef SWIGIMPORTED
22-
%constant char* __doc__ = "Classes to access files, memory and remote data.";
22+
%constant char* __doc__ =
23+
"Class interface to access files, memory and remote data.";
2324
#endif
2425

2526
#pragma SWIG nowarn=321 // 'open' conflicts with a built-in name in python
@@ -29,7 +30,6 @@
2930
%include "shared/enum.i"
3031
%include "shared/exception.i"
3132
%include "shared/keep_reference.i"
32-
%include "shared/remoteio_derived.i"
3333
%include "shared/unique_ptr.i"
3434
%include "shared/windows_path.i"
3535

@@ -48,81 +48,54 @@ UNIQUE_PTR(Exiv2::BasicIo);
4848
%thread Exiv2::BasicIo::mmap;
4949
%thread Exiv2::BasicIo::munmap;
5050
%thread Exiv2::BasicIo::read;
51-
%thread Exiv2::MemIo::read;
5251
%thread Exiv2::BasicIo::seek;
53-
%thread Exiv2::FileIo::size;
54-
%thread Exiv2::FileIo::tell;
5552
%thread Exiv2::BasicIo::transfer;
5653
%thread Exiv2::BasicIo::write;
57-
%thread Exiv2::MemIo::write;
5854

5955
// Some calls don't raise exceptions
60-
%noexception Exiv2::MemIo::close;
6156
%noexception Exiv2::BasicIo::eof;
6257
%noexception Exiv2::BasicIo::error;
6358
%noexception Exiv2::BasicIo::isopen;
64-
%noexception Exiv2::MemIo::mmap;
65-
%noexception Exiv2::MemIo::munmap;
66-
%noexception Exiv2::RemoteIo::munmap;
67-
%noexception Exiv2::MemIo::open;
6859
%noexception Exiv2::BasicIo::path;
69-
%noexception Exiv2::MemIo::read;
70-
%noexception Exiv2::MemIo::seek;
71-
%noexception Exiv2::RemoteIo::seek;
72-
%noexception Exiv2::MemIo::size;
73-
%noexception Exiv2::RemoteIo::size;
74-
%noexception Exiv2::MemIo::tell;
75-
%noexception Exiv2::RemoteIo::tell;
76-
%noexception Exiv2::MemIo::write;
7760

7861
// Convert path encoding on Windows
7962
WINDOWS_PATH(const std::string& path)
8063
WINDOWS_PATH(const std::string& orgPath)
8164
WINDOWS_PATH(const std::string& url)
8265
WINDOWS_PATH_OUT(path)
8366

84-
// Convert BasicIo return values to actual subclass
85-
%fragment("basicio_subtype", "header") {
86-
static swig_type_info* basicio_subtype(Exiv2::BasicIo* ptr) {
87-
if (dynamic_cast<Exiv2::MemIo*>(ptr))
88-
return $descriptor(Exiv2::MemIo*);
89-
else if (dynamic_cast<Exiv2::FileIo*>(ptr)) {
90-
if (dynamic_cast<Exiv2::XPathIo*>(ptr))
91-
return $descriptor(Exiv2::XPathIo*);
92-
else
93-
return $descriptor(Exiv2::FileIo*);
67+
// Add method to get the subclass type
68+
%feature("docstring") Exiv2::BasicIo::ioType "Return the derived class type.
69+
70+
You shouldn't usually need to know the type of IO as they all have
71+
the same interface.
72+
:rtype: str
73+
:return: A class name such as ""FileIo""."
74+
%extend Exiv2::BasicIo {
75+
const char* ioType() {
76+
if (dynamic_cast<Exiv2::MemIo*>($self))
77+
return "MemIo";
78+
else if (dynamic_cast<Exiv2::FileIo*>($self)) {
79+
if (dynamic_cast<Exiv2::XPathIo*>($self))
80+
return "XPathIo";
81+
return "FileIo";
82+
}
83+
else if (dynamic_cast<Exiv2::RemoteIo*>($self)) {
84+
if (dynamic_cast<Exiv2::HttpIo*>($self))
85+
return "HttpIo";
86+
%#ifdef EXV_USE_CURL
87+
else if (dynamic_cast<Exiv2::CurlIo*>($self))
88+
return "CurlIo";
89+
%#endif
90+
%#ifdef EXV_USE_SSH
91+
else if (dynamic_cast<Exiv2::SshIo*>($self))
92+
return "SshIo";
93+
%#endif
94+
return "RemoteIo";
95+
}
96+
return "unknown";
9497
}
95-
else if (dynamic_cast<Exiv2::RemoteIo*>(ptr)) {
96-
if (dynamic_cast<Exiv2::HttpIo*>(ptr))
97-
return $descriptor(Exiv2::HttpIo*);
98-
#ifdef EXV_USE_CURL
99-
else if (dynamic_cast<Exiv2::CurlIo*>(ptr))
100-
return $descriptor(Exiv2::CurlIo*);
101-
#endif
102-
else
103-
return $descriptor(Exiv2::RemoteIo*);
104-
}
105-
return $descriptor(Exiv2::BasicIo*);
106-
};
107-
}
108-
%typemap(out, fragment="basicio_subtype") Exiv2::BasicIo& {
109-
$result = SWIG_NewPointerObj($1, basicio_subtype($1), 0);
110-
}
111-
%typemap(out, fragment="basicio_subtype") Exiv2::BasicIo::SMART_PTR {
112-
Exiv2::BasicIo* ptr = (&$1)->release();
113-
$result = SWIG_NewPointerObj(
114-
ptr, basicio_subtype(ptr), SWIG_POINTER_OWN);
115-
}
116-
117-
// CurlIo destructor isn't seen by SWIG in v0.27.x
118-
#if EXIV2_VERSION_HEX < 0x001c0000
119-
#ifdef EXV_USE_CURL
120-
%extend Exiv2::CurlIo {
121-
~CurlIo() {};
12298
}
123-
%ignore Exiv2::CurlIo::~CurlIo;
124-
#endif
125-
#endif
12699

127100
// readOrThrow & seekOrThrow use ErrorCode internally without Exiv2:: prefix
128101
// as if SWIG doesn't realise ErrorCode is in the Exiv2 namespace
@@ -143,10 +116,6 @@ KEEP_REFERENCE(Exiv2::BasicIo&)
143116
INPUT_BUFFER_RO(const Exiv2::byte* data, long wcount)
144117
INPUT_BUFFER_RO(const Exiv2::byte* data, size_t wcount)
145118

146-
// Allow MemIo to be ceated from a buffer
147-
INPUT_BUFFER_RO_EX(const Exiv2::byte* data, long size)
148-
INPUT_BUFFER_RO_EX(const Exiv2::byte* data, size_t size)
149-
150119
// BasicIo::read can write to a Python buffer
151120
OUTPUT_BUFFER_RW(Exiv2::byte* buf, long rcount)
152121
OUTPUT_BUFFER_RW(Exiv2::byte* buf, size_t rcount)
@@ -159,12 +128,12 @@ OUTPUT_BUFFER_RW(Exiv2::byte* buf, size_t rcount)
159128
RETURN_VIEW(Exiv2::byte* mmap, $1 ? arg1->size() : 0,
160129
arg2 ? PyBUF_WRITE : PyBUF_READ,)
161130

162-
%define EXTEND_BASICIO(io_type)
163-
// Enable len(io_type)
164-
%feature("python:slot", "sq_length", functype="lenfunc") io_type::size;
165-
// Expose io_type contents as a Python buffer
166-
%fragment("get_ptr_size"{io_type}, "header") {
167-
static bool get_ptr_size(io_type* self, bool is_writeable,
131+
// Enable len(Exiv2::BasicIo)
132+
%feature("python:slot", "sq_length", functype="lenfunc")
133+
Exiv2::BasicIo::size;
134+
// Expose Exiv2::BasicIo contents as a Python buffer
135+
%fragment("get_ptr_size"{Exiv2::BasicIo}, "header") {
136+
static bool get_ptr_size(Exiv2::BasicIo* self, bool is_writeable,
168137
Exiv2::byte*& ptr, Py_ssize_t& size) {
169138
if (self->open())
170139
return false;
@@ -183,20 +152,15 @@ static bool get_ptr_size(io_type* self, bool is_writeable,
183152
return true;
184153
};
185154
}
186-
%fragment("release_ptr"{io_type}, "header") {
187-
static void release_ptr(io_type* self) {
155+
%fragment("release_ptr"{Exiv2::BasicIo}, "header") {
156+
static void release_ptr(Exiv2::BasicIo* self) {
188157
SWIG_PYTHON_THREAD_BEGIN_ALLOW;
189158
self->munmap();
190159
self->close();
191160
SWIG_PYTHON_THREAD_END_ALLOW;
192161
};
193162
}
194-
EXPOSE_OBJECT_BUFFER(io_type, true, true)
195-
%enddef // EXTEND_BASICIO
196-
197-
EXTEND_BASICIO(Exiv2::FileIo)
198-
EXTEND_BASICIO(Exiv2::MemIo)
199-
EXTEND_BASICIO(Exiv2::RemoteIo)
163+
EXPOSE_OBJECT_BUFFER(Exiv2::BasicIo, true, true)
200164

201165
// Make enum more Pythonic
202166
DEFINE_CLASS_ENUM(BasicIo, Position, "Seek starting positions.",
@@ -210,21 +174,21 @@ DEPRECATED_ENUM(BasicIo, Position, "Seek starting positions.",
210174
"cur", Exiv2::BasicIo::cur,
211175
"end", Exiv2::BasicIo::end);
212176

213-
%ignore Exiv2::BasicIo::~BasicIo;
214177
%ignore Exiv2::BasicIo::bigBlock_;
178+
%ignore Exiv2::BasicIo::operator=;
215179
%ignore Exiv2::BasicIo::populateFakeData;
216180
%ignore Exiv2::curlWriter;
217181
%ignore Exiv2::IoCloser;
218182
%ignore Exiv2::ReplaceStringInPlace;
219183
%ignore Exiv2::readFile;
220184
%ignore Exiv2::writeFile;
221-
%ignore Exiv2::XPathIo::GEN_FILE_EXT;
222-
%ignore Exiv2::XPathIo::TEMP_FILE_EXT;
223-
%ignore Exiv2::CurlIo::operator=;
224-
%ignore Exiv2::FileIo::operator=;
225-
%ignore Exiv2::HttpIo::operator=;
226-
%ignore Exiv2::MemIo::operator=;
227-
%ignore Exiv2::SshIo::operator=;
185+
%ignore Exiv2::CurlIo;
186+
%ignore Exiv2::FileIo;
187+
%ignore Exiv2::HttpIo;
188+
%ignore Exiv2::MemIo;
189+
%ignore Exiv2::RemoteIo;
190+
%ignore Exiv2::SshIo;
191+
%ignore Exiv2::XPathIo;
228192
%ignore EXV_XPATH_MEMIO;
229193

230194
%include "exiv2/basicio.hpp"

src/interface/image.i

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
%include "shared/enum.i"
3030
%include "shared/exception.i"
3131
%include "shared/keep_reference.i"
32-
%include "shared/remoteio_derived.i"
3332
%include "shared/windows_path.i"
3433

3534
%include "std_string.i"

src/interface/preview.i

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ For Exif thumbnail images see the :py:class:`ExifThumb` class.";
3030
%include "shared/buffers.i"
3131
%include "shared/exception.i"
3232
%include "shared/keep_reference.i"
33-
%include "shared/remoteio_derived.i"
3433
%include "shared/struct_dict.i"
3534
%include "shared/windows_path.i"
3635

src/interface/shared/remoteio_derived.i

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/interface/shared/windows_path.i

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
SWIG_exception_fail(SWIG_ValueError, "failed to transcode result");
3838
}
3939
%#endif
40-
$result = SWIG_From_std_string($1);
40+
$result = SWIG_FromCharPtrAndSize($1.data(), $1.size());
4141
}
4242
%typemap(out, fragment="utf8_to_wcp") const std::string& function {
4343
std::string copy = *$1;
@@ -46,6 +46,6 @@
4646
SWIG_exception_fail(SWIG_ValueError, "failed to transcode result");
4747
}
4848
%#endif
49-
$result = SWIG_From_std_string(copy);
49+
$result = SWIG_FromCharPtrAndSize(copy.data(), copy.size());
5050
}
5151
%enddef // WINDOWS_PATH_OUT

src/interface/version.i

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ EXCEPTION()
3939

4040
// Function to report build options used
4141
%feature("docstring") versionInfo "Return a dict of libexiv2 build options."
42-
#ifndef EXV_USE_CURL
43-
%{
44-
#undef EXV_USE_CURL
45-
%}
46-
#endif
4742
%inline %{
4843
static PyObject* versionInfo() {
4944
bool nls = false;

0 commit comments

Comments
 (0)