torrequest-0.1.0/0000755000076500000240000000000012755076003014000 5ustar erdistaff00000000000000torrequest-0.1.0/PKG-INFO0000644000076500000240000000041012755076003015070 0ustar erdistaff00000000000000Metadata-Version: 1.0 Name: torrequest Version: 0.1.0 Summary: A simple interface for HTTP(s) requests over Tor Home-page: http://github.com/erdiaker/torrequest Author: Erdi Aker Author-email: erdiaker@gmail.com License: MIT Description: UNKNOWN Platform: UNKNOWN torrequest-0.1.0/setup.cfg0000644000076500000240000000014412755076003015620 0ustar erdistaff00000000000000[metadata] description-file = README.md [egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 torrequest-0.1.0/setup.py0000644000076500000240000000062112755063631015514 0ustar erdistaff00000000000000from setuptools import setup setup(name='torrequest', version='0.1.0', description='A simple interface for HTTP(s) requests over Tor', url='http://github.com/erdiaker/torrequest', author='Erdi Aker', author_email='erdiaker@gmail.com', license='MIT', py_modules=['torrequest'], install_requires=[ 'PySocks>=1.5.7', 'requests>=2.11.0', 'stem>=1.4.0' ], zip_safe=False) torrequest-0.1.0/torrequest.egg-info/0000755000076500000240000000000012755076003017707 5ustar erdistaff00000000000000torrequest-0.1.0/torrequest.egg-info/dependency_links.txt0000644000076500000240000000000112755076003023755 0ustar erdistaff00000000000000 torrequest-0.1.0/torrequest.egg-info/not-zip-safe0000644000076500000240000000000112755064147022143 0ustar erdistaff00000000000000 torrequest-0.1.0/torrequest.egg-info/PKG-INFO0000644000076500000240000000041012755076003020777 0ustar erdistaff00000000000000Metadata-Version: 1.0 Name: torrequest Version: 0.1.0 Summary: A simple interface for HTTP(s) requests over Tor Home-page: http://github.com/erdiaker/torrequest Author: Erdi Aker Author-email: erdiaker@gmail.com License: MIT Description: UNKNOWN Platform: UNKNOWN torrequest-0.1.0/torrequest.egg-info/requires.txt0000644000076500000240000000005412755076003022306 0ustar erdistaff00000000000000PySocks>=1.5.7 requests>=2.11.0 stem>=1.4.0 torrequest-0.1.0/torrequest.egg-info/SOURCES.txt0000644000076500000240000000035212755076003021573 0ustar erdistaff00000000000000setup.cfg setup.py torrequest.py torrequest.egg-info/PKG-INFO torrequest.egg-info/SOURCES.txt torrequest.egg-info/dependency_links.txt torrequest.egg-info/not-zip-safe torrequest.egg-info/requires.txt torrequest.egg-info/top_level.txttorrequest-0.1.0/torrequest.egg-info/top_level.txt0000644000076500000240000000001312755076003022433 0ustar erdistaff00000000000000torrequest torrequest-0.1.0/torrequest.py0000644000076500000240000000364212755063716016603 0ustar erdistaff00000000000000 import stem from stem.control import Controller from stem.process import launch_tor_with_config import requests import time class TorRequest(object): def __init__(self, proxy_port=9050, ctrl_port=9051, password=None): self.proxy_port = proxy_port self.ctrl_port = ctrl_port self._tor_proc = None if not self._tor_process_exists(): self._tor_proc = self._launch_tor() self.ctrl = Controller.from_port(port=self.ctrl_port) self.ctrl.authenticate(password=password) self.session = requests.Session() self.session.proxies.update({ 'http': 'socks5://localhost:%d' % self.proxy_port, 'https:': 'socks5://localhost:%d' % self.proxy_port, }) def _tor_process_exists(self): try: ctrl = Controller.from_port(port=self.ctrl_port) ctrl.close() return True except: return False def _launch_tor(self): return launch_tor_with_config( config={ 'SocksPort': str(self.proxy_port), 'ControlPort': str(self.ctrl_port) }, take_ownership=True) def close(self): try: self.session.close() except: pass try: self.ctrl.close() except: pass if self._tor_proc: self._tor_proc.terminate() def reset_identity_async(self): self.ctrl.signal(stem.Signal.NEWNYM) def reset_identity(self): self.reset_identity_async() time.sleep(self.ctrl.get_newnym_wait()) def get(self, *args, **kwargs): return self.session.get(*args, **kwargs) def post(self, *args, **kwargs): return self.session.post(*args, **kwargs) def put(self, *args, **kwargs): return self.session.put(*args, **kwargs) def patch(self, *args, **kwargs): return self.session.patch(*args, **kwargs) def delete(self, *args, **kwargs): return self.session.delete(*args, **kwargs) def __enter__(self): return self def __exit__(self, *args): self.close()