Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Available at PyPi
Provides a wrapper class TimeoutIterator to add timeout feature to normal iterators
pip install iterators
See help of TimeoutIterator for all the features. Check tests for examples on how to use TimeoutIterator. See example tests below for basic usage
TimeoutIterator works like normal iterator:
from iterators import TimeoutIterator
def iter_simple():
yield 1
yield 2
def test_normal_iteration(self):
i = iter_simple()
it = TimeoutIterator(i)
self.assertEqual(next(it), 1)
self.assertEqual(next(it), 2)
self.assertRaises(StopIteration, next, it)
self.assertRaises(StopIteration, next, it)
When timeout is needed, use like this
def iter_with_sleep():
yield 1
time.sleep(0.6)
yield 2
time.sleep(0.4)
yield 3
def test_fixed_timeout(self):
i = iter_with_sleep()
it = TimeoutIterator(i, timeout=0.5)
self.assertEqual(next(it), 1)
self.assertEqual(next(it), it.get_sentinel())
self.assertEqual(next(it), 2)
self.assertEqual(next(it), 3)
self.assertRaises(StopIteration, next, it)
Dynamic timeout adjustment
def iter_with_sleep():
yield 1
time.sleep(0.6)
yield 2
time.sleep(0.4)
yield 3
def test_timeout_update(self):
i = iter_with_sleep()
it = TimeoutIterator(i, timeout=0.5)
self.assertEqual(next(it), 1)
self.assertEqual(next(it), it.get_sentinel())
it.set_timeout(0.3)
self.assertEqual(next(it), 2)
self.assertEqual(next(it), it.get_sentinel())
self.assertEqual(next(it), 3)
self.assertRaises(StopIteration, next, it)
python -m unittest discover tests
FAQs
Iterator utility classes and functions
We found that iterators demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.