[python-MultipartPostHandler2] Initial import (#920778)

Miro Hrončok churchyard at fedoraproject.org
Mon Mar 25 14:17:51 UTC 2013


commit c1638bb3e45596232b4d02f1e69901db0c28cfdb
Author: Miro Hrončok <miro at hroncok.cz>
Date:   Mon Mar 25 15:17:47 2013 +0100

    Initial import (#920778)

 .gitignore                                      |    1 +
 python-MultipartPostHandler2-cut-out-main.patch |   80 +++++++++++++++++
 python-MultipartPostHandler2-python3.patch      |   59 ++++++++++++
 python-MultipartPostHandler2.spec               |  108 +++++++++++++++++++++++
 sources                                         |    1 +
 5 files changed, 249 insertions(+), 0 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index e69de29..ee26a3a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -0,0 +1 @@
+/MultipartPostHandler2-0.1.1.tar.gz
diff --git a/python-MultipartPostHandler2-cut-out-main.patch b/python-MultipartPostHandler2-cut-out-main.patch
new file mode 100644
index 0000000..6d75d8e
--- /dev/null
+++ b/python-MultipartPostHandler2-cut-out-main.patch
@@ -0,0 +1,80 @@
+diff -ruN a/MultipartPostHandler-example.py b/MultipartPostHandler-example.py
+--- a/MultipartPostHandler-example.py	1970-01-01 01:00:00.000000000 +0100
++++ b/MultipartPostHandler-example.py	2013-03-21 19:43:06.265880080 +0100
+@@ -0,0 +1,29 @@
++#!/usr/bin/python
++"""
++  The main function of this file is a sample which downloads a page and
++  then uploads it to the W3C validator.
++"""
++
++def main():
++    import tempfile, sys, os, urllib2, MultipartPostHandler
++
++    validatorURL = "http://validator.w3.org/check"
++    opener = urllib2.build_opener(MultipartPostHandler.MultipartPostHandler)
++
++    def validateFile(url):
++        temp = tempfile.mkstemp(suffix=".html")
++        os.write(temp[0], opener.open(url).read())
++        params = { "ss" : "0",            # show source
++                   "doctype" : "Inline",
++                   "uploaded_file" : open(temp[1], "rb") }
++        print opener.open(validatorURL, params).read()
++        os.remove(temp[1])
++
++    if len(sys.argv[1:]) > 0:
++        for arg in sys.argv[1:]:
++            validateFile(arg)
++    else:
++        validateFile("http://www.google.com")
++
++if __name__=="__main__":
++    main()
+diff -ruN a/MultipartPostHandler.py b/MultipartPostHandler.py
+--- a/MultipartPostHandler.py	2011-06-04 13:54:31.000000000 +0200
++++ b/MultipartPostHandler.py	2013-03-21 20:08:57.948501315 +0100
+@@ -1,4 +1,3 @@
+-#!/usr/bin/python
+ # From http://peerit.blogspot.com/2007/07/multipartposthandler-doesnt-work-for.html
+ 
+ ####
+@@ -35,10 +34,6 @@
+   params = { "username" : "bob", "password" : "riviera",
+              "file" : open("filename", "rb") }
+   opener.open("http://wwww.bobsite.com/upload/", params)
+-
+-Further Example:
+-  The main function of this file is a sample which downloads a page and
+-  then uploads it to the W3C validator.
+ """
+ 
+ import urllib
+@@ -111,27 +106,3 @@
+     multipart_encode = Callable(multipart_encode)
+ 
+     https_request = http_request
+-
+-def main():
+-    import tempfile, sys
+-
+-    validatorURL = "http://validator.w3.org/check"
+-    opener = urllib2.build_opener(MultipartPostHandler)
+-
+-    def validateFile(url):
+-        temp = tempfile.mkstemp(suffix=".html")
+-        os.write(temp[0], opener.open(url).read())
+-        params = { "ss" : "0",            # show source
+-                   "doctype" : "Inline",
+-                   "uploaded_file" : open(temp[1], "rb") }
+-        print opener.open(validatorURL, params).read()
+-        os.remove(temp[1])
+-
+-    if len(sys.argv[1:]) > 0:
+-        for arg in sys.argv[1:]:
+-            validateFile(arg)
+-    else:
+-        validateFile("http://www.google.com")
+-
+-if __name__=="__main__":
+-    main()
diff --git a/python-MultipartPostHandler2-python3.patch b/python-MultipartPostHandler2-python3.patch
new file mode 100644
index 0000000..d6e0108
--- /dev/null
+++ b/python-MultipartPostHandler2-python3.patch
@@ -0,0 +1,59 @@
+diff -ruN a/MultipartPostHandler-example.py b/MultipartPostHandler-example.py
+--- a/MultipartPostHandler-example.py	2013-03-21 20:12:27.959314233 +0100
++++ b/MultipartPostHandler-example.py	2013-03-22 14:02:15.151389848 +0100
+@@ -13,17 +13,19 @@
+     def validateFile(url):
+         temp = tempfile.mkstemp(suffix=".html")
+         os.write(temp[0], opener.open(url).read())
++        # use the encoding of the uploaded page in open().read().decode()
+         params = { "ss" : "0",            # show source
+                    "doctype" : "Inline",
+-                   "uploaded_file" : open(temp[1], "rb") }
+-        print(opener.open(validatorURL, params).read())
++                   "uploaded_file" : open(temp[1], "rb").read().decode('utf-8') }
++        # use the encoding of the validator here
++        print(opener.open(validatorURL, params).read().decode('utf-8'))
+         os.remove(temp[1])
+ 
+     if len(sys.argv[1:]) > 0:
+         for arg in sys.argv[1:]:
+             validateFile(arg)
+     else:
+-        validateFile("http://www.google.com")
++        validateFile("http://www.python.org")
+ 
+ if __name__=="__main__":
+     main()
+diff -ruN a/MultipartPostHandler.py b/MultipartPostHandler.py
+--- a/MultipartPostHandler.py	2013-03-21 20:12:28.001314190 +0100
++++ b/MultipartPostHandler.py	2013-03-22 12:47:39.280527608 +0100
+@@ -38,9 +38,8 @@
+ 
+ import urllib.request, urllib.parse, urllib.error
+ import urllib.request, urllib.error, urllib.parse
+-import mimetools, mimetypes
+-import os, stat
+-from io import StringIO
++import email, mimetypes
++import os, stat, io
+ 
+ class Callable:
+     def __init__(self, anycallable):
+@@ -60,7 +59,7 @@
+             v_vars = []
+             try:
+                  for(key, value) in list(data.items()):
+-                     if type(value) == file:
++                     if type(value) == io.IOBase:
+                          v_files.append((key, value))
+                      else:
+                          v_vars.append((key, value))
+@@ -78,7 +77,7 @@
+                     print("Replacing %s with %s" % (request.get_header('content-type'), 'multipart/form-data'))
+                 request.add_unredirected_header('Content-Type', contenttype)
+ 
+-            request.add_data(data)
++            request.add_data(data.encode('utf-8'))
+         return request
+ 
+     def multipart_encode(vars, files, boundary = None, buffer = None):
diff --git a/python-MultipartPostHandler2.spec b/python-MultipartPostHandler2.spec
new file mode 100644
index 0000000..6fd0b89
--- /dev/null
+++ b/python-MultipartPostHandler2.spec
@@ -0,0 +1,108 @@
+%global with_python3 1
+# comment this out in koji
+%global locally 1
+%global pypi_name MultipartPostHandler2
+Name:           python-%{pypi_name}
+Version:        0.1.1
+Release:        4%{?dist}
+Summary:        A handler for urllib2 to enable multipart form uploading
+# License note in MultipartPostHandler.py
+License:        LGPLv2+
+URL:            http://pypi.python.org/pypi/%{pypi_name}/%{version}
+Source0:        http://pypi.python.org/packages/source/M/%{pypi_name}/%{pypi_name}-%{version}.tar.gz
+
+# Remove the example in main() from the library and keep it separated
+Patch0:         %{name}-cut-out-main.patch
+
+# Several Python3 specific things, needs to be applied after 2to3!
+Patch1:         %{name}-python3.patch
+
+BuildArch:      noarch
+BuildRequires:  python2-devel
+BuildRequires:  python-setuptools
+
+%if 0%{with_python3}
+BuildRequires:  python3-devel
+BuildRequires:  python3-setuptools
+BuildRequires:  python-tools
+%endif
+
+%description
+This is MultipartPostHandler plus a fix for UTF-8 systems.
+Enables the use of multipart/form-data for posting forms.
+
+%if 0%{?with_python3}
+%package -n python3-%{pypi_name}
+Summary:        A handler for urllib2 to enable multipart form uploading
+
+%description -n python3-%{pypi_name}
+This is MultipartPostHandler plus a fix for UTF-8 systems.
+Enables the use of multipart/form-data for posting forms.
+%endif # with_python3
+
+%prep
+%setup -q -n %{pypi_name}-%{version}
+%patch0 -p1
+rm -rf doc # no real doc there
+
+%if 0%{?with_python3}
+rm -rf %{py3dir}
+cp -a . %{py3dir}
+cd %{py3dir}
+find . -name '*.py' | xargs sed -i '1s|^#!%{__python}|#!%{__python3}|'
+2to3 --write --nobackup *.py
+%patch1 -p1
+cd -
+# copy the example back so it can be used in %%doc
+cp %{py3dir}/MultipartPostHandler-example.py python3-MultipartPostHandler-example.py
+%endif # with_python3
+
+%build
+%{__python} setup.py build
+
+%if 0%{?with_python3}
+cd %{py3dir}
+%{__python3} setup.py build
+cd -
+%endif # with_python3
+
+%install
+%if 0%{?with_python3}
+cd %{py3dir}
+%{__python3} setup.py install --skip-build --root %{buildroot}
+cd -
+%endif # with_python3
+
+%{__python} setup.py install --skip-build --root %{buildroot}
+
+%if 0%{?locally}
+%check
+%{__python} MultipartPostHandler-example.py
+%if 0%{?with_python3}
+cd %{py3dir}
+env LANG=en_US.utf8 %{__python3} MultipartPostHandler-example.py
+cd -
+%endif # with_python3
+%endif # locally
+
+%files
+%doc README.txt MultipartPostHandler-example.py
+%{python_sitelib}/*
+%files -n python3-%{pypi_name}
+%doc README.txt python3-MultipartPostHandler-example.py
+%{python3_sitelib}/*
+
+%changelog
+* Fri Mar 22 2013 Miro Hrončok <mhroncok at redhat.com> - 0.1.1-4
+- Dealing with more Pyhton 3 stuff
+
+* Thu Mar 21 2013 Miro Hrončok <mhroncok at redhat.com> - 0.1.1-3
+- Remove the example in main() from the library and keep it separated
+- Added patch witch Python 3 specific things
+
+* Wed Feb 20 2013 Miro Hrončok <mhroncok at redhat.com> - 0.1.1-2
+- Introduced Python 3 subpackage
+
+* Fri Jan 25 2013 Miro Hrončok <mhroncok at redhat.com> - 0.1.1-1
+- Created by pyp2rpm-0.5.1
+- Revised
diff --git a/sources b/sources
index e69de29..cac1b99 100644
--- a/sources
+++ b/sources
@@ -0,0 +1 @@
+e9c4b842ca5741dff9e6ea6cd5f2908e  MultipartPostHandler2-0.1.1.tar.gz


More information about the scm-commits mailing list