diff options
Diffstat (limited to 'cython')
| -rw-r--r-- | cython/afc.pxi | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/cython/afc.pxi b/cython/afc.pxi index ff5c2b0..398ea39 100644 --- a/cython/afc.pxi +++ b/cython/afc.pxi | |||
| @@ -67,6 +67,10 @@ cdef extern from "libimobiledevice/afc.h": | |||
| 67 | afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *position) | 67 | afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *position) |
| 68 | afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t newsize) | 68 | afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t newsize) |
| 69 | 69 | ||
| 70 | LOCK_SH = AFC_LOCK_SH | ||
| 71 | LOCK_EX = AFC_LOCK_EX | ||
| 72 | LOCK_UN = AFC_LOCK_UN | ||
| 73 | |||
| 70 | cdef class AfcError(BaseError): | 74 | cdef class AfcError(BaseError): |
| 71 | def __init__(self, *args, **kwargs): | 75 | def __init__(self, *args, **kwargs): |
| 72 | self._lookup_table = { | 76 | self._lookup_table = { |
| @@ -115,6 +119,9 @@ cdef class AfcFile(Base): | |||
| 115 | cpdef close(self): | 119 | cpdef close(self): |
| 116 | self.handle_error(afc_file_close(self._client._c_client, self._c_handle)) | 120 | self.handle_error(afc_file_close(self._client._c_client, self._c_handle)) |
| 117 | 121 | ||
| 122 | cpdef lock(self, int operation): | ||
| 123 | self.handle_error(afc_file_lock(self._client._c_client, self._c_handle, <afc_lock_op_t>operation)) | ||
| 124 | |||
| 118 | cpdef seek(self, int64_t offset, int whence): | 125 | cpdef seek(self, int64_t offset, int whence): |
| 119 | self.handle_error(afc_file_seek(self._client._c_client, self._c_handle, offset, whence)) | 126 | self.handle_error(afc_file_seek(self._client._c_client, self._c_handle, offset, whence)) |
| 120 | 127 | ||
| @@ -208,14 +215,26 @@ cdef class AfcClient(BaseService): | |||
| 208 | 215 | ||
| 209 | return result | 216 | return result |
| 210 | 217 | ||
| 211 | cpdef AfcFile open(self, bytes filename): | 218 | cpdef AfcFile open(self, bytes filename, bytes mode='r'): |
| 212 | cdef: | 219 | cdef: |
| 213 | str mode = 'r' | ||
| 214 | afc_file_mode_t c_mode | 220 | afc_file_mode_t c_mode |
| 215 | uint64_t handle | 221 | uint64_t handle |
| 216 | AfcFile f | 222 | AfcFile f |
| 217 | if mode == 'r': | 223 | if mode == <bytes>'r': |
| 218 | c_mode = AFC_FOPEN_RDONLY | 224 | c_mode = AFC_FOPEN_RDONLY |
| 225 | elif mode == <bytes>'r+': | ||
| 226 | c_mode = AFC_FOPEN_RW | ||
| 227 | elif mode == <bytes>'w': | ||
| 228 | c_mode = AFC_FOPEN_WRONLY | ||
| 229 | elif mode == <bytes>'w+': | ||
| 230 | c_mode = AFC_FOPEN_WR | ||
| 231 | elif mode == <bytes>'a': | ||
| 232 | c_mode = AFC_FOPEN_APPEND | ||
| 233 | elif mode == <bytes>'a+': | ||
| 234 | c_mode = AFC_FOPEN_RDAPPEND | ||
| 235 | else: | ||
| 236 | raise ValueError("mode string must be 'r', 'r+', 'w', 'w+', 'a', or 'a+'") | ||
| 237 | |||
| 219 | self.handle_error(afc_file_open(self._c_client, filename, c_mode, &handle)) | 238 | self.handle_error(afc_file_open(self._c_client, filename, c_mode, &handle)) |
| 220 | f = AfcFile.__new__(AfcFile) | 239 | f = AfcFile.__new__(AfcFile) |
| 221 | f._c_handle = handle | 240 | f._c_handle = handle |
| @@ -257,5 +276,11 @@ cdef class AfcClient(BaseService): | |||
| 257 | cpdef truncate(self, bytes path, uint64_t newsize): | 276 | cpdef truncate(self, bytes path, uint64_t newsize): |
| 258 | self.handle_error(afc_truncate(self._c_client, path, newsize)) | 277 | self.handle_error(afc_truncate(self._c_client, path, newsize)) |
| 259 | 278 | ||
| 279 | cpdef link(self, bytes source, bytes link_name): | ||
| 280 | self.handle_error(afc_make_link(self._c_client, AFC_HARDLINK, source, link_name)) | ||
| 281 | |||
| 282 | cpdef symlink(self, bytes source, bytes link_name): | ||
| 283 | self.handle_error(afc_make_link(self._c_client, AFC_SYMLINK, source, link_name)) | ||
| 284 | |||
| 260 | cpdef set_file_time(self, bytes path, uint64_t mtime): | 285 | cpdef set_file_time(self, bytes path, uint64_t mtime): |
| 261 | self.handle_error(afc_set_file_time(self._c_client, path, mtime)) | 286 | self.handle_error(afc_set_file_time(self._c_client, path, mtime)) |
