Rename module mod_pywebsocket to pywebsocket3 (#33)

* Rename module mod_pywebsocket to pywebsocket3
* Fix test test_unmasked_frame.
diff --git a/MANIFEST.in b/MANIFEST.in
index 1925688..116235d 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -2,5 +2,5 @@
 include MANIFEST.in
 include README
 recursive-include example *.py
-recursive-include mod_pywebsocket *.py
+recursive-include pywebsocket3 *.py
 recursive-include test *.py
diff --git a/README.md b/README.md
index 8684f2c..b46b416 100644
--- a/README.md
+++ b/README.md
@@ -1,13 +1,14 @@
 
 # pywebsocket3 #
 
-The pywebsocket project aims to provide a [WebSocket](https://tools.ietf.org/html/rfc6455) standalone server.
+The pywebsocket3 project aims to provide a [WebSocket](https://tools.ietf.org/html/rfc6455) standalone server.
 
 pywebsocket is intended for **testing** or **experimental** purposes.
 
 Run this to read the general document:
-```
-$ pydoc mod_pywebsocket
+
+```bash
+pydoc pywebsocket3
 ```
 
 Please see [Wiki](https://github.com/GoogleChromeLabs/pywebsocket3/wiki) for more details.
@@ -15,22 +16,27 @@
 # INSTALL #
 
 To install this package to the system, run this:
-```
-$ python setup.py build
-$ sudo python setup.py install
+
+```bash
+python setup.py build
+sudo python setup.py install
 ```
 
 To install this package as a normal user, run this instead:
 
+```bash
+python setup.py build
+python setup.py install --user
 ```
-$ python setup.py build
-$ python setup.py install --user
-```
+
 # LAUNCH #
 
 To use pywebsocket as standalone server, run this to read the document:
+
+```bash
+pydoc pywebsocket3.standalone
 ```
-$ pydoc mod_pywebsocket.standalone
-```
+
 # Disclaimer #
+
 This is not an officially supported Google product
diff --git a/example/abort_handshake_wsh.py b/example/abort_handshake_wsh.py
index 1b719ca..1bad8c0 100644
--- a/example/abort_handshake_wsh.py
+++ b/example/abort_handshake_wsh.py
@@ -28,7 +28,8 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 from __future__ import absolute_import
-from mod_pywebsocket import handshake
+
+from pywebsocket3 import handshake
 
 
 def web_socket_do_extra_handshake(request):
diff --git a/example/abort_wsh.py b/example/abort_wsh.py
index d4c240b..c0495c7 100644
--- a/example/abort_wsh.py
+++ b/example/abort_wsh.py
@@ -28,7 +28,8 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 from __future__ import absolute_import
-from mod_pywebsocket import handshake
+
+from pywebsocket3 import handshake
 
 
 def web_socket_do_extra_handshake(request):
diff --git a/example/bench_wsh.py b/example/bench_wsh.py
index 2df50e7..9ea2f93 100644
--- a/example/bench_wsh.py
+++ b/example/bench_wsh.py
@@ -35,7 +35,9 @@
 """
 
 from __future__ import absolute_import
+
 import time
+
 from six.moves import range
 
 
diff --git a/example/benchmark_helper_wsh.py b/example/benchmark_helper_wsh.py
index fc17533..9ea9f56 100644
--- a/example/benchmark_helper_wsh.py
+++ b/example/benchmark_helper_wsh.py
@@ -27,7 +27,9 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 """Handler for benchmark.html."""
+
 from __future__ import absolute_import
+
 import six
 
 
diff --git a/example/close_wsh.py b/example/close_wsh.py
index 8f0005f..2463bc7 100644
--- a/example/close_wsh.py
+++ b/example/close_wsh.py
@@ -28,10 +28,8 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 from __future__ import absolute_import
-import struct
 
-from mod_pywebsocket import common
-from mod_pywebsocket import stream
+from pywebsocket3 import common
 
 
 def web_socket_do_extra_handshake(request):
diff --git a/example/cookie_wsh.py b/example/cookie_wsh.py
index 8152096..1ca2c84 100644
--- a/example/cookie_wsh.py
+++ b/example/cookie_wsh.py
@@ -27,6 +27,7 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 from __future__ import absolute_import
+
 from six.moves import urllib
 
 
diff --git a/example/echo_client.py b/example/echo_client.py
index 2ed60b3..5063f00 100755
--- a/example/echo_client.py
+++ b/example/echo_client.py
@@ -30,13 +30,13 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 """Simple WebSocket client named echo_client just because of historical reason.
 
-mod_pywebsocket directory must be in PYTHONPATH.
+pywebsocket3 directory must be in PYTHONPATH.
 
 Example Usage:
 
 # server setup
- % cd $pywebsocket
- % PYTHONPATH=$cwd/src python ./mod_pywebsocket/standalone.py -p 8880 \
+ % cd $pywebsocket3
+ % PYTHONPATH=$cwd/src python ./pywebsocket3/standalone.py -p 8880 \
     -d $cwd/src/example
 
 # run client
@@ -47,27 +47,27 @@
 
 from __future__ import absolute_import
 from __future__ import print_function
+
+import argparse
 import base64
 import codecs
-from hashlib import sha1
 import logging
-import argparse
 import os
-import random
 import re
-import six
 import socket
 import ssl
-import struct
 import sys
+from hashlib import sha1
 
-from mod_pywebsocket import common
-from mod_pywebsocket.extensions import PerMessageDeflateExtensionProcessor
-from mod_pywebsocket.extensions import _PerMessageDeflateFramer
-from mod_pywebsocket.extensions import _parse_window_bits
-from mod_pywebsocket.stream import Stream
-from mod_pywebsocket.stream import StreamOptions
-from mod_pywebsocket import util
+import six
+
+from pywebsocket3 import common, util
+from pywebsocket3.extensions import (
+    PerMessageDeflateExtensionProcessor,
+    _PerMessageDeflateFramer,
+    _parse_window_bits,
+)
+from pywebsocket3.stream import Stream, StreamOptions
 
 _TIMEOUT_SEC = 10
 _UNDEFINED_PORT = -1
diff --git a/example/internal_error_wsh.py b/example/internal_error_wsh.py
index 04aa684..cbc0fd2 100644
--- a/example/internal_error_wsh.py
+++ b/example/internal_error_wsh.py
@@ -28,7 +28,8 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 from __future__ import absolute_import
-from mod_pywebsocket import msgutil
+
+from pywebsocket3 import msgutil
 
 
 def web_socket_do_extra_handshake(request):
diff --git a/mod_pywebsocket/__init__.py b/pywebsocket3/__init__.py
similarity index 96%
rename from mod_pywebsocket/__init__.py
rename to pywebsocket3/__init__.py
index 28d5f59..8f4ade0 100644
--- a/mod_pywebsocket/__init__.py
+++ b/pywebsocket3/__init__.py
@@ -28,7 +28,7 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 """ A Standalone WebSocket Server for testing purposes
 
-mod_pywebsocket is an API that provides WebSocket functionalities with
+pywebsocket3 is an API that provides WebSocket functionalities with
 a standalone WebSocket server. It is intended for testing or
 experimental purposes.
 
@@ -37,7 +37,7 @@
 1. Follow standalone server documentation to start running the
 standalone server. It can be read by running the following command:
 
-    $ pydoc mod_pywebsocket.standalone
+    $ pydoc pywebsocket3.standalone
 
 2. Once the standalone server is launched verify it by accessing
 http://localhost[:port]/console.html. Include the port number when
@@ -96,7 +96,7 @@
 
 web_socket_transfer_data is called after the handshake completed
 successfully. A handler can receive/send messages from/to the client
-using request. mod_pywebsocket.msgutil module provides utilities
+using request. pywebsocket3.msgutil module provides utilities
 for data transfer.
 
 You can receive a message by the following statement.
diff --git a/mod_pywebsocket/_stream_exceptions.py b/pywebsocket3/_stream_exceptions.py
similarity index 100%
rename from mod_pywebsocket/_stream_exceptions.py
rename to pywebsocket3/_stream_exceptions.py
diff --git a/mod_pywebsocket/common.py b/pywebsocket3/common.py
similarity index 99%
rename from mod_pywebsocket/common.py
rename to pywebsocket3/common.py
index 9cb11f1..a3321e4 100644
--- a/mod_pywebsocket/common.py
+++ b/pywebsocket3/common.py
@@ -30,7 +30,9 @@
 """
 
 from __future__ import absolute_import
-from mod_pywebsocket import http_header_util
+
+from pywebsocket3 import http_header_util
+
 
 # Additional log level definitions.
 LOGLEVEL_FINE = 9
diff --git a/mod_pywebsocket/dispatch.py b/pywebsocket3/dispatch.py
similarity index 98%
rename from mod_pywebsocket/dispatch.py
rename to pywebsocket3/dispatch.py
index 56cbb3c..fd35cea 100644
--- a/mod_pywebsocket/dispatch.py
+++ b/pywebsocket3/dispatch.py
@@ -30,17 +30,19 @@
 """
 
 from __future__ import absolute_import
+
 import io
-import logging
 import os
 import re
 import traceback
 
-from mod_pywebsocket import common
-from mod_pywebsocket import handshake
-from mod_pywebsocket import msgutil
-from mod_pywebsocket import stream
-from mod_pywebsocket import util
+from pywebsocket3 import (
+    common,
+    handshake,
+    msgutil,
+    stream,
+    util
+)
 
 _SOURCE_PATH_PATTERN = re.compile(r'(?i)_wsh\.py$')
 _SOURCE_SUFFIX = '_wsh.py'
diff --git a/mod_pywebsocket/extensions.py b/pywebsocket3/extensions.py
similarity index 98%
rename from mod_pywebsocket/extensions.py
rename to pywebsocket3/extensions.py
index 314a949..4b5b9e8 100644
--- a/mod_pywebsocket/extensions.py
+++ b/pywebsocket3/extensions.py
@@ -28,9 +28,9 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 from __future__ import absolute_import
-from mod_pywebsocket import common
-from mod_pywebsocket import util
-from mod_pywebsocket.http_header_util import quote_if_necessary
+
+from pywebsocket3 import common, util
+from pywebsocket3.http_header_util import quote_if_necessary
 
 # The list of available server side extension processor classes.
 _available_processors = {}
diff --git a/mod_pywebsocket/fast_masking.i b/pywebsocket3/fast_masking.i
similarity index 100%
rename from mod_pywebsocket/fast_masking.i
rename to pywebsocket3/fast_masking.i
diff --git a/mod_pywebsocket/handshake/__init__.py b/pywebsocket3/handshake/__init__.py
similarity index 93%
rename from mod_pywebsocket/handshake/__init__.py
rename to pywebsocket3/handshake/__init__.py
index 4bc1c67..275e447 100644
--- a/mod_pywebsocket/handshake/__init__.py
+++ b/pywebsocket3/handshake/__init__.py
@@ -32,15 +32,19 @@
 """
 
 from __future__ import absolute_import
+
 import logging
 
-from mod_pywebsocket import common
-from mod_pywebsocket.handshake import hybi
+from pywebsocket3 import common
+from pywebsocket3.handshake import hybi
 # Export AbortedByUserException, HandshakeException, and VersionException
 # symbol from this module.
-from mod_pywebsocket.handshake.base import AbortedByUserException
-from mod_pywebsocket.handshake.base import HandshakeException
-from mod_pywebsocket.handshake.base import VersionException
+from pywebsocket3.handshake.base import (
+    AbortedByUserException,
+    HandshakeException,
+    VersionException
+)
+
 
 _LOGGER = logging.getLogger(__name__)
 
diff --git a/mod_pywebsocket/handshake/base.py b/pywebsocket3/handshake/base.py
similarity index 97%
rename from mod_pywebsocket/handshake/base.py
rename to pywebsocket3/handshake/base.py
index ffad061..561f7b6 100644
--- a/mod_pywebsocket/handshake/base.py
+++ b/pywebsocket3/handshake/base.py
@@ -32,15 +32,12 @@
 
 from __future__ import absolute_import
 
-from mod_pywebsocket import common
-from mod_pywebsocket import http_header_util
-from mod_pywebsocket.extensions import get_extension_processor
-from mod_pywebsocket.stream import StreamOptions
-from mod_pywebsocket.stream import Stream
-from mod_pywebsocket import util
+from pywebsocket3 import common, http_header_util, util
+from pywebsocket3.extensions import get_extension_processor
+from pywebsocket3.stream import Stream, StreamOptions
 
-from six.moves import map
-from six.moves import range
+from six.moves import map, range
+
 
 # Defining aliases for values used frequently.
 _VERSION_LATEST = common.VERSION_HYBI_LATEST
diff --git a/mod_pywebsocket/handshake/hybi.py b/pywebsocket3/handshake/hybi.py
similarity index 95%
rename from mod_pywebsocket/handshake/hybi.py
rename to pywebsocket3/handshake/hybi.py
index cf931db..2e26532 100644
--- a/mod_pywebsocket/handshake/hybi.py
+++ b/pywebsocket3/handshake/hybi.py
@@ -34,17 +34,20 @@
 """
 
 from __future__ import absolute_import
+
 import base64
 import re
 from hashlib import sha1
 
-from mod_pywebsocket import common
-from mod_pywebsocket.handshake.base import get_mandatory_header
-from mod_pywebsocket.handshake.base import HandshakeException
-from mod_pywebsocket.handshake.base import parse_token_list
-from mod_pywebsocket.handshake.base import validate_mandatory_header
-from mod_pywebsocket.handshake.base import HandshakerBase
-from mod_pywebsocket import util
+from pywebsocket3 import common, util
+from pywebsocket3.handshake.base import (
+    get_mandatory_header,
+    HandshakeException,
+    parse_token_list,
+    validate_mandatory_header,
+    HandshakerBase
+)
+
 
 # Used to validate the value in the Sec-WebSocket-Key header strictly. RFC 4648
 # disallows non-zero padding, so the character right before == must be any of
diff --git a/mod_pywebsocket/http_header_util.py b/pywebsocket3/http_header_util.py
similarity index 99%
rename from mod_pywebsocket/http_header_util.py
rename to pywebsocket3/http_header_util.py
index 21fde59..63e698b 100644
--- a/mod_pywebsocket/http_header_util.py
+++ b/pywebsocket3/http_header_util.py
@@ -31,8 +31,10 @@
 """
 
 from __future__ import absolute_import
+
 import six.moves.urllib.parse
 
+
 _SEPARATORS = '()<>@,;:\\"/[]?={} \t'
 
 
diff --git a/mod_pywebsocket/memorizingfile.py b/pywebsocket3/memorizingfile.py
similarity index 99%
rename from mod_pywebsocket/memorizingfile.py
rename to pywebsocket3/memorizingfile.py
index d353967..4ee132f 100644
--- a/mod_pywebsocket/memorizingfile.py
+++ b/pywebsocket3/memorizingfile.py
@@ -34,6 +34,7 @@
 """
 
 from __future__ import absolute_import
+
 import sys
 
 
@@ -61,7 +62,7 @@
 
     def __getattribute__(self, name):
         """Return a file attribute.
-        
+
         Returns the value overridden by this class for some attributes,
         and forwards the call to _file for the other attributes.
         """
diff --git a/mod_pywebsocket/msgutil.py b/pywebsocket3/msgutil.py
similarity index 95%
rename from mod_pywebsocket/msgutil.py
rename to pywebsocket3/msgutil.py
index f58ca78..dd6a6fc 100644
--- a/mod_pywebsocket/msgutil.py
+++ b/pywebsocket3/msgutil.py
@@ -36,14 +36,18 @@
 """
 
 from __future__ import absolute_import
-import six.moves.queue
+
 import threading
 
+import six.moves.queue
+
 # Export Exception symbols from msgutil for backward compatibility
-from mod_pywebsocket._stream_exceptions import ConnectionTerminatedException
-from mod_pywebsocket._stream_exceptions import InvalidFrameException
-from mod_pywebsocket._stream_exceptions import BadOperationException
-from mod_pywebsocket._stream_exceptions import UnsupportedFrameException
+from pywebsocket3._stream_exceptions import (
+    ConnectionTerminatedException,
+    InvalidFrameException,
+    BadOperationException,
+    UnsupportedFrameException
+)
 
 
 # An API for handler to send/receive WebSocket messages.
diff --git a/mod_pywebsocket/request_handler.py b/pywebsocket3/request_handler.py
similarity index 97%
rename from mod_pywebsocket/request_handler.py
rename to pywebsocket3/request_handler.py
index 5e9c875..9d89b47 100644
--- a/mod_pywebsocket/request_handler.py
+++ b/pywebsocket3/request_handler.py
@@ -34,12 +34,14 @@
 from six.moves import CGIHTTPServer
 from six.moves import http_client
 
-from mod_pywebsocket import common
-from mod_pywebsocket import dispatch
-from mod_pywebsocket import handshake
-from mod_pywebsocket import http_header_util
-from mod_pywebsocket import memorizingfile
-from mod_pywebsocket import util
+from pywebsocket3 import (
+    common,
+    dispatch,
+    handshake,
+    http_header_util,
+    memorizingfile,
+    util
+)
 
 # 1024 is practically large enough to contain WebSocket handshake lines.
 _MAX_MEMORIZED_LINES = 1024
diff --git a/mod_pywebsocket/server_util.py b/pywebsocket3/server_util.py
similarity index 97%
rename from mod_pywebsocket/server_util.py
rename to pywebsocket3/server_util.py
index 8f9e273..3bf07f8 100644
--- a/mod_pywebsocket/server_util.py
+++ b/pywebsocket3/server_util.py
@@ -33,8 +33,7 @@
 import threading
 import time
 
-from mod_pywebsocket import common
-from mod_pywebsocket import util
+from pywebsocket3 import common, util
 
 
 def _get_logger_from_class(c):
diff --git a/mod_pywebsocket/standalone.py b/pywebsocket3/standalone.py
similarity index 96%
rename from mod_pywebsocket/standalone.py
rename to pywebsocket3/standalone.py
index bd32158..0c324c4 100755
--- a/mod_pywebsocket/standalone.py
+++ b/pywebsocket3/standalone.py
@@ -38,7 +38,7 @@
 
 Go to the src directory and run
 
-  $ python mod_pywebsocket/standalone.py [-p <ws_port>]
+  $ python pywebsocket3/standalone.py [-p <ws_port>]
                                          [-w <websock_handlers>]
                                          [-d <document_root>]
 
@@ -48,11 +48,11 @@
 
 <websock_handlers> is the path to the root directory of WebSocket handlers.
 If not specified, <document_root> will be used. See __init__.py (or
-run $ pydoc mod_pywebsocket) for how to write WebSocket handlers.
+run $ pydoc pywebsocket3) for how to write WebSocket handlers.
 
 For more detail and other options, run
 
-  $ python mod_pywebsocket/standalone.py --help
+  $ python pywebsocket3/standalone.py --help
 
 or see _build_option_parser method below.
 
@@ -66,7 +66,7 @@
 document root to the directory containing example HTMLs and handlers like this:
 
   $ cd src
-  $ PYTHONPATH=. python mod_pywebsocket/standalone.py -d example
+  $ PYTHONPATH=. python pywebsocket3/standalone.py -d example
 
 to launch pywebsocket with the sample handler and html on port 80. Open
 http://localhost/console.html, click the connect button, type something into
@@ -85,7 +85,7 @@
 
 Example:
 
-  $ PYTHONPATH=. python mod_pywebsocket/standalone.py \
+  $ PYTHONPATH=. python pywebsocket3/standalone.py \
         -d example \
         -p 10443 \
         -t \
@@ -105,7 +105,7 @@
 
 Example:
 
-  $ PYTHONPATH=. python mod_pywebsocket/standalone.py -d example -p 10443 -t \
+  $ PYTHONPATH=. python pywebsocket3/standalone.py -d example -p 10443 -t \
         -c ../test/cert/cert.pem -k ../test/cert/key.pem \
         --tls-client-auth \
         --tls-client-ca=../test/cert/cacert.pem
@@ -154,19 +154,20 @@
 """
 
 from __future__ import absolute_import
-from six.moves import configparser
+
+import argparse
 import base64
 import logging
-import argparse
 import os
-import six
 import sys
 import traceback
 
-from mod_pywebsocket import common
-from mod_pywebsocket import util
-from mod_pywebsocket import server_util
-from mod_pywebsocket.websocket_server import WebSocketServer
+import six
+from six.moves import configparser
+
+from pywebsocket3 import common, server_util, util
+from pywebsocket3.websocket_server import WebSocketServer
+
 
 _DEFAULT_LOG_MAX_BYTES = 1024 * 256
 _DEFAULT_LOG_BACKUP_COUNT = 5
@@ -480,8 +481,8 @@
         server = WebSocketServer(options)
         server.serve_forever()
     except Exception as e:
-        logging.critical('mod_pywebsocket: %s' % e)
-        logging.critical('mod_pywebsocket: %s' % traceback.format_exc())
+        logging.critical('pywebsocket3: %s' % e)
+        logging.critical('pywebsocket3: %s' % traceback.format_exc())
         sys.exit(1)
 
 
diff --git a/mod_pywebsocket/stream.py b/pywebsocket3/stream.py
similarity index 98%
rename from mod_pywebsocket/stream.py
rename to pywebsocket3/stream.py
index 82d1ea6..dd41850 100644
--- a/mod_pywebsocket/stream.py
+++ b/pywebsocket3/stream.py
@@ -33,21 +33,22 @@
 http://tools.ietf.org/html/rfc6455
 """
 
-from collections import deque
 import logging
 import os
 import struct
 import time
-import socket
+from collections import deque
+
 import six
 
-from mod_pywebsocket import common
-from mod_pywebsocket import util
-from mod_pywebsocket._stream_exceptions import BadOperationException
-from mod_pywebsocket._stream_exceptions import ConnectionTerminatedException
-from mod_pywebsocket._stream_exceptions import InvalidFrameException
-from mod_pywebsocket._stream_exceptions import InvalidUTF8Exception
-from mod_pywebsocket._stream_exceptions import UnsupportedFrameException
+from pywebsocket3 import common, util
+from pywebsocket3._stream_exceptions import (
+    BadOperationException,
+    ConnectionTerminatedException,
+    InvalidFrameException,
+    InvalidUTF8Exception,
+    UnsupportedFrameException
+)
 
 _NOOP_MASKER = util.NoopMasker()
 
diff --git a/mod_pywebsocket/util.py b/pywebsocket3/util.py
similarity index 98%
rename from mod_pywebsocket/util.py
rename to pywebsocket3/util.py
index 04006ec..9c25ab8 100644
--- a/mod_pywebsocket/util.py
+++ b/pywebsocket3/util.py
@@ -29,20 +29,18 @@
 """WebSocket utilities."""
 
 from __future__ import absolute_import
-import array
-import errno
+
 import logging
 import os
 import re
-import six
-from six.moves import map
-from six.moves import range
-import socket
 import struct
 import zlib
 
+import six
+from six.moves import map, range
+
 try:
-    from mod_pywebsocket import fast_masking
+    from pywebsocket3 import fast_masking
 except ImportError:
     pass
 
diff --git a/mod_pywebsocket/websocket_server.py b/pywebsocket3/websocket_server.py
similarity index 97%
rename from mod_pywebsocket/websocket_server.py
rename to pywebsocket3/websocket_server.py
index 9f67c9f..e7485ec 100644
--- a/mod_pywebsocket/websocket_server.py
+++ b/pywebsocket3/websocket_server.py
@@ -34,8 +34,7 @@
 """
 
 from __future__ import absolute_import
-from six.moves import BaseHTTPServer
-from six.moves import socketserver
+
 import logging
 import re
 import select
@@ -44,9 +43,10 @@
 import threading
 import traceback
 
-from mod_pywebsocket import dispatch
-from mod_pywebsocket import util
-from mod_pywebsocket.request_handler import WebSocketRequestHandler
+from six.moves import BaseHTTPServer, socketserver
+
+from pywebsocket3 import dispatch, util
+from pywebsocket3.request_handler import WebSocketRequestHandler
 
 
 def _alias_handlers(dispatcher, websock_handlers_map_file):
diff --git a/setup.py b/setup.py
index 12c60d8..4346622 100755
--- a/setup.py
+++ b/setup.py
@@ -28,7 +28,8 @@
 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-"""Set up script for mod_pywebsocket.
+
+"""Set up script for pywebsocket3.
 """
 
 from __future__ import absolute_import
@@ -36,7 +37,7 @@
 from setuptools import setup, Extension
 import sys
 
-_PACKAGE_NAME = 'mod_pywebsocket'
+_PACKAGE_NAME = 'pywebsocket3'
 
 # Build and use a C++ extension for faster masking. SWIG is required.
 _USE_FAST_MASKING = False
@@ -49,8 +50,8 @@
 
 if _USE_FAST_MASKING:
     setup(ext_modules=[
-        Extension('mod_pywebsocket/_fast_masking',
-                  ['mod_pywebsocket/fast_masking.i'],
+        Extension('pywebsocket3/_fast_masking',
+                  ['pywebsocket3/fast_masking.i'],
                   swig_opts=['-c++'])
     ])
 
@@ -58,9 +59,9 @@
     author='Yuzo Fujishima',
     author_email='yuzo@chromium.org',
     description='Standalone WebSocket Server for testing purposes.',
-    long_description=('mod_pywebsocket is a standalone server for '
+    long_description=('pywebsocket3 is a standalone server for '
                       'the WebSocket Protocol (RFC 6455). '
-                      'See mod_pywebsocket/__init__.py for more detail.'),
+                      'See pywebsocket3/__init__.py for more detail.'),
     license='See LICENSE',
     name=_PACKAGE_NAME,
     packages=[_PACKAGE_NAME, _PACKAGE_NAME + '.handshake'],
diff --git a/test/client_for_testing.py b/test/client_for_testing.py
index a45e8f5..6275676 100644
--- a/test/client_for_testing.py
+++ b/test/client_for_testing.py
@@ -33,8 +33,8 @@
 This module contains helper methods for performing handshake, frame
 sending/receiving as a WebSocket client.
 
-This is code for testing mod_pywebsocket. Keep this code independent from
-mod_pywebsocket. Don't import e.g. Stream class for generating frame for
+This is code for testing pywebsocket3. Keep this code independent from
+pywebsocket3. Don't import e.g. Stream class for generating frame for
 testing. Using util.hexify, etc. that are not related to protocol processing
 is allowed.
 
@@ -43,22 +43,20 @@
 """
 
 from __future__ import absolute_import
+
 import base64
 import errno
-import logging
 import os
-import random
 import re
 import socket
 import struct
 import time
 from hashlib import sha1
-from six import iterbytes
-from six import indexbytes
 
-from mod_pywebsocket import common
-from mod_pywebsocket import util
-from mod_pywebsocket.handshake import HandshakeException
+from six import indexbytes, iterbytes
+
+from pywebsocket3 import common, util
+from pywebsocket3.handshake import HandshakeException
 
 DEFAULT_PORT = 80
 DEFAULT_SECURE_PORT = 443
@@ -702,15 +700,15 @@
         try:
             read_data = receive_bytes(self._socket, 1)
         except Exception as e:
-            if str(e).find(
-                    'Connection closed before receiving requested length '
-            ) == 0:
+            if str(e).find('Connection closed before receiving requested length ') == 0:
                 return
+
             try:
-                error_number, message = e
                 for error_name in ['ECONNRESET', 'WSAECONNRESET']:
-                    if (error_name in dir(errno)
-                            and error_number == getattr(errno, error_name)):
+                    if (
+                        error_name in dir(errno) and
+                        e.errno == getattr(errno, error_name)
+                    ):
                         return
             except:
                 raise e
diff --git a/test/mock.py b/test/mock.py
index eeaef52..c460d9b 100644
--- a/test/mock.py
+++ b/test/mock.py
@@ -30,17 +30,14 @@
 """
 
 from __future__ import absolute_import
-import six.moves.queue
-import threading
-import struct
-import six
 
-from mod_pywebsocket import common
-from mod_pywebsocket import util
-from mod_pywebsocket.stream import Stream
-from mod_pywebsocket.stream import StreamOptions
+import six
+import six.moves.queue
 from six.moves import range
 
+from pywebsocket3 import common, util
+from pywebsocket3.stream import Stream, StreamOptions
+
 
 class _MockConnBase(object):
     """Base class of mocks for mod_python.apache.mp_conn.
diff --git a/test/run_all.py b/test/run_all.py
index ea52223..569bdb4 100755
--- a/test/run_all.py
+++ b/test/run_all.py
@@ -31,7 +31,7 @@
 """Run all tests in the same directory.
 
 This suite is expected to be run under pywebsocket's src directory, i.e. the
-directory containing mod_pywebsocket, test, etc.
+directory containing pywebsocket3, test, etc.
 
 To change loggin level, please specify --log-level option.
     python test/run_test.py --log-level debug
@@ -42,14 +42,16 @@
 """
 
 from __future__ import absolute_import
-import logging
+
 import argparse
+import logging
 import os
 import re
-import six
 import sys
 import unittest
 
+import six
+
 _TEST_MODULE_PATTERN = re.compile(r'^(test_.+)\.py$')
 
 
diff --git a/test/set_sys_path.py b/test/set_sys_path.py
index 48d0e11..c35cb6f 100644
--- a/test/set_sys_path.py
+++ b/test/set_sys_path.py
@@ -28,14 +28,15 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 """Configuration for testing.
 
-Test files should import this module before mod_pywebsocket.
+Test files should import this module before pywebsocket3.
 """
 
 from __future__ import absolute_import
+
 import os
 import sys
 
-# Add the parent directory to sys.path to enable importing mod_pywebsocket.
+# Add the parent directory to sys.path to enable importing pywebsocket3.
 sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
 
 # vi:sts=4 sw=4 et
diff --git a/test/test_dispatch.py b/test/test_dispatch.py
index 132dd92..18a39d1 100755
--- a/test/test_dispatch.py
+++ b/test/test_dispatch.py
@@ -31,16 +31,17 @@
 """Tests for dispatch module."""
 
 from __future__ import absolute_import
+
 import os
 import unittest
 
-import set_sys_path  # Update sys.path to locate mod_pywebsocket module.
-
-from mod_pywebsocket import dispatch
-from mod_pywebsocket import handshake
-from test import mock
 from six.moves import zip
 
+import set_sys_path  # Update sys.path to locate pywebsocket3 module.
+from pywebsocket3 import dispatch, handshake
+from test import mock
+
+
 _TEST_HANDLERS_DIR = os.path.join(os.path.dirname(__file__), 'testdata',
                                   'handlers')
 
diff --git a/test/test_endtoend.py b/test/test_endtoend.py
index 2789e4a..9718c6a 100755
--- a/test/test_endtoend.py
+++ b/test/test_endtoend.py
@@ -28,23 +28,23 @@
 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-"""End-to-end tests for pywebsocket. Tests standalone.py.
+"""End-to-end tests for pywebsocket3. Tests standalone.py.
 """
 
 from __future__ import absolute_import
-from six.moves import urllib
+
 import locale
 import logging
 import os
-import signal
 import socket
 import subprocess
 import sys
 import time
 import unittest
 
-import set_sys_path  # Update sys.path to locate mod_pywebsocket module.
+from six.moves import urllib
 
+import set_sys_path  # Update sys.path to locate pywebsocket3 module.
 from test import client_for_testing
 
 # Special message that tells the echo server to start closing handshake
@@ -137,7 +137,7 @@
         self.server_stderr = None
         self.top_dir = os.path.join(os.path.dirname(__file__), '..')
         os.putenv('PYTHONPATH', os.path.pathsep.join(sys.path))
-        self.standalone_command = os.path.join(self.top_dir, 'mod_pywebsocket',
+        self.standalone_command = os.path.join(self.top_dir, 'pywebsocket3',
                                                'standalone.py')
         self.document_root = os.path.join(self.top_dir, 'example')
         s = socket.socket()
diff --git a/test/test_extensions.py b/test/test_extensions.py
index 39a1118..008df24 100755
--- a/test/test_extensions.py
+++ b/test/test_extensions.py
@@ -31,13 +31,12 @@
 """Tests for extensions module."""
 
 from __future__ import absolute_import
+
 import unittest
 import zlib
 
-import set_sys_path  # Update sys.path to locate mod_pywebsocket module.
-
-from mod_pywebsocket import common
-from mod_pywebsocket import extensions
+import set_sys_path  # Update sys.path to locate pywebsocket3 module.
+from pywebsocket3 import common, extensions
 
 
 class ExtensionsTest(unittest.TestCase):
diff --git a/test/test_handshake.py b/test/test_handshake.py
index 7f4acf5..c8e25ab 100755
--- a/test/test_handshake.py
+++ b/test/test_handshake.py
@@ -31,16 +31,17 @@
 """Tests for handshake.base module."""
 
 from __future__ import absolute_import
+
 import unittest
 
-import set_sys_path  # Update sys.path to locate mod_pywebsocket module.
-
-from mod_pywebsocket.common import ExtensionParameter
-from mod_pywebsocket.common import ExtensionParsingException
-from mod_pywebsocket.common import format_extensions
-from mod_pywebsocket.common import parse_extensions
-from mod_pywebsocket.handshake.base import HandshakeException
-from mod_pywebsocket.handshake.base import validate_subprotocol
+import set_sys_path  # Update sys.path to locate pywebsocket3 module.
+from pywebsocket3.common import (
+    ExtensionParameter,
+    ExtensionParsingException,
+    format_extensions,
+    parse_extensions,
+)
+from pywebsocket3.handshake.base import HandshakeException, validate_subprotocol
 
 
 class ValidateSubprotocolTest(unittest.TestCase):
diff --git a/test/test_handshake_hybi.py b/test/test_handshake_hybi.py
index 8c65822..ee63ed4 100755
--- a/test/test_handshake_hybi.py
+++ b/test/test_handshake_hybi.py
@@ -31,15 +31,17 @@
 """Tests for handshake module."""
 
 from __future__ import absolute_import
+
 import unittest
 
-import set_sys_path  # Update sys.path to locate mod_pywebsocket module.
-from mod_pywebsocket import common
-from mod_pywebsocket.handshake.base import AbortedByUserException
-from mod_pywebsocket.handshake.base import HandshakeException
-from mod_pywebsocket.handshake.base import VersionException
-from mod_pywebsocket.handshake.hybi import Handshaker
-
+import set_sys_path  # Update sys.path to locate pywebsocket3 module.
+from pywebsocket3 import common
+from pywebsocket3.handshake.base import (
+    AbortedByUserException,
+    HandshakeException,
+    VersionException,
+)
+from pywebsocket3.handshake.hybi import Handshaker
 from test import mock
 
 
diff --git a/test/test_http_header_util.py b/test/test_http_header_util.py
index f8c8e7a..bd9b9bf 100755
--- a/test/test_http_header_util.py
+++ b/test/test_http_header_util.py
@@ -31,10 +31,11 @@
 """Tests for http_header_util module."""
 
 from __future__ import absolute_import
+
 import unittest
 import sys
 
-from mod_pywebsocket import http_header_util
+from pywebsocket3 import http_header_util
 
 
 class UnitTest(unittest.TestCase):
diff --git a/test/test_memorizingfile.py b/test/test_memorizingfile.py
index f7288c5..4749085 100755
--- a/test/test_memorizingfile.py
+++ b/test/test_memorizingfile.py
@@ -31,12 +31,13 @@
 """Tests for memorizingfile module."""
 
 from __future__ import absolute_import
+
 import unittest
+
 import six
 
-import set_sys_path  # Update sys.path to locate mod_pywebsocket module.
-
-from mod_pywebsocket import memorizingfile
+import set_sys_path  # Update sys.path to locate pywebsocket3 module.
+from pywebsocket3 import memorizingfile
 
 
 class UtilTest(unittest.TestCase):
diff --git a/test/test_mock.py b/test/test_mock.py
index 073873d..df5353b 100755
--- a/test/test_mock.py
+++ b/test/test_mock.py
@@ -31,12 +31,13 @@
 """Tests for mock module."""
 
 from __future__ import absolute_import
-import six.moves.queue
+
 import threading
 import unittest
 
-import set_sys_path  # Update sys.path to locate mod_pywebsocket module.
+import six.moves.queue
 
+import set_sys_path  # Update sys.path to locate pywebsocket3 module.
 from test import mock
 
 
diff --git a/test/test_msgutil.py b/test/test_msgutil.py
index 1122c28..99aa200 100755
--- a/test/test_msgutil.py
+++ b/test/test_msgutil.py
@@ -33,26 +33,26 @@
 from __future__ import absolute_import
 from __future__ import print_function
 from __future__ import division
-import array
-import six.moves.queue
+
 import random
 import struct
 import unittest
 import zlib
 
-import set_sys_path  # Update sys.path to locate mod_pywebsocket module.
-
-from mod_pywebsocket import common
-from mod_pywebsocket.extensions import PerMessageDeflateExtensionProcessor
-from mod_pywebsocket import msgutil
-from mod_pywebsocket.stream import InvalidUTF8Exception
-from mod_pywebsocket.stream import Stream
-from mod_pywebsocket.stream import StreamOptions
-from mod_pywebsocket import util
-from test import mock
+from six import iterbytes
 from six.moves import map
 from six.moves import range
-from six import iterbytes
+import six.moves.queue
+
+import set_sys_path  # Update sys.path to locate pywebsocket3 module.
+from pywebsocket3 import common, msgutil, util
+from pywebsocket3.extensions import PerMessageDeflateExtensionProcessor
+from pywebsocket3.stream import (
+    InvalidUTF8Exception,
+    Stream,
+    StreamOptions,
+)
+from test import mock
 
 # We use one fixed nonce for testing instead of cryptographically secure PRNG.
 _MASKING_NONCE = b'ABCD'
diff --git a/test/test_stream.py b/test/test_stream.py
index 153899d..c165e84 100755
--- a/test/test_stream.py
+++ b/test/test_stream.py
@@ -31,12 +31,11 @@
 """Tests for stream module."""
 
 from __future__ import absolute_import
+
 import unittest
 
-import set_sys_path  # Update sys.path to locate mod_pywebsocket module.
-
-from mod_pywebsocket import common
-from mod_pywebsocket import stream
+import set_sys_path  # Update sys.path to locate pywebsocket3 module.
+from pywebsocket3 import common, stream
 
 
 class StreamTest(unittest.TestCase):
diff --git a/test/test_util.py b/test/test_util.py
index bf4bd32..24c4b5b 100755
--- a/test/test_util.py
+++ b/test/test_util.py
@@ -32,18 +32,16 @@
 
 from __future__ import absolute_import
 from __future__ import print_function
+
 import os
 import random
-import sys
 import unittest
-import struct
 
-import set_sys_path  # Update sys.path to locate mod_pywebsocket module.
-
-from mod_pywebsocket import util
+from six import int2byte, PY3
 from six.moves import range
-from six import PY3
-from six import int2byte
+
+import set_sys_path  # Update sys.path to locate pywebsocket3 module.
+from pywebsocket3 import util
 
 _TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), 'testdata')
 
diff --git a/test/testdata/handlers/abort_by_user_wsh.py b/test/testdata/handlers/abort_by_user_wsh.py
index 63cb541..a6e0831 100644
--- a/test/testdata/handlers/abort_by_user_wsh.py
+++ b/test/testdata/handlers/abort_by_user_wsh.py
@@ -27,7 +27,7 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-from mod_pywebsocket import handshake
+from pywebsocket3 import handshake
 
 
 def web_socket_do_extra_handshake(request):