idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
31,100 | def decrypt_get_item ( decrypt_method , crypto_config_method , read_method , ** kwargs ) : validate_get_arguments ( kwargs ) crypto_config , ddb_kwargs = crypto_config_method ( ** kwargs ) response = read_method ( ** ddb_kwargs ) if "Item" in response : response [ "Item" ] = decrypt_method ( item = response [ "Item" ] ... | Transparently decrypt an item after getting it from the table . |
31,101 | def decrypt_batch_get_item ( decrypt_method , crypto_config_method , read_method , ** kwargs ) : request_crypto_config = kwargs . pop ( "crypto_config" , None ) for _table_name , table_kwargs in kwargs [ "RequestItems" ] . items ( ) : validate_get_arguments ( table_kwargs ) response = read_method ( ** kwargs ) for tabl... | Transparently decrypt multiple items after getting them in a batch request . |
31,102 | def encrypt_put_item ( encrypt_method , crypto_config_method , write_method , ** kwargs ) : crypto_config , ddb_kwargs = crypto_config_method ( ** kwargs ) ddb_kwargs [ "Item" ] = encrypt_method ( item = ddb_kwargs [ "Item" ] , crypto_config = crypto_config . with_item ( _item_transformer ( encrypt_method ) ( ddb_kwarg... | Transparently encrypt an item before putting it to the table . |
31,103 | def encrypt_batch_write_item ( encrypt_method , crypto_config_method , write_method , ** kwargs ) : request_crypto_config = kwargs . pop ( "crypto_config" , None ) table_crypto_configs = { } plaintext_items = copy . deepcopy ( kwargs [ "RequestItems" ] ) for table_name , items in kwargs [ "RequestItems" ] . items ( ) :... | Transparently encrypt multiple items before putting them in a batch request . |
31,104 | def _process_batch_write_response ( request , response , table_crypto_config ) : try : unprocessed_items = response [ "UnprocessedItems" ] except KeyError : return response for table_name , unprocessed in unprocessed_items . items ( ) : original_items = request [ table_name ] crypto_config = table_crypto_config [ table... | Handle unprocessed items in the response from a transparently encrypted write . |
31,105 | def _item_attributes_match ( crypto_config , plaintext_item , encrypted_item ) : for name , value in plaintext_item . items ( ) : if crypto_config . attribute_actions . action ( name ) == CryptoAction . ENCRYPT_AND_SIGN : continue if encrypted_item . get ( name ) != value : return False return True | Determines whether the unencrypted values in the plaintext items attributes are the same as those in the encrypted item . Essentially this uses brute force to cover when we don t know the primary and sort index attribute names since they can t be encrypted . |
31,106 | def _feed_line ( self , line ) : if line is None : self . set_result ( self . _callback ( self . __spooled_lines ) ) else : self . __spooled_lines . append ( line ) | Put the given line into the callback machinery and set the result on a None line . |
31,107 | def mpd_command_provider ( cls ) : def collect ( cls , callbacks = dict ( ) ) : for name , ob in cls . __dict__ . items ( ) : if hasattr ( ob , "mpd_commands" ) and name not in callbacks : callbacks [ name ] = ( ob , cls ) for base in cls . __bases__ : callbacks = collect ( base , callbacks ) return callbacks for name ... | Decorator hooking up registered MPD commands to concrete client implementation . |
31,108 | def _create_callback ( self , function , wrap_result ) : if not isinstance ( function , Callable ) : return None def command_callback ( ) : res = function ( self , self . _read_lines ( ) ) if wrap_result : res = self . _wrap_iterator ( res ) return res return command_callback | Create MPD command related response callback . |
31,109 | def _create_command ( wrapper , name , return_value , wrap_result ) : def mpd_command ( self , * args ) : callback = _create_callback ( self , return_value , wrap_result ) return wrapper ( self , name , args , callback ) return mpd_command | Create MPD command related function . |
31,110 | def i4_bit_hi1 ( n ) : i = np . floor ( n ) bit = 0 while i > 0 : bit += 1 i //= 2 return bit | i4_bit_hi1 returns the position of the high 1 bit base 2 in an integer . |
31,111 | def i4_bit_lo0 ( n ) : bit = 1 i = np . floor ( n ) while i != 2 * ( i // 2 ) : bit += 1 i //= 2 return bit | I4_BIT_LO0 returns the position of the low 0 bit base 2 in an integer . |
31,112 | def i4_sobol_generate ( dim_num , n , skip = 1 ) : r = np . full ( ( n , dim_num ) , np . nan ) for j in range ( n ) : seed = j + skip r [ j , 0 : dim_num ] , next_seed = i4_sobol ( dim_num , seed ) return r | i4_sobol_generate generates a Sobol dataset . |
31,113 | def i4_sobol_generate_std_normal ( dim_num , n , skip = 1 ) : sobols = i4_sobol_generate ( dim_num , n , skip ) normals = norm . ppf ( sobols ) return normals | Generates multivariate standard normal quasi - random variables . |
31,114 | def i4_uniform ( a , b , seed ) : if seed == 0 : print ( 'I4_UNIFORM - Fatal error!' ) print ( ' Input SEED = 0!' ) seed = np . floor ( seed ) a = round ( a ) b = round ( b ) seed = np . mod ( seed , 2147483647 ) if seed < 0 : seed += 2147483647 k = seed // 127773 seed = 16807 * ( seed - k * 127773 ) - k * 2836 if see... | i4_uniform returns a scaled pseudorandom I4 . |
31,115 | def prime_ge ( n ) : p = max ( np . ceil ( n ) , 2 ) while not is_prime ( p ) : p += 1 return p | PRIME_GE returns the smallest prime greater than or equal to N . |
31,116 | def is_prime ( n ) : if n != int ( n ) or n < 2 : return False if n == 2 or n == 3 : return True if n % 2 == 0 or n % 3 == 0 : return False p = 5 root = int ( np . ceil ( np . sqrt ( n ) ) ) while p <= root : if n % p == 0 or n % ( p + 2 ) == 0 : return False p += 6 return True | is_prime returns True if N is a prime number False otherwise |
31,117 | def generate_jwt ( claims , priv_key = None , algorithm = 'PS512' , lifetime = None , expires = None , not_before = None , jti_size = 16 , other_headers = None ) : header = { 'typ' : 'JWT' , 'alg' : algorithm if priv_key else 'none' } if other_headers is not None : redefined_keys = set ( header . keys ( ) ) & set ( oth... | Generate a JSON Web Token . |
31,118 | def verify_jwt ( jwt , pub_key = None , allowed_algs = None , iat_skew = timedelta ( ) , checks_optional = False , ignore_not_implemented = False ) : if allowed_algs is None : allowed_algs = [ ] if not isinstance ( allowed_algs , list ) : raise _JWTError ( 'allowed_algs must be a list' ) header , claims , _ = jwt . spl... | Verify a JSON Web Token . |
31,119 | def process_jwt ( jwt ) : header , claims , _ = jwt . split ( '.' ) parsed_header = json_decode ( base64url_decode ( header ) ) parsed_claims = json_decode ( base64url_decode ( claims ) ) return parsed_header , parsed_claims | Process a JSON Web Token without verifying it . |
31,120 | def run ( self , reporter = None ) : if not reporter : reporter = ConsoleReporter ( ) benchmarks = sorted ( self . _find_benchmarks ( ) ) reporter . write_titles ( map ( self . _function_name_to_title , benchmarks ) ) for value in self . input ( ) : results = [ ] for b in benchmarks : method = getattr ( self , b ) arg_... | This should generally not be overloaded . Runs the benchmark functions that are found in the child class . |
31,121 | def _find_benchmarks ( self ) : def is_bench_method ( attrname , prefix = "bench" ) : return attrname . startswith ( prefix ) and hasattr ( getattr ( self . __class__ , attrname ) , '__call__' ) return list ( filter ( is_bench_method , dir ( self . __class__ ) ) ) | Return a suite of all tests cases contained in testCaseClass |
31,122 | def send ( self , body , req_type , seq_no = 1 ) : header = TACACSHeader ( self . version , req_type , self . session_id , len ( body . packed ) , seq_no = seq_no ) packet = TACACSPacket ( header , body . packed , self . secret ) logger . debug ( '\n' . join ( [ body . __class__ . __name__ , 'sent header <%s>' % header... | Send a TACACS + message body |
31,123 | def authenticate ( self , username , password , priv_lvl = TAC_PLUS_PRIV_LVL_MIN , authen_type = TAC_PLUS_AUTHEN_TYPE_ASCII , chap_ppp_id = None , chap_challenge = None , rem_addr = TAC_PLUS_VIRTUAL_REM_ADDR , port = TAC_PLUS_VIRTUAL_PORT ) : start_data = six . b ( '' ) if authen_type in ( TAC_PLUS_AUTHEN_TYPE_PAP , TA... | Authenticate to a TACACS + server with a username and password . |
31,124 | def authorize ( self , username , arguments = [ ] , authen_type = TAC_PLUS_AUTHEN_TYPE_ASCII , priv_lvl = TAC_PLUS_PRIV_LVL_MIN , rem_addr = TAC_PLUS_VIRTUAL_REM_ADDR , port = TAC_PLUS_VIRTUAL_PORT ) : with self . closing ( ) : packet = self . send ( TACACSAuthorizationStart ( username , TAC_PLUS_AUTHEN_METH_TACACSPLUS... | Authorize with a TACACS + server . |
31,125 | def account ( self , username , flags , arguments = [ ] , authen_type = TAC_PLUS_AUTHEN_TYPE_ASCII , priv_lvl = TAC_PLUS_PRIV_LVL_MIN , rem_addr = TAC_PLUS_VIRTUAL_REM_ADDR , port = TAC_PLUS_VIRTUAL_PORT ) : with self . closing ( ) : packet = self . send ( TACACSAccountingStart ( username , flags , TAC_PLUS_AUTHEN_METH... | Account with a TACACS + server . |
31,126 | def __get_user_env_vars ( self ) : return ( os . environ . get ( self . GP_URL_ENV_VAR ) , os . environ . get ( self . GP_INSTANCE_ID_ENV_VAR ) , os . environ . get ( self . GP_USER_ID_ENV_VAR ) , os . environ . get ( self . GP_PASSWORD_ENV_VAR ) , os . environ . get ( self . GP_IAM_API_KEY_ENV_VAR ) ) | Return the user defined environment variables |
31,127 | def __parse_vcap_services_env_var ( self , serviceInstanceName = None ) : vcapServices = os . environ . get ( self . __VCAP_SERVICES_ENV_VAR ) if not vcapServices : return ( None , None , None , None , None ) parsedVcapServices = json . loads ( vcapServices ) gpServicesInstances = [ ] for serviceName in parsedVcapServi... | Parse the VCAP_SERVICES env var and search for the necessary values |
31,128 | def __prepare_gprest_call ( self , requestURL , params = None , headers = None , restType = 'GET' , body = None ) : if self . __serviceAccount . is_iam_enabled ( ) : auth = None iam_api_key_header = { self . __AUTHORIZATION_HEADER_KEY : str ( 'API-KEY ' + self . __serviceAccount . get_api_key ( ) ) } if not headers is ... | Returns Authorization type and GP headers |
31,129 | def __process_gprest_response ( self , r = None , restType = 'GET' ) : if r is None : logging . info ( 'No response for REST ' + restType + ' request' ) return None httpStatus = r . status_code logging . info ( 'HTTP status code: %s' , httpStatus ) if httpStatus == requests . codes . ok or httpStatus == requests . code... | Returns the processed response for rest calls |
31,130 | def __perform_rest_call ( self , requestURL , params = None , headers = None , restType = 'GET' , body = None ) : auth , headers = self . __prepare_gprest_call ( requestURL , params = params , headers = headers , restType = restType , body = body ) if restType == 'GET' : r = requests . get ( requestURL , auth = auth , ... | Returns the JSON representation of the response if the response status was ok returns None otherwise . |
31,131 | def createReaderUser ( self , accessibleBundles = None ) : url = self . __serviceAccount . get_url ( ) + '/' + self . __serviceAccount . get_instance_id ( ) + '/v2/users/new' headers = { 'content-type' : 'application/json' } data = { } data [ 'type' ] = 'READER' if accessibleBundles is not None : data [ 'bundles' ] = a... | Creates a new reader user with access to the specified bundle Ids |
31,132 | def __has_language ( self , bundleId , languageId ) : return True if self . __get_language_data ( bundleId = bundleId , languageId = languageId ) else False | Returns True if the bundle has the language False otherwise |
31,133 | def __get_keys_map ( self , bundleId , languageId , fallback = False ) : return self . __get_language_data ( bundleId = bundleId , languageId = languageId , fallback = fallback ) | Returns key - value pairs for the specified language . If fallback is True source language value is used if translated value is not available . |
31,134 | def __get_value ( self , bundleId , languageId , resourceKey , fallback = False ) : resourceEntryData = self . __get_resource_entry_data ( bundleId = bundleId , languageId = languageId , resourceKey = resourceKey , fallback = fallback ) if not resourceEntryData : return None value = resourceEntryData . get ( self . __R... | Returns the value for the key . If fallback is True source language value is used if translated value is not available . If the key is not found returns None . |
31,135 | def get_avaliable_languages ( self , bundleId ) : bundleData = self . __get_bundle_data ( bundleId ) if not bundleData : return [ ] sourceLanguage = bundleData . get ( self . __RESPONSE_SRC_LANGUAGE_KEY ) languages = bundleData . get ( self . __RESPONSE_TARGET_LANGUAGES_KEY ) languages . append ( sourceLanguage ) retur... | Returns a list of avaliable languages in the bundle |
31,136 | def create_bundle ( self , bundleId , data = None ) : headers = { 'content-type' : 'application/json' } url = self . __get_base_bundle_url ( ) + "/" + bundleId if data is None : data = { } data [ 'sourceLanguage' ] = 'en' data [ 'targetLanguages' ] = [ ] data [ 'notes' ] = [ ] data [ 'metadata' ] = { } data [ 'partner'... | Creates a bundle using Globalization Pipeline service |
31,137 | def update_resource_entry ( self , bundleId , languageId , resourceKey , data = None ) : headers = { 'content-type' : 'application/json' } url = self . __get_base_bundle_url ( ) + "/" + bundleId + "/" + languageId + "/" + resourceKey json_data = { } if not data is None : json_data = json . dumps ( data ) response = sel... | Updates the resource entry for a particular key in a target language for a specific bundle in the globalization pipeline |
31,138 | def __get_return_value ( self , messageKey , value ) : if value : return value else : if self . _fallback : return self . _fallback . gettext ( messageKey ) else : return messageKey | Determines the return value ; used to prevent code duplication |
31,139 | def _find_library_candidates ( library_names , library_file_extensions , library_search_paths ) : candidates = set ( ) for library_name in library_names : for search_path in library_search_paths : glob_query = os . path . join ( search_path , '*' + library_name + '*' ) for filename in glob . iglob ( glob_query ) : file... | Finds and returns filenames which might be the library you are looking for . |
31,140 | def _load_library ( library_names , library_file_extensions , library_search_paths , version_check_callback ) : candidates = _find_library_candidates ( library_names , library_file_extensions , library_search_paths ) library_versions = [ ] for filename in candidates : version = version_check_callback ( filename ) if ve... | Finds loads and returns the most recent version of the library . |
31,141 | def _get_library_search_paths ( ) : search_paths = [ '' , '/usr/lib64' , '/usr/local/lib64' , '/usr/lib' , '/usr/local/lib' , '/run/current-system/sw/lib' , '/usr/lib/x86_64-linux-gnu/' , os . path . abspath ( os . path . dirname ( __file__ ) ) ] if sys . platform == 'darwin' : path_environment_variable = 'DYLD_LIBRARY... | Returns a list of library search paths considering of the current working directory default paths and paths from environment variables . |
31,142 | def _prepare_errcheck ( ) : def errcheck ( result , * args ) : global _exc_info_from_callback if _exc_info_from_callback is not None : exc = _exc_info_from_callback _exc_info_from_callback = None _reraise ( exc [ 1 ] , exc [ 2 ] ) return result for symbol in dir ( _glfw ) : if symbol . startswith ( 'glfw' ) : getattr (... | This function sets the errcheck attribute of all ctypes wrapped functions to evaluate the _exc_info_from_callback global variable and re - raise any exceptions that might have been raised in callbacks . It also modifies all callback types to automatically wrap the function using the _callback_exception_decorator . |
31,143 | def init ( ) : cwd = _getcwd ( ) res = _glfw . glfwInit ( ) os . chdir ( cwd ) return res | Initializes the GLFW library . |
31,144 | def terminate ( ) : for callback_repository in _callback_repositories : for window_addr in list ( callback_repository . keys ( ) ) : del callback_repository [ window_addr ] for window_addr in list ( _window_user_data_repository . keys ( ) ) : del _window_user_data_repository [ window_addr ] _glfw . glfwTerminate ( ) | Terminates the GLFW library . |
31,145 | def get_version ( ) : major_value = ctypes . c_int ( 0 ) major = ctypes . pointer ( major_value ) minor_value = ctypes . c_int ( 0 ) minor = ctypes . pointer ( minor_value ) rev_value = ctypes . c_int ( 0 ) rev = ctypes . pointer ( rev_value ) _glfw . glfwGetVersion ( major , minor , rev ) return major_value . value , ... | Retrieves the version of the GLFW library . |
31,146 | def _raise_glfw_errors_as_exceptions ( error_code , description ) : global ERROR_REPORTING if ERROR_REPORTING : message = "(%d) %s" % ( error_code , description ) raise GLFWError ( message ) | Default error callback that raises GLFWError exceptions for glfw errors . Set an alternative error callback or set glfw . ERROR_REPORTING to False to disable this behavior . |
31,147 | def get_monitors ( ) : count_value = ctypes . c_int ( 0 ) count = ctypes . pointer ( count_value ) result = _glfw . glfwGetMonitors ( count ) monitors = [ result [ i ] for i in range ( count_value . value ) ] return monitors | Returns the currently connected monitors . |
31,148 | def get_monitor_pos ( monitor ) : xpos_value = ctypes . c_int ( 0 ) xpos = ctypes . pointer ( xpos_value ) ypos_value = ctypes . c_int ( 0 ) ypos = ctypes . pointer ( ypos_value ) _glfw . glfwGetMonitorPos ( monitor , xpos , ypos ) return xpos_value . value , ypos_value . value | Returns the position of the monitor s viewport on the virtual screen . |
31,149 | def get_monitor_physical_size ( monitor ) : width_value = ctypes . c_int ( 0 ) width = ctypes . pointer ( width_value ) height_value = ctypes . c_int ( 0 ) height = ctypes . pointer ( height_value ) _glfw . glfwGetMonitorPhysicalSize ( monitor , width , height ) return width_value . value , height_value . value | Returns the physical size of the monitor . |
31,150 | def set_monitor_callback ( cbfun ) : global _monitor_callback previous_callback = _monitor_callback if cbfun is None : cbfun = 0 c_cbfun = _GLFWmonitorfun ( cbfun ) _monitor_callback = ( cbfun , c_cbfun ) cbfun = c_cbfun _glfw . glfwSetMonitorCallback ( cbfun ) if previous_callback is not None and previous_callback [ 0... | Sets the monitor configuration callback . |
31,151 | def get_video_modes ( monitor ) : count_value = ctypes . c_int ( 0 ) count = ctypes . pointer ( count_value ) result = _glfw . glfwGetVideoModes ( monitor , count ) videomodes = [ result [ i ] . unwrap ( ) for i in range ( count_value . value ) ] return videomodes | Returns the available video modes for the specified monitor . |
31,152 | def set_gamma_ramp ( monitor , ramp ) : gammaramp = _GLFWgammaramp ( ) gammaramp . wrap ( ramp ) _glfw . glfwSetGammaRamp ( monitor , ctypes . pointer ( gammaramp ) ) | Sets the current gamma ramp for the specified monitor . |
31,153 | def create_window ( width , height , title , monitor , share ) : return _glfw . glfwCreateWindow ( width , height , _to_char_p ( title ) , monitor , share ) | Creates a window and its associated context . |
31,154 | def get_window_pos ( window ) : xpos_value = ctypes . c_int ( 0 ) xpos = ctypes . pointer ( xpos_value ) ypos_value = ctypes . c_int ( 0 ) ypos = ctypes . pointer ( ypos_value ) _glfw . glfwGetWindowPos ( window , xpos , ypos ) return xpos_value . value , ypos_value . value | Retrieves the position of the client area of the specified window . |
31,155 | def get_window_size ( window ) : width_value = ctypes . c_int ( 0 ) width = ctypes . pointer ( width_value ) height_value = ctypes . c_int ( 0 ) height = ctypes . pointer ( height_value ) _glfw . glfwGetWindowSize ( window , width , height ) return width_value . value , height_value . value | Retrieves the size of the client area of the specified window . |
31,156 | def get_framebuffer_size ( window ) : width_value = ctypes . c_int ( 0 ) width = ctypes . pointer ( width_value ) height_value = ctypes . c_int ( 0 ) height = ctypes . pointer ( height_value ) _glfw . glfwGetFramebufferSize ( window , width , height ) return width_value . value , height_value . value | Retrieves the size of the framebuffer of the specified window . |
31,157 | def set_window_user_pointer ( window , pointer ) : data = ( False , pointer ) if not isinstance ( pointer , ctypes . c_void_p ) : data = ( True , pointer ) pointer = ctypes . cast ( ctypes . pointer ( ctypes . py_object ( pointer ) ) , ctypes . c_void_p ) window_addr = ctypes . cast ( ctypes . pointer ( window ) , ctyp... | Sets the user pointer of the specified window . You may pass a normal python object into this function and it will be wrapped automatically . The object will be kept in existence until the pointer is set to something else or until the window is destroyed . |
31,158 | def get_window_user_pointer ( window ) : window_addr = ctypes . cast ( ctypes . pointer ( window ) , ctypes . POINTER ( ctypes . c_long ) ) . contents . value if window_addr in _window_user_data_repository : data = _window_user_data_repository [ window_addr ] is_wrapped_py_object = data [ 0 ] if is_wrapped_py_object : ... | Returns the user pointer of the specified window . |
31,159 | def set_window_pos_callback ( window , cbfun ) : window_addr = ctypes . cast ( ctypes . pointer ( window ) , ctypes . POINTER ( ctypes . c_long ) ) . contents . value if window_addr in _window_pos_callback_repository : previous_callback = _window_pos_callback_repository [ window_addr ] else : previous_callback = None i... | Sets the position callback for the specified window . |
31,160 | def set_window_size_callback ( window , cbfun ) : window_addr = ctypes . cast ( ctypes . pointer ( window ) , ctypes . POINTER ( ctypes . c_long ) ) . contents . value if window_addr in _window_size_callback_repository : previous_callback = _window_size_callback_repository [ window_addr ] else : previous_callback = Non... | Sets the size callback for the specified window . |
31,161 | def set_window_close_callback ( window , cbfun ) : window_addr = ctypes . cast ( ctypes . pointer ( window ) , ctypes . POINTER ( ctypes . c_long ) ) . contents . value if window_addr in _window_close_callback_repository : previous_callback = _window_close_callback_repository [ window_addr ] else : previous_callback = ... | Sets the close callback for the specified window . |
31,162 | def set_window_refresh_callback ( window , cbfun ) : window_addr = ctypes . cast ( ctypes . pointer ( window ) , ctypes . POINTER ( ctypes . c_long ) ) . contents . value if window_addr in _window_refresh_callback_repository : previous_callback = _window_refresh_callback_repository [ window_addr ] else : previous_callb... | Sets the refresh callback for the specified window . |
31,163 | def set_window_focus_callback ( window , cbfun ) : window_addr = ctypes . cast ( ctypes . pointer ( window ) , ctypes . POINTER ( ctypes . c_long ) ) . contents . value if window_addr in _window_focus_callback_repository : previous_callback = _window_focus_callback_repository [ window_addr ] else : previous_callback = ... | Sets the focus callback for the specified window . |
31,164 | def set_window_iconify_callback ( window , cbfun ) : window_addr = ctypes . cast ( ctypes . pointer ( window ) , ctypes . POINTER ( ctypes . c_long ) ) . contents . value if window_addr in _window_iconify_callback_repository : previous_callback = _window_iconify_callback_repository [ window_addr ] else : previous_callb... | Sets the iconify callback for the specified window . |
31,165 | def set_framebuffer_size_callback ( window , cbfun ) : window_addr = ctypes . cast ( ctypes . pointer ( window ) , ctypes . POINTER ( ctypes . c_long ) ) . contents . value if window_addr in _framebuffer_size_callback_repository : previous_callback = _framebuffer_size_callback_repository [ window_addr ] else : previous... | Sets the framebuffer resize callback for the specified window . |
31,166 | def get_cursor_pos ( window ) : xpos_value = ctypes . c_double ( 0.0 ) xpos = ctypes . pointer ( xpos_value ) ypos_value = ctypes . c_double ( 0.0 ) ypos = ctypes . pointer ( ypos_value ) _glfw . glfwGetCursorPos ( window , xpos , ypos ) return xpos_value . value , ypos_value . value | Retrieves the last reported cursor position relative to the client area of the window . |
31,167 | def set_key_callback ( window , cbfun ) : window_addr = ctypes . cast ( ctypes . pointer ( window ) , ctypes . POINTER ( ctypes . c_long ) ) . contents . value if window_addr in _key_callback_repository : previous_callback = _key_callback_repository [ window_addr ] else : previous_callback = None if cbfun is None : cbf... | Sets the key callback . |
31,168 | def set_char_callback ( window , cbfun ) : window_addr = ctypes . cast ( ctypes . pointer ( window ) , ctypes . POINTER ( ctypes . c_long ) ) . contents . value if window_addr in _char_callback_repository : previous_callback = _char_callback_repository [ window_addr ] else : previous_callback = None if cbfun is None : ... | Sets the Unicode character callback . |
31,169 | def set_mouse_button_callback ( window , cbfun ) : window_addr = ctypes . cast ( ctypes . pointer ( window ) , ctypes . POINTER ( ctypes . c_long ) ) . contents . value if window_addr in _mouse_button_callback_repository : previous_callback = _mouse_button_callback_repository [ window_addr ] else : previous_callback = ... | Sets the mouse button callback . |
31,170 | def set_cursor_pos_callback ( window , cbfun ) : window_addr = ctypes . cast ( ctypes . pointer ( window ) , ctypes . POINTER ( ctypes . c_long ) ) . contents . value if window_addr in _cursor_pos_callback_repository : previous_callback = _cursor_pos_callback_repository [ window_addr ] else : previous_callback = None i... | Sets the cursor position callback . |
31,171 | def set_scroll_callback ( window , cbfun ) : window_addr = ctypes . cast ( ctypes . pointer ( window ) , ctypes . POINTER ( ctypes . c_long ) ) . contents . value if window_addr in _scroll_callback_repository : previous_callback = _scroll_callback_repository [ window_addr ] else : previous_callback = None if cbfun is N... | Sets the scroll callback . |
31,172 | def get_joystick_axes ( joy ) : count_value = ctypes . c_int ( 0 ) count = ctypes . pointer ( count_value ) result = _glfw . glfwGetJoystickAxes ( joy , count ) return result , count_value . value | Returns the values of all axes of the specified joystick . |
31,173 | def get_joystick_buttons ( joy ) : count_value = ctypes . c_int ( 0 ) count = ctypes . pointer ( count_value ) result = _glfw . glfwGetJoystickButtons ( joy , count ) return result , count_value . value | Returns the state of all buttons of the specified joystick . |
31,174 | def unwrap ( self ) : size = self . Size ( self . width , self . height ) bits = self . Bits ( self . red_bits , self . green_bits , self . blue_bits ) return self . GLFWvidmode ( size , bits , self . refresh_rate ) | Returns a GLFWvidmode object . |
31,175 | def unwrap ( self ) : red = [ self . red [ i ] for i in range ( self . size ) ] green = [ self . green [ i ] for i in range ( self . size ) ] blue = [ self . blue [ i ] for i in range ( self . size ) ] if NORMALIZE_GAMMA_RAMPS : red = [ value / 65535.0 for value in red ] green = [ value / 65535.0 for value in green ] b... | Returns a GLFWgammaramp object . |
31,176 | def unwrap ( self ) : pixels = [ [ [ int ( c ) for c in p ] for p in l ] for l in self . pixels_array ] return self . GLFWimage ( self . width , self . height , pixels ) | Returns a GLFWimage object . |
31,177 | def stream_data ( self , host = HOST , port = GPSD_PORT , enable = True , gpsd_protocol = PROTOCOL , devicepath = None ) : self . socket . connect ( host , port ) self . socket . watch ( enable , gpsd_protocol , devicepath ) | Connect and command point and shoot flail and bail |
31,178 | def unpack_data ( self , usnap = .2 ) : for new_data in self . socket : if new_data : self . data_stream . unpack ( new_data ) else : sleep ( usnap ) | Iterates over socket response and unpacks values of object attributes . Sleeping here has the greatest response to cpu cycles short of blocking sockets |
31,179 | def run_thread ( self , usnap = .2 , daemon = True ) : try : gps3_data_thread = Thread ( target = self . unpack_data , args = { usnap : usnap } , daemon = daemon ) except TypeError : gps3_data_thread = Thread ( target = self . unpack_data , args = { usnap : usnap } ) gps3_data_thread . setDaemon ( daemon ) gps3_data_th... | run thread with data |
31,180 | def add_args ( ) : parser = argparse . ArgumentParser ( ) parser . add_argument ( '-host' , action = 'store' , dest = 'host' , default = '127.0.0.1' , help = 'DEFAULT "127.0.0.1"' ) parser . add_argument ( '-port' , action = 'store' , dest = 'port' , default = '2947' , help = 'DEFAULT 2947' , type = int ) parser . add_... | Adds commandline arguments and formatted Help |
31,181 | def make_time ( gps_datetime_str ) : if not 'n/a' == gps_datetime_str : datetime_string = gps_datetime_str datetime_object = datetime . strptime ( datetime_string , "%Y-%m-%dT%H:%M:%S" ) return datetime_object | Makes datetime object from string object |
31,182 | def elapsed_time_from ( start_time ) : time_then = make_time ( start_time ) time_now = datetime . utcnow ( ) . replace ( microsecond = 0 ) if time_then is None : return delta_t = time_now - time_then return delta_t | calculate time delta from latched time and current time |
31,183 | def unit_conversion ( thing , units , length = False ) : if 'n/a' == thing : return 'n/a' try : thing = round ( thing * CONVERSION [ units ] [ 0 + length ] , 2 ) except TypeError : thing = 'fubar' return thing , CONVERSION [ units ] [ 2 + length ] | converts base data between metric imperial or nautical units |
31,184 | def shut_down ( ) : curses . nocbreak ( ) curses . echo ( ) curses . endwin ( ) gpsd_socket . close ( ) print ( 'Keyboard interrupt received\nTerminated by user\nGood Bye.\n' ) sys . exit ( 1 ) | Closes connection and restores terminal |
31,185 | def close ( self ) : if self . streamSock : self . watch ( enable = False ) self . streamSock . close ( ) self . streamSock = None | turn off stream and close socket |
31,186 | def show_nmea ( ) : data_window = curses . newwin ( 24 , 79 , 0 , 0 ) for new_data in gpsd_socket : if new_data : screen . nodelay ( 1 ) key_press = screen . getch ( ) if key_press == ord ( 'q' ) : shut_down ( ) elif key_press == ord ( 'j' ) : gpsd_socket . watch ( enable = False , gpsd_protocol = 'nmea' ) gpsd_socket ... | NMEA output in curses terminal |
31,187 | def register_widget ( widget ) : if widget in registry : raise WidgetAlreadyRegistered ( _ ( 'The widget %s has already been registered.' ) % widget . __name__ ) registry . append ( widget ) | Register the given widget as a candidate to use in placeholder . |
31,188 | def get_widget ( name ) : for widget in registry : if widget . __name__ == name : return widget raise WidgetNotFound ( _ ( 'The widget %s has not been registered.' ) % name ) | Give back a widget class according to his name . |
31,189 | def get_setting ( * args , ** kwargs ) : for name in args : if hasattr ( settings , name ) : return getattr ( settings , name ) if kwargs . get ( 'raise_error' , False ) : setting_url = url % args [ 0 ] . lower ( ) . replace ( '_' , '-' ) raise ImproperlyConfigured ( 'Please make sure you specified at ' 'least one of t... | Get a setting and raise an appropriate user friendly error if the setting is not found . |
31,190 | def get_page_templates ( ) : PAGE_TEMPLATES = get_setting ( 'PAGE_TEMPLATES' , default_value = ( ) ) if isinstance ( PAGE_TEMPLATES , collections . Callable ) : return PAGE_TEMPLATES ( ) else : return PAGE_TEMPLATES | The callable that is used by the CMS . |
31,191 | def change_status ( request , page_id ) : perm = request . user . has_perm ( 'pages.change_page' ) if perm and request . method == 'POST' : page = Page . objects . get ( pk = page_id ) page . status = int ( request . POST [ 'status' ] ) page . invalidate ( ) page . save ( ) return HttpResponse ( str ( page . status ) )... | Switch the status of a page . |
31,192 | def get_last_content ( request , page_id ) : content_type = request . GET . get ( 'content_type' ) language_id = request . GET . get ( 'language_id' ) page = get_object_or_404 ( Page , pk = page_id ) placeholders = get_placeholders ( page . get_template ( ) ) _template = template . loader . get_template ( page . get_te... | Get the latest content for a particular type |
31,193 | def traduction ( request , page_id , language_id ) : page = Page . objects . get ( pk = page_id ) lang = language_id placeholders = get_placeholders ( page . get_template ( ) ) language_error = ( Content . objects . get_content ( page , language_id , "title" ) is None ) return render ( request , 'pages/traduction_helpe... | Traduction helper . |
31,194 | def get_content ( request , page_id , content_id ) : content = Content . objects . get ( pk = content_id ) return HttpResponse ( content . body ) | Get the content for a particular page |
31,195 | def get_media_url ( request , media_id ) : media = Media . objects . get ( id = media_id ) return HttpResponse ( media . url . name ) | Get media URL . |
31,196 | def media ( request ) : return { 'PAGES_MEDIA_URL' : settings . PAGES_MEDIA_URL , 'PAGES_STATIC_URL' : settings . PAGES_STATIC_URL , 'PAGE_USE_SITE_ID' : settings . PAGE_USE_SITE_ID , 'PAGE_HIDE_SITES' : settings . PAGE_HIDE_SITES , 'PAGE_LANGUAGES' : settings . PAGE_LANGUAGES , } | Adds media - related variables to the context . |
31,197 | def normalize_url ( url ) : if not url or len ( url ) == 0 : return '/' if not url . startswith ( '/' ) : url = '/' + url if len ( url ) > 1 and url . endswith ( '/' ) : url = url [ 0 : len ( url ) - 1 ] return url | Return a normalized url with trailing and without leading slash . |
31,198 | def page_templates_loading_check ( app_configs , ** kwargs ) : errors = [ ] for page_template in settings . get_page_templates ( ) : try : loader . get_template ( page_template [ 0 ] ) except template . TemplateDoesNotExist : errors . append ( checks . Warning ( 'Django cannot find template %s' % page_template [ 0 ] , ... | Check if any page template can t be loaded . |
31,199 | def _get_content ( context , page , content_type , lang , fallback = True ) : if not page : return '' if not lang and 'lang' in context : lang = context . get ( 'lang' , pages_settings . PAGE_DEFAULT_LANGUAGE ) page = get_page_from_string_or_id ( page , lang ) if not page : return '' content = Content . objects . get_c... | Helper function used by PlaceholderNode . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.