Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
limbra
limbra
Commits
bdc7651b
Commit
bdc7651b
authored
Jun 14, 2017
by
LE GAC Renaud
Browse files
Update InvenioStore to use the modules requests instead of urllib.
parent
e4010f30
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
12 deletions
+17
-12
modules/invenio_tools/inveniostore.py
modules/invenio_tools/inveniostore.py
+17
-12
No files found.
modules/invenio_tools/inveniostore.py
View file @
bdc7651b
...
...
@@ -5,8 +5,8 @@
import
httplib
import
json
import
re
import
requests
import
time
import
urllib
from
exception
import
CdsException
...
...
@@ -50,11 +50,19 @@ class InvenioStore(object):
self
.
_url
=
None
self
.
_try
=
0
def
interogate
(
self
,
url
):
# start a session, a persistent connection with the server
self
.
_session
=
requests
.
Session
()
def
__del__
(
self
):
# close the session
self
.
_session
.
close
()
def
interogate
(
self
,
url
,
params
=
None
):
"""Interrogate the store using the *URL*.
Args:
url (unicode): URL string
params (dict): parameters to be send with the URL
Returns:
unicode: the HTTP response
...
...
@@ -67,10 +75,9 @@ class InvenioStore(object):
self
.
_url
=
url
self
.
_try
+=
1
fi
=
urllib
.
urlopen
(
url
)
code
=
fi
.
getcode
()
data
=
fi
.
read
()
r
=
self
.
_session
.
get
(
url
,
params
=
params
)
code
=
r
.
status_code
data
=
r
.
content
# the server is busy or return error wait one minute an retry.
# the number of trial is limited to 5
...
...
@@ -166,10 +173,9 @@ class InvenioStore(object):
self
.
_try
=
0
kwargs
[
"jrec"
]
+=
N_IDS
params
=
urllib
.
urlencode
(
kwargs
)
url
=
"http://%s/search?%s"
%
(
self
.
_host
,
params
)
url
=
"http://%s/search"
%
self
.
_host
rep
=
self
.
interogate
(
url
)
rep
=
self
.
interogate
(
url
,
params
=
kwargs
)
# check that the list of ids is well form
# [1291068, 1352722, 1376692, 1454870, 1492807] or [1493820] or []
...
...
@@ -397,10 +403,9 @@ class InvenioStore(object):
kwargs
[
"action_search"
]
=
"Search"
params
=
urllib
.
urlencode
(
kwargs
)
url
=
"http://%s/search?%s"
%
(
self
.
_host
,
params
)
url
=
"http://%s/search"
%
self
.
_host
return
self
.
interogate
(
url
)
return
self
.
interogate
(
url
,
params
=
kwargs
)
def
search_year
(
self
,
collection
,
year
,
of
=
"xm"
,
rg
=
10
,
so
=
"d"
):
"""Search records for given *collection* and for a given *year*.
...
...
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