repo
stringlengths 7
55
| path
stringlengths 4
223
| func_name
stringlengths 1
134
| original_string
stringlengths 75
104k
| language
stringclasses 1
value | code
stringlengths 75
104k
| code_tokens
listlengths 19
28.4k
| docstring
stringlengths 1
46.9k
| docstring_tokens
listlengths 1
1.97k
| sha
stringlengths 40
40
| url
stringlengths 87
315
| partition
stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/ext.py
|
_AppState.sets
|
def sets(self):
"""Get list of sets."""
if self.cache:
return self.cache.get(
self.app.config['OAISERVER_CACHE_KEY'])
|
python
|
def sets(self):
"""Get list of sets."""
if self.cache:
return self.cache.get(
self.app.config['OAISERVER_CACHE_KEY'])
|
[
"def",
"sets",
"(",
"self",
")",
":",
"if",
"self",
".",
"cache",
":",
"return",
"self",
".",
"cache",
".",
"get",
"(",
"self",
".",
"app",
".",
"config",
"[",
"'OAISERVER_CACHE_KEY'",
"]",
")"
] |
Get list of sets.
|
[
"Get",
"list",
"of",
"sets",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/ext.py#L33-L37
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/ext.py
|
_AppState.sets
|
def sets(self, values):
"""Set list of sets."""
# if cache server is configured, save sets list
if self.cache:
self.cache.set(self.app.config['OAISERVER_CACHE_KEY'], values)
|
python
|
def sets(self, values):
"""Set list of sets."""
# if cache server is configured, save sets list
if self.cache:
self.cache.set(self.app.config['OAISERVER_CACHE_KEY'], values)
|
[
"def",
"sets",
"(",
"self",
",",
"values",
")",
":",
"# if cache server is configured, save sets list",
"if",
"self",
".",
"cache",
":",
"self",
".",
"cache",
".",
"set",
"(",
"self",
".",
"app",
".",
"config",
"[",
"'OAISERVER_CACHE_KEY'",
"]",
",",
"values",
")"
] |
Set list of sets.
|
[
"Set",
"list",
"of",
"sets",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/ext.py#L40-L44
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/ext.py
|
_AppState.register_signals
|
def register_signals(self):
"""Register signals."""
from .receivers import OAIServerUpdater
# Register Record signals to update OAI informations
self.update_function = OAIServerUpdater()
records_signals.before_record_insert.connect(self.update_function,
weak=False)
records_signals.before_record_update.connect(self.update_function,
weak=False)
if self.app.config['OAISERVER_REGISTER_SET_SIGNALS']:
self.register_signals_oaiset()
|
python
|
def register_signals(self):
"""Register signals."""
from .receivers import OAIServerUpdater
# Register Record signals to update OAI informations
self.update_function = OAIServerUpdater()
records_signals.before_record_insert.connect(self.update_function,
weak=False)
records_signals.before_record_update.connect(self.update_function,
weak=False)
if self.app.config['OAISERVER_REGISTER_SET_SIGNALS']:
self.register_signals_oaiset()
|
[
"def",
"register_signals",
"(",
"self",
")",
":",
"from",
".",
"receivers",
"import",
"OAIServerUpdater",
"# Register Record signals to update OAI informations",
"self",
".",
"update_function",
"=",
"OAIServerUpdater",
"(",
")",
"records_signals",
".",
"before_record_insert",
".",
"connect",
"(",
"self",
".",
"update_function",
",",
"weak",
"=",
"False",
")",
"records_signals",
".",
"before_record_update",
".",
"connect",
"(",
"self",
".",
"update_function",
",",
"weak",
"=",
"False",
")",
"if",
"self",
".",
"app",
".",
"config",
"[",
"'OAISERVER_REGISTER_SET_SIGNALS'",
"]",
":",
"self",
".",
"register_signals_oaiset",
"(",
")"
] |
Register signals.
|
[
"Register",
"signals",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/ext.py#L46-L56
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/ext.py
|
_AppState.register_signals_oaiset
|
def register_signals_oaiset(self):
"""Register OAISet signals to update records."""
from .models import OAISet
from .receivers import after_insert_oai_set, \
after_update_oai_set, after_delete_oai_set
listen(OAISet, 'after_insert', after_insert_oai_set)
listen(OAISet, 'after_update', after_update_oai_set)
listen(OAISet, 'after_delete', after_delete_oai_set)
|
python
|
def register_signals_oaiset(self):
"""Register OAISet signals to update records."""
from .models import OAISet
from .receivers import after_insert_oai_set, \
after_update_oai_set, after_delete_oai_set
listen(OAISet, 'after_insert', after_insert_oai_set)
listen(OAISet, 'after_update', after_update_oai_set)
listen(OAISet, 'after_delete', after_delete_oai_set)
|
[
"def",
"register_signals_oaiset",
"(",
"self",
")",
":",
"from",
".",
"models",
"import",
"OAISet",
"from",
".",
"receivers",
"import",
"after_insert_oai_set",
",",
"after_update_oai_set",
",",
"after_delete_oai_set",
"listen",
"(",
"OAISet",
",",
"'after_insert'",
",",
"after_insert_oai_set",
")",
"listen",
"(",
"OAISet",
",",
"'after_update'",
",",
"after_update_oai_set",
")",
"listen",
"(",
"OAISet",
",",
"'after_delete'",
",",
"after_delete_oai_set",
")"
] |
Register OAISet signals to update records.
|
[
"Register",
"OAISet",
"signals",
"to",
"update",
"records",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/ext.py#L58-L65
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/ext.py
|
_AppState.unregister_signals
|
def unregister_signals(self):
"""Unregister signals."""
# Unregister Record signals
if hasattr(self, 'update_function'):
records_signals.before_record_insert.disconnect(
self.update_function)
records_signals.before_record_update.disconnect(
self.update_function)
self.unregister_signals_oaiset()
|
python
|
def unregister_signals(self):
"""Unregister signals."""
# Unregister Record signals
if hasattr(self, 'update_function'):
records_signals.before_record_insert.disconnect(
self.update_function)
records_signals.before_record_update.disconnect(
self.update_function)
self.unregister_signals_oaiset()
|
[
"def",
"unregister_signals",
"(",
"self",
")",
":",
"# Unregister Record signals",
"if",
"hasattr",
"(",
"self",
",",
"'update_function'",
")",
":",
"records_signals",
".",
"before_record_insert",
".",
"disconnect",
"(",
"self",
".",
"update_function",
")",
"records_signals",
".",
"before_record_update",
".",
"disconnect",
"(",
"self",
".",
"update_function",
")",
"self",
".",
"unregister_signals_oaiset",
"(",
")"
] |
Unregister signals.
|
[
"Unregister",
"signals",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/ext.py#L67-L75
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/ext.py
|
_AppState.unregister_signals_oaiset
|
def unregister_signals_oaiset(self):
"""Unregister signals oaiset."""
from .models import OAISet
from .receivers import after_insert_oai_set, \
after_update_oai_set, after_delete_oai_set
if contains(OAISet, 'after_insert', after_insert_oai_set):
remove(OAISet, 'after_insert', after_insert_oai_set)
remove(OAISet, 'after_update', after_update_oai_set)
remove(OAISet, 'after_delete', after_delete_oai_set)
|
python
|
def unregister_signals_oaiset(self):
"""Unregister signals oaiset."""
from .models import OAISet
from .receivers import after_insert_oai_set, \
after_update_oai_set, after_delete_oai_set
if contains(OAISet, 'after_insert', after_insert_oai_set):
remove(OAISet, 'after_insert', after_insert_oai_set)
remove(OAISet, 'after_update', after_update_oai_set)
remove(OAISet, 'after_delete', after_delete_oai_set)
|
[
"def",
"unregister_signals_oaiset",
"(",
"self",
")",
":",
"from",
".",
"models",
"import",
"OAISet",
"from",
".",
"receivers",
"import",
"after_insert_oai_set",
",",
"after_update_oai_set",
",",
"after_delete_oai_set",
"if",
"contains",
"(",
"OAISet",
",",
"'after_insert'",
",",
"after_insert_oai_set",
")",
":",
"remove",
"(",
"OAISet",
",",
"'after_insert'",
",",
"after_insert_oai_set",
")",
"remove",
"(",
"OAISet",
",",
"'after_update'",
",",
"after_update_oai_set",
")",
"remove",
"(",
"OAISet",
",",
"'after_delete'",
",",
"after_delete_oai_set",
")"
] |
Unregister signals oaiset.
|
[
"Unregister",
"signals",
"oaiset",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/ext.py#L77-L85
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/ext.py
|
InvenioOAIServer.init_config
|
def init_config(self, app):
"""Initialize configuration.
:param app: An instance of :class:`flask.Flask`.
"""
app.config.setdefault(
'OAISERVER_BASE_TEMPLATE',
app.config.get('BASE_TEMPLATE',
'invenio_oaiserver/base.html'))
app.config.setdefault(
'OAISERVER_REPOSITORY_NAME',
app.config.get('THEME_SITENAME',
'Invenio-OAIServer'))
# warn user if ID_PREFIX is not set
if 'OAISERVER_ID_PREFIX' not in app.config:
import socket
import warnings
app.config.setdefault(
'OAISERVER_ID_PREFIX',
'oai:{0}:recid/'.format(socket.gethostname()))
warnings.warn(
"""Please specify the OAISERVER_ID_PREFIX configuration."""
"""default value is: {0}""".format(
app.config.get('OAISERVER_ID_PREFIX')))
for k in dir(config):
if k.startswith('OAISERVER_'):
app.config.setdefault(k, getattr(config, k))
|
python
|
def init_config(self, app):
"""Initialize configuration.
:param app: An instance of :class:`flask.Flask`.
"""
app.config.setdefault(
'OAISERVER_BASE_TEMPLATE',
app.config.get('BASE_TEMPLATE',
'invenio_oaiserver/base.html'))
app.config.setdefault(
'OAISERVER_REPOSITORY_NAME',
app.config.get('THEME_SITENAME',
'Invenio-OAIServer'))
# warn user if ID_PREFIX is not set
if 'OAISERVER_ID_PREFIX' not in app.config:
import socket
import warnings
app.config.setdefault(
'OAISERVER_ID_PREFIX',
'oai:{0}:recid/'.format(socket.gethostname()))
warnings.warn(
"""Please specify the OAISERVER_ID_PREFIX configuration."""
"""default value is: {0}""".format(
app.config.get('OAISERVER_ID_PREFIX')))
for k in dir(config):
if k.startswith('OAISERVER_'):
app.config.setdefault(k, getattr(config, k))
|
[
"def",
"init_config",
"(",
"self",
",",
"app",
")",
":",
"app",
".",
"config",
".",
"setdefault",
"(",
"'OAISERVER_BASE_TEMPLATE'",
",",
"app",
".",
"config",
".",
"get",
"(",
"'BASE_TEMPLATE'",
",",
"'invenio_oaiserver/base.html'",
")",
")",
"app",
".",
"config",
".",
"setdefault",
"(",
"'OAISERVER_REPOSITORY_NAME'",
",",
"app",
".",
"config",
".",
"get",
"(",
"'THEME_SITENAME'",
",",
"'Invenio-OAIServer'",
")",
")",
"# warn user if ID_PREFIX is not set",
"if",
"'OAISERVER_ID_PREFIX'",
"not",
"in",
"app",
".",
"config",
":",
"import",
"socket",
"import",
"warnings",
"app",
".",
"config",
".",
"setdefault",
"(",
"'OAISERVER_ID_PREFIX'",
",",
"'oai:{0}:recid/'",
".",
"format",
"(",
"socket",
".",
"gethostname",
"(",
")",
")",
")",
"warnings",
".",
"warn",
"(",
"\"\"\"Please specify the OAISERVER_ID_PREFIX configuration.\"\"\"",
"\"\"\"default value is: {0}\"\"\"",
".",
"format",
"(",
"app",
".",
"config",
".",
"get",
"(",
"'OAISERVER_ID_PREFIX'",
")",
")",
")",
"for",
"k",
"in",
"dir",
"(",
"config",
")",
":",
"if",
"k",
".",
"startswith",
"(",
"'OAISERVER_'",
")",
":",
"app",
".",
"config",
".",
"setdefault",
"(",
"k",
",",
"getattr",
"(",
"config",
",",
"k",
")",
")"
] |
Initialize configuration.
:param app: An instance of :class:`flask.Flask`.
|
[
"Initialize",
"configuration",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/ext.py#L108-L138
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
extract_params
|
def extract_params(params):
"""
Extracts the values of a set of parameters, recursing into nested dictionaries.
"""
values = []
if isinstance(params, dict):
for key, value in params.items():
values.extend(extract_params(value))
elif isinstance(params, list):
for value in params:
values.extend(extract_params(value))
else:
values.append(params)
return values
|
python
|
def extract_params(params):
"""
Extracts the values of a set of parameters, recursing into nested dictionaries.
"""
values = []
if isinstance(params, dict):
for key, value in params.items():
values.extend(extract_params(value))
elif isinstance(params, list):
for value in params:
values.extend(extract_params(value))
else:
values.append(params)
return values
|
[
"def",
"extract_params",
"(",
"params",
")",
":",
"values",
"=",
"[",
"]",
"if",
"isinstance",
"(",
"params",
",",
"dict",
")",
":",
"for",
"key",
",",
"value",
"in",
"params",
".",
"items",
"(",
")",
":",
"values",
".",
"extend",
"(",
"extract_params",
"(",
"value",
")",
")",
"elif",
"isinstance",
"(",
"params",
",",
"list",
")",
":",
"for",
"value",
"in",
"params",
":",
"values",
".",
"extend",
"(",
"extract_params",
"(",
"value",
")",
")",
"else",
":",
"values",
".",
"append",
"(",
"params",
")",
"return",
"values"
] |
Extracts the values of a set of parameters, recursing into nested dictionaries.
|
[
"Extracts",
"the",
"values",
"of",
"a",
"set",
"of",
"parameters",
"recursing",
"into",
"nested",
"dictionaries",
"."
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L11-L24
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
get_signature_string
|
def get_signature_string(params, secret):
"""
Returns the unhashed signature string (secret + sorted list of param values) for an API call.
@param params: dictionary values to generate signature string
@param secret: secret string
"""
str_list = [str(item) for item in extract_params(params)]
str_list.sort()
return (secret + ''.join(str_list)).encode('utf-8')
|
python
|
def get_signature_string(params, secret):
"""
Returns the unhashed signature string (secret + sorted list of param values) for an API call.
@param params: dictionary values to generate signature string
@param secret: secret string
"""
str_list = [str(item) for item in extract_params(params)]
str_list.sort()
return (secret + ''.join(str_list)).encode('utf-8')
|
[
"def",
"get_signature_string",
"(",
"params",
",",
"secret",
")",
":",
"str_list",
"=",
"[",
"str",
"(",
"item",
")",
"for",
"item",
"in",
"extract_params",
"(",
"params",
")",
"]",
"str_list",
".",
"sort",
"(",
")",
"return",
"(",
"secret",
"+",
"''",
".",
"join",
"(",
"str_list",
")",
")",
".",
"encode",
"(",
"'utf-8'",
")"
] |
Returns the unhashed signature string (secret + sorted list of param values) for an API call.
@param params: dictionary values to generate signature string
@param secret: secret string
|
[
"Returns",
"the",
"unhashed",
"signature",
"string",
"(",
"secret",
"+",
"sorted",
"list",
"of",
"param",
"values",
")",
"for",
"an",
"API",
"call",
"."
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L26-L34
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
SailthruClient.send
|
def send(self, template, email, _vars=None, options=None, schedule_time=None, limit=None):
"""
Remotely send an email template to a single email address.
http://docs.sailthru.com/api/send
@param template: template string
@param email: Email value
@param _vars: a key/value hash of the replacement vars to use in the send. Each var may be referenced as {varname} within the template itself
@param options: optional dictionary to include replyto and/or test keys
@param limit: optional dictionary to name, time, and handle conflicts of limits
@param schedule_time: do not send the email immediately, but at some point in the future. Any date recognized by PHP's strtotime function is valid, but be sure to specify timezone or use a UTC time to avoid confusion
"""
_vars = _vars or {}
options = options or {}
data = {'template': template,
'email': email,
'vars': _vars,
'options': options.copy()}
if limit:
data['limit'] = limit.copy()
if schedule_time is not None:
data['schedule_time'] = schedule_time
return self.api_post('send', data)
|
python
|
def send(self, template, email, _vars=None, options=None, schedule_time=None, limit=None):
"""
Remotely send an email template to a single email address.
http://docs.sailthru.com/api/send
@param template: template string
@param email: Email value
@param _vars: a key/value hash of the replacement vars to use in the send. Each var may be referenced as {varname} within the template itself
@param options: optional dictionary to include replyto and/or test keys
@param limit: optional dictionary to name, time, and handle conflicts of limits
@param schedule_time: do not send the email immediately, but at some point in the future. Any date recognized by PHP's strtotime function is valid, but be sure to specify timezone or use a UTC time to avoid confusion
"""
_vars = _vars or {}
options = options or {}
data = {'template': template,
'email': email,
'vars': _vars,
'options': options.copy()}
if limit:
data['limit'] = limit.copy()
if schedule_time is not None:
data['schedule_time'] = schedule_time
return self.api_post('send', data)
|
[
"def",
"send",
"(",
"self",
",",
"template",
",",
"email",
",",
"_vars",
"=",
"None",
",",
"options",
"=",
"None",
",",
"schedule_time",
"=",
"None",
",",
"limit",
"=",
"None",
")",
":",
"_vars",
"=",
"_vars",
"or",
"{",
"}",
"options",
"=",
"options",
"or",
"{",
"}",
"data",
"=",
"{",
"'template'",
":",
"template",
",",
"'email'",
":",
"email",
",",
"'vars'",
":",
"_vars",
",",
"'options'",
":",
"options",
".",
"copy",
"(",
")",
"}",
"if",
"limit",
":",
"data",
"[",
"'limit'",
"]",
"=",
"limit",
".",
"copy",
"(",
")",
"if",
"schedule_time",
"is",
"not",
"None",
":",
"data",
"[",
"'schedule_time'",
"]",
"=",
"schedule_time",
"return",
"self",
".",
"api_post",
"(",
"'send'",
",",
"data",
")"
] |
Remotely send an email template to a single email address.
http://docs.sailthru.com/api/send
@param template: template string
@param email: Email value
@param _vars: a key/value hash of the replacement vars to use in the send. Each var may be referenced as {varname} within the template itself
@param options: optional dictionary to include replyto and/or test keys
@param limit: optional dictionary to name, time, and handle conflicts of limits
@param schedule_time: do not send the email immediately, but at some point in the future. Any date recognized by PHP's strtotime function is valid, but be sure to specify timezone or use a UTC time to avoid confusion
|
[
"Remotely",
"send",
"an",
"email",
"template",
"to",
"a",
"single",
"email",
"address",
".",
"http",
":",
"//",
"docs",
".",
"sailthru",
".",
"com",
"/",
"api",
"/",
"send"
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L65-L86
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
SailthruClient.multi_send
|
def multi_send(self, template, emails, _vars=None, evars=None, schedule_time=None, options=None):
"""
Remotely send an email template to multiple email addresses.
http://docs.sailthru.com/api/send
@param template: template string
@param emails: List with email values or comma separated email string
@param _vars: a key/value hash of the replacement vars to use in the send. Each var may be referenced as {varname} within the template itself
@param options: optional dictionary to include replyto and/or test keys
@param schedule_time: do not send the email immediately, but at some point in the future. Any date recognized by PHP's strtotime function is valid, but be sure to specify timezone or use a UTC time to avoid confusion
"""
_vars = _vars or {}
evars = evars or {}
options = options or {}
data = {'template': template,
'email': ','.join(emails) if isinstance(emails, list) else emails,
'vars': _vars.copy(),
'evars': evars.copy(),
'options': options.copy()}
if schedule_time is not None:
data['schedule_time'] = schedule_time
return self.api_post('send', data)
|
python
|
def multi_send(self, template, emails, _vars=None, evars=None, schedule_time=None, options=None):
"""
Remotely send an email template to multiple email addresses.
http://docs.sailthru.com/api/send
@param template: template string
@param emails: List with email values or comma separated email string
@param _vars: a key/value hash of the replacement vars to use in the send. Each var may be referenced as {varname} within the template itself
@param options: optional dictionary to include replyto and/or test keys
@param schedule_time: do not send the email immediately, but at some point in the future. Any date recognized by PHP's strtotime function is valid, but be sure to specify timezone or use a UTC time to avoid confusion
"""
_vars = _vars or {}
evars = evars or {}
options = options or {}
data = {'template': template,
'email': ','.join(emails) if isinstance(emails, list) else emails,
'vars': _vars.copy(),
'evars': evars.copy(),
'options': options.copy()}
if schedule_time is not None:
data['schedule_time'] = schedule_time
return self.api_post('send', data)
|
[
"def",
"multi_send",
"(",
"self",
",",
"template",
",",
"emails",
",",
"_vars",
"=",
"None",
",",
"evars",
"=",
"None",
",",
"schedule_time",
"=",
"None",
",",
"options",
"=",
"None",
")",
":",
"_vars",
"=",
"_vars",
"or",
"{",
"}",
"evars",
"=",
"evars",
"or",
"{",
"}",
"options",
"=",
"options",
"or",
"{",
"}",
"data",
"=",
"{",
"'template'",
":",
"template",
",",
"'email'",
":",
"','",
".",
"join",
"(",
"emails",
")",
"if",
"isinstance",
"(",
"emails",
",",
"list",
")",
"else",
"emails",
",",
"'vars'",
":",
"_vars",
".",
"copy",
"(",
")",
",",
"'evars'",
":",
"evars",
".",
"copy",
"(",
")",
",",
"'options'",
":",
"options",
".",
"copy",
"(",
")",
"}",
"if",
"schedule_time",
"is",
"not",
"None",
":",
"data",
"[",
"'schedule_time'",
"]",
"=",
"schedule_time",
"return",
"self",
".",
"api_post",
"(",
"'send'",
",",
"data",
")"
] |
Remotely send an email template to multiple email addresses.
http://docs.sailthru.com/api/send
@param template: template string
@param emails: List with email values or comma separated email string
@param _vars: a key/value hash of the replacement vars to use in the send. Each var may be referenced as {varname} within the template itself
@param options: optional dictionary to include replyto and/or test keys
@param schedule_time: do not send the email immediately, but at some point in the future. Any date recognized by PHP's strtotime function is valid, but be sure to specify timezone or use a UTC time to avoid confusion
|
[
"Remotely",
"send",
"an",
"email",
"template",
"to",
"multiple",
"email",
"addresses",
".",
"http",
":",
"//",
"docs",
".",
"sailthru",
".",
"com",
"/",
"api",
"/",
"send"
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L88-L108
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
SailthruClient.set_email
|
def set_email(self, email, _vars=None, lists=None, templates=None, verified=0, optout=None, send=None, send_vars=None):
"""
DEPRECATED!
Update information about one of your users, including adding and removing the user from lists.
http://docs.sailthru.com/api/email
"""
_vars = _vars or {}
lists = lists or []
templates = templates or []
send_vars = send_vars or []
data = {'email': email,
'vars': _vars.copy(),
'lists': lists,
'templates': templates,
'verified': int(verified)}
if optout is not None:
data['optout'] = optout
if send is not None:
data['send'] = send
if send_vars:
data['send_vars'] = send_vars
return self.api_post('email', data)
|
python
|
def set_email(self, email, _vars=None, lists=None, templates=None, verified=0, optout=None, send=None, send_vars=None):
"""
DEPRECATED!
Update information about one of your users, including adding and removing the user from lists.
http://docs.sailthru.com/api/email
"""
_vars = _vars or {}
lists = lists or []
templates = templates or []
send_vars = send_vars or []
data = {'email': email,
'vars': _vars.copy(),
'lists': lists,
'templates': templates,
'verified': int(verified)}
if optout is not None:
data['optout'] = optout
if send is not None:
data['send'] = send
if send_vars:
data['send_vars'] = send_vars
return self.api_post('email', data)
|
[
"def",
"set_email",
"(",
"self",
",",
"email",
",",
"_vars",
"=",
"None",
",",
"lists",
"=",
"None",
",",
"templates",
"=",
"None",
",",
"verified",
"=",
"0",
",",
"optout",
"=",
"None",
",",
"send",
"=",
"None",
",",
"send_vars",
"=",
"None",
")",
":",
"_vars",
"=",
"_vars",
"or",
"{",
"}",
"lists",
"=",
"lists",
"or",
"[",
"]",
"templates",
"=",
"templates",
"or",
"[",
"]",
"send_vars",
"=",
"send_vars",
"or",
"[",
"]",
"data",
"=",
"{",
"'email'",
":",
"email",
",",
"'vars'",
":",
"_vars",
".",
"copy",
"(",
")",
",",
"'lists'",
":",
"lists",
",",
"'templates'",
":",
"templates",
",",
"'verified'",
":",
"int",
"(",
"verified",
")",
"}",
"if",
"optout",
"is",
"not",
"None",
":",
"data",
"[",
"'optout'",
"]",
"=",
"optout",
"if",
"send",
"is",
"not",
"None",
":",
"data",
"[",
"'send'",
"]",
"=",
"send",
"if",
"send_vars",
":",
"data",
"[",
"'send_vars'",
"]",
"=",
"send_vars",
"return",
"self",
".",
"api_post",
"(",
"'email'",
",",
"data",
")"
] |
DEPRECATED!
Update information about one of your users, including adding and removing the user from lists.
http://docs.sailthru.com/api/email
|
[
"DEPRECATED!",
"Update",
"information",
"about",
"one",
"of",
"your",
"users",
"including",
"adding",
"and",
"removing",
"the",
"user",
"from",
"lists",
".",
"http",
":",
"//",
"docs",
".",
"sailthru",
".",
"com",
"/",
"api",
"/",
"email"
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L131-L152
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
SailthruClient.get_user
|
def get_user(self, idvalue, options=None):
"""
get user by a given id
http://getstarted.sailthru.com/api/user
"""
options = options or {}
data = options.copy()
data['id'] = idvalue
return self.api_get('user', data)
|
python
|
def get_user(self, idvalue, options=None):
"""
get user by a given id
http://getstarted.sailthru.com/api/user
"""
options = options or {}
data = options.copy()
data['id'] = idvalue
return self.api_get('user', data)
|
[
"def",
"get_user",
"(",
"self",
",",
"idvalue",
",",
"options",
"=",
"None",
")",
":",
"options",
"=",
"options",
"or",
"{",
"}",
"data",
"=",
"options",
".",
"copy",
"(",
")",
"data",
"[",
"'id'",
"]",
"=",
"idvalue",
"return",
"self",
".",
"api_get",
"(",
"'user'",
",",
"data",
")"
] |
get user by a given id
http://getstarted.sailthru.com/api/user
|
[
"get",
"user",
"by",
"a",
"given",
"id",
"http",
":",
"//",
"getstarted",
".",
"sailthru",
".",
"com",
"/",
"api",
"/",
"user"
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L154-L162
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
SailthruClient.save_user
|
def save_user(self, idvalue, options=None):
"""
save user by a given id
http://getstarted.sailthru.com/api/user
"""
options = options or {}
data = options.copy()
data['id'] = idvalue
return self.api_post('user', data)
|
python
|
def save_user(self, idvalue, options=None):
"""
save user by a given id
http://getstarted.sailthru.com/api/user
"""
options = options or {}
data = options.copy()
data['id'] = idvalue
return self.api_post('user', data)
|
[
"def",
"save_user",
"(",
"self",
",",
"idvalue",
",",
"options",
"=",
"None",
")",
":",
"options",
"=",
"options",
"or",
"{",
"}",
"data",
"=",
"options",
".",
"copy",
"(",
")",
"data",
"[",
"'id'",
"]",
"=",
"idvalue",
"return",
"self",
".",
"api_post",
"(",
"'user'",
",",
"data",
")"
] |
save user by a given id
http://getstarted.sailthru.com/api/user
|
[
"save",
"user",
"by",
"a",
"given",
"id",
"http",
":",
"//",
"getstarted",
".",
"sailthru",
".",
"com",
"/",
"api",
"/",
"user"
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L164-L172
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
SailthruClient.schedule_blast
|
def schedule_blast(self, name, list, schedule_time, from_name, from_email, subject, content_html, content_text, options=None):
"""
Schedule a mass mail blast
http://docs.sailthru.com/api/blast
@param name: name to give to this new blast
@param list: mailing list name to send to
@param schedule_time: when the blast should send. Dates in the past will be scheduled for immediate delivery. Any English textual datetime format known to PHP's strtotime function is acceptable, such as 2009-03-18 23:57:22 UTC, now (immediate delivery), +3 hours (3 hours from now), or February 14, 9:30 EST. Be sure to specify a timezone if you use an exact time.
@param from_name: name appearing in the "From" of the email
@param from_email: email address to use as the "from" - choose from any of your verified emails
@param subject: subject line of the email
@param content_html: HTML format version of the email
@param content_text: Text format version of the email
@param options: optional parameters dictionary
blast_id
copy_blast
copy_template
replyto
report_email
is_link_tracking
is_google_analytics
is_public
suppress_list
test_vars
email_hour_range
abtest
test_percent
data_feed_url
"""
options = options or {}
data = options.copy()
data['name'] = name
data['list'] = list
data['schedule_time'] = schedule_time
data['from_name'] = from_name
data['from_email'] = from_email
data['subject'] = subject
data['content_html'] = content_html
data['content_text'] = content_text
return self.api_post('blast', data)
|
python
|
def schedule_blast(self, name, list, schedule_time, from_name, from_email, subject, content_html, content_text, options=None):
"""
Schedule a mass mail blast
http://docs.sailthru.com/api/blast
@param name: name to give to this new blast
@param list: mailing list name to send to
@param schedule_time: when the blast should send. Dates in the past will be scheduled for immediate delivery. Any English textual datetime format known to PHP's strtotime function is acceptable, such as 2009-03-18 23:57:22 UTC, now (immediate delivery), +3 hours (3 hours from now), or February 14, 9:30 EST. Be sure to specify a timezone if you use an exact time.
@param from_name: name appearing in the "From" of the email
@param from_email: email address to use as the "from" - choose from any of your verified emails
@param subject: subject line of the email
@param content_html: HTML format version of the email
@param content_text: Text format version of the email
@param options: optional parameters dictionary
blast_id
copy_blast
copy_template
replyto
report_email
is_link_tracking
is_google_analytics
is_public
suppress_list
test_vars
email_hour_range
abtest
test_percent
data_feed_url
"""
options = options or {}
data = options.copy()
data['name'] = name
data['list'] = list
data['schedule_time'] = schedule_time
data['from_name'] = from_name
data['from_email'] = from_email
data['subject'] = subject
data['content_html'] = content_html
data['content_text'] = content_text
return self.api_post('blast', data)
|
[
"def",
"schedule_blast",
"(",
"self",
",",
"name",
",",
"list",
",",
"schedule_time",
",",
"from_name",
",",
"from_email",
",",
"subject",
",",
"content_html",
",",
"content_text",
",",
"options",
"=",
"None",
")",
":",
"options",
"=",
"options",
"or",
"{",
"}",
"data",
"=",
"options",
".",
"copy",
"(",
")",
"data",
"[",
"'name'",
"]",
"=",
"name",
"data",
"[",
"'list'",
"]",
"=",
"list",
"data",
"[",
"'schedule_time'",
"]",
"=",
"schedule_time",
"data",
"[",
"'from_name'",
"]",
"=",
"from_name",
"data",
"[",
"'from_email'",
"]",
"=",
"from_email",
"data",
"[",
"'subject'",
"]",
"=",
"subject",
"data",
"[",
"'content_html'",
"]",
"=",
"content_html",
"data",
"[",
"'content_text'",
"]",
"=",
"content_text",
"return",
"self",
".",
"api_post",
"(",
"'blast'",
",",
"data",
")"
] |
Schedule a mass mail blast
http://docs.sailthru.com/api/blast
@param name: name to give to this new blast
@param list: mailing list name to send to
@param schedule_time: when the blast should send. Dates in the past will be scheduled for immediate delivery. Any English textual datetime format known to PHP's strtotime function is acceptable, such as 2009-03-18 23:57:22 UTC, now (immediate delivery), +3 hours (3 hours from now), or February 14, 9:30 EST. Be sure to specify a timezone if you use an exact time.
@param from_name: name appearing in the "From" of the email
@param from_email: email address to use as the "from" - choose from any of your verified emails
@param subject: subject line of the email
@param content_html: HTML format version of the email
@param content_text: Text format version of the email
@param options: optional parameters dictionary
blast_id
copy_blast
copy_template
replyto
report_email
is_link_tracking
is_google_analytics
is_public
suppress_list
test_vars
email_hour_range
abtest
test_percent
data_feed_url
|
[
"Schedule",
"a",
"mass",
"mail",
"blast",
"http",
":",
"//",
"docs",
".",
"sailthru",
".",
"com",
"/",
"api",
"/",
"blast"
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L174-L212
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
SailthruClient.schedule_blast_from_template
|
def schedule_blast_from_template(self, template, list_name, schedule_time, options=None):
"""
Schedule a mass mail blast from template
http://docs.sailthru.com/api/blast
@param template: template to copy from
@param list_name: list to send to
@param schedule_time
@param options: additional optional params
"""
options = options or {}
data = options.copy()
data['copy_template'] = template
data['list'] = list_name
data['schedule_time'] = schedule_time
return self.api_post('blast', data)
|
python
|
def schedule_blast_from_template(self, template, list_name, schedule_time, options=None):
"""
Schedule a mass mail blast from template
http://docs.sailthru.com/api/blast
@param template: template to copy from
@param list_name: list to send to
@param schedule_time
@param options: additional optional params
"""
options = options or {}
data = options.copy()
data['copy_template'] = template
data['list'] = list_name
data['schedule_time'] = schedule_time
return self.api_post('blast', data)
|
[
"def",
"schedule_blast_from_template",
"(",
"self",
",",
"template",
",",
"list_name",
",",
"schedule_time",
",",
"options",
"=",
"None",
")",
":",
"options",
"=",
"options",
"or",
"{",
"}",
"data",
"=",
"options",
".",
"copy",
"(",
")",
"data",
"[",
"'copy_template'",
"]",
"=",
"template",
"data",
"[",
"'list'",
"]",
"=",
"list_name",
"data",
"[",
"'schedule_time'",
"]",
"=",
"schedule_time",
"return",
"self",
".",
"api_post",
"(",
"'blast'",
",",
"data",
")"
] |
Schedule a mass mail blast from template
http://docs.sailthru.com/api/blast
@param template: template to copy from
@param list_name: list to send to
@param schedule_time
@param options: additional optional params
|
[
"Schedule",
"a",
"mass",
"mail",
"blast",
"from",
"template",
"http",
":",
"//",
"docs",
".",
"sailthru",
".",
"com",
"/",
"api",
"/",
"blast"
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L214-L228
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
SailthruClient.schedule_blast_from_blast
|
def schedule_blast_from_blast(self, blast_id, schedule_time, options=None):
"""
Schedule a mass mail blast from previous blast
http://docs.sailthru.com/api/blast
@param blast_id: blast_id to copy from
@param schedule_time
@param options: additional optional params
"""
options = options or {}
data = options.copy()
data['copy_blast'] = blast_id
data['schedule_time'] = schedule_time
return self.api_post('blast', data)
|
python
|
def schedule_blast_from_blast(self, blast_id, schedule_time, options=None):
"""
Schedule a mass mail blast from previous blast
http://docs.sailthru.com/api/blast
@param blast_id: blast_id to copy from
@param schedule_time
@param options: additional optional params
"""
options = options or {}
data = options.copy()
data['copy_blast'] = blast_id
data['schedule_time'] = schedule_time
return self.api_post('blast', data)
|
[
"def",
"schedule_blast_from_blast",
"(",
"self",
",",
"blast_id",
",",
"schedule_time",
",",
"options",
"=",
"None",
")",
":",
"options",
"=",
"options",
"or",
"{",
"}",
"data",
"=",
"options",
".",
"copy",
"(",
")",
"data",
"[",
"'copy_blast'",
"]",
"=",
"blast_id",
"data",
"[",
"'schedule_time'",
"]",
"=",
"schedule_time",
"return",
"self",
".",
"api_post",
"(",
"'blast'",
",",
"data",
")"
] |
Schedule a mass mail blast from previous blast
http://docs.sailthru.com/api/blast
@param blast_id: blast_id to copy from
@param schedule_time
@param options: additional optional params
|
[
"Schedule",
"a",
"mass",
"mail",
"blast",
"from",
"previous",
"blast",
"http",
":",
"//",
"docs",
".",
"sailthru",
".",
"com",
"/",
"api",
"/",
"blast"
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L230-L242
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
SailthruClient.get_list
|
def get_list(self, list_name, options=None):
"""
Get detailed metadata information about a list.
"""
options = options or {}
data = {'list': list_name}
data.update(options)
return self.api_get('list', data)
|
python
|
def get_list(self, list_name, options=None):
"""
Get detailed metadata information about a list.
"""
options = options or {}
data = {'list': list_name}
data.update(options)
return self.api_get('list', data)
|
[
"def",
"get_list",
"(",
"self",
",",
"list_name",
",",
"options",
"=",
"None",
")",
":",
"options",
"=",
"options",
"or",
"{",
"}",
"data",
"=",
"{",
"'list'",
":",
"list_name",
"}",
"data",
".",
"update",
"(",
"options",
")",
"return",
"self",
".",
"api_get",
"(",
"'list'",
",",
"data",
")"
] |
Get detailed metadata information about a list.
|
[
"Get",
"detailed",
"metadata",
"information",
"about",
"a",
"list",
"."
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L341-L348
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
SailthruClient.save_list
|
def save_list(self, list_name, emails):
"""
Upload a list. The list import job is queued and will happen shortly after the API request.
http://docs.sailthru.com/api/list
@param list: list name
@param emails: List of email values or comma separated string
"""
data = {'list': list_name,
'emails': ','.join(emails) if isinstance(emails, list) else emails}
return self.api_post('list', data)
|
python
|
def save_list(self, list_name, emails):
"""
Upload a list. The list import job is queued and will happen shortly after the API request.
http://docs.sailthru.com/api/list
@param list: list name
@param emails: List of email values or comma separated string
"""
data = {'list': list_name,
'emails': ','.join(emails) if isinstance(emails, list) else emails}
return self.api_post('list', data)
|
[
"def",
"save_list",
"(",
"self",
",",
"list_name",
",",
"emails",
")",
":",
"data",
"=",
"{",
"'list'",
":",
"list_name",
",",
"'emails'",
":",
"','",
".",
"join",
"(",
"emails",
")",
"if",
"isinstance",
"(",
"emails",
",",
"list",
")",
"else",
"emails",
"}",
"return",
"self",
".",
"api_post",
"(",
"'list'",
",",
"data",
")"
] |
Upload a list. The list import job is queued and will happen shortly after the API request.
http://docs.sailthru.com/api/list
@param list: list name
@param emails: List of email values or comma separated string
|
[
"Upload",
"a",
"list",
".",
"The",
"list",
"import",
"job",
"is",
"queued",
"and",
"will",
"happen",
"shortly",
"after",
"the",
"API",
"request",
".",
"http",
":",
"//",
"docs",
".",
"sailthru",
".",
"com",
"/",
"api",
"/",
"list"
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L356-L365
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
SailthruClient.import_contacts
|
def import_contacts(self, email, password, include_name=False):
"""
Fetch email contacts from a user's address book on one of the major email websites. Currently supports AOL, Gmail, Hotmail, and Yahoo! Mail.
"""
data = {'email': email,
'password': password}
if include_name:
data['names'] = 1
return self.api_post('contacts', data)
|
python
|
def import_contacts(self, email, password, include_name=False):
"""
Fetch email contacts from a user's address book on one of the major email websites. Currently supports AOL, Gmail, Hotmail, and Yahoo! Mail.
"""
data = {'email': email,
'password': password}
if include_name:
data['names'] = 1
return self.api_post('contacts', data)
|
[
"def",
"import_contacts",
"(",
"self",
",",
"email",
",",
"password",
",",
"include_name",
"=",
"False",
")",
":",
"data",
"=",
"{",
"'email'",
":",
"email",
",",
"'password'",
":",
"password",
"}",
"if",
"include_name",
":",
"data",
"[",
"'names'",
"]",
"=",
"1",
"return",
"self",
".",
"api_post",
"(",
"'contacts'",
",",
"data",
")"
] |
Fetch email contacts from a user's address book on one of the major email websites. Currently supports AOL, Gmail, Hotmail, and Yahoo! Mail.
|
[
"Fetch",
"email",
"contacts",
"from",
"a",
"user",
"s",
"address",
"book",
"on",
"one",
"of",
"the",
"major",
"email",
"websites",
".",
"Currently",
"supports",
"AOL",
"Gmail",
"Hotmail",
"and",
"Yahoo!",
"Mail",
"."
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L374-L382
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
SailthruClient.push_content
|
def push_content(self, title, url,
images=None, date=None, expire_date=None,
description=None, location=None, price=None,
tags=None,
author=None, site_name=None,
spider=None, vars=None):
"""
Push a new piece of content to Sailthru.
Expected names for the `images` argument's map are "full" and "thumb"
Expected format for `location` should be [longitude,latitude]
@param title: title string for the content
@param url: URL string for the content
@param images: map of image names
@param date: date string
@param expire_date: date string for when the content expires
@param description: description for the content
@param location: location of the content
@param price: price for the content
@param tags: list or comma separated string values
@param author: author for the content
@param site_name: site name for the content
@param spider: truthy value to force respidering content
@param vars: replaceable vars dictionary
"""
vars = vars or {}
data = {'title': title,
'url': url}
if images is not None:
data['images'] = images
if date is not None:
data['date'] = date
if expire_date is not None:
data['expire_date'] = date
if location is not None:
data['location'] = date
if price is not None:
data['price'] = price
if description is not None:
data['description'] = description
if site_name is not None:
data['site_name'] = images
if author is not None:
data['author'] = author
if spider:
data['spider'] = 1
if tags is not None:
data['tags'] = ",".join(tags) if isinstance(tags, list) else tags
if len(vars) > 0:
data['vars'] = vars.copy()
return self.api_post('content', data)
|
python
|
def push_content(self, title, url,
images=None, date=None, expire_date=None,
description=None, location=None, price=None,
tags=None,
author=None, site_name=None,
spider=None, vars=None):
"""
Push a new piece of content to Sailthru.
Expected names for the `images` argument's map are "full" and "thumb"
Expected format for `location` should be [longitude,latitude]
@param title: title string for the content
@param url: URL string for the content
@param images: map of image names
@param date: date string
@param expire_date: date string for when the content expires
@param description: description for the content
@param location: location of the content
@param price: price for the content
@param tags: list or comma separated string values
@param author: author for the content
@param site_name: site name for the content
@param spider: truthy value to force respidering content
@param vars: replaceable vars dictionary
"""
vars = vars or {}
data = {'title': title,
'url': url}
if images is not None:
data['images'] = images
if date is not None:
data['date'] = date
if expire_date is not None:
data['expire_date'] = date
if location is not None:
data['location'] = date
if price is not None:
data['price'] = price
if description is not None:
data['description'] = description
if site_name is not None:
data['site_name'] = images
if author is not None:
data['author'] = author
if spider:
data['spider'] = 1
if tags is not None:
data['tags'] = ",".join(tags) if isinstance(tags, list) else tags
if len(vars) > 0:
data['vars'] = vars.copy()
return self.api_post('content', data)
|
[
"def",
"push_content",
"(",
"self",
",",
"title",
",",
"url",
",",
"images",
"=",
"None",
",",
"date",
"=",
"None",
",",
"expire_date",
"=",
"None",
",",
"description",
"=",
"None",
",",
"location",
"=",
"None",
",",
"price",
"=",
"None",
",",
"tags",
"=",
"None",
",",
"author",
"=",
"None",
",",
"site_name",
"=",
"None",
",",
"spider",
"=",
"None",
",",
"vars",
"=",
"None",
")",
":",
"vars",
"=",
"vars",
"or",
"{",
"}",
"data",
"=",
"{",
"'title'",
":",
"title",
",",
"'url'",
":",
"url",
"}",
"if",
"images",
"is",
"not",
"None",
":",
"data",
"[",
"'images'",
"]",
"=",
"images",
"if",
"date",
"is",
"not",
"None",
":",
"data",
"[",
"'date'",
"]",
"=",
"date",
"if",
"expire_date",
"is",
"not",
"None",
":",
"data",
"[",
"'expire_date'",
"]",
"=",
"date",
"if",
"location",
"is",
"not",
"None",
":",
"data",
"[",
"'location'",
"]",
"=",
"date",
"if",
"price",
"is",
"not",
"None",
":",
"data",
"[",
"'price'",
"]",
"=",
"price",
"if",
"description",
"is",
"not",
"None",
":",
"data",
"[",
"'description'",
"]",
"=",
"description",
"if",
"site_name",
"is",
"not",
"None",
":",
"data",
"[",
"'site_name'",
"]",
"=",
"images",
"if",
"author",
"is",
"not",
"None",
":",
"data",
"[",
"'author'",
"]",
"=",
"author",
"if",
"spider",
":",
"data",
"[",
"'spider'",
"]",
"=",
"1",
"if",
"tags",
"is",
"not",
"None",
":",
"data",
"[",
"'tags'",
"]",
"=",
"\",\"",
".",
"join",
"(",
"tags",
")",
"if",
"isinstance",
"(",
"tags",
",",
"list",
")",
"else",
"tags",
"if",
"len",
"(",
"vars",
")",
">",
"0",
":",
"data",
"[",
"'vars'",
"]",
"=",
"vars",
".",
"copy",
"(",
")",
"return",
"self",
".",
"api_post",
"(",
"'content'",
",",
"data",
")"
] |
Push a new piece of content to Sailthru.
Expected names for the `images` argument's map are "full" and "thumb"
Expected format for `location` should be [longitude,latitude]
@param title: title string for the content
@param url: URL string for the content
@param images: map of image names
@param date: date string
@param expire_date: date string for when the content expires
@param description: description for the content
@param location: location of the content
@param price: price for the content
@param tags: list or comma separated string values
@param author: author for the content
@param site_name: site name for the content
@param spider: truthy value to force respidering content
@param vars: replaceable vars dictionary
|
[
"Push",
"a",
"new",
"piece",
"of",
"content",
"to",
"Sailthru",
"."
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L384-L437
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
SailthruClient.save_alert
|
def save_alert(self, email, type, template, when=None, options=None):
"""
Add a new alert to a user. You can add either a realtime or a summary alert (daily/weekly).
http://docs.sailthru.com/api/alert
Usage:
email = 'praj@sailthru.com'
type = 'weekly'
template = 'default'
when = '+5 hours'
alert_options = {'match': {}, 'min': {}, 'max': {}, 'tags': []}
alert_options['match']['type'] = 'shoes'
alert_options['min']['price'] = 20000 #cents
alert_options['tags'] = ['red', 'blue', 'green']
response = client.save_alert(email, type, template, when, alert_options)
@param email: Email value
@param type: daily|weekly|realtime
@param template: template name
@param when: date string required for summary alert (daily/weekly)
@param options: dictionary value for adding tags, max price, min price, match type
"""
options = options or {}
data = options.copy()
data['email'] = email
data['type'] = type
data['template'] = template
if type in ['weekly', 'daily']:
data['when'] = when
return self.api_post('alert', data)
|
python
|
def save_alert(self, email, type, template, when=None, options=None):
"""
Add a new alert to a user. You can add either a realtime or a summary alert (daily/weekly).
http://docs.sailthru.com/api/alert
Usage:
email = 'praj@sailthru.com'
type = 'weekly'
template = 'default'
when = '+5 hours'
alert_options = {'match': {}, 'min': {}, 'max': {}, 'tags': []}
alert_options['match']['type'] = 'shoes'
alert_options['min']['price'] = 20000 #cents
alert_options['tags'] = ['red', 'blue', 'green']
response = client.save_alert(email, type, template, when, alert_options)
@param email: Email value
@param type: daily|weekly|realtime
@param template: template name
@param when: date string required for summary alert (daily/weekly)
@param options: dictionary value for adding tags, max price, min price, match type
"""
options = options or {}
data = options.copy()
data['email'] = email
data['type'] = type
data['template'] = template
if type in ['weekly', 'daily']:
data['when'] = when
return self.api_post('alert', data)
|
[
"def",
"save_alert",
"(",
"self",
",",
"email",
",",
"type",
",",
"template",
",",
"when",
"=",
"None",
",",
"options",
"=",
"None",
")",
":",
"options",
"=",
"options",
"or",
"{",
"}",
"data",
"=",
"options",
".",
"copy",
"(",
")",
"data",
"[",
"'email'",
"]",
"=",
"email",
"data",
"[",
"'type'",
"]",
"=",
"type",
"data",
"[",
"'template'",
"]",
"=",
"template",
"if",
"type",
"in",
"[",
"'weekly'",
",",
"'daily'",
"]",
":",
"data",
"[",
"'when'",
"]",
"=",
"when",
"return",
"self",
".",
"api_post",
"(",
"'alert'",
",",
"data",
")"
] |
Add a new alert to a user. You can add either a realtime or a summary alert (daily/weekly).
http://docs.sailthru.com/api/alert
Usage:
email = 'praj@sailthru.com'
type = 'weekly'
template = 'default'
when = '+5 hours'
alert_options = {'match': {}, 'min': {}, 'max': {}, 'tags': []}
alert_options['match']['type'] = 'shoes'
alert_options['min']['price'] = 20000 #cents
alert_options['tags'] = ['red', 'blue', 'green']
response = client.save_alert(email, type, template, when, alert_options)
@param email: Email value
@param type: daily|weekly|realtime
@param template: template name
@param when: date string required for summary alert (daily/weekly)
@param options: dictionary value for adding tags, max price, min price, match type
|
[
"Add",
"a",
"new",
"alert",
"to",
"a",
"user",
".",
"You",
"can",
"add",
"either",
"a",
"realtime",
"or",
"a",
"summary",
"alert",
"(",
"daily",
"/",
"weekly",
")",
".",
"http",
":",
"//",
"docs",
".",
"sailthru",
".",
"com",
"/",
"api",
"/",
"alert"
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L445-L474
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
SailthruClient.delete_alert
|
def delete_alert(self, email, alert_id):
"""
delete user alert
"""
data = {'email': email,
'alert_id': alert_id}
return self.api_delete('alert', data)
|
python
|
def delete_alert(self, email, alert_id):
"""
delete user alert
"""
data = {'email': email,
'alert_id': alert_id}
return self.api_delete('alert', data)
|
[
"def",
"delete_alert",
"(",
"self",
",",
"email",
",",
"alert_id",
")",
":",
"data",
"=",
"{",
"'email'",
":",
"email",
",",
"'alert_id'",
":",
"alert_id",
"}",
"return",
"self",
".",
"api_delete",
"(",
"'alert'",
",",
"data",
")"
] |
delete user alert
|
[
"delete",
"user",
"alert"
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L476-L482
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
SailthruClient.purchase
|
def purchase(self, email, items=None, incomplete=None, message_id=None, options=None, extid=None):
"""
Record that a user has made a purchase, or has added items to their purchase total.
http://docs.sailthru.com/api/purchase
@param email: Email string
@param items: list of item dictionary with keys: id, title, price, qty, and url
@param message_id: message_id string
@param extid: external ID to track purchases
@param options: other options that can be set as per the API documentation
"""
items = items or {}
options = options or {}
data = options.copy()
data['email'] = email
data['items'] = items
if incomplete is not None:
data['incomplete'] = incomplete
if message_id is not None:
data['message_id'] = message_id
if extid is not None:
data['extid'] = extid
return self.api_post('purchase', data)
|
python
|
def purchase(self, email, items=None, incomplete=None, message_id=None, options=None, extid=None):
"""
Record that a user has made a purchase, or has added items to their purchase total.
http://docs.sailthru.com/api/purchase
@param email: Email string
@param items: list of item dictionary with keys: id, title, price, qty, and url
@param message_id: message_id string
@param extid: external ID to track purchases
@param options: other options that can be set as per the API documentation
"""
items = items or {}
options = options or {}
data = options.copy()
data['email'] = email
data['items'] = items
if incomplete is not None:
data['incomplete'] = incomplete
if message_id is not None:
data['message_id'] = message_id
if extid is not None:
data['extid'] = extid
return self.api_post('purchase', data)
|
[
"def",
"purchase",
"(",
"self",
",",
"email",
",",
"items",
"=",
"None",
",",
"incomplete",
"=",
"None",
",",
"message_id",
"=",
"None",
",",
"options",
"=",
"None",
",",
"extid",
"=",
"None",
")",
":",
"items",
"=",
"items",
"or",
"{",
"}",
"options",
"=",
"options",
"or",
"{",
"}",
"data",
"=",
"options",
".",
"copy",
"(",
")",
"data",
"[",
"'email'",
"]",
"=",
"email",
"data",
"[",
"'items'",
"]",
"=",
"items",
"if",
"incomplete",
"is",
"not",
"None",
":",
"data",
"[",
"'incomplete'",
"]",
"=",
"incomplete",
"if",
"message_id",
"is",
"not",
"None",
":",
"data",
"[",
"'message_id'",
"]",
"=",
"message_id",
"if",
"extid",
"is",
"not",
"None",
":",
"data",
"[",
"'extid'",
"]",
"=",
"extid",
"return",
"self",
".",
"api_post",
"(",
"'purchase'",
",",
"data",
")"
] |
Record that a user has made a purchase, or has added items to their purchase total.
http://docs.sailthru.com/api/purchase
@param email: Email string
@param items: list of item dictionary with keys: id, title, price, qty, and url
@param message_id: message_id string
@param extid: external ID to track purchases
@param options: other options that can be set as per the API documentation
|
[
"Record",
"that",
"a",
"user",
"has",
"made",
"a",
"purchase",
"or",
"has",
"added",
"items",
"to",
"their",
"purchase",
"total",
".",
"http",
":",
"//",
"docs",
".",
"sailthru",
".",
"com",
"/",
"api",
"/",
"purchase"
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L484-L505
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
SailthruClient.get_purchase
|
def get_purchase(self, purchase_id, purchase_key='sid'):
"""
Retrieve information about a purchase using the system's unique ID or a client's ID
@param id_: a string that represents a unique_id or an extid.
@param key: a string that is either 'sid' or 'extid'.
"""
data = {'purchase_id': purchase_id,
'purchase_key': purchase_key}
return self.api_get('purchase', data)
|
python
|
def get_purchase(self, purchase_id, purchase_key='sid'):
"""
Retrieve information about a purchase using the system's unique ID or a client's ID
@param id_: a string that represents a unique_id or an extid.
@param key: a string that is either 'sid' or 'extid'.
"""
data = {'purchase_id': purchase_id,
'purchase_key': purchase_key}
return self.api_get('purchase', data)
|
[
"def",
"get_purchase",
"(",
"self",
",",
"purchase_id",
",",
"purchase_key",
"=",
"'sid'",
")",
":",
"data",
"=",
"{",
"'purchase_id'",
":",
"purchase_id",
",",
"'purchase_key'",
":",
"purchase_key",
"}",
"return",
"self",
".",
"api_get",
"(",
"'purchase'",
",",
"data",
")"
] |
Retrieve information about a purchase using the system's unique ID or a client's ID
@param id_: a string that represents a unique_id or an extid.
@param key: a string that is either 'sid' or 'extid'.
|
[
"Retrieve",
"information",
"about",
"a",
"purchase",
"using",
"the",
"system",
"s",
"unique",
"ID",
"or",
"a",
"client",
"s",
"ID"
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L507-L515
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
SailthruClient.stats_list
|
def stats_list(self, list=None, date=None, headers=None):
"""
Retrieve information about your subscriber counts on a particular list, on a particular day.
http://docs.sailthru.com/api/stat
"""
data = {'stat': 'list'}
if list is not None:
data['list'] = list
if date is not None:
data['date'] = date
return self._stats(data, headers)
|
python
|
def stats_list(self, list=None, date=None, headers=None):
"""
Retrieve information about your subscriber counts on a particular list, on a particular day.
http://docs.sailthru.com/api/stat
"""
data = {'stat': 'list'}
if list is not None:
data['list'] = list
if date is not None:
data['date'] = date
return self._stats(data, headers)
|
[
"def",
"stats_list",
"(",
"self",
",",
"list",
"=",
"None",
",",
"date",
"=",
"None",
",",
"headers",
"=",
"None",
")",
":",
"data",
"=",
"{",
"'stat'",
":",
"'list'",
"}",
"if",
"list",
"is",
"not",
"None",
":",
"data",
"[",
"'list'",
"]",
"=",
"list",
"if",
"date",
"is",
"not",
"None",
":",
"data",
"[",
"'date'",
"]",
"=",
"date",
"return",
"self",
".",
"_stats",
"(",
"data",
",",
"headers",
")"
] |
Retrieve information about your subscriber counts on a particular list, on a particular day.
http://docs.sailthru.com/api/stat
|
[
"Retrieve",
"information",
"about",
"your",
"subscriber",
"counts",
"on",
"a",
"particular",
"list",
"on",
"a",
"particular",
"day",
".",
"http",
":",
"//",
"docs",
".",
"sailthru",
".",
"com",
"/",
"api",
"/",
"stat"
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L517-L527
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
SailthruClient.stats_blast
|
def stats_blast(self, blast_id=None, start_date=None, end_date=None, options=None):
"""
Retrieve information about a particular blast or aggregated information from all of blasts over a specified date range.
http://docs.sailthru.com/api/stat
"""
options = options or {}
data = options.copy()
if blast_id is not None:
data['blast_id'] = blast_id
if start_date is not None:
data['start_date'] = start_date
if end_date is not None:
data['end_date'] = end_date
data['stat'] = 'blast'
return self._stats(data)
|
python
|
def stats_blast(self, blast_id=None, start_date=None, end_date=None, options=None):
"""
Retrieve information about a particular blast or aggregated information from all of blasts over a specified date range.
http://docs.sailthru.com/api/stat
"""
options = options or {}
data = options.copy()
if blast_id is not None:
data['blast_id'] = blast_id
if start_date is not None:
data['start_date'] = start_date
if end_date is not None:
data['end_date'] = end_date
data['stat'] = 'blast'
return self._stats(data)
|
[
"def",
"stats_blast",
"(",
"self",
",",
"blast_id",
"=",
"None",
",",
"start_date",
"=",
"None",
",",
"end_date",
"=",
"None",
",",
"options",
"=",
"None",
")",
":",
"options",
"=",
"options",
"or",
"{",
"}",
"data",
"=",
"options",
".",
"copy",
"(",
")",
"if",
"blast_id",
"is",
"not",
"None",
":",
"data",
"[",
"'blast_id'",
"]",
"=",
"blast_id",
"if",
"start_date",
"is",
"not",
"None",
":",
"data",
"[",
"'start_date'",
"]",
"=",
"start_date",
"if",
"end_date",
"is",
"not",
"None",
":",
"data",
"[",
"'end_date'",
"]",
"=",
"end_date",
"data",
"[",
"'stat'",
"]",
"=",
"'blast'",
"return",
"self",
".",
"_stats",
"(",
"data",
")"
] |
Retrieve information about a particular blast or aggregated information from all of blasts over a specified date range.
http://docs.sailthru.com/api/stat
|
[
"Retrieve",
"information",
"about",
"a",
"particular",
"blast",
"or",
"aggregated",
"information",
"from",
"all",
"of",
"blasts",
"over",
"a",
"specified",
"date",
"range",
".",
"http",
":",
"//",
"docs",
".",
"sailthru",
".",
"com",
"/",
"api",
"/",
"stat"
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L529-L543
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
SailthruClient.stats_send
|
def stats_send(self, template, start_date, end_date, options=None):
"""
Retrieve information about a particular transactional or aggregated information
from transactionals from that template over a specified date range.
http://docs.sailthru.com/api/stat
"""
options = options or {}
data = options.copy()
data = {'template': template,
'start_date': start_date,
'end_date': end_date
}
data['stat'] = 'send'
return self._stats(data)
|
python
|
def stats_send(self, template, start_date, end_date, options=None):
"""
Retrieve information about a particular transactional or aggregated information
from transactionals from that template over a specified date range.
http://docs.sailthru.com/api/stat
"""
options = options or {}
data = options.copy()
data = {'template': template,
'start_date': start_date,
'end_date': end_date
}
data['stat'] = 'send'
return self._stats(data)
|
[
"def",
"stats_send",
"(",
"self",
",",
"template",
",",
"start_date",
",",
"end_date",
",",
"options",
"=",
"None",
")",
":",
"options",
"=",
"options",
"or",
"{",
"}",
"data",
"=",
"options",
".",
"copy",
"(",
")",
"data",
"=",
"{",
"'template'",
":",
"template",
",",
"'start_date'",
":",
"start_date",
",",
"'end_date'",
":",
"end_date",
"}",
"data",
"[",
"'stat'",
"]",
"=",
"'send'",
"return",
"self",
".",
"_stats",
"(",
"data",
")"
] |
Retrieve information about a particular transactional or aggregated information
from transactionals from that template over a specified date range.
http://docs.sailthru.com/api/stat
|
[
"Retrieve",
"information",
"about",
"a",
"particular",
"transactional",
"or",
"aggregated",
"information",
"from",
"transactionals",
"from",
"that",
"template",
"over",
"a",
"specified",
"date",
"range",
".",
"http",
":",
"//",
"docs",
".",
"sailthru",
".",
"com",
"/",
"api",
"/",
"stat"
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L545-L558
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
SailthruClient.receive_verify_post
|
def receive_verify_post(self, post_params):
"""
Returns true if the incoming request is an authenticated verify post.
"""
if isinstance(post_params, dict):
required_params = ['action', 'email', 'send_id', 'sig']
if not self.check_for_valid_postback_actions(required_params, post_params):
return False
else:
return False
if post_params['action'] != 'verify':
return False
sig = post_params['sig']
post_params = post_params.copy()
del post_params['sig']
if sig != get_signature_hash(post_params, self.secret):
return False
send_response = self.get_send(post_params['send_id'])
try:
send_body = send_response.get_body()
send_json = json.loads(send_body)
if 'email' not in send_body:
return False
if send_json['email'] != post_params['email']:
return False
except ValueError:
return False
return True
|
python
|
def receive_verify_post(self, post_params):
"""
Returns true if the incoming request is an authenticated verify post.
"""
if isinstance(post_params, dict):
required_params = ['action', 'email', 'send_id', 'sig']
if not self.check_for_valid_postback_actions(required_params, post_params):
return False
else:
return False
if post_params['action'] != 'verify':
return False
sig = post_params['sig']
post_params = post_params.copy()
del post_params['sig']
if sig != get_signature_hash(post_params, self.secret):
return False
send_response = self.get_send(post_params['send_id'])
try:
send_body = send_response.get_body()
send_json = json.loads(send_body)
if 'email' not in send_body:
return False
if send_json['email'] != post_params['email']:
return False
except ValueError:
return False
return True
|
[
"def",
"receive_verify_post",
"(",
"self",
",",
"post_params",
")",
":",
"if",
"isinstance",
"(",
"post_params",
",",
"dict",
")",
":",
"required_params",
"=",
"[",
"'action'",
",",
"'email'",
",",
"'send_id'",
",",
"'sig'",
"]",
"if",
"not",
"self",
".",
"check_for_valid_postback_actions",
"(",
"required_params",
",",
"post_params",
")",
":",
"return",
"False",
"else",
":",
"return",
"False",
"if",
"post_params",
"[",
"'action'",
"]",
"!=",
"'verify'",
":",
"return",
"False",
"sig",
"=",
"post_params",
"[",
"'sig'",
"]",
"post_params",
"=",
"post_params",
".",
"copy",
"(",
")",
"del",
"post_params",
"[",
"'sig'",
"]",
"if",
"sig",
"!=",
"get_signature_hash",
"(",
"post_params",
",",
"self",
".",
"secret",
")",
":",
"return",
"False",
"send_response",
"=",
"self",
".",
"get_send",
"(",
"post_params",
"[",
"'send_id'",
"]",
")",
"try",
":",
"send_body",
"=",
"send_response",
".",
"get_body",
"(",
")",
"send_json",
"=",
"json",
".",
"loads",
"(",
"send_body",
")",
"if",
"'email'",
"not",
"in",
"send_body",
":",
"return",
"False",
"if",
"send_json",
"[",
"'email'",
"]",
"!=",
"post_params",
"[",
"'email'",
"]",
":",
"return",
"False",
"except",
"ValueError",
":",
"return",
"False",
"return",
"True"
] |
Returns true if the incoming request is an authenticated verify post.
|
[
"Returns",
"true",
"if",
"the",
"incoming",
"request",
"is",
"an",
"authenticated",
"verify",
"post",
"."
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L566-L599
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
SailthruClient.receive_update_post
|
def receive_update_post(self, post_params):
"""
Update postbacks
"""
if isinstance(post_params, dict):
required_params = ['action', 'email', 'sig']
if not self.check_for_valid_postback_actions(required_params, post_params):
return False
else:
return False
if post_params['action'] != 'update':
return False
signature = post_params['sig']
post_params = post_params.copy()
del post_params['sig']
if signature != get_signature_hash(post_params, self.secret):
return False
return True
|
python
|
def receive_update_post(self, post_params):
"""
Update postbacks
"""
if isinstance(post_params, dict):
required_params = ['action', 'email', 'sig']
if not self.check_for_valid_postback_actions(required_params, post_params):
return False
else:
return False
if post_params['action'] != 'update':
return False
signature = post_params['sig']
post_params = post_params.copy()
del post_params['sig']
if signature != get_signature_hash(post_params, self.secret):
return False
return True
|
[
"def",
"receive_update_post",
"(",
"self",
",",
"post_params",
")",
":",
"if",
"isinstance",
"(",
"post_params",
",",
"dict",
")",
":",
"required_params",
"=",
"[",
"'action'",
",",
"'email'",
",",
"'sig'",
"]",
"if",
"not",
"self",
".",
"check_for_valid_postback_actions",
"(",
"required_params",
",",
"post_params",
")",
":",
"return",
"False",
"else",
":",
"return",
"False",
"if",
"post_params",
"[",
"'action'",
"]",
"!=",
"'update'",
":",
"return",
"False",
"signature",
"=",
"post_params",
"[",
"'sig'",
"]",
"post_params",
"=",
"post_params",
".",
"copy",
"(",
")",
"del",
"post_params",
"[",
"'sig'",
"]",
"if",
"signature",
"!=",
"get_signature_hash",
"(",
"post_params",
",",
"self",
".",
"secret",
")",
":",
"return",
"False",
"return",
"True"
] |
Update postbacks
|
[
"Update",
"postbacks"
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L601-L623
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
SailthruClient.receive_hardbounce_post
|
def receive_hardbounce_post(self, post_params):
"""
Hard bounce postbacks
"""
if isinstance(post_params, dict):
required_params = ['action', 'email', 'sig']
if not self.check_for_valid_postback_actions(required_params, post_params):
return False
else:
return False
if post_params['action'] != 'hardbounce':
return False
signature = post_params['sig']
post_params = post_params.copy()
del post_params['sig']
if signature != get_signature_hash(post_params, self.secret):
return False
# for sends
if 'send_id' in post_params:
send_id = post_params['send_id']
send_response = self.get_send(send_id)
if not send_response.is_ok():
return False
send_obj = send_response.get_body()
if not send_obj or 'email' not in send_obj:
return False
# for blasts
if 'blast_id' in post_params:
blast_id = post_params['blast_id']
blast_response = self.get_blast(blast_id)
if not blast_response.is_ok():
return False
blast_obj = blast_response.get_body()
if not blast_obj:
return False
return True
|
python
|
def receive_hardbounce_post(self, post_params):
"""
Hard bounce postbacks
"""
if isinstance(post_params, dict):
required_params = ['action', 'email', 'sig']
if not self.check_for_valid_postback_actions(required_params, post_params):
return False
else:
return False
if post_params['action'] != 'hardbounce':
return False
signature = post_params['sig']
post_params = post_params.copy()
del post_params['sig']
if signature != get_signature_hash(post_params, self.secret):
return False
# for sends
if 'send_id' in post_params:
send_id = post_params['send_id']
send_response = self.get_send(send_id)
if not send_response.is_ok():
return False
send_obj = send_response.get_body()
if not send_obj or 'email' not in send_obj:
return False
# for blasts
if 'blast_id' in post_params:
blast_id = post_params['blast_id']
blast_response = self.get_blast(blast_id)
if not blast_response.is_ok():
return False
blast_obj = blast_response.get_body()
if not blast_obj:
return False
return True
|
[
"def",
"receive_hardbounce_post",
"(",
"self",
",",
"post_params",
")",
":",
"if",
"isinstance",
"(",
"post_params",
",",
"dict",
")",
":",
"required_params",
"=",
"[",
"'action'",
",",
"'email'",
",",
"'sig'",
"]",
"if",
"not",
"self",
".",
"check_for_valid_postback_actions",
"(",
"required_params",
",",
"post_params",
")",
":",
"return",
"False",
"else",
":",
"return",
"False",
"if",
"post_params",
"[",
"'action'",
"]",
"!=",
"'hardbounce'",
":",
"return",
"False",
"signature",
"=",
"post_params",
"[",
"'sig'",
"]",
"post_params",
"=",
"post_params",
".",
"copy",
"(",
")",
"del",
"post_params",
"[",
"'sig'",
"]",
"if",
"signature",
"!=",
"get_signature_hash",
"(",
"post_params",
",",
"self",
".",
"secret",
")",
":",
"return",
"False",
"# for sends",
"if",
"'send_id'",
"in",
"post_params",
":",
"send_id",
"=",
"post_params",
"[",
"'send_id'",
"]",
"send_response",
"=",
"self",
".",
"get_send",
"(",
"send_id",
")",
"if",
"not",
"send_response",
".",
"is_ok",
"(",
")",
":",
"return",
"False",
"send_obj",
"=",
"send_response",
".",
"get_body",
"(",
")",
"if",
"not",
"send_obj",
"or",
"'email'",
"not",
"in",
"send_obj",
":",
"return",
"False",
"# for blasts",
"if",
"'blast_id'",
"in",
"post_params",
":",
"blast_id",
"=",
"post_params",
"[",
"'blast_id'",
"]",
"blast_response",
"=",
"self",
".",
"get_blast",
"(",
"blast_id",
")",
"if",
"not",
"blast_response",
".",
"is_ok",
"(",
")",
":",
"return",
"False",
"blast_obj",
"=",
"blast_response",
".",
"get_body",
"(",
")",
"if",
"not",
"blast_obj",
":",
"return",
"False",
"return",
"True"
] |
Hard bounce postbacks
|
[
"Hard",
"bounce",
"postbacks"
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L648-L689
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
SailthruClient.check_for_valid_postback_actions
|
def check_for_valid_postback_actions(self, required_keys, post_params):
"""
checks if post_params contain required keys
"""
for key in required_keys:
if key not in post_params:
return False
return True
|
python
|
def check_for_valid_postback_actions(self, required_keys, post_params):
"""
checks if post_params contain required keys
"""
for key in required_keys:
if key not in post_params:
return False
return True
|
[
"def",
"check_for_valid_postback_actions",
"(",
"self",
",",
"required_keys",
",",
"post_params",
")",
":",
"for",
"key",
"in",
"required_keys",
":",
"if",
"key",
"not",
"in",
"post_params",
":",
"return",
"False",
"return",
"True"
] |
checks if post_params contain required keys
|
[
"checks",
"if",
"post_params",
"contain",
"required",
"keys"
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L691-L698
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
SailthruClient.api_get
|
def api_get(self, action, data, headers=None):
"""
Perform an HTTP GET request, using the shared-secret auth hash.
@param action: API action call
@param data: dictionary values
"""
return self._api_request(action, data, 'GET', headers)
|
python
|
def api_get(self, action, data, headers=None):
"""
Perform an HTTP GET request, using the shared-secret auth hash.
@param action: API action call
@param data: dictionary values
"""
return self._api_request(action, data, 'GET', headers)
|
[
"def",
"api_get",
"(",
"self",
",",
"action",
",",
"data",
",",
"headers",
"=",
"None",
")",
":",
"return",
"self",
".",
"_api_request",
"(",
"action",
",",
"data",
",",
"'GET'",
",",
"headers",
")"
] |
Perform an HTTP GET request, using the shared-secret auth hash.
@param action: API action call
@param data: dictionary values
|
[
"Perform",
"an",
"HTTP",
"GET",
"request",
"using",
"the",
"shared",
"-",
"secret",
"auth",
"hash",
"."
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L700-L706
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
SailthruClient.api_post
|
def api_post(self, action, data, binary_data_param=None):
"""
Perform an HTTP POST request, using the shared-secret auth hash.
@param action: API action call
@param data: dictionary values
"""
binary_data_param = binary_data_param or []
if binary_data_param:
return self.api_post_multipart(action, data, binary_data_param)
else:
return self._api_request(action, data, 'POST')
|
python
|
def api_post(self, action, data, binary_data_param=None):
"""
Perform an HTTP POST request, using the shared-secret auth hash.
@param action: API action call
@param data: dictionary values
"""
binary_data_param = binary_data_param or []
if binary_data_param:
return self.api_post_multipart(action, data, binary_data_param)
else:
return self._api_request(action, data, 'POST')
|
[
"def",
"api_post",
"(",
"self",
",",
"action",
",",
"data",
",",
"binary_data_param",
"=",
"None",
")",
":",
"binary_data_param",
"=",
"binary_data_param",
"or",
"[",
"]",
"if",
"binary_data_param",
":",
"return",
"self",
".",
"api_post_multipart",
"(",
"action",
",",
"data",
",",
"binary_data_param",
")",
"else",
":",
"return",
"self",
".",
"_api_request",
"(",
"action",
",",
"data",
",",
"'POST'",
")"
] |
Perform an HTTP POST request, using the shared-secret auth hash.
@param action: API action call
@param data: dictionary values
|
[
"Perform",
"an",
"HTTP",
"POST",
"request",
"using",
"the",
"shared",
"-",
"secret",
"auth",
"hash",
"."
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L708-L718
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
SailthruClient.api_post_multipart
|
def api_post_multipart(self, action, data, binary_data_param):
"""
Perform an HTTP Multipart POST request, using the shared-secret auth hash.
@param action: API action call
@param data: dictionary values
@param: binary_data_params: array of multipart keys
"""
binary_data = {}
data = data.copy()
try:
file_handles = []
for param in binary_data_param:
if param in data:
binary_data[param] = file_handle = open(data[param], 'r')
file_handles.append(file_handle)
del data[param]
json_payload = self._prepare_json_payload(data)
return self._http_request(action, json_payload, "POST", binary_data)
finally:
for file_handle in file_handles:
file_handle.close()
|
python
|
def api_post_multipart(self, action, data, binary_data_param):
"""
Perform an HTTP Multipart POST request, using the shared-secret auth hash.
@param action: API action call
@param data: dictionary values
@param: binary_data_params: array of multipart keys
"""
binary_data = {}
data = data.copy()
try:
file_handles = []
for param in binary_data_param:
if param in data:
binary_data[param] = file_handle = open(data[param], 'r')
file_handles.append(file_handle)
del data[param]
json_payload = self._prepare_json_payload(data)
return self._http_request(action, json_payload, "POST", binary_data)
finally:
for file_handle in file_handles:
file_handle.close()
|
[
"def",
"api_post_multipart",
"(",
"self",
",",
"action",
",",
"data",
",",
"binary_data_param",
")",
":",
"binary_data",
"=",
"{",
"}",
"data",
"=",
"data",
".",
"copy",
"(",
")",
"try",
":",
"file_handles",
"=",
"[",
"]",
"for",
"param",
"in",
"binary_data_param",
":",
"if",
"param",
"in",
"data",
":",
"binary_data",
"[",
"param",
"]",
"=",
"file_handle",
"=",
"open",
"(",
"data",
"[",
"param",
"]",
",",
"'r'",
")",
"file_handles",
".",
"append",
"(",
"file_handle",
")",
"del",
"data",
"[",
"param",
"]",
"json_payload",
"=",
"self",
".",
"_prepare_json_payload",
"(",
"data",
")",
"return",
"self",
".",
"_http_request",
"(",
"action",
",",
"json_payload",
",",
"\"POST\"",
",",
"binary_data",
")",
"finally",
":",
"for",
"file_handle",
"in",
"file_handles",
":",
"file_handle",
".",
"close",
"(",
")"
] |
Perform an HTTP Multipart POST request, using the shared-secret auth hash.
@param action: API action call
@param data: dictionary values
@param: binary_data_params: array of multipart keys
|
[
"Perform",
"an",
"HTTP",
"Multipart",
"POST",
"request",
"using",
"the",
"shared",
"-",
"secret",
"auth",
"hash",
"."
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L720-L742
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
SailthruClient._api_request
|
def _api_request(self, action, data, request_type, headers=None):
"""
Make Request to Sailthru API with given data and api key, format and signature hash
"""
if 'file' in data:
file_data = {'file': open(data['file'], 'rb')}
else:
file_data = None
return self._http_request(action, self._prepare_json_payload(data), request_type, file_data, headers)
|
python
|
def _api_request(self, action, data, request_type, headers=None):
"""
Make Request to Sailthru API with given data and api key, format and signature hash
"""
if 'file' in data:
file_data = {'file': open(data['file'], 'rb')}
else:
file_data = None
return self._http_request(action, self._prepare_json_payload(data), request_type, file_data, headers)
|
[
"def",
"_api_request",
"(",
"self",
",",
"action",
",",
"data",
",",
"request_type",
",",
"headers",
"=",
"None",
")",
":",
"if",
"'file'",
"in",
"data",
":",
"file_data",
"=",
"{",
"'file'",
":",
"open",
"(",
"data",
"[",
"'file'",
"]",
",",
"'rb'",
")",
"}",
"else",
":",
"file_data",
"=",
"None",
"return",
"self",
".",
"_http_request",
"(",
"action",
",",
"self",
".",
"_prepare_json_payload",
"(",
"data",
")",
",",
"request_type",
",",
"file_data",
",",
"headers",
")"
] |
Make Request to Sailthru API with given data and api key, format and signature hash
|
[
"Make",
"Request",
"to",
"Sailthru",
"API",
"with",
"given",
"data",
"and",
"api",
"key",
"format",
"and",
"signature",
"hash"
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L752-L761
|
train
|
sailthru/sailthru-python-client
|
sailthru/sailthru_client.py
|
SailthruClient.get_last_rate_limit_info
|
def get_last_rate_limit_info(self, action, method):
"""
Get rate limit information for last API call
:param action: API endpoint
:param method: Http method, GET, POST or DELETE
:return: dict|None
"""
method = method.upper()
if (action in self.last_rate_limit_info and method in self.last_rate_limit_info[action]):
return self.last_rate_limit_info[action][method]
return None
|
python
|
def get_last_rate_limit_info(self, action, method):
"""
Get rate limit information for last API call
:param action: API endpoint
:param method: Http method, GET, POST or DELETE
:return: dict|None
"""
method = method.upper()
if (action in self.last_rate_limit_info and method in self.last_rate_limit_info[action]):
return self.last_rate_limit_info[action][method]
return None
|
[
"def",
"get_last_rate_limit_info",
"(",
"self",
",",
"action",
",",
"method",
")",
":",
"method",
"=",
"method",
".",
"upper",
"(",
")",
"if",
"(",
"action",
"in",
"self",
".",
"last_rate_limit_info",
"and",
"method",
"in",
"self",
".",
"last_rate_limit_info",
"[",
"action",
"]",
")",
":",
"return",
"self",
".",
"last_rate_limit_info",
"[",
"action",
"]",
"[",
"method",
"]",
"return",
"None"
] |
Get rate limit information for last API call
:param action: API endpoint
:param method: Http method, GET, POST or DELETE
:return: dict|None
|
[
"Get",
"rate",
"limit",
"information",
"for",
"last",
"API",
"call",
":",
"param",
"action",
":",
"API",
"endpoint",
":",
"param",
"method",
":",
"Http",
"method",
"GET",
"POST",
"or",
"DELETE",
":",
"return",
":",
"dict|None"
] |
22aa39ba0c5bddd7b8743e24ada331128c0f4f54
|
https://github.com/sailthru/sailthru-python-client/blob/22aa39ba0c5bddd7b8743e24ada331128c0f4f54/sailthru/sailthru_client.py#L781-L792
|
train
|
mesemus/django-angular-dynamic-forms
|
angular_dynamic_forms/linked_form.py
|
linked_form
|
def linked_form(viewset, form_id=None, link=None, link_id=None, method=None):
"""
When having foreign key or m2m relationships between models A and B (B has foreign key to A named parent),
we want to have a form that sits on A's viewset but creates/edits B and sets it relationship to A
automatically.
In order to do so, define linked_forms on A's viewset containing a call to linked_form as follows:
@linked_forms()
class AViewSet(AngularFormMixin, ...):
linked_forms = {
'new-b': linked_form(BViewSet, link='parent')
}
Then, there will be a form definition on <aviewset>/pk/forms/new-b, with POST/PATCH operations pointing
to an automatically created endpoint <aviewset>/pk/linked-endpoint/new-b and detail-route named "new_b"
:param viewset: the foreign viewset
:param form_id: id of the form on the foreign viewset. If unset, use the default form
:param link: either a field name on the foreign viewset or a callable that will get (foreign_instance, this_instance)
:return: an internal definition of a linked form
"""
return {
'viewset' : viewset,
'form_id' : form_id,
'link' : link,
'link_id' : link_id,
'method' : method
}
|
python
|
def linked_form(viewset, form_id=None, link=None, link_id=None, method=None):
"""
When having foreign key or m2m relationships between models A and B (B has foreign key to A named parent),
we want to have a form that sits on A's viewset but creates/edits B and sets it relationship to A
automatically.
In order to do so, define linked_forms on A's viewset containing a call to linked_form as follows:
@linked_forms()
class AViewSet(AngularFormMixin, ...):
linked_forms = {
'new-b': linked_form(BViewSet, link='parent')
}
Then, there will be a form definition on <aviewset>/pk/forms/new-b, with POST/PATCH operations pointing
to an automatically created endpoint <aviewset>/pk/linked-endpoint/new-b and detail-route named "new_b"
:param viewset: the foreign viewset
:param form_id: id of the form on the foreign viewset. If unset, use the default form
:param link: either a field name on the foreign viewset or a callable that will get (foreign_instance, this_instance)
:return: an internal definition of a linked form
"""
return {
'viewset' : viewset,
'form_id' : form_id,
'link' : link,
'link_id' : link_id,
'method' : method
}
|
[
"def",
"linked_form",
"(",
"viewset",
",",
"form_id",
"=",
"None",
",",
"link",
"=",
"None",
",",
"link_id",
"=",
"None",
",",
"method",
"=",
"None",
")",
":",
"return",
"{",
"'viewset'",
":",
"viewset",
",",
"'form_id'",
":",
"form_id",
",",
"'link'",
":",
"link",
",",
"'link_id'",
":",
"link_id",
",",
"'method'",
":",
"method",
"}"
] |
When having foreign key or m2m relationships between models A and B (B has foreign key to A named parent),
we want to have a form that sits on A's viewset but creates/edits B and sets it relationship to A
automatically.
In order to do so, define linked_forms on A's viewset containing a call to linked_form as follows:
@linked_forms()
class AViewSet(AngularFormMixin, ...):
linked_forms = {
'new-b': linked_form(BViewSet, link='parent')
}
Then, there will be a form definition on <aviewset>/pk/forms/new-b, with POST/PATCH operations pointing
to an automatically created endpoint <aviewset>/pk/linked-endpoint/new-b and detail-route named "new_b"
:param viewset: the foreign viewset
:param form_id: id of the form on the foreign viewset. If unset, use the default form
:param link: either a field name on the foreign viewset or a callable that will get (foreign_instance, this_instance)
:return: an internal definition of a linked form
|
[
"When",
"having",
"foreign",
"key",
"or",
"m2m",
"relationships",
"between",
"models",
"A",
"and",
"B",
"(",
"B",
"has",
"foreign",
"key",
"to",
"A",
"named",
"parent",
")",
"we",
"want",
"to",
"have",
"a",
"form",
"that",
"sits",
"on",
"A",
"s",
"viewset",
"but",
"creates",
"/",
"edits",
"B",
"and",
"sets",
"it",
"relationship",
"to",
"A",
"automatically",
"."
] |
8d4839a26a22c1cda0d317cbd80457bacc13365a
|
https://github.com/mesemus/django-angular-dynamic-forms/blob/8d4839a26a22c1cda0d317cbd80457bacc13365a/angular_dynamic_forms/linked_form.py#L7-L35
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/minters.py
|
oaiid_minter
|
def oaiid_minter(record_uuid, data):
"""Mint record identifiers.
:param record_uuid: The record UUID.
:param data: The record data.
:returns: A :class:`invenio_pidstore.models.PersistentIdentifier` instance.
"""
pid_value = data.get('_oai', {}).get('id')
if pid_value is None:
fetcher_name = \
current_app.config.get('OAISERVER_CONTROL_NUMBER_FETCHER', 'recid')
cn_pid = current_pidstore.fetchers[fetcher_name](record_uuid, data)
pid_value = current_app.config.get('OAISERVER_ID_PREFIX', '') + str(
cn_pid.pid_value
)
provider = OAIIDProvider.create(
object_type='rec', object_uuid=record_uuid,
pid_value=str(pid_value)
)
data.setdefault('_oai', {})
data['_oai']['id'] = provider.pid.pid_value
return provider.pid
|
python
|
def oaiid_minter(record_uuid, data):
"""Mint record identifiers.
:param record_uuid: The record UUID.
:param data: The record data.
:returns: A :class:`invenio_pidstore.models.PersistentIdentifier` instance.
"""
pid_value = data.get('_oai', {}).get('id')
if pid_value is None:
fetcher_name = \
current_app.config.get('OAISERVER_CONTROL_NUMBER_FETCHER', 'recid')
cn_pid = current_pidstore.fetchers[fetcher_name](record_uuid, data)
pid_value = current_app.config.get('OAISERVER_ID_PREFIX', '') + str(
cn_pid.pid_value
)
provider = OAIIDProvider.create(
object_type='rec', object_uuid=record_uuid,
pid_value=str(pid_value)
)
data.setdefault('_oai', {})
data['_oai']['id'] = provider.pid.pid_value
return provider.pid
|
[
"def",
"oaiid_minter",
"(",
"record_uuid",
",",
"data",
")",
":",
"pid_value",
"=",
"data",
".",
"get",
"(",
"'_oai'",
",",
"{",
"}",
")",
".",
"get",
"(",
"'id'",
")",
"if",
"pid_value",
"is",
"None",
":",
"fetcher_name",
"=",
"current_app",
".",
"config",
".",
"get",
"(",
"'OAISERVER_CONTROL_NUMBER_FETCHER'",
",",
"'recid'",
")",
"cn_pid",
"=",
"current_pidstore",
".",
"fetchers",
"[",
"fetcher_name",
"]",
"(",
"record_uuid",
",",
"data",
")",
"pid_value",
"=",
"current_app",
".",
"config",
".",
"get",
"(",
"'OAISERVER_ID_PREFIX'",
",",
"''",
")",
"+",
"str",
"(",
"cn_pid",
".",
"pid_value",
")",
"provider",
"=",
"OAIIDProvider",
".",
"create",
"(",
"object_type",
"=",
"'rec'",
",",
"object_uuid",
"=",
"record_uuid",
",",
"pid_value",
"=",
"str",
"(",
"pid_value",
")",
")",
"data",
".",
"setdefault",
"(",
"'_oai'",
",",
"{",
"}",
")",
"data",
"[",
"'_oai'",
"]",
"[",
"'id'",
"]",
"=",
"provider",
".",
"pid",
".",
"pid_value",
"return",
"provider",
".",
"pid"
] |
Mint record identifiers.
:param record_uuid: The record UUID.
:param data: The record data.
:returns: A :class:`invenio_pidstore.models.PersistentIdentifier` instance.
|
[
"Mint",
"record",
"identifiers",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/minters.py#L22-L43
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/views/server.py
|
validation_error
|
def validation_error(exception):
"""Return formatter validation error."""
messages = getattr(exception, 'messages', None)
if messages is None:
messages = getattr(exception, 'data', {'messages': None})['messages']
def extract_errors():
"""Extract errors from exception."""
if isinstance(messages, dict):
for field, message in messages.items():
if field == 'verb':
yield 'badVerb', '\n'.join(message)
else:
yield 'badArgument', '\n'.join(message)
else:
for field in exception.field_names:
if field == 'verb':
yield 'badVerb', '\n'.join(messages)
else:
yield 'badArgument', '\n'.join(messages)
if not exception.field_names:
yield 'badArgument', '\n'.join(messages)
return (etree.tostring(xml.error(extract_errors())),
422,
{'Content-Type': 'text/xml'})
|
python
|
def validation_error(exception):
"""Return formatter validation error."""
messages = getattr(exception, 'messages', None)
if messages is None:
messages = getattr(exception, 'data', {'messages': None})['messages']
def extract_errors():
"""Extract errors from exception."""
if isinstance(messages, dict):
for field, message in messages.items():
if field == 'verb':
yield 'badVerb', '\n'.join(message)
else:
yield 'badArgument', '\n'.join(message)
else:
for field in exception.field_names:
if field == 'verb':
yield 'badVerb', '\n'.join(messages)
else:
yield 'badArgument', '\n'.join(messages)
if not exception.field_names:
yield 'badArgument', '\n'.join(messages)
return (etree.tostring(xml.error(extract_errors())),
422,
{'Content-Type': 'text/xml'})
|
[
"def",
"validation_error",
"(",
"exception",
")",
":",
"messages",
"=",
"getattr",
"(",
"exception",
",",
"'messages'",
",",
"None",
")",
"if",
"messages",
"is",
"None",
":",
"messages",
"=",
"getattr",
"(",
"exception",
",",
"'data'",
",",
"{",
"'messages'",
":",
"None",
"}",
")",
"[",
"'messages'",
"]",
"def",
"extract_errors",
"(",
")",
":",
"\"\"\"Extract errors from exception.\"\"\"",
"if",
"isinstance",
"(",
"messages",
",",
"dict",
")",
":",
"for",
"field",
",",
"message",
"in",
"messages",
".",
"items",
"(",
")",
":",
"if",
"field",
"==",
"'verb'",
":",
"yield",
"'badVerb'",
",",
"'\\n'",
".",
"join",
"(",
"message",
")",
"else",
":",
"yield",
"'badArgument'",
",",
"'\\n'",
".",
"join",
"(",
"message",
")",
"else",
":",
"for",
"field",
"in",
"exception",
".",
"field_names",
":",
"if",
"field",
"==",
"'verb'",
":",
"yield",
"'badVerb'",
",",
"'\\n'",
".",
"join",
"(",
"messages",
")",
"else",
":",
"yield",
"'badArgument'",
",",
"'\\n'",
".",
"join",
"(",
"messages",
")",
"if",
"not",
"exception",
".",
"field_names",
":",
"yield",
"'badArgument'",
",",
"'\\n'",
".",
"join",
"(",
"messages",
")",
"return",
"(",
"etree",
".",
"tostring",
"(",
"xml",
".",
"error",
"(",
"extract_errors",
"(",
")",
")",
")",
",",
"422",
",",
"{",
"'Content-Type'",
":",
"'text/xml'",
"}",
")"
] |
Return formatter validation error.
|
[
"Return",
"formatter",
"validation",
"error",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/views/server.py#L33-L59
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/views/server.py
|
response
|
def response(args):
"""Response endpoint."""
e_tree = getattr(xml, args['verb'].lower())(**args)
response = make_response(etree.tostring(
e_tree,
pretty_print=True,
xml_declaration=True,
encoding='UTF-8',
))
response.headers['Content-Type'] = 'text/xml'
return response
|
python
|
def response(args):
"""Response endpoint."""
e_tree = getattr(xml, args['verb'].lower())(**args)
response = make_response(etree.tostring(
e_tree,
pretty_print=True,
xml_declaration=True,
encoding='UTF-8',
))
response.headers['Content-Type'] = 'text/xml'
return response
|
[
"def",
"response",
"(",
"args",
")",
":",
"e_tree",
"=",
"getattr",
"(",
"xml",
",",
"args",
"[",
"'verb'",
"]",
".",
"lower",
"(",
")",
")",
"(",
"*",
"*",
"args",
")",
"response",
"=",
"make_response",
"(",
"etree",
".",
"tostring",
"(",
"e_tree",
",",
"pretty_print",
"=",
"True",
",",
"xml_declaration",
"=",
"True",
",",
"encoding",
"=",
"'UTF-8'",
",",
")",
")",
"response",
".",
"headers",
"[",
"'Content-Type'",
"]",
"=",
"'text/xml'",
"return",
"response"
] |
Response endpoint.
|
[
"Response",
"endpoint",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/views/server.py#L82-L93
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/provider.py
|
OAIIDProvider.create
|
def create(cls, object_type=None, object_uuid=None, **kwargs):
"""Create a new record identifier.
:param object_type: The object type. (Default: ``None``)
:param object_uuid: The object UUID. (Default: ``None``)
"""
assert 'pid_value' in kwargs
kwargs.setdefault('status', cls.default_status)
if object_type and object_uuid:
kwargs['status'] = PIDStatus.REGISTERED
return super(OAIIDProvider, cls).create(
object_type=object_type, object_uuid=object_uuid, **kwargs)
|
python
|
def create(cls, object_type=None, object_uuid=None, **kwargs):
"""Create a new record identifier.
:param object_type: The object type. (Default: ``None``)
:param object_uuid: The object UUID. (Default: ``None``)
"""
assert 'pid_value' in kwargs
kwargs.setdefault('status', cls.default_status)
if object_type and object_uuid:
kwargs['status'] = PIDStatus.REGISTERED
return super(OAIIDProvider, cls).create(
object_type=object_type, object_uuid=object_uuid, **kwargs)
|
[
"def",
"create",
"(",
"cls",
",",
"object_type",
"=",
"None",
",",
"object_uuid",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"assert",
"'pid_value'",
"in",
"kwargs",
"kwargs",
".",
"setdefault",
"(",
"'status'",
",",
"cls",
".",
"default_status",
")",
"if",
"object_type",
"and",
"object_uuid",
":",
"kwargs",
"[",
"'status'",
"]",
"=",
"PIDStatus",
".",
"REGISTERED",
"return",
"super",
"(",
"OAIIDProvider",
",",
"cls",
")",
".",
"create",
"(",
"object_type",
"=",
"object_type",
",",
"object_uuid",
"=",
"object_uuid",
",",
"*",
"*",
"kwargs",
")"
] |
Create a new record identifier.
:param object_type: The object type. (Default: ``None``)
:param object_uuid: The object UUID. (Default: ``None``)
|
[
"Create",
"a",
"new",
"record",
"identifier",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/provider.py#L30-L43
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/percolator.py
|
_create_percolator_mapping
|
def _create_percolator_mapping(index, doc_type):
"""Update mappings with the percolator field.
.. note::
This is only needed from ElasticSearch v5 onwards, because percolators
are now just a special type of field inside mappings.
"""
if ES_VERSION[0] >= 5:
current_search_client.indices.put_mapping(
index=index, doc_type=doc_type,
body=PERCOLATOR_MAPPING, ignore=[400, 404])
|
python
|
def _create_percolator_mapping(index, doc_type):
"""Update mappings with the percolator field.
.. note::
This is only needed from ElasticSearch v5 onwards, because percolators
are now just a special type of field inside mappings.
"""
if ES_VERSION[0] >= 5:
current_search_client.indices.put_mapping(
index=index, doc_type=doc_type,
body=PERCOLATOR_MAPPING, ignore=[400, 404])
|
[
"def",
"_create_percolator_mapping",
"(",
"index",
",",
"doc_type",
")",
":",
"if",
"ES_VERSION",
"[",
"0",
"]",
">=",
"5",
":",
"current_search_client",
".",
"indices",
".",
"put_mapping",
"(",
"index",
"=",
"index",
",",
"doc_type",
"=",
"doc_type",
",",
"body",
"=",
"PERCOLATOR_MAPPING",
",",
"ignore",
"=",
"[",
"400",
",",
"404",
"]",
")"
] |
Update mappings with the percolator field.
.. note::
This is only needed from ElasticSearch v5 onwards, because percolators
are now just a special type of field inside mappings.
|
[
"Update",
"mappings",
"with",
"the",
"percolator",
"field",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/percolator.py#L23-L34
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/percolator.py
|
_percolate_query
|
def _percolate_query(index, doc_type, percolator_doc_type, document):
"""Get results for a percolate query."""
if ES_VERSION[0] in (2, 5):
results = current_search_client.percolate(
index=index, doc_type=doc_type, allow_no_indices=True,
ignore_unavailable=True, body={'doc': document}
)
return results['matches']
elif ES_VERSION[0] == 6:
results = current_search_client.search(
index=index, doc_type=percolator_doc_type, allow_no_indices=True,
ignore_unavailable=True, body={
'query': {
'percolate': {
'field': 'query',
'document_type': percolator_doc_type,
'document': document,
}
}
}
)
return results['hits']['hits']
|
python
|
def _percolate_query(index, doc_type, percolator_doc_type, document):
"""Get results for a percolate query."""
if ES_VERSION[0] in (2, 5):
results = current_search_client.percolate(
index=index, doc_type=doc_type, allow_no_indices=True,
ignore_unavailable=True, body={'doc': document}
)
return results['matches']
elif ES_VERSION[0] == 6:
results = current_search_client.search(
index=index, doc_type=percolator_doc_type, allow_no_indices=True,
ignore_unavailable=True, body={
'query': {
'percolate': {
'field': 'query',
'document_type': percolator_doc_type,
'document': document,
}
}
}
)
return results['hits']['hits']
|
[
"def",
"_percolate_query",
"(",
"index",
",",
"doc_type",
",",
"percolator_doc_type",
",",
"document",
")",
":",
"if",
"ES_VERSION",
"[",
"0",
"]",
"in",
"(",
"2",
",",
"5",
")",
":",
"results",
"=",
"current_search_client",
".",
"percolate",
"(",
"index",
"=",
"index",
",",
"doc_type",
"=",
"doc_type",
",",
"allow_no_indices",
"=",
"True",
",",
"ignore_unavailable",
"=",
"True",
",",
"body",
"=",
"{",
"'doc'",
":",
"document",
"}",
")",
"return",
"results",
"[",
"'matches'",
"]",
"elif",
"ES_VERSION",
"[",
"0",
"]",
"==",
"6",
":",
"results",
"=",
"current_search_client",
".",
"search",
"(",
"index",
"=",
"index",
",",
"doc_type",
"=",
"percolator_doc_type",
",",
"allow_no_indices",
"=",
"True",
",",
"ignore_unavailable",
"=",
"True",
",",
"body",
"=",
"{",
"'query'",
":",
"{",
"'percolate'",
":",
"{",
"'field'",
":",
"'query'",
",",
"'document_type'",
":",
"percolator_doc_type",
",",
"'document'",
":",
"document",
",",
"}",
"}",
"}",
")",
"return",
"results",
"[",
"'hits'",
"]",
"[",
"'hits'",
"]"
] |
Get results for a percolate query.
|
[
"Get",
"results",
"for",
"a",
"percolate",
"query",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/percolator.py#L37-L58
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/percolator.py
|
_new_percolator
|
def _new_percolator(spec, search_pattern):
"""Create new percolator associated with the new set."""
if spec and search_pattern:
query = query_string_parser(search_pattern=search_pattern).to_dict()
for index in current_search.mappings.keys():
# Create the percolator doc_type in the existing index for >= ES5
# TODO: Consider doing this only once in app initialization
percolator_doc_type = _get_percolator_doc_type(index)
_create_percolator_mapping(index, percolator_doc_type)
current_search_client.index(
index=index, doc_type=percolator_doc_type,
id='oaiset-{}'.format(spec),
body={'query': query}
)
|
python
|
def _new_percolator(spec, search_pattern):
"""Create new percolator associated with the new set."""
if spec and search_pattern:
query = query_string_parser(search_pattern=search_pattern).to_dict()
for index in current_search.mappings.keys():
# Create the percolator doc_type in the existing index for >= ES5
# TODO: Consider doing this only once in app initialization
percolator_doc_type = _get_percolator_doc_type(index)
_create_percolator_mapping(index, percolator_doc_type)
current_search_client.index(
index=index, doc_type=percolator_doc_type,
id='oaiset-{}'.format(spec),
body={'query': query}
)
|
[
"def",
"_new_percolator",
"(",
"spec",
",",
"search_pattern",
")",
":",
"if",
"spec",
"and",
"search_pattern",
":",
"query",
"=",
"query_string_parser",
"(",
"search_pattern",
"=",
"search_pattern",
")",
".",
"to_dict",
"(",
")",
"for",
"index",
"in",
"current_search",
".",
"mappings",
".",
"keys",
"(",
")",
":",
"# Create the percolator doc_type in the existing index for >= ES5",
"# TODO: Consider doing this only once in app initialization",
"percolator_doc_type",
"=",
"_get_percolator_doc_type",
"(",
"index",
")",
"_create_percolator_mapping",
"(",
"index",
",",
"percolator_doc_type",
")",
"current_search_client",
".",
"index",
"(",
"index",
"=",
"index",
",",
"doc_type",
"=",
"percolator_doc_type",
",",
"id",
"=",
"'oaiset-{}'",
".",
"format",
"(",
"spec",
")",
",",
"body",
"=",
"{",
"'query'",
":",
"query",
"}",
")"
] |
Create new percolator associated with the new set.
|
[
"Create",
"new",
"percolator",
"associated",
"with",
"the",
"new",
"set",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/percolator.py#L78-L91
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/percolator.py
|
_delete_percolator
|
def _delete_percolator(spec, search_pattern):
"""Delete percolator associated with the new oaiset."""
if spec:
for index in current_search.mappings.keys():
# Create the percolator doc_type in the existing index for >= ES5
percolator_doc_type = _get_percolator_doc_type(index)
_create_percolator_mapping(index, percolator_doc_type)
current_search_client.delete(
index=index, doc_type=percolator_doc_type,
id='oaiset-{}'.format(spec), ignore=[404]
)
|
python
|
def _delete_percolator(spec, search_pattern):
"""Delete percolator associated with the new oaiset."""
if spec:
for index in current_search.mappings.keys():
# Create the percolator doc_type in the existing index for >= ES5
percolator_doc_type = _get_percolator_doc_type(index)
_create_percolator_mapping(index, percolator_doc_type)
current_search_client.delete(
index=index, doc_type=percolator_doc_type,
id='oaiset-{}'.format(spec), ignore=[404]
)
|
[
"def",
"_delete_percolator",
"(",
"spec",
",",
"search_pattern",
")",
":",
"if",
"spec",
":",
"for",
"index",
"in",
"current_search",
".",
"mappings",
".",
"keys",
"(",
")",
":",
"# Create the percolator doc_type in the existing index for >= ES5",
"percolator_doc_type",
"=",
"_get_percolator_doc_type",
"(",
"index",
")",
"_create_percolator_mapping",
"(",
"index",
",",
"percolator_doc_type",
")",
"current_search_client",
".",
"delete",
"(",
"index",
"=",
"index",
",",
"doc_type",
"=",
"percolator_doc_type",
",",
"id",
"=",
"'oaiset-{}'",
".",
"format",
"(",
"spec",
")",
",",
"ignore",
"=",
"[",
"404",
"]",
")"
] |
Delete percolator associated with the new oaiset.
|
[
"Delete",
"percolator",
"associated",
"with",
"the",
"new",
"oaiset",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/percolator.py#L94-L104
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/percolator.py
|
_build_cache
|
def _build_cache():
"""Build sets cache."""
sets = current_oaiserver.sets
if sets is None:
# build sets cache
sets = current_oaiserver.sets = [
oaiset.spec for oaiset in OAISet.query.filter(
OAISet.search_pattern.is_(None)).all()]
return sets
|
python
|
def _build_cache():
"""Build sets cache."""
sets = current_oaiserver.sets
if sets is None:
# build sets cache
sets = current_oaiserver.sets = [
oaiset.spec for oaiset in OAISet.query.filter(
OAISet.search_pattern.is_(None)).all()]
return sets
|
[
"def",
"_build_cache",
"(",
")",
":",
"sets",
"=",
"current_oaiserver",
".",
"sets",
"if",
"sets",
"is",
"None",
":",
"# build sets cache",
"sets",
"=",
"current_oaiserver",
".",
"sets",
"=",
"[",
"oaiset",
".",
"spec",
"for",
"oaiset",
"in",
"OAISet",
".",
"query",
".",
"filter",
"(",
"OAISet",
".",
"search_pattern",
".",
"is_",
"(",
"None",
")",
")",
".",
"all",
"(",
")",
"]",
"return",
"sets"
] |
Build sets cache.
|
[
"Build",
"sets",
"cache",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/percolator.py#L107-L115
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/percolator.py
|
get_record_sets
|
def get_record_sets(record):
"""Find matching sets."""
# get lists of sets with search_pattern equals to None but already in the
# set list inside the record
record_sets = set(record.get('_oai', {}).get('sets', []))
for spec in _build_cache():
if spec in record_sets:
yield spec
# get list of sets that match using percolator
index, doc_type = RecordIndexer().record_to_index(record)
document = record.dumps()
percolator_doc_type = _get_percolator_doc_type(index)
_create_percolator_mapping(index, percolator_doc_type)
results = _percolate_query(index, doc_type, percolator_doc_type, document)
prefix = 'oaiset-'
prefix_len = len(prefix)
for match in results:
set_name = match['_id']
if set_name.startswith(prefix):
name = set_name[prefix_len:]
yield name
raise StopIteration
|
python
|
def get_record_sets(record):
"""Find matching sets."""
# get lists of sets with search_pattern equals to None but already in the
# set list inside the record
record_sets = set(record.get('_oai', {}).get('sets', []))
for spec in _build_cache():
if spec in record_sets:
yield spec
# get list of sets that match using percolator
index, doc_type = RecordIndexer().record_to_index(record)
document = record.dumps()
percolator_doc_type = _get_percolator_doc_type(index)
_create_percolator_mapping(index, percolator_doc_type)
results = _percolate_query(index, doc_type, percolator_doc_type, document)
prefix = 'oaiset-'
prefix_len = len(prefix)
for match in results:
set_name = match['_id']
if set_name.startswith(prefix):
name = set_name[prefix_len:]
yield name
raise StopIteration
|
[
"def",
"get_record_sets",
"(",
"record",
")",
":",
"# get lists of sets with search_pattern equals to None but already in the",
"# set list inside the record",
"record_sets",
"=",
"set",
"(",
"record",
".",
"get",
"(",
"'_oai'",
",",
"{",
"}",
")",
".",
"get",
"(",
"'sets'",
",",
"[",
"]",
")",
")",
"for",
"spec",
"in",
"_build_cache",
"(",
")",
":",
"if",
"spec",
"in",
"record_sets",
":",
"yield",
"spec",
"# get list of sets that match using percolator",
"index",
",",
"doc_type",
"=",
"RecordIndexer",
"(",
")",
".",
"record_to_index",
"(",
"record",
")",
"document",
"=",
"record",
".",
"dumps",
"(",
")",
"percolator_doc_type",
"=",
"_get_percolator_doc_type",
"(",
"index",
")",
"_create_percolator_mapping",
"(",
"index",
",",
"percolator_doc_type",
")",
"results",
"=",
"_percolate_query",
"(",
"index",
",",
"doc_type",
",",
"percolator_doc_type",
",",
"document",
")",
"prefix",
"=",
"'oaiset-'",
"prefix_len",
"=",
"len",
"(",
"prefix",
")",
"for",
"match",
"in",
"results",
":",
"set_name",
"=",
"match",
"[",
"'_id'",
"]",
"if",
"set_name",
".",
"startswith",
"(",
"prefix",
")",
":",
"name",
"=",
"set_name",
"[",
"prefix_len",
":",
"]",
"yield",
"name",
"raise",
"StopIteration"
] |
Find matching sets.
|
[
"Find",
"matching",
"sets",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/percolator.py#L118-L142
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/tasks.py
|
_records_commit
|
def _records_commit(record_ids):
"""Commit all records."""
for record_id in record_ids:
record = Record.get_record(record_id)
record.commit()
|
python
|
def _records_commit(record_ids):
"""Commit all records."""
for record_id in record_ids:
record = Record.get_record(record_id)
record.commit()
|
[
"def",
"_records_commit",
"(",
"record_ids",
")",
":",
"for",
"record_id",
"in",
"record_ids",
":",
"record",
"=",
"Record",
".",
"get_record",
"(",
"record_id",
")",
"record",
".",
"commit",
"(",
")"
] |
Commit all records.
|
[
"Commit",
"all",
"records",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/tasks.py#L25-L29
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/tasks.py
|
update_affected_records
|
def update_affected_records(spec=None, search_pattern=None):
"""Update all affected records by OAISet change.
:param spec: The record spec.
:param search_pattern: The search pattern.
"""
chunk_size = current_app.config['OAISERVER_CELERY_TASK_CHUNK_SIZE']
record_ids = get_affected_records(spec=spec, search_pattern=search_pattern)
group(
update_records_sets.s(list(filter(None, chunk)))
for chunk in zip_longest(*[iter(record_ids)] * chunk_size)
)()
|
python
|
def update_affected_records(spec=None, search_pattern=None):
"""Update all affected records by OAISet change.
:param spec: The record spec.
:param search_pattern: The search pattern.
"""
chunk_size = current_app.config['OAISERVER_CELERY_TASK_CHUNK_SIZE']
record_ids = get_affected_records(spec=spec, search_pattern=search_pattern)
group(
update_records_sets.s(list(filter(None, chunk)))
for chunk in zip_longest(*[iter(record_ids)] * chunk_size)
)()
|
[
"def",
"update_affected_records",
"(",
"spec",
"=",
"None",
",",
"search_pattern",
"=",
"None",
")",
":",
"chunk_size",
"=",
"current_app",
".",
"config",
"[",
"'OAISERVER_CELERY_TASK_CHUNK_SIZE'",
"]",
"record_ids",
"=",
"get_affected_records",
"(",
"spec",
"=",
"spec",
",",
"search_pattern",
"=",
"search_pattern",
")",
"group",
"(",
"update_records_sets",
".",
"s",
"(",
"list",
"(",
"filter",
"(",
"None",
",",
"chunk",
")",
")",
")",
"for",
"chunk",
"in",
"zip_longest",
"(",
"*",
"[",
"iter",
"(",
"record_ids",
")",
"]",
"*",
"chunk_size",
")",
")",
"(",
")"
] |
Update all affected records by OAISet change.
:param spec: The record spec.
:param search_pattern: The search pattern.
|
[
"Update",
"all",
"affected",
"records",
"by",
"OAISet",
"change",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/tasks.py#L43-L55
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/response.py
|
envelope
|
def envelope(**kwargs):
"""Create OAI-PMH envelope for response."""
e_oaipmh = Element(etree.QName(NS_OAIPMH, 'OAI-PMH'), nsmap=NSMAP)
e_oaipmh.set(etree.QName(NS_XSI, 'schemaLocation'),
'{0} {1}'.format(NS_OAIPMH, NS_OAIPMH_XSD))
e_tree = ElementTree(element=e_oaipmh)
if current_app.config['OAISERVER_XSL_URL']:
e_oaipmh.addprevious(etree.ProcessingInstruction(
'xml-stylesheet', 'type="text/xsl" href="{0}"'
.format(current_app.config['OAISERVER_XSL_URL'])))
e_responseDate = SubElement(
e_oaipmh, etree.QName(
NS_OAIPMH, 'responseDate'))
# date should be first possible moment
e_responseDate.text = datetime_to_datestamp(datetime.utcnow())
e_request = SubElement(e_oaipmh, etree.QName(NS_OAIPMH, 'request'))
for key, value in kwargs.items():
if key == 'from_' or key == 'until':
value = datetime_to_datestamp(value)
elif key == 'resumptionToken':
value = value['token']
e_request.set(key, value)
e_request.text = url_for('invenio_oaiserver.response', _external=True)
return e_tree, e_oaipmh
|
python
|
def envelope(**kwargs):
"""Create OAI-PMH envelope for response."""
e_oaipmh = Element(etree.QName(NS_OAIPMH, 'OAI-PMH'), nsmap=NSMAP)
e_oaipmh.set(etree.QName(NS_XSI, 'schemaLocation'),
'{0} {1}'.format(NS_OAIPMH, NS_OAIPMH_XSD))
e_tree = ElementTree(element=e_oaipmh)
if current_app.config['OAISERVER_XSL_URL']:
e_oaipmh.addprevious(etree.ProcessingInstruction(
'xml-stylesheet', 'type="text/xsl" href="{0}"'
.format(current_app.config['OAISERVER_XSL_URL'])))
e_responseDate = SubElement(
e_oaipmh, etree.QName(
NS_OAIPMH, 'responseDate'))
# date should be first possible moment
e_responseDate.text = datetime_to_datestamp(datetime.utcnow())
e_request = SubElement(e_oaipmh, etree.QName(NS_OAIPMH, 'request'))
for key, value in kwargs.items():
if key == 'from_' or key == 'until':
value = datetime_to_datestamp(value)
elif key == 'resumptionToken':
value = value['token']
e_request.set(key, value)
e_request.text = url_for('invenio_oaiserver.response', _external=True)
return e_tree, e_oaipmh
|
[
"def",
"envelope",
"(",
"*",
"*",
"kwargs",
")",
":",
"e_oaipmh",
"=",
"Element",
"(",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'OAI-PMH'",
")",
",",
"nsmap",
"=",
"NSMAP",
")",
"e_oaipmh",
".",
"set",
"(",
"etree",
".",
"QName",
"(",
"NS_XSI",
",",
"'schemaLocation'",
")",
",",
"'{0} {1}'",
".",
"format",
"(",
"NS_OAIPMH",
",",
"NS_OAIPMH_XSD",
")",
")",
"e_tree",
"=",
"ElementTree",
"(",
"element",
"=",
"e_oaipmh",
")",
"if",
"current_app",
".",
"config",
"[",
"'OAISERVER_XSL_URL'",
"]",
":",
"e_oaipmh",
".",
"addprevious",
"(",
"etree",
".",
"ProcessingInstruction",
"(",
"'xml-stylesheet'",
",",
"'type=\"text/xsl\" href=\"{0}\"'",
".",
"format",
"(",
"current_app",
".",
"config",
"[",
"'OAISERVER_XSL_URL'",
"]",
")",
")",
")",
"e_responseDate",
"=",
"SubElement",
"(",
"e_oaipmh",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'responseDate'",
")",
")",
"# date should be first possible moment",
"e_responseDate",
".",
"text",
"=",
"datetime_to_datestamp",
"(",
"datetime",
".",
"utcnow",
"(",
")",
")",
"e_request",
"=",
"SubElement",
"(",
"e_oaipmh",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'request'",
")",
")",
"for",
"key",
",",
"value",
"in",
"kwargs",
".",
"items",
"(",
")",
":",
"if",
"key",
"==",
"'from_'",
"or",
"key",
"==",
"'until'",
":",
"value",
"=",
"datetime_to_datestamp",
"(",
"value",
")",
"elif",
"key",
"==",
"'resumptionToken'",
":",
"value",
"=",
"value",
"[",
"'token'",
"]",
"e_request",
".",
"set",
"(",
"key",
",",
"value",
")",
"e_request",
".",
"text",
"=",
"url_for",
"(",
"'invenio_oaiserver.response'",
",",
"_external",
"=",
"True",
")",
"return",
"e_tree",
",",
"e_oaipmh"
] |
Create OAI-PMH envelope for response.
|
[
"Create",
"OAI",
"-",
"PMH",
"envelope",
"for",
"response",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/response.py#L50-L75
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/response.py
|
error
|
def error(errors):
"""Create error element."""
e_tree, e_oaipmh = envelope()
for code, message in errors:
e_error = SubElement(e_oaipmh, etree.QName(NS_OAIPMH, 'error'))
e_error.set('code', code)
e_error.text = message
return e_tree
|
python
|
def error(errors):
"""Create error element."""
e_tree, e_oaipmh = envelope()
for code, message in errors:
e_error = SubElement(e_oaipmh, etree.QName(NS_OAIPMH, 'error'))
e_error.set('code', code)
e_error.text = message
return e_tree
|
[
"def",
"error",
"(",
"errors",
")",
":",
"e_tree",
",",
"e_oaipmh",
"=",
"envelope",
"(",
")",
"for",
"code",
",",
"message",
"in",
"errors",
":",
"e_error",
"=",
"SubElement",
"(",
"e_oaipmh",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'error'",
")",
")",
"e_error",
".",
"set",
"(",
"'code'",
",",
"code",
")",
"e_error",
".",
"text",
"=",
"message",
"return",
"e_tree"
] |
Create error element.
|
[
"Create",
"error",
"element",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/response.py#L78-L85
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/response.py
|
verb
|
def verb(**kwargs):
"""Create OAI-PMH envelope for response with verb."""
e_tree, e_oaipmh = envelope(**kwargs)
e_element = SubElement(e_oaipmh, etree.QName(NS_OAIPMH, kwargs['verb']))
return e_tree, e_element
|
python
|
def verb(**kwargs):
"""Create OAI-PMH envelope for response with verb."""
e_tree, e_oaipmh = envelope(**kwargs)
e_element = SubElement(e_oaipmh, etree.QName(NS_OAIPMH, kwargs['verb']))
return e_tree, e_element
|
[
"def",
"verb",
"(",
"*",
"*",
"kwargs",
")",
":",
"e_tree",
",",
"e_oaipmh",
"=",
"envelope",
"(",
"*",
"*",
"kwargs",
")",
"e_element",
"=",
"SubElement",
"(",
"e_oaipmh",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"kwargs",
"[",
"'verb'",
"]",
")",
")",
"return",
"e_tree",
",",
"e_element"
] |
Create OAI-PMH envelope for response with verb.
|
[
"Create",
"OAI",
"-",
"PMH",
"envelope",
"for",
"response",
"with",
"verb",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/response.py#L88-L92
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/response.py
|
identify
|
def identify(**kwargs):
"""Create OAI-PMH response for verb Identify."""
cfg = current_app.config
e_tree, e_identify = verb(**kwargs)
e_repositoryName = SubElement(
e_identify, etree.QName(NS_OAIPMH, 'repositoryName'))
e_repositoryName.text = cfg['OAISERVER_REPOSITORY_NAME']
e_baseURL = SubElement(e_identify, etree.QName(NS_OAIPMH, 'baseURL'))
e_baseURL.text = url_for('invenio_oaiserver.response', _external=True)
e_protocolVersion = SubElement(e_identify,
etree.QName(NS_OAIPMH, 'protocolVersion'))
e_protocolVersion.text = cfg['OAISERVER_PROTOCOL_VERSION']
for adminEmail in cfg['OAISERVER_ADMIN_EMAILS']:
e = SubElement(e_identify, etree.QName(NS_OAIPMH, 'adminEmail'))
e.text = adminEmail
e_earliestDatestamp = SubElement(
e_identify, etree.QName(
NS_OAIPMH, 'earliestDatestamp'))
earliest_date = datetime(MINYEAR, 1, 1)
earliest_record = OAIServerSearch(
index=current_app.config['OAISERVER_RECORD_INDEX']).sort({
"_created": {"order": "asc"}})[0:1].execute()
if len(earliest_record.hits.hits) > 0:
created_date_str = earliest_record.hits.hits[0].get(
"_source", {}).get('_created')
if created_date_str:
earliest_date = arrow.get(
created_date_str).to('utc').datetime.replace(tzinfo=None)
e_earliestDatestamp.text = datetime_to_datestamp(earliest_date)
e_deletedRecord = SubElement(e_identify,
etree.QName(NS_OAIPMH, 'deletedRecord'))
e_deletedRecord.text = 'no'
e_granularity = SubElement(e_identify,
etree.QName(NS_OAIPMH, 'granularity'))
assert cfg['OAISERVER_GRANULARITY'] in DATETIME_FORMATS
e_granularity.text = cfg['OAISERVER_GRANULARITY']
compressions = cfg['OAISERVER_COMPRESSIONS']
if compressions != ['identity']:
for compression in compressions:
e_compression = SubElement(e_identify,
etree.QName(NS_OAIPMH, 'compression'))
e_compression.text = compression
for description in cfg.get('OAISERVER_DESCRIPTIONS', []):
e_description = SubElement(e_identify,
etree.QName(NS_OAIPMH, 'description'))
e_description.append(etree.fromstring(description))
return e_tree
|
python
|
def identify(**kwargs):
"""Create OAI-PMH response for verb Identify."""
cfg = current_app.config
e_tree, e_identify = verb(**kwargs)
e_repositoryName = SubElement(
e_identify, etree.QName(NS_OAIPMH, 'repositoryName'))
e_repositoryName.text = cfg['OAISERVER_REPOSITORY_NAME']
e_baseURL = SubElement(e_identify, etree.QName(NS_OAIPMH, 'baseURL'))
e_baseURL.text = url_for('invenio_oaiserver.response', _external=True)
e_protocolVersion = SubElement(e_identify,
etree.QName(NS_OAIPMH, 'protocolVersion'))
e_protocolVersion.text = cfg['OAISERVER_PROTOCOL_VERSION']
for adminEmail in cfg['OAISERVER_ADMIN_EMAILS']:
e = SubElement(e_identify, etree.QName(NS_OAIPMH, 'adminEmail'))
e.text = adminEmail
e_earliestDatestamp = SubElement(
e_identify, etree.QName(
NS_OAIPMH, 'earliestDatestamp'))
earliest_date = datetime(MINYEAR, 1, 1)
earliest_record = OAIServerSearch(
index=current_app.config['OAISERVER_RECORD_INDEX']).sort({
"_created": {"order": "asc"}})[0:1].execute()
if len(earliest_record.hits.hits) > 0:
created_date_str = earliest_record.hits.hits[0].get(
"_source", {}).get('_created')
if created_date_str:
earliest_date = arrow.get(
created_date_str).to('utc').datetime.replace(tzinfo=None)
e_earliestDatestamp.text = datetime_to_datestamp(earliest_date)
e_deletedRecord = SubElement(e_identify,
etree.QName(NS_OAIPMH, 'deletedRecord'))
e_deletedRecord.text = 'no'
e_granularity = SubElement(e_identify,
etree.QName(NS_OAIPMH, 'granularity'))
assert cfg['OAISERVER_GRANULARITY'] in DATETIME_FORMATS
e_granularity.text = cfg['OAISERVER_GRANULARITY']
compressions = cfg['OAISERVER_COMPRESSIONS']
if compressions != ['identity']:
for compression in compressions:
e_compression = SubElement(e_identify,
etree.QName(NS_OAIPMH, 'compression'))
e_compression.text = compression
for description in cfg.get('OAISERVER_DESCRIPTIONS', []):
e_description = SubElement(e_identify,
etree.QName(NS_OAIPMH, 'description'))
e_description.append(etree.fromstring(description))
return e_tree
|
[
"def",
"identify",
"(",
"*",
"*",
"kwargs",
")",
":",
"cfg",
"=",
"current_app",
".",
"config",
"e_tree",
",",
"e_identify",
"=",
"verb",
"(",
"*",
"*",
"kwargs",
")",
"e_repositoryName",
"=",
"SubElement",
"(",
"e_identify",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'repositoryName'",
")",
")",
"e_repositoryName",
".",
"text",
"=",
"cfg",
"[",
"'OAISERVER_REPOSITORY_NAME'",
"]",
"e_baseURL",
"=",
"SubElement",
"(",
"e_identify",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'baseURL'",
")",
")",
"e_baseURL",
".",
"text",
"=",
"url_for",
"(",
"'invenio_oaiserver.response'",
",",
"_external",
"=",
"True",
")",
"e_protocolVersion",
"=",
"SubElement",
"(",
"e_identify",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'protocolVersion'",
")",
")",
"e_protocolVersion",
".",
"text",
"=",
"cfg",
"[",
"'OAISERVER_PROTOCOL_VERSION'",
"]",
"for",
"adminEmail",
"in",
"cfg",
"[",
"'OAISERVER_ADMIN_EMAILS'",
"]",
":",
"e",
"=",
"SubElement",
"(",
"e_identify",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'adminEmail'",
")",
")",
"e",
".",
"text",
"=",
"adminEmail",
"e_earliestDatestamp",
"=",
"SubElement",
"(",
"e_identify",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'earliestDatestamp'",
")",
")",
"earliest_date",
"=",
"datetime",
"(",
"MINYEAR",
",",
"1",
",",
"1",
")",
"earliest_record",
"=",
"OAIServerSearch",
"(",
"index",
"=",
"current_app",
".",
"config",
"[",
"'OAISERVER_RECORD_INDEX'",
"]",
")",
".",
"sort",
"(",
"{",
"\"_created\"",
":",
"{",
"\"order\"",
":",
"\"asc\"",
"}",
"}",
")",
"[",
"0",
":",
"1",
"]",
".",
"execute",
"(",
")",
"if",
"len",
"(",
"earliest_record",
".",
"hits",
".",
"hits",
")",
">",
"0",
":",
"created_date_str",
"=",
"earliest_record",
".",
"hits",
".",
"hits",
"[",
"0",
"]",
".",
"get",
"(",
"\"_source\"",
",",
"{",
"}",
")",
".",
"get",
"(",
"'_created'",
")",
"if",
"created_date_str",
":",
"earliest_date",
"=",
"arrow",
".",
"get",
"(",
"created_date_str",
")",
".",
"to",
"(",
"'utc'",
")",
".",
"datetime",
".",
"replace",
"(",
"tzinfo",
"=",
"None",
")",
"e_earliestDatestamp",
".",
"text",
"=",
"datetime_to_datestamp",
"(",
"earliest_date",
")",
"e_deletedRecord",
"=",
"SubElement",
"(",
"e_identify",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'deletedRecord'",
")",
")",
"e_deletedRecord",
".",
"text",
"=",
"'no'",
"e_granularity",
"=",
"SubElement",
"(",
"e_identify",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'granularity'",
")",
")",
"assert",
"cfg",
"[",
"'OAISERVER_GRANULARITY'",
"]",
"in",
"DATETIME_FORMATS",
"e_granularity",
".",
"text",
"=",
"cfg",
"[",
"'OAISERVER_GRANULARITY'",
"]",
"compressions",
"=",
"cfg",
"[",
"'OAISERVER_COMPRESSIONS'",
"]",
"if",
"compressions",
"!=",
"[",
"'identity'",
"]",
":",
"for",
"compression",
"in",
"compressions",
":",
"e_compression",
"=",
"SubElement",
"(",
"e_identify",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'compression'",
")",
")",
"e_compression",
".",
"text",
"=",
"compression",
"for",
"description",
"in",
"cfg",
".",
"get",
"(",
"'OAISERVER_DESCRIPTIONS'",
",",
"[",
"]",
")",
":",
"e_description",
"=",
"SubElement",
"(",
"e_identify",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'description'",
")",
")",
"e_description",
".",
"append",
"(",
"etree",
".",
"fromstring",
"(",
"description",
")",
")",
"return",
"e_tree"
] |
Create OAI-PMH response for verb Identify.
|
[
"Create",
"OAI",
"-",
"PMH",
"response",
"for",
"verb",
"Identify",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/response.py#L95-L153
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/response.py
|
resumption_token
|
def resumption_token(parent, pagination, **kwargs):
"""Attach resumption token element to a parent."""
# Do not add resumptionToken if all results fit to the first page.
if pagination.page == 1 and not pagination.has_next:
return
token = serialize(pagination, **kwargs)
e_resumptionToken = SubElement(parent, etree.QName(NS_OAIPMH,
'resumptionToken'))
if pagination.total:
expiration_date = datetime.utcnow() + timedelta(
seconds=current_app.config[
'OAISERVER_RESUMPTION_TOKEN_EXPIRE_TIME'
]
)
e_resumptionToken.set('expirationDate', datetime_to_datestamp(
expiration_date
))
e_resumptionToken.set('cursor', str(
(pagination.page - 1) * pagination.per_page
))
e_resumptionToken.set('completeListSize', str(pagination.total))
if token:
e_resumptionToken.text = token
|
python
|
def resumption_token(parent, pagination, **kwargs):
"""Attach resumption token element to a parent."""
# Do not add resumptionToken if all results fit to the first page.
if pagination.page == 1 and not pagination.has_next:
return
token = serialize(pagination, **kwargs)
e_resumptionToken = SubElement(parent, etree.QName(NS_OAIPMH,
'resumptionToken'))
if pagination.total:
expiration_date = datetime.utcnow() + timedelta(
seconds=current_app.config[
'OAISERVER_RESUMPTION_TOKEN_EXPIRE_TIME'
]
)
e_resumptionToken.set('expirationDate', datetime_to_datestamp(
expiration_date
))
e_resumptionToken.set('cursor', str(
(pagination.page - 1) * pagination.per_page
))
e_resumptionToken.set('completeListSize', str(pagination.total))
if token:
e_resumptionToken.text = token
|
[
"def",
"resumption_token",
"(",
"parent",
",",
"pagination",
",",
"*",
"*",
"kwargs",
")",
":",
"# Do not add resumptionToken if all results fit to the first page.",
"if",
"pagination",
".",
"page",
"==",
"1",
"and",
"not",
"pagination",
".",
"has_next",
":",
"return",
"token",
"=",
"serialize",
"(",
"pagination",
",",
"*",
"*",
"kwargs",
")",
"e_resumptionToken",
"=",
"SubElement",
"(",
"parent",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'resumptionToken'",
")",
")",
"if",
"pagination",
".",
"total",
":",
"expiration_date",
"=",
"datetime",
".",
"utcnow",
"(",
")",
"+",
"timedelta",
"(",
"seconds",
"=",
"current_app",
".",
"config",
"[",
"'OAISERVER_RESUMPTION_TOKEN_EXPIRE_TIME'",
"]",
")",
"e_resumptionToken",
".",
"set",
"(",
"'expirationDate'",
",",
"datetime_to_datestamp",
"(",
"expiration_date",
")",
")",
"e_resumptionToken",
".",
"set",
"(",
"'cursor'",
",",
"str",
"(",
"(",
"pagination",
".",
"page",
"-",
"1",
")",
"*",
"pagination",
".",
"per_page",
")",
")",
"e_resumptionToken",
".",
"set",
"(",
"'completeListSize'",
",",
"str",
"(",
"pagination",
".",
"total",
")",
")",
"if",
"token",
":",
"e_resumptionToken",
".",
"text",
"=",
"token"
] |
Attach resumption token element to a parent.
|
[
"Attach",
"resumption",
"token",
"element",
"to",
"a",
"parent",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/response.py#L156-L180
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/response.py
|
listsets
|
def listsets(**kwargs):
"""Create OAI-PMH response for ListSets verb."""
e_tree, e_listsets = verb(**kwargs)
page = kwargs.get('resumptionToken', {}).get('page', 1)
size = current_app.config['OAISERVER_PAGE_SIZE']
oai_sets = OAISet.query.paginate(page=page, per_page=size, error_out=False)
for oai_set in oai_sets.items:
e_set = SubElement(e_listsets, etree.QName(NS_OAIPMH, 'set'))
e_setSpec = SubElement(e_set, etree.QName(NS_OAIPMH, 'setSpec'))
e_setSpec.text = oai_set.spec
e_setName = SubElement(e_set, etree.QName(NS_OAIPMH, 'setName'))
e_setName.text = sanitize_unicode(oai_set.name)
if oai_set.description:
e_setDescription = SubElement(e_set, etree.QName(NS_OAIPMH,
'setDescription'))
e_dc = SubElement(
e_setDescription, etree.QName(NS_OAIDC, 'dc'),
nsmap=NSMAP_DESCRIPTION
)
e_dc.set(etree.QName(NS_XSI, 'schemaLocation'), NS_OAIDC)
e_description = SubElement(e_dc, etree.QName(NS_DC, 'description'))
e_description.text = oai_set.description
resumption_token(e_listsets, oai_sets, **kwargs)
return e_tree
|
python
|
def listsets(**kwargs):
"""Create OAI-PMH response for ListSets verb."""
e_tree, e_listsets = verb(**kwargs)
page = kwargs.get('resumptionToken', {}).get('page', 1)
size = current_app.config['OAISERVER_PAGE_SIZE']
oai_sets = OAISet.query.paginate(page=page, per_page=size, error_out=False)
for oai_set in oai_sets.items:
e_set = SubElement(e_listsets, etree.QName(NS_OAIPMH, 'set'))
e_setSpec = SubElement(e_set, etree.QName(NS_OAIPMH, 'setSpec'))
e_setSpec.text = oai_set.spec
e_setName = SubElement(e_set, etree.QName(NS_OAIPMH, 'setName'))
e_setName.text = sanitize_unicode(oai_set.name)
if oai_set.description:
e_setDescription = SubElement(e_set, etree.QName(NS_OAIPMH,
'setDescription'))
e_dc = SubElement(
e_setDescription, etree.QName(NS_OAIDC, 'dc'),
nsmap=NSMAP_DESCRIPTION
)
e_dc.set(etree.QName(NS_XSI, 'schemaLocation'), NS_OAIDC)
e_description = SubElement(e_dc, etree.QName(NS_DC, 'description'))
e_description.text = oai_set.description
resumption_token(e_listsets, oai_sets, **kwargs)
return e_tree
|
[
"def",
"listsets",
"(",
"*",
"*",
"kwargs",
")",
":",
"e_tree",
",",
"e_listsets",
"=",
"verb",
"(",
"*",
"*",
"kwargs",
")",
"page",
"=",
"kwargs",
".",
"get",
"(",
"'resumptionToken'",
",",
"{",
"}",
")",
".",
"get",
"(",
"'page'",
",",
"1",
")",
"size",
"=",
"current_app",
".",
"config",
"[",
"'OAISERVER_PAGE_SIZE'",
"]",
"oai_sets",
"=",
"OAISet",
".",
"query",
".",
"paginate",
"(",
"page",
"=",
"page",
",",
"per_page",
"=",
"size",
",",
"error_out",
"=",
"False",
")",
"for",
"oai_set",
"in",
"oai_sets",
".",
"items",
":",
"e_set",
"=",
"SubElement",
"(",
"e_listsets",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'set'",
")",
")",
"e_setSpec",
"=",
"SubElement",
"(",
"e_set",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'setSpec'",
")",
")",
"e_setSpec",
".",
"text",
"=",
"oai_set",
".",
"spec",
"e_setName",
"=",
"SubElement",
"(",
"e_set",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'setName'",
")",
")",
"e_setName",
".",
"text",
"=",
"sanitize_unicode",
"(",
"oai_set",
".",
"name",
")",
"if",
"oai_set",
".",
"description",
":",
"e_setDescription",
"=",
"SubElement",
"(",
"e_set",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'setDescription'",
")",
")",
"e_dc",
"=",
"SubElement",
"(",
"e_setDescription",
",",
"etree",
".",
"QName",
"(",
"NS_OAIDC",
",",
"'dc'",
")",
",",
"nsmap",
"=",
"NSMAP_DESCRIPTION",
")",
"e_dc",
".",
"set",
"(",
"etree",
".",
"QName",
"(",
"NS_XSI",
",",
"'schemaLocation'",
")",
",",
"NS_OAIDC",
")",
"e_description",
"=",
"SubElement",
"(",
"e_dc",
",",
"etree",
".",
"QName",
"(",
"NS_DC",
",",
"'description'",
")",
")",
"e_description",
".",
"text",
"=",
"oai_set",
".",
"description",
"resumption_token",
"(",
"e_listsets",
",",
"oai_sets",
",",
"*",
"*",
"kwargs",
")",
"return",
"e_tree"
] |
Create OAI-PMH response for ListSets verb.
|
[
"Create",
"OAI",
"-",
"PMH",
"response",
"for",
"ListSets",
"verb",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/response.py#L183-L209
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/response.py
|
listmetadataformats
|
def listmetadataformats(**kwargs):
"""Create OAI-PMH response for ListMetadataFormats verb."""
cfg = current_app.config
e_tree, e_listmetadataformats = verb(**kwargs)
if 'identifier' in kwargs:
# test if record exists
OAIIDProvider.get(pid_value=kwargs['identifier'])
for prefix, metadata in cfg.get('OAISERVER_METADATA_FORMATS', {}).items():
e_metadataformat = SubElement(
e_listmetadataformats, etree.QName(NS_OAIPMH, 'metadataFormat')
)
e_metadataprefix = SubElement(
e_metadataformat, etree.QName(NS_OAIPMH, 'metadataPrefix')
)
e_metadataprefix.text = prefix
e_schema = SubElement(
e_metadataformat, etree.QName(NS_OAIPMH, 'schema')
)
e_schema.text = metadata['schema']
e_metadataNamespace = SubElement(
e_metadataformat, etree.QName(NS_OAIPMH, 'metadataNamespace')
)
e_metadataNamespace.text = metadata['namespace']
return e_tree
|
python
|
def listmetadataformats(**kwargs):
"""Create OAI-PMH response for ListMetadataFormats verb."""
cfg = current_app.config
e_tree, e_listmetadataformats = verb(**kwargs)
if 'identifier' in kwargs:
# test if record exists
OAIIDProvider.get(pid_value=kwargs['identifier'])
for prefix, metadata in cfg.get('OAISERVER_METADATA_FORMATS', {}).items():
e_metadataformat = SubElement(
e_listmetadataformats, etree.QName(NS_OAIPMH, 'metadataFormat')
)
e_metadataprefix = SubElement(
e_metadataformat, etree.QName(NS_OAIPMH, 'metadataPrefix')
)
e_metadataprefix.text = prefix
e_schema = SubElement(
e_metadataformat, etree.QName(NS_OAIPMH, 'schema')
)
e_schema.text = metadata['schema']
e_metadataNamespace = SubElement(
e_metadataformat, etree.QName(NS_OAIPMH, 'metadataNamespace')
)
e_metadataNamespace.text = metadata['namespace']
return e_tree
|
[
"def",
"listmetadataformats",
"(",
"*",
"*",
"kwargs",
")",
":",
"cfg",
"=",
"current_app",
".",
"config",
"e_tree",
",",
"e_listmetadataformats",
"=",
"verb",
"(",
"*",
"*",
"kwargs",
")",
"if",
"'identifier'",
"in",
"kwargs",
":",
"# test if record exists",
"OAIIDProvider",
".",
"get",
"(",
"pid_value",
"=",
"kwargs",
"[",
"'identifier'",
"]",
")",
"for",
"prefix",
",",
"metadata",
"in",
"cfg",
".",
"get",
"(",
"'OAISERVER_METADATA_FORMATS'",
",",
"{",
"}",
")",
".",
"items",
"(",
")",
":",
"e_metadataformat",
"=",
"SubElement",
"(",
"e_listmetadataformats",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'metadataFormat'",
")",
")",
"e_metadataprefix",
"=",
"SubElement",
"(",
"e_metadataformat",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'metadataPrefix'",
")",
")",
"e_metadataprefix",
".",
"text",
"=",
"prefix",
"e_schema",
"=",
"SubElement",
"(",
"e_metadataformat",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'schema'",
")",
")",
"e_schema",
".",
"text",
"=",
"metadata",
"[",
"'schema'",
"]",
"e_metadataNamespace",
"=",
"SubElement",
"(",
"e_metadataformat",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'metadataNamespace'",
")",
")",
"e_metadataNamespace",
".",
"text",
"=",
"metadata",
"[",
"'namespace'",
"]",
"return",
"e_tree"
] |
Create OAI-PMH response for ListMetadataFormats verb.
|
[
"Create",
"OAI",
"-",
"PMH",
"response",
"for",
"ListMetadataFormats",
"verb",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/response.py#L212-L238
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/response.py
|
header
|
def header(parent, identifier, datestamp, sets=None, deleted=False):
"""Attach ``<header/>`` element to a parent."""
e_header = SubElement(parent, etree.QName(NS_OAIPMH, 'header'))
if deleted:
e_header.set('status', 'deleted')
e_identifier = SubElement(e_header, etree.QName(NS_OAIPMH, 'identifier'))
e_identifier.text = identifier
e_datestamp = SubElement(e_header, etree.QName(NS_OAIPMH, 'datestamp'))
e_datestamp.text = datetime_to_datestamp(datestamp)
for spec in sets or []:
e = SubElement(e_header, etree.QName(NS_OAIPMH, 'setSpec'))
e.text = spec
return e_header
|
python
|
def header(parent, identifier, datestamp, sets=None, deleted=False):
"""Attach ``<header/>`` element to a parent."""
e_header = SubElement(parent, etree.QName(NS_OAIPMH, 'header'))
if deleted:
e_header.set('status', 'deleted')
e_identifier = SubElement(e_header, etree.QName(NS_OAIPMH, 'identifier'))
e_identifier.text = identifier
e_datestamp = SubElement(e_header, etree.QName(NS_OAIPMH, 'datestamp'))
e_datestamp.text = datetime_to_datestamp(datestamp)
for spec in sets or []:
e = SubElement(e_header, etree.QName(NS_OAIPMH, 'setSpec'))
e.text = spec
return e_header
|
[
"def",
"header",
"(",
"parent",
",",
"identifier",
",",
"datestamp",
",",
"sets",
"=",
"None",
",",
"deleted",
"=",
"False",
")",
":",
"e_header",
"=",
"SubElement",
"(",
"parent",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'header'",
")",
")",
"if",
"deleted",
":",
"e_header",
".",
"set",
"(",
"'status'",
",",
"'deleted'",
")",
"e_identifier",
"=",
"SubElement",
"(",
"e_header",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'identifier'",
")",
")",
"e_identifier",
".",
"text",
"=",
"identifier",
"e_datestamp",
"=",
"SubElement",
"(",
"e_header",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'datestamp'",
")",
")",
"e_datestamp",
".",
"text",
"=",
"datetime_to_datestamp",
"(",
"datestamp",
")",
"for",
"spec",
"in",
"sets",
"or",
"[",
"]",
":",
"e",
"=",
"SubElement",
"(",
"e_header",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'setSpec'",
")",
")",
"e",
".",
"text",
"=",
"spec",
"return",
"e_header"
] |
Attach ``<header/>`` element to a parent.
|
[
"Attach",
"<header",
"/",
">",
"element",
"to",
"a",
"parent",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/response.py#L241-L253
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/response.py
|
getrecord
|
def getrecord(**kwargs):
"""Create OAI-PMH response for verb Identify."""
record_dumper = serializer(kwargs['metadataPrefix'])
pid = OAIIDProvider.get(pid_value=kwargs['identifier']).pid
record = Record.get_record(pid.object_uuid)
e_tree, e_getrecord = verb(**kwargs)
e_record = SubElement(e_getrecord, etree.QName(NS_OAIPMH, 'record'))
header(
e_record,
identifier=pid.pid_value,
datestamp=record.updated,
sets=record.get('_oai', {}).get('sets', []),
)
e_metadata = SubElement(e_record,
etree.QName(NS_OAIPMH, 'metadata'))
e_metadata.append(record_dumper(pid, {'_source': record}))
return e_tree
|
python
|
def getrecord(**kwargs):
"""Create OAI-PMH response for verb Identify."""
record_dumper = serializer(kwargs['metadataPrefix'])
pid = OAIIDProvider.get(pid_value=kwargs['identifier']).pid
record = Record.get_record(pid.object_uuid)
e_tree, e_getrecord = verb(**kwargs)
e_record = SubElement(e_getrecord, etree.QName(NS_OAIPMH, 'record'))
header(
e_record,
identifier=pid.pid_value,
datestamp=record.updated,
sets=record.get('_oai', {}).get('sets', []),
)
e_metadata = SubElement(e_record,
etree.QName(NS_OAIPMH, 'metadata'))
e_metadata.append(record_dumper(pid, {'_source': record}))
return e_tree
|
[
"def",
"getrecord",
"(",
"*",
"*",
"kwargs",
")",
":",
"record_dumper",
"=",
"serializer",
"(",
"kwargs",
"[",
"'metadataPrefix'",
"]",
")",
"pid",
"=",
"OAIIDProvider",
".",
"get",
"(",
"pid_value",
"=",
"kwargs",
"[",
"'identifier'",
"]",
")",
".",
"pid",
"record",
"=",
"Record",
".",
"get_record",
"(",
"pid",
".",
"object_uuid",
")",
"e_tree",
",",
"e_getrecord",
"=",
"verb",
"(",
"*",
"*",
"kwargs",
")",
"e_record",
"=",
"SubElement",
"(",
"e_getrecord",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'record'",
")",
")",
"header",
"(",
"e_record",
",",
"identifier",
"=",
"pid",
".",
"pid_value",
",",
"datestamp",
"=",
"record",
".",
"updated",
",",
"sets",
"=",
"record",
".",
"get",
"(",
"'_oai'",
",",
"{",
"}",
")",
".",
"get",
"(",
"'sets'",
",",
"[",
"]",
")",
",",
")",
"e_metadata",
"=",
"SubElement",
"(",
"e_record",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'metadata'",
")",
")",
"e_metadata",
".",
"append",
"(",
"record_dumper",
"(",
"pid",
",",
"{",
"'_source'",
":",
"record",
"}",
")",
")",
"return",
"e_tree"
] |
Create OAI-PMH response for verb Identify.
|
[
"Create",
"OAI",
"-",
"PMH",
"response",
"for",
"verb",
"Identify",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/response.py#L256-L275
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/response.py
|
listidentifiers
|
def listidentifiers(**kwargs):
"""Create OAI-PMH response for verb ListIdentifiers."""
e_tree, e_listidentifiers = verb(**kwargs)
result = get_records(**kwargs)
for record in result.items:
pid = oaiid_fetcher(record['id'], record['json']['_source'])
header(
e_listidentifiers,
identifier=pid.pid_value,
datestamp=record['updated'],
sets=record['json']['_source'].get('_oai', {}).get('sets', []),
)
resumption_token(e_listidentifiers, result, **kwargs)
return e_tree
|
python
|
def listidentifiers(**kwargs):
"""Create OAI-PMH response for verb ListIdentifiers."""
e_tree, e_listidentifiers = verb(**kwargs)
result = get_records(**kwargs)
for record in result.items:
pid = oaiid_fetcher(record['id'], record['json']['_source'])
header(
e_listidentifiers,
identifier=pid.pid_value,
datestamp=record['updated'],
sets=record['json']['_source'].get('_oai', {}).get('sets', []),
)
resumption_token(e_listidentifiers, result, **kwargs)
return e_tree
|
[
"def",
"listidentifiers",
"(",
"*",
"*",
"kwargs",
")",
":",
"e_tree",
",",
"e_listidentifiers",
"=",
"verb",
"(",
"*",
"*",
"kwargs",
")",
"result",
"=",
"get_records",
"(",
"*",
"*",
"kwargs",
")",
"for",
"record",
"in",
"result",
".",
"items",
":",
"pid",
"=",
"oaiid_fetcher",
"(",
"record",
"[",
"'id'",
"]",
",",
"record",
"[",
"'json'",
"]",
"[",
"'_source'",
"]",
")",
"header",
"(",
"e_listidentifiers",
",",
"identifier",
"=",
"pid",
".",
"pid_value",
",",
"datestamp",
"=",
"record",
"[",
"'updated'",
"]",
",",
"sets",
"=",
"record",
"[",
"'json'",
"]",
"[",
"'_source'",
"]",
".",
"get",
"(",
"'_oai'",
",",
"{",
"}",
")",
".",
"get",
"(",
"'sets'",
",",
"[",
"]",
")",
",",
")",
"resumption_token",
"(",
"e_listidentifiers",
",",
"result",
",",
"*",
"*",
"kwargs",
")",
"return",
"e_tree"
] |
Create OAI-PMH response for verb ListIdentifiers.
|
[
"Create",
"OAI",
"-",
"PMH",
"response",
"for",
"verb",
"ListIdentifiers",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/response.py#L278-L293
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/response.py
|
listrecords
|
def listrecords(**kwargs):
"""Create OAI-PMH response for verb ListRecords."""
record_dumper = serializer(kwargs['metadataPrefix'])
e_tree, e_listrecords = verb(**kwargs)
result = get_records(**kwargs)
for record in result.items:
pid = oaiid_fetcher(record['id'], record['json']['_source'])
e_record = SubElement(e_listrecords,
etree.QName(NS_OAIPMH, 'record'))
header(
e_record,
identifier=pid.pid_value,
datestamp=record['updated'],
sets=record['json']['_source'].get('_oai', {}).get('sets', []),
)
e_metadata = SubElement(e_record, etree.QName(NS_OAIPMH, 'metadata'))
e_metadata.append(record_dumper(pid, record['json']))
resumption_token(e_listrecords, result, **kwargs)
return e_tree
|
python
|
def listrecords(**kwargs):
"""Create OAI-PMH response for verb ListRecords."""
record_dumper = serializer(kwargs['metadataPrefix'])
e_tree, e_listrecords = verb(**kwargs)
result = get_records(**kwargs)
for record in result.items:
pid = oaiid_fetcher(record['id'], record['json']['_source'])
e_record = SubElement(e_listrecords,
etree.QName(NS_OAIPMH, 'record'))
header(
e_record,
identifier=pid.pid_value,
datestamp=record['updated'],
sets=record['json']['_source'].get('_oai', {}).get('sets', []),
)
e_metadata = SubElement(e_record, etree.QName(NS_OAIPMH, 'metadata'))
e_metadata.append(record_dumper(pid, record['json']))
resumption_token(e_listrecords, result, **kwargs)
return e_tree
|
[
"def",
"listrecords",
"(",
"*",
"*",
"kwargs",
")",
":",
"record_dumper",
"=",
"serializer",
"(",
"kwargs",
"[",
"'metadataPrefix'",
"]",
")",
"e_tree",
",",
"e_listrecords",
"=",
"verb",
"(",
"*",
"*",
"kwargs",
")",
"result",
"=",
"get_records",
"(",
"*",
"*",
"kwargs",
")",
"for",
"record",
"in",
"result",
".",
"items",
":",
"pid",
"=",
"oaiid_fetcher",
"(",
"record",
"[",
"'id'",
"]",
",",
"record",
"[",
"'json'",
"]",
"[",
"'_source'",
"]",
")",
"e_record",
"=",
"SubElement",
"(",
"e_listrecords",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'record'",
")",
")",
"header",
"(",
"e_record",
",",
"identifier",
"=",
"pid",
".",
"pid_value",
",",
"datestamp",
"=",
"record",
"[",
"'updated'",
"]",
",",
"sets",
"=",
"record",
"[",
"'json'",
"]",
"[",
"'_source'",
"]",
".",
"get",
"(",
"'_oai'",
",",
"{",
"}",
")",
".",
"get",
"(",
"'sets'",
",",
"[",
"]",
")",
",",
")",
"e_metadata",
"=",
"SubElement",
"(",
"e_record",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'metadata'",
")",
")",
"e_metadata",
".",
"append",
"(",
"record_dumper",
"(",
"pid",
",",
"record",
"[",
"'json'",
"]",
")",
")",
"resumption_token",
"(",
"e_listrecords",
",",
"result",
",",
"*",
"*",
"kwargs",
")",
"return",
"e_tree"
] |
Create OAI-PMH response for verb ListRecords.
|
[
"Create",
"OAI",
"-",
"PMH",
"response",
"for",
"verb",
"ListRecords",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/response.py#L296-L317
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/fetchers.py
|
oaiid_fetcher
|
def oaiid_fetcher(record_uuid, data):
"""Fetch a record's identifier.
:param record_uuid: The record UUID.
:param data: The record data.
:returns: A :class:`invenio_pidstore.fetchers.FetchedPID` instance.
"""
pid_value = data.get('_oai', {}).get('id')
if pid_value is None:
raise PersistentIdentifierError()
return FetchedPID(
provider=OAIIDProvider,
pid_type=OAIIDProvider.pid_type,
pid_value=str(pid_value),
)
|
python
|
def oaiid_fetcher(record_uuid, data):
"""Fetch a record's identifier.
:param record_uuid: The record UUID.
:param data: The record data.
:returns: A :class:`invenio_pidstore.fetchers.FetchedPID` instance.
"""
pid_value = data.get('_oai', {}).get('id')
if pid_value is None:
raise PersistentIdentifierError()
return FetchedPID(
provider=OAIIDProvider,
pid_type=OAIIDProvider.pid_type,
pid_value=str(pid_value),
)
|
[
"def",
"oaiid_fetcher",
"(",
"record_uuid",
",",
"data",
")",
":",
"pid_value",
"=",
"data",
".",
"get",
"(",
"'_oai'",
",",
"{",
"}",
")",
".",
"get",
"(",
"'id'",
")",
"if",
"pid_value",
"is",
"None",
":",
"raise",
"PersistentIdentifierError",
"(",
")",
"return",
"FetchedPID",
"(",
"provider",
"=",
"OAIIDProvider",
",",
"pid_type",
"=",
"OAIIDProvider",
".",
"pid_type",
",",
"pid_value",
"=",
"str",
"(",
"pid_value",
")",
",",
")"
] |
Fetch a record's identifier.
:param record_uuid: The record UUID.
:param data: The record data.
:returns: A :class:`invenio_pidstore.fetchers.FetchedPID` instance.
|
[
"Fetch",
"a",
"record",
"s",
"identifier",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/fetchers.py#L19-L33
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/models.py
|
OAISet.validate_spec
|
def validate_spec(self, key, value):
"""Forbit updates of set identifier."""
if self.spec and self.spec != value:
raise OAISetSpecUpdateError("Updating spec is not allowed.")
return value
|
python
|
def validate_spec(self, key, value):
"""Forbit updates of set identifier."""
if self.spec and self.spec != value:
raise OAISetSpecUpdateError("Updating spec is not allowed.")
return value
|
[
"def",
"validate_spec",
"(",
"self",
",",
"key",
",",
"value",
")",
":",
"if",
"self",
".",
"spec",
"and",
"self",
".",
"spec",
"!=",
"value",
":",
"raise",
"OAISetSpecUpdateError",
"(",
"\"Updating spec is not allowed.\"",
")",
"return",
"value"
] |
Forbit updates of set identifier.
|
[
"Forbit",
"updates",
"of",
"set",
"identifier",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/models.py#L73-L77
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/models.py
|
OAISet.add_record
|
def add_record(self, record):
"""Add a record to the OAISet.
:param record: Record to be added.
:type record: `invenio_records.api.Record` or derivative.
"""
record.setdefault('_oai', {}).setdefault('sets', [])
assert not self.has_record(record)
record['_oai']['sets'].append(self.spec)
|
python
|
def add_record(self, record):
"""Add a record to the OAISet.
:param record: Record to be added.
:type record: `invenio_records.api.Record` or derivative.
"""
record.setdefault('_oai', {}).setdefault('sets', [])
assert not self.has_record(record)
record['_oai']['sets'].append(self.spec)
|
[
"def",
"add_record",
"(",
"self",
",",
"record",
")",
":",
"record",
".",
"setdefault",
"(",
"'_oai'",
",",
"{",
"}",
")",
".",
"setdefault",
"(",
"'sets'",
",",
"[",
"]",
")",
"assert",
"not",
"self",
".",
"has_record",
"(",
"record",
")",
"record",
"[",
"'_oai'",
"]",
"[",
"'sets'",
"]",
".",
"append",
"(",
"self",
".",
"spec",
")"
] |
Add a record to the OAISet.
:param record: Record to be added.
:type record: `invenio_records.api.Record` or derivative.
|
[
"Add",
"a",
"record",
"to",
"the",
"OAISet",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/models.py#L79-L89
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/models.py
|
OAISet.remove_record
|
def remove_record(self, record):
"""Remove a record from the OAISet.
:param record: Record to be removed.
:type record: `invenio_records.api.Record` or derivative.
"""
assert self.has_record(record)
record['_oai']['sets'] = [
s for s in record['_oai']['sets'] if s != self.spec]
|
python
|
def remove_record(self, record):
"""Remove a record from the OAISet.
:param record: Record to be removed.
:type record: `invenio_records.api.Record` or derivative.
"""
assert self.has_record(record)
record['_oai']['sets'] = [
s for s in record['_oai']['sets'] if s != self.spec]
|
[
"def",
"remove_record",
"(",
"self",
",",
"record",
")",
":",
"assert",
"self",
".",
"has_record",
"(",
"record",
")",
"record",
"[",
"'_oai'",
"]",
"[",
"'sets'",
"]",
"=",
"[",
"s",
"for",
"s",
"in",
"record",
"[",
"'_oai'",
"]",
"[",
"'sets'",
"]",
"if",
"s",
"!=",
"self",
".",
"spec",
"]"
] |
Remove a record from the OAISet.
:param record: Record to be removed.
:type record: `invenio_records.api.Record` or derivative.
|
[
"Remove",
"a",
"record",
"from",
"the",
"OAISet",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/models.py#L91-L100
|
train
|
inveniosoftware/invenio-oaiserver
|
examples/app.py
|
oaiserver
|
def oaiserver(sets, records):
"""Initialize OAI-PMH server."""
from invenio_db import db
from invenio_oaiserver.models import OAISet
from invenio_records.api import Record
# create a OAI Set
with db.session.begin_nested():
for i in range(sets):
db.session.add(OAISet(
spec='test{0}'.format(i),
name='Test{0}'.format(i),
description='test desc {0}'.format(i),
search_pattern='title_statement.title:Test{0}'.format(i),
))
# create a record
schema = {
'type': 'object',
'properties': {
'title_statement': {
'type': 'object',
'properties': {
'title': {
'type': 'string',
},
},
},
'field': {'type': 'boolean'},
},
}
with app.app_context():
indexer = RecordIndexer()
with db.session.begin_nested():
for i in range(records):
record_id = uuid.uuid4()
data = {
'title_statement': {'title': 'Test{0}'.format(i)},
'$schema': schema,
}
recid_minter(record_id, data)
oaiid_minter(record_id, data)
record = Record.create(data, id_=record_id)
indexer.index(record)
db.session.commit()
|
python
|
def oaiserver(sets, records):
"""Initialize OAI-PMH server."""
from invenio_db import db
from invenio_oaiserver.models import OAISet
from invenio_records.api import Record
# create a OAI Set
with db.session.begin_nested():
for i in range(sets):
db.session.add(OAISet(
spec='test{0}'.format(i),
name='Test{0}'.format(i),
description='test desc {0}'.format(i),
search_pattern='title_statement.title:Test{0}'.format(i),
))
# create a record
schema = {
'type': 'object',
'properties': {
'title_statement': {
'type': 'object',
'properties': {
'title': {
'type': 'string',
},
},
},
'field': {'type': 'boolean'},
},
}
with app.app_context():
indexer = RecordIndexer()
with db.session.begin_nested():
for i in range(records):
record_id = uuid.uuid4()
data = {
'title_statement': {'title': 'Test{0}'.format(i)},
'$schema': schema,
}
recid_minter(record_id, data)
oaiid_minter(record_id, data)
record = Record.create(data, id_=record_id)
indexer.index(record)
db.session.commit()
|
[
"def",
"oaiserver",
"(",
"sets",
",",
"records",
")",
":",
"from",
"invenio_db",
"import",
"db",
"from",
"invenio_oaiserver",
".",
"models",
"import",
"OAISet",
"from",
"invenio_records",
".",
"api",
"import",
"Record",
"# create a OAI Set",
"with",
"db",
".",
"session",
".",
"begin_nested",
"(",
")",
":",
"for",
"i",
"in",
"range",
"(",
"sets",
")",
":",
"db",
".",
"session",
".",
"add",
"(",
"OAISet",
"(",
"spec",
"=",
"'test{0}'",
".",
"format",
"(",
"i",
")",
",",
"name",
"=",
"'Test{0}'",
".",
"format",
"(",
"i",
")",
",",
"description",
"=",
"'test desc {0}'",
".",
"format",
"(",
"i",
")",
",",
"search_pattern",
"=",
"'title_statement.title:Test{0}'",
".",
"format",
"(",
"i",
")",
",",
")",
")",
"# create a record",
"schema",
"=",
"{",
"'type'",
":",
"'object'",
",",
"'properties'",
":",
"{",
"'title_statement'",
":",
"{",
"'type'",
":",
"'object'",
",",
"'properties'",
":",
"{",
"'title'",
":",
"{",
"'type'",
":",
"'string'",
",",
"}",
",",
"}",
",",
"}",
",",
"'field'",
":",
"{",
"'type'",
":",
"'boolean'",
"}",
",",
"}",
",",
"}",
"with",
"app",
".",
"app_context",
"(",
")",
":",
"indexer",
"=",
"RecordIndexer",
"(",
")",
"with",
"db",
".",
"session",
".",
"begin_nested",
"(",
")",
":",
"for",
"i",
"in",
"range",
"(",
"records",
")",
":",
"record_id",
"=",
"uuid",
".",
"uuid4",
"(",
")",
"data",
"=",
"{",
"'title_statement'",
":",
"{",
"'title'",
":",
"'Test{0}'",
".",
"format",
"(",
"i",
")",
"}",
",",
"'$schema'",
":",
"schema",
",",
"}",
"recid_minter",
"(",
"record_id",
",",
"data",
")",
"oaiid_minter",
"(",
"record_id",
",",
"data",
")",
"record",
"=",
"Record",
".",
"create",
"(",
"data",
",",
"id_",
"=",
"record_id",
")",
"indexer",
".",
"index",
"(",
"record",
")",
"db",
".",
"session",
".",
"commit",
"(",
")"
] |
Initialize OAI-PMH server.
|
[
"Initialize",
"OAI",
"-",
"PMH",
"server",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/examples/app.py#L92-L138
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/utils.py
|
serializer
|
def serializer(metadata_prefix):
"""Return etree_dumper instances.
:param metadata_prefix: One of the metadata identifiers configured in
``OAISERVER_METADATA_FORMATS``.
"""
metadataFormats = current_app.config['OAISERVER_METADATA_FORMATS']
serializer_ = metadataFormats[metadata_prefix]['serializer']
if isinstance(serializer_, tuple):
return partial(import_string(serializer_[0]), **serializer_[1])
return import_string(serializer_)
|
python
|
def serializer(metadata_prefix):
"""Return etree_dumper instances.
:param metadata_prefix: One of the metadata identifiers configured in
``OAISERVER_METADATA_FORMATS``.
"""
metadataFormats = current_app.config['OAISERVER_METADATA_FORMATS']
serializer_ = metadataFormats[metadata_prefix]['serializer']
if isinstance(serializer_, tuple):
return partial(import_string(serializer_[0]), **serializer_[1])
return import_string(serializer_)
|
[
"def",
"serializer",
"(",
"metadata_prefix",
")",
":",
"metadataFormats",
"=",
"current_app",
".",
"config",
"[",
"'OAISERVER_METADATA_FORMATS'",
"]",
"serializer_",
"=",
"metadataFormats",
"[",
"metadata_prefix",
"]",
"[",
"'serializer'",
"]",
"if",
"isinstance",
"(",
"serializer_",
",",
"tuple",
")",
":",
"return",
"partial",
"(",
"import_string",
"(",
"serializer_",
"[",
"0",
"]",
")",
",",
"*",
"*",
"serializer_",
"[",
"1",
"]",
")",
"return",
"import_string",
"(",
"serializer_",
")"
] |
Return etree_dumper instances.
:param metadata_prefix: One of the metadata identifiers configured in
``OAISERVER_METADATA_FORMATS``.
|
[
"Return",
"etree_dumper",
"instances",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/utils.py#L53-L63
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/utils.py
|
dumps_etree
|
def dumps_etree(pid, record, **kwargs):
"""Dump MARC21 compatible record.
:param pid: The :class:`invenio_pidstore.models.PersistentIdentifier`
instance.
:param record: The :class:`invenio_records.api.Record` instance.
:returns: A LXML Element instance.
"""
from dojson.contrib.to_marc21 import to_marc21
from dojson.contrib.to_marc21.utils import dumps_etree
return dumps_etree(to_marc21.do(record['_source']), **kwargs)
|
python
|
def dumps_etree(pid, record, **kwargs):
"""Dump MARC21 compatible record.
:param pid: The :class:`invenio_pidstore.models.PersistentIdentifier`
instance.
:param record: The :class:`invenio_records.api.Record` instance.
:returns: A LXML Element instance.
"""
from dojson.contrib.to_marc21 import to_marc21
from dojson.contrib.to_marc21.utils import dumps_etree
return dumps_etree(to_marc21.do(record['_source']), **kwargs)
|
[
"def",
"dumps_etree",
"(",
"pid",
",",
"record",
",",
"*",
"*",
"kwargs",
")",
":",
"from",
"dojson",
".",
"contrib",
".",
"to_marc21",
"import",
"to_marc21",
"from",
"dojson",
".",
"contrib",
".",
"to_marc21",
".",
"utils",
"import",
"dumps_etree",
"return",
"dumps_etree",
"(",
"to_marc21",
".",
"do",
"(",
"record",
"[",
"'_source'",
"]",
")",
",",
"*",
"*",
"kwargs",
")"
] |
Dump MARC21 compatible record.
:param pid: The :class:`invenio_pidstore.models.PersistentIdentifier`
instance.
:param record: The :class:`invenio_records.api.Record` instance.
:returns: A LXML Element instance.
|
[
"Dump",
"MARC21",
"compatible",
"record",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/utils.py#L66-L77
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/utils.py
|
eprints_description
|
def eprints_description(metadataPolicy, dataPolicy,
submissionPolicy=None, content=None):
"""Generate the eprints element for the identify response.
The eprints container is used by the e-print community to describe
the content and policies of repositories.
For the full specification and schema definition visit:
http://www.openarchives.org/OAI/2.0/guidelines-eprints.htm
"""
eprints = Element(etree.QName(NS_EPRINTS[None], 'eprints'),
nsmap=NS_EPRINTS)
eprints.set(etree.QName(ns['xsi'], 'schemaLocation'),
'{0} {1}'.format(EPRINTS_SCHEMA_LOCATION,
EPRINTS_SCHEMA_LOCATION_XSD))
if content:
contentElement = etree.Element('content')
for key, value in content.items():
contentElement.append(E(key, value))
eprints.append(contentElement)
metadataPolicyElement = etree.Element('metadataPolicy')
for key, value in metadataPolicy.items():
metadataPolicyElement.append(E(key, value))
eprints.append(metadataPolicyElement)
dataPolicyElement = etree.Element('dataPolicy')
for key, value in dataPolicy.items():
dataPolicyElement.append(E(key, value))
eprints.append(dataPolicyElement)
if submissionPolicy:
submissionPolicyElement = etree.Element('submissionPolicy')
for key, value in submissionPolicy.items():
submissionPolicyElement.append(E(key, value))
eprints.append(submissionPolicyElement)
return etree.tostring(eprints, pretty_print=True)
|
python
|
def eprints_description(metadataPolicy, dataPolicy,
submissionPolicy=None, content=None):
"""Generate the eprints element for the identify response.
The eprints container is used by the e-print community to describe
the content and policies of repositories.
For the full specification and schema definition visit:
http://www.openarchives.org/OAI/2.0/guidelines-eprints.htm
"""
eprints = Element(etree.QName(NS_EPRINTS[None], 'eprints'),
nsmap=NS_EPRINTS)
eprints.set(etree.QName(ns['xsi'], 'schemaLocation'),
'{0} {1}'.format(EPRINTS_SCHEMA_LOCATION,
EPRINTS_SCHEMA_LOCATION_XSD))
if content:
contentElement = etree.Element('content')
for key, value in content.items():
contentElement.append(E(key, value))
eprints.append(contentElement)
metadataPolicyElement = etree.Element('metadataPolicy')
for key, value in metadataPolicy.items():
metadataPolicyElement.append(E(key, value))
eprints.append(metadataPolicyElement)
dataPolicyElement = etree.Element('dataPolicy')
for key, value in dataPolicy.items():
dataPolicyElement.append(E(key, value))
eprints.append(dataPolicyElement)
if submissionPolicy:
submissionPolicyElement = etree.Element('submissionPolicy')
for key, value in submissionPolicy.items():
submissionPolicyElement.append(E(key, value))
eprints.append(submissionPolicyElement)
return etree.tostring(eprints, pretty_print=True)
|
[
"def",
"eprints_description",
"(",
"metadataPolicy",
",",
"dataPolicy",
",",
"submissionPolicy",
"=",
"None",
",",
"content",
"=",
"None",
")",
":",
"eprints",
"=",
"Element",
"(",
"etree",
".",
"QName",
"(",
"NS_EPRINTS",
"[",
"None",
"]",
",",
"'eprints'",
")",
",",
"nsmap",
"=",
"NS_EPRINTS",
")",
"eprints",
".",
"set",
"(",
"etree",
".",
"QName",
"(",
"ns",
"[",
"'xsi'",
"]",
",",
"'schemaLocation'",
")",
",",
"'{0} {1}'",
".",
"format",
"(",
"EPRINTS_SCHEMA_LOCATION",
",",
"EPRINTS_SCHEMA_LOCATION_XSD",
")",
")",
"if",
"content",
":",
"contentElement",
"=",
"etree",
".",
"Element",
"(",
"'content'",
")",
"for",
"key",
",",
"value",
"in",
"content",
".",
"items",
"(",
")",
":",
"contentElement",
".",
"append",
"(",
"E",
"(",
"key",
",",
"value",
")",
")",
"eprints",
".",
"append",
"(",
"contentElement",
")",
"metadataPolicyElement",
"=",
"etree",
".",
"Element",
"(",
"'metadataPolicy'",
")",
"for",
"key",
",",
"value",
"in",
"metadataPolicy",
".",
"items",
"(",
")",
":",
"metadataPolicyElement",
".",
"append",
"(",
"E",
"(",
"key",
",",
"value",
")",
")",
"eprints",
".",
"append",
"(",
"metadataPolicyElement",
")",
"dataPolicyElement",
"=",
"etree",
".",
"Element",
"(",
"'dataPolicy'",
")",
"for",
"key",
",",
"value",
"in",
"dataPolicy",
".",
"items",
"(",
")",
":",
"dataPolicyElement",
".",
"append",
"(",
"E",
"(",
"key",
",",
"value",
")",
")",
"eprints",
".",
"append",
"(",
"dataPolicyElement",
")",
"if",
"submissionPolicy",
":",
"submissionPolicyElement",
"=",
"etree",
".",
"Element",
"(",
"'submissionPolicy'",
")",
"for",
"key",
",",
"value",
"in",
"submissionPolicy",
".",
"items",
"(",
")",
":",
"submissionPolicyElement",
".",
"append",
"(",
"E",
"(",
"key",
",",
"value",
")",
")",
"eprints",
".",
"append",
"(",
"submissionPolicyElement",
")",
"return",
"etree",
".",
"tostring",
"(",
"eprints",
",",
"pretty_print",
"=",
"True",
")"
] |
Generate the eprints element for the identify response.
The eprints container is used by the e-print community to describe
the content and policies of repositories.
For the full specification and schema definition visit:
http://www.openarchives.org/OAI/2.0/guidelines-eprints.htm
|
[
"Generate",
"the",
"eprints",
"element",
"for",
"the",
"identify",
"response",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/utils.py#L96-L131
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/utils.py
|
oai_identifier_description
|
def oai_identifier_description(scheme, repositoryIdentifier,
delimiter, sampleIdentifier):
"""Generate the oai-identifier element for the identify response.
The OAI identifier format is intended to provide persistent resource
identifiers for items in repositories that implement OAI-PMH.
For the full specification and schema definition visit:
http://www.openarchives.org/OAI/2.0/guidelines-oai-identifier.htm
"""
oai_identifier = Element(etree.QName(NS_OAI_IDENTIFIER[None],
'oai_identifier'),
nsmap=NS_OAI_IDENTIFIER)
oai_identifier.set(etree.QName(ns['xsi'], 'schemaLocation'),
'{0} {1}'.format(OAI_IDENTIFIER_SCHEMA_LOCATION,
OAI_IDENTIFIER_SCHEMA_LOCATION_XSD))
oai_identifier.append(E('scheme', scheme))
oai_identifier.append(E('repositoryIdentifier', repositoryIdentifier))
oai_identifier.append(E('delimiter', delimiter))
oai_identifier.append(E('sampleIdentifier', sampleIdentifier))
return etree.tostring(oai_identifier, pretty_print=True)
|
python
|
def oai_identifier_description(scheme, repositoryIdentifier,
delimiter, sampleIdentifier):
"""Generate the oai-identifier element for the identify response.
The OAI identifier format is intended to provide persistent resource
identifiers for items in repositories that implement OAI-PMH.
For the full specification and schema definition visit:
http://www.openarchives.org/OAI/2.0/guidelines-oai-identifier.htm
"""
oai_identifier = Element(etree.QName(NS_OAI_IDENTIFIER[None],
'oai_identifier'),
nsmap=NS_OAI_IDENTIFIER)
oai_identifier.set(etree.QName(ns['xsi'], 'schemaLocation'),
'{0} {1}'.format(OAI_IDENTIFIER_SCHEMA_LOCATION,
OAI_IDENTIFIER_SCHEMA_LOCATION_XSD))
oai_identifier.append(E('scheme', scheme))
oai_identifier.append(E('repositoryIdentifier', repositoryIdentifier))
oai_identifier.append(E('delimiter', delimiter))
oai_identifier.append(E('sampleIdentifier', sampleIdentifier))
return etree.tostring(oai_identifier, pretty_print=True)
|
[
"def",
"oai_identifier_description",
"(",
"scheme",
",",
"repositoryIdentifier",
",",
"delimiter",
",",
"sampleIdentifier",
")",
":",
"oai_identifier",
"=",
"Element",
"(",
"etree",
".",
"QName",
"(",
"NS_OAI_IDENTIFIER",
"[",
"None",
"]",
",",
"'oai_identifier'",
")",
",",
"nsmap",
"=",
"NS_OAI_IDENTIFIER",
")",
"oai_identifier",
".",
"set",
"(",
"etree",
".",
"QName",
"(",
"ns",
"[",
"'xsi'",
"]",
",",
"'schemaLocation'",
")",
",",
"'{0} {1}'",
".",
"format",
"(",
"OAI_IDENTIFIER_SCHEMA_LOCATION",
",",
"OAI_IDENTIFIER_SCHEMA_LOCATION_XSD",
")",
")",
"oai_identifier",
".",
"append",
"(",
"E",
"(",
"'scheme'",
",",
"scheme",
")",
")",
"oai_identifier",
".",
"append",
"(",
"E",
"(",
"'repositoryIdentifier'",
",",
"repositoryIdentifier",
")",
")",
"oai_identifier",
".",
"append",
"(",
"E",
"(",
"'delimiter'",
",",
"delimiter",
")",
")",
"oai_identifier",
".",
"append",
"(",
"E",
"(",
"'sampleIdentifier'",
",",
"sampleIdentifier",
")",
")",
"return",
"etree",
".",
"tostring",
"(",
"oai_identifier",
",",
"pretty_print",
"=",
"True",
")"
] |
Generate the oai-identifier element for the identify response.
The OAI identifier format is intended to provide persistent resource
identifiers for items in repositories that implement OAI-PMH.
For the full specification and schema definition visit:
http://www.openarchives.org/OAI/2.0/guidelines-oai-identifier.htm
|
[
"Generate",
"the",
"oai",
"-",
"identifier",
"element",
"for",
"the",
"identify",
"response",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/utils.py#L134-L153
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/utils.py
|
friends_description
|
def friends_description(baseURLs):
"""Generate the friends element for the identify response.
The friends container is recommended for use by repositories
to list confederate repositories.
For the schema definition visit:
http://www.openarchives.org/OAI/2.0/guidelines-friends.htm
"""
friends = Element(etree.QName(NS_FRIENDS[None], 'friends'),
nsmap=NS_FRIENDS)
friends.set(etree.QName(ns['xsi'], 'schemaLocation'),
'{0} {1}'.format(FRIENDS_SCHEMA_LOCATION,
FRIENDS_SCHEMA_LOCATION_XSD))
for baseURL in baseURLs:
friends.append(E('baseURL', baseURL))
return etree.tostring(friends, pretty_print=True)
|
python
|
def friends_description(baseURLs):
"""Generate the friends element for the identify response.
The friends container is recommended for use by repositories
to list confederate repositories.
For the schema definition visit:
http://www.openarchives.org/OAI/2.0/guidelines-friends.htm
"""
friends = Element(etree.QName(NS_FRIENDS[None], 'friends'),
nsmap=NS_FRIENDS)
friends.set(etree.QName(ns['xsi'], 'schemaLocation'),
'{0} {1}'.format(FRIENDS_SCHEMA_LOCATION,
FRIENDS_SCHEMA_LOCATION_XSD))
for baseURL in baseURLs:
friends.append(E('baseURL', baseURL))
return etree.tostring(friends, pretty_print=True)
|
[
"def",
"friends_description",
"(",
"baseURLs",
")",
":",
"friends",
"=",
"Element",
"(",
"etree",
".",
"QName",
"(",
"NS_FRIENDS",
"[",
"None",
"]",
",",
"'friends'",
")",
",",
"nsmap",
"=",
"NS_FRIENDS",
")",
"friends",
".",
"set",
"(",
"etree",
".",
"QName",
"(",
"ns",
"[",
"'xsi'",
"]",
",",
"'schemaLocation'",
")",
",",
"'{0} {1}'",
".",
"format",
"(",
"FRIENDS_SCHEMA_LOCATION",
",",
"FRIENDS_SCHEMA_LOCATION_XSD",
")",
")",
"for",
"baseURL",
"in",
"baseURLs",
":",
"friends",
".",
"append",
"(",
"E",
"(",
"'baseURL'",
",",
"baseURL",
")",
")",
"return",
"etree",
".",
"tostring",
"(",
"friends",
",",
"pretty_print",
"=",
"True",
")"
] |
Generate the friends element for the identify response.
The friends container is recommended for use by repositories
to list confederate repositories.
For the schema definition visit:
http://www.openarchives.org/OAI/2.0/guidelines-friends.htm
|
[
"Generate",
"the",
"friends",
"element",
"for",
"the",
"identify",
"response",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/utils.py#L156-L171
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/receivers.py
|
after_insert_oai_set
|
def after_insert_oai_set(mapper, connection, target):
"""Update records on OAISet insertion."""
_new_percolator(spec=target.spec, search_pattern=target.search_pattern)
sleep(2)
update_affected_records.delay(
search_pattern=target.search_pattern
)
|
python
|
def after_insert_oai_set(mapper, connection, target):
"""Update records on OAISet insertion."""
_new_percolator(spec=target.spec, search_pattern=target.search_pattern)
sleep(2)
update_affected_records.delay(
search_pattern=target.search_pattern
)
|
[
"def",
"after_insert_oai_set",
"(",
"mapper",
",",
"connection",
",",
"target",
")",
":",
"_new_percolator",
"(",
"spec",
"=",
"target",
".",
"spec",
",",
"search_pattern",
"=",
"target",
".",
"search_pattern",
")",
"sleep",
"(",
"2",
")",
"update_affected_records",
".",
"delay",
"(",
"search_pattern",
"=",
"target",
".",
"search_pattern",
")"
] |
Update records on OAISet insertion.
|
[
"Update",
"records",
"on",
"OAISet",
"insertion",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/receivers.py#L36-L42
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/receivers.py
|
after_update_oai_set
|
def after_update_oai_set(mapper, connection, target):
"""Update records on OAISet update."""
_delete_percolator(spec=target.spec, search_pattern=target.search_pattern)
_new_percolator(spec=target.spec, search_pattern=target.search_pattern)
sleep(2)
update_affected_records.delay(
spec=target.spec, search_pattern=target.search_pattern
)
|
python
|
def after_update_oai_set(mapper, connection, target):
"""Update records on OAISet update."""
_delete_percolator(spec=target.spec, search_pattern=target.search_pattern)
_new_percolator(spec=target.spec, search_pattern=target.search_pattern)
sleep(2)
update_affected_records.delay(
spec=target.spec, search_pattern=target.search_pattern
)
|
[
"def",
"after_update_oai_set",
"(",
"mapper",
",",
"connection",
",",
"target",
")",
":",
"_delete_percolator",
"(",
"spec",
"=",
"target",
".",
"spec",
",",
"search_pattern",
"=",
"target",
".",
"search_pattern",
")",
"_new_percolator",
"(",
"spec",
"=",
"target",
".",
"spec",
",",
"search_pattern",
"=",
"target",
".",
"search_pattern",
")",
"sleep",
"(",
"2",
")",
"update_affected_records",
".",
"delay",
"(",
"spec",
"=",
"target",
".",
"spec",
",",
"search_pattern",
"=",
"target",
".",
"search_pattern",
")"
] |
Update records on OAISet update.
|
[
"Update",
"records",
"on",
"OAISet",
"update",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/receivers.py#L45-L52
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/receivers.py
|
after_delete_oai_set
|
def after_delete_oai_set(mapper, connection, target):
"""Update records on OAISet deletion."""
_delete_percolator(spec=target.spec, search_pattern=target.search_pattern)
sleep(2)
update_affected_records.delay(
spec=target.spec
)
|
python
|
def after_delete_oai_set(mapper, connection, target):
"""Update records on OAISet deletion."""
_delete_percolator(spec=target.spec, search_pattern=target.search_pattern)
sleep(2)
update_affected_records.delay(
spec=target.spec
)
|
[
"def",
"after_delete_oai_set",
"(",
"mapper",
",",
"connection",
",",
"target",
")",
":",
"_delete_percolator",
"(",
"spec",
"=",
"target",
".",
"spec",
",",
"search_pattern",
"=",
"target",
".",
"search_pattern",
")",
"sleep",
"(",
"2",
")",
"update_affected_records",
".",
"delay",
"(",
"spec",
"=",
"target",
".",
"spec",
")"
] |
Update records on OAISet deletion.
|
[
"Update",
"records",
"on",
"OAISet",
"deletion",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/receivers.py#L55-L61
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/query.py
|
query_string_parser
|
def query_string_parser(search_pattern):
"""Elasticsearch query string parser."""
if not hasattr(current_oaiserver, 'query_parser'):
query_parser = current_app.config['OAISERVER_QUERY_PARSER']
if isinstance(query_parser, six.string_types):
query_parser = import_string(query_parser)
current_oaiserver.query_parser = query_parser
return current_oaiserver.query_parser('query_string', query=search_pattern)
|
python
|
def query_string_parser(search_pattern):
"""Elasticsearch query string parser."""
if not hasattr(current_oaiserver, 'query_parser'):
query_parser = current_app.config['OAISERVER_QUERY_PARSER']
if isinstance(query_parser, six.string_types):
query_parser = import_string(query_parser)
current_oaiserver.query_parser = query_parser
return current_oaiserver.query_parser('query_string', query=search_pattern)
|
[
"def",
"query_string_parser",
"(",
"search_pattern",
")",
":",
"if",
"not",
"hasattr",
"(",
"current_oaiserver",
",",
"'query_parser'",
")",
":",
"query_parser",
"=",
"current_app",
".",
"config",
"[",
"'OAISERVER_QUERY_PARSER'",
"]",
"if",
"isinstance",
"(",
"query_parser",
",",
"six",
".",
"string_types",
")",
":",
"query_parser",
"=",
"import_string",
"(",
"query_parser",
")",
"current_oaiserver",
".",
"query_parser",
"=",
"query_parser",
"return",
"current_oaiserver",
".",
"query_parser",
"(",
"'query_string'",
",",
"query",
"=",
"search_pattern",
")"
] |
Elasticsearch query string parser.
|
[
"Elasticsearch",
"query",
"string",
"parser",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/query.py#L20-L27
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/query.py
|
get_affected_records
|
def get_affected_records(spec=None, search_pattern=None):
"""Get list of affected records.
:param spec: The record spec.
:param search_pattern: The search pattern.
:returns: An iterator to lazily find results.
"""
# spec pattern query
# ---------- ---------- -------
# None None None
# None Y Y
# X None X
# X '' X
# X Y X OR Y
if spec is None and search_pattern is None:
raise StopIteration
queries = []
if spec is not None:
queries.append(Q('match', **{'_oai.sets': spec}))
if search_pattern:
queries.append(query_string_parser(search_pattern=search_pattern))
search = OAIServerSearch(
index=current_app.config['OAISERVER_RECORD_INDEX'],
).query(Q('bool', should=queries))
for result in search.scan():
yield result.meta.id
|
python
|
def get_affected_records(spec=None, search_pattern=None):
"""Get list of affected records.
:param spec: The record spec.
:param search_pattern: The search pattern.
:returns: An iterator to lazily find results.
"""
# spec pattern query
# ---------- ---------- -------
# None None None
# None Y Y
# X None X
# X '' X
# X Y X OR Y
if spec is None and search_pattern is None:
raise StopIteration
queries = []
if spec is not None:
queries.append(Q('match', **{'_oai.sets': spec}))
if search_pattern:
queries.append(query_string_parser(search_pattern=search_pattern))
search = OAIServerSearch(
index=current_app.config['OAISERVER_RECORD_INDEX'],
).query(Q('bool', should=queries))
for result in search.scan():
yield result.meta.id
|
[
"def",
"get_affected_records",
"(",
"spec",
"=",
"None",
",",
"search_pattern",
"=",
"None",
")",
":",
"# spec pattern query",
"# ---------- ---------- -------",
"# None None None",
"# None Y Y",
"# X None X",
"# X '' X",
"# X Y X OR Y",
"if",
"spec",
"is",
"None",
"and",
"search_pattern",
"is",
"None",
":",
"raise",
"StopIteration",
"queries",
"=",
"[",
"]",
"if",
"spec",
"is",
"not",
"None",
":",
"queries",
".",
"append",
"(",
"Q",
"(",
"'match'",
",",
"*",
"*",
"{",
"'_oai.sets'",
":",
"spec",
"}",
")",
")",
"if",
"search_pattern",
":",
"queries",
".",
"append",
"(",
"query_string_parser",
"(",
"search_pattern",
"=",
"search_pattern",
")",
")",
"search",
"=",
"OAIServerSearch",
"(",
"index",
"=",
"current_app",
".",
"config",
"[",
"'OAISERVER_RECORD_INDEX'",
"]",
",",
")",
".",
"query",
"(",
"Q",
"(",
"'bool'",
",",
"should",
"=",
"queries",
")",
")",
"for",
"result",
"in",
"search",
".",
"scan",
"(",
")",
":",
"yield",
"result",
".",
"meta",
".",
"id"
] |
Get list of affected records.
:param spec: The record spec.
:param search_pattern: The search pattern.
:returns: An iterator to lazily find results.
|
[
"Get",
"list",
"of",
"affected",
"records",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/query.py#L39-L70
|
train
|
inveniosoftware/invenio-oaiserver
|
invenio_oaiserver/query.py
|
get_records
|
def get_records(**kwargs):
"""Get records paginated."""
page_ = kwargs.get('resumptionToken', {}).get('page', 1)
size_ = current_app.config['OAISERVER_PAGE_SIZE']
scroll = current_app.config['OAISERVER_RESUMPTION_TOKEN_EXPIRE_TIME']
scroll_id = kwargs.get('resumptionToken', {}).get('scroll_id')
if scroll_id is None:
search = OAIServerSearch(
index=current_app.config['OAISERVER_RECORD_INDEX'],
).params(
scroll='{0}s'.format(scroll),
).extra(
version=True,
)[(page_-1)*size_:page_*size_]
if 'set' in kwargs:
search = search.query('match', **{'_oai.sets': kwargs['set']})
time_range = {}
if 'from_' in kwargs:
time_range['gte'] = kwargs['from_']
if 'until' in kwargs:
time_range['lte'] = kwargs['until']
if time_range:
search = search.filter('range', **{'_updated': time_range})
response = search.execute().to_dict()
else:
response = current_search_client.scroll(
scroll_id=scroll_id,
scroll='{0}s'.format(scroll),
)
class Pagination(object):
"""Dummy pagination class."""
page = page_
per_page = size_
def __init__(self, response):
"""Initilize pagination."""
self.response = response
self.total = response['hits']['total']
self._scroll_id = response.get('_scroll_id')
# clean descriptor on last page
if not self.has_next:
current_search_client.clear_scroll(
scroll_id=self._scroll_id
)
self._scroll_id = None
@cached_property
def has_next(self):
"""Return True if there is next page."""
return self.page * self.per_page <= self.total
@cached_property
def next_num(self):
"""Return next page number."""
return self.page + 1 if self.has_next else None
@property
def items(self):
"""Return iterator."""
from datetime import datetime
for result in self.response['hits']['hits']:
if '_oai' in result['_source']:
yield {
'id': result['_id'],
'json': result,
'updated': datetime.strptime(
result['_source']['_updated'][:19],
'%Y-%m-%dT%H:%M:%S'
),
}
return Pagination(response)
|
python
|
def get_records(**kwargs):
"""Get records paginated."""
page_ = kwargs.get('resumptionToken', {}).get('page', 1)
size_ = current_app.config['OAISERVER_PAGE_SIZE']
scroll = current_app.config['OAISERVER_RESUMPTION_TOKEN_EXPIRE_TIME']
scroll_id = kwargs.get('resumptionToken', {}).get('scroll_id')
if scroll_id is None:
search = OAIServerSearch(
index=current_app.config['OAISERVER_RECORD_INDEX'],
).params(
scroll='{0}s'.format(scroll),
).extra(
version=True,
)[(page_-1)*size_:page_*size_]
if 'set' in kwargs:
search = search.query('match', **{'_oai.sets': kwargs['set']})
time_range = {}
if 'from_' in kwargs:
time_range['gte'] = kwargs['from_']
if 'until' in kwargs:
time_range['lte'] = kwargs['until']
if time_range:
search = search.filter('range', **{'_updated': time_range})
response = search.execute().to_dict()
else:
response = current_search_client.scroll(
scroll_id=scroll_id,
scroll='{0}s'.format(scroll),
)
class Pagination(object):
"""Dummy pagination class."""
page = page_
per_page = size_
def __init__(self, response):
"""Initilize pagination."""
self.response = response
self.total = response['hits']['total']
self._scroll_id = response.get('_scroll_id')
# clean descriptor on last page
if not self.has_next:
current_search_client.clear_scroll(
scroll_id=self._scroll_id
)
self._scroll_id = None
@cached_property
def has_next(self):
"""Return True if there is next page."""
return self.page * self.per_page <= self.total
@cached_property
def next_num(self):
"""Return next page number."""
return self.page + 1 if self.has_next else None
@property
def items(self):
"""Return iterator."""
from datetime import datetime
for result in self.response['hits']['hits']:
if '_oai' in result['_source']:
yield {
'id': result['_id'],
'json': result,
'updated': datetime.strptime(
result['_source']['_updated'][:19],
'%Y-%m-%dT%H:%M:%S'
),
}
return Pagination(response)
|
[
"def",
"get_records",
"(",
"*",
"*",
"kwargs",
")",
":",
"page_",
"=",
"kwargs",
".",
"get",
"(",
"'resumptionToken'",
",",
"{",
"}",
")",
".",
"get",
"(",
"'page'",
",",
"1",
")",
"size_",
"=",
"current_app",
".",
"config",
"[",
"'OAISERVER_PAGE_SIZE'",
"]",
"scroll",
"=",
"current_app",
".",
"config",
"[",
"'OAISERVER_RESUMPTION_TOKEN_EXPIRE_TIME'",
"]",
"scroll_id",
"=",
"kwargs",
".",
"get",
"(",
"'resumptionToken'",
",",
"{",
"}",
")",
".",
"get",
"(",
"'scroll_id'",
")",
"if",
"scroll_id",
"is",
"None",
":",
"search",
"=",
"OAIServerSearch",
"(",
"index",
"=",
"current_app",
".",
"config",
"[",
"'OAISERVER_RECORD_INDEX'",
"]",
",",
")",
".",
"params",
"(",
"scroll",
"=",
"'{0}s'",
".",
"format",
"(",
"scroll",
")",
",",
")",
".",
"extra",
"(",
"version",
"=",
"True",
",",
")",
"[",
"(",
"page_",
"-",
"1",
")",
"*",
"size_",
":",
"page_",
"*",
"size_",
"]",
"if",
"'set'",
"in",
"kwargs",
":",
"search",
"=",
"search",
".",
"query",
"(",
"'match'",
",",
"*",
"*",
"{",
"'_oai.sets'",
":",
"kwargs",
"[",
"'set'",
"]",
"}",
")",
"time_range",
"=",
"{",
"}",
"if",
"'from_'",
"in",
"kwargs",
":",
"time_range",
"[",
"'gte'",
"]",
"=",
"kwargs",
"[",
"'from_'",
"]",
"if",
"'until'",
"in",
"kwargs",
":",
"time_range",
"[",
"'lte'",
"]",
"=",
"kwargs",
"[",
"'until'",
"]",
"if",
"time_range",
":",
"search",
"=",
"search",
".",
"filter",
"(",
"'range'",
",",
"*",
"*",
"{",
"'_updated'",
":",
"time_range",
"}",
")",
"response",
"=",
"search",
".",
"execute",
"(",
")",
".",
"to_dict",
"(",
")",
"else",
":",
"response",
"=",
"current_search_client",
".",
"scroll",
"(",
"scroll_id",
"=",
"scroll_id",
",",
"scroll",
"=",
"'{0}s'",
".",
"format",
"(",
"scroll",
")",
",",
")",
"class",
"Pagination",
"(",
"object",
")",
":",
"\"\"\"Dummy pagination class.\"\"\"",
"page",
"=",
"page_",
"per_page",
"=",
"size_",
"def",
"__init__",
"(",
"self",
",",
"response",
")",
":",
"\"\"\"Initilize pagination.\"\"\"",
"self",
".",
"response",
"=",
"response",
"self",
".",
"total",
"=",
"response",
"[",
"'hits'",
"]",
"[",
"'total'",
"]",
"self",
".",
"_scroll_id",
"=",
"response",
".",
"get",
"(",
"'_scroll_id'",
")",
"# clean descriptor on last page",
"if",
"not",
"self",
".",
"has_next",
":",
"current_search_client",
".",
"clear_scroll",
"(",
"scroll_id",
"=",
"self",
".",
"_scroll_id",
")",
"self",
".",
"_scroll_id",
"=",
"None",
"@",
"cached_property",
"def",
"has_next",
"(",
"self",
")",
":",
"\"\"\"Return True if there is next page.\"\"\"",
"return",
"self",
".",
"page",
"*",
"self",
".",
"per_page",
"<=",
"self",
".",
"total",
"@",
"cached_property",
"def",
"next_num",
"(",
"self",
")",
":",
"\"\"\"Return next page number.\"\"\"",
"return",
"self",
".",
"page",
"+",
"1",
"if",
"self",
".",
"has_next",
"else",
"None",
"@",
"property",
"def",
"items",
"(",
"self",
")",
":",
"\"\"\"Return iterator.\"\"\"",
"from",
"datetime",
"import",
"datetime",
"for",
"result",
"in",
"self",
".",
"response",
"[",
"'hits'",
"]",
"[",
"'hits'",
"]",
":",
"if",
"'_oai'",
"in",
"result",
"[",
"'_source'",
"]",
":",
"yield",
"{",
"'id'",
":",
"result",
"[",
"'_id'",
"]",
",",
"'json'",
":",
"result",
",",
"'updated'",
":",
"datetime",
".",
"strptime",
"(",
"result",
"[",
"'_source'",
"]",
"[",
"'_updated'",
"]",
"[",
":",
"19",
"]",
",",
"'%Y-%m-%dT%H:%M:%S'",
")",
",",
"}",
"return",
"Pagination",
"(",
"response",
")"
] |
Get records paginated.
|
[
"Get",
"records",
"paginated",
"."
] |
eae765e32bd816ddc5612d4b281caf205518b512
|
https://github.com/inveniosoftware/invenio-oaiserver/blob/eae765e32bd816ddc5612d4b281caf205518b512/invenio_oaiserver/query.py#L73-L151
|
train
|
AaronWatters/jp_proxy_widget
|
jp_proxy_widget/js_context.py
|
get_file_path
|
def get_file_path(filename, local=True, relative_to_module=None, my_dir=my_dir):
"""
Look for an existing path matching filename.
Try to resolve relative to the module location if the path cannot by found
using "normal" resolution.
"""
# override my_dir if module is provided
if relative_to_module is not None:
my_dir = os.path.dirname(relative_to_module.__file__)
user_path = result = filename
if local:
user_path = os.path.expanduser(filename)
result = os.path.abspath(user_path)
if os.path.exists(result):
return result # The file was found normally
# otherwise look relative to the module.
result = os.path.join(my_dir, filename)
assert os.path.exists(result), "no such file " + repr((filename, result, user_path))
return result
|
python
|
def get_file_path(filename, local=True, relative_to_module=None, my_dir=my_dir):
"""
Look for an existing path matching filename.
Try to resolve relative to the module location if the path cannot by found
using "normal" resolution.
"""
# override my_dir if module is provided
if relative_to_module is not None:
my_dir = os.path.dirname(relative_to_module.__file__)
user_path = result = filename
if local:
user_path = os.path.expanduser(filename)
result = os.path.abspath(user_path)
if os.path.exists(result):
return result # The file was found normally
# otherwise look relative to the module.
result = os.path.join(my_dir, filename)
assert os.path.exists(result), "no such file " + repr((filename, result, user_path))
return result
|
[
"def",
"get_file_path",
"(",
"filename",
",",
"local",
"=",
"True",
",",
"relative_to_module",
"=",
"None",
",",
"my_dir",
"=",
"my_dir",
")",
":",
"# override my_dir if module is provided",
"if",
"relative_to_module",
"is",
"not",
"None",
":",
"my_dir",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"relative_to_module",
".",
"__file__",
")",
"user_path",
"=",
"result",
"=",
"filename",
"if",
"local",
":",
"user_path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"filename",
")",
"result",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"user_path",
")",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"result",
")",
":",
"return",
"result",
"# The file was found normally",
"# otherwise look relative to the module.",
"result",
"=",
"os",
".",
"path",
".",
"join",
"(",
"my_dir",
",",
"filename",
")",
"assert",
"os",
".",
"path",
".",
"exists",
"(",
"result",
")",
",",
"\"no such file \"",
"+",
"repr",
"(",
"(",
"filename",
",",
"result",
",",
"user_path",
")",
")",
"return",
"result"
] |
Look for an existing path matching filename.
Try to resolve relative to the module location if the path cannot by found
using "normal" resolution.
|
[
"Look",
"for",
"an",
"existing",
"path",
"matching",
"filename",
".",
"Try",
"to",
"resolve",
"relative",
"to",
"the",
"module",
"location",
"if",
"the",
"path",
"cannot",
"by",
"found",
"using",
"normal",
"resolution",
"."
] |
e53789c9b8a587e2f6e768d16b68e0ae5b3790d9
|
https://github.com/AaronWatters/jp_proxy_widget/blob/e53789c9b8a587e2f6e768d16b68e0ae5b3790d9/jp_proxy_widget/js_context.py#L19-L37
|
train
|
AaronWatters/jp_proxy_widget
|
jp_proxy_widget/js_context.py
|
load_if_not_loaded
|
def load_if_not_loaded(widget, filenames, verbose=False, delay=0.1, force=False, local=True, evaluator=None):
"""
Load a javascript file to the Jupyter notebook context,
unless it was already loaded.
"""
if evaluator is None:
evaluator = EVALUATOR # default if not specified.
for filename in filenames:
loaded = False
if force or not filename in LOADED_JAVASCRIPT:
js_text = get_text_from_file_name(filename, local)
if verbose:
print("loading javascript file", filename, "with", evaluator)
evaluator(widget, js_text)
LOADED_JAVASCRIPT.add(filename)
loaded = True
else:
if verbose:
print ("not reloading javascript file", filename)
if loaded and delay > 0:
if verbose:
print ("delaying to allow JS interpreter to sync.")
time.sleep(delay)
|
python
|
def load_if_not_loaded(widget, filenames, verbose=False, delay=0.1, force=False, local=True, evaluator=None):
"""
Load a javascript file to the Jupyter notebook context,
unless it was already loaded.
"""
if evaluator is None:
evaluator = EVALUATOR # default if not specified.
for filename in filenames:
loaded = False
if force or not filename in LOADED_JAVASCRIPT:
js_text = get_text_from_file_name(filename, local)
if verbose:
print("loading javascript file", filename, "with", evaluator)
evaluator(widget, js_text)
LOADED_JAVASCRIPT.add(filename)
loaded = True
else:
if verbose:
print ("not reloading javascript file", filename)
if loaded and delay > 0:
if verbose:
print ("delaying to allow JS interpreter to sync.")
time.sleep(delay)
|
[
"def",
"load_if_not_loaded",
"(",
"widget",
",",
"filenames",
",",
"verbose",
"=",
"False",
",",
"delay",
"=",
"0.1",
",",
"force",
"=",
"False",
",",
"local",
"=",
"True",
",",
"evaluator",
"=",
"None",
")",
":",
"if",
"evaluator",
"is",
"None",
":",
"evaluator",
"=",
"EVALUATOR",
"# default if not specified.",
"for",
"filename",
"in",
"filenames",
":",
"loaded",
"=",
"False",
"if",
"force",
"or",
"not",
"filename",
"in",
"LOADED_JAVASCRIPT",
":",
"js_text",
"=",
"get_text_from_file_name",
"(",
"filename",
",",
"local",
")",
"if",
"verbose",
":",
"print",
"(",
"\"loading javascript file\"",
",",
"filename",
",",
"\"with\"",
",",
"evaluator",
")",
"evaluator",
"(",
"widget",
",",
"js_text",
")",
"LOADED_JAVASCRIPT",
".",
"add",
"(",
"filename",
")",
"loaded",
"=",
"True",
"else",
":",
"if",
"verbose",
":",
"print",
"(",
"\"not reloading javascript file\"",
",",
"filename",
")",
"if",
"loaded",
"and",
"delay",
">",
"0",
":",
"if",
"verbose",
":",
"print",
"(",
"\"delaying to allow JS interpreter to sync.\"",
")",
"time",
".",
"sleep",
"(",
"delay",
")"
] |
Load a javascript file to the Jupyter notebook context,
unless it was already loaded.
|
[
"Load",
"a",
"javascript",
"file",
"to",
"the",
"Jupyter",
"notebook",
"context",
"unless",
"it",
"was",
"already",
"loaded",
"."
] |
e53789c9b8a587e2f6e768d16b68e0ae5b3790d9
|
https://github.com/AaronWatters/jp_proxy_widget/blob/e53789c9b8a587e2f6e768d16b68e0ae5b3790d9/jp_proxy_widget/js_context.py#L71-L93
|
train
|
AaronWatters/jp_proxy_widget
|
jp_proxy_widget/proxy_widget.py
|
ElementWrapper._set
|
def _set(self, name, value):
"Proxy to set a property of the widget element."
return self.widget(self.widget_element._set(name, value))
|
python
|
def _set(self, name, value):
"Proxy to set a property of the widget element."
return self.widget(self.widget_element._set(name, value))
|
[
"def",
"_set",
"(",
"self",
",",
"name",
",",
"value",
")",
":",
"return",
"self",
".",
"widget",
"(",
"self",
".",
"widget_element",
".",
"_set",
"(",
"name",
",",
"value",
")",
")"
] |
Proxy to set a property of the widget element.
|
[
"Proxy",
"to",
"set",
"a",
"property",
"of",
"the",
"widget",
"element",
"."
] |
e53789c9b8a587e2f6e768d16b68e0ae5b3790d9
|
https://github.com/AaronWatters/jp_proxy_widget/blob/e53789c9b8a587e2f6e768d16b68e0ae5b3790d9/jp_proxy_widget/proxy_widget.py#L855-L857
|
train
|
jmoiron/speedparser
|
speedparser/speedparser.py
|
strip_outer_tag
|
def strip_outer_tag(text):
"""Strips the outer tag, if text starts with a tag. Not entity aware;
designed to quickly strip outer tags from lxml cleaner output. Only
checks for <p> and <div> outer tags."""
if not text or not isinstance(text, basestring):
return text
stripped = text.strip()
if (stripped.startswith('<p>') or stripped.startswith('<div>')) and \
(stripped.endswith('</p>') or stripped.endswith('</div>')):
return stripped[stripped.index('>')+1:stripped.rindex('<')]
return text
|
python
|
def strip_outer_tag(text):
"""Strips the outer tag, if text starts with a tag. Not entity aware;
designed to quickly strip outer tags from lxml cleaner output. Only
checks for <p> and <div> outer tags."""
if not text or not isinstance(text, basestring):
return text
stripped = text.strip()
if (stripped.startswith('<p>') or stripped.startswith('<div>')) and \
(stripped.endswith('</p>') or stripped.endswith('</div>')):
return stripped[stripped.index('>')+1:stripped.rindex('<')]
return text
|
[
"def",
"strip_outer_tag",
"(",
"text",
")",
":",
"if",
"not",
"text",
"or",
"not",
"isinstance",
"(",
"text",
",",
"basestring",
")",
":",
"return",
"text",
"stripped",
"=",
"text",
".",
"strip",
"(",
")",
"if",
"(",
"stripped",
".",
"startswith",
"(",
"'<p>'",
")",
"or",
"stripped",
".",
"startswith",
"(",
"'<div>'",
")",
")",
"and",
"(",
"stripped",
".",
"endswith",
"(",
"'</p>'",
")",
"or",
"stripped",
".",
"endswith",
"(",
"'</div>'",
")",
")",
":",
"return",
"stripped",
"[",
"stripped",
".",
"index",
"(",
"'>'",
")",
"+",
"1",
":",
"stripped",
".",
"rindex",
"(",
"'<'",
")",
"]",
"return",
"text"
] |
Strips the outer tag, if text starts with a tag. Not entity aware;
designed to quickly strip outer tags from lxml cleaner output. Only
checks for <p> and <div> outer tags.
|
[
"Strips",
"the",
"outer",
"tag",
"if",
"text",
"starts",
"with",
"a",
"tag",
".",
"Not",
"entity",
"aware",
";",
"designed",
"to",
"quickly",
"strip",
"outer",
"tags",
"from",
"lxml",
"cleaner",
"output",
".",
"Only",
"checks",
"for",
"<p",
">",
"and",
"<div",
">",
"outer",
"tags",
"."
] |
e7e8d79daf73b35c9259695ad1e379476e1dfc77
|
https://github.com/jmoiron/speedparser/blob/e7e8d79daf73b35c9259695ad1e379476e1dfc77/speedparser/speedparser.py#L94-L104
|
train
|
jmoiron/speedparser
|
speedparser/speedparser.py
|
munge_author
|
def munge_author(author):
"""If an author contains an email and a name in it, make sure it is in
the format: "name (email)"."""
# this loveliness is from feedparser but was not usable as a function
if '@' in author:
emailmatch = re.search(r"(([a-zA-Z0-9\_\-\.\+]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?))(\?subject=\S+)?", author, re.UNICODE)
if emailmatch:
email = emailmatch.group(0)
# probably a better way to do the following, but it passes all the tests
author = author.replace(email, u'')
author = author.replace(u'()', u'')
author = author.replace(u'<>', u'')
author = author.replace(u'<>', u'')
author = author.strip()
if author and (author[0] == u'('):
author = author[1:]
if author and (author[-1] == u')'):
author = author[:-1]
author = author.strip()
return '%s (%s)' % (author, email)
return author
|
python
|
def munge_author(author):
"""If an author contains an email and a name in it, make sure it is in
the format: "name (email)"."""
# this loveliness is from feedparser but was not usable as a function
if '@' in author:
emailmatch = re.search(r"(([a-zA-Z0-9\_\-\.\+]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?))(\?subject=\S+)?", author, re.UNICODE)
if emailmatch:
email = emailmatch.group(0)
# probably a better way to do the following, but it passes all the tests
author = author.replace(email, u'')
author = author.replace(u'()', u'')
author = author.replace(u'<>', u'')
author = author.replace(u'<>', u'')
author = author.strip()
if author and (author[0] == u'('):
author = author[1:]
if author and (author[-1] == u')'):
author = author[:-1]
author = author.strip()
return '%s (%s)' % (author, email)
return author
|
[
"def",
"munge_author",
"(",
"author",
")",
":",
"# this loveliness is from feedparser but was not usable as a function",
"if",
"'@'",
"in",
"author",
":",
"emailmatch",
"=",
"re",
".",
"search",
"(",
"r\"(([a-zA-Z0-9\\_\\-\\.\\+]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?))(\\?subject=\\S+)?\"",
",",
"author",
",",
"re",
".",
"UNICODE",
")",
"if",
"emailmatch",
":",
"email",
"=",
"emailmatch",
".",
"group",
"(",
"0",
")",
"# probably a better way to do the following, but it passes all the tests",
"author",
"=",
"author",
".",
"replace",
"(",
"email",
",",
"u''",
")",
"author",
"=",
"author",
".",
"replace",
"(",
"u'()'",
",",
"u''",
")",
"author",
"=",
"author",
".",
"replace",
"(",
"u'<>'",
",",
"u''",
")",
"author",
"=",
"author",
".",
"replace",
"(",
"u'<>'",
",",
"u''",
")",
"author",
"=",
"author",
".",
"strip",
"(",
")",
"if",
"author",
"and",
"(",
"author",
"[",
"0",
"]",
"==",
"u'('",
")",
":",
"author",
"=",
"author",
"[",
"1",
":",
"]",
"if",
"author",
"and",
"(",
"author",
"[",
"-",
"1",
"]",
"==",
"u')'",
")",
":",
"author",
"=",
"author",
"[",
":",
"-",
"1",
"]",
"author",
"=",
"author",
".",
"strip",
"(",
")",
"return",
"'%s (%s)'",
"%",
"(",
"author",
",",
"email",
")",
"return",
"author"
] |
If an author contains an email and a name in it, make sure it is in
the format: "name (email)".
|
[
"If",
"an",
"author",
"contains",
"an",
"email",
"and",
"a",
"name",
"in",
"it",
"make",
"sure",
"it",
"is",
"in",
"the",
"format",
":",
"name",
"(",
"email",
")",
"."
] |
e7e8d79daf73b35c9259695ad1e379476e1dfc77
|
https://github.com/jmoiron/speedparser/blob/e7e8d79daf73b35c9259695ad1e379476e1dfc77/speedparser/speedparser.py#L121-L141
|
train
|
jmoiron/speedparser
|
speedparser/speedparser.py
|
base_url
|
def base_url(root):
"""Determine the base url for a root element."""
for attr, value in root.attrib.iteritems():
if attr.endswith('base') and 'http' in value:
return value
return None
|
python
|
def base_url(root):
"""Determine the base url for a root element."""
for attr, value in root.attrib.iteritems():
if attr.endswith('base') and 'http' in value:
return value
return None
|
[
"def",
"base_url",
"(",
"root",
")",
":",
"for",
"attr",
",",
"value",
"in",
"root",
".",
"attrib",
".",
"iteritems",
"(",
")",
":",
"if",
"attr",
".",
"endswith",
"(",
"'base'",
")",
"and",
"'http'",
"in",
"value",
":",
"return",
"value",
"return",
"None"
] |
Determine the base url for a root element.
|
[
"Determine",
"the",
"base",
"url",
"for",
"a",
"root",
"element",
"."
] |
e7e8d79daf73b35c9259695ad1e379476e1dfc77
|
https://github.com/jmoiron/speedparser/blob/e7e8d79daf73b35c9259695ad1e379476e1dfc77/speedparser/speedparser.py#L152-L157
|
train
|
jmoiron/speedparser
|
speedparser/speedparser.py
|
clean_ns
|
def clean_ns(tag):
"""Return a tag and its namespace separately."""
if '}' in tag:
split = tag.split('}')
return split[0].strip('{'), split[-1]
return '', tag
|
python
|
def clean_ns(tag):
"""Return a tag and its namespace separately."""
if '}' in tag:
split = tag.split('}')
return split[0].strip('{'), split[-1]
return '', tag
|
[
"def",
"clean_ns",
"(",
"tag",
")",
":",
"if",
"'}'",
"in",
"tag",
":",
"split",
"=",
"tag",
".",
"split",
"(",
"'}'",
")",
"return",
"split",
"[",
"0",
"]",
".",
"strip",
"(",
"'{'",
")",
",",
"split",
"[",
"-",
"1",
"]",
"return",
"''",
",",
"tag"
] |
Return a tag and its namespace separately.
|
[
"Return",
"a",
"tag",
"and",
"its",
"namespace",
"separately",
"."
] |
e7e8d79daf73b35c9259695ad1e379476e1dfc77
|
https://github.com/jmoiron/speedparser/blob/e7e8d79daf73b35c9259695ad1e379476e1dfc77/speedparser/speedparser.py#L174-L179
|
train
|
jmoiron/speedparser
|
speedparser/speedparser.py
|
xpath
|
def xpath(node, query, namespaces={}):
"""A safe xpath that only uses namespaces if available."""
if namespaces and 'None' not in namespaces:
return node.xpath(query, namespaces=namespaces)
return node.xpath(query)
|
python
|
def xpath(node, query, namespaces={}):
"""A safe xpath that only uses namespaces if available."""
if namespaces and 'None' not in namespaces:
return node.xpath(query, namespaces=namespaces)
return node.xpath(query)
|
[
"def",
"xpath",
"(",
"node",
",",
"query",
",",
"namespaces",
"=",
"{",
"}",
")",
":",
"if",
"namespaces",
"and",
"'None'",
"not",
"in",
"namespaces",
":",
"return",
"node",
".",
"xpath",
"(",
"query",
",",
"namespaces",
"=",
"namespaces",
")",
"return",
"node",
".",
"xpath",
"(",
"query",
")"
] |
A safe xpath that only uses namespaces if available.
|
[
"A",
"safe",
"xpath",
"that",
"only",
"uses",
"namespaces",
"if",
"available",
"."
] |
e7e8d79daf73b35c9259695ad1e379476e1dfc77
|
https://github.com/jmoiron/speedparser/blob/e7e8d79daf73b35c9259695ad1e379476e1dfc77/speedparser/speedparser.py#L182-L186
|
train
|
jmoiron/speedparser
|
speedparser/speedparser.py
|
innertext
|
def innertext(node):
"""Return the inner text of a node. If a node has no sub elements, this
is just node.text. Otherwise, it's node.text + sub-element-text +
node.tail."""
if not len(node):
return node.text
return (node.text or '') + ''.join([etree.tostring(c) for c in node]) + (node.tail or '')
|
python
|
def innertext(node):
"""Return the inner text of a node. If a node has no sub elements, this
is just node.text. Otherwise, it's node.text + sub-element-text +
node.tail."""
if not len(node):
return node.text
return (node.text or '') + ''.join([etree.tostring(c) for c in node]) + (node.tail or '')
|
[
"def",
"innertext",
"(",
"node",
")",
":",
"if",
"not",
"len",
"(",
"node",
")",
":",
"return",
"node",
".",
"text",
"return",
"(",
"node",
".",
"text",
"or",
"''",
")",
"+",
"''",
".",
"join",
"(",
"[",
"etree",
".",
"tostring",
"(",
"c",
")",
"for",
"c",
"in",
"node",
"]",
")",
"+",
"(",
"node",
".",
"tail",
"or",
"''",
")"
] |
Return the inner text of a node. If a node has no sub elements, this
is just node.text. Otherwise, it's node.text + sub-element-text +
node.tail.
|
[
"Return",
"the",
"inner",
"text",
"of",
"a",
"node",
".",
"If",
"a",
"node",
"has",
"no",
"sub",
"elements",
"this",
"is",
"just",
"node",
".",
"text",
".",
"Otherwise",
"it",
"s",
"node",
".",
"text",
"+",
"sub",
"-",
"element",
"-",
"text",
"+",
"node",
".",
"tail",
"."
] |
e7e8d79daf73b35c9259695ad1e379476e1dfc77
|
https://github.com/jmoiron/speedparser/blob/e7e8d79daf73b35c9259695ad1e379476e1dfc77/speedparser/speedparser.py#L189-L196
|
train
|
jmoiron/speedparser
|
speedparser/speedparser.py
|
parse
|
def parse(document, clean_html=True, unix_timestamp=False, encoding=None):
"""Parse a document and return a feedparser dictionary with attr key access.
If clean_html is False, the html in the feed will not be cleaned. If
clean_html is True, a sane version of lxml.html.clean.Cleaner will be used.
If it is a Cleaner object, that cleaner will be used. If unix_timestamp is
True, the date information will be a numerical unix timestamp rather than a
struct_time. If encoding is provided, the encoding of the document will be
manually set to that."""
if isinstance(clean_html, bool):
cleaner = default_cleaner if clean_html else fake_cleaner
else:
cleaner = clean_html
result = feedparser.FeedParserDict()
result['feed'] = feedparser.FeedParserDict()
result['entries'] = []
result['bozo'] = 0
try:
parser = SpeedParser(document, cleaner, unix_timestamp, encoding)
parser.update(result)
except Exception as e:
if isinstance(e, UnicodeDecodeError) and encoding is True:
encoding = chardet.detect(document)['encoding']
document = document.decode(encoding, 'replace').encode('utf-8')
return parse(document, clean_html, unix_timestamp, encoding)
import traceback
result['bozo'] = 1
result['bozo_exception'] = e
result['bozo_tb'] = traceback.format_exc()
return result
|
python
|
def parse(document, clean_html=True, unix_timestamp=False, encoding=None):
"""Parse a document and return a feedparser dictionary with attr key access.
If clean_html is False, the html in the feed will not be cleaned. If
clean_html is True, a sane version of lxml.html.clean.Cleaner will be used.
If it is a Cleaner object, that cleaner will be used. If unix_timestamp is
True, the date information will be a numerical unix timestamp rather than a
struct_time. If encoding is provided, the encoding of the document will be
manually set to that."""
if isinstance(clean_html, bool):
cleaner = default_cleaner if clean_html else fake_cleaner
else:
cleaner = clean_html
result = feedparser.FeedParserDict()
result['feed'] = feedparser.FeedParserDict()
result['entries'] = []
result['bozo'] = 0
try:
parser = SpeedParser(document, cleaner, unix_timestamp, encoding)
parser.update(result)
except Exception as e:
if isinstance(e, UnicodeDecodeError) and encoding is True:
encoding = chardet.detect(document)['encoding']
document = document.decode(encoding, 'replace').encode('utf-8')
return parse(document, clean_html, unix_timestamp, encoding)
import traceback
result['bozo'] = 1
result['bozo_exception'] = e
result['bozo_tb'] = traceback.format_exc()
return result
|
[
"def",
"parse",
"(",
"document",
",",
"clean_html",
"=",
"True",
",",
"unix_timestamp",
"=",
"False",
",",
"encoding",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"clean_html",
",",
"bool",
")",
":",
"cleaner",
"=",
"default_cleaner",
"if",
"clean_html",
"else",
"fake_cleaner",
"else",
":",
"cleaner",
"=",
"clean_html",
"result",
"=",
"feedparser",
".",
"FeedParserDict",
"(",
")",
"result",
"[",
"'feed'",
"]",
"=",
"feedparser",
".",
"FeedParserDict",
"(",
")",
"result",
"[",
"'entries'",
"]",
"=",
"[",
"]",
"result",
"[",
"'bozo'",
"]",
"=",
"0",
"try",
":",
"parser",
"=",
"SpeedParser",
"(",
"document",
",",
"cleaner",
",",
"unix_timestamp",
",",
"encoding",
")",
"parser",
".",
"update",
"(",
"result",
")",
"except",
"Exception",
"as",
"e",
":",
"if",
"isinstance",
"(",
"e",
",",
"UnicodeDecodeError",
")",
"and",
"encoding",
"is",
"True",
":",
"encoding",
"=",
"chardet",
".",
"detect",
"(",
"document",
")",
"[",
"'encoding'",
"]",
"document",
"=",
"document",
".",
"decode",
"(",
"encoding",
",",
"'replace'",
")",
".",
"encode",
"(",
"'utf-8'",
")",
"return",
"parse",
"(",
"document",
",",
"clean_html",
",",
"unix_timestamp",
",",
"encoding",
")",
"import",
"traceback",
"result",
"[",
"'bozo'",
"]",
"=",
"1",
"result",
"[",
"'bozo_exception'",
"]",
"=",
"e",
"result",
"[",
"'bozo_tb'",
"]",
"=",
"traceback",
".",
"format_exc",
"(",
")",
"return",
"result"
] |
Parse a document and return a feedparser dictionary with attr key access.
If clean_html is False, the html in the feed will not be cleaned. If
clean_html is True, a sane version of lxml.html.clean.Cleaner will be used.
If it is a Cleaner object, that cleaner will be used. If unix_timestamp is
True, the date information will be a numerical unix timestamp rather than a
struct_time. If encoding is provided, the encoding of the document will be
manually set to that.
|
[
"Parse",
"a",
"document",
"and",
"return",
"a",
"feedparser",
"dictionary",
"with",
"attr",
"key",
"access",
".",
"If",
"clean_html",
"is",
"False",
"the",
"html",
"in",
"the",
"feed",
"will",
"not",
"be",
"cleaned",
".",
"If",
"clean_html",
"is",
"True",
"a",
"sane",
"version",
"of",
"lxml",
".",
"html",
".",
"clean",
".",
"Cleaner",
"will",
"be",
"used",
".",
"If",
"it",
"is",
"a",
"Cleaner",
"object",
"that",
"cleaner",
"will",
"be",
"used",
".",
"If",
"unix_timestamp",
"is",
"True",
"the",
"date",
"information",
"will",
"be",
"a",
"numerical",
"unix",
"timestamp",
"rather",
"than",
"a",
"struct_time",
".",
"If",
"encoding",
"is",
"provided",
"the",
"encoding",
"of",
"the",
"document",
"will",
"be",
"manually",
"set",
"to",
"that",
"."
] |
e7e8d79daf73b35c9259695ad1e379476e1dfc77
|
https://github.com/jmoiron/speedparser/blob/e7e8d79daf73b35c9259695ad1e379476e1dfc77/speedparser/speedparser.py#L671-L699
|
train
|
jmoiron/speedparser
|
speedparser/speedparser.py
|
SpeedParserEntriesRss20.parse_entry
|
def parse_entry(self, entry):
"""An attempt to parse pieces of an entry out w/o xpath, by looping
over the entry root's children and slotting them into the right places.
This is going to be way messier than SpeedParserEntries, and maybe
less cleanly usable, but it should be faster."""
e = feedparser.FeedParserDict()
tag_map = self.tag_map
nslookup = self.nslookup
for child in entry.getchildren():
if isinstance(child, etree._Comment):
continue
ns, tag = clean_ns(child.tag)
mapping = tag_map.get(tag, None)
if mapping:
getattr(self, 'parse_%s' % mapping)(child, e, nslookup.get(ns, ns))
if not ns:
continue
fulltag = '%s:%s' % (nslookup.get(ns, ''), tag)
mapping = tag_map.get(fulltag, None)
if mapping:
getattr(self, 'parse_%s' % mapping)(child, e, nslookup[ns])
lacks_summary = 'summary' not in e or e['summary'] is None
lacks_content = 'content' not in e or not bool(e.get('content', None))
if not lacks_summary and lacks_content:
e['content'] = [{'value': e.summary}]
# feedparser sometimes copies the first content value into the
# summary field when summary was completely missing; we want
# to do that as well, but avoid the case where summary was given as ''
if lacks_summary and not lacks_content:
e['summary'] = e['content'][0]['value']
if e.get('summary', False) is None:
e['summary'] = u''
# support feed entries that have a guid but no link
if 'guid' in e and 'link' not in e:
e['link'] = full_href(e['guid'], self.baseurl)
return e
|
python
|
def parse_entry(self, entry):
"""An attempt to parse pieces of an entry out w/o xpath, by looping
over the entry root's children and slotting them into the right places.
This is going to be way messier than SpeedParserEntries, and maybe
less cleanly usable, but it should be faster."""
e = feedparser.FeedParserDict()
tag_map = self.tag_map
nslookup = self.nslookup
for child in entry.getchildren():
if isinstance(child, etree._Comment):
continue
ns, tag = clean_ns(child.tag)
mapping = tag_map.get(tag, None)
if mapping:
getattr(self, 'parse_%s' % mapping)(child, e, nslookup.get(ns, ns))
if not ns:
continue
fulltag = '%s:%s' % (nslookup.get(ns, ''), tag)
mapping = tag_map.get(fulltag, None)
if mapping:
getattr(self, 'parse_%s' % mapping)(child, e, nslookup[ns])
lacks_summary = 'summary' not in e or e['summary'] is None
lacks_content = 'content' not in e or not bool(e.get('content', None))
if not lacks_summary and lacks_content:
e['content'] = [{'value': e.summary}]
# feedparser sometimes copies the first content value into the
# summary field when summary was completely missing; we want
# to do that as well, but avoid the case where summary was given as ''
if lacks_summary and not lacks_content:
e['summary'] = e['content'][0]['value']
if e.get('summary', False) is None:
e['summary'] = u''
# support feed entries that have a guid but no link
if 'guid' in e and 'link' not in e:
e['link'] = full_href(e['guid'], self.baseurl)
return e
|
[
"def",
"parse_entry",
"(",
"self",
",",
"entry",
")",
":",
"e",
"=",
"feedparser",
".",
"FeedParserDict",
"(",
")",
"tag_map",
"=",
"self",
".",
"tag_map",
"nslookup",
"=",
"self",
".",
"nslookup",
"for",
"child",
"in",
"entry",
".",
"getchildren",
"(",
")",
":",
"if",
"isinstance",
"(",
"child",
",",
"etree",
".",
"_Comment",
")",
":",
"continue",
"ns",
",",
"tag",
"=",
"clean_ns",
"(",
"child",
".",
"tag",
")",
"mapping",
"=",
"tag_map",
".",
"get",
"(",
"tag",
",",
"None",
")",
"if",
"mapping",
":",
"getattr",
"(",
"self",
",",
"'parse_%s'",
"%",
"mapping",
")",
"(",
"child",
",",
"e",
",",
"nslookup",
".",
"get",
"(",
"ns",
",",
"ns",
")",
")",
"if",
"not",
"ns",
":",
"continue",
"fulltag",
"=",
"'%s:%s'",
"%",
"(",
"nslookup",
".",
"get",
"(",
"ns",
",",
"''",
")",
",",
"tag",
")",
"mapping",
"=",
"tag_map",
".",
"get",
"(",
"fulltag",
",",
"None",
")",
"if",
"mapping",
":",
"getattr",
"(",
"self",
",",
"'parse_%s'",
"%",
"mapping",
")",
"(",
"child",
",",
"e",
",",
"nslookup",
"[",
"ns",
"]",
")",
"lacks_summary",
"=",
"'summary'",
"not",
"in",
"e",
"or",
"e",
"[",
"'summary'",
"]",
"is",
"None",
"lacks_content",
"=",
"'content'",
"not",
"in",
"e",
"or",
"not",
"bool",
"(",
"e",
".",
"get",
"(",
"'content'",
",",
"None",
")",
")",
"if",
"not",
"lacks_summary",
"and",
"lacks_content",
":",
"e",
"[",
"'content'",
"]",
"=",
"[",
"{",
"'value'",
":",
"e",
".",
"summary",
"}",
"]",
"# feedparser sometimes copies the first content value into the",
"# summary field when summary was completely missing; we want",
"# to do that as well, but avoid the case where summary was given as ''",
"if",
"lacks_summary",
"and",
"not",
"lacks_content",
":",
"e",
"[",
"'summary'",
"]",
"=",
"e",
"[",
"'content'",
"]",
"[",
"0",
"]",
"[",
"'value'",
"]",
"if",
"e",
".",
"get",
"(",
"'summary'",
",",
"False",
")",
"is",
"None",
":",
"e",
"[",
"'summary'",
"]",
"=",
"u''",
"# support feed entries that have a guid but no link",
"if",
"'guid'",
"in",
"e",
"and",
"'link'",
"not",
"in",
"e",
":",
"e",
"[",
"'link'",
"]",
"=",
"full_href",
"(",
"e",
"[",
"'guid'",
"]",
",",
"self",
".",
"baseurl",
")",
"return",
"e"
] |
An attempt to parse pieces of an entry out w/o xpath, by looping
over the entry root's children and slotting them into the right places.
This is going to be way messier than SpeedParserEntries, and maybe
less cleanly usable, but it should be faster.
|
[
"An",
"attempt",
"to",
"parse",
"pieces",
"of",
"an",
"entry",
"out",
"w",
"/",
"o",
"xpath",
"by",
"looping",
"over",
"the",
"entry",
"root",
"s",
"children",
"and",
"slotting",
"them",
"into",
"the",
"right",
"places",
".",
"This",
"is",
"going",
"to",
"be",
"way",
"messier",
"than",
"SpeedParserEntries",
"and",
"maybe",
"less",
"cleanly",
"usable",
"but",
"it",
"should",
"be",
"faster",
"."
] |
e7e8d79daf73b35c9259695ad1e379476e1dfc77
|
https://github.com/jmoiron/speedparser/blob/e7e8d79daf73b35c9259695ad1e379476e1dfc77/speedparser/speedparser.py#L255-L298
|
train
|
AaronWatters/jp_proxy_widget
|
jp_proxy_widget/watcher.py
|
FileWatcherWidget.changed_path
|
def changed_path(self):
"Find any changed path and update all changed modification times."
result = None # default
for path in self.paths_to_modification_times:
lastmod = self.paths_to_modification_times[path]
mod = os.path.getmtime(path)
if mod > lastmod:
result = "Watch file has been modified: " + repr(path)
self.paths_to_modification_times[path] = mod
for folder in self.folder_paths:
for filename in os.listdir(folder):
subpath = os.path.join(folder, filename)
if os.path.isfile(subpath) and subpath not in self.paths_to_modification_times:
result = "New file in watched folder: " + repr(subpath)
self.add(subpath)
if self.check_python_modules:
# refresh the modules
self.add_all_modules()
if self.check_javascript:
self.watch_javascript()
return result
|
python
|
def changed_path(self):
"Find any changed path and update all changed modification times."
result = None # default
for path in self.paths_to_modification_times:
lastmod = self.paths_to_modification_times[path]
mod = os.path.getmtime(path)
if mod > lastmod:
result = "Watch file has been modified: " + repr(path)
self.paths_to_modification_times[path] = mod
for folder in self.folder_paths:
for filename in os.listdir(folder):
subpath = os.path.join(folder, filename)
if os.path.isfile(subpath) and subpath not in self.paths_to_modification_times:
result = "New file in watched folder: " + repr(subpath)
self.add(subpath)
if self.check_python_modules:
# refresh the modules
self.add_all_modules()
if self.check_javascript:
self.watch_javascript()
return result
|
[
"def",
"changed_path",
"(",
"self",
")",
":",
"result",
"=",
"None",
"# default",
"for",
"path",
"in",
"self",
".",
"paths_to_modification_times",
":",
"lastmod",
"=",
"self",
".",
"paths_to_modification_times",
"[",
"path",
"]",
"mod",
"=",
"os",
".",
"path",
".",
"getmtime",
"(",
"path",
")",
"if",
"mod",
">",
"lastmod",
":",
"result",
"=",
"\"Watch file has been modified: \"",
"+",
"repr",
"(",
"path",
")",
"self",
".",
"paths_to_modification_times",
"[",
"path",
"]",
"=",
"mod",
"for",
"folder",
"in",
"self",
".",
"folder_paths",
":",
"for",
"filename",
"in",
"os",
".",
"listdir",
"(",
"folder",
")",
":",
"subpath",
"=",
"os",
".",
"path",
".",
"join",
"(",
"folder",
",",
"filename",
")",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"subpath",
")",
"and",
"subpath",
"not",
"in",
"self",
".",
"paths_to_modification_times",
":",
"result",
"=",
"\"New file in watched folder: \"",
"+",
"repr",
"(",
"subpath",
")",
"self",
".",
"add",
"(",
"subpath",
")",
"if",
"self",
".",
"check_python_modules",
":",
"# refresh the modules",
"self",
".",
"add_all_modules",
"(",
")",
"if",
"self",
".",
"check_javascript",
":",
"self",
".",
"watch_javascript",
"(",
")",
"return",
"result"
] |
Find any changed path and update all changed modification times.
|
[
"Find",
"any",
"changed",
"path",
"and",
"update",
"all",
"changed",
"modification",
"times",
"."
] |
e53789c9b8a587e2f6e768d16b68e0ae5b3790d9
|
https://github.com/AaronWatters/jp_proxy_widget/blob/e53789c9b8a587e2f6e768d16b68e0ae5b3790d9/jp_proxy_widget/watcher.py#L124-L144
|
train
|
jmoiron/speedparser
|
speedparser/feedparsercompat.py
|
_parse_date_iso8601
|
def _parse_date_iso8601(dateString):
'''Parse a variety of ISO-8601-compatible formats like 20040105'''
m = None
for _iso8601_match in _iso8601_matches:
m = _iso8601_match(dateString)
if m:
break
if not m:
return
if m.span() == (0, 0):
return
params = m.groupdict()
ordinal = params.get('ordinal', 0)
if ordinal:
ordinal = int(ordinal)
else:
ordinal = 0
year = params.get('year', '--')
if not year or year == '--':
year = time.gmtime()[0]
elif len(year) == 2:
# ISO 8601 assumes current century, i.e. 93 -> 2093, NOT 1993
year = 100 * int(time.gmtime()[0] / 100) + int(year)
else:
year = int(year)
month = params.get('month', '-')
if not month or month == '-':
# ordinals are NOT normalized by mktime, we simulate them
# by setting month=1, day=ordinal
if ordinal:
month = 1
else:
month = time.gmtime()[1]
month = int(month)
day = params.get('day', 0)
if not day:
# see above
if ordinal:
day = ordinal
elif params.get('century', 0) or \
params.get('year', 0) or params.get('month', 0):
day = 1
else:
day = time.gmtime()[2]
else:
day = int(day)
# special case of the century - is the first year of the 21st century
# 2000 or 2001 ? The debate goes on...
if 'century' in params:
year = (int(params['century']) - 1) * 100 + 1
# in ISO 8601 most fields are optional
for field in ['hour', 'minute', 'second', 'tzhour', 'tzmin']:
if not params.get(field, None):
params[field] = 0
hour = int(params.get('hour', 0))
minute = int(params.get('minute', 0))
second = int(float(params.get('second', 0)))
# weekday is normalized by mktime(), we can ignore it
weekday = 0
daylight_savings_flag = -1
tm = [year, month, day, hour, minute, second, weekday,
ordinal, daylight_savings_flag]
# ISO 8601 time zone adjustments
tz = params.get('tz')
if tz and tz != 'Z':
if tz[0] == '-':
tm[3] += int(params.get('tzhour', 0))
tm[4] += int(params.get('tzmin', 0))
elif tz[0] == '+':
tm[3] -= int(params.get('tzhour', 0))
tm[4] -= int(params.get('tzmin', 0))
else:
return None
# Python's time.mktime() is a wrapper around the ANSI C mktime(3c)
# which is guaranteed to normalize d/m/y/h/m/s.
# Many implementations have bugs, but we'll pretend they don't.
return time.localtime(time.mktime(tuple(tm)))
|
python
|
def _parse_date_iso8601(dateString):
'''Parse a variety of ISO-8601-compatible formats like 20040105'''
m = None
for _iso8601_match in _iso8601_matches:
m = _iso8601_match(dateString)
if m:
break
if not m:
return
if m.span() == (0, 0):
return
params = m.groupdict()
ordinal = params.get('ordinal', 0)
if ordinal:
ordinal = int(ordinal)
else:
ordinal = 0
year = params.get('year', '--')
if not year or year == '--':
year = time.gmtime()[0]
elif len(year) == 2:
# ISO 8601 assumes current century, i.e. 93 -> 2093, NOT 1993
year = 100 * int(time.gmtime()[0] / 100) + int(year)
else:
year = int(year)
month = params.get('month', '-')
if not month or month == '-':
# ordinals are NOT normalized by mktime, we simulate them
# by setting month=1, day=ordinal
if ordinal:
month = 1
else:
month = time.gmtime()[1]
month = int(month)
day = params.get('day', 0)
if not day:
# see above
if ordinal:
day = ordinal
elif params.get('century', 0) or \
params.get('year', 0) or params.get('month', 0):
day = 1
else:
day = time.gmtime()[2]
else:
day = int(day)
# special case of the century - is the first year of the 21st century
# 2000 or 2001 ? The debate goes on...
if 'century' in params:
year = (int(params['century']) - 1) * 100 + 1
# in ISO 8601 most fields are optional
for field in ['hour', 'minute', 'second', 'tzhour', 'tzmin']:
if not params.get(field, None):
params[field] = 0
hour = int(params.get('hour', 0))
minute = int(params.get('minute', 0))
second = int(float(params.get('second', 0)))
# weekday is normalized by mktime(), we can ignore it
weekday = 0
daylight_savings_flag = -1
tm = [year, month, day, hour, minute, second, weekday,
ordinal, daylight_savings_flag]
# ISO 8601 time zone adjustments
tz = params.get('tz')
if tz and tz != 'Z':
if tz[0] == '-':
tm[3] += int(params.get('tzhour', 0))
tm[4] += int(params.get('tzmin', 0))
elif tz[0] == '+':
tm[3] -= int(params.get('tzhour', 0))
tm[4] -= int(params.get('tzmin', 0))
else:
return None
# Python's time.mktime() is a wrapper around the ANSI C mktime(3c)
# which is guaranteed to normalize d/m/y/h/m/s.
# Many implementations have bugs, but we'll pretend they don't.
return time.localtime(time.mktime(tuple(tm)))
|
[
"def",
"_parse_date_iso8601",
"(",
"dateString",
")",
":",
"m",
"=",
"None",
"for",
"_iso8601_match",
"in",
"_iso8601_matches",
":",
"m",
"=",
"_iso8601_match",
"(",
"dateString",
")",
"if",
"m",
":",
"break",
"if",
"not",
"m",
":",
"return",
"if",
"m",
".",
"span",
"(",
")",
"==",
"(",
"0",
",",
"0",
")",
":",
"return",
"params",
"=",
"m",
".",
"groupdict",
"(",
")",
"ordinal",
"=",
"params",
".",
"get",
"(",
"'ordinal'",
",",
"0",
")",
"if",
"ordinal",
":",
"ordinal",
"=",
"int",
"(",
"ordinal",
")",
"else",
":",
"ordinal",
"=",
"0",
"year",
"=",
"params",
".",
"get",
"(",
"'year'",
",",
"'--'",
")",
"if",
"not",
"year",
"or",
"year",
"==",
"'--'",
":",
"year",
"=",
"time",
".",
"gmtime",
"(",
")",
"[",
"0",
"]",
"elif",
"len",
"(",
"year",
")",
"==",
"2",
":",
"# ISO 8601 assumes current century, i.e. 93 -> 2093, NOT 1993",
"year",
"=",
"100",
"*",
"int",
"(",
"time",
".",
"gmtime",
"(",
")",
"[",
"0",
"]",
"/",
"100",
")",
"+",
"int",
"(",
"year",
")",
"else",
":",
"year",
"=",
"int",
"(",
"year",
")",
"month",
"=",
"params",
".",
"get",
"(",
"'month'",
",",
"'-'",
")",
"if",
"not",
"month",
"or",
"month",
"==",
"'-'",
":",
"# ordinals are NOT normalized by mktime, we simulate them",
"# by setting month=1, day=ordinal",
"if",
"ordinal",
":",
"month",
"=",
"1",
"else",
":",
"month",
"=",
"time",
".",
"gmtime",
"(",
")",
"[",
"1",
"]",
"month",
"=",
"int",
"(",
"month",
")",
"day",
"=",
"params",
".",
"get",
"(",
"'day'",
",",
"0",
")",
"if",
"not",
"day",
":",
"# see above",
"if",
"ordinal",
":",
"day",
"=",
"ordinal",
"elif",
"params",
".",
"get",
"(",
"'century'",
",",
"0",
")",
"or",
"params",
".",
"get",
"(",
"'year'",
",",
"0",
")",
"or",
"params",
".",
"get",
"(",
"'month'",
",",
"0",
")",
":",
"day",
"=",
"1",
"else",
":",
"day",
"=",
"time",
".",
"gmtime",
"(",
")",
"[",
"2",
"]",
"else",
":",
"day",
"=",
"int",
"(",
"day",
")",
"# special case of the century - is the first year of the 21st century",
"# 2000 or 2001 ? The debate goes on...",
"if",
"'century'",
"in",
"params",
":",
"year",
"=",
"(",
"int",
"(",
"params",
"[",
"'century'",
"]",
")",
"-",
"1",
")",
"*",
"100",
"+",
"1",
"# in ISO 8601 most fields are optional",
"for",
"field",
"in",
"[",
"'hour'",
",",
"'minute'",
",",
"'second'",
",",
"'tzhour'",
",",
"'tzmin'",
"]",
":",
"if",
"not",
"params",
".",
"get",
"(",
"field",
",",
"None",
")",
":",
"params",
"[",
"field",
"]",
"=",
"0",
"hour",
"=",
"int",
"(",
"params",
".",
"get",
"(",
"'hour'",
",",
"0",
")",
")",
"minute",
"=",
"int",
"(",
"params",
".",
"get",
"(",
"'minute'",
",",
"0",
")",
")",
"second",
"=",
"int",
"(",
"float",
"(",
"params",
".",
"get",
"(",
"'second'",
",",
"0",
")",
")",
")",
"# weekday is normalized by mktime(), we can ignore it",
"weekday",
"=",
"0",
"daylight_savings_flag",
"=",
"-",
"1",
"tm",
"=",
"[",
"year",
",",
"month",
",",
"day",
",",
"hour",
",",
"minute",
",",
"second",
",",
"weekday",
",",
"ordinal",
",",
"daylight_savings_flag",
"]",
"# ISO 8601 time zone adjustments",
"tz",
"=",
"params",
".",
"get",
"(",
"'tz'",
")",
"if",
"tz",
"and",
"tz",
"!=",
"'Z'",
":",
"if",
"tz",
"[",
"0",
"]",
"==",
"'-'",
":",
"tm",
"[",
"3",
"]",
"+=",
"int",
"(",
"params",
".",
"get",
"(",
"'tzhour'",
",",
"0",
")",
")",
"tm",
"[",
"4",
"]",
"+=",
"int",
"(",
"params",
".",
"get",
"(",
"'tzmin'",
",",
"0",
")",
")",
"elif",
"tz",
"[",
"0",
"]",
"==",
"'+'",
":",
"tm",
"[",
"3",
"]",
"-=",
"int",
"(",
"params",
".",
"get",
"(",
"'tzhour'",
",",
"0",
")",
")",
"tm",
"[",
"4",
"]",
"-=",
"int",
"(",
"params",
".",
"get",
"(",
"'tzmin'",
",",
"0",
")",
")",
"else",
":",
"return",
"None",
"# Python's time.mktime() is a wrapper around the ANSI C mktime(3c)",
"# which is guaranteed to normalize d/m/y/h/m/s.",
"# Many implementations have bugs, but we'll pretend they don't.",
"return",
"time",
".",
"localtime",
"(",
"time",
".",
"mktime",
"(",
"tuple",
"(",
"tm",
")",
")",
")"
] |
Parse a variety of ISO-8601-compatible formats like 20040105
|
[
"Parse",
"a",
"variety",
"of",
"ISO",
"-",
"8601",
"-",
"compatible",
"formats",
"like",
"20040105"
] |
e7e8d79daf73b35c9259695ad1e379476e1dfc77
|
https://github.com/jmoiron/speedparser/blob/e7e8d79daf73b35c9259695ad1e379476e1dfc77/speedparser/feedparsercompat.py#L205-L281
|
train
|
jmoiron/speedparser
|
speedparser/feedparsercompat.py
|
_parse_date_onblog
|
def _parse_date_onblog(dateString):
'''Parse a string according to the OnBlog 8-bit date format'''
m = _korean_onblog_date_re.match(dateString)
if not m:
return
w3dtfdate = '%(year)s-%(month)s-%(day)sT%(hour)s:%(minute)s:%(second)s%(zonediff)s' % \
{'year': m.group(1), 'month': m.group(2), 'day': m.group(3),\
'hour': m.group(4), 'minute': m.group(5), 'second': m.group(6),\
'zonediff': '+09:00'}
return _parse_date_w3dtf(w3dtfdate)
|
python
|
def _parse_date_onblog(dateString):
'''Parse a string according to the OnBlog 8-bit date format'''
m = _korean_onblog_date_re.match(dateString)
if not m:
return
w3dtfdate = '%(year)s-%(month)s-%(day)sT%(hour)s:%(minute)s:%(second)s%(zonediff)s' % \
{'year': m.group(1), 'month': m.group(2), 'day': m.group(3),\
'hour': m.group(4), 'minute': m.group(5), 'second': m.group(6),\
'zonediff': '+09:00'}
return _parse_date_w3dtf(w3dtfdate)
|
[
"def",
"_parse_date_onblog",
"(",
"dateString",
")",
":",
"m",
"=",
"_korean_onblog_date_re",
".",
"match",
"(",
"dateString",
")",
"if",
"not",
"m",
":",
"return",
"w3dtfdate",
"=",
"'%(year)s-%(month)s-%(day)sT%(hour)s:%(minute)s:%(second)s%(zonediff)s'",
"%",
"{",
"'year'",
":",
"m",
".",
"group",
"(",
"1",
")",
",",
"'month'",
":",
"m",
".",
"group",
"(",
"2",
")",
",",
"'day'",
":",
"m",
".",
"group",
"(",
"3",
")",
",",
"'hour'",
":",
"m",
".",
"group",
"(",
"4",
")",
",",
"'minute'",
":",
"m",
".",
"group",
"(",
"5",
")",
",",
"'second'",
":",
"m",
".",
"group",
"(",
"6",
")",
",",
"'zonediff'",
":",
"'+09:00'",
"}",
"return",
"_parse_date_w3dtf",
"(",
"w3dtfdate",
")"
] |
Parse a string according to the OnBlog 8-bit date format
|
[
"Parse",
"a",
"string",
"according",
"to",
"the",
"OnBlog",
"8",
"-",
"bit",
"date",
"format"
] |
e7e8d79daf73b35c9259695ad1e379476e1dfc77
|
https://github.com/jmoiron/speedparser/blob/e7e8d79daf73b35c9259695ad1e379476e1dfc77/speedparser/feedparsercompat.py#L297-L306
|
train
|
jmoiron/speedparser
|
speedparser/feedparsercompat.py
|
_parse_date_nate
|
def _parse_date_nate(dateString):
'''Parse a string according to the Nate 8-bit date format'''
m = _korean_nate_date_re.match(dateString)
if not m:
return
hour = int(m.group(5))
ampm = m.group(4)
if (ampm == _korean_pm):
hour += 12
hour = str(hour)
if len(hour) == 1:
hour = '0' + hour
w3dtfdate = '%(year)s-%(month)s-%(day)sT%(hour)s:%(minute)s:%(second)s%(zonediff)s' % \
{'year': m.group(1), 'month': m.group(2), 'day': m.group(3),\
'hour': hour, 'minute': m.group(6), 'second': m.group(7),\
'zonediff': '+09:00'}
return _parse_date_w3dtf(w3dtfdate)
|
python
|
def _parse_date_nate(dateString):
'''Parse a string according to the Nate 8-bit date format'''
m = _korean_nate_date_re.match(dateString)
if not m:
return
hour = int(m.group(5))
ampm = m.group(4)
if (ampm == _korean_pm):
hour += 12
hour = str(hour)
if len(hour) == 1:
hour = '0' + hour
w3dtfdate = '%(year)s-%(month)s-%(day)sT%(hour)s:%(minute)s:%(second)s%(zonediff)s' % \
{'year': m.group(1), 'month': m.group(2), 'day': m.group(3),\
'hour': hour, 'minute': m.group(6), 'second': m.group(7),\
'zonediff': '+09:00'}
return _parse_date_w3dtf(w3dtfdate)
|
[
"def",
"_parse_date_nate",
"(",
"dateString",
")",
":",
"m",
"=",
"_korean_nate_date_re",
".",
"match",
"(",
"dateString",
")",
"if",
"not",
"m",
":",
"return",
"hour",
"=",
"int",
"(",
"m",
".",
"group",
"(",
"5",
")",
")",
"ampm",
"=",
"m",
".",
"group",
"(",
"4",
")",
"if",
"(",
"ampm",
"==",
"_korean_pm",
")",
":",
"hour",
"+=",
"12",
"hour",
"=",
"str",
"(",
"hour",
")",
"if",
"len",
"(",
"hour",
")",
"==",
"1",
":",
"hour",
"=",
"'0'",
"+",
"hour",
"w3dtfdate",
"=",
"'%(year)s-%(month)s-%(day)sT%(hour)s:%(minute)s:%(second)s%(zonediff)s'",
"%",
"{",
"'year'",
":",
"m",
".",
"group",
"(",
"1",
")",
",",
"'month'",
":",
"m",
".",
"group",
"(",
"2",
")",
",",
"'day'",
":",
"m",
".",
"group",
"(",
"3",
")",
",",
"'hour'",
":",
"hour",
",",
"'minute'",
":",
"m",
".",
"group",
"(",
"6",
")",
",",
"'second'",
":",
"m",
".",
"group",
"(",
"7",
")",
",",
"'zonediff'",
":",
"'+09:00'",
"}",
"return",
"_parse_date_w3dtf",
"(",
"w3dtfdate",
")"
] |
Parse a string according to the Nate 8-bit date format
|
[
"Parse",
"a",
"string",
"according",
"to",
"the",
"Nate",
"8",
"-",
"bit",
"date",
"format"
] |
e7e8d79daf73b35c9259695ad1e379476e1dfc77
|
https://github.com/jmoiron/speedparser/blob/e7e8d79daf73b35c9259695ad1e379476e1dfc77/speedparser/feedparsercompat.py#L309-L325
|
train
|
jmoiron/speedparser
|
speedparser/feedparsercompat.py
|
_parse_date_greek
|
def _parse_date_greek(dateString):
'''Parse a string according to a Greek 8-bit date format.'''
m = _greek_date_format_re.match(dateString)
if not m:
return
wday = _greek_wdays[m.group(1)]
month = _greek_months[m.group(3)]
rfc822date = '%(wday)s, %(day)s %(month)s %(year)s %(hour)s:%(minute)s:%(second)s %(zonediff)s' % \
{'wday': wday, 'day': m.group(2), 'month': month, 'year': m.group(4),\
'hour': m.group(5), 'minute': m.group(6), 'second': m.group(7),\
'zonediff': m.group(8)}
return _parse_date_rfc822(rfc822date)
|
python
|
def _parse_date_greek(dateString):
'''Parse a string according to a Greek 8-bit date format.'''
m = _greek_date_format_re.match(dateString)
if not m:
return
wday = _greek_wdays[m.group(1)]
month = _greek_months[m.group(3)]
rfc822date = '%(wday)s, %(day)s %(month)s %(year)s %(hour)s:%(minute)s:%(second)s %(zonediff)s' % \
{'wday': wday, 'day': m.group(2), 'month': month, 'year': m.group(4),\
'hour': m.group(5), 'minute': m.group(6), 'second': m.group(7),\
'zonediff': m.group(8)}
return _parse_date_rfc822(rfc822date)
|
[
"def",
"_parse_date_greek",
"(",
"dateString",
")",
":",
"m",
"=",
"_greek_date_format_re",
".",
"match",
"(",
"dateString",
")",
"if",
"not",
"m",
":",
"return",
"wday",
"=",
"_greek_wdays",
"[",
"m",
".",
"group",
"(",
"1",
")",
"]",
"month",
"=",
"_greek_months",
"[",
"m",
".",
"group",
"(",
"3",
")",
"]",
"rfc822date",
"=",
"'%(wday)s, %(day)s %(month)s %(year)s %(hour)s:%(minute)s:%(second)s %(zonediff)s'",
"%",
"{",
"'wday'",
":",
"wday",
",",
"'day'",
":",
"m",
".",
"group",
"(",
"2",
")",
",",
"'month'",
":",
"month",
",",
"'year'",
":",
"m",
".",
"group",
"(",
"4",
")",
",",
"'hour'",
":",
"m",
".",
"group",
"(",
"5",
")",
",",
"'minute'",
":",
"m",
".",
"group",
"(",
"6",
")",
",",
"'second'",
":",
"m",
".",
"group",
"(",
"7",
")",
",",
"'zonediff'",
":",
"m",
".",
"group",
"(",
"8",
")",
"}",
"return",
"_parse_date_rfc822",
"(",
"rfc822date",
")"
] |
Parse a string according to a Greek 8-bit date format.
|
[
"Parse",
"a",
"string",
"according",
"to",
"a",
"Greek",
"8",
"-",
"bit",
"date",
"format",
"."
] |
e7e8d79daf73b35c9259695ad1e379476e1dfc77
|
https://github.com/jmoiron/speedparser/blob/e7e8d79daf73b35c9259695ad1e379476e1dfc77/speedparser/feedparsercompat.py#L366-L377
|
train
|
jmoiron/speedparser
|
speedparser/feedparsercompat.py
|
_parse_date_hungarian
|
def _parse_date_hungarian(dateString):
'''Parse a string according to a Hungarian 8-bit date format.'''
m = _hungarian_date_format_re.match(dateString)
if not m or m.group(2) not in _hungarian_months:
return None
month = _hungarian_months[m.group(2)]
day = m.group(3)
if len(day) == 1:
day = '0' + day
hour = m.group(4)
if len(hour) == 1:
hour = '0' + hour
w3dtfdate = '%(year)s-%(month)s-%(day)sT%(hour)s:%(minute)s%(zonediff)s' % \
{'year': m.group(1), 'month': month, 'day': day,\
'hour': hour, 'minute': m.group(5),\
'zonediff': m.group(6)}
return _parse_date_w3dtf(w3dtfdate)
|
python
|
def _parse_date_hungarian(dateString):
'''Parse a string according to a Hungarian 8-bit date format.'''
m = _hungarian_date_format_re.match(dateString)
if not m or m.group(2) not in _hungarian_months:
return None
month = _hungarian_months[m.group(2)]
day = m.group(3)
if len(day) == 1:
day = '0' + day
hour = m.group(4)
if len(hour) == 1:
hour = '0' + hour
w3dtfdate = '%(year)s-%(month)s-%(day)sT%(hour)s:%(minute)s%(zonediff)s' % \
{'year': m.group(1), 'month': month, 'day': day,\
'hour': hour, 'minute': m.group(5),\
'zonediff': m.group(6)}
return _parse_date_w3dtf(w3dtfdate)
|
[
"def",
"_parse_date_hungarian",
"(",
"dateString",
")",
":",
"m",
"=",
"_hungarian_date_format_re",
".",
"match",
"(",
"dateString",
")",
"if",
"not",
"m",
"or",
"m",
".",
"group",
"(",
"2",
")",
"not",
"in",
"_hungarian_months",
":",
"return",
"None",
"month",
"=",
"_hungarian_months",
"[",
"m",
".",
"group",
"(",
"2",
")",
"]",
"day",
"=",
"m",
".",
"group",
"(",
"3",
")",
"if",
"len",
"(",
"day",
")",
"==",
"1",
":",
"day",
"=",
"'0'",
"+",
"day",
"hour",
"=",
"m",
".",
"group",
"(",
"4",
")",
"if",
"len",
"(",
"hour",
")",
"==",
"1",
":",
"hour",
"=",
"'0'",
"+",
"hour",
"w3dtfdate",
"=",
"'%(year)s-%(month)s-%(day)sT%(hour)s:%(minute)s%(zonediff)s'",
"%",
"{",
"'year'",
":",
"m",
".",
"group",
"(",
"1",
")",
",",
"'month'",
":",
"month",
",",
"'day'",
":",
"day",
",",
"'hour'",
":",
"hour",
",",
"'minute'",
":",
"m",
".",
"group",
"(",
"5",
")",
",",
"'zonediff'",
":",
"m",
".",
"group",
"(",
"6",
")",
"}",
"return",
"_parse_date_w3dtf",
"(",
"w3dtfdate",
")"
] |
Parse a string according to a Hungarian 8-bit date format.
|
[
"Parse",
"a",
"string",
"according",
"to",
"a",
"Hungarian",
"8",
"-",
"bit",
"date",
"format",
"."
] |
e7e8d79daf73b35c9259695ad1e379476e1dfc77
|
https://github.com/jmoiron/speedparser/blob/e7e8d79daf73b35c9259695ad1e379476e1dfc77/speedparser/feedparsercompat.py#L400-L416
|
train
|
jmoiron/speedparser
|
speedparser/feedparsercompat.py
|
_parse_date_rfc822
|
def _parse_date_rfc822(dateString):
'''Parse an RFC822, RFC1123, RFC2822, or asctime-style date'''
data = dateString.split()
if not data:
return None
if data[0][-1] in (',', '.') or data[0].lower() in rfc822._daynames:
del data[0]
if len(data) == 4:
s = data[3]
i = s.find('+')
if i > 0:
data[3:] = [s[:i], s[i+1:]]
else:
data.append('')
dateString = " ".join(data)
# Account for the Etc/GMT timezone by stripping 'Etc/'
elif len(data) == 5 and data[4].lower().startswith('etc/'):
data[4] = data[4][4:]
dateString = " ".join(data)
if len(data) < 5:
dateString += ' 00:00:00 GMT'
tm = rfc822.parsedate_tz(dateString)
if tm:
# Jython doesn't adjust for 2-digit years like CPython does,
# so account for it by shifting the year so that it's in the
# range 1970-2069 (1970 being the year of the Unix epoch).
if tm[0] < 100:
tm = (tm[0] + (1900, 2000)[tm[0] < 70],) + tm[1:]
return time.gmtime(rfc822.mktime_tz(tm))
|
python
|
def _parse_date_rfc822(dateString):
'''Parse an RFC822, RFC1123, RFC2822, or asctime-style date'''
data = dateString.split()
if not data:
return None
if data[0][-1] in (',', '.') or data[0].lower() in rfc822._daynames:
del data[0]
if len(data) == 4:
s = data[3]
i = s.find('+')
if i > 0:
data[3:] = [s[:i], s[i+1:]]
else:
data.append('')
dateString = " ".join(data)
# Account for the Etc/GMT timezone by stripping 'Etc/'
elif len(data) == 5 and data[4].lower().startswith('etc/'):
data[4] = data[4][4:]
dateString = " ".join(data)
if len(data) < 5:
dateString += ' 00:00:00 GMT'
tm = rfc822.parsedate_tz(dateString)
if tm:
# Jython doesn't adjust for 2-digit years like CPython does,
# so account for it by shifting the year so that it's in the
# range 1970-2069 (1970 being the year of the Unix epoch).
if tm[0] < 100:
tm = (tm[0] + (1900, 2000)[tm[0] < 70],) + tm[1:]
return time.gmtime(rfc822.mktime_tz(tm))
|
[
"def",
"_parse_date_rfc822",
"(",
"dateString",
")",
":",
"data",
"=",
"dateString",
".",
"split",
"(",
")",
"if",
"not",
"data",
":",
"return",
"None",
"if",
"data",
"[",
"0",
"]",
"[",
"-",
"1",
"]",
"in",
"(",
"','",
",",
"'.'",
")",
"or",
"data",
"[",
"0",
"]",
".",
"lower",
"(",
")",
"in",
"rfc822",
".",
"_daynames",
":",
"del",
"data",
"[",
"0",
"]",
"if",
"len",
"(",
"data",
")",
"==",
"4",
":",
"s",
"=",
"data",
"[",
"3",
"]",
"i",
"=",
"s",
".",
"find",
"(",
"'+'",
")",
"if",
"i",
">",
"0",
":",
"data",
"[",
"3",
":",
"]",
"=",
"[",
"s",
"[",
":",
"i",
"]",
",",
"s",
"[",
"i",
"+",
"1",
":",
"]",
"]",
"else",
":",
"data",
".",
"append",
"(",
"''",
")",
"dateString",
"=",
"\" \"",
".",
"join",
"(",
"data",
")",
"# Account for the Etc/GMT timezone by stripping 'Etc/'",
"elif",
"len",
"(",
"data",
")",
"==",
"5",
"and",
"data",
"[",
"4",
"]",
".",
"lower",
"(",
")",
".",
"startswith",
"(",
"'etc/'",
")",
":",
"data",
"[",
"4",
"]",
"=",
"data",
"[",
"4",
"]",
"[",
"4",
":",
"]",
"dateString",
"=",
"\" \"",
".",
"join",
"(",
"data",
")",
"if",
"len",
"(",
"data",
")",
"<",
"5",
":",
"dateString",
"+=",
"' 00:00:00 GMT'",
"tm",
"=",
"rfc822",
".",
"parsedate_tz",
"(",
"dateString",
")",
"if",
"tm",
":",
"# Jython doesn't adjust for 2-digit years like CPython does,",
"# so account for it by shifting the year so that it's in the",
"# range 1970-2069 (1970 being the year of the Unix epoch).",
"if",
"tm",
"[",
"0",
"]",
"<",
"100",
":",
"tm",
"=",
"(",
"tm",
"[",
"0",
"]",
"+",
"(",
"1900",
",",
"2000",
")",
"[",
"tm",
"[",
"0",
"]",
"<",
"70",
"]",
",",
")",
"+",
"tm",
"[",
"1",
":",
"]",
"return",
"time",
".",
"gmtime",
"(",
"rfc822",
".",
"mktime_tz",
"(",
"tm",
")",
")"
] |
Parse an RFC822, RFC1123, RFC2822, or asctime-style date
|
[
"Parse",
"an",
"RFC822",
"RFC1123",
"RFC2822",
"or",
"asctime",
"-",
"style",
"date"
] |
e7e8d79daf73b35c9259695ad1e379476e1dfc77
|
https://github.com/jmoiron/speedparser/blob/e7e8d79daf73b35c9259695ad1e379476e1dfc77/speedparser/feedparsercompat.py#L522-L550
|
train
|
jmoiron/speedparser
|
speedparser/feedparsercompat.py
|
_parse_date_perforce
|
def _parse_date_perforce(aDateString):
"""parse a date in yyyy/mm/dd hh:mm:ss TTT format"""
# Fri, 2006/09/15 08:19:53 EDT
_my_date_pattern = re.compile( \
r'(\w{,3}), (\d{,4})/(\d{,2})/(\d{2}) (\d{,2}):(\d{2}):(\d{2}) (\w{,3})')
m = _my_date_pattern.search(aDateString)
if m is None:
return None
dow, year, month, day, hour, minute, second, tz = m.groups()
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
dateString = "%s, %s %s %s %s:%s:%s %s" % (dow, day, months[int(month) - 1], year, hour, minute, second, tz)
tm = rfc822.parsedate_tz(dateString)
if tm:
return time.gmtime(rfc822.mktime_tz(tm))
|
python
|
def _parse_date_perforce(aDateString):
"""parse a date in yyyy/mm/dd hh:mm:ss TTT format"""
# Fri, 2006/09/15 08:19:53 EDT
_my_date_pattern = re.compile( \
r'(\w{,3}), (\d{,4})/(\d{,2})/(\d{2}) (\d{,2}):(\d{2}):(\d{2}) (\w{,3})')
m = _my_date_pattern.search(aDateString)
if m is None:
return None
dow, year, month, day, hour, minute, second, tz = m.groups()
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
dateString = "%s, %s %s %s %s:%s:%s %s" % (dow, day, months[int(month) - 1], year, hour, minute, second, tz)
tm = rfc822.parsedate_tz(dateString)
if tm:
return time.gmtime(rfc822.mktime_tz(tm))
|
[
"def",
"_parse_date_perforce",
"(",
"aDateString",
")",
":",
"# Fri, 2006/09/15 08:19:53 EDT",
"_my_date_pattern",
"=",
"re",
".",
"compile",
"(",
"r'(\\w{,3}), (\\d{,4})/(\\d{,2})/(\\d{2}) (\\d{,2}):(\\d{2}):(\\d{2}) (\\w{,3})'",
")",
"m",
"=",
"_my_date_pattern",
".",
"search",
"(",
"aDateString",
")",
"if",
"m",
"is",
"None",
":",
"return",
"None",
"dow",
",",
"year",
",",
"month",
",",
"day",
",",
"hour",
",",
"minute",
",",
"second",
",",
"tz",
"=",
"m",
".",
"groups",
"(",
")",
"months",
"=",
"[",
"'Jan'",
",",
"'Feb'",
",",
"'Mar'",
",",
"'Apr'",
",",
"'May'",
",",
"'Jun'",
",",
"'Jul'",
",",
"'Aug'",
",",
"'Sep'",
",",
"'Oct'",
",",
"'Nov'",
",",
"'Dec'",
"]",
"dateString",
"=",
"\"%s, %s %s %s %s:%s:%s %s\"",
"%",
"(",
"dow",
",",
"day",
",",
"months",
"[",
"int",
"(",
"month",
")",
"-",
"1",
"]",
",",
"year",
",",
"hour",
",",
"minute",
",",
"second",
",",
"tz",
")",
"tm",
"=",
"rfc822",
".",
"parsedate_tz",
"(",
"dateString",
")",
"if",
"tm",
":",
"return",
"time",
".",
"gmtime",
"(",
"rfc822",
".",
"mktime_tz",
"(",
"tm",
")",
")"
] |
parse a date in yyyy/mm/dd hh:mm:ss TTT format
|
[
"parse",
"a",
"date",
"in",
"yyyy",
"/",
"mm",
"/",
"dd",
"hh",
":",
"mm",
":",
"ss",
"TTT",
"format"
] |
e7e8d79daf73b35c9259695ad1e379476e1dfc77
|
https://github.com/jmoiron/speedparser/blob/e7e8d79daf73b35c9259695ad1e379476e1dfc77/speedparser/feedparsercompat.py#L557-L571
|
train
|
jmoiron/speedparser
|
speedparser/feedparsercompat.py
|
parse_date
|
def parse_date(dateString):
'''Parses a variety of date formats into a 9-tuple in GMT'''
if not dateString:
return None
for handler in _date_handlers:
try:
date9tuple = handler(dateString)
except (KeyError, OverflowError, ValueError):
continue
if not date9tuple:
continue
if len(date9tuple) != 9:
continue
return date9tuple
return None
|
python
|
def parse_date(dateString):
'''Parses a variety of date formats into a 9-tuple in GMT'''
if not dateString:
return None
for handler in _date_handlers:
try:
date9tuple = handler(dateString)
except (KeyError, OverflowError, ValueError):
continue
if not date9tuple:
continue
if len(date9tuple) != 9:
continue
return date9tuple
return None
|
[
"def",
"parse_date",
"(",
"dateString",
")",
":",
"if",
"not",
"dateString",
":",
"return",
"None",
"for",
"handler",
"in",
"_date_handlers",
":",
"try",
":",
"date9tuple",
"=",
"handler",
"(",
"dateString",
")",
"except",
"(",
"KeyError",
",",
"OverflowError",
",",
"ValueError",
")",
":",
"continue",
"if",
"not",
"date9tuple",
":",
"continue",
"if",
"len",
"(",
"date9tuple",
")",
"!=",
"9",
":",
"continue",
"return",
"date9tuple",
"return",
"None"
] |
Parses a variety of date formats into a 9-tuple in GMT
|
[
"Parses",
"a",
"variety",
"of",
"date",
"formats",
"into",
"a",
"9",
"-",
"tuple",
"in",
"GMT"
] |
e7e8d79daf73b35c9259695ad1e379476e1dfc77
|
https://github.com/jmoiron/speedparser/blob/e7e8d79daf73b35c9259695ad1e379476e1dfc77/speedparser/feedparsercompat.py#L574-L588
|
train
|
AaronWatters/jp_proxy_widget
|
jp_proxy_widget/uploader.py
|
UnicodeUploader.handle_chunk_wrapper
|
def handle_chunk_wrapper(self, status, name, content, file_info):
"""wrapper to allow output redirects for handle_chunk."""
out = self.output
if out is not None:
with out:
print("handling chunk " + repr(type(content)))
self.handle_chunk(status, name, content, file_info)
else:
self.handle_chunk(status, name, content, file_info)
|
python
|
def handle_chunk_wrapper(self, status, name, content, file_info):
"""wrapper to allow output redirects for handle_chunk."""
out = self.output
if out is not None:
with out:
print("handling chunk " + repr(type(content)))
self.handle_chunk(status, name, content, file_info)
else:
self.handle_chunk(status, name, content, file_info)
|
[
"def",
"handle_chunk_wrapper",
"(",
"self",
",",
"status",
",",
"name",
",",
"content",
",",
"file_info",
")",
":",
"out",
"=",
"self",
".",
"output",
"if",
"out",
"is",
"not",
"None",
":",
"with",
"out",
":",
"print",
"(",
"\"handling chunk \"",
"+",
"repr",
"(",
"type",
"(",
"content",
")",
")",
")",
"self",
".",
"handle_chunk",
"(",
"status",
",",
"name",
",",
"content",
",",
"file_info",
")",
"else",
":",
"self",
".",
"handle_chunk",
"(",
"status",
",",
"name",
",",
"content",
",",
"file_info",
")"
] |
wrapper to allow output redirects for handle_chunk.
|
[
"wrapper",
"to",
"allow",
"output",
"redirects",
"for",
"handle_chunk",
"."
] |
e53789c9b8a587e2f6e768d16b68e0ae5b3790d9
|
https://github.com/AaronWatters/jp_proxy_widget/blob/e53789c9b8a587e2f6e768d16b68e0ae5b3790d9/jp_proxy_widget/uploader.py#L106-L114
|
train
|
AaronWatters/jp_proxy_widget
|
jp_proxy_widget/uploader.py
|
UnicodeUploader.handle_chunk
|
def handle_chunk(self, status, name, content, file_info):
"Handle one chunk of the file. Override this method for peicewise delivery or error handling."
if status == "error":
msg = repr(file_info.get("message"))
exc = JavaScriptError(msg)
exc.file_info = file_info
self.status = "Javascript sent exception " + msg
self.chunk_collector = []
raise exc
if status == "more":
self.chunk_collector.append(content)
self.progress_callback(self.chunk_collector, file_info)
else:
assert status == "done", "Unknown status " + repr(status)
self.save_chunks = self.chunk_collector
self.chunk_collector.append(content)
all_content = self.combine_chunks(self.chunk_collector)
self.chunk_collector = []
content_callback = self.content_callback
if content_callback is None:
content_callback = self.default_content_callback
self.status = "calling " + repr(content_callback)
try:
content_callback(self.widget, name, all_content)
except Exception as e:
self.status += "\n" + repr(content_callback) + " raised " + repr(e)
raise
|
python
|
def handle_chunk(self, status, name, content, file_info):
"Handle one chunk of the file. Override this method for peicewise delivery or error handling."
if status == "error":
msg = repr(file_info.get("message"))
exc = JavaScriptError(msg)
exc.file_info = file_info
self.status = "Javascript sent exception " + msg
self.chunk_collector = []
raise exc
if status == "more":
self.chunk_collector.append(content)
self.progress_callback(self.chunk_collector, file_info)
else:
assert status == "done", "Unknown status " + repr(status)
self.save_chunks = self.chunk_collector
self.chunk_collector.append(content)
all_content = self.combine_chunks(self.chunk_collector)
self.chunk_collector = []
content_callback = self.content_callback
if content_callback is None:
content_callback = self.default_content_callback
self.status = "calling " + repr(content_callback)
try:
content_callback(self.widget, name, all_content)
except Exception as e:
self.status += "\n" + repr(content_callback) + " raised " + repr(e)
raise
|
[
"def",
"handle_chunk",
"(",
"self",
",",
"status",
",",
"name",
",",
"content",
",",
"file_info",
")",
":",
"if",
"status",
"==",
"\"error\"",
":",
"msg",
"=",
"repr",
"(",
"file_info",
".",
"get",
"(",
"\"message\"",
")",
")",
"exc",
"=",
"JavaScriptError",
"(",
"msg",
")",
"exc",
".",
"file_info",
"=",
"file_info",
"self",
".",
"status",
"=",
"\"Javascript sent exception \"",
"+",
"msg",
"self",
".",
"chunk_collector",
"=",
"[",
"]",
"raise",
"exc",
"if",
"status",
"==",
"\"more\"",
":",
"self",
".",
"chunk_collector",
".",
"append",
"(",
"content",
")",
"self",
".",
"progress_callback",
"(",
"self",
".",
"chunk_collector",
",",
"file_info",
")",
"else",
":",
"assert",
"status",
"==",
"\"done\"",
",",
"\"Unknown status \"",
"+",
"repr",
"(",
"status",
")",
"self",
".",
"save_chunks",
"=",
"self",
".",
"chunk_collector",
"self",
".",
"chunk_collector",
".",
"append",
"(",
"content",
")",
"all_content",
"=",
"self",
".",
"combine_chunks",
"(",
"self",
".",
"chunk_collector",
")",
"self",
".",
"chunk_collector",
"=",
"[",
"]",
"content_callback",
"=",
"self",
".",
"content_callback",
"if",
"content_callback",
"is",
"None",
":",
"content_callback",
"=",
"self",
".",
"default_content_callback",
"self",
".",
"status",
"=",
"\"calling \"",
"+",
"repr",
"(",
"content_callback",
")",
"try",
":",
"content_callback",
"(",
"self",
".",
"widget",
",",
"name",
",",
"all_content",
")",
"except",
"Exception",
"as",
"e",
":",
"self",
".",
"status",
"+=",
"\"\\n\"",
"+",
"repr",
"(",
"content_callback",
")",
"+",
"\" raised \"",
"+",
"repr",
"(",
"e",
")",
"raise"
] |
Handle one chunk of the file. Override this method for peicewise delivery or error handling.
|
[
"Handle",
"one",
"chunk",
"of",
"the",
"file",
".",
"Override",
"this",
"method",
"for",
"peicewise",
"delivery",
"or",
"error",
"handling",
"."
] |
e53789c9b8a587e2f6e768d16b68e0ae5b3790d9
|
https://github.com/AaronWatters/jp_proxy_widget/blob/e53789c9b8a587e2f6e768d16b68e0ae5b3790d9/jp_proxy_widget/uploader.py#L116-L142
|
train
|
ORCID/python-orcid
|
orcid/orcid.py
|
PublicAPI.get_login_url
|
def get_login_url(self, scope, redirect_uri, state=None,
family_names=None, given_names=None, email=None,
lang=None, show_login=None):
"""Return a URL for a user to login/register with ORCID.
Parameters
----------
:param scope: string or iterable of strings
The scope(s) of the authorization request.
For example '/authenticate'
:param redirect_uri: string
The URI to which the user's browser should be redirected after the
login.
:param state: string
An arbitrary token to prevent CSRF. See the OAuth 2 docs for
details.
:param family_names: string
The user's family name, used to fill the registration form.
:param given_names: string
The user's given name, used to fill the registration form.
:param email: string
The user's email address, used to fill the sign-in or registration
form.
:param lang: string
The language in which to display the authorization page.
:param show_login: bool
Determines whether the log-in or registration form will be shown by
default.
Returns
-------
:returns: string
The URL ready to be offered as a link to the user.
"""
if not isinstance(scope, string_types):
scope = " ".join(sorted(set(scope)))
data = [("client_id", self._key), ("scope", scope),
("response_type", "code"), ("redirect_uri", redirect_uri)]
if state:
data.append(("state", state))
if family_names:
data.append(("family_names", family_names.encode("utf-8")))
if given_names:
data.append(("given_names", given_names.encode("utf-8")))
if email:
data.append(("email", email))
if lang:
data.append(("lang", lang))
if show_login is not None:
data.append(("show_login", "true" if show_login else "false"))
return self._login_or_register_endpoint + "?" + urlencode(data)
|
python
|
def get_login_url(self, scope, redirect_uri, state=None,
family_names=None, given_names=None, email=None,
lang=None, show_login=None):
"""Return a URL for a user to login/register with ORCID.
Parameters
----------
:param scope: string or iterable of strings
The scope(s) of the authorization request.
For example '/authenticate'
:param redirect_uri: string
The URI to which the user's browser should be redirected after the
login.
:param state: string
An arbitrary token to prevent CSRF. See the OAuth 2 docs for
details.
:param family_names: string
The user's family name, used to fill the registration form.
:param given_names: string
The user's given name, used to fill the registration form.
:param email: string
The user's email address, used to fill the sign-in or registration
form.
:param lang: string
The language in which to display the authorization page.
:param show_login: bool
Determines whether the log-in or registration form will be shown by
default.
Returns
-------
:returns: string
The URL ready to be offered as a link to the user.
"""
if not isinstance(scope, string_types):
scope = " ".join(sorted(set(scope)))
data = [("client_id", self._key), ("scope", scope),
("response_type", "code"), ("redirect_uri", redirect_uri)]
if state:
data.append(("state", state))
if family_names:
data.append(("family_names", family_names.encode("utf-8")))
if given_names:
data.append(("given_names", given_names.encode("utf-8")))
if email:
data.append(("email", email))
if lang:
data.append(("lang", lang))
if show_login is not None:
data.append(("show_login", "true" if show_login else "false"))
return self._login_or_register_endpoint + "?" + urlencode(data)
|
[
"def",
"get_login_url",
"(",
"self",
",",
"scope",
",",
"redirect_uri",
",",
"state",
"=",
"None",
",",
"family_names",
"=",
"None",
",",
"given_names",
"=",
"None",
",",
"email",
"=",
"None",
",",
"lang",
"=",
"None",
",",
"show_login",
"=",
"None",
")",
":",
"if",
"not",
"isinstance",
"(",
"scope",
",",
"string_types",
")",
":",
"scope",
"=",
"\" \"",
".",
"join",
"(",
"sorted",
"(",
"set",
"(",
"scope",
")",
")",
")",
"data",
"=",
"[",
"(",
"\"client_id\"",
",",
"self",
".",
"_key",
")",
",",
"(",
"\"scope\"",
",",
"scope",
")",
",",
"(",
"\"response_type\"",
",",
"\"code\"",
")",
",",
"(",
"\"redirect_uri\"",
",",
"redirect_uri",
")",
"]",
"if",
"state",
":",
"data",
".",
"append",
"(",
"(",
"\"state\"",
",",
"state",
")",
")",
"if",
"family_names",
":",
"data",
".",
"append",
"(",
"(",
"\"family_names\"",
",",
"family_names",
".",
"encode",
"(",
"\"utf-8\"",
")",
")",
")",
"if",
"given_names",
":",
"data",
".",
"append",
"(",
"(",
"\"given_names\"",
",",
"given_names",
".",
"encode",
"(",
"\"utf-8\"",
")",
")",
")",
"if",
"email",
":",
"data",
".",
"append",
"(",
"(",
"\"email\"",
",",
"email",
")",
")",
"if",
"lang",
":",
"data",
".",
"append",
"(",
"(",
"\"lang\"",
",",
"lang",
")",
")",
"if",
"show_login",
"is",
"not",
"None",
":",
"data",
".",
"append",
"(",
"(",
"\"show_login\"",
",",
"\"true\"",
"if",
"show_login",
"else",
"\"false\"",
")",
")",
"return",
"self",
".",
"_login_or_register_endpoint",
"+",
"\"?\"",
"+",
"urlencode",
"(",
"data",
")"
] |
Return a URL for a user to login/register with ORCID.
Parameters
----------
:param scope: string or iterable of strings
The scope(s) of the authorization request.
For example '/authenticate'
:param redirect_uri: string
The URI to which the user's browser should be redirected after the
login.
:param state: string
An arbitrary token to prevent CSRF. See the OAuth 2 docs for
details.
:param family_names: string
The user's family name, used to fill the registration form.
:param given_names: string
The user's given name, used to fill the registration form.
:param email: string
The user's email address, used to fill the sign-in or registration
form.
:param lang: string
The language in which to display the authorization page.
:param show_login: bool
Determines whether the log-in or registration form will be shown by
default.
Returns
-------
:returns: string
The URL ready to be offered as a link to the user.
|
[
"Return",
"a",
"URL",
"for",
"a",
"user",
"to",
"login",
"/",
"register",
"with",
"ORCID",
"."
] |
217a56a905f53aef94811e54b4e651a1b09c1f76
|
https://github.com/ORCID/python-orcid/blob/217a56a905f53aef94811e54b4e651a1b09c1f76/orcid/orcid.py#L80-L130
|
train
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.