python: Default whence argument for Data() to SEEK_SET.
* lang/python/gpgme.i: copied signature from gpgme.h and defaulted the value to SEEK_SET. * lang/python/tests/t-data.py: Added a test for no second argument -- Having to import the os package when wanting to read a Data object is a slight annoyance. With SWIG, we can define default parameters. This change defaults the whence argument to SEEK_SET which is how StringIO and BytesIO behave. Signed-off-by: Tobias Mueller <muelli@cryptobitch.de>
This commit is contained in:
parent
2205ee2cd9
commit
3cf9aedc92
@ -557,6 +557,11 @@ gpgme_error_t gpgme_op_keylist_start (gpgme_ctx_t ctx,
|
|||||||
const char *pattern="",
|
const char *pattern="",
|
||||||
int secret_only=0);
|
int secret_only=0);
|
||||||
|
|
||||||
|
/* The whence argument is surprising in Python-land,
|
||||||
|
because BytesIO or StringIO objects do not require it.
|
||||||
|
It defaults to SEEK_SET. Let's do that for Data objects, too */
|
||||||
|
off_t gpgme_data_seek (gpgme_data_t dh, off_t offset, int whence=SEEK_SET);
|
||||||
|
|
||||||
/* Include the unmodified <gpgme.h> for cc, and the cleaned-up local
|
/* Include the unmodified <gpgme.h> for cc, and the cleaned-up local
|
||||||
version for SWIG. We do, however, want to hide certain fields on
|
version for SWIG. We do, however, want to hide certain fields on
|
||||||
some structs, which we provide prior to including the version for
|
some structs, which we provide prior to including the version for
|
||||||
|
@ -51,6 +51,12 @@ data.write(b'Hello world!')
|
|||||||
data.seek(0, os.SEEK_SET)
|
data.seek(0, os.SEEK_SET)
|
||||||
assert data.read() == b'Hello world!'
|
assert data.read() == b'Hello world!'
|
||||||
|
|
||||||
|
data = gpg.Data()
|
||||||
|
data.write(b'Hello world!')
|
||||||
|
# We expect the second argument to default to SEEK_SET
|
||||||
|
data.seek(0)
|
||||||
|
assert data.read() == b'Hello world!'
|
||||||
|
|
||||||
binjunk = bytes(range(256))
|
binjunk = bytes(range(256))
|
||||||
data = gpg.Data()
|
data = gpg.Data()
|
||||||
data.write(binjunk)
|
data.write(binjunk)
|
||||||
|
Loading…
Reference in New Issue
Block a user