Skip to content

Commit 5b000bc

Browse files
committed
moved _convert_volume_entry_stat to utils
1 parent d11f652 commit 5b000bc

3 files changed

Lines changed: 37 additions & 52 deletions

File tree

packages/python-sdk/e2b/volume/utils.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
from typing import Optional
2+
3+
from e2b.api.client.models import VolumeEntryStat as VolumeEntryStatApi
4+
from e2b.api.client.types import UNSET
5+
from e2b.volume.types import VolumeEntryStat
6+
7+
8+
def convert_volume_entry_stat(api_stat: VolumeEntryStatApi) -> VolumeEntryStat:
9+
"""Convert API VolumeEntryStat to SDK VolumeEntryStat."""
10+
target: Optional[str] = None
11+
if api_stat.target is not UNSET and api_stat.target is not None:
12+
target = str(api_stat.target)
13+
14+
return VolumeEntryStat(
15+
name=api_stat.name,
16+
type=api_stat.type_,
17+
path=api_stat.path,
18+
size=api_stat.size,
19+
mode=api_stat.mode,
20+
uid=api_stat.uid,
21+
gid=api_stat.gid,
22+
mtime=api_stat.mtime,
23+
ctime=api_stat.ctime,
24+
target=target,
25+
)
26+
27+
128
class DualMethod:
229
"""Descriptor enabling the same name for a static (class-level) and instance method.
330

packages/python-sdk/e2b/volume/volume_async.py

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,7 @@
2828
VolumeInfo,
2929
VolumeEntryStat,
3030
)
31-
from e2b.volume.utils import DualMethod
32-
33-
34-
def _convert_volume_entry_stat(api_stat: VolumeEntryStatApi) -> VolumeEntryStat:
35-
"""Convert API VolumeEntryStat to SDK VolumeEntryStat."""
36-
from e2b.api.client.types import UNSET
37-
38-
target: Optional[str] = None
39-
if api_stat.target is not UNSET and api_stat.target is not None:
40-
target = str(api_stat.target)
41-
42-
return VolumeEntryStat(
43-
name=api_stat.name,
44-
type=api_stat.type_,
45-
path=api_stat.path,
46-
size=api_stat.size,
47-
mode=api_stat.mode,
48-
uid=api_stat.uid,
49-
gid=api_stat.gid,
50-
mtime=api_stat.mtime,
51-
ctime=api_stat.ctime,
52-
target=target,
53-
)
31+
from e2b.volume.utils import DualMethod, convert_volume_entry_stat
5432

5533

5634
class AsyncVolume:
@@ -244,7 +222,7 @@ async def _instance_list(
244222

245223
# VolumeDirectoryListing is a list according to the spec
246224
if isinstance(res.parsed, list):
247-
return [_convert_volume_entry_stat(entry) for entry in res.parsed]
225+
return [convert_volume_entry_stat(entry) for entry in res.parsed]
248226
return []
249227

250228
async def make_dir(
@@ -335,7 +313,7 @@ async def _instance_get_info(
335313
if isinstance(res.parsed, Error):
336314
raise Exception(f"{res.parsed.message}: Request failed")
337315

338-
return _convert_volume_entry_stat(res.parsed)
316+
return convert_volume_entry_stat(res.parsed)
339317

340318
get_info = DualMethod(_class_get_info.__func__, _instance_get_info)
341319
list = DualMethod(_class_list.__func__, _instance_list)
@@ -384,7 +362,7 @@ async def update_metadata(
384362
if res.parsed is None:
385363
raise Exception("Body of the request is None")
386364

387-
return _convert_volume_entry_stat(res.parsed)
365+
return convert_volume_entry_stat(res.parsed)
388366

389367
@overload
390368
async def read_file(
@@ -535,7 +513,7 @@ async def write_file(
535513
raise err
536514

537515
parsed = VolumeEntryStatApi.from_dict(response.json())
538-
return _convert_volume_entry_stat(parsed)
516+
return convert_volume_entry_stat(parsed)
539517

540518
async def remove(
541519
self,

packages/python-sdk/e2b/volume/volume_sync.py

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,7 @@
2828
VolumeInfo,
2929
VolumeEntryStat,
3030
)
31-
from e2b.volume.utils import DualMethod
32-
33-
34-
def _convert_volume_entry_stat(api_stat: VolumeEntryStatApi) -> VolumeEntryStat:
35-
"""Convert API VolumeEntryStat to SDK VolumeEntryStat."""
36-
target: Optional[str] = None
37-
if api_stat.target is not UNSET and api_stat.target is not None:
38-
target = str(api_stat.target)
39-
40-
return VolumeEntryStat(
41-
name=api_stat.name,
42-
type=api_stat.type_,
43-
path=api_stat.path,
44-
size=api_stat.size,
45-
mode=api_stat.mode,
46-
uid=api_stat.uid,
47-
gid=api_stat.gid,
48-
mtime=api_stat.mtime,
49-
ctime=api_stat.ctime,
50-
target=target,
51-
)
31+
from e2b.volume.utils import DualMethod, convert_volume_entry_stat
5232

5333

5434
class Volume:
@@ -242,7 +222,7 @@ def _instance_list(
242222

243223
# VolumeDirectoryListing is a list according to the spec
244224
if isinstance(res.parsed, list):
245-
return [_convert_volume_entry_stat(entry) for entry in res.parsed]
225+
return [convert_volume_entry_stat(entry) for entry in res.parsed]
246226
return []
247227

248228
def make_dir(
@@ -333,7 +313,7 @@ def _instance_get_info(
333313
if isinstance(res.parsed, Error):
334314
raise Exception(f"{res.parsed.message}: Request failed")
335315

336-
return _convert_volume_entry_stat(res.parsed)
316+
return convert_volume_entry_stat(res.parsed)
337317

338318
get_info = DualMethod(_class_get_info.__func__, _instance_get_info)
339319
list = DualMethod(_class_list.__func__, _instance_list)
@@ -382,7 +362,7 @@ def update_metadata(
382362
if res.parsed is None:
383363
raise Exception("Body of the request is None")
384364

385-
return _convert_volume_entry_stat(res.parsed)
365+
return convert_volume_entry_stat(res.parsed)
386366

387367
@overload
388368
def read_file(
@@ -533,7 +513,7 @@ def write_file(
533513
raise err
534514

535515
parsed = VolumeEntryStatApi.from_dict(response.json())
536-
return _convert_volume_entry_stat(parsed)
516+
return convert_volume_entry_stat(parsed)
537517

538518
def remove(
539519
self,

0 commit comments

Comments
 (0)