mozhttpd 0.7.1__tar.gz → 0.7.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,26 @@
1
+ Metadata-Version: 2.4
2
+ Name: mozhttpd
3
+ Version: 0.7.2
4
+ Summary: Python webserver intended for use with Mozilla testing
5
+ Home-page: https://wiki.mozilla.org/Auto-tools/Projects/Mozbase
6
+ Author: Mozilla Automation and Testing Team
7
+ Author-email: tools@lists.mozilla.org
8
+ License: MPL
9
+ Keywords: mozilla
10
+ Classifier: Programming Language :: Python
11
+ Classifier: Programming Language :: Python :: 3 :: Only
12
+ Requires-Python: >=3.9
13
+ Requires-Dist: moznetwork>=0.24
14
+ Requires-Dist: mozinfo>=1.0.0
15
+ Dynamic: author
16
+ Dynamic: author-email
17
+ Dynamic: classifier
18
+ Dynamic: description
19
+ Dynamic: home-page
20
+ Dynamic: keywords
21
+ Dynamic: license
22
+ Dynamic: requires-dist
23
+ Dynamic: requires-python
24
+ Dynamic: summary
25
+
26
+ see https://firefox-source-docs.mozilla.org/mozbase/index.html
@@ -41,9 +41,8 @@ content from the current directory, defines a single API endpoint
41
41
  httpd.start(block=True)
42
42
 
43
43
  """
44
- from __future__ import absolute_import
45
44
 
46
- from .mozhttpd import MozHttpd, Request, RequestHandler, main
47
45
  from .handlers import json_response
46
+ from .mozhttpd import MozHttpd, Request, RequestHandler, main
48
47
 
49
- __all__ = ['MozHttpd', 'Request', 'RequestHandler', 'main', 'json_response']
48
+ __all__ = ["MozHttpd", "Request", "RequestHandler", "main", "json_response"]
@@ -2,17 +2,19 @@
2
2
  # License, v. 2.0. If a copy of the MPL was not distributed with this file,
3
3
  # You can obtain one at http://mozilla.org/MPL/2.0/.
4
4
 
5
- from __future__ import absolute_import
6
-
7
5
  import json
8
6
 
9
7
 
10
8
  def json_response(func):
11
- """ Translates results of 'func' into a JSON response. """
9
+ """Translates results of 'func' into a JSON response."""
10
+
12
11
  def wrap(*a, **kw):
13
12
  (code, data) = func(*a, **kw)
14
13
  json_data = json.dumps(data)
15
- return (code, {'Content-type': 'application/json',
16
- 'Content-Length': len(json_data)}, json_data)
14
+ return (
15
+ code,
16
+ {"Content-type": "application/json", "Content-Length": len(json_data)},
17
+ json_data,
18
+ )
17
19
 
18
20
  return wrap
@@ -4,31 +4,22 @@
4
4
  # License, v. 2.0. If a copy of the MPL was not distributed with this file,
5
5
  # You can obtain one at http://mozilla.org/MPL/2.0/.
6
6
 
7
- from __future__ import absolute_import, print_function
8
-
9
-
10
7
  import errno
11
8
  import logging
12
- import threading
9
+ import os
13
10
  import posixpath
11
+ import re
14
12
  import socket
15
13
  import sys
16
- import os
17
- import re
18
- import moznetwork
14
+ import threading
19
15
  import time
20
16
  import traceback
17
+ from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser
18
+ from http.server import HTTPServer, SimpleHTTPRequestHandler
19
+ from socketserver import ThreadingMixIn
20
+ from urllib.parse import unquote, urlsplit
21
21
 
22
- from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
23
- from six import iteritems
24
- from six.moves.socketserver import ThreadingMixIn
25
- from six.moves.BaseHTTPServer import HTTPServer
26
-
27
- from six.moves.urllib.parse import (
28
- urlsplit,
29
- unquote,
30
- )
31
- from six.moves.SimpleHTTPServer import SimpleHTTPRequestHandler
22
+ import moznetwork
32
23
 
33
24
 
34
25
  class EasyServer(ThreadingMixIn, HTTPServer):
@@ -38,12 +29,11 @@ class EasyServer(ThreadingMixIn, HTTPServer):
38
29
  def handle_error(self, request, client_address):
39
30
  error = sys.exc_info()[1]
40
31
 
41
- if ((isinstance(error, socket.error) and
42
- isinstance(error.args, tuple) and
43
- error.args[0] in self.acceptable_errors)
44
- or
45
- (isinstance(error, IOError) and
46
- error.errno in self.acceptable_errors)):
32
+ if (
33
+ isinstance(error, socket.error)
34
+ and isinstance(error.args, tuple)
35
+ and error.args[0] in self.acceptable_errors
36
+ ) or (isinstance(error, IOError) and error.errno in self.acceptable_errors):
47
37
  pass # remote hang up before the result is sent
48
38
  else:
49
39
  logging.error(error)
@@ -52,11 +42,11 @@ class EasyServer(ThreadingMixIn, HTTPServer):
52
42
  traceback.print_exc()
53
43
 
54
44
 
55
- class Request(object):
45
+ class Request:
56
46
  """Details of a request."""
57
47
 
58
48
  # attributes from urlsplit that this class also sets
59
- uri_attrs = ('scheme', 'netloc', 'path', 'query', 'fragment')
49
+ uri_attrs = ("scheme", "netloc", "path", "query", "fragment")
60
50
 
61
51
  def __init__(self, uri, headers, rfile=None):
62
52
  self.uri = uri
@@ -65,7 +55,7 @@ class Request(object):
65
55
  for i, attr in enumerate(self.uri_attrs):
66
56
  setattr(self, attr, parsed[i])
67
57
  try:
68
- body_len = int(self.headers.get('Content-length', 0))
58
+ body_len = int(self.headers.get("Content-length", 0))
69
59
  except ValueError:
70
60
  body_len = 0
71
61
  if body_len and rfile:
@@ -75,7 +65,6 @@ class Request(object):
75
65
 
76
66
 
77
67
  class RequestHandler(SimpleHTTPRequestHandler):
78
-
79
68
  docroot = os.getcwd() # current working directory at time of import
80
69
  proxy_host_dirs = False
81
70
  request_log = []
@@ -84,25 +73,31 @@ class RequestHandler(SimpleHTTPRequestHandler):
84
73
 
85
74
  def __init__(self, *args, **kwargs):
86
75
  SimpleHTTPRequestHandler.__init__(self, *args, **kwargs)
87
- self.extensions_map['.svg'] = 'image/svg+xml'
76
+ self.extensions_map[".svg"] = "image/svg+xml"
88
77
 
89
78
  def _try_handler(self, method):
90
79
  if self.log_requests:
91
- self.request_log.append({'method': method,
92
- 'path': self.request.path,
93
- 'time': time.time()})
94
-
95
- handlers = [handler for handler in self.urlhandlers
96
- if handler['method'] == method]
80
+ self.request_log.append({
81
+ "method": method,
82
+ "path": self.request.path,
83
+ "time": time.time(),
84
+ })
85
+
86
+ handlers = [
87
+ handler for handler in self.urlhandlers if handler["method"] == method
88
+ ]
97
89
  for handler in handlers:
98
- m = re.match(handler['path'], self.request.path)
90
+ m = re.match(handler["path"], self.request.path)
99
91
  if m:
100
- (response_code, headerdict, data) = \
101
- handler['function'](self.request, *m.groups())
92
+ (response_code, headerdict, data) = handler["function"](
93
+ self.request, *m.groups()
94
+ )
102
95
  self.send_response(response_code)
103
- for (keyword, value) in iteritems(headerdict):
96
+ for keyword, value in headerdict.items():
104
97
  self.send_header(keyword, value)
105
98
  self.end_headers()
99
+ if isinstance(data, str):
100
+ data = data.encode()
106
101
  self.wfile.write(data)
107
102
 
108
103
  return True
@@ -113,14 +108,13 @@ class RequestHandler(SimpleHTTPRequestHandler):
113
108
  """Find the on-disk path to serve this request from,
114
109
  using self.path_mappings and self.docroot.
115
110
  Return (url_path, disk_path)."""
116
- path_components = list(filter(None, self.request.path.split('/')))
117
- for prefix, disk_path in iteritems(self.path_mappings):
118
- prefix_components = list(filter(None, prefix.split('/')))
111
+ path_components = list(filter(None, self.request.path.split("/")))
112
+ for prefix, disk_path in self.path_mappings.items():
113
+ prefix_components = list(filter(None, prefix.split("/")))
119
114
  if len(path_components) < len(prefix_components):
120
115
  continue
121
- if path_components[:len(prefix_components)] == prefix_components:
122
- return ('/'.join(path_components[len(prefix_components):]),
123
- disk_path)
116
+ if path_components[: len(prefix_components)] == prefix_components:
117
+ return ("/".join(path_components[len(prefix_components) :]), disk_path)
124
118
  if self.docroot:
125
119
  return self.request.path, self.docroot
126
120
  return None
@@ -131,38 +125,37 @@ class RequestHandler(SimpleHTTPRequestHandler):
131
125
  return retval
132
126
 
133
127
  def do_GET(self):
134
- if not self._try_handler('GET'):
128
+ if not self._try_handler("GET"):
135
129
  res = self._find_path()
136
130
  if res:
137
131
  self.path, self.disk_root = res
138
132
  # don't include query string and fragment, and prepend
139
133
  # host directory if required.
140
134
  if self.request.netloc and self.proxy_host_dirs:
141
- self.path = '/' + self.request.netloc + \
142
- self.path
135
+ self.path = "/" + self.request.netloc + self.path
143
136
  SimpleHTTPRequestHandler.do_GET(self)
144
137
  else:
145
138
  self.send_response(404)
146
139
  self.end_headers()
147
- self.wfile.write(b'')
140
+ self.wfile.write(b"")
148
141
 
149
142
  def do_POST(self):
150
143
  # if we don't have a match, we always fall through to 404 (this may
151
144
  # not be "technically" correct if we have a local file at the same
152
145
  # path as the resource but... meh)
153
- if not self._try_handler('POST'):
146
+ if not self._try_handler("POST"):
154
147
  self.send_response(404)
155
148
  self.end_headers()
156
- self.wfile.write(b'')
149
+ self.wfile.write(b"")
157
150
 
158
151
  def do_DEL(self):
159
152
  # if we don't have a match, we always fall through to 404 (this may
160
153
  # not be "technically" correct if we have a local file at the same
161
154
  # path as the resource but... meh)
162
- if not self._try_handler('DEL'):
155
+ if not self._try_handler("DEL"):
163
156
  self.send_response(404)
164
157
  self.end_headers()
165
- self.wfile.write(b'')
158
+ self.wfile.write(b"")
166
159
 
167
160
  def translate_path(self, path):
168
161
  # this is taken from SimpleHTTPRequestHandler.translate_path(),
@@ -170,7 +163,7 @@ class RequestHandler(SimpleHTTPRequestHandler):
170
163
  # parse_request()/do_GET() have already stripped the query string and
171
164
  # fragment and mangled the path for proxying, if required.
172
165
  path = posixpath.normpath(unquote(self.path))
173
- words = path.split('/')
166
+ words = path.split("/")
174
167
  words = list(filter(None, words))
175
168
  path = self.disk_root
176
169
  for word in words:
@@ -191,7 +184,7 @@ class RequestHandler(SimpleHTTPRequestHandler):
191
184
  pass
192
185
 
193
186
 
194
- class MozHttpd(object):
187
+ class MozHttpd:
195
188
  """
196
189
  :param host: Host from which to serve (default 127.0.0.1)
197
190
  :param port: Port from which to serve (default 8888)
@@ -232,14 +225,16 @@ class MozHttpd(object):
232
225
  True.
233
226
  """
234
227
 
235
- def __init__(self,
236
- host="127.0.0.1",
237
- port=0,
238
- docroot=None,
239
- urlhandlers=None,
240
- path_mappings=None,
241
- proxy_host_dirs=False,
242
- log_requests=False):
228
+ def __init__(
229
+ self,
230
+ host="127.0.0.1",
231
+ port=0,
232
+ docroot=None,
233
+ urlhandlers=None,
234
+ path_mappings=None,
235
+ proxy_host_dirs=False,
236
+ log_requests=False,
237
+ ):
243
238
  self.host = host
244
239
  self.port = int(port)
245
240
  self.docroot = docroot
@@ -309,20 +304,36 @@ class MozHttpd(object):
309
304
 
310
305
  def main(args=sys.argv[1:]):
311
306
  # parse command line options
312
- parser = ArgumentParser(description='Basic python webserver.',
313
- formatter_class=ArgumentDefaultsHelpFormatter)
314
- parser.add_argument('-p', '--port', dest='port',
315
- type=int, default=8888,
316
- help="port to run the server on")
317
- parser.add_argument('-H', '--host', dest='host',
318
- default='127.0.0.1',
319
- help="host address")
320
- parser.add_argument('-i', '--external-ip', action="store_true",
321
- dest='external_ip', default=False,
322
- help="find and use external ip for host")
323
- parser.add_argument('-d', '--docroot', dest='docroot',
324
- default=os.getcwd(),
325
- help="directory to serve files from")
307
+ parser = ArgumentParser(
308
+ description="Basic python webserver.",
309
+ formatter_class=ArgumentDefaultsHelpFormatter,
310
+ )
311
+ parser.add_argument(
312
+ "-p",
313
+ "--port",
314
+ dest="port",
315
+ type=int,
316
+ default=8888,
317
+ help="port to run the server on",
318
+ )
319
+ parser.add_argument(
320
+ "-H", "--host", dest="host", default="127.0.0.1", help="host address"
321
+ )
322
+ parser.add_argument(
323
+ "-i",
324
+ "--external-ip",
325
+ action="store_true",
326
+ dest="external_ip",
327
+ default=False,
328
+ help="find and use external ip for host",
329
+ )
330
+ parser.add_argument(
331
+ "-d",
332
+ "--docroot",
333
+ dest="docroot",
334
+ default=os.getcwd(),
335
+ help="directory to serve files from",
336
+ )
326
337
  args = parser.parse_args()
327
338
 
328
339
  if args.external_ip:
@@ -337,5 +348,5 @@ def main(args=sys.argv[1:]):
337
348
  server.start(block=True)
338
349
 
339
350
 
340
- if __name__ == '__main__':
351
+ if __name__ == "__main__":
341
352
  main()
@@ -0,0 +1,26 @@
1
+ Metadata-Version: 2.4
2
+ Name: mozhttpd
3
+ Version: 0.7.2
4
+ Summary: Python webserver intended for use with Mozilla testing
5
+ Home-page: https://wiki.mozilla.org/Auto-tools/Projects/Mozbase
6
+ Author: Mozilla Automation and Testing Team
7
+ Author-email: tools@lists.mozilla.org
8
+ License: MPL
9
+ Keywords: mozilla
10
+ Classifier: Programming Language :: Python
11
+ Classifier: Programming Language :: Python :: 3 :: Only
12
+ Requires-Python: >=3.9
13
+ Requires-Dist: moznetwork>=0.24
14
+ Requires-Dist: mozinfo>=1.0.0
15
+ Dynamic: author
16
+ Dynamic: author-email
17
+ Dynamic: classifier
18
+ Dynamic: description
19
+ Dynamic: home-page
20
+ Dynamic: keywords
21
+ Dynamic: license
22
+ Dynamic: requires-dist
23
+ Dynamic: requires-python
24
+ Dynamic: summary
25
+
26
+ see https://firefox-source-docs.mozilla.org/mozbase/index.html
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ mozhttpd = mozhttpd:main
@@ -1,3 +1,2 @@
1
1
  moznetwork>=0.24
2
2
  mozinfo>=1.0.0
3
- six>=1.10.0
@@ -0,0 +1,35 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this file,
3
+ # You can obtain one at http://mozilla.org/MPL/2.0/.
4
+
5
+ from setuptools import setup
6
+
7
+ PACKAGE_VERSION = "0.7.2"
8
+ deps = ["moznetwork >= 0.24", "mozinfo >= 1.0.0"]
9
+
10
+ setup(
11
+ name="mozhttpd",
12
+ version=PACKAGE_VERSION,
13
+ description="Python webserver intended for use with Mozilla testing",
14
+ long_description="see https://firefox-source-docs.mozilla.org/mozbase/index.html",
15
+ classifiers=[
16
+ "Programming Language :: Python",
17
+ "Programming Language :: Python :: 3 :: Only",
18
+ ],
19
+ # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
20
+ keywords="mozilla",
21
+ author="Mozilla Automation and Testing Team",
22
+ author_email="tools@lists.mozilla.org",
23
+ url="https://wiki.mozilla.org/Auto-tools/Projects/Mozbase",
24
+ license="MPL",
25
+ packages=["mozhttpd"],
26
+ include_package_data=True,
27
+ zip_safe=False,
28
+ install_requires=deps,
29
+ entry_points="""
30
+ # -*- Entry points: -*-
31
+ [console_scripts]
32
+ mozhttpd = mozhttpd:main
33
+ """,
34
+ python_requires=">=3.9",
35
+ )
mozhttpd-0.7.1/PKG-INFO DELETED
@@ -1,13 +0,0 @@
1
- Metadata-Version: 1.1
2
- Name: mozhttpd
3
- Version: 0.7.1
4
- Summary: Python webserver intended for use with Mozilla testing
5
- Home-page: https://wiki.mozilla.org/Auto-tools/Projects/Mozbase
6
- Author: Mozilla Automation and Testing Team
7
- Author-email: tools@lists.mozilla.org
8
- License: MPL
9
- Description: see https://firefox-source-docs.mozilla.org/mozbase/index.html
10
- Keywords: mozilla
11
- Platform: UNKNOWN
12
- Classifier: Programming Language :: Python :: 2.7
13
- Classifier: Programming Language :: Python :: 2 :: Only
@@ -1,13 +0,0 @@
1
- Metadata-Version: 1.1
2
- Name: mozhttpd
3
- Version: 0.7.1
4
- Summary: Python webserver intended for use with Mozilla testing
5
- Home-page: https://wiki.mozilla.org/Auto-tools/Projects/Mozbase
6
- Author: Mozilla Automation and Testing Team
7
- Author-email: tools@lists.mozilla.org
8
- License: MPL
9
- Description: see https://firefox-source-docs.mozilla.org/mozbase/index.html
10
- Keywords: mozilla
11
- Platform: UNKNOWN
12
- Classifier: Programming Language :: Python :: 2.7
13
- Classifier: Programming Language :: Python :: 2 :: Only
@@ -1,5 +0,0 @@
1
-
2
- # -*- Entry points: -*-
3
- [console_scripts]
4
- mozhttpd = mozhttpd:main
5
-
mozhttpd-0.7.1/setup.py DELETED
@@ -1,33 +0,0 @@
1
- # This Source Code Form is subject to the terms of the Mozilla Public
2
- # License, v. 2.0. If a copy of the MPL was not distributed with this file,
3
- # You can obtain one at http://mozilla.org/MPL/2.0/.
4
-
5
- from __future__ import absolute_import
6
-
7
- from setuptools import setup
8
-
9
- PACKAGE_VERSION = '0.7.1'
10
- deps = ['moznetwork >= 0.24', 'mozinfo >= 1.0.0', 'six >= 1.10.0']
11
-
12
- setup(name='mozhttpd',
13
- version=PACKAGE_VERSION,
14
- description="Python webserver intended for use with Mozilla testing",
15
- long_description="see https://firefox-source-docs.mozilla.org/mozbase/index.html",
16
- classifiers=['Programming Language :: Python :: 2.7',
17
- 'Programming Language :: Python :: 2 :: Only'],
18
- # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
19
- keywords='mozilla',
20
- author='Mozilla Automation and Testing Team',
21
- author_email='tools@lists.mozilla.org',
22
- url='https://wiki.mozilla.org/Auto-tools/Projects/Mozbase',
23
- license='MPL',
24
- packages=['mozhttpd'],
25
- include_package_data=True,
26
- zip_safe=False,
27
- install_requires=deps,
28
- entry_points="""
29
- # -*- Entry points: -*-
30
- [console_scripts]
31
- mozhttpd = mozhttpd:main
32
- """,
33
- )
File without changes