idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
13,900
def master_for ( self , service_name , redis_class = StrictRedis , connection_pool_class = SentinelConnectionPool , ** kwargs ) : kwargs [ 'is_master' ] = True connection_kwargs = dict ( self . connection_kwargs ) connection_kwargs . update ( kwargs ) return redis_class ( connection_pool = connection_pool_class ( service_name , self , ** connection_kwargs ) )
Returns a redis client instance for the service_name master .
13,901
async def extend ( self , additional_time ) : if self . local . token is None : raise LockError ( "Cannot extend an unlocked lock" ) if self . timeout is None : raise LockError ( "Cannot extend a lock with no timeout" ) return await self . do_extend ( additional_time )
Adds more time to an already acquired lock .
13,902
async def cluster_delslots ( self , * slots ) : cluster_nodes = self . _nodes_slots_to_slots_nodes ( await self . cluster_nodes ( ) ) res = list ( ) for slot in slots : res . append ( await self . execute_command ( 'CLUSTER DELSLOTS' , slot , node_id = cluster_nodes [ slot ] ) ) return res
Set hash slots as unbound in the cluster . It determines by it self what node the slot is in and sends it there
13,903
async def cluster_failover ( self , node_id , option ) : if not isinstance ( option , str ) or option . upper ( ) not in { 'FORCE' , 'TAKEOVER' } : raise ClusterError ( 'Wrong option provided' ) return await self . execute_command ( 'CLUSTER FAILOVER' , option , node_id = node_id )
Forces a slave to perform a manual failover of its master
13,904
async def cluster_reset ( self , node_id , soft = True ) : option = 'SOFT' if soft else 'HARD' return await self . execute_command ( 'CLUSTER RESET' , option , node_id = node_id )
Reset a Redis Cluster node
13,905
async def cluster_reset_all_nodes ( self , soft = True ) : option = 'SOFT' if soft else 'HARD' res = list ( ) for node in await self . cluster_nodes ( ) : res . append ( await self . execute_command ( 'CLUSTER RESET' , option , node_id = node [ 'id' ] ) ) return res
Send CLUSTER RESET to all nodes in the cluster
13,906
async def cluster_setslot ( self , node_id , slot_id , state ) : if state . upper ( ) in { 'IMPORTING' , 'MIGRATING' , 'NODE' } and node_id is not None : return await self . execute_command ( 'CLUSTER SETSLOT' , slot_id , state , node_id ) elif state . upper ( ) == 'STABLE' : return await self . execute_command ( 'CLUSTER SETSLOT' , slot_id , 'STABLE' ) else : raise RedisError ( 'Invalid slot state: {0}' . format ( state ) )
Bind an hash slot to a specific node
13,907
async def execute ( self , keys = [ ] , args = [ ] , client = None ) : "Execute the script, passing any required ``args``" if client is None : client = self . registered_client args = tuple ( keys ) + tuple ( args ) if isinstance ( client , BasePipeline ) : client . scripts . add ( self ) try : return await client . evalsha ( self . sha , len ( keys ) , * args ) except NoScriptError : self . sha = await client . script_load ( self . script ) return await client . evalsha ( self . sha , len ( keys ) , * args )
Execute the script passing any required args
13,908
def _random_id ( self , size = 16 , chars = string . ascii_uppercase + string . digits ) : return '' . join ( random . choice ( chars ) for _ in range ( size ) )
Generates a random id based on size and chars variable .
13,909
async def sentinel_monitor ( self , name , ip , port , quorum ) : "Add a new master to Sentinel to be monitored" return await self . execute_command ( 'SENTINEL MONITOR' , name , ip , port , quorum )
Add a new master to Sentinel to be monitored
13,910
async def sentinel_set ( self , name , option , value ) : "Set Sentinel monitoring parameters for a given master" return await self . execute_command ( 'SENTINEL SET' , name , option , value )
Set Sentinel monitoring parameters for a given master
13,911
async def sdiff ( self , keys , * args ) : "Return the difference of sets specified by ``keys``" args = list_or_args ( keys , args ) return await self . execute_command ( 'SDIFF' , * args )
Return the difference of sets specified by keys
13,912
async def spop ( self , name , count = None ) : if count and isinstance ( count , int ) : return await self . execute_command ( 'SPOP' , name , count ) else : return await self . execute_command ( 'SPOP' , name )
Remove and return a random member of set name count should be type of int and default set to 1 . If count is supplied pops a list of count random + members of set name
13,913
async def srandmember ( self , name , number = None ) : args = number and [ number ] or [ ] return await self . execute_command ( 'SRANDMEMBER' , name , * args )
If number is None returns a random member of set name .
13,914
async def sunion ( self , keys , * args ) : "Return the union of sets specified by ``keys``" args = list_or_args ( keys , args ) return await self . execute_command ( 'SUNION' , * args )
Return the union of sets specified by keys
13,915
async def sdiffstore ( self , dest , keys , * args ) : res = await self . sdiff ( keys , * args ) await self . delete ( dest ) if not res : return 0 return await self . sadd ( dest , * res )
Store the difference of sets specified by keys into a new set named dest . Returns the number of keys in the new set . Overwrites dest key if it exists .
13,916
async def execute_command ( self , * args , ** kwargs ) : if not self . connection_pool . initialized : await self . connection_pool . initialize ( ) if not args : raise RedisClusterException ( "Unable to determine command to use" ) command = args [ 0 ] node = self . determine_node ( * args , ** kwargs ) if node : return await self . execute_command_on_nodes ( node , * args , ** kwargs ) if self . refresh_table_asap : await self . connection_pool . nodes . initialize ( ) self . refresh_table_asap = False redirect_addr = None asking = False try_random_node = False slot = self . _determine_slot ( * args ) ttl = int ( self . RedisClusterRequestTTL ) while ttl > 0 : ttl -= 1 if asking : node = self . connection_pool . nodes . nodes [ redirect_addr ] r = self . connection_pool . get_connection_by_node ( node ) elif try_random_node : r = self . connection_pool . get_random_connection ( ) try_random_node = False else : if self . refresh_table_asap : node = self . connection_pool . get_master_node_by_slot ( slot ) else : node = self . connection_pool . get_node_by_slot ( slot ) r = self . connection_pool . get_connection_by_node ( node ) try : if asking : await r . send_command ( 'ASKING' ) await self . parse_response ( r , "ASKING" , ** kwargs ) asking = False await r . send_command ( * args ) return await self . parse_response ( r , command , ** kwargs ) except ( RedisClusterException , BusyLoadingError ) : raise except ( CancelledError , ConnectionError , TimeoutError ) : try_random_node = True if ttl < self . RedisClusterRequestTTL / 2 : await asyncio . sleep ( 0.1 ) except ClusterDownError as e : self . connection_pool . disconnect ( ) self . connection_pool . reset ( ) self . refresh_table_asap = True raise e except MovedError as e : self . refresh_table_asap = True await self . connection_pool . nodes . increment_reinitialize_counter ( ) node = self . connection_pool . nodes . set_node ( e . host , e . port , server_type = 'master' ) self . connection_pool . nodes . slots [ e . slot_id ] [ 0 ] = node except TryAgainError as e : if ttl < self . RedisClusterRequestTTL / 2 : await asyncio . sleep ( 0.05 ) except AskError as e : redirect_addr , asking = "{0}:{1}" . format ( e . host , e . port ) , True finally : self . connection_pool . release ( r ) raise ClusterError ( 'TTL exhausted.' )
Send a command to a node in the cluster
13,917
def on_connect ( self , connection ) : "Called when the stream connects" self . _stream = connection . _reader self . _buffer = SocketBuffer ( self . _stream , self . _read_size ) if connection . decode_responses : self . encoding = connection . encoding
Called when the stream connects
13,918
def on_disconnect ( self ) : "Called when the stream disconnects" if self . _stream is not None : self . _stream = None if self . _buffer is not None : self . _buffer . close ( ) self . _buffer = None self . encoding = None
Called when the stream disconnects
13,919
async def can_read ( self ) : "See if there's data that can be read." if not ( self . _reader and self . _writer ) : await self . connect ( ) return self . _parser . can_read ( )
See if there s data that can be read .
13,920
def pack_commands ( self , commands ) : "Pack multiple commands into the Redis protocol" output = [ ] pieces = [ ] buffer_length = 0 for cmd in commands : for chunk in self . pack_command ( * cmd ) : pieces . append ( chunk ) buffer_length += len ( chunk ) if buffer_length > 6000 : output . append ( SYM_EMPTY . join ( pieces ) ) buffer_length = 0 pieces = [ ] if pieces : output . append ( SYM_EMPTY . join ( pieces ) ) return output
Pack multiple commands into the Redis protocol
13,921
async def on_connect ( self ) : if self . db : warnings . warn ( 'SELECT DB is not allowed in cluster mode' ) self . db = '' await super ( ClusterConnection , self ) . on_connect ( ) if self . readonly : await self . send_command ( 'READONLY' ) if nativestr ( await self . read_response ( ) ) != 'OK' : raise ConnectionError ( 'READONLY command failed' )
Initialize the connection authenticate and select a database and send READONLY if it is set during object initialization .
13,922
def add_schema ( self , schema ) : if isinstance ( schema , SchemaBuilder ) : schema_uri = schema . schema_uri schema = schema . to_schema ( ) if schema_uri is None : del schema [ '$schema' ] elif isinstance ( schema , SchemaNode ) : schema = schema . to_schema ( ) if '$schema' in schema : self . schema_uri = self . schema_uri or schema [ '$schema' ] schema = dict ( schema ) del schema [ '$schema' ] self . _root_node . add_schema ( schema )
Merge in a JSON schema . This can be a dict or another SchemaBuilder
13,923
def to_schema ( self ) : schema = self . _base_schema ( ) schema . update ( self . _root_node . to_schema ( ) ) return schema
Generate a schema based on previous inputs .
13,924
def to_json ( self , * args , ** kwargs ) : return json . dumps ( self . to_schema ( ) , * args , ** kwargs )
Generate a schema and convert it directly to serialized JSON .
13,925
def get_long_docs ( * filenames ) : docs = [ ] for filename in filenames : with open ( filename , 'r' ) as f : docs . append ( f . read ( ) ) return "\n\n" . join ( docs )
Build rst description from a set of files .
13,926
def add_schema ( self , schema ) : if isinstance ( schema , SchemaNode ) : schema = schema . to_schema ( ) for subschema in self . _get_subschemas ( schema ) : schema_generator = self . _get_generator_for_schema ( subschema ) schema_generator . add_schema ( subschema ) return self
Merges in an existing schema .
13,927
def add_object ( self , obj ) : schema_generator = self . _get_generator_for_object ( obj ) schema_generator . add_object ( obj ) return self
Modify the schema to accommodate an object .
13,928
def to_schema ( self ) : types = set ( ) generated_schemas = [ ] for schema_generator in self . _schema_generators : generated_schema = schema_generator . to_schema ( ) if len ( generated_schema ) == 1 and 'type' in generated_schema : types . add ( generated_schema [ 'type' ] ) else : generated_schemas . append ( generated_schema ) if types : if len ( types ) == 1 : ( types , ) = types else : types = sorted ( types ) generated_schemas = [ { 'type' : types } ] + generated_schemas if len ( generated_schemas ) == 1 : ( result_schema , ) = generated_schemas elif generated_schemas : result_schema = { 'anyOf' : generated_schemas } else : result_schema = { } return result_schema
Convert the current schema to a dict .
13,929
def hsts_header ( self ) : hsts_policy = 'max-age={0}' . format ( self . hsts_age ) if self . hsts_include_subdomains : hsts_policy += '; includeSubDomains' return hsts_policy
Returns the proper HSTS policy .
13,930
def skip ( self ) : if self . skip_list and isinstance ( self . skip_list , list ) : for skip in self . skip_list : if request . path . startswith ( '/{0}' . format ( skip ) ) : return True return False
Checks the skip list .
13,931
def redirect_to_ssl ( self ) : criteria = [ request . is_secure , current_app . debug , current_app . testing , request . headers . get ( 'X-Forwarded-Proto' , 'http' ) == 'https' ] if not any ( criteria ) and not self . skip : if request . url . startswith ( 'http://' ) : url = request . url . replace ( 'http://' , 'https://' , 1 ) code = 302 if self . permanent : code = 301 r = redirect ( url , code = code ) return r
Redirect incoming requests to HTTPS .
13,932
def set_hue ( self , hue , duration = 0 , rapid = False ) : color = self . get_color ( ) color2 = ( hue , color [ 1 ] , color [ 2 ] , color [ 3 ] ) try : if rapid : self . fire_and_forget ( LightSetColor , { "color" : color2 , "duration" : duration } , num_repeats = 1 ) else : self . req_with_ack ( LightSetColor , { "color" : color2 , "duration" : duration } ) except WorkflowException as e : raise
hue to set duration in ms
13,933
def set_saturation ( self , saturation , duration = 0 , rapid = False ) : color = self . get_color ( ) color2 = ( color [ 0 ] , saturation , color [ 2 ] , color [ 3 ] ) try : if rapid : self . fire_and_forget ( LightSetColor , { "color" : color2 , "duration" : duration } , num_repeats = 1 ) else : self . req_with_ack ( LightSetColor , { "color" : color2 , "duration" : duration } ) except WorkflowException as e : raise
saturation to set duration in ms
13,934
def set_brightness ( self , brightness , duration = 0 , rapid = False ) : color = self . get_color ( ) color2 = ( color [ 0 ] , color [ 1 ] , brightness , color [ 3 ] ) try : if rapid : self . fire_and_forget ( LightSetColor , { "color" : color2 , "duration" : duration } , num_repeats = 1 ) else : self . req_with_ack ( LightSetColor , { "color" : color2 , "duration" : duration } ) except WorkflowException as e : raise
brightness to set duration in ms
13,935
def _rotate ( edges , step ) : step = Step ( step ) result = set ( ) movement = { "U" : "RFLB" , "D" : "LFRB" , "R" : "FUBD" , "L" : "FDBU" , "F" : "URDL" , "B" : "ULDR" , } [ step . face ] movement = { movement [ i ] : movement [ ( i + step . is_clockwise + ( - 1 * step . is_counter_clockwise ) + ( 2 * step . is_180 ) ) % 4 ] for i in range ( 4 ) } for edge in edges : if step . face not in edge : result . add ( edge . copy ( ) ) else : k = ( set ( edge . facings . keys ( ) ) - { step . face } ) . pop ( ) new_edge = Edge ( ** { step . face : edge [ step . face ] , movement [ k ] : edge [ k ] , } ) result . add ( new_edge ) return result
Simulate the cube rotation by updating four edges .
13,936
def cross_successors ( state , last_action = None ) : centres , edges = state acts = sum ( [ [ s , s . inverse ( ) , s * 2 ] for s in map ( Step , "RUFDRB" . replace ( last_action . face if last_action else "" , "" , 1 ) ) ] , [ ] ) for step in acts : yield step , ( centres , CrossSolver . _rotate ( edges , step ) )
Successors function for solving the cross .
13,937
def cross_goal ( state ) : centres , edges = state for edge in edges : if "D" not in edge . facings : return False if edge [ "D" ] != centres [ "D" ] [ "D" ] : return False k = "" . join ( edge . facings . keys ( ) ) . replace ( "D" , "" ) if edge [ k ] != centres [ k ] [ k ] : return False return True
The goal function for cross solving search .
13,938
def solve ( self ) : result = Formula ( path_actions ( a_star_search ( ( { f : self . cube [ f ] for f in "LUFDRB" } , self . cube . select_type ( "edge" ) & self . cube . has_colour ( self . cube [ "D" ] . colour ) ) , self . cross_successors , self . cross_state_value , self . cross_goal , ) ) ) self . cube ( result ) return result
Solve the cross .
13,939
def is_solved ( self ) : return self . cross_goal ( ( { f : self . cube [ f ] for f in "LUFDRB" } , self . cube . select_type ( "edge" ) & self . cube . has_colour ( self . cube [ "D" ] . colour ) ) )
Check if the cross of Cube is solved .
13,940
def recognise ( self ) : result = "" for side in "LFRB" : for square in self . cube . get_face ( side ) [ 0 ] : for _side in "LFRB" : if square . colour == self . cube [ _side ] . colour : result += _side break return result
Recognise the PLL case of Cube .
13,941
def solve ( self ) : if not isinstance ( self . cube , Cube ) : raise ValueError ( "Use Solver.feed(cube) to feed the cube to solver." ) for i in range ( 4 ) : rec_id = self . recognise ( ) if rec_id in algo_dict : self . cube ( algo_dict [ rec_id ] ) return Formula ( ( Step ( "y" ) * i ) or [ ] ) + algo_dict [ rec_id ] self . cube ( Step ( "y" ) ) raise ValueError ( "Invalid cube." )
Solve PLL of Cube .
13,942
def is_solved ( self ) : for side in "LUFDRB" : sample = self . cube [ side ] . facings [ side ] for square in sum ( self . cube . get_face ( side ) , [ ] ) : if square != sample : return False return True
Check if Cube is solved .
13,943
def recognise ( self ) : if not isinstance ( self . cube , Cube ) : raise ValueError ( "Use Solver.feed(cube) to feed the cube to solver." ) result = "" for face in "LFRB" : for square in self . cube . get_face ( face ) [ 0 ] : result += str ( int ( square == self . cube [ "U" ] [ "U" ] ) ) if result not in algo_dict : raise ValueError ( "Invalid Cube, probably didn't solve F2L, or wrong input value.\nUse Solver.feed(cube) to reset the cube." ) self . case = result return result
Recognise which is Cube s OLL case .
13,944
def solve ( self ) : if not isinstance ( self . cube , Cube ) : raise ValueError ( "Use Solver.feed(cube) to feed the cube to solver." ) self . recognise ( ) self . cube ( algo_dict [ self . case ] ) return algo_dict [ self . case ]
Solve the OLL . Returns an Formula .
13,945
def feed ( self , cube , pair ) : self . cube = cube if pair not in [ "FR" , "RB" , "BL" , "LF" ] : pair = [ "FR" , "RB" , "BL" , "LF" ] [ [ "RF" , "BR" , "LB" , "FL" ] . index ( pair ) ] self . pair = pair
Feed Cube to the solver .
13,946
def estimated_position ( self ) : corner = { "D" : self . cube [ "D" ] [ "D" ] } edge = { } for cubie in ( corner , edge ) : for face in self . pair : cubie . update ( { face : self . cube [ face ] [ face ] } ) return ( Corner ( ** corner ) , Edge ( ** edge ) )
Get the estimated cubie of solved pair .
13,947
def get_slot ( self ) : corner , edge = self . get_pair ( ) corner_slot , edge_slot = corner . location . replace ( "D" , "" , 1 ) , edge . location if "U" not in corner_slot and corner_slot not in [ "FR" , "RB" , "BL" , "LF" ] : corner_slot = [ "FR" , "RB" , "BL" , "LF" ] [ [ "RF" , "BR" , "LB" , "FL" ] . index ( corner_slot ) ] if "U" not in edge_slot and edge_slot not in [ "FR" , "RB" , "BL" , "LF" ] : edge_slot = [ "FR" , "RB" , "BL" , "LF" ] [ [ "RF" , "BR" , "LB" , "FL" ] . index ( edge_slot ) ] if "U" in corner_slot and "U" in edge_slot : return ( "SLOTFREE" , ( None , None ) , ( corner , edge ) ) if "U" in corner_slot : return ( "CSLOTFREE" , ( None , edge_slot ) , ( corner , edge ) ) if "U" in edge_slot : return ( "ESLOTFREE" , ( corner_slot , None ) , ( corner , edge ) ) if corner_slot not in [ edge_slot , edge_slot [ : : - 1 ] ] : return ( "DIFFSLOT" , ( corner_slot , edge_slot ) , ( corner , edge ) ) if ( corner , edge ) == self . estimated_position ( ) : return ( "SOLVED" , ( corner_slot , edge_slot ) , ( corner , edge ) ) return ( "WRONGSLOT" , ( corner_slot , edge_slot ) , ( corner , edge ) )
Get the slot position of this pair .
13,948
def combining_goal ( state ) : ( ( corner , edge ) , ( L , U , F , D , R , B ) ) = state if "U" not in corner or "U" not in edge : return False if set ( edge ) . issubset ( set ( corner ) ) : return True elif set ( edge . facings . keys ( ) ) . issubset ( set ( corner . facings . keys ( ) ) ) : return False opposite = { "L" : "R" , "R" : "L" , "F" : "B" , "B" : "F" } edge_facings = list ( edge ) for i , ( face , square ) in enumerate ( edge_facings ) : if face == "U" : if square != corner [ opposite [ edge_facings [ ( i + 1 ) % 2 ] [ 0 ] ] ] : return False else : if square != corner [ "U" ] : return False return True
Check if two Cubies are combined on the U face .
13,949
def _rotate ( pair , step ) : step = Step ( step ) movement = { "U" : "RFLB" , "D" : "LFRB" , "R" : "FUBD" , "L" : "FDBU" , "F" : "URDL" , "B" : "ULDR" , } [ step . face ] movement = { movement [ i ] : movement [ ( i + step . is_clockwise + ( - 1 * step . is_counter_clockwise ) + ( 2 * step . is_180 ) ) % 4 ] for i in range ( 4 ) } for cubie in pair : if step . face not in cubie : if cubie . type == "edge" : result_edge = cubie . copy ( ) else : result_corner = cubie . copy ( ) else : result = { } for face , square in cubie : if face not in movement : result [ face ] = square else : result [ movement [ face ] ] = square if len ( result ) == 2 : result_edge = Edge ( ** result ) else : result_corner = Corner ( ** result ) return ( result_corner , result_edge )
Simulate the cube rotation by updating the pair .
13,950
def combining_successors ( state , last_action = ( ) ) : ( ( corner , edge ) , ( L , U , F , D , R , B ) ) = state U_turns = [ Formula ( "U" ) , Formula ( "U'" ) , Formula ( "U2" ) ] if len ( last_action ) != 1 else [ ] R_turns = [ Formula ( "R U R'" ) , Formula ( "R U' R'" ) , Formula ( "R U2 R'" ) ] if "R" not in last_action else [ ] F_turns = [ Formula ( "F' U F" ) , Formula ( "F' U' F" ) , Formula ( "F' U2 F" ) ] if "F" not in last_action else [ ] for act in ( U_turns + R_turns + F_turns ) : new = ( corner , edge ) for q in act : new = F2LPairSolver . _rotate ( new , q ) yield act , ( new , ( L , U , F , D , R , B ) )
Successors function for finding path of combining F2L pair .
13,951
def combining_search ( self ) : start = ( self . get_pair ( ) , ( self . cube [ "L" ] , self . cube [ "U" ] , self . cube [ "F" ] , self . cube [ "D" ] , self . cube [ "R" ] , self . cube [ "B" ] , ) , ) return sum ( path_actions ( a_star_search ( start , self . combining_successors , lambda x : len ( x ) , self . combining_goal ) ) , Formula ( ) )
Searching the path for combining the pair .
13,952
def combining_setup ( self ) : ( slot_type , ( corner_slot , edge_slot ) , ( corner , edge ) ) = self . get_slot ( ) cycle = [ "FR" , "RB" , "BL" , "LF" ] if slot_type == "SLOTFREE" : return ( "FR" , Formula ( Step ( "y" ) * cycle . index ( self . pair ) or [ ] ) ) elif slot_type == "CSLOTFREE" : return ( cycle [ - ( cycle . index ( edge_slot ) - cycle . index ( self . pair ) ) ] , Formula ( Step ( "y" ) * cycle . index ( edge_slot ) or [ ] ) ) elif slot_type in ( "ESLOTFREE" , "WRONGSLOT" ) : return ( cycle [ - ( cycle . index ( corner_slot ) - cycle . index ( self . pair ) ) ] , Formula ( Step ( "y" ) * cycle . index ( corner_slot ) or [ ] ) ) elif slot_type == "DIFFSLOT" : if corner_slot != self . pair : corner_slot , edge_slot = edge_slot , corner_slot result = Formula ( Step ( "y" ) * cycle . index ( edge_slot ) or [ ] ) result += Formula ( "R U R'" ) result += Formula ( Step ( "y'" ) * cycle . index ( edge_slot ) or [ ] ) result += Formula ( Step ( "y" ) * cycle . index ( corner_slot ) or [ ] ) if result [ - 1 ] . face == "y" and result [ - 2 ] . face == "y" : result [ - 2 ] += result [ - 1 ] del result [ - 1 ] return ( cycle [ - ( cycle . index ( corner_slot ) - cycle . index ( self . pair ) ) ] , result ) else : return ( cycle [ - cycle . index ( self . pair ) ] , Formula ( ) )
Setup for some special F2L cases .
13,953
def combine ( self ) : self . pair , setup = self . combining_setup ( ) self . cube ( setup ) actual = self . combining_search ( ) self . cube ( actual ) return setup + actual
Combine the pair .
13,954
def solve ( self ) : cycle = [ "FR" , "RB" , "BL" , "LF" ] combine = self . combine ( ) put = Formula ( Step ( "y" ) * cycle . index ( self . pair ) or [ ] ) self . cube ( put ) self . pair = "FR" estimated = self . estimated_position ( ) for U_act in [ Formula ( ) , Formula ( "U" ) , Formula ( "U2" ) , Formula ( "U'" ) ] : self . cube ( U_act ) for put_act in [ Formula ( "R U R'" ) , Formula ( "R U' R'" ) , Formula ( "R U2 R'" ) , Formula ( "F' U F" ) , Formula ( "F' U' F" ) , Formula ( "F' U2 F" ) ] : self . cube ( put_act ) if self . get_pair ( ) == estimated : return combine + put + U_act + put_act self . cube ( put_act . reverse ( ) ) self . cube ( U_act . reverse ( ) )
Solve the pair .
13,955
def is_solved ( self ) : if self . cube . D == [ [ Square ( self . cube [ "D" ] . colour ) ] * 3 ] * 3 : for face in "LFRB" : if self . cube . get_face ( face ) [ 1 : ] != [ [ Square ( self . cube [ face ] . colour ) ] * 3 ] * 2 : return False return True return False
Check if Cube s F2L is solved .
13,956
def authorization_code_pkce ( self , client_id , code_verifier , code , redirect_uri , grant_type = 'authorization_code' ) : return self . post ( 'https://{}/oauth/token' . format ( self . domain ) , data = { 'client_id' : client_id , 'code_verifier' : code_verifier , 'code' : code , 'grant_type' : grant_type , 'redirect_uri' : redirect_uri , } , headers = { 'Content-Type' : 'application/json' } )
Authorization code pkce grant
13,957
def client_credentials ( self , client_id , client_secret , audience , grant_type = 'client_credentials' ) : return self . post ( 'https://{}/oauth/token' . format ( self . domain ) , data = { 'client_id' : client_id , 'client_secret' : client_secret , 'audience' : audience , 'grant_type' : grant_type , } , headers = { 'Content-Type' : 'application/json' } )
Client credentials grant
13,958
def get ( self , id , fields = None , include_fields = True ) : params = { 'fields' : fields and ',' . join ( fields ) or None , 'include_fields' : str ( include_fields ) . lower ( ) } return self . client . get ( self . _url ( id ) , params = params )
Retrieve connection by id .
13,959
def update ( self , id , body ) : return self . client . patch ( self . _url ( id ) , data = body )
Modifies a connection .
13,960
def create ( self , body ) : return self . client . post ( self . _url ( ) , data = body )
Creates a new connection .
13,961
def delete_user_by_email ( self , id , email ) : return self . client . delete ( self . _url ( id ) + '/users' , params = { 'email' : email } )
Deletes a specified connection user by its email .
13,962
def get ( self , user_id , client_id , type , fields = None , include_fields = True ) : params = { 'fields' : fields and ',' . join ( fields ) or None , 'include_fields' : str ( include_fields ) . lower ( ) , 'user_id' : user_id , 'client_id' : client_id , 'type' : type , } return self . client . get ( self . _url ( ) , params = params )
List device credentials .
13,963
def get ( self , id ) : url = self . _url ( '%s' % ( id ) ) return self . client . get ( url )
Retrieves custom domain .
13,964
def delete ( self , id ) : url = self . _url ( '%s' % ( id ) ) return self . client . delete ( url )
Deletes a grant .
13,965
def create_new ( self , body ) : return self . client . post ( self . _url ( ) , data = body )
Configure a new custom domain
13,966
def verify ( self , id ) : url = self . _url ( '%s/verify' % ( id ) ) return self . client . post ( url )
Verify a custom domain
13,967
def saml_metadata ( self , client_id ) : return self . get ( url = 'https://{}/samlp/metadata/{}' . format ( self . domain , client_id ) )
Get SAML2 . 0 Metadata .
13,968
def wsfed_metadata ( self ) : url = 'https://{}/wsfed/FederationMetadata' '/2007-06/FederationMetadata.xml' return self . get ( url = url . format ( self . domain ) )
Returns the WS - Federation Metadata .
13,969
def all ( self , fields = None , include_fields = True , page = None , per_page = None , extra_params = None ) : params = extra_params or { } params [ 'fields' ] = fields and ',' . join ( fields ) or None params [ 'include_fields' ] = str ( include_fields ) . lower ( ) params [ 'page' ] = page params [ 'per_page' ] = per_page return self . client . get ( self . _url ( ) , params = params )
Retrieves a list of all the applications .
13,970
def rotate_secret ( self , id ) : params = { 'id' : id } url = self . _url ( '%s/rotate-secret' % id ) return self . client . get ( url , params = params )
Rotate a client secret . The generated secret is NOT base64 encoded .
13,971
def email ( self , client_id , email , send = 'link' , auth_params = None ) : return self . post ( 'https://{}/passwordless/start' . format ( self . domain ) , data = { 'client_id' : client_id , 'connection' : 'email' , 'email' : email , 'send' : send , 'authParams' : auth_params } , headers = { 'Content-Type' : 'application/json' } )
Start flow sending an email .
13,972
def sms ( self , client_id , phone_number ) : return self . post ( 'https://{}/passwordless/start' . format ( self . domain ) , data = { 'client_id' : client_id , 'connection' : 'sms' , 'phone_number' : phone_number , } , headers = { 'Content-Type' : 'application/json' } )
Start flow sending a SMS message .
13,973
def get_all ( self , page = None , per_page = None , include_totals = False ) : params = { 'page' : page , 'per_page' : per_page , 'include_totals' : str ( include_totals ) . lower ( ) } return self . client . get ( self . _url ( ) , params = params )
Retrieves all resource servers
13,974
def get_by_identifier ( self , identifier ) : params = { 'identifier' : identifier } return self . client . get ( self . _url ( ) , params = params )
Gets blocks by identifier
13,975
def unblock_by_identifier ( self , identifier ) : params = { 'identifier' : identifier } return self . client . delete ( self . _url ( ) , params = params )
Unblocks by identifier
13,976
def get_token ( self , client_id , target , api_type , grant_type , id_token = None , refresh_token = None , scope = 'openid' ) : if id_token and refresh_token : raise ValueError ( 'Only one of id_token or refresh_token ' 'can be None' ) data = { 'client_id' : client_id , 'grant_type' : grant_type , 'target' : target , 'scope' : scope , 'api_type' : api_type , } if id_token : data . update ( { 'id_token' : id_token } ) elif refresh_token : data . update ( { 'refresh_token' : refresh_token } ) else : raise ValueError ( 'Either id_token or refresh_token must ' 'have a value' ) return self . post ( 'https://{}/delegation' . format ( self . domain ) , headers = { 'Content-Type' : 'application/json' } , data = data )
Obtain a delegation token .
13,977
def update_templates ( self , body ) : return self . client . put ( self . _url ( 'factors/sms/templates' ) , data = body )
Update enrollment and verification SMS templates .
13,978
def get_enrollment ( self , id ) : url = self . _url ( 'enrollments/{}' . format ( id ) ) return self . client . get ( url )
Retrieves an enrollment . Useful to check its type and related metadata .
13,979
def delete_enrollment ( self , id ) : url = self . _url ( 'enrollments/{}' . format ( id ) ) return self . client . delete ( url )
Deletes an enrollment .
13,980
def create_enrollment_ticket ( self , body ) : return self . client . post ( self . _url ( 'enrollments/ticket' ) , data = body )
Creates an enrollment ticket for user_id
13,981
def get_factor_providers ( self , factor_name , name ) : url = self . _url ( 'factors/{}/providers/{}' . format ( factor_name , name ) ) return self . client . get ( url )
Get Guardian SNS or SMS factor providers .
13,982
def update_factor_providers ( self , factor_name , name , body ) : url = self . _url ( 'factors/{}/providers/{}' . format ( factor_name , name ) ) return self . client . put ( url , data = body )
Get Guardian factor providers .
13,983
def revoke_refresh_token ( self , client_id , token , client_secret = None ) : body = { 'client_id' : client_id , 'token' : token , 'client_secret' : client_secret } return self . post ( 'https://{}/oauth/revoke' . format ( self . domain ) , data = body )
Revokes a Refresh Token if it has been compromised Each revocation request invalidates not only the specific token but all other tokens based on the same authorization grant . This means that all Refresh Tokens that have been issued for the same user application and audience will be revoked .
13,984
def unset ( self , key ) : params = { 'key' : key } return self . client . delete ( self . _url ( ) , params = params )
Removes the rules config for a given key .
13,985
def set ( self , key , value ) : url = self . _url ( '{}' . format ( key ) ) body = { 'value' : value } return self . client . put ( url , data = body )
Sets the rules config for a given key .
13,986
def daily_stats ( self , from_date = None , to_date = None ) : return self . client . get ( self . _url ( 'daily' ) , params = { 'from' : from_date , 'to' : to_date } )
Gets the daily stats for a particular period .
13,987
def create_email_verification ( self , body ) : return self . client . post ( self . _url ( 'email-verification' ) , data = body )
Create an email verification ticket .
13,988
def create_pswd_change ( self , body ) : return self . client . post ( self . _url ( 'password-change' ) , data = body )
Create password change ticket .
13,989
def search ( self , page = 0 , per_page = 50 , sort = None , q = None , include_totals = True , fields = None , from_param = None , take = None , include_fields = True ) : params = { 'per_page' : per_page , 'page' : page , 'include_totals' : str ( include_totals ) . lower ( ) , 'sort' : sort , 'fields' : fields and ',' . join ( fields ) or None , 'include_fields' : str ( include_fields ) . lower ( ) , 'q' : q , 'from' : from_param , 'take' : take } return self . client . get ( self . _url ( ) , params = params )
Search log events .
13,990
def all ( self , audience = None , page = None , per_page = None , include_totals = False , client_id = None ) : params = { 'audience' : audience , 'page' : page , 'per_page' : per_page , 'include_totals' : str ( include_totals ) . lower ( ) , 'client_id' : client_id , } return self . client . get ( self . _url ( ) , params = params )
Retrieves all client grants .
13,991
def login ( self , client_id , access_token , connection , scope = 'openid' ) : return self . post ( 'https://{}/oauth/access_token' . format ( self . domain ) , data = { 'client_id' : client_id , 'access_token' : access_token , 'connection' : connection , 'scope' : scope , } , headers = { 'Content-Type' : 'application/json' } )
Login using a social provider s access token
13,992
def get ( self , aud = None ) : params = { 'aud' : aud } return self . client . get ( self . url , params = params )
Retrieves the jti and aud of all tokens in the blacklist .
13,993
def create ( self , jti , aud = '' ) : return self . client . post ( self . url , data = { 'jti' : jti , 'aud' : aud } )
Adds a token to the blacklist .
13,994
def list ( self , page = 0 , per_page = 25 , sort = None , connection = None , q = None , search_engine = None , include_totals = True , fields = None , include_fields = True ) : params = { 'per_page' : per_page , 'page' : page , 'include_totals' : str ( include_totals ) . lower ( ) , 'sort' : sort , 'connection' : connection , 'fields' : fields and ',' . join ( fields ) or None , 'include_fields' : str ( include_fields ) . lower ( ) , 'q' : q , 'search_engine' : search_engine } return self . client . get ( self . _url ( ) , params = params )
List or search users .
13,995
def delete_multifactor ( self , id , provider ) : url = self . _url ( '{}/multifactor/{}' . format ( id , provider ) ) return self . client . delete ( url )
Delete a user s multifactor provider .
13,996
def unlink_user_account ( self , id , provider , user_id ) : url = self . _url ( '{}/identities/{}/{}' . format ( id , provider , user_id ) ) return self . client . delete ( url )
Unlink a user account
13,997
def link_user_account ( self , user_id , body ) : url = self . _url ( '{}/identities' . format ( user_id ) ) return self . client . post ( url , data = body )
Link user accounts .
13,998
def regenerate_recovery_code ( self , user_id ) : url = self . _url ( '{}/recovery-code-regeneration' . format ( user_id ) ) return self . client . post ( url )
Removes the current recovery token generates and returns a new one
13,999
def get_guardian_enrollments ( self , user_id ) : url = self . _url ( '{}/enrollments' . format ( user_id ) ) return self . client . get ( url )
Retrieves all Guardian enrollments .