mozhttpd 0.7__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
@@ -42,5 +42,7 @@ content from the current directory, defines a single API endpoint
42
42
 
43
43
  """
44
44
 
45
- from mozhttpd import MozHttpd, Request, RequestHandler, main
46
- from handlers import json_response
45
+ from .handlers import json_response
46
+ from .mozhttpd import MozHttpd, Request, RequestHandler, main
47
+
48
+ __all__ = ["MozHttpd", "Request", "RequestHandler", "main", "json_response"]
@@ -4,12 +4,17 @@
4
4
 
5
5
  import json
6
6
 
7
+
7
8
  def json_response(func):
8
- """ Translates results of 'func' into a JSON response. """
9
+ """Translates results of 'func' into a JSON response."""
10
+
9
11
  def wrap(*a, **kw):
10
12
  (code, data) = func(*a, **kw)
11
13
  json_data = json.dumps(data)
12
- return (code, { 'Content-type': 'application/json',
13
- '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
+ )
14
19
 
15
20
  return wrap
@@ -4,54 +4,58 @@
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
- import BaseHTTPServer
8
- import SimpleHTTPServer
9
7
  import errno
10
8
  import logging
11
- import threading
9
+ import os
12
10
  import posixpath
11
+ import re
13
12
  import socket
14
13
  import sys
15
- import os
16
- import urllib
17
- import urlparse
18
- import re
19
- import moznetwork
14
+ import threading
20
15
  import time
21
- from SocketServer import ThreadingMixIn
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
+
22
+ import moznetwork
22
23
 
23
- class EasyServer(ThreadingMixIn, BaseHTTPServer.HTTPServer):
24
+
25
+ class EasyServer(ThreadingMixIn, HTTPServer):
24
26
  allow_reuse_address = True
25
27
  acceptable_errors = (errno.EPIPE, errno.ECONNABORTED)
26
28
 
27
29
  def handle_error(self, request, client_address):
28
- error = sys.exc_value
29
-
30
- if ((isinstance(error, socket.error) and
31
- isinstance(error.args, tuple) and
32
- error.args[0] in self.acceptable_errors)
33
- or
34
- (isinstance(error, IOError) and
35
- error.errno in self.acceptable_errors)):
30
+ error = sys.exc_info()[1]
31
+
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):
36
37
  pass # remote hang up before the result is sent
37
38
  else:
38
39
  logging.error(error)
40
+ # The error can be ambiguous just the short description is logged, so we
41
+ # dump a stack trace to discover its origin.
42
+ traceback.print_exc()
39
43
 
40
44
 
41
- class Request(object):
45
+ class Request:
42
46
  """Details of a request."""
43
47
 
44
48
  # attributes from urlsplit that this class also sets
45
- uri_attrs = ('scheme', 'netloc', 'path', 'query', 'fragment')
49
+ uri_attrs = ("scheme", "netloc", "path", "query", "fragment")
46
50
 
47
51
  def __init__(self, uri, headers, rfile=None):
48
52
  self.uri = uri
49
53
  self.headers = headers
50
- parsed = urlparse.urlsplit(uri)
54
+ parsed = urlsplit(uri)
51
55
  for i, attr in enumerate(self.uri_attrs):
52
56
  setattr(self, attr, parsed[i])
53
57
  try:
54
- body_len = int(self.headers.get('Content-length', 0))
58
+ body_len = int(self.headers.get("Content-length", 0))
55
59
  except ValueError:
56
60
  body_len = 0
57
61
  if body_len and rfile:
@@ -60,35 +64,40 @@ class Request(object):
60
64
  self.body = None
61
65
 
62
66
 
63
- class RequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
64
-
65
- docroot = os.getcwd() # current working directory at time of import
67
+ class RequestHandler(SimpleHTTPRequestHandler):
68
+ docroot = os.getcwd() # current working directory at time of import
66
69
  proxy_host_dirs = False
67
70
  request_log = []
68
71
  log_requests = False
69
72
  request = None
70
73
 
71
74
  def __init__(self, *args, **kwargs):
72
- SimpleHTTPServer.SimpleHTTPRequestHandler.__init__(self, *args, **kwargs)
73
- self.extensions_map['.svg'] = 'image/svg+xml'
75
+ SimpleHTTPRequestHandler.__init__(self, *args, **kwargs)
76
+ self.extensions_map[".svg"] = "image/svg+xml"
74
77
 
75
78
  def _try_handler(self, method):
76
79
  if self.log_requests:
77
- self.request_log.append({ 'method': method,
78
- 'path': self.request.path,
79
- 'time': time.time() })
80
-
81
- handlers = [handler for handler in self.urlhandlers
82
- 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
+ ]
83
89
  for handler in handlers:
84
- m = re.match(handler['path'], self.request.path)
90
+ m = re.match(handler["path"], self.request.path)
85
91
  if m:
86
- (response_code, headerdict, data) = \
87
- handler['function'](self.request, *m.groups())
92
+ (response_code, headerdict, data) = handler["function"](
93
+ self.request, *m.groups()
94
+ )
88
95
  self.send_response(response_code)
89
- for (keyword, value) in headerdict.iteritems():
96
+ for keyword, value in headerdict.items():
90
97
  self.send_header(keyword, value)
91
98
  self.end_headers()
99
+ if isinstance(data, str):
100
+ data = data.encode()
92
101
  self.wfile.write(data)
93
102
 
94
103
  return True
@@ -99,74 +108,72 @@ class RequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
99
108
  """Find the on-disk path to serve this request from,
100
109
  using self.path_mappings and self.docroot.
101
110
  Return (url_path, disk_path)."""
102
- path_components = filter(None, self.request.path.split('/'))
103
- for prefix, disk_path in self.path_mappings.iteritems():
104
- prefix_components = 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("/")))
105
114
  if len(path_components) < len(prefix_components):
106
115
  continue
107
- if path_components[:len(prefix_components)] == prefix_components:
108
- return ('/'.join(path_components[len(prefix_components):]),
109
- disk_path)
116
+ if path_components[: len(prefix_components)] == prefix_components:
117
+ return ("/".join(path_components[len(prefix_components) :]), disk_path)
110
118
  if self.docroot:
111
119
  return self.request.path, self.docroot
112
120
  return None
113
121
 
114
122
  def parse_request(self):
115
- retval = SimpleHTTPServer.SimpleHTTPRequestHandler.parse_request(self)
123
+ retval = SimpleHTTPRequestHandler.parse_request(self)
116
124
  self.request = Request(self.path, self.headers, self.rfile)
117
125
  return retval
118
126
 
119
127
  def do_GET(self):
120
- if not self._try_handler('GET'):
128
+ if not self._try_handler("GET"):
121
129
  res = self._find_path()
122
130
  if res:
123
131
  self.path, self.disk_root = res
124
132
  # don't include query string and fragment, and prepend
125
133
  # host directory if required.
126
134
  if self.request.netloc and self.proxy_host_dirs:
127
- self.path = '/' + self.request.netloc + \
128
- self.path
129
- SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
135
+ self.path = "/" + self.request.netloc + self.path
136
+ SimpleHTTPRequestHandler.do_GET(self)
130
137
  else:
131
138
  self.send_response(404)
132
139
  self.end_headers()
133
- self.wfile.write('')
140
+ self.wfile.write(b"")
134
141
 
135
142
  def do_POST(self):
136
143
  # if we don't have a match, we always fall through to 404 (this may
137
144
  # not be "technically" correct if we have a local file at the same
138
145
  # path as the resource but... meh)
139
- if not self._try_handler('POST'):
146
+ if not self._try_handler("POST"):
140
147
  self.send_response(404)
141
148
  self.end_headers()
142
- self.wfile.write('')
149
+ self.wfile.write(b"")
143
150
 
144
151
  def do_DEL(self):
145
152
  # if we don't have a match, we always fall through to 404 (this may
146
153
  # not be "technically" correct if we have a local file at the same
147
154
  # path as the resource but... meh)
148
- if not self._try_handler('DEL'):
155
+ if not self._try_handler("DEL"):
149
156
  self.send_response(404)
150
157
  self.end_headers()
151
- self.wfile.write('')
158
+ self.wfile.write(b"")
152
159
 
153
160
  def translate_path(self, path):
154
161
  # this is taken from SimpleHTTPRequestHandler.translate_path(),
155
162
  # except we serve from self.docroot instead of os.getcwd(), and
156
163
  # parse_request()/do_GET() have already stripped the query string and
157
164
  # fragment and mangled the path for proxying, if required.
158
- path = posixpath.normpath(urllib.unquote(self.path))
159
- words = path.split('/')
160
- words = filter(None, words)
165
+ path = posixpath.normpath(unquote(self.path))
166
+ words = path.split("/")
167
+ words = list(filter(None, words))
161
168
  path = self.disk_root
162
169
  for word in words:
163
170
  drive, word = os.path.splitdrive(word)
164
171
  head, word = os.path.split(word)
165
- if word in (os.curdir, os.pardir): continue
172
+ if word in (os.curdir, os.pardir):
173
+ continue
166
174
  path = os.path.join(path, word)
167
175
  return path
168
176
 
169
-
170
177
  # I found on my local network that calls to this were timing out
171
178
  # I believe all of these calls are from log_message
172
179
  def address_string(self):
@@ -177,7 +184,7 @@ class RequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
177
184
  pass
178
185
 
179
186
 
180
- class MozHttpd(object):
187
+ class MozHttpd:
181
188
  """
182
189
  :param host: Host from which to serve (default 127.0.0.1)
183
190
  :param port: Port from which to serve (default 8888)
@@ -218,14 +225,16 @@ class MozHttpd(object):
218
225
  True.
219
226
  """
220
227
 
221
- def __init__(self,
222
- host="127.0.0.1",
223
- port=0,
224
- docroot=None,
225
- urlhandlers=None,
226
- path_mappings=None,
227
- proxy_host_dirs=False,
228
- 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
+ ):
229
238
  self.host = host
230
239
  self.port = int(port)
231
240
  self.docroot = docroot
@@ -261,7 +270,7 @@ class MozHttpd(object):
261
270
  self.httpd.serve_forever()
262
271
  else:
263
272
  self.server = threading.Thread(target=self.httpd.serve_forever)
264
- self.server.setDaemon(True) # don't hang on exit
273
+ self.server.setDaemon(True) # don't hang on exit
265
274
  self.server.start()
266
275
 
267
276
  def stop(self):
@@ -271,7 +280,7 @@ class MozHttpd(object):
271
280
  If the server is not running, this method has no effect.
272
281
  """
273
282
  if self.httpd:
274
- ### FIXME: There is no shutdown() method in Python 2.4...
283
+ # FIXME: There is no shutdown() method in Python 2.4...
275
284
  try:
276
285
  self.httpd.shutdown()
277
286
  except AttributeError:
@@ -294,36 +303,50 @@ class MozHttpd(object):
294
303
 
295
304
 
296
305
  def main(args=sys.argv[1:]):
297
-
298
306
  # parse command line options
299
- from optparse import OptionParser
300
- parser = OptionParser()
301
- parser.add_option('-p', '--port', dest='port',
302
- type="int", default=8888,
303
- help="port to run the server on [DEFAULT: %default]")
304
- parser.add_option('-H', '--host', dest='host',
305
- default='127.0.0.1',
306
- help="host [DEFAULT: %default]")
307
- parser.add_option('-i', '--external-ip', action="store_true",
308
- dest='external_ip', default=False,
309
- help="find and use external ip for host")
310
- parser.add_option('-d', '--docroot', dest='docroot',
311
- default=os.getcwd(),
312
- help="directory to serve files from [DEFAULT: %default]")
313
- options, args = parser.parse_args(args)
314
- if args:
315
- parser.error("mozhttpd does not take any arguments")
316
-
317
- if options.external_ip:
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
+ )
337
+ args = parser.parse_args()
338
+
339
+ if args.external_ip:
318
340
  host = moznetwork.get_lan_ip()
319
341
  else:
320
- host = options.host
342
+ host = args.host
321
343
 
322
344
  # create the server
323
- server = MozHttpd(host=host, port=options.port, docroot=options.docroot)
345
+ server = MozHttpd(host=host, port=args.port, docroot=args.docroot)
324
346
 
325
- print "Serving '%s' at %s:%s" % (server.docroot, server.host, server.port)
347
+ print("Serving '%s' at %s:%s" % (server.docroot, server.host, server.port))
326
348
  server.start(block=True)
327
349
 
328
- if __name__ == '__main__':
350
+
351
+ if __name__ == "__main__":
329
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
@@ -0,0 +1,2 @@
1
+ moznetwork>=0.24
2
+ mozinfo>=1.0.0
@@ -1,5 +1,4 @@
1
1
  [egg_info]
2
2
  tag_build =
3
3
  tag_date = 0
4
- tag_svn_revision = 0
5
4
 
@@ -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/PKG-INFO DELETED
@@ -1,11 +0,0 @@
1
- Metadata-Version: 1.0
2
- Name: mozhttpd
3
- Version: 0.7
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 http://mozbase.readthedocs.org/
10
- Keywords: mozilla
11
- Platform: UNKNOWN
@@ -1,11 +0,0 @@
1
- Metadata-Version: 1.0
2
- Name: mozhttpd
3
- Version: 0.7
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 http://mozbase.readthedocs.org/
10
- Keywords: mozilla
11
- Platform: UNKNOWN
@@ -1,5 +0,0 @@
1
-
2
- # -*- Entry points: -*-
3
- [console_scripts]
4
- mozhttpd = mozhttpd:main
5
-
@@ -1 +0,0 @@
1
- moznetwork >= 0.24
mozhttpd-0.7/setup.py DELETED
@@ -1,30 +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 setuptools import setup
6
-
7
- PACKAGE_VERSION = '0.7'
8
- deps = ['moznetwork >= 0.24']
9
-
10
- setup(name='mozhttpd',
11
- version=PACKAGE_VERSION,
12
- description="Python webserver intended for use with Mozilla testing",
13
- long_description="see http://mozbase.readthedocs.org/",
14
- classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
15
- keywords='mozilla',
16
- author='Mozilla Automation and Testing Team',
17
- author_email='tools@lists.mozilla.org',
18
- url='https://wiki.mozilla.org/Auto-tools/Projects/Mozbase',
19
- license='MPL',
20
- packages=['mozhttpd'],
21
- include_package_data=True,
22
- zip_safe=False,
23
- install_requires=deps,
24
- entry_points="""
25
- # -*- Entry points: -*-
26
- [console_scripts]
27
- mozhttpd = mozhttpd:main
28
- """,
29
- )
30
-