[Python-modules-commits] [python-mechanicalsoup] 01/05: Import python-mechanicalsoup_0.6.0.orig.tar.gz
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Wed Dec 28 07:23:59 UTC 2016
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch master
in repository python-mechanicalsoup.
commit dadf203813df4c14a22654fc7c9d4fe5ba0e25f7
Author: Ghislain Antony Vaillant <ghisvail at gmail.com>
Date: Tue Dec 27 16:02:40 2016 +0000
Import python-mechanicalsoup_0.6.0.orig.tar.gz
---
MechanicalSoup.egg-info/PKG-INFO | 19 +++++
MechanicalSoup.egg-info/SOURCES.txt | 10 +++
MechanicalSoup.egg-info/dependency_links.txt | 1 +
MechanicalSoup.egg-info/requires.txt | 3 +
MechanicalSoup.egg-info/top_level.txt | 1 +
PKG-INFO | 19 +++++
mechanicalsoup/__init__.py | 2 +
mechanicalsoup/browser.py | 120 +++++++++++++++++++++++++++
mechanicalsoup/form.py | 49 +++++++++++
setup.cfg | 8 ++
setup.py | 45 ++++++++++
11 files changed, 277 insertions(+)
diff --git a/MechanicalSoup.egg-info/PKG-INFO b/MechanicalSoup.egg-info/PKG-INFO
new file mode 100644
index 0000000..798ac2a
--- /dev/null
+++ b/MechanicalSoup.egg-info/PKG-INFO
@@ -0,0 +1,19 @@
+Metadata-Version: 1.1
+Name: MechanicalSoup
+Version: 0.6.0
+Summary: A Python library for automating interaction with websites
+Home-page: https://github.com/hickford/MechanicalSoup
+Author: UNKNOWN
+Author-email: UNKNOWN
+License: MIT
+Description: UNKNOWN
+Platform: UNKNOWN
+Classifier: License :: OSI Approved :: MIT License
+Classifier: Programming Language :: Python :: 2
+Classifier: Programming Language :: Python :: 2.6
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3
+Classifier: Programming Language :: Python :: 3.2
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: 3.5
diff --git a/MechanicalSoup.egg-info/SOURCES.txt b/MechanicalSoup.egg-info/SOURCES.txt
new file mode 100644
index 0000000..3061499
--- /dev/null
+++ b/MechanicalSoup.egg-info/SOURCES.txt
@@ -0,0 +1,10 @@
+setup.cfg
+setup.py
+MechanicalSoup.egg-info/PKG-INFO
+MechanicalSoup.egg-info/SOURCES.txt
+MechanicalSoup.egg-info/dependency_links.txt
+MechanicalSoup.egg-info/requires.txt
+MechanicalSoup.egg-info/top_level.txt
+mechanicalsoup/__init__.py
+mechanicalsoup/browser.py
+mechanicalsoup/form.py
\ No newline at end of file
diff --git a/MechanicalSoup.egg-info/dependency_links.txt b/MechanicalSoup.egg-info/dependency_links.txt
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/MechanicalSoup.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
diff --git a/MechanicalSoup.egg-info/requires.txt b/MechanicalSoup.egg-info/requires.txt
new file mode 100644
index 0000000..d53c097
--- /dev/null
+++ b/MechanicalSoup.egg-info/requires.txt
@@ -0,0 +1,3 @@
+requests >= 2.0
+beautifulsoup4
+six >= 1.4
diff --git a/MechanicalSoup.egg-info/top_level.txt b/MechanicalSoup.egg-info/top_level.txt
new file mode 100644
index 0000000..c1ab8a2
--- /dev/null
+++ b/MechanicalSoup.egg-info/top_level.txt
@@ -0,0 +1 @@
+mechanicalsoup
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..798ac2a
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,19 @@
+Metadata-Version: 1.1
+Name: MechanicalSoup
+Version: 0.6.0
+Summary: A Python library for automating interaction with websites
+Home-page: https://github.com/hickford/MechanicalSoup
+Author: UNKNOWN
+Author-email: UNKNOWN
+License: MIT
+Description: UNKNOWN
+Platform: UNKNOWN
+Classifier: License :: OSI Approved :: MIT License
+Classifier: Programming Language :: Python :: 2
+Classifier: Programming Language :: Python :: 2.6
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3
+Classifier: Programming Language :: Python :: 3.2
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: 3.5
diff --git a/mechanicalsoup/__init__.py b/mechanicalsoup/__init__.py
new file mode 100644
index 0000000..05fe111
--- /dev/null
+++ b/mechanicalsoup/__init__.py
@@ -0,0 +1,2 @@
+from .browser import Browser
+from .form import Form
\ No newline at end of file
diff --git a/mechanicalsoup/browser.py b/mechanicalsoup/browser.py
new file mode 100644
index 0000000..15f4768
--- /dev/null
+++ b/mechanicalsoup/browser.py
@@ -0,0 +1,120 @@
+import warnings
+import requests
+import bs4
+from six.moves import urllib
+from six import string_types
+from .form import Form
+
+# see https://www.crummy.com/software/BeautifulSoup/bs4/doc/#specifying-the-parser-to-use
+warnings.filterwarnings("ignore", "No parser was explicitly specified", module="bs4")
+
+class Browser(object):
+
+ def __init__(self, session=None, soup_config=None, requests_adapters=None):
+ self.session = session or requests.Session()
+
+ if requests_adapters is not None:
+ for adaptee, adapter in requests_adapters.items():
+ self.session.mount(adaptee, adapter)
+
+ self.soup_config = soup_config or dict()
+
+ @staticmethod
+ def add_soup(response, soup_config):
+ if "text/html" in response.headers.get("Content-Type", ""):
+ response.soup = bs4.BeautifulSoup(
+ response.content, **soup_config)
+
+ def request(self, *args, **kwargs):
+ response = self.session.request(*args, **kwargs)
+ Browser.add_soup(response, self.soup_config)
+ return response
+
+ def get(self, *args, **kwargs):
+ response = self.session.get(*args, **kwargs)
+ Browser.add_soup(response, self.soup_config)
+ return response
+
+ def post(self, *args, **kwargs):
+ response = self.session.post(*args, **kwargs)
+ Browser.add_soup(response, self.soup_config)
+ return response
+
+ def _build_request(self, form, url=None, **kwargs):
+ method = form.get("method", "get")
+ action = form.get("action")
+ url = urllib.parse.urljoin(url, action)
+ if url is None: # This happens when both `action` and `url` are None.
+ raise ValueError('no URL to submit to')
+
+ # read http://www.w3.org/TR/html5/forms.html
+ data = kwargs.pop("data", dict())
+ files = kwargs.pop("files", dict())
+
+ for input in form.select("input"):
+ name = input.get("name")
+ if not name:
+ continue
+
+ if input.get("type") in ("radio", "checkbox"):
+ if "checked" not in input.attrs:
+ continue
+ value = input.get("value", "on")
+ else:
+ # web browsers use empty string for inputs with missing values
+ value = input.get("value", "")
+
+ if input.get("type") == "checkbox":
+ data.setdefault(name, []).append(value)
+
+ elif input.get("type") == "file":
+ # read http://www.cs.tut.fi/~jkorpela/forms/file.html
+ # in web browsers, file upload only happens if the form"s (or
+ # submit button"s) enctype attribute is set to
+ # "multipart/form-data". we don"t care, simplify.
+ if not value:
+ continue
+ if isinstance(value, string_types):
+ value = open(value, "rb")
+ files[name] = value
+
+ else:
+ data[name] = value
+
+ for textarea in form.select("textarea"):
+ name = textarea.get("name")
+ if not name:
+ continue
+ data[name] = textarea.text
+
+ for select in form.select("select"):
+ name = select.get("name")
+ if not name:
+ continue
+ multiple = "multiple" in select.attrs
+ values = []
+ for i, option in enumerate(select.select("option")):
+ if (i == 0 and not multiple) or "selected" in option.attrs:
+ values.append(option.get("value", ""))
+ if multiple:
+ data[name] = values
+ elif values:
+ data[name] = values[-1]
+
+ if method.lower() == "get":
+ kwargs["params"] = data
+ else:
+ kwargs["data"] = data
+ return requests.Request(method, url, files=files, **kwargs)
+
+ def _prepare_request(self, form, url=None, **kwargs):
+ request = self._build_request(form, url, **kwargs)
+ return self.session.prepare_request(request)
+
+ def submit(self, form, url=None, **kwargs):
+ if isinstance(form, Form):
+ form = form.form
+ request = self._prepare_request(form, url, **kwargs)
+ response = self.session.send(request)
+ Browser.add_soup(response, self.soup_config)
+ return response
diff --git a/mechanicalsoup/form.py b/mechanicalsoup/form.py
new file mode 100644
index 0000000..618b20e
--- /dev/null
+++ b/mechanicalsoup/form.py
@@ -0,0 +1,49 @@
+class Form(object):
+
+ def __init__(self, form):
+ self.form = form
+
+ def input(self, data):
+ for (name, value) in data.items():
+ self.form.find("input", {"name": name})["value"] = value
+
+ def check(self, data):
+ for (name, value) in data.items():
+ if isinstance(value, list):
+ for choice in value:
+ self.form.find("input", {"name": name, "value": choice})[
+ "checked"] = ""
+ else:
+ self.form.find("input", {"name": name, "value": value})[
+ "checked"] = ""
+
+ def textarea(self, data):
+ for (name, value) in data.items():
+ self.form.find("textarea", {"name": name}).insert(0, value)
+
+ def attach(self, data):
+ for (name, value) in data.items():
+ self.form.find("input", {"name": name})["value"] = value
+
+ def choose_submit(self, el):
+ # In a normal web browser, when a input[type=submit] is clicked,
+ # all other submits aren't sent. You can use simulate this as following:
+
+ # page = browser.get(URL)
+ # form_el = page.soup.form
+ # form = Form(form_el)
+ # submit = page.soup.select(SUBMIT_SELECTOR)[0]
+ # form.choose_submit(submit)
+ # url = BASE_DOMAIN + form_el.attrs['action']
+ # return browser.submit(form, url)
+
+ for inp in self.form.select("input"):
+ if inp.get('type') != 'submit':
+ continue
+ if inp == el:
+ continue
+
+ del inp['name']
+ return True
+
+ return False
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..9ea0a41
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,8 @@
+[bdist_wheel]
+universal = 1
+
+[egg_info]
+tag_build =
+tag_date = 0
+tag_svn_revision = 0
+
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..1e28e39
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,45 @@
+from setuptools import setup, find_packages # Always prefer setuptools over distutils
+from codecs import open # To use a consistent encoding
+from os import path
+
+here = path.abspath(path.dirname(__file__))
+
+setup(
+ name='MechanicalSoup',
+
+ # useful: python setup.py sdist bdist_wheel upload
+ version='0.6.0',
+
+ description='A Python library for automating interaction with websites',
+
+ url='https://github.com/hickford/MechanicalSoup',
+
+ license='MIT',
+
+ classifiers=[
+ 'License :: OSI Approved :: MIT License',
+
+ # Specify the Python versions you support here. In particular, ensure
+ # that you indicate whether you support Python 2, Python 3 or both.
+ 'Programming Language :: Python :: 2',
+ 'Programming Language :: Python :: 2.6',
+ 'Programming Language :: Python :: 2.7',
+ 'Programming Language :: Python :: 3',
+ 'Programming Language :: Python :: 3.2',
+ 'Programming Language :: Python :: 3.3',
+ 'Programming Language :: Python :: 3.4',
+ 'Programming Language :: Python :: 3.5',
+ ],
+
+ packages=['mechanicalsoup'],
+
+ # List run-time dependencies here. These will be installed by pip when your
+ # project is installed. For an analysis of "install_requires" vs pip's
+ # requirements files see:
+ # https://packaging.python.org/en/latest/requirements.html
+ install_requires=[
+ 'requests >= 2.0',
+ 'beautifulsoup4',
+ 'six >= 1.4'
+ ],
+)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-mechanicalsoup.git
More information about the Python-modules-commits
mailing list