Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
4dd3ffd2
authored
Feb 27, 2013
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firewall: "if not x" is better than "if x is None" (for maat)
parent
893d31b6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
11 deletions
+11
-11
firewall/fields.py
+1
-1
firewall/fw.py
+3
-3
firewall/models.py
+7
-7
No files found.
firewall/fields.py
View file @
4dd3ffd2
...
...
@@ -37,7 +37,7 @@ add_introspection_rules([], ["firewall\.fields\.MACAddressField"])
def
val_alfanum
(
value
):
"""Validate whether the parameter is a valid alphanumeric value."""
if
alfanum_re
.
match
(
value
)
is
None
:
if
not
alfanum_re
.
match
(
value
)
:
raise
ValidationError
(
_
(
u'
%
s - only letters, numbers, underscores '
'and hyphens are allowed!'
)
%
value
)
...
...
firewall/fw.py
View file @
4dd3ffd2
...
...
@@ -44,7 +44,7 @@ class Firewall:
self
.
RULES_NAT
.
append
(
s
)
def
host2vlan
(
self
,
host
,
rule
):
if
rule
.
foreign_network
is
None
:
if
not
rule
.
foreign_network
:
return
if
self
.
IPV6
and
host
.
ipv6
:
...
...
@@ -77,7 +77,7 @@ class Firewall:
def
fw2vlan
(
self
,
rule
):
if
rule
.
foreign_network
is
None
:
if
not
rule
.
foreign_network
:
return
dport_sport
=
self
.
dportsport
(
rule
)
...
...
@@ -93,7 +93,7 @@ class Firewall:
'LOG_ACC'
if
rule
.
accept
else
'LOG_DROP'
))
def
vlan2vlan
(
self
,
l_vlan
,
rule
):
if
rule
.
foreign_network
is
None
:
if
not
rule
.
foreign_network
:
return
dport_sport
=
self
.
dportsport
(
rule
)
...
...
firewall/models.py
View file @
4dd3ffd2
...
...
@@ -164,7 +164,7 @@ class Host(models.Model):
"address as your own IPv4."
))
self
.
full_clean
()
super
(
Host
,
self
)
.
save
(
*
args
,
**
kwargs
)
if
id
is
None
:
if
not
id
:
Record
(
domain
=
self
.
vlan
.
domain
,
host
=
self
,
type
=
'A'
,
owner
=
self
.
owner
)
.
save
()
if
self
.
ipv6
:
...
...
@@ -270,14 +270,14 @@ class Record(models.Model):
raise
ValidationError
(
_
(
"Can't specify name for "
"A or AAAA records if host is set!"
))
elif
self
.
type
==
'CNAME'
:
if
self
.
name
is
Non
e
:
if
not
self
.
nam
e
:
raise
ValidationError
(
_
(
"Name must be specified for "
"CNAME records if host is set!"
))
if
self
.
address
:
raise
ValidationError
(
_
(
"Can't specify address for "
"CNAME records if host is set!"
))
else
:
# if self.host is None
if
self
.
address
is
None
:
if
not
self
.
address
:
raise
ValidationError
(
_
(
"Address must be specified!"
))
if
self
.
type
==
'A'
:
...
...
@@ -304,10 +304,10 @@ class Record(models.Model):
else
:
return
self
.
name
else
:
# if self.host is None
if
not
self
.
name
:
return
unicode
(
self
.
domain
)
else
:
if
self
.
name
:
return
self
.
name
+
'.'
+
unicode
(
self
.
domain
)
else
:
return
unicode
(
self
.
domain
)
def
__get_address
(
self
):
if
self
.
host
:
...
...
@@ -327,7 +327,7 @@ class Record(models.Model):
address
=
self
.
__get_address
()
if
self
.
host
and
self
.
type
==
'AAAA'
and
not
self
.
host
.
ipv6
:
return
None
elif
address
is
None
or
name
is
Non
e
:
elif
not
address
or
not
nam
e
:
return
None
else
:
return
{
'name'
:
name
,
...
...
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