repository_name
stringlengths
7
55
func_path_in_repository
stringlengths
4
223
func_name
stringlengths
1
134
whole_func_string
stringlengths
75
104k
language
stringclasses
1 value
func_code_string
stringlengths
75
104k
func_code_tokens
listlengths
19
28.4k
func_documentation_string
stringlengths
1
46.9k
func_documentation_tokens
listlengths
1
1.97k
split_name
stringclasses
1 value
func_code_url
stringlengths
87
315
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/manager.py
AsperaTransferCoordinatorController.free_processed_queue
def free_processed_queue(self): ''' call the Aspera sdk to freeup resources ''' with self._lock: if len(self._processed_coordinators) > 0: for _coordinator in self._processed_coordinators: _coordinator.free_resources() self._processed_coord...
python
def free_processed_queue(self): ''' call the Aspera sdk to freeup resources ''' with self._lock: if len(self._processed_coordinators) > 0: for _coordinator in self._processed_coordinators: _coordinator.free_resources() self._processed_coord...
[ "def", "free_processed_queue", "(", "self", ")", ":", "with", "self", ".", "_lock", ":", "if", "len", "(", "self", ".", "_processed_coordinators", ")", ">", "0", ":", "for", "_coordinator", "in", "self", ".", "_processed_coordinators", ":", "_coordinator", "...
call the Aspera sdk to freeup resources
[ "call", "the", "Aspera", "sdk", "to", "freeup", "resources" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/manager.py#L567-L573
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/manager.py
AsperaTransferCoordinatorController.is_stop
def is_stop(self): ''' has either of the stop processing flags been set ''' if len(self._processed_coordinators) > 0: self.free_processed_queue() return self._cancel_called or self._processing_stop
python
def is_stop(self): ''' has either of the stop processing flags been set ''' if len(self._processed_coordinators) > 0: self.free_processed_queue() return self._cancel_called or self._processing_stop
[ "def", "is_stop", "(", "self", ")", ":", "if", "len", "(", "self", ".", "_processed_coordinators", ")", ">", "0", ":", "self", ".", "free_processed_queue", "(", ")", "return", "self", ".", "_cancel_called", "or", "self", ".", "_processing_stop" ]
has either of the stop processing flags been set
[ "has", "either", "of", "the", "stop", "processing", "flags", "been", "set" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/manager.py#L575-L579
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/manager.py
AsperaTransferCoordinatorController._process_waiting_queue
def _process_waiting_queue(self): ''' thread to processes the waiting queue fetches transfer spec then calls start transfer ensures that max ascp is not exceeded ''' logger.info("Queue processing thread started") while not self.is_stop(): self._pro...
python
def _process_waiting_queue(self): ''' thread to processes the waiting queue fetches transfer spec then calls start transfer ensures that max ascp is not exceeded ''' logger.info("Queue processing thread started") while not self.is_stop(): self._pro...
[ "def", "_process_waiting_queue", "(", "self", ")", ":", "logger", ".", "info", "(", "\"Queue processing thread started\"", ")", "while", "not", "self", ".", "is_stop", "(", ")", ":", "self", ".", "_processing_event", ".", "wait", "(", "3", ")", "self", ".", ...
thread to processes the waiting queue fetches transfer spec then calls start transfer ensures that max ascp is not exceeded
[ "thread", "to", "processes", "the", "waiting", "queue", "fetches", "transfer", "spec", "then", "calls", "start", "transfer", "ensures", "that", "max", "ascp", "is", "not", "exceeded" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/manager.py#L581-L620
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/manager.py
AsperaTransferCoordinatorController.clear_waiting_coordinators
def clear_waiting_coordinators(self, cancel=False): ''' remove all entries from waiting queue or cancell all in waiting queue ''' with self._lockw: if cancel: for _coordinator in self._waiting_transfer_coordinators: _coordinator.notify_cancelled("Clear Wai...
python
def clear_waiting_coordinators(self, cancel=False): ''' remove all entries from waiting queue or cancell all in waiting queue ''' with self._lockw: if cancel: for _coordinator in self._waiting_transfer_coordinators: _coordinator.notify_cancelled("Clear Wai...
[ "def", "clear_waiting_coordinators", "(", "self", ",", "cancel", "=", "False", ")", ":", "with", "self", ".", "_lockw", ":", "if", "cancel", ":", "for", "_coordinator", "in", "self", ".", "_waiting_transfer_coordinators", ":", "_coordinator", ".", "notify_cancel...
remove all entries from waiting queue or cancell all in waiting queue
[ "remove", "all", "entries", "from", "waiting", "queue", "or", "cancell", "all", "in", "waiting", "queue" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/manager.py#L622-L628
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/manager.py
AsperaTransferCoordinatorController.cancel
def cancel(self, *args, **kwargs): """ Cancel all queue items - then attempt to cancel all in progress items """ self._cancel_called = True self.clear_waiting_coordinators(cancel=True) super(AsperaTransferCoordinatorController, self).cancel(*args, **kwargs)
python
def cancel(self, *args, **kwargs): """ Cancel all queue items - then attempt to cancel all in progress items """ self._cancel_called = True self.clear_waiting_coordinators(cancel=True) super(AsperaTransferCoordinatorController, self).cancel(*args, **kwargs)
[ "def", "cancel", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "self", ".", "_cancel_called", "=", "True", "self", ".", "clear_waiting_coordinators", "(", "cancel", "=", "True", ")", "super", "(", "AsperaTransferCoordinatorController", ",...
Cancel all queue items - then attempt to cancel all in progress items
[ "Cancel", "all", "queue", "items", "-", "then", "attempt", "to", "cancel", "all", "in", "progress", "items" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/manager.py#L630-L634
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/manager.py
AsperaTransferCoordinatorController.wait
def wait(self): """ Wait until all in progress and queued items are processed """ self._wait_called = True while self.tracked_coordinator_count() > 0 or \ self.waiting_coordinator_count() > 0: time.sleep(1) super(AsperaTransferCoordinatorController, self)....
python
def wait(self): """ Wait until all in progress and queued items are processed """ self._wait_called = True while self.tracked_coordinator_count() > 0 or \ self.waiting_coordinator_count() > 0: time.sleep(1) super(AsperaTransferCoordinatorController, self)....
[ "def", "wait", "(", "self", ")", ":", "self", ".", "_wait_called", "=", "True", "while", "self", ".", "tracked_coordinator_count", "(", ")", ">", "0", "or", "self", ".", "waiting_coordinator_count", "(", ")", ">", "0", ":", "time", ".", "sleep", "(", "...
Wait until all in progress and queued items are processed
[ "Wait", "until", "all", "in", "progress", "and", "queued", "items", "are", "processed" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/manager.py#L636-L643
SuperCowPowers/workbench
workbench/workers/view_zip.py
ViewZip.execute
def execute(self, input_data): ''' Execute the ViewZip worker ''' # Just a small check to make sure we haven't been called on the wrong file type if (input_data['meta']['type_tag'] != 'zip'): return {'error': self.__class__.__name__+': called on '+input_data['meta']['type_tag']} ...
python
def execute(self, input_data): ''' Execute the ViewZip worker ''' # Just a small check to make sure we haven't been called on the wrong file type if (input_data['meta']['type_tag'] != 'zip'): return {'error': self.__class__.__name__+': called on '+input_data['meta']['type_tag']} ...
[ "def", "execute", "(", "self", ",", "input_data", ")", ":", "# Just a small check to make sure we haven't been called on the wrong file type", "if", "(", "input_data", "[", "'meta'", "]", "[", "'type_tag'", "]", "!=", "'zip'", ")", ":", "return", "{", "'error'", ":"...
Execute the ViewZip worker
[ "Execute", "the", "ViewZip", "worker" ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/workers/view_zip.py#L15-L29
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/futures.py
AsperaTransferFuture.set_exception
def set_exception(self, exception): """Sets the exception on the future.""" if not self.is_done(): raise TransferNotDoneError( 'set_exception can only be called once the transfer is ' 'complete.') self._coordinator.set_exception(exception, override=Tru...
python
def set_exception(self, exception): """Sets the exception on the future.""" if not self.is_done(): raise TransferNotDoneError( 'set_exception can only be called once the transfer is ' 'complete.') self._coordinator.set_exception(exception, override=Tru...
[ "def", "set_exception", "(", "self", ",", "exception", ")", ":", "if", "not", "self", ".", "is_done", "(", ")", ":", "raise", "TransferNotDoneError", "(", "'set_exception can only be called once the transfer is '", "'complete.'", ")", "self", ".", "_coordinator", "....
Sets the exception on the future.
[ "Sets", "the", "exception", "on", "the", "future", "." ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/futures.py#L126-L132
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/futures.py
AsperaTransferListener.transferReporter
def transferReporter(self, xferId, message): ''' the callback method used by the Aspera sdk during transfer to notify progress, error or successful completion ''' if self.is_stopped(): return True _asp_message = AsperaMessage(message) if not _asp_message...
python
def transferReporter(self, xferId, message): ''' the callback method used by the Aspera sdk during transfer to notify progress, error or successful completion ''' if self.is_stopped(): return True _asp_message = AsperaMessage(message) if not _asp_message...
[ "def", "transferReporter", "(", "self", ",", "xferId", ",", "message", ")", ":", "if", "self", ".", "is_stopped", "(", ")", ":", "return", "True", "_asp_message", "=", "AsperaMessage", "(", "message", ")", "if", "not", "_asp_message", ".", "is_msg_type", "...
the callback method used by the Aspera sdk during transfer to notify progress, error or successful completion
[ "the", "callback", "method", "used", "by", "the", "Aspera", "sdk", "during", "transfer", "to", "notify", "progress", "error", "or", "successful", "completion" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/futures.py#L160-L201
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/futures.py
AsperaTransferListener.start_transfer
def start_transfer(self): ''' pass the transfer spec to the Aspera sdk and start the transfer ''' try: if not self.is_done(): faspmanager2.startTransfer(self.get_transfer_id(), None, self.ge...
python
def start_transfer(self): ''' pass the transfer spec to the Aspera sdk and start the transfer ''' try: if not self.is_done(): faspmanager2.startTransfer(self.get_transfer_id(), None, self.ge...
[ "def", "start_transfer", "(", "self", ")", ":", "try", ":", "if", "not", "self", ".", "is_done", "(", ")", ":", "faspmanager2", ".", "startTransfer", "(", "self", ".", "get_transfer_id", "(", ")", ",", "None", ",", "self", ".", "get_transfer_spec", "(", ...
pass the transfer spec to the Aspera sdk and start the transfer
[ "pass", "the", "transfer", "spec", "to", "the", "Aspera", "sdk", "and", "start", "the", "transfer" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/futures.py#L203-L212
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/futures.py
AsperaTransferListener.is_running
def is_running(self, is_stopped): ''' check whether a transfer is currently running ''' if is_stopped and self.is_stopped(): return False return faspmanager2.isRunning(self.get_transfer_id())
python
def is_running(self, is_stopped): ''' check whether a transfer is currently running ''' if is_stopped and self.is_stopped(): return False return faspmanager2.isRunning(self.get_transfer_id())
[ "def", "is_running", "(", "self", ",", "is_stopped", ")", ":", "if", "is_stopped", "and", "self", ".", "is_stopped", "(", ")", ":", "return", "False", "return", "faspmanager2", ".", "isRunning", "(", "self", ".", "get_transfer_id", "(", ")", ")" ]
check whether a transfer is currently running
[ "check", "whether", "a", "transfer", "is", "currently", "running" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/futures.py#L227-L232
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/futures.py
AsperaTransferListener.is_stopped
def is_stopped(self, is_stopping=True): ''' check whether a transfer is stopped or is being stopped ''' if is_stopping: return self._is_stopped or self._is_stopping return self._is_stopped
python
def is_stopped(self, is_stopping=True): ''' check whether a transfer is stopped or is being stopped ''' if is_stopping: return self._is_stopped or self._is_stopping return self._is_stopped
[ "def", "is_stopped", "(", "self", ",", "is_stopping", "=", "True", ")", ":", "if", "is_stopping", ":", "return", "self", ".", "_is_stopped", "or", "self", ".", "_is_stopping", "return", "self", ".", "_is_stopped" ]
check whether a transfer is stopped or is being stopped
[ "check", "whether", "a", "transfer", "is", "stopped", "or", "is", "being", "stopped" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/futures.py#L234-L238
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/futures.py
AsperaTransferListener._modify_transfer
def _modify_transfer(self, option, value=0): ''' call Apsera sdk modify an in progress eg pause/resume allowed values defined in enumAsperaModifyTransfer class ''' _ret = False try: if self.is_running(True): logger.info("ModifyTransfer called %d = %d" % (o...
python
def _modify_transfer(self, option, value=0): ''' call Apsera sdk modify an in progress eg pause/resume allowed values defined in enumAsperaModifyTransfer class ''' _ret = False try: if self.is_running(True): logger.info("ModifyTransfer called %d = %d" % (o...
[ "def", "_modify_transfer", "(", "self", ",", "option", ",", "value", "=", "0", ")", ":", "_ret", "=", "False", "try", ":", "if", "self", ".", "is_running", "(", "True", ")", ":", "logger", ".", "info", "(", "\"ModifyTransfer called %d = %d\"", "%", "(", ...
call Apsera sdk modify an in progress eg pause/resume allowed values defined in enumAsperaModifyTransfer class
[ "call", "Apsera", "sdk", "modify", "an", "in", "progress", "eg", "pause", "/", "resume", "allowed", "values", "defined", "in", "enumAsperaModifyTransfer", "class" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/futures.py#L240-L252
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/futures.py
AsperaTransferListener.stop
def stop(self, free_resource=False): ''' send a stop transfer request to the Aspera sdk, can be done for: cancel - stop an in progress transfer free_resource - request to the Aspera sdk free resouces related to trasnfer_id ''' if not self.is_stopped(): self._...
python
def stop(self, free_resource=False): ''' send a stop transfer request to the Aspera sdk, can be done for: cancel - stop an in progress transfer free_resource - request to the Aspera sdk free resouces related to trasnfer_id ''' if not self.is_stopped(): self._...
[ "def", "stop", "(", "self", ",", "free_resource", "=", "False", ")", ":", "if", "not", "self", ".", "is_stopped", "(", ")", ":", "self", ".", "_is_stopping", "=", "True", "try", ":", "if", "free_resource", "or", "self", ".", "is_running", "(", "False",...
send a stop transfer request to the Aspera sdk, can be done for: cancel - stop an in progress transfer free_resource - request to the Aspera sdk free resouces related to trasnfer_id
[ "send", "a", "stop", "transfer", "request", "to", "the", "Aspera", "sdk", "can", "be", "done", "for", ":", "cancel", "-", "stop", "an", "in", "progress", "transfer", "free_resource", "-", "request", "to", "the", "Aspera", "sdk", "free", "resouces", "relate...
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/futures.py#L254-L274
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/futures.py
AsperaTransferListener.free_resources
def free_resources(self): ''' call stop to free up resources ''' if not self.is_stopped(): logger.info("Freeing resources: %s" % self.get_transfer_id()) self.stop(True)
python
def free_resources(self): ''' call stop to free up resources ''' if not self.is_stopped(): logger.info("Freeing resources: %s" % self.get_transfer_id()) self.stop(True)
[ "def", "free_resources", "(", "self", ")", ":", "if", "not", "self", ".", "is_stopped", "(", ")", ":", "logger", ".", "info", "(", "\"Freeing resources: %s\"", "%", "self", ".", "get_transfer_id", "(", ")", ")", "self", ".", "stop", "(", "True", ")" ]
call stop to free up resources
[ "call", "stop", "to", "free", "up", "resources" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/futures.py#L276-L280
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/futures.py
AsperaMessage.extract_message_value
def extract_message_value(self, name): ''' search message to find and extract a named value ''' name += ":" assert(self._message) _start = self._message.find(name) if _start >= 0: _start += len(name) + 1 _end = self._message.find("\n", _start) ...
python
def extract_message_value(self, name): ''' search message to find and extract a named value ''' name += ":" assert(self._message) _start = self._message.find(name) if _start >= 0: _start += len(name) + 1 _end = self._message.find("\n", _start) ...
[ "def", "extract_message_value", "(", "self", ",", "name", ")", ":", "name", "+=", "\":\"", "assert", "(", "self", ".", "_message", ")", "_start", "=", "self", ".", "_message", ".", "find", "(", "name", ")", "if", "_start", ">=", "0", ":", "_start", "...
search message to find and extract a named value
[ "search", "message", "to", "find", "and", "extract", "a", "named", "value" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/futures.py#L302-L313
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/futures.py
AsperaSession._set_status
def _set_status(self, status, ex=None): ''' set session status - eg failed, success -- valid values contained in enumAsperaControllerStatus class ''' self._status = status logger.debug("Set status(%s) for %s" % (self._status, self.session_id)) self.set_done() if ex: ...
python
def _set_status(self, status, ex=None): ''' set session status - eg failed, success -- valid values contained in enumAsperaControllerStatus class ''' self._status = status logger.debug("Set status(%s) for %s" % (self._status, self.session_id)) self.set_done() if ex: ...
[ "def", "_set_status", "(", "self", ",", "status", ",", "ex", "=", "None", ")", ":", "self", ".", "_status", "=", "status", "logger", ".", "debug", "(", "\"Set status(%s) for %s\"", "%", "(", "self", ".", "_status", ",", "self", ".", "session_id", ")", ...
set session status - eg failed, success -- valid values contained in enumAsperaControllerStatus class
[ "set", "session", "status", "-", "eg", "failed", "success", "--", "valid", "values", "contained", "in", "enumAsperaControllerStatus", "class" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/futures.py#L352-L359
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/futures.py
AsperaSession.set_bytes_transferred
def set_bytes_transferred(self, bytes_transferred): ''' set the number of bytes transferred - if it has changed return True ''' _changed = False if bytes_transferred: _changed = (self._bytes_transferred != int(bytes_transferred)) if _changed: self._bytes_t...
python
def set_bytes_transferred(self, bytes_transferred): ''' set the number of bytes transferred - if it has changed return True ''' _changed = False if bytes_transferred: _changed = (self._bytes_transferred != int(bytes_transferred)) if _changed: self._bytes_t...
[ "def", "set_bytes_transferred", "(", "self", ",", "bytes_transferred", ")", ":", "_changed", "=", "False", "if", "bytes_transferred", ":", "_changed", "=", "(", "self", ".", "_bytes_transferred", "!=", "int", "(", "bytes_transferred", ")", ")", "if", "_changed",...
set the number of bytes transferred - if it has changed return True
[ "set", "the", "number", "of", "bytes", "transferred", "-", "if", "it", "has", "changed", "return", "True" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/futures.py#L361-L372
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/futures.py
AsperaSession.set_exception
def set_exception(self, exception): ''' set the exception message and set the status to failed ''' logger.error("%s : %s" % (exception.__class__.__name__, str(exception))) self._set_status(enumAsperaControllerStatus.FAILED, exception)
python
def set_exception(self, exception): ''' set the exception message and set the status to failed ''' logger.error("%s : %s" % (exception.__class__.__name__, str(exception))) self._set_status(enumAsperaControllerStatus.FAILED, exception)
[ "def", "set_exception", "(", "self", ",", "exception", ")", ":", "logger", ".", "error", "(", "\"%s : %s\"", "%", "(", "exception", ".", "__class__", ".", "__name__", ",", "str", "(", "exception", ")", ")", ")", "self", ".", "_set_status", "(", "enumAspe...
set the exception message and set the status to failed
[ "set", "the", "exception", "message", "and", "set", "the", "status", "to", "failed" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/futures.py#L383-L386
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/futures.py
AsperaSession.wait
def wait(self): ''' wait for the done event to be set - no timeout''' self._done_event.wait(MAXINT) return self._status, self._exception
python
def wait(self): ''' wait for the done event to be set - no timeout''' self._done_event.wait(MAXINT) return self._status, self._exception
[ "def", "wait", "(", "self", ")", ":", "self", ".", "_done_event", ".", "wait", "(", "MAXINT", ")", "return", "self", ".", "_status", ",", "self", ".", "_exception" ]
wait for the done event to be set - no timeout
[ "wait", "for", "the", "done", "event", "to", "be", "set", "-", "no", "timeout" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/futures.py#L416-L419
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/futures.py
AsperaTransferCoordinator.cancel
def cancel(self, msg='', exc_type=CancelledError): """Cancels the TransferFuture :param msg: The message to attach to the cancellation :param exc_type: The type of exception to set for the cancellation """ _ret = False if not self.is_done(): self.notify_...
python
def cancel(self, msg='', exc_type=CancelledError): """Cancels the TransferFuture :param msg: The message to attach to the cancellation :param exc_type: The type of exception to set for the cancellation """ _ret = False if not self.is_done(): self.notify_...
[ "def", "cancel", "(", "self", ",", "msg", "=", "''", ",", "exc_type", "=", "CancelledError", ")", ":", "_ret", "=", "False", "if", "not", "self", ".", "is_done", "(", ")", ":", "self", ".", "notify_cancelled", "(", "msg", ",", "True", ")", "_ret", ...
Cancels the TransferFuture :param msg: The message to attach to the cancellation :param exc_type: The type of exception to set for the cancellation
[ "Cancels", "the", "TransferFuture", ":", "param", "msg", ":", "The", "message", "to", "attach", "to", "the", "cancellation", ":", "param", "exc_type", ":", "The", "type", "of", "exception", "to", "set", "for", "the", "cancellation" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/futures.py#L438-L448
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/futures.py
AsperaTransferCoordinator._update_session_count
def _update_session_count(self, type=0, actutal_session_count=0): ''' update the session/ascp count 0 : set the number of sessions being used to 1 or number specified in transfer config -1: decrement the session count by one 1: set the session count to param value ''...
python
def _update_session_count(self, type=0, actutal_session_count=0): ''' update the session/ascp count 0 : set the number of sessions being used to 1 or number specified in transfer config -1: decrement the session count by one 1: set the session count to param value ''...
[ "def", "_update_session_count", "(", "self", ",", "type", "=", "0", ",", "actutal_session_count", "=", "0", ")", ":", "if", "type", "==", "0", ":", "# init", "_count", "=", "0", "if", "self", ".", "_args", ".", "transfer_config", ":", "_count", "=", "s...
update the session/ascp count 0 : set the number of sessions being used to 1 or number specified in transfer config -1: decrement the session count by one 1: set the session count to param value
[ "update", "the", "session", "/", "ascp", "count", "0", ":", "set", "the", "number", "of", "sessions", "being", "used", "to", "1", "or", "number", "specified", "in", "transfer", "config", "-", "1", ":", "decrement", "the", "session", "count", "by", "one",...
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/futures.py#L455-L469
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/futures.py
AsperaTransferCoordinator.result
def result(self, raise_exception=True): """Waits until TransferFuture is done and returns the result If the TransferFuture succeeded, it will return the result. If the TransferFuture failed, it will raise the exception associated to the failure. """ _status = None ...
python
def result(self, raise_exception=True): """Waits until TransferFuture is done and returns the result If the TransferFuture succeeded, it will return the result. If the TransferFuture failed, it will raise the exception associated to the failure. """ _status = None ...
[ "def", "result", "(", "self", ",", "raise_exception", "=", "True", ")", ":", "_status", "=", "None", "_exception", "=", "None", "self", ".", "_done_event", ".", "wait", "(", "MAXINT", ")", "# first wait for session global", "if", "self", ".", "is_failed", "(...
Waits until TransferFuture is done and returns the result If the TransferFuture succeeded, it will return the result. If the TransferFuture failed, it will raise the exception associated to the failure.
[ "Waits", "until", "TransferFuture", "is", "done", "and", "returns", "the", "result" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/futures.py#L471-L495
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/futures.py
AsperaTransferCoordinator.notify_init
def notify_init(self): ''' run the queed callback for just the first session only ''' _session_count = len(self._sessions) self._update_session_count(1, _session_count) if _session_count == 1: self._run_queued_callbacks()
python
def notify_init(self): ''' run the queed callback for just the first session only ''' _session_count = len(self._sessions) self._update_session_count(1, _session_count) if _session_count == 1: self._run_queued_callbacks()
[ "def", "notify_init", "(", "self", ")", ":", "_session_count", "=", "len", "(", "self", ".", "_sessions", ")", "self", ".", "_update_session_count", "(", "1", ",", "_session_count", ")", "if", "_session_count", "==", "1", ":", "self", ".", "_run_queued_callb...
run the queed callback for just the first session only
[ "run", "the", "queed", "callback", "for", "just", "the", "first", "session", "only" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/futures.py#L501-L506
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/futures.py
AsperaTransferCoordinator.notify_done
def notify_done(self, error=False, run_done_callbacks=True): ''' if error clear all sessions otherwise check to see if all other sessions are complete then run the done callbacks ''' if error: for _session in self._sessions.values(): _session.set_done() ...
python
def notify_done(self, error=False, run_done_callbacks=True): ''' if error clear all sessions otherwise check to see if all other sessions are complete then run the done callbacks ''' if error: for _session in self._sessions.values(): _session.set_done() ...
[ "def", "notify_done", "(", "self", ",", "error", "=", "False", ",", "run_done_callbacks", "=", "True", ")", ":", "if", "error", ":", "for", "_session", "in", "self", ".", "_sessions", ".", "values", "(", ")", ":", "_session", ".", "set_done", "(", ")",...
if error clear all sessions otherwise check to see if all other sessions are complete then run the done callbacks
[ "if", "error", "clear", "all", "sessions", "otherwise", "check", "to", "see", "if", "all", "other", "sessions", "are", "complete", "then", "run", "the", "done", "callbacks" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/futures.py#L508-L524
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/futures.py
AsperaTransferCoordinator.notify_progress
def notify_progress(self): ''' only call the progress callback if total has changed or PROGRESS_MSGS_SEND_ALL is set ''' _total = 0 for _session in self._sessions.values(): _total += _session.bytes_transferred if AsperaSession.PROGRESS_MSGS_SEND_ALL: ...
python
def notify_progress(self): ''' only call the progress callback if total has changed or PROGRESS_MSGS_SEND_ALL is set ''' _total = 0 for _session in self._sessions.values(): _total += _session.bytes_transferred if AsperaSession.PROGRESS_MSGS_SEND_ALL: ...
[ "def", "notify_progress", "(", "self", ")", ":", "_total", "=", "0", "for", "_session", "in", "self", ".", "_sessions", ".", "values", "(", ")", ":", "_total", "+=", "_session", ".", "bytes_transferred", "if", "AsperaSession", ".", "PROGRESS_MSGS_SEND_ALL", ...
only call the progress callback if total has changed or PROGRESS_MSGS_SEND_ALL is set
[ "only", "call", "the", "progress", "callback", "if", "total", "has", "changed", "or", "PROGRESS_MSGS_SEND_ALL", "is", "set" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/futures.py#L526-L539
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/futures.py
AsperaTransferCoordinator.notify_exception
def notify_exception(self, exception, run_done_callbacks=True): ''' set the exception message, stop transfer if running and set the done event ''' logger.error("%s : %s" % (exception.__class__.__name__, str(exception))) self._exception = exception if self.is_running(True): # ...
python
def notify_exception(self, exception, run_done_callbacks=True): ''' set the exception message, stop transfer if running and set the done event ''' logger.error("%s : %s" % (exception.__class__.__name__, str(exception))) self._exception = exception if self.is_running(True): # ...
[ "def", "notify_exception", "(", "self", ",", "exception", ",", "run_done_callbacks", "=", "True", ")", ":", "logger", ".", "error", "(", "\"%s : %s\"", "%", "(", "exception", ".", "__class__", ".", "__name__", ",", "str", "(", "exception", ")", ")", ")", ...
set the exception message, stop transfer if running and set the done event
[ "set", "the", "exception", "message", "stop", "transfer", "if", "running", "and", "set", "the", "done", "event" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/futures.py#L541-L553
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/futures.py
AsperaTransferCoordinator.is_success
def is_success(self): ''' check all sessions to see if they have completed successfully ''' for _session in self._sessions.values(): if not _session.is_success(): return False return True
python
def is_success(self): ''' check all sessions to see if they have completed successfully ''' for _session in self._sessions.values(): if not _session.is_success(): return False return True
[ "def", "is_success", "(", "self", ")", ":", "for", "_session", "in", "self", ".", "_sessions", ".", "values", "(", ")", ":", "if", "not", "_session", ".", "is_success", "(", ")", ":", "return", "False", "return", "True" ]
check all sessions to see if they have completed successfully
[ "check", "all", "sessions", "to", "see", "if", "they", "have", "completed", "successfully" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/futures.py#L555-L560
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/futures.py
AsperaTransferCoordinator.set_transfer_spec
def set_transfer_spec(self): ''' run the function to set the transfer spec on error set associated exception ''' _ret = False try: self._args.transfer_spec_func(self._args) _ret = True except Exception as ex: self.notify_exception(AsperaTransferSpecErr...
python
def set_transfer_spec(self): ''' run the function to set the transfer spec on error set associated exception ''' _ret = False try: self._args.transfer_spec_func(self._args) _ret = True except Exception as ex: self.notify_exception(AsperaTransferSpecErr...
[ "def", "set_transfer_spec", "(", "self", ")", ":", "_ret", "=", "False", "try", ":", "self", ".", "_args", ".", "transfer_spec_func", "(", "self", ".", "_args", ")", "_ret", "=", "True", "except", "Exception", "as", "ex", ":", "self", ".", "notify_except...
run the function to set the transfer spec on error set associated exception
[ "run", "the", "function", "to", "set", "the", "transfer", "spec", "on", "error", "set", "associated", "exception" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/futures.py#L584-L592
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/futures.py
AsperaTransferCoordinator._add_subscribers_for_type
def _add_subscribers_for_type(self, callback_type, subscribers, callbacks, **kwargs): ''' add a done/queued/progress callback to the appropriate list ''' for subscriber in subscribers: callback_name = 'on_' + callback_type if hasattr(subscriber, callback_name): _f...
python
def _add_subscribers_for_type(self, callback_type, subscribers, callbacks, **kwargs): ''' add a done/queued/progress callback to the appropriate list ''' for subscriber in subscribers: callback_name = 'on_' + callback_type if hasattr(subscriber, callback_name): _f...
[ "def", "_add_subscribers_for_type", "(", "self", ",", "callback_type", ",", "subscribers", ",", "callbacks", ",", "*", "*", "kwargs", ")", ":", "for", "subscriber", "in", "subscribers", ":", "callback_name", "=", "'on_'", "+", "callback_type", "if", "hasattr", ...
add a done/queued/progress callback to the appropriate list
[ "add", "a", "done", "/", "queued", "/", "progress", "callback", "to", "the", "appropriate", "list" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/futures.py#L609-L615
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/futures.py
AsperaTransferCoordinator.add_done_callback
def add_done_callback(self, function, **kwargs): """Add a done callback to be invoked when transfer is complete """ with self._callbacks_lock: _function = functools.partial(function, **kwargs) self._done_callbacks.append(_function)
python
def add_done_callback(self, function, **kwargs): """Add a done callback to be invoked when transfer is complete """ with self._callbacks_lock: _function = functools.partial(function, **kwargs) self._done_callbacks.append(_function)
[ "def", "add_done_callback", "(", "self", ",", "function", ",", "*", "*", "kwargs", ")", ":", "with", "self", ".", "_callbacks_lock", ":", "_function", "=", "functools", ".", "partial", "(", "function", ",", "*", "*", "kwargs", ")", "self", ".", "_done_ca...
Add a done callback to be invoked when transfer is complete
[ "Add", "a", "done", "callback", "to", "be", "invoked", "when", "transfer", "is", "complete" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/futures.py#L617-L621
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/futures.py
AsperaTransferCoordinator.add_subscribers
def add_subscribers(self, subscribers, **kwargs): """ Add a callbacks to be invoked during transfer """ if subscribers: with self._callbacks_lock: self._add_subscribers_for_type( 'done', subscribers, self._done_callbacks, **kwargs) self._ad...
python
def add_subscribers(self, subscribers, **kwargs): """ Add a callbacks to be invoked during transfer """ if subscribers: with self._callbacks_lock: self._add_subscribers_for_type( 'done', subscribers, self._done_callbacks, **kwargs) self._ad...
[ "def", "add_subscribers", "(", "self", ",", "subscribers", ",", "*", "*", "kwargs", ")", ":", "if", "subscribers", ":", "with", "self", ".", "_callbacks_lock", ":", "self", ".", "_add_subscribers_for_type", "(", "'done'", ",", "subscribers", ",", "self", "."...
Add a callbacks to be invoked during transfer
[ "Add", "a", "callbacks", "to", "be", "invoked", "during", "transfer" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/futures.py#L623-L632
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/futures.py
AsperaTransferCoordinator._run_queued_callbacks
def _run_queued_callbacks(self): ''' run the init/quued calback when the trasnfer is initiated on apsera ''' for callback in self._queued_callbacks: try: callback() except Exception as ex: logger.error("Exception: %s" % str(ex))
python
def _run_queued_callbacks(self): ''' run the init/quued calback when the trasnfer is initiated on apsera ''' for callback in self._queued_callbacks: try: callback() except Exception as ex: logger.error("Exception: %s" % str(ex))
[ "def", "_run_queued_callbacks", "(", "self", ")", ":", "for", "callback", "in", "self", ".", "_queued_callbacks", ":", "try", ":", "callback", "(", ")", "except", "Exception", "as", "ex", ":", "logger", ".", "error", "(", "\"Exception: %s\"", "%", "str", "...
run the init/quued calback when the trasnfer is initiated on apsera
[ "run", "the", "init", "/", "quued", "calback", "when", "the", "trasnfer", "is", "initiated", "on", "apsera" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/futures.py#L634-L640
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/futures.py
AsperaTransferCoordinator._run_progress_callbacks
def _run_progress_callbacks(self, bytes_transferred): ''' pass the number of bytes process to progress callbacks ''' if bytes_transferred: for callback in self._progress_callbacks: try: callback(bytes_transferred=bytes_transferred) except E...
python
def _run_progress_callbacks(self, bytes_transferred): ''' pass the number of bytes process to progress callbacks ''' if bytes_transferred: for callback in self._progress_callbacks: try: callback(bytes_transferred=bytes_transferred) except E...
[ "def", "_run_progress_callbacks", "(", "self", ",", "bytes_transferred", ")", ":", "if", "bytes_transferred", ":", "for", "callback", "in", "self", ".", "_progress_callbacks", ":", "try", ":", "callback", "(", "bytes_transferred", "=", "bytes_transferred", ")", "e...
pass the number of bytes process to progress callbacks
[ "pass", "the", "number", "of", "bytes", "process", "to", "progress", "callbacks" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/futures.py#L642-L649
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/futures.py
AsperaTransferCoordinator._run_done_callbacks
def _run_done_callbacks(self): ''' Run the callbacks and remove the callbacks from the internal List so they do not get run again if done is notified more than once. ''' with self._callbacks_lock: for callback in self._done_callbacks: try: ...
python
def _run_done_callbacks(self): ''' Run the callbacks and remove the callbacks from the internal List so they do not get run again if done is notified more than once. ''' with self._callbacks_lock: for callback in self._done_callbacks: try: ...
[ "def", "_run_done_callbacks", "(", "self", ")", ":", "with", "self", ".", "_callbacks_lock", ":", "for", "callback", "in", "self", ".", "_done_callbacks", ":", "try", ":", "callback", "(", ")", "# We do not want a callback interrupting the process, especially", "# in ...
Run the callbacks and remove the callbacks from the internal List so they do not get run again if done is notified more than once.
[ "Run", "the", "callbacks", "and", "remove", "the", "callbacks", "from", "the", "internal", "List", "so", "they", "do", "not", "get", "run", "again", "if", "done", "is", "notified", "more", "than", "once", "." ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/futures.py#L651-L665
yfpeng/bioc
bioc/bioc.py
BioCAnnotation.total_span
def total_span(self) -> BioCLocation: """The total span of this annotation. Discontinued locations will be merged.""" if not self.locations: raise ValueError('BioCAnnotation must have at least one location') start = min(l.offset for l in self.locations) end = max(l.end for l ...
python
def total_span(self) -> BioCLocation: """The total span of this annotation. Discontinued locations will be merged.""" if not self.locations: raise ValueError('BioCAnnotation must have at least one location') start = min(l.offset for l in self.locations) end = max(l.end for l ...
[ "def", "total_span", "(", "self", ")", "->", "BioCLocation", ":", "if", "not", "self", ".", "locations", ":", "raise", "ValueError", "(", "'BioCAnnotation must have at least one location'", ")", "start", "=", "min", "(", "l", ".", "offset", "for", "l", "in", ...
The total span of this annotation. Discontinued locations will be merged.
[ "The", "total", "span", "of", "this", "annotation", ".", "Discontinued", "locations", "will", "be", "merged", "." ]
train
https://github.com/yfpeng/bioc/blob/47ddaa010960d9ba673aefe068e7bbaf39f0fff4/bioc/bioc.py#L128-L134
yfpeng/bioc
bioc/bioc.py
BioCRelation.get_node
def get_node(self, role: str, default=None) -> BioCNode: """ Get the first node with role Args: role: role default: node returned instead of raising StopIteration Returns: the first node with role """ return next((node for node in sel...
python
def get_node(self, role: str, default=None) -> BioCNode: """ Get the first node with role Args: role: role default: node returned instead of raising StopIteration Returns: the first node with role """ return next((node for node in sel...
[ "def", "get_node", "(", "self", ",", "role", ":", "str", ",", "default", "=", "None", ")", "->", "BioCNode", ":", "return", "next", "(", "(", "node", "for", "node", "in", "self", ".", "nodes", "if", "node", ".", "role", "==", "role", ")", ",", "d...
Get the first node with role Args: role: role default: node returned instead of raising StopIteration Returns: the first node with role
[ "Get", "the", "first", "node", "with", "role" ]
train
https://github.com/yfpeng/bioc/blob/47ddaa010960d9ba673aefe068e7bbaf39f0fff4/bioc/bioc.py#L174-L185
yfpeng/bioc
bioc/bioc.py
BioCPassage.get_sentence
def get_sentence(self, offset: int) -> BioCSentence or None: """ Gets sentence with specified offset Args: offset: sentence offset Return: the sentence with specified offset """ for sentence in self.sentences: if sentence.offset == of...
python
def get_sentence(self, offset: int) -> BioCSentence or None: """ Gets sentence with specified offset Args: offset: sentence offset Return: the sentence with specified offset """ for sentence in self.sentences: if sentence.offset == of...
[ "def", "get_sentence", "(", "self", ",", "offset", ":", "int", ")", "->", "BioCSentence", "or", "None", ":", "for", "sentence", "in", "self", ".", "sentences", ":", "if", "sentence", ".", "offset", "==", "offset", ":", "return", "sentence", "return", "No...
Gets sentence with specified offset Args: offset: sentence offset Return: the sentence with specified offset
[ "Gets", "sentence", "with", "specified", "offset" ]
train
https://github.com/yfpeng/bioc/blob/47ddaa010960d9ba673aefe068e7bbaf39f0fff4/bioc/bioc.py#L294-L307
yfpeng/bioc
bioc/bioc.py
BioCDocument.get_passage
def get_passage(self, offset: int) -> BioCPassage or None: """ Gets passage Args: offset: passage offset Return: the passage with specified offset """ for passage in self.passages: if passage.offset == offset: return p...
python
def get_passage(self, offset: int) -> BioCPassage or None: """ Gets passage Args: offset: passage offset Return: the passage with specified offset """ for passage in self.passages: if passage.offset == offset: return p...
[ "def", "get_passage", "(", "self", ",", "offset", ":", "int", ")", "->", "BioCPassage", "or", "None", ":", "for", "passage", "in", "self", ".", "passages", ":", "if", "passage", ".", "offset", "==", "offset", ":", "return", "passage", "return", "None" ]
Gets passage Args: offset: passage offset Return: the passage with specified offset
[ "Gets", "passage" ]
train
https://github.com/yfpeng/bioc/blob/47ddaa010960d9ba673aefe068e7bbaf39f0fff4/bioc/bioc.py#L345-L358
yfpeng/bioc
bioc/bioc.py
BioCDocument.of
def of(cls, *passages: BioCPassage): """ Returns a collection passages """ if len(passages) <= 0: raise ValueError("There has to be at least one passage.") c = BioCDocument() for passage in passages: if passage is None: raise ValueE...
python
def of(cls, *passages: BioCPassage): """ Returns a collection passages """ if len(passages) <= 0: raise ValueError("There has to be at least one passage.") c = BioCDocument() for passage in passages: if passage is None: raise ValueE...
[ "def", "of", "(", "cls", ",", "*", "passages", ":", "BioCPassage", ")", ":", "if", "len", "(", "passages", ")", "<=", "0", ":", "raise", "ValueError", "(", "\"There has to be at least one passage.\"", ")", "c", "=", "BioCDocument", "(", ")", "for", "passag...
Returns a collection passages
[ "Returns", "a", "collection", "passages" ]
train
https://github.com/yfpeng/bioc/blob/47ddaa010960d9ba673aefe068e7bbaf39f0fff4/bioc/bioc.py#L361-L372
yfpeng/bioc
bioc/bioc.py
BioCCollection.of
def of(cls, *documents: BioCDocument): """ Returns a collection documents """ if len(documents) <= 0: raise ValueError("There has to be at least one document.") c = BioCCollection() for document in documents: if document is None: ra...
python
def of(cls, *documents: BioCDocument): """ Returns a collection documents """ if len(documents) <= 0: raise ValueError("There has to be at least one document.") c = BioCCollection() for document in documents: if document is None: ra...
[ "def", "of", "(", "cls", ",", "*", "documents", ":", "BioCDocument", ")", ":", "if", "len", "(", "documents", ")", "<=", "0", ":", "raise", "ValueError", "(", "\"There has to be at least one document.\"", ")", "c", "=", "BioCCollection", "(", ")", "for", "...
Returns a collection documents
[ "Returns", "a", "collection", "documents" ]
train
https://github.com/yfpeng/bioc/blob/47ddaa010960d9ba673aefe068e7bbaf39f0fff4/bioc/bioc.py#L420-L431
SuperCowPowers/workbench
workbench/clients/pe_sim_graph.py
add_it
def add_it(workbench, file_list, labels): """Add the given file_list to workbench as samples, also add them as nodes. Args: workbench: Instance of Workbench Client. file_list: list of files. labels: labels for the nodes. Returns: A list of md5s. """ md5s = [] f...
python
def add_it(workbench, file_list, labels): """Add the given file_list to workbench as samples, also add them as nodes. Args: workbench: Instance of Workbench Client. file_list: list of files. labels: labels for the nodes. Returns: A list of md5s. """ md5s = [] f...
[ "def", "add_it", "(", "workbench", ",", "file_list", ",", "labels", ")", ":", "md5s", "=", "[", "]", "for", "filename", "in", "file_list", ":", "if", "filename", "!=", "'.DS_Store'", ":", "with", "open", "(", "filename", ",", "'rb'", ")", "as", "pe_fil...
Add the given file_list to workbench as samples, also add them as nodes. Args: workbench: Instance of Workbench Client. file_list: list of files. labels: labels for the nodes. Returns: A list of md5s.
[ "Add", "the", "given", "file_list", "to", "workbench", "as", "samples", "also", "add", "them", "as", "nodes", "." ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/clients/pe_sim_graph.py#L7-L27
SuperCowPowers/workbench
workbench/clients/pe_sim_graph.py
jaccard_sims
def jaccard_sims(feature_list): """Compute Jaccard similarities between all the observations in the feature list. Args: feature_list: a list of dictionaries, each having structure as { 'md5' : String, 'features': list of Strings } Returns: list of dictionaries with st...
python
def jaccard_sims(feature_list): """Compute Jaccard similarities between all the observations in the feature list. Args: feature_list: a list of dictionaries, each having structure as { 'md5' : String, 'features': list of Strings } Returns: list of dictionaries with st...
[ "def", "jaccard_sims", "(", "feature_list", ")", ":", "sim_info_list", "=", "[", "]", "for", "feature_info", "in", "feature_list", ":", "md5_source", "=", "feature_info", "[", "'md5'", "]", "features_source", "=", "feature_info", "[", "'features'", "]", "for", ...
Compute Jaccard similarities between all the observations in the feature list. Args: feature_list: a list of dictionaries, each having structure as { 'md5' : String, 'features': list of Strings } Returns: list of dictionaries with structure as {'source': md5 Stri...
[ "Compute", "Jaccard", "similarities", "between", "all", "the", "observations", "in", "the", "feature", "list", "." ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/clients/pe_sim_graph.py#L30-L55
SuperCowPowers/workbench
workbench/clients/pe_sim_graph.py
jaccard_sim
def jaccard_sim(features1, features2): """Compute similarity between two sets using Jaccard similarity. Args: features1: list of PE Symbols. features2: list of PE Symbols. Returns: Returns an int. """ set1 = set(features1) set2 = set(features2) try: return ...
python
def jaccard_sim(features1, features2): """Compute similarity between two sets using Jaccard similarity. Args: features1: list of PE Symbols. features2: list of PE Symbols. Returns: Returns an int. """ set1 = set(features1) set2 = set(features2) try: return ...
[ "def", "jaccard_sim", "(", "features1", ",", "features2", ")", ":", "set1", "=", "set", "(", "features1", ")", "set2", "=", "set", "(", "features2", ")", "try", ":", "return", "len", "(", "set1", ".", "intersection", "(", "set2", ")", ")", "/", "floa...
Compute similarity between two sets using Jaccard similarity. Args: features1: list of PE Symbols. features2: list of PE Symbols. Returns: Returns an int.
[ "Compute", "similarity", "between", "two", "sets", "using", "Jaccard", "similarity", "." ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/clients/pe_sim_graph.py#L58-L73
SuperCowPowers/workbench
workbench/clients/pe_sim_graph.py
run
def run(): """This client generates a similarity graph from features in PE Files.""" # Grab server args args = client_helper.grab_server_args() # Start up workbench connection workbench = zerorpc.Client(timeout=300, heartbeat=60) workbench.connect('tcp://'+args['server']+':'+args['port']) ...
python
def run(): """This client generates a similarity graph from features in PE Files.""" # Grab server args args = client_helper.grab_server_args() # Start up workbench connection workbench = zerorpc.Client(timeout=300, heartbeat=60) workbench.connect('tcp://'+args['server']+':'+args['port']) ...
[ "def", "run", "(", ")", ":", "# Grab server args", "args", "=", "client_helper", ".", "grab_server_args", "(", ")", "# Start up workbench connection", "workbench", "=", "zerorpc", ".", "Client", "(", "timeout", "=", "300", ",", "heartbeat", "=", "60", ")", "wo...
This client generates a similarity graph from features in PE Files.
[ "This", "client", "generates", "a", "similarity", "graph", "from", "features", "in", "PE", "Files", "." ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/clients/pe_sim_graph.py#L76-L153
yfpeng/bioc
bioc/utils.py
pad_char
def pad_char(text: str, width: int, char: str = '\n') -> str: """Pads a text until length width.""" dis = width - len(text) if dis < 0: raise ValueError if dis > 0: text += char * dis return text
python
def pad_char(text: str, width: int, char: str = '\n') -> str: """Pads a text until length width.""" dis = width - len(text) if dis < 0: raise ValueError if dis > 0: text += char * dis return text
[ "def", "pad_char", "(", "text", ":", "str", ",", "width", ":", "int", ",", "char", ":", "str", "=", "'\\n'", ")", "->", "str", ":", "dis", "=", "width", "-", "len", "(", "text", ")", "if", "dis", "<", "0", ":", "raise", "ValueError", "if", "dis...
Pads a text until length width.
[ "Pads", "a", "text", "until", "length", "width", "." ]
train
https://github.com/yfpeng/bioc/blob/47ddaa010960d9ba673aefe068e7bbaf39f0fff4/bioc/utils.py#L11-L18
yfpeng/bioc
bioc/utils.py
get_text
def get_text(obj) -> Tuple[int, str]: """ Return text with its offset in the document Args: obj: BioCDocument, BioCPassage, or BioCSentence Returns: offset, text """ from bioc.bioc import BioCDocument, BioCPassage, BioCSentence if isinstance(obj, BioCSentence):...
python
def get_text(obj) -> Tuple[int, str]: """ Return text with its offset in the document Args: obj: BioCDocument, BioCPassage, or BioCSentence Returns: offset, text """ from bioc.bioc import BioCDocument, BioCPassage, BioCSentence if isinstance(obj, BioCSentence):...
[ "def", "get_text", "(", "obj", ")", "->", "Tuple", "[", "int", ",", "str", "]", ":", "from", "bioc", ".", "bioc", "import", "BioCDocument", ",", "BioCPassage", ",", "BioCSentence", "if", "isinstance", "(", "obj", ",", "BioCSentence", ")", ":", "return", ...
Return text with its offset in the document Args: obj: BioCDocument, BioCPassage, or BioCSentence Returns: offset, text
[ "Return", "text", "with", "its", "offset", "in", "the", "document", "Args", ":", "obj", ":", "BioCDocument", "BioCPassage", "or", "BioCSentence", "Returns", ":", "offset", "text" ]
train
https://github.com/yfpeng/bioc/blob/47ddaa010960d9ba673aefe068e7bbaf39f0fff4/bioc/utils.py#L21-L57
yfpeng/bioc
bioc/utils.py
pretty_print
def pretty_print(source, dest): """ Pretty print the XML file """ parser = etree.XMLParser(remove_blank_text=True) if not isinstance(source, str): source = str(source) tree = etree.parse(source, parser) docinfo = tree.docinfo with open(dest, 'wb') as fp: fp.writ...
python
def pretty_print(source, dest): """ Pretty print the XML file """ parser = etree.XMLParser(remove_blank_text=True) if not isinstance(source, str): source = str(source) tree = etree.parse(source, parser) docinfo = tree.docinfo with open(dest, 'wb') as fp: fp.writ...
[ "def", "pretty_print", "(", "source", ",", "dest", ")", ":", "parser", "=", "etree", ".", "XMLParser", "(", "remove_blank_text", "=", "True", ")", "if", "not", "isinstance", "(", "source", ",", "str", ")", ":", "source", "=", "str", "(", "source", ")",...
Pretty print the XML file
[ "Pretty", "print", "the", "XML", "file" ]
train
https://github.com/yfpeng/bioc/blob/47ddaa010960d9ba673aefe068e7bbaf39f0fff4/bioc/utils.py#L60-L71
yfpeng/bioc
bioc/utils.py
shorten_text
def shorten_text(text: str): """Return a short repr of text if it is longer than 40""" if len(text) <= 40: text = text else: text = text[:17] + ' ... ' + text[-17:] return repr(text)
python
def shorten_text(text: str): """Return a short repr of text if it is longer than 40""" if len(text) <= 40: text = text else: text = text[:17] + ' ... ' + text[-17:] return repr(text)
[ "def", "shorten_text", "(", "text", ":", "str", ")", ":", "if", "len", "(", "text", ")", "<=", "40", ":", "text", "=", "text", "else", ":", "text", "=", "text", "[", ":", "17", "]", "+", "' ... '", "+", "text", "[", "-", "17", ":", "]", "retu...
Return a short repr of text if it is longer than 40
[ "Return", "a", "short", "repr", "of", "text", "if", "it", "is", "longer", "than", "40" ]
train
https://github.com/yfpeng/bioc/blob/47ddaa010960d9ba673aefe068e7bbaf39f0fff4/bioc/utils.py#L74-L80
SuperCowPowers/workbench
workbench/workers/meta.py
MetaData.execute
def execute(self, input_data): ''' This worker computes meta data for any file type. ''' raw_bytes = input_data['sample']['raw_bytes'] self.meta['md5'] = hashlib.md5(raw_bytes).hexdigest() self.meta['tags'] = input_data['tags']['tags'] self.meta['type_tag'] = input_data['sample']...
python
def execute(self, input_data): ''' This worker computes meta data for any file type. ''' raw_bytes = input_data['sample']['raw_bytes'] self.meta['md5'] = hashlib.md5(raw_bytes).hexdigest() self.meta['tags'] = input_data['tags']['tags'] self.meta['type_tag'] = input_data['sample']...
[ "def", "execute", "(", "self", ",", "input_data", ")", ":", "raw_bytes", "=", "input_data", "[", "'sample'", "]", "[", "'raw_bytes'", "]", "self", ".", "meta", "[", "'md5'", "]", "=", "hashlib", ".", "md5", "(", "raw_bytes", ")", ".", "hexdigest", "(",...
This worker computes meta data for any file type.
[ "This", "worker", "computes", "meta", "data", "for", "any", "file", "type", "." ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/workers/meta.py#L15-L36
SuperCowPowers/workbench
workbench/workers/strings.py
Strings.execute
def execute(self, input_data): ''' Execute the Strings worker ''' raw_bytes = input_data['sample']['raw_bytes'] strings = self.find_strings.findall(raw_bytes) return {'string_list': strings}
python
def execute(self, input_data): ''' Execute the Strings worker ''' raw_bytes = input_data['sample']['raw_bytes'] strings = self.find_strings.findall(raw_bytes) return {'string_list': strings}
[ "def", "execute", "(", "self", ",", "input_data", ")", ":", "raw_bytes", "=", "input_data", "[", "'sample'", "]", "[", "'raw_bytes'", "]", "strings", "=", "self", ".", "find_strings", ".", "findall", "(", "raw_bytes", ")", "return", "{", "'string_list'", "...
Execute the Strings worker
[ "Execute", "the", "Strings", "worker" ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/workers/strings.py#L14-L18
SuperCowPowers/workbench
workbench/workers/pe_indicators.py
PEIndicators.execute
def execute(self, input_data): ''' Execute the PEIndicators worker ''' raw_bytes = input_data['sample']['raw_bytes'] # Analyze the output of pefile for any anomalous conditions. # Have the PE File module process the file try: self.pefile_handle = pefile.PE(data=raw_b...
python
def execute(self, input_data): ''' Execute the PEIndicators worker ''' raw_bytes = input_data['sample']['raw_bytes'] # Analyze the output of pefile for any anomalous conditions. # Have the PE File module process the file try: self.pefile_handle = pefile.PE(data=raw_b...
[ "def", "execute", "(", "self", ",", "input_data", ")", ":", "raw_bytes", "=", "input_data", "[", "'sample'", "]", "[", "'raw_bytes'", "]", "# Analyze the output of pefile for any anomalous conditions.", "# Have the PE File module process the file", "try", ":", "self", "."...
Execute the PEIndicators worker
[ "Execute", "the", "PEIndicators", "worker" ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/workers/pe_indicators.py#L45-L67
SuperCowPowers/workbench
workbench/workers/pe_indicators.py
PEIndicators.check_checksum_mismatch
def check_checksum_mismatch(self): ''' Checking for a checksum that doesn't match the generated checksum ''' if self.pefile_handle.OPTIONAL_HEADER: if self.pefile_handle.OPTIONAL_HEADER.CheckSum != self.pefile_handle.generate_checksum(): return {'description': 'Reported Check...
python
def check_checksum_mismatch(self): ''' Checking for a checksum that doesn't match the generated checksum ''' if self.pefile_handle.OPTIONAL_HEADER: if self.pefile_handle.OPTIONAL_HEADER.CheckSum != self.pefile_handle.generate_checksum(): return {'description': 'Reported Check...
[ "def", "check_checksum_mismatch", "(", "self", ")", ":", "if", "self", ".", "pefile_handle", ".", "OPTIONAL_HEADER", ":", "if", "self", ".", "pefile_handle", ".", "OPTIONAL_HEADER", ".", "CheckSum", "!=", "self", ".", "pefile_handle", ".", "generate_checksum", "...
Checking for a checksum that doesn't match the generated checksum
[ "Checking", "for", "a", "checksum", "that", "doesn", "t", "match", "the", "generated", "checksum" ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/workers/pe_indicators.py#L94-L100
SuperCowPowers/workbench
workbench/workers/pe_indicators.py
PEIndicators.check_nonstandard_section_name
def check_nonstandard_section_name(self): ''' Checking for an non-standard section name ''' std_sections = ['.text', '.bss', '.rdata', '.data', '.rsrc', '.edata', '.idata', '.pdata', '.debug', '.reloc', '.stab', '.stabstr', '.tls', '.crt', '.gnu_deb', '.eh...
python
def check_nonstandard_section_name(self): ''' Checking for an non-standard section name ''' std_sections = ['.text', '.bss', '.rdata', '.data', '.rsrc', '.edata', '.idata', '.pdata', '.debug', '.reloc', '.stab', '.stabstr', '.tls', '.crt', '.gnu_deb', '.eh...
[ "def", "check_nonstandard_section_name", "(", "self", ")", ":", "std_sections", "=", "[", "'.text'", ",", "'.bss'", ",", "'.rdata'", ",", "'.data'", ",", "'.rsrc'", ",", "'.edata'", ",", "'.idata'", ",", "'.pdata'", ",", "'.debug'", ",", "'.reloc'", ",", "'....
Checking for an non-standard section name
[ "Checking", "for", "an", "non", "-", "standard", "section", "name" ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/workers/pe_indicators.py#L110-L126
SuperCowPowers/workbench
workbench/workers/pe_indicators.py
PEIndicators.check_image_size_incorrect
def check_image_size_incorrect(self): ''' Checking if the reported image size matches the actual image size ''' last_virtual_address = 0 last_virtual_size = 0 section_alignment = self.pefile_handle.OPTIONAL_HEADER.SectionAlignment total_image_size = self.pefile_handle.OPTIONAL_H...
python
def check_image_size_incorrect(self): ''' Checking if the reported image size matches the actual image size ''' last_virtual_address = 0 last_virtual_size = 0 section_alignment = self.pefile_handle.OPTIONAL_HEADER.SectionAlignment total_image_size = self.pefile_handle.OPTIONAL_H...
[ "def", "check_image_size_incorrect", "(", "self", ")", ":", "last_virtual_address", "=", "0", "last_virtual_size", "=", "0", "section_alignment", "=", "self", ".", "pefile_handle", ".", "OPTIONAL_HEADER", ".", "SectionAlignment", "total_image_size", "=", "self", ".", ...
Checking if the reported image size matches the actual image size
[ "Checking", "if", "the", "reported", "image", "size", "matches", "the", "actual", "image", "size" ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/workers/pe_indicators.py#L128-L147
SuperCowPowers/workbench
workbench/workers/pe_indicators.py
PEIndicators.check_section_unaligned
def check_section_unaligned(self): ''' Checking if any of the sections are unaligned ''' file_alignment = self.pefile_handle.OPTIONAL_HEADER.FileAlignment unaligned_sections = [] for section in self.pefile_handle.sections: if section.PointerToRawData % file_alignment: ...
python
def check_section_unaligned(self): ''' Checking if any of the sections are unaligned ''' file_alignment = self.pefile_handle.OPTIONAL_HEADER.FileAlignment unaligned_sections = [] for section in self.pefile_handle.sections: if section.PointerToRawData % file_alignment: ...
[ "def", "check_section_unaligned", "(", "self", ")", ":", "file_alignment", "=", "self", ".", "pefile_handle", ".", "OPTIONAL_HEADER", ".", "FileAlignment", "unaligned_sections", "=", "[", "]", "for", "section", "in", "self", ".", "pefile_handle", ".", "sections", ...
Checking if any of the sections are unaligned
[ "Checking", "if", "any", "of", "the", "sections", "are", "unaligned" ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/workers/pe_indicators.py#L158-L170
SuperCowPowers/workbench
workbench/workers/pe_indicators.py
PEIndicators.check_section_oversized
def check_section_oversized(self): ''' Checking if any of the sections go past the total size of the image ''' total_image_size = self.pefile_handle.OPTIONAL_HEADER.SizeOfImage for section in self.pefile_handle.sections: if section.PointerToRawData + section.SizeOfRawData > total_im...
python
def check_section_oversized(self): ''' Checking if any of the sections go past the total size of the image ''' total_image_size = self.pefile_handle.OPTIONAL_HEADER.SizeOfImage for section in self.pefile_handle.sections: if section.PointerToRawData + section.SizeOfRawData > total_im...
[ "def", "check_section_oversized", "(", "self", ")", ":", "total_image_size", "=", "self", ".", "pefile_handle", ".", "OPTIONAL_HEADER", ".", "SizeOfImage", "for", "section", "in", "self", ".", "pefile_handle", ".", "sections", ":", "if", "section", ".", "Pointer...
Checking if any of the sections go past the total size of the image
[ "Checking", "if", "any", "of", "the", "sections", "go", "past", "the", "total", "size", "of", "the", "image" ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/workers/pe_indicators.py#L172-L181
SuperCowPowers/workbench
workbench/workers/pe_indicators.py
PEIndicators._search_within_pe_warnings
def _search_within_pe_warnings(self, matches): ''' Just encapsulating a search that takes place fairly often ''' pattern = '|'.join(re.escape(match) for match in matches) exp = re.compile(pattern) if any(exp.search(warning) for warning in self.pefile_handle.get_warnings()): r...
python
def _search_within_pe_warnings(self, matches): ''' Just encapsulating a search that takes place fairly often ''' pattern = '|'.join(re.escape(match) for match in matches) exp = re.compile(pattern) if any(exp.search(warning) for warning in self.pefile_handle.get_warnings()): r...
[ "def", "_search_within_pe_warnings", "(", "self", ",", "matches", ")", ":", "pattern", "=", "'|'", ".", "join", "(", "re", ".", "escape", "(", "match", ")", "for", "match", "in", "matches", ")", "exp", "=", "re", ".", "compile", "(", "pattern", ")", ...
Just encapsulating a search that takes place fairly often
[ "Just", "encapsulating", "a", "search", "that", "takes", "place", "fairly", "often" ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/workers/pe_indicators.py#L349-L356
SuperCowPowers/workbench
workbench/workers/pe_indicators.py
PEIndicators._search_for_import_symbols
def _search_for_import_symbols(self, matches): ''' Just encapsulating a search that takes place fairly often ''' # Sanity check if not hasattr(self.pefile_handle, 'DIRECTORY_ENTRY_IMPORT'): return [] # Find symbols that match pattern = '|'.join(re.escape(match) for ...
python
def _search_for_import_symbols(self, matches): ''' Just encapsulating a search that takes place fairly often ''' # Sanity check if not hasattr(self.pefile_handle, 'DIRECTORY_ENTRY_IMPORT'): return [] # Find symbols that match pattern = '|'.join(re.escape(match) for ...
[ "def", "_search_for_import_symbols", "(", "self", ",", "matches", ")", ":", "# Sanity check", "if", "not", "hasattr", "(", "self", ".", "pefile_handle", ",", "'DIRECTORY_ENTRY_IMPORT'", ")", ":", "return", "[", "]", "# Find symbols that match", "pattern", "=", "'|...
Just encapsulating a search that takes place fairly often
[ "Just", "encapsulating", "a", "search", "that", "takes", "place", "fairly", "often" ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/workers/pe_indicators.py#L358-L377
SuperCowPowers/workbench
workbench/workers/pe_indicators.py
PEIndicators._search_for_export_symbols
def _search_for_export_symbols(self, matches): ''' Just encapsulating a search that takes place fairly often ''' pattern = '|'.join(re.escape(match) for match in matches) exp = re.compile(pattern) symbol_list = [] try: for symbol in self.pefile_handle.DIRECTORY_ENTRY_...
python
def _search_for_export_symbols(self, matches): ''' Just encapsulating a search that takes place fairly often ''' pattern = '|'.join(re.escape(match) for match in matches) exp = re.compile(pattern) symbol_list = [] try: for symbol in self.pefile_handle.DIRECTORY_ENTRY_...
[ "def", "_search_for_export_symbols", "(", "self", ",", "matches", ")", ":", "pattern", "=", "'|'", ".", "join", "(", "re", ".", "escape", "(", "match", ")", "for", "match", "in", "matches", ")", "exp", "=", "re", ".", "compile", "(", "pattern", ")", ...
Just encapsulating a search that takes place fairly often
[ "Just", "encapsulating", "a", "search", "that", "takes", "place", "fairly", "often" ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/workers/pe_indicators.py#L379-L394
yfpeng/bioc
bioc/biocitertools.py
annotations
def annotations(obj: BioCCollection or BioCDocument or BioCPassage or BioCSentence, docid: str = None, level: int = PASSAGE) -> Generator[BioCAnnotation, None, None]: """ Get all annotations in document id. Args: obj: BioCCollection, BioCDocument, BioCPassage, or BioCSentence ...
python
def annotations(obj: BioCCollection or BioCDocument or BioCPassage or BioCSentence, docid: str = None, level: int = PASSAGE) -> Generator[BioCAnnotation, None, None]: """ Get all annotations in document id. Args: obj: BioCCollection, BioCDocument, BioCPassage, or BioCSentence ...
[ "def", "annotations", "(", "obj", ":", "BioCCollection", "or", "BioCDocument", "or", "BioCPassage", "or", "BioCSentence", ",", "docid", ":", "str", "=", "None", ",", "level", ":", "int", "=", "PASSAGE", ")", "->", "Generator", "[", "BioCAnnotation", ",", "...
Get all annotations in document id. Args: obj: BioCCollection, BioCDocument, BioCPassage, or BioCSentence docid: document id. If None, all documents level: one of DOCUMENT, PASSAGE, SENTENCE Yields: one annotation
[ "Get", "all", "annotations", "in", "document", "id", ".", "Args", ":", "obj", ":", "BioCCollection", "BioCDocument", "BioCPassage", "or", "BioCSentence", "docid", ":", "document", "id", ".", "If", "None", "all", "documents", "level", ":", "one", "of", "DOCUM...
train
https://github.com/yfpeng/bioc/blob/47ddaa010960d9ba673aefe068e7bbaf39f0fff4/bioc/biocitertools.py#L12-L51
yfpeng/bioc
bioc/biocitertools.py
sentences
def sentences(obj: BioCCollection or BioCDocument or BioCPassage) \ -> Generator[BioCSentence, None, None]: """ Get all sentences in document id. Args: obj: BioCCollection, BioCDocument, or BioCPassage Yields: one sentence """ if isinstance(obj, BioCCollectio...
python
def sentences(obj: BioCCollection or BioCDocument or BioCPassage) \ -> Generator[BioCSentence, None, None]: """ Get all sentences in document id. Args: obj: BioCCollection, BioCDocument, or BioCPassage Yields: one sentence """ if isinstance(obj, BioCCollectio...
[ "def", "sentences", "(", "obj", ":", "BioCCollection", "or", "BioCDocument", "or", "BioCPassage", ")", "->", "Generator", "[", "BioCSentence", ",", "None", ",", "None", "]", ":", "if", "isinstance", "(", "obj", ",", "BioCCollection", ")", ":", "for", "docu...
Get all sentences in document id. Args: obj: BioCCollection, BioCDocument, or BioCPassage Yields: one sentence
[ "Get", "all", "sentences", "in", "document", "id", ".", "Args", ":", "obj", ":", "BioCCollection", "BioCDocument", "or", "BioCPassage", "Yields", ":", "one", "sentence" ]
train
https://github.com/yfpeng/bioc/blob/47ddaa010960d9ba673aefe068e7bbaf39f0fff4/bioc/biocitertools.py#L96-L117
SuperCowPowers/workbench
workbench/workers/pe_classifier.py
PEClassifier.execute
def execute(self, input_data): ''' This worker classifies PEFiles as Evil or AOK (TOY not a real classifier at this point)''' # In general you'd do something different with these two outputs # for this toy example will just smash them in a big string pefile_output = input_data['pe_feat...
python
def execute(self, input_data): ''' This worker classifies PEFiles as Evil or AOK (TOY not a real classifier at this point)''' # In general you'd do something different with these two outputs # for this toy example will just smash them in a big string pefile_output = input_data['pe_feat...
[ "def", "execute", "(", "self", ",", "input_data", ")", ":", "# In general you'd do something different with these two outputs", "# for this toy example will just smash them in a big string", "pefile_output", "=", "input_data", "[", "'pe_features'", "]", "indicators", "=", "input_...
This worker classifies PEFiles as Evil or AOK (TOY not a real classifier at this point)
[ "This", "worker", "classifies", "PEFiles", "as", "Evil", "or", "AOK", "(", "TOY", "not", "a", "real", "classifier", "at", "this", "point", ")" ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/workers/pe_classifier.py#L12-L25
yfpeng/bioc
bioc/biocxml/encoder.py
dump
def dump(collection: BioCCollection, fp, pretty_print: bool = True): """ Serialize ``collection`` as a BioC formatted stream to ``fp``. Args: collection: the BioC collection fp: a ``.write()``-supporting file-like object pretty_print: enables formatted XML """ fp.wr...
python
def dump(collection: BioCCollection, fp, pretty_print: bool = True): """ Serialize ``collection`` as a BioC formatted stream to ``fp``. Args: collection: the BioC collection fp: a ``.write()``-supporting file-like object pretty_print: enables formatted XML """ fp.wr...
[ "def", "dump", "(", "collection", ":", "BioCCollection", ",", "fp", ",", "pretty_print", ":", "bool", "=", "True", ")", ":", "fp", ".", "write", "(", "dumps", "(", "collection", ",", "pretty_print", ")", ")" ]
Serialize ``collection`` as a BioC formatted stream to ``fp``. Args: collection: the BioC collection fp: a ``.write()``-supporting file-like object pretty_print: enables formatted XML
[ "Serialize", "collection", "as", "a", "BioC", "formatted", "stream", "to", "fp", ".", "Args", ":", "collection", ":", "the", "BioC", "collection", "fp", ":", "a", ".", "write", "()", "-", "supporting", "file", "-", "like", "object", "pretty_print", ":", ...
train
https://github.com/yfpeng/bioc/blob/47ddaa010960d9ba673aefe068e7bbaf39f0fff4/bioc/biocxml/encoder.py#L10-L19
yfpeng/bioc
bioc/biocxml/encoder.py
dumps
def dumps(collection: BioCCollection, pretty_print: bool = True) -> str: """ Serialize ``collection`` to a BioC formatted ``str``. Args: collection: the BioC collection pretty_print: enables formatted XML Returns: a BioC formatted ``str`` """ doc = etree.Elem...
python
def dumps(collection: BioCCollection, pretty_print: bool = True) -> str: """ Serialize ``collection`` to a BioC formatted ``str``. Args: collection: the BioC collection pretty_print: enables formatted XML Returns: a BioC formatted ``str`` """ doc = etree.Elem...
[ "def", "dumps", "(", "collection", ":", "BioCCollection", ",", "pretty_print", ":", "bool", "=", "True", ")", "->", "str", ":", "doc", "=", "etree", ".", "ElementTree", "(", "BioCXMLEncoder", "(", ")", ".", "encode", "(", "collection", ")", ")", "s", "...
Serialize ``collection`` to a BioC formatted ``str``. Args: collection: the BioC collection pretty_print: enables formatted XML Returns: a BioC formatted ``str``
[ "Serialize", "collection", "to", "a", "BioC", "formatted", "str", ".", "Args", ":", "collection", ":", "the", "BioC", "collection", "pretty_print", ":", "enables", "formatted", "XML", "Returns", ":", "a", "BioC", "formatted", "str" ]
train
https://github.com/yfpeng/bioc/blob/47ddaa010960d9ba673aefe068e7bbaf39f0fff4/bioc/biocxml/encoder.py#L22-L36
yfpeng/bioc
bioc/biocxml/encoder.py
encode_location
def encode_location(location: BioCLocation): """Encode a single location.""" return etree.Element('location', {'offset': str(location.offset), 'length': str(location.length)})
python
def encode_location(location: BioCLocation): """Encode a single location.""" return etree.Element('location', {'offset': str(location.offset), 'length': str(location.length)})
[ "def", "encode_location", "(", "location", ":", "BioCLocation", ")", ":", "return", "etree", ".", "Element", "(", "'location'", ",", "{", "'offset'", ":", "str", "(", "location", ".", "offset", ")", ",", "'length'", ":", "str", "(", "location", ".", "len...
Encode a single location.
[ "Encode", "a", "single", "location", "." ]
train
https://github.com/yfpeng/bioc/blob/47ddaa010960d9ba673aefe068e7bbaf39f0fff4/bioc/biocxml/encoder.py#L39-L42
yfpeng/bioc
bioc/biocxml/encoder.py
encode_relation
def encode_relation(relation: BioCRelation): """Encode a single relation.""" tree = etree.Element('relation', {'id': relation.id}) encode_infons(tree, relation.infons) for node in relation.nodes: tree.append(encode_node(node)) return tree
python
def encode_relation(relation: BioCRelation): """Encode a single relation.""" tree = etree.Element('relation', {'id': relation.id}) encode_infons(tree, relation.infons) for node in relation.nodes: tree.append(encode_node(node)) return tree
[ "def", "encode_relation", "(", "relation", ":", "BioCRelation", ")", ":", "tree", "=", "etree", ".", "Element", "(", "'relation'", ",", "{", "'id'", ":", "relation", ".", "id", "}", ")", "encode_infons", "(", "tree", ",", "relation", ".", "infons", ")", ...
Encode a single relation.
[ "Encode", "a", "single", "relation", "." ]
train
https://github.com/yfpeng/bioc/blob/47ddaa010960d9ba673aefe068e7bbaf39f0fff4/bioc/biocxml/encoder.py#L50-L56
yfpeng/bioc
bioc/biocxml/encoder.py
encode_annotation
def encode_annotation(annotation): """Encode a single annotation.""" tree = etree.Element('annotation', {'id': annotation.id}) encode_infons(tree, annotation.infons) for location in annotation.locations: tree.append(encode_location(location)) etree.SubElement(tree, 'text').text = annot...
python
def encode_annotation(annotation): """Encode a single annotation.""" tree = etree.Element('annotation', {'id': annotation.id}) encode_infons(tree, annotation.infons) for location in annotation.locations: tree.append(encode_location(location)) etree.SubElement(tree, 'text').text = annot...
[ "def", "encode_annotation", "(", "annotation", ")", ":", "tree", "=", "etree", ".", "Element", "(", "'annotation'", ",", "{", "'id'", ":", "annotation", ".", "id", "}", ")", "encode_infons", "(", "tree", ",", "annotation", ".", "infons", ")", "for", "loc...
Encode a single annotation.
[ "Encode", "a", "single", "annotation", "." ]
train
https://github.com/yfpeng/bioc/blob/47ddaa010960d9ba673aefe068e7bbaf39f0fff4/bioc/biocxml/encoder.py#L71-L78
yfpeng/bioc
bioc/biocxml/encoder.py
encode_sentence
def encode_sentence(sentence): """Encode a single sentence.""" tree = etree.Element('sentence') encode_infons(tree, sentence.infons) etree.SubElement(tree, 'offset').text = str(sentence.offset) if sentence.text: etree.SubElement(tree, 'text').text = sentence.text for ann in senten...
python
def encode_sentence(sentence): """Encode a single sentence.""" tree = etree.Element('sentence') encode_infons(tree, sentence.infons) etree.SubElement(tree, 'offset').text = str(sentence.offset) if sentence.text: etree.SubElement(tree, 'text').text = sentence.text for ann in senten...
[ "def", "encode_sentence", "(", "sentence", ")", ":", "tree", "=", "etree", ".", "Element", "(", "'sentence'", ")", "encode_infons", "(", "tree", ",", "sentence", ".", "infons", ")", "etree", ".", "SubElement", "(", "tree", ",", "'offset'", ")", ".", "tex...
Encode a single sentence.
[ "Encode", "a", "single", "sentence", "." ]
train
https://github.com/yfpeng/bioc/blob/47ddaa010960d9ba673aefe068e7bbaf39f0fff4/bioc/biocxml/encoder.py#L81-L92
yfpeng/bioc
bioc/biocxml/encoder.py
encode_passage
def encode_passage(passage): """Encode a single passage.""" tree = etree.Element('passage') encode_infons(tree, passage.infons) etree.SubElement(tree, 'offset').text = str(passage.offset) if passage.text: etree.SubElement(tree, 'text').text = passage.text for sen in passage.senten...
python
def encode_passage(passage): """Encode a single passage.""" tree = etree.Element('passage') encode_infons(tree, passage.infons) etree.SubElement(tree, 'offset').text = str(passage.offset) if passage.text: etree.SubElement(tree, 'text').text = passage.text for sen in passage.senten...
[ "def", "encode_passage", "(", "passage", ")", ":", "tree", "=", "etree", ".", "Element", "(", "'passage'", ")", "encode_infons", "(", "tree", ",", "passage", ".", "infons", ")", "etree", ".", "SubElement", "(", "tree", ",", "'offset'", ")", ".", "text", ...
Encode a single passage.
[ "Encode", "a", "single", "passage", "." ]
train
https://github.com/yfpeng/bioc/blob/47ddaa010960d9ba673aefe068e7bbaf39f0fff4/bioc/biocxml/encoder.py#L95-L108
yfpeng/bioc
bioc/biocxml/encoder.py
encode_document
def encode_document(document): """Encode a single document.""" tree = etree.Element('document') etree.SubElement(tree, 'id').text = document.id encode_infons(tree, document.infons) for passage in document.passages: tree.append(encode_passage(passage)) for ann in document.annotatio...
python
def encode_document(document): """Encode a single document.""" tree = etree.Element('document') etree.SubElement(tree, 'id').text = document.id encode_infons(tree, document.infons) for passage in document.passages: tree.append(encode_passage(passage)) for ann in document.annotatio...
[ "def", "encode_document", "(", "document", ")", ":", "tree", "=", "etree", ".", "Element", "(", "'document'", ")", "etree", ".", "SubElement", "(", "tree", ",", "'id'", ")", ".", "text", "=", "document", ".", "id", "encode_infons", "(", "tree", ",", "d...
Encode a single document.
[ "Encode", "a", "single", "document", "." ]
train
https://github.com/yfpeng/bioc/blob/47ddaa010960d9ba673aefe068e7bbaf39f0fff4/bioc/biocxml/encoder.py#L111-L122
yfpeng/bioc
bioc/biocxml/encoder.py
encode_collection
def encode_collection(collection): """Encode a single collection.""" tree = etree.Element('collection') etree.SubElement(tree, 'source').text = collection.source etree.SubElement(tree, 'date').text = collection.date etree.SubElement(tree, 'key').text = collection.key encode_infons(tree, co...
python
def encode_collection(collection): """Encode a single collection.""" tree = etree.Element('collection') etree.SubElement(tree, 'source').text = collection.source etree.SubElement(tree, 'date').text = collection.date etree.SubElement(tree, 'key').text = collection.key encode_infons(tree, co...
[ "def", "encode_collection", "(", "collection", ")", ":", "tree", "=", "etree", ".", "Element", "(", "'collection'", ")", "etree", ".", "SubElement", "(", "tree", ",", "'source'", ")", ".", "text", "=", "collection", ".", "source", "etree", ".", "SubElement...
Encode a single collection.
[ "Encode", "a", "single", "collection", "." ]
train
https://github.com/yfpeng/bioc/blob/47ddaa010960d9ba673aefe068e7bbaf39f0fff4/bioc/biocxml/encoder.py#L125-L134
yfpeng/bioc
bioc/biocxml/encoder.py
BioCXMLEncoder.default
def default(self, obj): """Implement this method in a subclass such that it returns a tree for ``o``.""" if isinstance(obj, BioCDocument): return encode_document(obj) if isinstance(obj, BioCCollection): return encode_collection(obj) raise TypeError(f'Object ...
python
def default(self, obj): """Implement this method in a subclass such that it returns a tree for ``o``.""" if isinstance(obj, BioCDocument): return encode_document(obj) if isinstance(obj, BioCCollection): return encode_collection(obj) raise TypeError(f'Object ...
[ "def", "default", "(", "self", ",", "obj", ")", ":", "if", "isinstance", "(", "obj", ",", "BioCDocument", ")", ":", "return", "encode_document", "(", "obj", ")", "if", "isinstance", "(", "obj", ",", "BioCCollection", ")", ":", "return", "encode_collection"...
Implement this method in a subclass such that it returns a tree for ``o``.
[ "Implement", "this", "method", "in", "a", "subclass", "such", "that", "it", "returns", "a", "tree", "for", "o", "." ]
train
https://github.com/yfpeng/bioc/blob/47ddaa010960d9ba673aefe068e7bbaf39f0fff4/bioc/biocxml/encoder.py#L146-L152
yfpeng/bioc
bioc/biocxml/encoder.py
BioCXMLDocumentWriter.write_collection_info
def write_collection_info(self, collection: BioCCollection): """ Writes the collection information: encoding, version, DTD, source, date, key, infons, etc. """ elem = etree.Element('source') elem.text = collection.source self.__writer.send(elem) elem = et...
python
def write_collection_info(self, collection: BioCCollection): """ Writes the collection information: encoding, version, DTD, source, date, key, infons, etc. """ elem = etree.Element('source') elem.text = collection.source self.__writer.send(elem) elem = et...
[ "def", "write_collection_info", "(", "self", ",", "collection", ":", "BioCCollection", ")", ":", "elem", "=", "etree", ".", "Element", "(", "'source'", ")", "elem", ".", "text", "=", "collection", ".", "source", "self", ".", "__writer", ".", "send", "(", ...
Writes the collection information: encoding, version, DTD, source, date, key, infons, etc.
[ "Writes", "the", "collection", "information", ":", "encoding", "version", "DTD", "source", "date", "key", "infons", "etc", "." ]
train
https://github.com/yfpeng/bioc/blob/47ddaa010960d9ba673aefe068e7bbaf39f0fff4/bioc/biocxml/encoder.py#L185-L204
yfpeng/bioc
bioc/biocxml/encoder.py
BioCXMLDocumentWriter.write_document
def write_document(self, document: BioCDocument): """Encode and write a single document.""" tree = self.encoder.encode(document) self.__writer.send(tree)
python
def write_document(self, document: BioCDocument): """Encode and write a single document.""" tree = self.encoder.encode(document) self.__writer.send(tree)
[ "def", "write_document", "(", "self", ",", "document", ":", "BioCDocument", ")", ":", "tree", "=", "self", ".", "encoder", ".", "encode", "(", "document", ")", "self", ".", "__writer", ".", "send", "(", "tree", ")" ]
Encode and write a single document.
[ "Encode", "and", "write", "a", "single", "document", "." ]
train
https://github.com/yfpeng/bioc/blob/47ddaa010960d9ba673aefe068e7bbaf39f0fff4/bioc/biocxml/encoder.py#L210-L213
SuperCowPowers/workbench
workbench/clients/customer_report.py
run
def run(): """This client generates customer reports on all the samples in workbench.""" # Grab server args args = client_helper.grab_server_args() # Start up workbench connection workbench = zerorpc.Client(timeout=300, heartbeat=60) workbench.connect('tcp://'+args['server']+':'+args['port...
python
def run(): """This client generates customer reports on all the samples in workbench.""" # Grab server args args = client_helper.grab_server_args() # Start up workbench connection workbench = zerorpc.Client(timeout=300, heartbeat=60) workbench.connect('tcp://'+args['server']+':'+args['port...
[ "def", "run", "(", ")", ":", "# Grab server args", "args", "=", "client_helper", ".", "grab_server_args", "(", ")", "# Start up workbench connection", "workbench", "=", "zerorpc", ".", "Client", "(", "timeout", "=", "300", ",", "heartbeat", "=", "60", ")", "wo...
This client generates customer reports on all the samples in workbench.
[ "This", "client", "generates", "customer", "reports", "on", "all", "the", "samples", "in", "workbench", "." ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/clients/customer_report.py#L7-L20
IBM/ibm-cos-sdk-python-s3transfer
ibm_s3transfer/aspera/utils.py
check_io_access
def check_io_access(ioobj, access, is_file=False): ''' check if a file/folder exists and has a given IO access ''' if ((is_file and not os.path.isfile(ioobj)) or (not is_file and not os.path.isdir(ioobj)) or not os.access(ioobj, access)): _objtype = "File" if is_file else "Direct...
python
def check_io_access(ioobj, access, is_file=False): ''' check if a file/folder exists and has a given IO access ''' if ((is_file and not os.path.isfile(ioobj)) or (not is_file and not os.path.isdir(ioobj)) or not os.access(ioobj, access)): _objtype = "File" if is_file else "Direct...
[ "def", "check_io_access", "(", "ioobj", ",", "access", ",", "is_file", "=", "False", ")", ":", "if", "(", "(", "is_file", "and", "not", "os", ".", "path", ".", "isfile", "(", "ioobj", ")", ")", "or", "(", "not", "is_file", "and", "not", "os", ".", ...
check if a file/folder exists and has a given IO access
[ "check", "if", "a", "file", "/", "folder", "exists", "and", "has", "a", "given", "IO", "access" ]
train
https://github.com/IBM/ibm-cos-sdk-python-s3transfer/blob/24ba53137213e26e6b8fc2c3ec1e8198d507d22b/ibm_s3transfer/aspera/utils.py#L26-L32
yfpeng/bioc
bioc/validator.py
validate
def validate(collection, onerror: Callable[[str, List], None] = None): """Validate BioC data structure.""" BioCValidator(onerror).validate(collection)
python
def validate(collection, onerror: Callable[[str, List], None] = None): """Validate BioC data structure.""" BioCValidator(onerror).validate(collection)
[ "def", "validate", "(", "collection", ",", "onerror", ":", "Callable", "[", "[", "str", ",", "List", "]", ",", "None", "]", "=", "None", ")", ":", "BioCValidator", "(", "onerror", ")", ".", "validate", "(", "collection", ")" ]
Validate BioC data structure.
[ "Validate", "BioC", "data", "structure", "." ]
train
https://github.com/yfpeng/bioc/blob/47ddaa010960d9ba673aefe068e7bbaf39f0fff4/bioc/validator.py#L131-L133
yfpeng/bioc
bioc/validator.py
BioCValidator.validate_doc
def validate_doc(self, document: BioCDocument): """Validate a single document.""" annotations = [] annotations.extend(document.annotations) annotations.extend(document.relations) for passage in document.passages: annotations.extend(passage.annotations) ann...
python
def validate_doc(self, document: BioCDocument): """Validate a single document.""" annotations = [] annotations.extend(document.annotations) annotations.extend(document.relations) for passage in document.passages: annotations.extend(passage.annotations) ann...
[ "def", "validate_doc", "(", "self", ",", "document", ":", "BioCDocument", ")", ":", "annotations", "=", "[", "]", "annotations", ".", "extend", "(", "document", ".", "annotations", ")", "annotations", ".", "extend", "(", "document", ".", "relations", ")", ...
Validate a single document.
[ "Validate", "a", "single", "document", "." ]
train
https://github.com/yfpeng/bioc/blob/47ddaa010960d9ba673aefe068e7bbaf39f0fff4/bioc/validator.py#L28-L62
yfpeng/bioc
bioc/validator.py
BioCValidator.validate
def validate(self, collection: BioCCollection): """Validate a single collection.""" for document in collection.documents: self.validate_doc(document)
python
def validate(self, collection: BioCCollection): """Validate a single collection.""" for document in collection.documents: self.validate_doc(document)
[ "def", "validate", "(", "self", ",", "collection", ":", "BioCCollection", ")", ":", "for", "document", "in", "collection", ".", "documents", ":", "self", ".", "validate_doc", "(", "document", ")" ]
Validate a single collection.
[ "Validate", "a", "single", "collection", "." ]
train
https://github.com/yfpeng/bioc/blob/47ddaa010960d9ba673aefe068e7bbaf39f0fff4/bioc/validator.py#L64-L67
SuperCowPowers/workbench
workbench/clients/pe_indexer.py
run
def run(): """This client pushes PE Files -> ELS Indexer.""" # Grab server args args = client_helper.grab_server_args() # Start up workbench connection workbench = zerorpc.Client(timeout=300, heartbeat=60) workbench.connect('tcp://'+args['server']+':'+args['port']) # Test out PEFile -...
python
def run(): """This client pushes PE Files -> ELS Indexer.""" # Grab server args args = client_helper.grab_server_args() # Start up workbench connection workbench = zerorpc.Client(timeout=300, heartbeat=60) workbench.connect('tcp://'+args['server']+':'+args['port']) # Test out PEFile -...
[ "def", "run", "(", ")", ":", "# Grab server args", "args", "=", "client_helper", ".", "grab_server_args", "(", ")", "# Start up workbench connection", "workbench", "=", "zerorpc", ".", "Client", "(", "timeout", "=", "300", ",", "heartbeat", "=", "60", ")", "wo...
This client pushes PE Files -> ELS Indexer.
[ "This", "client", "pushes", "PE", "Files", "-", ">", "ELS", "Indexer", "." ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/clients/pe_indexer.py#L7-L64
SuperCowPowers/workbench
workbench/workers/mem_procdump.py
MemoryImageProcDump.execute
def execute(self, input_data): ''' Execute method ''' # Spin up the rekall adapter adapter = RekallAdapter() adapter.set_plugin_name(self.plugin_name) # Create a temporary directory and run this plugin from there with self.goto_temp_directory(): # R...
python
def execute(self, input_data): ''' Execute method ''' # Spin up the rekall adapter adapter = RekallAdapter() adapter.set_plugin_name(self.plugin_name) # Create a temporary directory and run this plugin from there with self.goto_temp_directory(): # R...
[ "def", "execute", "(", "self", ",", "input_data", ")", ":", "# Spin up the rekall adapter", "adapter", "=", "RekallAdapter", "(", ")", "adapter", ".", "set_plugin_name", "(", "self", ".", "plugin_name", ")", "# Create a temporary directory and run this plugin from there",...
Execute method
[ "Execute", "method" ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/workers/mem_procdump.py#L32-L78
SuperCowPowers/workbench
workbench/workers/pe_features.py
convert_to_utf8
def convert_to_utf8(string): ''' Convert string to UTF8 ''' if (isinstance(string, unicode)): return string.encode('utf-8') try: u = unicode(string, 'utf-8') except TypeError: return str(string) utf8 = u.encode('utf-8') return utf8
python
def convert_to_utf8(string): ''' Convert string to UTF8 ''' if (isinstance(string, unicode)): return string.encode('utf-8') try: u = unicode(string, 'utf-8') except TypeError: return str(string) utf8 = u.encode('utf-8') return utf8
[ "def", "convert_to_utf8", "(", "string", ")", ":", "if", "(", "isinstance", "(", "string", ",", "unicode", ")", ")", ":", "return", "string", ".", "encode", "(", "'utf-8'", ")", "try", ":", "u", "=", "unicode", "(", "string", ",", "'utf-8'", ")", "ex...
Convert string to UTF8
[ "Convert", "string", "to", "UTF8" ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/workers/pe_features.py#L309-L318
SuperCowPowers/workbench
workbench/workers/pe_features.py
PEFileWorker.execute
def execute(self, input_data): ''' Process the input bytes with pefile ''' raw_bytes = input_data['sample']['raw_bytes'] # Have the PE File module process the file pefile_handle, error_str = self.open_using_pefile('unknown', raw_bytes) if not pefile_handle: return {...
python
def execute(self, input_data): ''' Process the input bytes with pefile ''' raw_bytes = input_data['sample']['raw_bytes'] # Have the PE File module process the file pefile_handle, error_str = self.open_using_pefile('unknown', raw_bytes) if not pefile_handle: return {...
[ "def", "execute", "(", "self", ",", "input_data", ")", ":", "raw_bytes", "=", "input_data", "[", "'sample'", "]", "[", "'raw_bytes'", "]", "# Have the PE File module process the file", "pefile_handle", ",", "error_str", "=", "self", ".", "open_using_pefile", "(", ...
Process the input bytes with pefile
[ "Process", "the", "input", "bytes", "with", "pefile" ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/workers/pe_features.py#L53-L67
SuperCowPowers/workbench
workbench/workers/pe_features.py
PEFileWorker.open_using_pefile
def open_using_pefile(input_name, input_bytes): ''' Open the PE File using the Python pefile module. ''' try: pef = pefile.PE(data=input_bytes, fast_load=False) except (AttributeError, pefile.PEFormatError), error: print 'warning: pe_fail (with exception from pefile modul...
python
def open_using_pefile(input_name, input_bytes): ''' Open the PE File using the Python pefile module. ''' try: pef = pefile.PE(data=input_bytes, fast_load=False) except (AttributeError, pefile.PEFormatError), error: print 'warning: pe_fail (with exception from pefile modul...
[ "def", "open_using_pefile", "(", "input_name", ",", "input_bytes", ")", ":", "try", ":", "pef", "=", "pefile", ".", "PE", "(", "data", "=", "input_bytes", ",", "fast_load", "=", "False", ")", "except", "(", "AttributeError", ",", "pefile", ".", "PEFormatEr...
Open the PE File using the Python pefile module.
[ "Open", "the", "PE", "File", "using", "the", "Python", "pefile", "module", "." ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/workers/pe_features.py#L93-L109
SuperCowPowers/workbench
workbench/workers/pe_features.py
PEFileWorker.extract_features_using_pefile
def extract_features_using_pefile(self, pef): ''' Process the PE File using the Python pefile module. ''' # Store all extracted features into feature lists extracted_dense = {} extracted_sparse = {} # Now slog through the info and extract the features feature_not_found_...
python
def extract_features_using_pefile(self, pef): ''' Process the PE File using the Python pefile module. ''' # Store all extracted features into feature lists extracted_dense = {} extracted_sparse = {} # Now slog through the info and extract the features feature_not_found_...
[ "def", "extract_features_using_pefile", "(", "self", ",", "pef", ")", ":", "# Store all extracted features into feature lists", "extracted_dense", "=", "{", "}", "extracted_sparse", "=", "{", "}", "# Now slog through the info and extract the features", "feature_not_found_flag", ...
Process the PE File using the Python pefile module.
[ "Process", "the", "PE", "File", "using", "the", "Python", "pefile", "module", "." ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/workers/pe_features.py#L112-L306
SuperCowPowers/workbench
workbench/server/bro/bro_log_reader.py
BroLogReader.read_log
def read_log(self, logfile): """The read_log method returns a memory efficient generator for rows in a Bro log. Usage: rows = my_bro_reader.read_log(logfile) for row in rows: do something with row Args: logfile: The Bro Log file. """...
python
def read_log(self, logfile): """The read_log method returns a memory efficient generator for rows in a Bro log. Usage: rows = my_bro_reader.read_log(logfile) for row in rows: do something with row Args: logfile: The Bro Log file. """...
[ "def", "read_log", "(", "self", ",", "logfile", ")", ":", "# Make sure we're at the beginning", "logfile", ".", "seek", "(", "0", ")", "# First parse the header of the bro log", "field_names", ",", "_", "=", "self", ".", "_parse_bro_header", "(", "logfile", ")", "...
The read_log method returns a memory efficient generator for rows in a Bro log. Usage: rows = my_bro_reader.read_log(logfile) for row in rows: do something with row Args: logfile: The Bro Log file.
[ "The", "read_log", "method", "returns", "a", "memory", "efficient", "generator", "for", "rows", "in", "a", "Bro", "log", "." ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/server/bro/bro_log_reader.py#L20-L48
SuperCowPowers/workbench
workbench/server/bro/bro_log_reader.py
BroLogReader._parse_bro_header
def _parse_bro_header(self, logfile): """This method tries to parse the Bro log header section. Note: My googling is failing me on the documentation on the format, so just making a lot of assumptions and skipping some shit. Assumption 1: The delimeter is a tab. Assumption 2: Typ...
python
def _parse_bro_header(self, logfile): """This method tries to parse the Bro log header section. Note: My googling is failing me on the documentation on the format, so just making a lot of assumptions and skipping some shit. Assumption 1: The delimeter is a tab. Assumption 2: Typ...
[ "def", "_parse_bro_header", "(", "self", ",", "logfile", ")", ":", "# Skip until you find the #fields line", "_line", "=", "next", "(", "logfile", ")", "while", "(", "not", "_line", ".", "startswith", "(", "'#fields'", ")", ")", ":", "_line", "=", "next", "(...
This method tries to parse the Bro log header section. Note: My googling is failing me on the documentation on the format, so just making a lot of assumptions and skipping some shit. Assumption 1: The delimeter is a tab. Assumption 2: Types are either time, string, int or float ...
[ "This", "method", "tries", "to", "parse", "the", "Bro", "log", "header", "section", "." ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/server/bro/bro_log_reader.py#L51-L90
SuperCowPowers/workbench
workbench/server/bro/bro_log_reader.py
BroLogReader._cast_dict
def _cast_dict(self, data_dict): """Internal method that makes sure any dictionary elements are properly cast into the correct types, instead of just treating everything like a string from the csv file. Args: data_dict: dictionary containing bro log data. Returns: ...
python
def _cast_dict(self, data_dict): """Internal method that makes sure any dictionary elements are properly cast into the correct types, instead of just treating everything like a string from the csv file. Args: data_dict: dictionary containing bro log data. Returns: ...
[ "def", "_cast_dict", "(", "self", ",", "data_dict", ")", ":", "for", "key", ",", "value", "in", "data_dict", ".", "iteritems", "(", ")", ":", "data_dict", "[", "key", "]", "=", "self", ".", "_cast_value", "(", "value", ")", "# Fixme: resp_body_data can be ...
Internal method that makes sure any dictionary elements are properly cast into the correct types, instead of just treating everything like a string from the csv file. Args: data_dict: dictionary containing bro log data. Returns: Cleaned Data dict.
[ "Internal", "method", "that", "makes", "sure", "any", "dictionary", "elements", "are", "properly", "cast", "into", "the", "correct", "types", "instead", "of", "just", "treating", "everything", "like", "a", "string", "from", "the", "csv", "file", "." ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/server/bro/bro_log_reader.py#L92-L110
SuperCowPowers/workbench
workbench/server/bro/bro_log_reader.py
BroLogReader._cast_value
def _cast_value(self, value): """Internal method that makes sure every value in dictionary is properly cast into the correct types, instead of just treating everything like a string from the csv file. Args: value : The value to be casted Returns: A caste...
python
def _cast_value(self, value): """Internal method that makes sure every value in dictionary is properly cast into the correct types, instead of just treating everything like a string from the csv file. Args: value : The value to be casted Returns: A caste...
[ "def", "_cast_value", "(", "self", ",", "value", ")", ":", "# Try to convert to a datetime (if requested)", "if", "(", "self", ".", "convert_datetimes", ")", ":", "try", ":", "date_time", "=", "datetime", ".", "datetime", ".", "fromtimestamp", "(", "float", "(",...
Internal method that makes sure every value in dictionary is properly cast into the correct types, instead of just treating everything like a string from the csv file. Args: value : The value to be casted Returns: A casted Value.
[ "Internal", "method", "that", "makes", "sure", "every", "value", "in", "dictionary", "is", "properly", "cast", "into", "the", "correct", "types", "instead", "of", "just", "treating", "everything", "like", "a", "string", "from", "the", "csv", "file", "." ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/server/bro/bro_log_reader.py#L112-L143
SuperCowPowers/workbench
workbench/clients/zip_file_extraction.py
run
def run(): """This client shows workbench extacting files from a zip file.""" # Grab server args args = client_helper.grab_server_args() # Start up workbench connection workbench = zerorpc.Client(timeout=300, heartbeat=60) workbench.connect('tcp://'+args['server']+':'+args['port']) # ...
python
def run(): """This client shows workbench extacting files from a zip file.""" # Grab server args args = client_helper.grab_server_args() # Start up workbench connection workbench = zerorpc.Client(timeout=300, heartbeat=60) workbench.connect('tcp://'+args['server']+':'+args['port']) # ...
[ "def", "run", "(", ")", ":", "# Grab server args", "args", "=", "client_helper", ".", "grab_server_args", "(", ")", "# Start up workbench connection", "workbench", "=", "zerorpc", ".", "Client", "(", "timeout", "=", "300", ",", "heartbeat", "=", "60", ")", "wo...
This client shows workbench extacting files from a zip file.
[ "This", "client", "shows", "workbench", "extacting", "files", "from", "a", "zip", "file", "." ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/clients/zip_file_extraction.py#L8-L34
SuperCowPowers/workbench
workbench/workers/vt_query.py
VTQuery.execute
def execute(self, input_data): ''' Execute the VTQuery worker ''' md5 = input_data['meta']['md5'] response = requests.get('http://www.virustotal.com/vtapi/v2/file/report', params={'apikey':self.apikey,'resource':md5, 'allinfo':1}) # Make sure we got a js...
python
def execute(self, input_data): ''' Execute the VTQuery worker ''' md5 = input_data['meta']['md5'] response = requests.get('http://www.virustotal.com/vtapi/v2/file/report', params={'apikey':self.apikey,'resource':md5, 'allinfo':1}) # Make sure we got a js...
[ "def", "execute", "(", "self", ",", "input_data", ")", ":", "md5", "=", "input_data", "[", "'meta'", "]", "[", "'md5'", "]", "response", "=", "requests", ".", "get", "(", "'http://www.virustotal.com/vtapi/v2/file/report'", ",", "params", "=", "{", "'apikey'", ...
Execute the VTQuery worker
[ "Execute", "the", "VTQuery", "worker" ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/workers/vt_query.py#L30-L63
SuperCowPowers/workbench
workbench/workers/pe_peid.py
get_peid_db
def get_peid_db(): ''' Grab the peid_userdb.txt file from local disk ''' # Try to find the yara rules directory relative to the worker my_dir = os.path.dirname(os.path.realpath(__file__)) db_path = os.path.join(my_dir, 'peid_userdb.txt') if not os.path.exists(db_path): raise RuntimeError('p...
python
def get_peid_db(): ''' Grab the peid_userdb.txt file from local disk ''' # Try to find the yara rules directory relative to the worker my_dir = os.path.dirname(os.path.realpath(__file__)) db_path = os.path.join(my_dir, 'peid_userdb.txt') if not os.path.exists(db_path): raise RuntimeError('p...
[ "def", "get_peid_db", "(", ")", ":", "# Try to find the yara rules directory relative to the worker", "my_dir", "=", "os", ".", "path", ".", "dirname", "(", "os", ".", "path", ".", "realpath", "(", "__file__", ")", ")", "db_path", "=", "os", ".", "path", ".", ...
Grab the peid_userdb.txt file from local disk
[ "Grab", "the", "peid_userdb", ".", "txt", "file", "from", "local", "disk" ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/workers/pe_peid.py#L9-L20
SuperCowPowers/workbench
workbench/workers/pe_peid.py
PEIDWorker.execute
def execute(self, input_data): ''' Execute the PEIDWorker ''' raw_bytes = input_data['sample']['raw_bytes'] # Have the PE File module process the file try: pefile_handle = pefile.PE(data=raw_bytes, fast_load=False) except (AttributeError, pefile.PEFormatError), error...
python
def execute(self, input_data): ''' Execute the PEIDWorker ''' raw_bytes = input_data['sample']['raw_bytes'] # Have the PE File module process the file try: pefile_handle = pefile.PE(data=raw_bytes, fast_load=False) except (AttributeError, pefile.PEFormatError), error...
[ "def", "execute", "(", "self", ",", "input_data", ")", ":", "raw_bytes", "=", "input_data", "[", "'sample'", "]", "[", "'raw_bytes'", "]", "# Have the PE File module process the file", "try", ":", "pefile_handle", "=", "pefile", ".", "PE", "(", "data", "=", "r...
Execute the PEIDWorker
[ "Execute", "the", "PEIDWorker" ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/workers/pe_peid.py#L31-L43
SuperCowPowers/workbench
workbench/workers/pe_peid.py
PEIDWorker.peid_features
def peid_features(self, pefile_handle): ''' Get features from PEid signature database''' peid_match = self.peid_sigs.match(pefile_handle) return peid_match if peid_match else []
python
def peid_features(self, pefile_handle): ''' Get features from PEid signature database''' peid_match = self.peid_sigs.match(pefile_handle) return peid_match if peid_match else []
[ "def", "peid_features", "(", "self", ",", "pefile_handle", ")", ":", "peid_match", "=", "self", ".", "peid_sigs", ".", "match", "(", "pefile_handle", ")", "return", "peid_match", "if", "peid_match", "else", "[", "]" ]
Get features from PEid signature database
[ "Get", "features", "from", "PEid", "signature", "database" ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/workers/pe_peid.py#L45-L48
SuperCowPowers/workbench
workbench/clients/pcap_report.py
run
def run(): """This client pulls PCAP files for building report. Returns: A list with `view_pcap` , `meta` and `filename` objects. """ global WORKBENCH # Grab grab_server_argsrver args args = client_helper.grab_server_args() # Start up workbench connection WORKBENCH = zero...
python
def run(): """This client pulls PCAP files for building report. Returns: A list with `view_pcap` , `meta` and `filename` objects. """ global WORKBENCH # Grab grab_server_argsrver args args = client_helper.grab_server_args() # Start up workbench connection WORKBENCH = zero...
[ "def", "run", "(", ")", ":", "global", "WORKBENCH", "# Grab grab_server_argsrver args", "args", "=", "client_helper", ".", "grab_server_args", "(", ")", "# Start up workbench connection", "WORKBENCH", "=", "zerorpc", ".", "Client", "(", "timeout", "=", "300", ",", ...
This client pulls PCAP files for building report. Returns: A list with `view_pcap` , `meta` and `filename` objects.
[ "This", "client", "pulls", "PCAP", "files", "for", "building", "report", "." ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/clients/pcap_report.py#L17-L51
SuperCowPowers/workbench
workbench/clients/pcap_report.py
show_files
def show_files(md5): '''Renders template with `view` of the md5.''' if not WORKBENCH: return flask.redirect('/') md5_view = WORKBENCH.work_request('view', md5) return flask.render_template('templates/md5_view.html', md5_view=md5_view['view'], md5=md5)
python
def show_files(md5): '''Renders template with `view` of the md5.''' if not WORKBENCH: return flask.redirect('/') md5_view = WORKBENCH.work_request('view', md5) return flask.render_template('templates/md5_view.html', md5_view=md5_view['view'], md5=md5)
[ "def", "show_files", "(", "md5", ")", ":", "if", "not", "WORKBENCH", ":", "return", "flask", ".", "redirect", "(", "'/'", ")", "md5_view", "=", "WORKBENCH", ".", "work_request", "(", "'view'", ",", "md5", ")", "return", "flask", ".", "render_template", "...
Renders template with `view` of the md5.
[ "Renders", "template", "with", "view", "of", "the", "md5", "." ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/clients/pcap_report.py#L60-L66
SuperCowPowers/workbench
workbench/clients/pcap_report.py
show_md5_view
def show_md5_view(md5): '''Renders template with `stream_sample` of the md5.''' if not WORKBENCH: return flask.redirect('/') md5_view = WORKBENCH.stream_sample(md5) return flask.render_template('templates/md5_view.html', md5_view=list(md5_view), md5=md5)
python
def show_md5_view(md5): '''Renders template with `stream_sample` of the md5.''' if not WORKBENCH: return flask.redirect('/') md5_view = WORKBENCH.stream_sample(md5) return flask.render_template('templates/md5_view.html', md5_view=list(md5_view), md5=md5)
[ "def", "show_md5_view", "(", "md5", ")", ":", "if", "not", "WORKBENCH", ":", "return", "flask", ".", "redirect", "(", "'/'", ")", "md5_view", "=", "WORKBENCH", ".", "stream_sample", "(", "md5", ")", "return", "flask", ".", "render_template", "(", "'templat...
Renders template with `stream_sample` of the md5.
[ "Renders", "template", "with", "stream_sample", "of", "the", "md5", "." ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/clients/pcap_report.py#L71-L78
SuperCowPowers/workbench
workbench/workers/timeout_corner/pe_features_df.py
PEFeaturesDF.execute
def execute(self, input_data): """This worker puts the output of pe_features into a dictionary of dataframes""" if 'sample' in input_data: print 'Warning: PEFeaturesDF is supposed to be called on a sample_set' self.samples.append(input_data['sample']['md5']) else: ...
python
def execute(self, input_data): """This worker puts the output of pe_features into a dictionary of dataframes""" if 'sample' in input_data: print 'Warning: PEFeaturesDF is supposed to be called on a sample_set' self.samples.append(input_data['sample']['md5']) else: ...
[ "def", "execute", "(", "self", ",", "input_data", ")", ":", "if", "'sample'", "in", "input_data", ":", "print", "'Warning: PEFeaturesDF is supposed to be called on a sample_set'", "self", ".", "samples", ".", "append", "(", "input_data", "[", "'sample'", "]", "[", ...
This worker puts the output of pe_features into a dictionary of dataframes
[ "This", "worker", "puts", "the", "output", "of", "pe_features", "into", "a", "dictionary", "of", "dataframes" ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/workers/timeout_corner/pe_features_df.py#L19-L55
SuperCowPowers/workbench
workbench/server/neo_db.py
NeoDB.add_node
def add_node(self, node_id, name, labels): """Add the node with name and labels. Args: node_id: Id for the node. name: Name for the node. labels: Label for the node. Raises: NotImplementedError: When adding labels is not supported. """ ...
python
def add_node(self, node_id, name, labels): """Add the node with name and labels. Args: node_id: Id for the node. name: Name for the node. labels: Label for the node. Raises: NotImplementedError: When adding labels is not supported. """ ...
[ "def", "add_node", "(", "self", ",", "node_id", ",", "name", ",", "labels", ")", ":", "node", "=", "self", ".", "graph_db", ".", "get_or_create_indexed_node", "(", "'Node'", ",", "'node_id'", ",", "node_id", ",", "{", "'node_id'", ":", "node_id", ",", "'...
Add the node with name and labels. Args: node_id: Id for the node. name: Name for the node. labels: Label for the node. Raises: NotImplementedError: When adding labels is not supported.
[ "Add", "the", "node", "with", "name", "and", "labels", "." ]
train
https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/server/neo_db.py#L26-L41