Skip to content

Commit 7186848

Browse files
committed
Squashed 'tools/third_party/pywebsocket3/' changes from e0d3b5a519..49ae4cba89
49ae4cba89 Fix Sphinx errors 115f9a6f7c Add .gitignore file b1ef45f362 Simplify some uses of os.path.split faf478a045 Add UnitTests for standalone server 3ae555c3fa Update optparse to argparse git-subtree-dir: tools/third_party/pywebsocket3 git-subtree-split: 49ae4cba89a81ddc55a29d7365f2f18434b0ea9f
1 parent 11efe41 commit 7186848

14 files changed

+360
-283
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.pyc
2+
build/
3+
*.egg-info/
4+
dist/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Run this to read the general document:
1010
$ pydoc mod_pywebsocket
1111
```
1212

13-
Please see [Wiki](../../wiki) for more details.
13+
Please see [Wiki](https://github.com/GoogleChromeLabs/pywebsocket3/wiki) for more details.
1414

1515
# INSTALL #
1616

example/echo_client.py

Lines changed: 71 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
import codecs
5252
from hashlib import sha1
5353
import logging
54-
from optparse import OptionParser
54+
import argparse
5555
import os
5656
import random
5757
import re
@@ -602,76 +602,78 @@ def main():
602602
if six.PY2:
603603
sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
604604

605-
parser = OptionParser()
605+
parser = argparse.ArgumentParser()
606606
# We accept --command_line_flag style flags which is the same as Google
607607
# gflags in addition to common --command-line-flag style flags.
608-
parser.add_option('-s',
609-
'--server-host',
610-
'--server_host',
611-
dest='server_host',
612-
type='string',
613-
default='localhost',
614-
help='server host')
615-
parser.add_option('-p',
616-
'--server-port',
617-
'--server_port',
618-
dest='server_port',
619-
type='int',
620-
default=_UNDEFINED_PORT,
621-
help='server port')
622-
parser.add_option('-o',
623-
'--origin',
624-
dest='origin',
625-
type='string',
626-
default=None,
627-
help='origin')
628-
parser.add_option('-r',
629-
'--resource',
630-
dest='resource',
631-
type='string',
632-
default='/echo',
633-
help='resource path')
634-
parser.add_option('-m',
635-
'--message',
636-
dest='message',
637-
type='string',
638-
help=('comma-separated messages to send. '
639-
'%s will force close the connection from server.' %
640-
_GOODBYE_MESSAGE))
641-
parser.add_option('-q',
642-
'--quiet',
643-
dest='verbose',
644-
action='store_false',
645-
default=True,
646-
help='suppress messages')
647-
parser.add_option('-t',
648-
'--tls',
649-
dest='use_tls',
650-
action='store_true',
651-
default=False,
652-
help='use TLS (wss://).')
653-
parser.add_option('-k',
654-
'--socket-timeout',
655-
'--socket_timeout',
656-
dest='socket_timeout',
657-
type='int',
658-
default=_TIMEOUT_SEC,
659-
help='Timeout(sec) for sockets')
660-
parser.add_option('--use-permessage-deflate',
661-
'--use_permessage_deflate',
662-
dest='use_permessage_deflate',
663-
action='store_true',
664-
default=False,
665-
help='Use the permessage-deflate extension.')
666-
parser.add_option('--log-level',
667-
'--log_level',
668-
type='choice',
669-
dest='log_level',
670-
default='warn',
671-
choices=['debug', 'info', 'warn', 'error', 'critical'],
672-
help='Log level.')
673-
674-
(options, unused_args) = parser.parse_args()
608+
parser.add_argument('-s',
609+
'--server-host',
610+
'--server_host',
611+
dest='server_host',
612+
type=six.text_type,
613+
default='localhost',
614+
help='server host')
615+
parser.add_argument('-p',
616+
'--server-port',
617+
'--server_port',
618+
dest='server_port',
619+
type=int,
620+
default=_UNDEFINED_PORT,
621+
help='server port')
622+
parser.add_argument('-o',
623+
'--origin',
624+
dest='origin',
625+
type=six.text_type,
626+
default=None,
627+
help='origin')
628+
parser.add_argument('-r',
629+
'--resource',
630+
dest='resource',
631+
type=six.text_type,
632+
default='/echo',
633+
help='resource path')
634+
parser.add_argument(
635+
'-m',
636+
'--message',
637+
dest='message',
638+
type=six.text_type,
639+
default=u'Hello,\u65e5\u672c',
640+
help=('comma-separated messages to send. '
641+
'%s will force close the connection from server.' %
642+
_GOODBYE_MESSAGE))
643+
parser.add_argument('-q',
644+
'--quiet',
645+
dest='verbose',
646+
action='store_false',
647+
default=True,
648+
help='suppress messages')
649+
parser.add_argument('-t',
650+
'--tls',
651+
dest='use_tls',
652+
action='store_true',
653+
default=False,
654+
help='use TLS (wss://).')
655+
parser.add_argument('-k',
656+
'--socket-timeout',
657+
'--socket_timeout',
658+
dest='socket_timeout',
659+
type=int,
660+
default=_TIMEOUT_SEC,
661+
help='Timeout(sec) for sockets')
662+
parser.add_argument('--use-permessage-deflate',
663+
'--use_permessage_deflate',
664+
dest='use_permessage_deflate',
665+
action='store_true',
666+
default=False,
667+
help='Use the permessage-deflate extension.')
668+
parser.add_argument('--log-level',
669+
'--log_level',
670+
type=six.text_type,
671+
dest='log_level',
672+
default='warn',
673+
choices=['debug', 'info', 'warn', 'error', 'critical'],
674+
help='Log level.')
675+
676+
options = parser.parse_args()
675677

676678
logging.basicConfig(level=logging.getLevelName(options.log_level.upper()))
677679

@@ -682,11 +684,6 @@ def main():
682684
else:
683685
options.server_port = common.DEFAULT_WEB_SOCKET_PORT
684686

685-
# optparse doesn't seem to handle non-ascii default values.
686-
# Set default message here.
687-
if not options.message:
688-
options.message = u'Hello,\u65e5\u672c' # "Japan" in Japanese
689-
690687
EchoClient(options).run()
691688

692689

mod_pywebsocket/extensions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ def set_client_max_window_bits(self, value):
273273
274274
If this method has been called with True and an offer without the
275275
client_max_window_bits extension parameter is received,
276+
276277
- (When processing the permessage-deflate extension) this processor
277278
declines the request.
278279
- (When processing the permessage-compress extension) this processor

mod_pywebsocket/http_header_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def consume_lws(state):
120120

121121

122122
def consume_lwses(state):
123-
"""Consumes *LWS from the head."""
123+
r"""Consumes \*LWS from the head."""
124124

125125
while consume_lws(state):
126126
pass

mod_pywebsocket/request_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def parse_request(self):
208208
return False
209209

210210
if self._options.use_basic_auth:
211-
auth = self.headers.getheader('Authorization')
211+
auth = self.headers.get('Authorization')
212212
if auth != self._options.basic_auth_credential:
213213
self.send_response(401)
214214
self.send_header('WWW-Authenticate',

0 commit comments

Comments
 (0)