Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
webssh
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
郑天保
webssh
Commits
88405edd
Commit
88405edd
authored
Oct 10, 2018
by
Sheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added to_int to utils
parent
de0fda1a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
18 deletions
+24
-18
test_utils.py
tests/test_utils.py
+10
-2
handler.py
webssh/handler.py
+7
-16
utils.py
webssh/utils.py
+7
-0
No files found.
tests/test_utils.py
View file @
88405edd
import
unittest
from
webssh.utils
import
(
is_valid_ipv4_address
,
is_valid_ipv6_address
,
is_valid_port
,
is_valid_hostname
,
to_str
,
to_bytes
)
from
webssh.utils
import
(
is_valid_ipv4_address
,
is_valid_ipv6_address
,
is_valid_port
,
is_valid_hostname
,
to_str
,
to_bytes
,
to_int
)
class
TestUitls
(
unittest
.
TestCase
):
...
...
@@ -18,6 +20,12 @@ class TestUitls(unittest.TestCase):
self
.
assertEqual
(
to_bytes
(
b
),
b
)
self
.
assertEqual
(
to_bytes
(
u
),
b
)
def
test_to_int
(
self
):
self
.
assertEqual
(
to_int
(
''
),
None
)
self
.
assertEqual
(
to_int
(
None
),
None
)
self
.
assertEqual
(
to_int
(
'22'
),
22
)
self
.
assertEqual
(
to_int
(
' 22 '
),
22
)
def
test_is_valid_ipv4_address
(
self
):
self
.
assertFalse
(
is_valid_ipv4_address
(
'127.0.0'
))
self
.
assertFalse
(
is_valid_ipv4_address
(
b
'127.0.0'
))
...
...
webssh/handler.py
View file @
88405edd
...
...
@@ -13,7 +13,7 @@ from tornado.ioloop import IOLoop
from
webssh.settings
import
swallow_http_errors
from
webssh.utils
import
(
is_valid_ipv4_address
,
is_valid_ipv6_address
,
is_valid_port
,
is_valid_hostname
,
to_bytes
,
to_str
,
UnicodeType
is_valid_hostname
,
to_bytes
,
to_str
,
to_int
,
UnicodeType
)
from
webssh.worker
import
Worker
,
recycle_worker
,
workers
...
...
@@ -52,13 +52,9 @@ class MixinHandler(object):
return
# suppose this app doesn't run after an nginx server
if
is_valid_ipv4_address
(
ip
)
or
is_valid_ipv6_address
(
ip
):
try
:
port
=
int
(
port
)
except
(
TypeError
,
ValueError
):
pass
else
:
if
is_valid_port
(
port
):
return
(
ip
,
port
)
port
=
to_int
(
port
)
if
port
and
is_valid_port
(
port
):
return
(
ip
,
port
)
logging
.
warning
(
'Bad nginx configuration.'
)
return
False
...
...
@@ -154,14 +150,9 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler):
def
get_port
(
self
):
value
=
self
.
get_value
(
'port'
)
try
:
port
=
int
(
value
)
except
ValueError
:
pass
else
:
if
is_valid_port
(
port
):
return
port
port
=
to_int
(
value
)
if
port
and
is_valid_port
(
port
):
return
port
raise
InvalidValueError
(
'Invalid port: {}'
.
format
(
value
))
def
lookup_hostname
(
self
,
hostname
,
port
):
...
...
webssh/utils.py
View file @
88405edd
...
...
@@ -23,6 +23,13 @@ def to_bytes(ustr, encoding='utf-8'):
return
ustr
def
to_int
(
string
):
try
:
return
int
(
string
)
except
(
TypeError
,
ValueError
):
pass
def
is_valid_ipv4_address
(
ipstr
):
ipstr
=
to_str
(
ipstr
)
try
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment