idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
15,100 | def process ( self ) : client = self . _get_client_by_hostname ( self . host ) self . _await_flow ( client , self . flow_id ) collected_flow_data = self . _download_files ( client , self . flow_id ) if collected_flow_data : print ( '{0:s}: Downloaded: {1:s}' . format ( self . flow_id , collected_flow_data ) ) fqdn = cl... | Collect the results . |
15,101 | def process ( self ) : for disk in self . disks_to_copy : print ( "Disk copy of {0:s} started..." . format ( disk . name ) ) snapshot = disk . snapshot ( ) new_disk = self . analysis_project . create_disk_from_snapshot ( snapshot , disk_name_prefix = "incident" + self . incident_id ) self . analysis_vm . attach_disk ( ... | Copy a disk to the analysis project . |
15,102 | def setup ( self , analysis_project_name , remote_project_name , incident_id , zone , boot_disk_size , cpu_cores , remote_instance_name = None , disk_names = None , all_disks = False , image_project = "ubuntu-os-cloud" , image_family = "ubuntu-1604-lts" ) : disk_names = disk_names . split ( "," ) if disk_names else [ ]... | Sets up a Google cloud collector . |
15,103 | def setup ( self , timezone = None ) : self . _timezone = timezone self . _output_path = tempfile . mkdtemp ( ) | Sets up the _timezone attribute . |
15,104 | def process ( self ) : for description , path in self . state . input : log_file_path = os . path . join ( self . _output_path , 'plaso.log' ) print ( 'Log file: {0:s}' . format ( log_file_path ) ) cmd = [ 'log2timeline.py' ] cmd . extend ( [ '-q' , '--status_view' , 'none' ] ) if self . _timezone : cmd . extend ( [ '-... | Execute the Plaso process . |
15,105 | def setup ( self , reason , grr_server_url , grr_username , grr_password , approvers = None , verify = True ) : grr_auth = ( grr_username , grr_password ) self . approvers = [ ] if approvers : self . approvers = [ item . strip ( ) for item in approvers . strip ( ) . split ( ',' ) ] self . grr_api = grr_api . InitHttp (... | Initializes a GRR hunt result collector . |
15,106 | def _check_approval_wrapper ( self , grr_object , grr_function , * args , ** kwargs ) : approval_sent = False while True : try : return grr_function ( * args , ** kwargs ) except grr_errors . AccessForbiddenError as exception : print ( 'No valid approval found: {0!s}' . format ( exception ) ) if approval_sent : print (... | Wraps a call to GRR functions checking for approval . |
15,107 | def _create_session ( self , username , password ) : session = requests . Session ( ) session . verify = False try : response = session . get ( self . host_url ) except requests . exceptions . ConnectionError : return False soup = BeautifulSoup ( response . text , 'html.parser' ) csrf_token = soup . find ( 'input' , di... | Create HTTP session . |
15,108 | def create_sketch ( self , name , description ) : resource_url = '{0:s}/sketches/' . format ( self . api_base_url ) form_data = { 'name' : name , 'description' : description } response = self . session . post ( resource_url , json = form_data ) response_dict = response . json ( ) sketch_id = response_dict [ 'objects' ]... | Create a new sketch with the specified name and description . |
15,109 | def upload_timeline ( self , timeline_name , plaso_storage_path ) : resource_url = '{0:s}/upload/' . format ( self . api_base_url ) files = { 'file' : open ( plaso_storage_path , 'rb' ) } data = { 'name' : timeline_name } response = self . session . post ( resource_url , files = files , data = data ) try : response_dic... | Create a timeline with the specified name from the given plaso file . |
15,110 | def export_artifacts ( self , processed_artifacts , sketch_id ) : for timeline_name , artifact_path in processed_artifacts : print ( 'Uploading {0:s} to timeline {1:s}' . format ( artifact_path , timeline_name ) ) new_timeline_id = self . upload_timeline ( timeline_name , artifact_path ) self . add_timeline_to_sketch (... | Upload provided artifacts to specified or new if non - existent sketch . |
15,111 | def add_timeline_to_sketch ( self , sketch_id , index_id ) : resource_url = '{0:s}/sketches/{1:d}/timelines/' . format ( self . api_base_url , sketch_id ) form_data = { 'timeline' : [ index_id ] } self . session . post ( resource_url , json = form_data ) | Associate the specified timeline and sketch . |
15,112 | def get_sketch ( self , sketch_id ) : resource_url = '{0:s}/sketches/{1:d}/' . format ( self . api_base_url , sketch_id ) response = self . session . get ( resource_url ) response_dict = response . json ( ) try : response_dict [ 'objects' ] except KeyError : raise ValueError ( 'Sketch does not exist or you have no acce... | Get information on the specified sketch . |
15,113 | def setup ( self , keywords = None ) : self . _keywords = keywords self . _output_path = tempfile . mkdtemp ( ) | Sets up the _keywords attribute . |
15,114 | def process ( self ) : for _ , path in self . state . input : log_file_path = os . path . join ( self . _output_path , 'grepper.log' ) print ( 'Log file: {0:s}' . format ( log_file_path ) ) print ( 'Walking through dir (absolute) = ' + os . path . abspath ( path ) ) try : for root , _ , files in os . walk ( path ) : fo... | Execute the grep command |
15,115 | def grepPDF ( self , path ) : with open ( path , 'rb' ) as pdf_file_obj : match = set ( ) text = '' pdf_reader = PyPDF2 . PdfFileReader ( pdf_file_obj ) pages = pdf_reader . numPages for page in range ( pages ) : page_obj = pdf_reader . getPage ( page ) text += '\n' + page_obj . extractText ( ) match . update ( set ( x... | Parse PDF files text content for keywords . |
15,116 | def load_recipe ( self , recipe ) : self . recipe = recipe for module_description in recipe [ 'modules' ] : module_name = module_description [ 'name' ] module = self . config . get_module ( module_name ) ( self ) self . _module_pool [ module_name ] = module | Populates the internal module pool with modules declared in a recipe . |
15,117 | def store_container ( self , container ) : with self . _store_lock : self . store . setdefault ( container . CONTAINER_TYPE , [ ] ) . append ( container ) | Thread - safe method to store data in the state s store . |
15,118 | def get_containers ( self , container_class ) : with self . _store_lock : return self . store . get ( container_class . CONTAINER_TYPE , [ ] ) | Thread - safe method to retrieve data from the state s store . |
15,119 | def setup_modules ( self , args ) : def _setup_module_thread ( module_description ) : new_args = utils . import_args_from_dict ( module_description [ 'args' ] , vars ( args ) , self . config ) module = self . _module_pool [ module_description [ 'name' ] ] try : module . setup ( ** new_args ) except Exception as error :... | Performs setup tasks for each module in the module pool . |
15,120 | def run_modules ( self ) : def _run_module_thread ( module_description ) : for blocker in module_description [ 'wants' ] : self . events [ blocker ] . wait ( ) module = self . _module_pool [ module_description [ 'name' ] ] try : module . process ( ) except DFTimewolfError as error : self . add_error ( error . message ,... | Performs the actual processing for each module in the module pool . |
15,121 | def add_error ( self , error , critical = False ) : self . errors . append ( ( error , critical ) ) | Adds an error to the state . |
15,122 | def cleanup ( self ) : self . global_errors . extend ( self . errors ) self . errors = [ ] self . input = self . output self . output = [ ] | Basic cleanup after modules . |
15,123 | def check_errors ( self , is_global = False ) : errors = self . global_errors if is_global else self . errors if errors : print ( 'dfTimewolf encountered one or more errors:' ) for error , critical in errors : print ( '{0:s} {1:s}' . format ( 'CRITICAL: ' if critical else '' , error ) ) if critical : print ( 'Critical... | Checks for errors and exits if any of them are critical . |
15,124 | def setup ( self , disk_name , project , turbinia_zone ) : if project is None or turbinia_zone is None : self . state . add_error ( 'project or turbinia_zone are not all specified, bailing out' , critical = True ) return self . disk_name = disk_name self . project = project self . turbinia_zone = turbinia_zone try : tu... | Sets up the object attributes . |
15,125 | def _print_task_data ( self , task ) : print ( ' {0:s} ({1:s})' . format ( task [ 'name' ] , task [ 'id' ] ) ) paths = task . get ( 'saved_paths' , [ ] ) if not paths : return for path in paths : if path . endswith ( 'worker-log.txt' ) : continue if path . endswith ( '{0:s}.log' . format ( task . get ( 'id' ) ) ) : con... | Pretty - prints task data . |
15,126 | def display_task_progress ( self , instance , project , region , request_id = None , user = None , poll_interval = 60 ) : total_completed = 0 while True : task_results = self . client . get_task_data ( instance , project , region , request_id = request_id , user = user ) tasks = { task [ 'id' ] : task for task in task_... | Displays the overall progress of tasks in a Turbinia job . |
15,127 | def generate_help ( ) : help_text = '\nAvailable recipes:\n\n' recipes = config . Config . get_registered_recipes ( ) for contents , _ , _ in sorted ( recipes , key = lambda k : k [ 0 ] [ 'name' ] ) : help_text += ' {0:<35s}{1:s}\n' . format ( contents [ 'name' ] , contents . get ( 'short_description' , 'No description... | Generates help text with alphabetically sorted recipes . |
15,128 | def main ( ) : parser = argparse . ArgumentParser ( formatter_class = argparse . RawDescriptionHelpFormatter , description = generate_help ( ) ) subparsers = parser . add_subparsers ( ) for registered_recipe in config . Config . get_registered_recipes ( ) : recipe , recipe_args , documentation = registered_recipe subpa... | Main function for DFTimewolf . |
15,129 | def setup ( self , endpoint = None , username = None , password = None , incident_id = None , sketch_id = None ) : self . timesketch_api = timesketch_utils . TimesketchApiClient ( endpoint , username , password ) self . incident_id = None self . sketch_id = int ( sketch_id ) if sketch_id else None if not self . timeske... | Setup a connection to a Timesketch server and create a sketch if needed . |
15,130 | def process ( self ) : if not self . timesketch_api . session : message = 'Could not connect to Timesketch server' self . state . add_error ( message , critical = True ) named_timelines = [ ] for description , path in self . state . input : if not description : description = 'untitled timeline for ' + path named_timeli... | Executes a Timesketch export . |
15,131 | def setup ( self , target_directory = None ) : self . _target_directory = target_directory if not target_directory : self . _target_directory = tempfile . mkdtemp ( ) elif not os . path . exists ( target_directory ) : try : os . makedirs ( target_directory ) except OSError as exception : message = 'An unknown error occ... | Sets up the _target_directory attribute . |
15,132 | def _copy_file_or_directory ( self , source , destination_directory ) : if os . path . isdir ( source ) : for item in os . listdir ( source ) : full_source = os . path . join ( source , item ) full_destination = os . path . join ( destination_directory , item ) shutil . copytree ( full_source , full_destination ) else ... | Recursively copies files from source to destination_directory . |
15,133 | def import_args_from_dict ( value , args , config ) : if isinstance ( value , six . string_types ) : for match in TOKEN_REGEX . finditer ( str ( value ) ) : token = match . group ( 1 ) if token in args : actual_param = args [ token ] if isinstance ( actual_param , six . string_types ) : value = value . replace ( "@" + ... | Replaces some arguments by those specified by a key - value dictionary . |
15,134 | def get_version ( ) : reg = re . compile ( r'__version__ = [\'"]([^\'"]*)[\'"]' ) with open ( 'requests_kerberos/__init__.py' ) as fd : matches = list ( filter ( lambda x : x , map ( reg . match , fd ) ) ) if not matches : raise RuntimeError ( 'Could not find the version information for requests_kerberos' ) return matc... | Simple function to extract the current version using regular expressions . |
15,135 | def _negotiate_value ( response ) : if hasattr ( _negotiate_value , 'regex' ) : regex = _negotiate_value . regex else : regex = re . compile ( '(?:.*,)*\s*Negotiate\s*([^,]*),?' , re . I ) _negotiate_value . regex = regex authreq = response . headers . get ( 'www-authenticate' , None ) if authreq : match_obj = regex . ... | Extracts the gssapi authentication token from the appropriate header |
15,136 | def generate_request_header ( self , response , host , is_preemptive = False ) : gssflags = kerberos . GSS_C_MUTUAL_FLAG | kerberos . GSS_C_SEQUENCE_FLAG if self . delegate : gssflags |= kerberos . GSS_C_DELEG_FLAG try : kerb_stage = "authGSSClientInit()" kerb_host = self . hostname_override if self . hostname_override... | Generates the GSSAPI authentication token with kerberos . |
15,137 | def handle_other ( self , response ) : log . debug ( "handle_other(): Handling: %d" % response . status_code ) if self . mutual_authentication in ( REQUIRED , OPTIONAL ) and not self . auth_done : is_http_error = response . status_code >= 400 if _negotiate_value ( response ) is not None : log . debug ( "handle_other():... | Handles all responses with the exception of 401s . |
15,138 | def authenticate_server ( self , response ) : log . debug ( "authenticate_server(): Authenticate header: {0}" . format ( _negotiate_value ( response ) ) ) host = urlparse ( response . url ) . hostname try : if self . cbt_struct : result = kerberos . authGSSClientStep ( self . context [ host ] , _negotiate_value ( respo... | Uses GSSAPI to authenticate the server . |
15,139 | def handle_response ( self , response , ** kwargs ) : num_401s = kwargs . pop ( 'num_401s' , 0 ) if not self . cbt_binding_tried and self . send_cbt : cbt_application_data = _get_channel_bindings_application_data ( response ) if cbt_application_data : try : self . cbt_struct = kerberos . channelBindings ( application_d... | Takes the given response and tries kerberos - auth as needed . |
15,140 | def _quote_query ( query ) : return "&" . join ( "%s=%s" % ( k , urllib_quote ( unicode ( query [ k ] ) . encode ( 'utf-8' ) , safe = '~' ) ) for k in sorted ( query ) ) | Turn a dictionary into a query string in a URL with keys in alphabetical order . |
15,141 | def api_url ( self , ** kwargs ) : query = { 'Operation' : self . Operation , 'Service' : "AWSECommerceService" , 'Timestamp' : time . strftime ( "%Y-%m-%dT%H:%M:%SZ" , time . gmtime ( ) ) , 'Version' : self . Version , } query . update ( kwargs ) query [ 'AWSAccessKeyId' ] = self . AWSAccessKeyId query [ 'Timestamp' ]... | The URL for making the given query against the API . |
15,142 | def isSameTypeWith ( self , other , matchTags = True , matchConstraints = True ) : return ( self is other or ( not matchTags or self . tagSet == other . tagSet ) and ( not matchConstraints or self . subtypeSpec == other . subtypeSpec ) ) | Examine |ASN . 1| type for equality with other ASN . 1 type . |
15,143 | def isSuperTypeOf ( self , other , matchTags = True , matchConstraints = True ) : return ( not matchTags or ( self . tagSet . isSuperTagSetOf ( other . tagSet ) ) and ( not matchConstraints or self . subtypeSpec . isSuperTypeOf ( other . subtypeSpec ) ) ) | Examine |ASN . 1| type for subtype relationship with other ASN . 1 type . |
15,144 | def clone ( self , value = noValue , ** kwargs ) : if value is noValue : if not kwargs : return self value = self . _value initializers = self . readOnly . copy ( ) initializers . update ( kwargs ) return self . __class__ ( value , ** initializers ) | Create a modified version of |ASN . 1| schema or value object . |
15,145 | def subtype ( self , value = noValue , ** kwargs ) : if value is noValue : if not kwargs : return self value = self . _value initializers = self . readOnly . copy ( ) implicitTag = kwargs . pop ( 'implicitTag' , None ) if implicitTag is not None : initializers [ 'tagSet' ] = self . tagSet . tagImplicitly ( implicitTag ... | Create a specialization of |ASN . 1| schema or value object . |
15,146 | def clone ( self , ** kwargs ) : cloneValueFlag = kwargs . pop ( 'cloneValueFlag' , False ) initializers = self . readOnly . copy ( ) initializers . update ( kwargs ) clone = self . __class__ ( ** initializers ) if cloneValueFlag : self . _cloneComponentValues ( clone , cloneValueFlag ) return clone | Create a modified version of |ASN . 1| schema object . |
15,147 | def subtype ( self , ** kwargs ) : initializers = self . readOnly . copy ( ) cloneValueFlag = kwargs . pop ( 'cloneValueFlag' , False ) implicitTag = kwargs . pop ( 'implicitTag' , None ) if implicitTag is not None : initializers [ 'tagSet' ] = self . tagSet . tagImplicitly ( implicitTag ) explicitTag = kwargs . pop ( ... | Create a specialization of |ASN . 1| schema object . |
15,148 | def getTypeByPosition ( self , idx ) : try : return self . __namedTypes [ idx ] . asn1Object except IndexError : raise error . PyAsn1Error ( 'Type position out of range' ) | Return ASN . 1 type object by its position in fields set . |
15,149 | def getPositionByType ( self , tagSet ) : try : return self . __tagToPosMap [ tagSet ] except KeyError : raise error . PyAsn1Error ( 'Type %s not found' % ( tagSet , ) ) | Return field position by its ASN . 1 type . |
15,150 | def getNameByPosition ( self , idx ) : try : return self . __namedTypes [ idx ] . name except IndexError : raise error . PyAsn1Error ( 'Type position out of range' ) | Return field name by its position in fields set . |
15,151 | def getPositionByName ( self , name ) : try : return self . __nameToPosMap [ name ] except KeyError : raise error . PyAsn1Error ( 'Name %s not found' % ( name , ) ) | Return field position by filed name . |
15,152 | def getTagMapNearPosition ( self , idx ) : try : return self . __ambiguousTypes [ idx ] . tagMap except KeyError : raise error . PyAsn1Error ( 'Type position out of range' ) | Return ASN . 1 types that are allowed at or past given field position . |
15,153 | def getPositionNearType ( self , tagSet , idx ) : try : return idx + self . __ambiguousTypes [ idx ] . getPositionByType ( tagSet ) except KeyError : raise error . PyAsn1Error ( 'Type position out of range' ) | Return the closest field position where given ASN . 1 type is allowed . |
15,154 | def asBinary ( self ) : binString = binary . bin ( self . _value ) [ 2 : ] return '0' * ( len ( self . _value ) - len ( binString ) ) + binString | Get |ASN . 1| value as a text string of bits . |
15,155 | def fromOctetString ( cls , value , internalFormat = False , prepend = None , padding = 0 ) : value = SizedInteger ( integer . from_bytes ( value ) >> padding ) . setBitLength ( len ( value ) * 8 - padding ) if prepend is not None : value = SizedInteger ( ( SizedInteger ( prepend ) << len ( value ) ) | value ) . setBit... | Create a |ASN . 1| object initialized from a string . |
15,156 | def fromBinaryString ( value ) : bitNo = 8 byte = 0 r = [ ] for v in value : if bitNo : bitNo -= 1 else : bitNo = 7 r . append ( byte ) byte = 0 if v in ( '0' , '1' ) : v = int ( v ) else : raise error . PyAsn1Error ( 'Non-binary OCTET STRING initializer %s' % ( v , ) ) byte |= v << bitNo r . append ( byte ) return oct... | Create a |ASN . 1| object initialized from a string of 0 and 1 . |
15,157 | def isPrefixOf ( self , other ) : l = len ( self ) if l <= len ( other ) : if self . _value [ : l ] == other [ : l ] : return True return False | Indicate if this |ASN . 1| object is a prefix of other |ASN . 1| object . |
15,158 | def getComponentByPosition ( self , idx , default = noValue , instantiate = True ) : try : componentValue = self . _componentValues [ idx ] except IndexError : if not instantiate : return default self . setComponentByPosition ( idx ) componentValue = self . _componentValues [ idx ] if default is noValue or componentVal... | Return |ASN . 1| type component value by position . |
15,159 | def getComponentByName ( self , name , default = noValue , instantiate = True ) : if self . _componentTypeLen : idx = self . componentType . getPositionByName ( name ) else : try : idx = self . _dynamicNames . getPositionByName ( name ) except KeyError : raise error . PyAsn1Error ( 'Name %s not found' % ( name , ) ) re... | Returns |ASN . 1| type component by name . |
15,160 | def setComponentByName ( self , name , value = noValue , verifyConstraints = True , matchTags = True , matchConstraints = True ) : if self . _componentTypeLen : idx = self . componentType . getPositionByName ( name ) else : try : idx = self . _dynamicNames . getPositionByName ( name ) except KeyError : raise error . Py... | Assign |ASN . 1| type component by name . |
15,161 | def prettyPrint ( self , scope = 0 ) : scope += 1 representation = self . __class__ . __name__ + ':\n' for idx , componentValue in enumerate ( self . _componentValues ) : if componentValue is not noValue and componentValue . isValue : representation += ' ' * scope if self . componentType : representation += self . comp... | Return an object representation string . |
15,162 | def getComponentByType ( self , tagSet , default = noValue , instantiate = True , innerFlag = False ) : componentValue = self . getComponentByPosition ( self . componentType . getPositionByType ( tagSet ) , default = default , instantiate = instantiate ) if innerFlag and isinstance ( componentValue , Set ) : return com... | Returns |ASN . 1| type component by ASN . 1 tag . |
15,163 | def setComponentByType ( self , tagSet , value = noValue , verifyConstraints = True , matchTags = True , matchConstraints = True , innerFlag = False ) : idx = self . componentType . getPositionByType ( tagSet ) if innerFlag : componentType = self . componentType . getTypeByPosition ( idx ) if componentType . tagSet : r... | Assign |ASN . 1| type component by ASN . 1 tag . |
15,164 | def getComponent ( self , innerFlag = False ) : if self . _currentIdx is None : raise error . PyAsn1Error ( 'Component not chosen' ) else : c = self . _componentValues [ self . _currentIdx ] if innerFlag and isinstance ( c , Choice ) : return c . getComponent ( innerFlag ) else : return c | Return currently assigned component of the |ASN . 1| object . |
15,165 | def getName ( self , innerFlag = False ) : if self . _currentIdx is None : raise error . PyAsn1Error ( 'Component not chosen' ) else : if innerFlag : c = self . _componentValues [ self . _currentIdx ] if isinstance ( c , Choice ) : return c . getName ( innerFlag ) return self . componentType . getNameByPosition ( self ... | Return the name of currently assigned component of the |ASN . 1| object . |
15,166 | def expand_path ( path ) : expanded = [ ] if len ( path ) < 2 : return expanded for i in range ( len ( path ) - 1 ) : expanded += bresenham ( path [ i ] , path [ i + 1 ] ) expanded += [ path [ : - 1 ] ] return expanded | Given a compressed path return a new path that has all the segments in it interpolated . |
15,167 | def apply_heuristic ( self , node_a , node_b , heuristic = None ) : if not heuristic : heuristic = self . heuristic return heuristic ( abs ( node_a . x - node_b . x ) , abs ( node_a . y - node_b . y ) ) | helper function to apply heuristic |
15,168 | def cleanup ( self ) : self . h = 0.0 self . g = 0.0 self . f = 0.0 self . opened = 0 self . closed = False self . parent = None self . retain_count = 0 self . tested = False | reset all calculated values fresh start for pathfinding |
15,169 | def walkable ( self , x , y ) : return self . inside ( x , y ) and self . nodes [ y ] [ x ] . walkable | check if the tile is inside grid and if it is set as walkable |
15,170 | def grid_str ( self , path = None , start = None , end = None , border = True , start_chr = 's' , end_chr = 'e' , path_chr = 'x' , empty_chr = ' ' , block_chr = '#' , show_weight = False ) : data = '' if border : data = '+{}+' . format ( '-' * len ( self . nodes [ 0 ] ) ) for y in range ( len ( self . nodes ) ) : line ... | create a printable string from the grid using ASCII characters |
15,171 | def load ( ) : if 'Windows' == platform . system ( ) : fname , dependencies = _windows_fnames ( ) def load_objects ( directory ) : deps = [ cdll . LoadLibrary ( str ( directory . joinpath ( dep ) ) ) for dep in dependencies ] libzbar = cdll . LoadLibrary ( str ( directory . joinpath ( fname ) ) ) return deps , libzbar ... | Loads the libzar shared library and its dependencies . |
15,172 | def load_libzbar ( ) : global LIBZBAR global EXTERNAL_DEPENDENCIES if not LIBZBAR : libzbar , dependencies = zbar_library . load ( ) LIBZBAR = libzbar EXTERNAL_DEPENDENCIES = [ LIBZBAR ] + dependencies return LIBZBAR | Loads the zbar shared library and its dependencies . |
15,173 | def zbar_function ( fname , restype , * args ) : prototype = CFUNCTYPE ( restype , * args ) return prototype ( ( fname , load_libzbar ( ) ) ) | Returns a foreign function exported by zbar . |
15,174 | def _symbols_for_image ( image ) : symbol = zbar_image_first_symbol ( image ) while symbol : yield symbol symbol = zbar_symbol_next ( symbol ) | Generator of symbols . |
15,175 | def _decode_symbols ( symbols ) : for symbol in symbols : data = string_at ( zbar_symbol_get_data ( symbol ) ) symbol_type = ZBarSymbol ( symbol . contents . type ) . name polygon = convex_hull ( ( zbar_symbol_get_loc_x ( symbol , index ) , zbar_symbol_get_loc_y ( symbol , index ) ) for index in _RANGEFN ( zbar_symbol_... | Generator of decoded symbol information . |
15,176 | def render_app_name ( context , app , template = "/admin_app_name.html" ) : try : template = app [ 'app_label' ] + template text = render_to_string ( template , context ) except : text = app [ 'name' ] return text | Render the application name using the default template name . If it cannot find a template matching the given path fallback to the application name . |
15,177 | def render_app_label ( context , app , fallback = "" ) : try : text = app [ 'app_label' ] except KeyError : text = fallback except TypeError : text = app return text | Render the application label . |
15,178 | def render_app_description ( context , app , fallback = "" , template = "/admin_app_description.html" ) : try : template = app [ 'app_label' ] + template text = render_to_string ( template , context ) except : text = fallback return text | Render the application description using the default template name . If it cannot find a template matching the given path fallback to the fallback argument . |
15,179 | def custom_field_rendering ( context , field , * args , ** kwargs ) : if CUSTOM_FIELD_RENDERER : mod , cls = CUSTOM_FIELD_RENDERER . rsplit ( "." , 1 ) field_renderer = getattr ( import_module ( mod ) , cls ) if field_renderer : return field_renderer ( field , ** kwargs ) . render ( ) return field | Wrapper for rendering the field via an external renderer |
15,180 | def filenames ( self ) : if self . _is_reader : assert self . _filenames is not None return self . _filenames else : return self . data_producer . filenames | list of file names the data is originally being read from . |
15,181 | def _data_flow_chain ( self ) : if self . data_producer is None : return [ ] res = [ ] ds = self . data_producer while not ds . is_reader : res . append ( ds ) ds = ds . data_producer res . append ( ds ) res = res [ : : - 1 ] return res | Get a list of all elements in the data flow graph . The first element is the original source the next one reads from the prior and so on and so forth . |
15,182 | def number_of_trajectories ( self , stride = None ) : r if not IteratorState . is_uniform_stride ( stride ) : n = len ( np . unique ( stride [ : , 0 ] ) ) else : n = self . ntraj return n | r Returns the number of trajectories . |
15,183 | def trajectory_length ( self , itraj , stride = 1 , skip = 0 ) : r if itraj >= self . ntraj : raise IndexError ( "given index (%s) exceeds number of data sets (%s)." " Zero based indexing!" % ( itraj , self . ntraj ) ) if not IteratorState . is_uniform_stride ( stride ) : selection = stride [ stride [ : , 0 ] == itraj ... | r Returns the length of trajectory of the requested index . |
15,184 | def trajectory_lengths ( self , stride = 1 , skip = 0 ) : r n = self . ntraj if not IteratorState . is_uniform_stride ( stride ) : return np . fromiter ( ( self . trajectory_length ( itraj , stride ) for itraj in range ( n ) ) , dtype = int , count = n ) else : return np . fromiter ( ( self . trajectory_length ( itraj ... | r Returns the length of each trajectory . |
15,185 | def n_frames_total ( self , stride = 1 , skip = 0 ) : r if not IteratorState . is_uniform_stride ( stride ) : return len ( stride ) return sum ( self . trajectory_lengths ( stride = stride , skip = skip ) ) | r Returns total number of frames . |
15,186 | def write_to_csv ( self , filename = None , extension = '.dat' , overwrite = False , stride = 1 , chunksize = None , ** kw ) : import os if not filename : assert hasattr ( self , 'filenames' ) filenames = [ ] for f in self . filenames : base , _ = os . path . splitext ( f ) filenames . append ( base + extension ) elif ... | write all data to csv with numpy . savetxt |
15,187 | def n_chunks ( self ) : return self . _data_source . n_chunks ( self . chunksize , stride = self . stride , skip = self . skip ) | rough estimate of how many chunks will be processed |
15,188 | def _select_file_guard ( datasource_method ) : from functools import wraps @ wraps ( datasource_method ) def wrapper ( self , itraj ) : if itraj == self . _selected_itraj : return datasource_method ( self , itraj ) self . _itraj = self . _selected_itraj = itraj return wrapper | in case we call _select_file multiple times with the same value we do not want to reopen file handles . |
15,189 | def name ( self ) : try : return self . _name except AttributeError : self . _name = "%s.%s[%i]" % ( self . __module__ , self . __class__ . __name__ , next ( Loggable . __ids ) ) return self . _name | The name of this instance |
15,190 | def _get_model_param_names ( cls ) : r if hasattr ( cls , 'set_model_params' ) : args , varargs , kw , default = getargspec_no_self ( cls . set_model_params ) if varargs is not None : raise RuntimeError ( "PyEMMA models should always specify their parameters in the signature" " of their set_model_params (no varargs). %... | r Get parameter names for the model |
15,191 | def update_model_params ( self , ** params ) : r for key , value in params . items ( ) : if not hasattr ( self , key ) : setattr ( self , key , value ) elif getattr ( self , key ) is None : setattr ( self , key , value ) elif value is not None : setattr ( self , key , value ) | r Update given model parameter if they are set to specific values |
15,192 | def get_model_params ( self , deep = True ) : r out = dict ( ) for key in self . _get_model_param_names ( ) : from pyemma . util . exceptions import PyEMMA_DeprecationWarning warnings . simplefilter ( "always" , DeprecationWarning ) warnings . simplefilter ( "always" , PyEMMA_DeprecationWarning ) try : with warnings . ... | r Get parameters for this model . |
15,193 | def sample_f ( self , f , * args , ** kwargs ) : r self . _check_samples_available ( ) return [ call_member ( M , f , * args , ** kwargs ) for M in self . samples ] | r Evaluated method f for all samples |
15,194 | def sample_mean ( self , f , * args , ** kwargs ) : r vals = self . sample_f ( f , * args , ** kwargs ) return _np . mean ( vals , axis = 0 ) | r Sample mean of numerical method f over all samples |
15,195 | def sample_std ( self , f , * args , ** kwargs ) : r vals = self . sample_f ( f , * args , ** kwargs ) return _np . std ( vals , axis = 0 ) | r Sample standard deviation of numerical method f over all samples |
15,196 | def sample_conf ( self , f , * args , ** kwargs ) : r vals = self . sample_f ( f , * args , ** kwargs ) return confidence_interval ( vals , conf = self . conf ) | r Sample confidence interval of numerical method f over all samples |
15,197 | def describe ( self ) : all_labels = [ ] for f in self . active_features : all_labels += f . describe ( ) return all_labels | Returns a list of strings one for each feature selected with human - readable descriptions of the features . |
15,198 | def add_distances ( self , indices , periodic = True , indices2 = None ) : r from . distances import DistanceFeature atom_pairs = _parse_pairwise_input ( indices , indices2 , self . logger , fname = 'add_distances()' ) atom_pairs = self . _check_indices ( atom_pairs ) f = DistanceFeature ( self . topology , atom_pairs ... | r Adds the distances between atoms to the feature list . |
15,199 | def add_distances_ca ( self , periodic = True , excluded_neighbors = 2 ) : at_idxs_ca = self . select_Ca ( ) res_idxs_ca = [ self . topology . atom ( ca ) . residue . index for ca in at_idxs_ca ] res_idxs_ca_pairs = self . pairs ( res_idxs_ca , excluded_neighbors = excluded_neighbors ) distance_indexes = [ ] for ri , r... | Adds the distances between all Ca s to the feature list . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.