Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
Warden
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pavel Valach
Warden
Commits
94d1b721
Commit
94d1b721
authored
9 years ago
by
Pavel Kácha
Browse files
Options
Downloads
Patches
Plain Diff
Python 3 compatibility - imports, str decodes, iterators (thx to Radko Krkos)
parent
808cdaec
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
warden3/warden_client/warden_client.py
+17
-7
17 additions, 7 deletions
warden3/warden_client/warden_client.py
warden3/warden_client/warden_client_examples.py
+1
-2
1 addition, 2 deletions
warden3/warden_client/warden_client_examples.py
with
18 additions
and
9 deletions
warden3/warden_client/warden_client.py
+
17
−
7
View file @
94d1b721
...
...
@@ -5,17 +5,25 @@
# Use of this source is governed by a 3-clause BSD-style license, see LICENSE file.
import
hashlib
# Some Python/ssl versions incorrectly initialize hashes, this helps
import
json
,
httplib
,
ssl
,
socket
,
logging
,
logging
.
handlers
,
time
from
urlparse
import
urlparse
from
urllib
import
urlencode
from
sys
import
stderr
,
exc_info
from
sys
import
stderr
,
exc_info
,
version_info
import
json
,
ssl
,
socket
,
logging
,
logging
.
handlers
,
time
from
traceback
import
format_tb
from
os
import
path
from
operator
import
itemgetter
from
sys
import
version_info
fix_logging_filename
=
str
if
version_info
<
(
2
,
7
)
else
lambda
x
:
x
if
version_info
>
(
3
,
0
):
import
http.client
as
httplib
from
urllib.parse
import
urlparse
from
urllib.parse
import
urlencode
basestring
=
str
else
:
import
httplib
from
urlparse
import
urlparse
from
urllib
import
urlencode
VERSION
=
"
3.0-beta2
"
...
...
@@ -142,6 +150,8 @@ class Error(Exception):
"""
In list or iterable context we
'
re empty
"""
raise
StopIteration
__next__
=
next
def
__bool__
(
self
):
"""
In boolean context we
'
re never True
"""
...
...
@@ -434,13 +444,13 @@ class Client(object):
if
res
.
status
==
httplib
.
OK
:
try
:
data
=
json
.
loads
(
response_data
)
data
=
json
.
loads
(
response_data
.
decode
(
"
utf-8
"
)
)
except
:
data
=
Error
(
method
=
func
,
message
=
"
JSON message parsing failed
"
,
exc
=
exc_info
(),
response
=
response_data
)
else
:
try
:
data
=
json
.
loads
(
response_data
)
data
=
json
.
loads
(
response_data
.
decode
(
"
utf-8
"
)
)
data
[
"
errors
"
]
# trigger exception if not dict or no error key
except
:
data
=
Error
(
method
=
func
,
message
=
"
Generic server HTTP error
"
,
...
...
This diff is collapsed.
Click to expand it.
warden3/warden_client/warden_client_examples.py
+
1
−
2
View file @
94d1b721
...
...
@@ -106,7 +106,7 @@ def gen_random_idea(client_name="cz.example.warden.test"):
"
Size
"
:
46
,
"
Ref
"
:
[
"
cve:CVE-%s-%s
"
%
(
randstr
(
string
.
digits
,
4
),
randstr
())],
"
ContentEncoding
"
:
"
base64
"
,
"
Content
"
:
b64encode
(
randstr
(
maxlen
=
128
*
1024
)
)
"
Content
"
:
b64encode
(
randstr
(
).
encode
(
'
ascii
'
)).
decode
(
"
ascii
"
)
}
],
"
Node
"
:
[
...
...
@@ -181,7 +181,6 @@ def main():
group
=
[]
nogroup
=
[]
ret
=
wclient
.
getEvents
(
count
=
0
,
id
=
0
,
cat
=
cat
,
nocat
=
nocat
,
tag
=
tag
,
notag
=
notag
,
group
=
group
,
nogroup
=
nogroup
)
ret
=
wclient
.
getEvents
(
count
=
10
,
cat
=
cat
,
nocat
=
nocat
,
tag
=
tag
,
notag
=
notag
,
group
=
group
,
nogroup
=
nogroup
)
print
(
"
Time: %f
"
%
(
time
()
-
start
))
print
(
"
Got %i events
"
%
len
(
ret
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment