forked from ParallelSSH/ssh-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsftp_attributes.pyx
More file actions
248 lines (202 loc) · 6.85 KB
/
sftp_attributes.pyx
File metadata and controls
248 lines (202 loc) · 6.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# This file is part of ssh-python.
# Copyright (C) 2018 Panos Kittenis
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation, version 2.1.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130
from libc.stdlib cimport malloc, free
from sftp cimport SFTP
from utils cimport ssh_string_to_bytes
from c_ssh cimport ssh_string, uint8_t, uint32_t, uint64_t
cimport c_sftp
cdef class SFTPAttributes:
def __cinit__(self):
self.self_made = False
def __dealloc__(self):
if self._attrs is not NULL and not self.self_made:
c_sftp.sftp_attributes_free(self._attrs)
self._attrs = NULL
elif self._attrs is not NULL and self.self_made:
free(self._attrs)
self._attrs = NULL
@staticmethod
cdef SFTPAttributes from_ptr(c_sftp.sftp_attributes attrs, SFTP sftp):
cdef SFTPAttributes _attrs = SFTPAttributes.__new__(SFTPAttributes)
_attrs._attrs = attrs
_attrs.sftp = sftp
return _attrs
@staticmethod
def new_attrs(SFTP sftp):
cdef SFTPAttributes attrs
cdef c_sftp.sftp_attributes _attrs
with nogil:
_attrs = <c_sftp.sftp_attributes>malloc(
sizeof(c_sftp.sftp_attributes_struct))
if _attrs is NULL:
raise MemoryError
_attrs.name = b''
_attrs.longname = b''
_attrs.flags = 0
_attrs.type = 0
_attrs.size = 0
_attrs.uid = 0
_attrs.gid = 0
_attrs.owner = b''
_attrs.group = b''
_attrs.permissions = 0
_attrs.atime64 = 0
_attrs.atime = 0
_attrs.atime_nseconds = 0
_attrs.createtime = 0
_attrs.createtime_nseconds = 0
_attrs.mtime64 = 0
_attrs.mtime = 0
_attrs.mtime_nseconds = 0
_attrs.acl = NULL
_attrs.extended_count = 0
_attrs.extended_type = NULL
_attrs.extended_data = NULL
attrs = SFTPAttributes.from_ptr(_attrs, sftp)
attrs.self_made = True
return attrs
@property
def name(self):
if self._attrs is NULL:
return
cdef bytes b_name = self._attrs.name
return b_name
@property
def longname(self):
if self._attrs is NULL:
return
cdef bytes b_longname = self._attrs.longname
return b_longname
@property
def flags(self):
return self._attrs.flags if self._attrs is not NULL else None
@flags.setter
def flags(self, uint32_t flags):
self._attrs.flags = flags
@property
def type(self):
return self._attrs.type if self._attrs is not NULL else None
@type.setter
def type(self, uint8_t _type):
self._attrs.type = _type
@property
def size(self):
return self._attrs.size if self._attrs is not NULL else None
@size.setter
def size(self, uint64_t size):
self._attrs.size = size
@property
def uid(self):
return self._attrs.uid if self._attrs is not NULL else None
@uid.setter
def uid(self, uint32_t uid):
self._attrs.uid = uid
@property
def gid(self):
return self._attrs.gid if self._attrs is not NULL else None
@gid.setter
def gid(self, uint32_t gid):
self._attrs.gid = gid
@property
def owner(self):
if self._attrs is NULL:
return
cdef bytes b_owner = self._attrs.owner \
if self._attrs.owner is not NULL else None
return b_owner
@property
def group(self):
if self._attrs is NULL:
return
cdef bytes b_group = self._attrs.group \
if self._attrs.group is not NULL else None
return b_group
@property
def permissions(self):
return self._attrs.permissions if self._attrs is not NULL else None
@permissions.setter
def permissions(self, uint32_t permissions):
self._attrs.permissions = permissions
@property
def atime64(self):
return self._attrs.atime64 if self._attrs is not NULL else None
@atime64.setter
def atime64(self, uint64_t atime):
self._attrs.atime64 = atime
@property
def atime(self):
return self._attrs.atime if self._attrs is not NULL else None
@atime.setter
def atime(self, uint32_t atime):
self._attrs.atime = atime
@property
def atime_nseconds(self):
return self._attrs.atime_nseconds if self._attrs is not NULL else None
@atime_nseconds.setter
def atime_nseconds(self, uint32_t nseconds):
self._attrs.atime_nseconds = nseconds
@property
def createtime(self):
return self._attrs.createtime if self._attrs is not NULL else None
@createtime.setter
def createtime(self, uint64_t createtime):
self._attrs.createtime = createtime
@property
def createtime_nseconds(self):
return self._attrs.createtime_nseconds \
if self._attrs is not NULL else None
@createtime_nseconds.setter
def createtime_nseconds(self, uint32_t nseconds):
self._attrs.createtime_nseconds = nseconds
@property
def mtime64(self):
return self._attrs.mtime64 if self._attrs is not NULL else None
@mtime64.setter
def mtime64(self, uint64_t mtime):
self._attrs.mtime64 = mtime
@property
def mtime(self):
return self._attrs.mtime if self._attrs is not NULL else None
@mtime.setter
def mtime(self, uint32_t mtime):
self._attrs.mtime = mtime
@property
def mtime_nseconds(self):
return self._attrs.mtime_nseconds if self._attrs is not NULL else None
@mtime_nseconds.setter
def mtime_nseconds(self, uint32_t nseconds):
self._attrs.mtime_nseconds = nseconds
@property
def acl(self):
if self._attrs is NULL:
return
return ssh_string_to_bytes(self._attrs.acl)
@property
def extended_count(self):
return self._attrs.extended_count if self._attrs is not NULL else None
@extended_count.setter
def extended_count(self, uint32_t count):
self._attrs.extended_count = count
@property
def extended_type(self):
if self._attrs is NULL:
return
return ssh_string_to_bytes(self._attrs.extended_type)
@property
def extended_data(self):
if self._attrs is NULL:
return
return ssh_string_to_bytes(self._attrs.extended_data)