-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hardware Profile: Now works python2 and python3
New packages required: python-uritools python3-uritools python-mailer python3-mailer python-simplejson python3-simplejson python3-mysqldb # required for bindings too python3-future # required for bindings too
- Loading branch information
Bill Meek
committed
Nov 15, 2019
1 parent
871accb
commit 1df343e
Showing
25 changed files
with
484 additions
and
351 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
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 |
---|---|---|
|
@@ -3,18 +3,18 @@ | |
|
||
#### | ||
# 02/2006 Will Holcomb <[email protected]> | ||
# | ||
# | ||
# This library is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU Lesser General Public | ||
# License as published by the Free Software Foundation; either | ||
# version 2.1 of the License, or (at your option) any later version. | ||
# | ||
# | ||
# This library is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# Lesser General Public License for more details. | ||
# | ||
# 7/26/07 Slightly modified by Brian Schneider | ||
# 7/26/07 Slightly modified by Brian Schneider | ||
# in order to support unicode files ( multipart_encode function ) | ||
""" | ||
Usage: | ||
|
@@ -40,60 +40,63 @@ | |
The main function of this file is a sample which downloads a page and | ||
then uploads it to the W3C validator. | ||
""" | ||
|
||
import urllib | ||
import urllib2 | ||
import mimetools, mimetypes | ||
from __future__ import print_function | ||
|
||
from future import standard_library | ||
standard_library.install_aliases() | ||
from builtins import object | ||
import urllib.request, urllib.error, urllib.parse | ||
from email.generator import _make_boundary | ||
import mimetypes | ||
import os, stat | ||
from cStringIO import StringIO | ||
import sys | ||
from io import StringIO | ||
|
||
class Callable: | ||
class Callable(object): | ||
def __init__(self, anycallable): | ||
self.__call__ = anycallable | ||
|
||
# Controls how sequences are uncoded. If true, elements may be given multiple values by | ||
# assigning a sequence. | ||
doseq = 1 | ||
|
||
class MultipartPostHandler(urllib2.BaseHandler): | ||
handler_order = urllib2.HTTPHandler.handler_order - 10 # needs to run first | ||
class MultipartPostHandler(urllib.request.BaseHandler): | ||
handler_order = urllib.request.HTTPHandler.handler_order - 10 # needs to run first | ||
|
||
def http_request(self, request): | ||
data = request.get_data() | ||
data = request.data | ||
if data is not None and type(data) != str: | ||
v_files = [] | ||
v_vars = [] | ||
try: | ||
for(key, value) in data.items(): | ||
if type(value) == file: | ||
v_files.append((key, value)) | ||
else: | ||
v_vars.append((key, value)) | ||
for(key, value) in list(data.items()): | ||
# 'file' type doesn't exist in python3 and we didn't use it. Removed if: | ||
v_vars.append((key, value)) | ||
except TypeError: | ||
systype, value, traceback = sys.exc_info() | ||
raise TypeError, "not a valid non-string sequence or mapping object", traceback | ||
raise TypeError("not a valid non-string sequence or mapping object", traceback) | ||
|
||
if len(v_files) == 0: | ||
data = urllib.urlencode(v_vars, doseq) | ||
data = urllib.parse.urlencode(v_vars, doseq) | ||
else: | ||
boundary, data = self.multipart_encode(v_vars, v_files) | ||
|
||
contenttype = 'multipart/form-data; boundary=%s' % boundary | ||
if(request.has_header('Content-Type') | ||
and request.get_header('Content-Type').find('multipart/form-data') != 0): | ||
print "Replacing %s with %s" % (request.get_header('content-type'), 'multipart/form-data') | ||
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.data = bytearray(data, 'latin1') | ||
|
||
return request | ||
|
||
def multipart_encode(vars, files, boundary = None, buf = None): | ||
def multipart_encode(self, these_vars, files, boundary = None, buf = None): | ||
if boundary is None: | ||
boundary = mimetools.choose_boundary() | ||
boundary = _make_boundary(os.getuid + os.getpid()) | ||
if buf is None: | ||
buf = StringIO() | ||
for(key, value) in vars: | ||
for(key, value) in these_vars: | ||
buf.write('--%s\r\n' % boundary) | ||
buf.write('Content-Disposition: form-data; name="%s"' % key) | ||
buf.write('\r\n\r\n' + value + '\r\n') | ||
|
@@ -118,15 +121,15 @@ def main(): | |
import tempfile, sys | ||
|
||
validatorURL = "http://validator.w3.org/check" | ||
opener = urllib2.build_opener(MultipartPostHandler) | ||
opener = urllib.request.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() | ||
print(opener.open(validatorURL, params).read()) | ||
os.remove(temp[1]) | ||
|
||
if len(sys.argv[1:]) > 0: | ||
|
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
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
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
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
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
Oops, something went wrong.