Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getCurrentToken(allowCookie=True)
kwargs['params'] = params
# Add before call for the API method. Listeners can return
# their own responses by calling preventDefault() and
# adding a response on the event.
if hasattr(self, 'resourceName'):
resource = self.resourceName
else:
resource = handler.__module__.rsplit('.', 1)[-1]
routeStr = '/'.join((resource, '/'.join(route))).rstrip('/')
eventPrefix = '.'.join(('rest', method, routeStr))
event = events.trigger('.'.join((eventPrefix, 'before')),
kwargs, pre=self._defaultAccess)
if event.defaultPrevented and len(event.responses) > 0:
val = event.responses[0]
else:
self._defaultAccess(handler)
val = handler(**kwargs)
# Fire the after-call event that has a chance to augment the
# return value of the API method that was called. You can
# reassign the return value completely by adding a response to
# the event and calling preventDefault() on it.
kwargs['returnVal'] = val
event = events.trigger('.'.join((eventPrefix, 'after')), kwargs)
if event.defaultPrevented and len(event.responses) > 0:
val = event.responses[0]
cherrypy.request.girderAllowCookie = True
kwargs['params'] = params
# Add before call for the API method. Listeners can return
# their own responses by calling preventDefault() and
# adding a response on the event.
if hasattr(self, 'resourceName'):
resource = self.resourceName
else:
resource = handler.__module__.rsplit('.', 1)[-1]
routeStr = '/'.join((resource, '/'.join(route))).rstrip('/')
eventPrefix = '.'.join(('rest', method, routeStr))
event = events.trigger('.'.join((eventPrefix, 'before')),
kwargs, pre=self._defaultAccess)
if event.defaultPrevented and len(event.responses) > 0:
val = event.responses[0]
else:
self._defaultAccess(handler)
val = handler(**kwargs)
# Fire the after-call event that has a chance to augment the
# return value of the API method that was called. You can
# reassign the return value completely by adding a response to
# the event and calling preventDefault() on it.
kwargs['returnVal'] = val
event = events.trigger('.'.join((eventPrefix, 'after')), kwargs)
if event.defaultPrevented and len(event.responses) > 0:
val = event.responses[0]
"""
This should only be called manually in the case of creating an
empty file, i.e. one that has no chunks.
:param upload: The upload document.
:type upload: dict
:param assetstore: If known, the containing assetstore for the upload.
:type assetstore: dict
:returns: The file object that was created.
"""
from .assetstore import Assetstore
from .file import File
from .item import Item
from girder.utility import assetstore_utilities
events.trigger('model.upload.finalize', upload)
if assetstore is None:
assetstore = Assetstore().load(upload['assetstoreId'])
if 'fileId' in upload: # Updating an existing file's contents
file = File().load(upload['fileId'], force=True)
# Delete the previous file contents from the containing assetstore
assetstore_utilities.getAssetstoreAdapter(
Assetstore().load(file['assetstoreId'])).deleteFile(file)
item = Item().load(file['itemId'], force=True)
File().propagateSizeChange(item, upload['size'] - file['size'])
# Update file info
file['creatorId'] = upload['userId']
file['created'] = datetime.datetime.utcnow()
def scheduleJob(self, job):
"""
Trigger the event to schedule this job. Other plugins are in charge of
actually scheduling and/or executing the job, except in the case when
the handler is 'local'.
"""
if job.get('async') is True:
events.daemon.trigger('jobs.schedule', info=job)
else:
events.trigger('jobs.schedule', info=job)
def validTransitions(job, status):
"""
Returns a list of states that it is valid to transition from for the
status.
:param status: The status being transitioned to.
:type status: str
:return Returns list of states it valid to transition from.
"""
event = events.trigger('jobs.status.validTransitions', info={
'job': job,
'status': status
})
if event.defaultPrevented and len(event.responses):
return event.responses[-1]
return JobStatus.valid_transitions.get(status)
eventPrefix = '.'.join(('rest', method, routeStr))
event = events.trigger('.'.join((eventPrefix, 'before')),
kwargs, pre=self._defaultAccess)
if event.defaultPrevented and len(event.responses) > 0:
val = event.responses[0]
else:
self._defaultAccess(handler)
val = handler(**kwargs)
# Fire the after-call event that has a chance to augment the
# return value of the API method that was called. You can
# reassign the return value completely by adding a response to
# the event and calling preventDefault() on it.
kwargs['returnVal'] = val
event = events.trigger('.'.join((eventPrefix, 'after')), kwargs)
if event.defaultPrevented and len(event.responses) > 0:
val = event.responses[0]
return val
raise RestException('No matching route for "%s %s"' % (
method.upper(), '/'.join(path)))
def createThumbnail(width, height, crop, fileId, attachToType, attachToId):
"""
Creates the thumbnail. Validation and access control must be done prior
to the invocation of this method.
"""
fileModel = File()
file = fileModel.load(fileId, force=True)
streamFn = functools.partial(fileModel.download, file, headers=False)
event = events.trigger('thumbnails.create', info={
'file': file,
'width': width,
'height': height,
'crop': crop,
'attachToType': attachToType,
'attachToId': attachToId,
'streamFn': streamFn
})
if len(event.responses):
resp = event.responses[-1]
newFile = resp['file']
if event.defaultPrevented:
if resp.get('attach', True):
newFile = attachThumbnail(file, newFile, attachToType, attachToId, width, height)
eventPrefix = '.'.join(('rest', method, routeStr))
event = events.trigger('.'.join((eventPrefix, 'before')),
kwargs, pre=self._defaultAccess)
if event.defaultPrevented and len(event.responses) > 0:
val = event.responses[0]
else:
self._defaultAccess(handler)
val = handler(**kwargs)
# Fire the after-call event that has a chance to augment the
# return value of the API method that was called. You can
# reassign the return value completely by adding a response to
# the event and calling preventDefault() on it.
kwargs['returnVal'] = val
event = events.trigger('.'.join((eventPrefix, 'after')), kwargs)
if event.defaultPrevented and len(event.responses) > 0:
val = event.responses[0]
return val
try:
for image in result['response']['docs']:
image['highlight'] = result['highlighting'][image['id']]
except KeyError:
return {
'numFound': 0,
'docs': []
}
response = {
'numFound': result['response']['numFound'],
'docs': result['response']['docs']
}
# Give plugins a chance to adjust the end response of the imagesearch
event = events.trigger('imagespace.imagesearch.results', response)
for eventResponse in event.responses:
response = eventResponse
return response
getImageSearch.description = Description('Searches image database')