-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91ede01
commit 5d6e2b5
Showing
3 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import | ||
|
||
from ._jail import RunningJail, StoppedJail | ||
from ._jail import RunningJail, StoppedJail, Jls | ||
|
||
__all__ = ['RunningJail', 'StoppedJail'] | ||
__all__ = ['RunningJail', 'StoppedJail', 'Jls'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use pyo3::prelude::*; | ||
use pyo3::{PyIterProtocol, PyObjectWithToken}; | ||
|
||
use jail as native; | ||
use running::RunningJail; | ||
|
||
#[pyclass] | ||
pub struct Jls { | ||
token: PyToken, | ||
it: native::RunningJailIter, | ||
} | ||
|
||
#[pymethods] | ||
impl Jls { | ||
#[new] | ||
fn __new__(obj: &PyRawObject) -> PyResult<()> { | ||
obj.init(|token| Jls { | ||
it: native::RunningJail::all(), | ||
token, | ||
}) | ||
} | ||
} | ||
|
||
#[pyproto] | ||
impl PyIterProtocol for Jls { | ||
fn __iter__(&mut self) -> PyResult<PyObject> { | ||
self.it = native::RunningJail::all(); | ||
Ok(self.into()) | ||
} | ||
|
||
fn __next__(&mut self) -> PyResult<Option<Py<RunningJail>>> { | ||
match self.it.next() { | ||
None => Ok(None), | ||
Some(next) => Ok(Some(self.py().init(|token| RunningJail::create(token, next))?) | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters