Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
routersploit
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
czos-dpend
routersploit
Commits
00e9f68b
Commit
00e9f68b
authored
Aug 07, 2016
by
fwkz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding boolify() as validator.
parent
a8c5cb03
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
0 deletions
+73
-0
test_validators.py
routersploit/test/test_validators.py
+55
-0
validators.py
routersploit/validators.py
+18
-0
No files found.
routersploit/test/test_validators.py
View file @
00e9f68b
...
...
@@ -80,6 +80,61 @@ class ValidatorsTest(RoutersploitTestCase):
address
=
"ftp://127.0.0.1"
self
.
assertEqual
(
validators
.
address
(
address
),
"127.0.0.1"
)
def
test_boolify_false_1
(
self
):
value
=
False
self
.
assertEqual
(
validators
.
boolify
(
value
),
False
)
def
test_boolify_false_2
(
self
):
value
=
"No"
self
.
assertEqual
(
validators
.
boolify
(
value
),
False
)
def
test_boolify_false_3
(
self
):
value
=
"n"
self
.
assertEqual
(
validators
.
boolify
(
value
),
False
)
def
test_boolify_false_4
(
self
):
value
=
"OFF"
self
.
assertEqual
(
validators
.
boolify
(
value
),
False
)
def
test_boolify_false_5
(
self
):
value
=
"0"
self
.
assertEqual
(
validators
.
boolify
(
value
),
False
)
def
test_boolify_false_6
(
self
):
value
=
"False"
self
.
assertEqual
(
validators
.
boolify
(
value
),
False
)
def
test_boolify_false_7
(
self
):
value
=
"f"
self
.
assertEqual
(
validators
.
boolify
(
value
),
False
)
def
test_boolify_true_1
(
self
):
value
=
True
self
.
assertEqual
(
validators
.
boolify
(
value
),
True
)
def
test_boolify_true_2
(
self
):
value
=
"Yes"
self
.
assertEqual
(
validators
.
boolify
(
value
),
True
)
def
test_boolify_true_3
(
self
):
value
=
"y"
self
.
assertEqual
(
validators
.
boolify
(
value
),
True
)
def
test_boolify_true_4
(
self
):
value
=
"oN"
self
.
assertEqual
(
validators
.
boolify
(
value
),
True
)
def
test_boolify_true_5
(
self
):
value
=
"1"
self
.
assertEqual
(
validators
.
boolify
(
value
),
True
)
def
test_boolify_true_6
(
self
):
value
=
"tRuE"
self
.
assertEqual
(
validators
.
boolify
(
value
),
True
)
def
test_boolify_true_7
(
self
):
value
=
"t"
self
.
assertEqual
(
validators
.
boolify
(
value
),
True
)
if
__name__
==
'__main__'
:
unittest
.
main
()
routersploit/validators.py
View file @
00e9f68b
import
socket
import
urlparse
from
distutils.util
import
strtobool
from
.exceptions
import
OptionValidationError
...
...
@@ -37,3 +38,20 @@ def ipv4(address):
raise
OptionValidationError
(
"Option have to be valid IP address."
)
return
address
def
boolify
(
value
):
""" Function that will translate common strings into bool values
True -> "True", "t", "yes", "y", "on", "1"
False -> any other string
Objects other than string will be transformed using built-in bool() function.
"""
if
isinstance
(
value
,
basestring
):
try
:
return
bool
(
strtobool
(
value
))
except
ValueError
:
return
False
else
:
return
bool
(
value
)
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