idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
41,800 | def _normalize_group_dns ( self , group_dns ) : if isinstance ( group_dns , LDAPGroupQuery ) : query = group_dns elif isinstance ( group_dns , str ) : query = LDAPGroupQuery ( group_dns ) elif isinstance ( group_dns , ( list , tuple ) ) and len ( group_dns ) > 0 : query = reduce ( operator . or_ , map ( LDAPGroupQuery ... | Converts one or more group DNs to an LDAPGroupQuery . |
41,801 | def _normalize_mirror_settings ( self ) : def malformed_mirror_groups_except ( ) : return ImproperlyConfigured ( "{} must be a collection of group names" . format ( self . settings . _name ( "MIRROR_GROUPS_EXCEPT" ) ) ) def malformed_mirror_groups ( ) : return ImproperlyConfigured ( "{} must be True or a collection of ... | Validates the group mirroring settings and converts them as necessary . |
41,802 | def _get_groups ( self ) : if self . _groups is None : self . _groups = _LDAPUserGroups ( self ) return self . _groups | Returns an _LDAPUserGroups object which can determine group membership . |
41,803 | def _bind ( self ) : self . _bind_as ( self . settings . BIND_DN , self . settings . BIND_PASSWORD , sticky = True ) | Binds to the LDAP server with AUTH_LDAP_BIND_DN and AUTH_LDAP_BIND_PASSWORD . |
41,804 | def _bind_as ( self , bind_dn , bind_password , sticky = False ) : self . _get_connection ( ) . simple_bind_s ( bind_dn , bind_password ) self . _connection_bound = sticky | Binds to the LDAP server with the given credentials . This does not trap exceptions . |
41,805 | def _init_group_settings ( self ) : self . _group_type = self . settings . GROUP_TYPE if self . _group_type is None : raise ImproperlyConfigured ( "AUTH_LDAP_GROUP_TYPE must be an LDAPGroupType instance." ) self . _group_search = self . settings . GROUP_SEARCH if self . _group_search is None : raise ImproperlyConfigure... | Loads the settings we need to deal with groups . |
41,806 | def get_group_names ( self ) : if self . _group_names is None : self . _load_cached_attr ( "_group_names" ) if self . _group_names is None : group_infos = self . _get_group_infos ( ) self . _group_names = { self . _group_type . group_name_from_info ( group_info ) for group_info in group_infos } self . _cache_attr ( "_g... | Returns the set of Django group names that this user belongs to by virtue of LDAP group memberships . |
41,807 | def is_member_of ( self , group_dn ) : is_member = None group_dn = group_dn . lower ( ) if self . _group_dns is None : is_member = self . _group_type . is_member ( self . _ldap_user , group_dn ) if is_member is None : is_member = group_dn in self . get_group_dns ( ) logger . debug ( "{} is{}a member of {}" . format ( s... | Returns true if our user is a member of the given group . |
41,808 | def get_ldap ( cls , global_options = None ) : if not cls . _ldap_configured and global_options is not None : for opt , value in global_options . items ( ) : ldap . set_option ( opt , value ) cls . _ldap_configured = True return ldap | Returns the configured ldap module . |
41,809 | def search_with_additional_terms ( self , term_dict , escape = True ) : term_strings = [ self . filterstr ] for name , value in term_dict . items ( ) : if escape : value = self . ldap . filter . escape_filter_chars ( value ) term_strings . append ( "({}={})" . format ( name , value ) ) filterstr = "(&{})" . format ( ""... | Returns a new search object with additional search terms and - ed to the filter string . term_dict maps attribute names to assertion values . If you don t want the values escaped pass escape = False . |
41,810 | def user_groups ( self , ldap_user , group_search ) : groups = [ ] try : user_uid = ldap_user . attrs [ "uid" ] [ 0 ] if "gidNumber" in ldap_user . attrs : user_gid = ldap_user . attrs [ "gidNumber" ] [ 0 ] filterstr = "(|(gidNumber={})(memberUid={}))" . format ( self . ldap . filter . escape_filter_chars ( user_gid ) ... | Searches for any group that is either the user s primary or contains the user as a member . |
41,811 | def is_member ( self , ldap_user , group_dn ) : try : user_uid = ldap_user . attrs [ "uid" ] [ 0 ] try : is_member = ldap_user . connection . compare_s ( group_dn , "memberUid" , user_uid . encode ( ) ) except ( ldap . UNDEFINED_TYPE , ldap . NO_SUCH_ATTRIBUTE ) : is_member = False if not is_member : try : user_gid = l... | Returns True if the group is the user s primary group or if the user is listed in the group s memberUid attribute . |
41,812 | def user_groups ( self , ldap_user , group_search ) : group_info_map = { } member_dn_set = { ldap_user . dn } handled_dn_set = set ( ) while len ( member_dn_set ) > 0 : group_infos = self . find_groups_with_any_member ( member_dn_set , group_search , ldap_user . connection ) new_group_info_map = { info [ 0 ] : info for... | This searches for all of a user s groups from the bottom up . In other words it returns the groups that the user belongs to the groups that those groups belong to etc . Circular references will be detected and pruned . |
41,813 | def aggregator ( self ) : if self . connector == self . AND : aggregator = all elif self . connector == self . OR : aggregator = any else : raise ValueError ( self . connector ) return aggregator | Returns a function for aggregating a sequence of sub - results . |
41,814 | def _resolve_children ( self , ldap_user , groups ) : for child in self . children : if isinstance ( child , LDAPGroupQuery ) : yield child . resolve ( ldap_user , groups ) else : yield groups . is_member_of ( child ) | Generates the query result for each child . |
41,815 | def gather_positions ( tree ) : pos = { 'data-x' : 'r0' , 'data-y' : 'r0' , 'data-z' : 'r0' , 'data-rotate-x' : 'r0' , 'data-rotate-y' : 'r0' , 'data-rotate-z' : 'r0' , 'data-scale' : 'r0' , 'is_path' : False } steps = 0 default_movement = True for step in tree . findall ( 'step' ) : steps += 1 for key in POSITION_ATTR... | Makes a list of positions and position commands from the tree |
41,816 | def calculate_positions ( positions ) : current_position = { 'data-x' : 0 , 'data-y' : 0 , 'data-z' : 0 , 'data-rotate-x' : 0 , 'data-rotate-y' : 0 , 'data-rotate-z' : 0 , 'data-scale' : 1 , } positer = iter ( positions ) position = next ( positer ) _update_position ( current_position , position ) while True : if 'path... | Calculates position information |
41,817 | def update_positions ( tree , positions ) : for step , pos in zip ( tree . findall ( 'step' ) , positions ) : for key in sorted ( pos ) : value = pos . get ( key ) if key . endswith ( "-rel" ) : abs_key = key [ : key . index ( "-rel" ) ] if value is not None : els = tree . findall ( ".//*[@id='" + value + "']" ) for el... | Updates the tree with new positions |
41,818 | def position_slides ( tree ) : positions = gather_positions ( tree ) positions = calculate_positions ( positions ) update_positions ( tree , positions ) | Position the slides in the tree |
41,819 | def copy_node ( node ) : element = node . makeelement ( node . tag ) element . text = node . text element . tail = node . tail for key , value in node . items ( ) : element . set ( key , value ) return element | Makes a copy of a node with the same attributes and text but no children . |
41,820 | def copy_resource ( self , resource , targetdir ) : final_path = resource . final_path ( ) if final_path [ 0 ] == '/' or ( ':' in final_path ) or ( '?' in final_path ) : return source_path = self . get_source_path ( resource ) if resource . resource_type == DIRECTORY_RESOURCE : for file_path in glob . iglob ( os . path... | Copies a resource file and returns the source path for monitoring |
41,821 | def generate ( args ) : source_files = { args . presentation } template_info = Template ( args . template ) if args . css : presentation_dir = os . path . split ( args . presentation ) [ 0 ] target_path = os . path . relpath ( args . css , presentation_dir ) template_info . add_resource ( args . css , CSS_RESOURCE , ta... | Generates the presentation and returns a list of files used |
41,822 | def port ( self , port = None ) : if ( port is None ) or ( port == self . __port ) : return self . __port self . close ( ) if 0 < int ( port ) < 65536 : self . __port = int ( port ) return self . __port else : return None | Get or set TCP port |
41,823 | def unit_id ( self , unit_id = None ) : if unit_id is None : return self . __unit_id if 0 <= int ( unit_id ) < 256 : self . __unit_id = int ( unit_id ) return self . __unit_id else : return None | Get or set unit ID field |
41,824 | def timeout ( self , timeout = None ) : if timeout is None : return self . __timeout if 0 < float ( timeout ) < 3600 : self . __timeout = float ( timeout ) return self . __timeout else : return None | Get or set timeout field |
41,825 | def debug ( self , state = None ) : if state is None : return self . __debug self . __debug = bool ( state ) return self . __debug | Get or set debug mode |
41,826 | def auto_open ( self , state = None ) : if state is None : return self . __auto_open self . __auto_open = bool ( state ) return self . __auto_open | Get or set automatic TCP connect mode |
41,827 | def _can_read ( self ) : if self . __sock is None : return None if select . select ( [ self . __sock ] , [ ] , [ ] , self . __timeout ) [ 0 ] : return True else : self . __last_error = const . MB_TIMEOUT_ERR self . __debug_msg ( 'timeout error' ) self . close ( ) return None | Wait data available for socket read |
41,828 | def _send ( self , data ) : if self . __sock is None : self . __debug_msg ( 'call _send on close socket' ) return None data_l = len ( data ) try : send_l = self . __sock . send ( data ) except socket . error : send_l = None if ( send_l is None ) or ( send_l != data_l ) : self . __last_error = const . MB_SEND_ERR self .... | Send data over current socket |
41,829 | def _recv ( self , max_size ) : if not self . _can_read ( ) : self . close ( ) return None try : r_buffer = self . __sock . recv ( max_size ) except socket . error : r_buffer = None if not r_buffer : self . __last_error = const . MB_RECV_ERR self . __debug_msg ( '_recv error' ) self . close ( ) return None return r_buf... | Receive data over current socket |
41,830 | def _send_mbus ( self , frame ) : if self . __auto_open and not self . is_open ( ) : self . open ( ) bytes_send = self . _send ( frame ) if bytes_send : if self . __debug : self . _pretty_dump ( 'Tx' , frame ) return bytes_send else : return None | Send modbus frame |
41,831 | def _recv_mbus ( self ) : if self . __mode == const . MODBUS_TCP : rx_buffer = self . _recv_all ( 7 ) if not ( rx_buffer and len ( rx_buffer ) == 7 ) : self . __last_error = const . MB_RECV_ERR self . __debug_msg ( '_recv MBAP error' ) self . close ( ) return None rx_frame = rx_buffer ( rx_hd_tr_id , rx_hd_pr_id , rx_h... | Receive a modbus frame |
41,832 | def _wc_hard_wrap ( line , length ) : chars = [ ] chars_len = 0 for char in line : char_len = wcwidth ( char ) if chars_len + char_len > length : yield "" . join ( chars ) chars = [ ] chars_len = 0 chars . append ( char ) chars_len += char_len if chars : yield "" . join ( chars ) | Wrap text to length characters breaking when target length is reached taking into account character width . |
41,833 | def wc_wrap ( text , length ) : line_words = [ ] line_len = 0 words = re . split ( r"\s+" , text . strip ( ) ) for word in words : word_len = wcswidth ( word ) if line_words and line_len + word_len > length : line = " " . join ( line_words ) if line_len <= length : yield line else : yield from _wc_hard_wrap ( line , le... | Wrap text to given length breaking on whitespace and taking into account character width . |
41,834 | def trunc ( text , length ) : if length < 1 : raise ValueError ( "length should be 1 or larger" ) text = text . strip ( ) text_length = wcswidth ( text ) if text_length <= length : return text chars_to_truncate = 0 trunc_length = 0 for char in reversed ( text ) : chars_to_truncate += 1 trunc_length += wcwidth ( char ) ... | Truncates text to given length taking into account wide characters . |
41,835 | def pad ( text , length ) : text_length = wcswidth ( text ) if text_length < length : return text + ' ' * ( length - text_length ) return text | Pads text to given length taking into account wide characters . |
41,836 | def fit_text ( text , length ) : text_length = wcswidth ( text ) if text_length > length : return trunc ( text , length ) if text_length < length : return pad ( text , length ) return text | Makes text fit the given length by padding or truncating it . |
41,837 | def _get_error_message ( response ) : try : data = response . json ( ) if "error_description" in data : return data [ 'error_description' ] if "error" in data : return data [ 'error' ] except Exception : pass return "Unknown error" | Attempt to extract an error message from response body |
41,838 | def _get_next_path ( headers ) : links = headers . get ( 'Link' , '' ) matches = re . match ( '<([^>]+)>; rel="next"' , links ) if matches : parsed = urlparse ( matches . group ( 1 ) ) return "?" . join ( [ parsed . path , parsed . query ] ) | Given timeline response headers returns the path to the next batch |
41,839 | def select_previous ( self ) : self . footer . clear_message ( ) if self . selected == 0 : self . footer . draw_message ( "Cannot move beyond first toot." , Color . GREEN ) return old_index = self . selected new_index = self . selected - 1 self . selected = new_index self . redraw_after_selection_change ( old_index , n... | Move to the previous status in the timeline . |
41,840 | def select_next ( self ) : self . footer . clear_message ( ) old_index = self . selected new_index = self . selected + 1 if self . selected + 1 >= len ( self . statuses ) : self . fetch_next ( ) self . left . draw_statuses ( self . statuses , self . selected , new_index - 1 ) self . draw_footer_status ( ) self . select... | Move to the next status in the timeline . |
41,841 | def full_redraw ( self ) : self . left . draw_statuses ( self . statuses , self . selected ) self . right . draw ( self . get_selected_status ( ) ) self . header . draw ( self . user ) self . draw_footer_status ( ) | Perform a full redraw of the UI . |
41,842 | def size_as_drawn ( lines , screen_width ) : y = 0 x = 0 for line in lines : wrapped = list ( wc_wrap ( line , screen_width ) ) if len ( wrapped ) > 0 : for wrapped_line in wrapped : x = len ( wrapped_line ) y += 1 else : x = 0 y += 1 return y - 1 , x - 1 if x != 0 else 0 | Get the bottom - right corner of some text as would be drawn by draw_lines |
41,843 | def _find_account ( app , user , account_name ) : if not account_name : raise ConsoleError ( "Empty account name given" ) accounts = api . search_accounts ( app , user , account_name ) if account_name [ 0 ] == "@" : account_name = account_name [ 1 : ] for account in accounts : if account [ 'acct' ] == account_name : re... | For a given account name returns the Account object . |
41,844 | def add_username ( user , apps ) : if not user : return None apps = [ a for a in apps if a . instance == user . instance ] if not apps : return None from toot . api import verify_credentials creds = verify_credentials ( apps . pop ( ) , user ) return User ( user . instance , creds [ 'username' ] , user . access_token ) | When using broser login username was not stored so look it up |
41,845 | def get_text ( html ) : with warnings . catch_warnings ( ) : warnings . simplefilter ( "ignore" ) text = BeautifulSoup ( html . replace ( ''' , "'" ) , "html.parser" ) . get_text ( ) return unicodedata . normalize ( 'NFKC' , text ) | Converts html to text strips all tags . |
41,846 | def parse_html ( html ) : paragraphs = re . split ( "</?p[^>]*>" , html ) paragraphs = [ re . split ( "<br */?>" , p ) for p in paragraphs if p ] return [ [ get_text ( l ) for l in p ] for p in paragraphs ] | Attempt to convert html to plain text while keeping line breaks . Returns a list of paragraphs each being a list of lines . |
41,847 | def format_content ( content ) : paragraphs = parse_html ( content ) first = True for paragraph in paragraphs : if not first : yield "" for line in paragraph : yield line first = False | Given a Status contents in HTML converts it into lines of plain text . |
41,848 | def multiline_input ( ) : lines = [ ] while True : try : lines . append ( input ( ) ) except EOFError : break return "\n" . join ( lines ) . strip ( ) | Lets user input multiple lines of text terminated by EOF . |
41,849 | def to_dict ( self ) : return { "name" : self . table_name , "kind" : self . table_kind , "data" : [ r . to_dict ( ) for r in self ] } | Converts the table to a dict . |
41,850 | def to_datetime ( value ) : if value is None : return None if isinstance ( value , six . integer_types ) : return parser . parse ( value ) return parser . isoparse ( value ) | Converts a string to a datetime . |
41,851 | def to_timedelta ( value ) : if value is None : return None if isinstance ( value , ( six . integer_types , float ) ) : return timedelta ( microseconds = ( float ( value ) / 10 ) ) match = _TIMESPAN_PATTERN . match ( value ) if match : if match . group ( 1 ) == "-" : factor = - 1 else : factor = 1 return factor * timed... | Converts a string to a timedelta . |
41,852 | def acquire_authorization_header ( self ) : try : return self . _acquire_authorization_header ( ) except AdalError as error : if self . _authentication_method is AuthenticationMethod . aad_username_password : kwargs = { "username" : self . _username , "client_id" : self . _client_id } elif self . _authentication_method... | Acquire tokens from AAD . |
41,853 | def _execute ( self , endpoint , database , query , default_timeout , properties = None ) : request_payload = { "db" : database , "csl" : query } if properties : request_payload [ "properties" ] = properties . to_json ( ) request_headers = { "Accept" : "application/json" , "Accept-Encoding" : "gzip,deflate" , "Content-... | Executes given query against this client |
41,854 | def set_option ( self , name , value ) : _assert_value_is_valid ( name ) self . _options [ name ] = value | Sets an option s value |
41,855 | def parse ( cls , uri ) : match = _URI_FORMAT . search ( uri ) return cls ( match . group ( 1 ) , match . group ( 2 ) , match . group ( 3 ) , match . group ( 4 ) ) | Parses uri into a ResourceUri object |
41,856 | def get_mapping_format ( self ) : if self . format == DataFormat . json or self . format == DataFormat . avro : return self . format . name else : return DataFormat . csv . name | Dictating the corresponding mapping to the format . |
41,857 | def getAtomChars ( t ) : s = c_char_p ( ) if PL_get_atom_chars ( t , byref ( s ) ) : return s . value else : raise InvalidTypeError ( "atom" ) | If t is an atom return it as a string otherwise raise InvalidTypeError . |
41,858 | def getBool ( t ) : b = c_int ( ) if PL_get_long ( t , byref ( b ) ) : return bool ( b . value ) else : raise InvalidTypeError ( "bool" ) | If t is of type bool return it otherwise raise InvalidTypeError . |
41,859 | def getLong ( t ) : i = c_long ( ) if PL_get_long ( t , byref ( i ) ) : return i . value else : raise InvalidTypeError ( "long" ) | If t is of type long return it otherwise raise InvalidTypeError . |
41,860 | def getFloat ( t ) : d = c_double ( ) if PL_get_float ( t , byref ( d ) ) : return d . value else : raise InvalidTypeError ( "float" ) | If t is of type float return it otherwise raise InvalidTypeError . |
41,861 | def getString ( t ) : slen = c_int ( ) s = c_char_p ( ) if PL_get_string_chars ( t , byref ( s ) , byref ( slen ) ) : return s . value else : raise InvalidTypeError ( "string" ) | If t is of type string return it otherwise raise InvalidTypeError . |
41,862 | def getList ( x ) : t = PL_copy_term_ref ( x ) head = PL_new_term_ref ( ) result = [ ] while PL_get_list ( t , head , t ) : result . append ( getTerm ( head ) ) head = PL_new_term_ref ( ) return result | Return t as a list . |
41,863 | def fromTerm ( cls , term ) : if isinstance ( term , Term ) : term = term . handle elif not isinstance ( term , ( c_void_p , int ) ) : raise ArgumentTypeError ( ( str ( Term ) , str ( c_void_p ) ) , str ( type ( term ) ) ) a = atom_t ( ) if PL_get_atom ( term , byref ( a ) ) : return cls ( a . value ) | Create an atom from a Term or term handle . |
41,864 | def fromTerm ( cls , term ) : if isinstance ( term , Term ) : term = term . handle elif not isinstance ( term , ( c_void_p , int ) ) : raise ArgumentTypeError ( ( str ( Term ) , str ( int ) ) , str ( type ( term ) ) ) f = functor_t ( ) if PL_get_functor ( term , byref ( f ) ) : args = [ ] arity = PL_functor_arity ( f .... | Create a functor from a Term or term handle . |
41,865 | def _findSwiplWin ( ) : import re dllNames = ( 'swipl.dll' , 'libswipl.dll' ) programFiles = os . getenv ( 'ProgramFiles' ) paths = [ os . path . join ( programFiles , r'pl\bin' , dllName ) for dllName in dllNames ] for path in paths : if os . path . exists ( path ) : return ( path , None ) path = _findSwiplPathFromFin... | This function uses several heuristics to gues where SWI - Prolog is installed in Windows . It always returns None as the path of the resource file because in Windows the way to find it is more robust so the SWI - Prolog DLL is always able to find it . |
41,866 | def _findSwiplLin ( ) : ( path , swiHome ) = _findSwiplFromExec ( ) if path is not None : return ( path , swiHome ) path = _findSwiplPathFromFindLib ( ) if path is not None : return ( path , swiHome ) paths = [ '/lib' , '/usr/lib' , '/usr/local/lib' , '.' , './lib' ] names = [ 'libswipl.so' , 'libpl.so' ] path = None f... | This function uses several heuristics to guess where SWI - Prolog is installed in Linuxes . |
41,867 | def _findSwiplDar ( ) : ( path , swiHome ) = _findSwiplFromExec ( ) if path is not None : return ( path , swiHome ) path = _findSwiplPathFromFindLib ( ) if path is not None : return ( path , swiHome ) paths = [ '.' , './lib' , '/usr/lib/' , '/usr/local/lib' , '/opt/local/lib' ] names = [ 'libswipl.dylib' , 'libpl.dylib... | This function uses several heuristics to guess where SWI - Prolog is installed in MacOS . |
41,868 | def _fixWindowsPath ( dll ) : if sys . platform [ : 3 ] != 'win' : return pathToDll = os . path . dirname ( dll ) currentWindowsPath = os . getenv ( 'PATH' ) if pathToDll not in currentWindowsPath : newPath = pathToDll + ';' + currentWindowsPath os . putenv ( 'PATH' , newPath ) | When the path to the DLL is not in Windows search path Windows will not be able to find other DLLs on the same directory so we have to add it to the path . This function takes care of it . |
41,869 | def list_to_bytes_list ( strList ) : pList = c_char_p * len ( strList ) if isinstance ( strList , ( pList , type ( None ) ) ) : return strList if not isinstance ( strList , ( list , set , tuple ) ) : raise TypeError ( "strList must be list, set or tuple, not " + str ( type ( strList ) ) ) pList = pList ( ) for i , elem... | This function turns an array of strings into a pointer array with pointers pointing to the encodings of those strings Possibly contained bytes are kept as they are . |
41,870 | def check_strings ( strings , arrays ) : if isinstance ( strings , int ) : strings = [ strings ] elif strings is None : strings = [ ] for i , k in enumerate ( strings ) : if not isinstance ( k , int ) : raise TypeError ( ( 'Wrong type for index at {0} ' + 'in strings. Must be int, not {1}!' ) . format ( i , k ) ) if is... | Decorator function which can be used to automatically turn an incoming string into a bytes object and an incoming list to a pointer array if necessary . |
41,871 | def add ( self , item ) : def result_fnc ( f ) : if f . result ( ) : return True raise Full ( "Queue is full!" ) return self . offer ( item ) . continue_with ( result_fnc ) | Adds the specified item to this queue if there is available space . |
41,872 | def add_all ( self , items ) : check_not_none ( items , "Value can't be None" ) data_items = [ ] for item in items : check_not_none ( item , "Value can't be None" ) data_items . append ( self . _to_data ( item ) ) return self . _encode_invoke ( queue_add_all_codec , data_list = data_items ) | Adds the elements in the specified collection to this queue . |
41,873 | def contains_all ( self , items ) : check_not_none ( items , "Items can't be None" ) data_items = [ ] for item in items : check_not_none ( item , "item can't be None" ) data_items . append ( self . _to_data ( item ) ) return self . _encode_invoke ( queue_contains_all_codec , data_list = data_items ) | Determines whether this queue contains all of the items in the specified collection or not . |
41,874 | def drain_to ( self , list , max_size = - 1 ) : def drain_result ( f ) : resp = f . result ( ) list . extend ( resp ) return len ( resp ) return self . _encode_invoke ( queue_drain_to_max_size_codec , max_size = max_size ) . continue_with ( drain_result ) | Transfers all available items to the given list _ and removes these items from this queue . If a max_size is specified it transfers at most the given number of items . In case of a failure an item can exist in both collections or none of them . |
41,875 | def put ( self , item ) : check_not_none ( item , "Value can't be None" ) element_data = self . _to_data ( item ) return self . _encode_invoke ( queue_put_codec , value = element_data ) | Adds the specified element into this queue . If there is no space it waits until necessary space becomes available . |
41,876 | def remove_all ( self , items ) : check_not_none ( items , "Value can't be None" ) data_items = [ ] for item in items : check_not_none ( item , "Value can't be None" ) data_items . append ( self . _to_data ( item ) ) return self . _encode_invoke ( queue_compare_and_remove_all_codec , data_list = data_items ) | Removes all of the elements of the specified collection from this queue . |
41,877 | def retain_all ( self , items ) : check_not_none ( items , "Value can't be None" ) data_items = [ ] for item in items : check_not_none ( item , "Value can't be None" ) data_items . append ( self . _to_data ( item ) ) return self . _encode_invoke ( queue_compare_and_retain_all_codec , data_list = data_items ) | Removes the items which are not contained in the specified collection . In other words only the items that are contained in the specified collection will be retained . |
41,878 | def get_and_add ( self , delta ) : return self . _invoke_internal ( pn_counter_add_codec , delta = delta , get_before_update = True ) | Adds the given value to the current value and returns the previous value . |
41,879 | def add_and_get ( self , delta ) : return self . _invoke_internal ( pn_counter_add_codec , delta = delta , get_before_update = False ) | Adds the given value to the current value and returns the updated value . |
41,880 | def get_and_subtract ( self , delta ) : return self . _invoke_internal ( pn_counter_add_codec , delta = - 1 * delta , get_before_update = True ) | Subtracts the given value from the current value and returns the previous value . |
41,881 | def subtract_and_get ( self , delta ) : return self . _invoke_internal ( pn_counter_add_codec , delta = - 1 * delta , get_before_update = False ) | Subtracts the given value from the current value and returns the updated value . |
41,882 | def shutdown ( self ) : if self . lifecycle . is_live : self . lifecycle . fire_lifecycle_event ( LIFECYCLE_STATE_SHUTTING_DOWN ) self . near_cache_manager . destroy_all_near_caches ( ) self . statistics . shutdown ( ) self . partition_service . shutdown ( ) self . heartbeat . shutdown ( ) self . cluster . shutdown ( )... | Shuts down this HazelcastClient . |
41,883 | def publish ( self , message ) : message_data = self . _to_data ( message ) self . _encode_invoke ( topic_publish_codec , message = message_data ) | Publishes the message to all subscribers of this topic |
41,884 | def remove_listener ( self , registration_id ) : return self . _stop_listening ( registration_id , lambda i : topic_remove_message_listener_codec . encode_request ( self . name , i ) ) | Stops receiving messages for the given message listener . If the given listener already removed this method does nothing . |
41,885 | def validate_serializer ( serializer , _type ) : if not issubclass ( serializer , _type ) : raise ValueError ( "Serializer should be an instance of {}" . format ( _type . __name__ ) ) | Validates the serializer for given type . |
41,886 | def create_exception ( error_codec ) : if error_codec . error_code in ERROR_CODE_TO_ERROR : return ERROR_CODE_TO_ERROR [ error_codec . error_code ] ( error_codec . message ) stack_trace = "\n" . join ( [ "\tat %s.%s(%s:%s)" % ( x . declaring_class , x . method_name , x . file_name , x . line_number ) for x in error_cod... | Creates an exception with given error codec . |
41,887 | def capacity ( self ) : if not self . _capacity : def cache_capacity ( f ) : self . _capacity = f . result ( ) return f . result ( ) return self . _encode_invoke ( ringbuffer_capacity_codec ) . continue_with ( cache_capacity ) return ImmediateFuture ( self . _capacity ) | Returns the capacity of this Ringbuffer . |
41,888 | def read_one ( self , sequence ) : check_not_negative ( sequence , "sequence can't be smaller than 0" ) return self . _encode_invoke ( ringbuffer_read_one_codec , sequence = sequence ) | Reads one item from the Ringbuffer . If the sequence is one beyond the current tail this call blocks until an item is added . Currently it isn t possible to control how long this call is going to block . |
41,889 | def read_many ( self , start_sequence , min_count , max_count ) : check_not_negative ( start_sequence , "sequence can't be smaller than 0" ) check_true ( max_count >= min_count , "max count should be greater or equal to min count" ) check_true ( min_count <= self . capacity ( ) . result ( ) , "min count should be small... | Reads a batch of items from the Ringbuffer . If the number of available items after the first read item is smaller than the max_count these items are returned . So it could be the number of items read is smaller than the max_count . If there are less items available than min_count then this call blocks . Reading a batc... |
41,890 | def init ( self , initial ) : if initial <= 0 : return False step = initial // BLOCK_SIZE with self . _lock : init = self . _atomic_long . compare_and_set ( 0 , step + 1 ) . result ( ) if init : self . _local = step self . _residue = ( initial % BLOCK_SIZE ) + 1 return init | Try to initialize this IdGenerator instance with the given id . The first generated id will be 1 greater than id . |
41,891 | def new_id ( self ) : with self . _lock : curr = self . _residue self . _residue += 1 if self . _residue >= BLOCK_SIZE : increment = self . _atomic_long . get_and_increment ( ) . result ( ) self . _local = increment self . _residue = 0 return self . new_id ( ) return self . _local * BLOCK_SIZE + curr | Generates and returns a cluster - wide unique id . Generated ids are guaranteed to be unique for the entire cluster as long as the cluster is live . If the cluster restarts then id generation will start from 0 . |
41,892 | def execute_on_key_owner ( self , key , task ) : check_not_none ( key , "key can't be None" ) key_data = self . _to_data ( key ) partition_id = self . _client . partition_service . get_partition_id ( key_data ) uuid = self . _get_uuid ( ) return self . _encode_invoke_on_partition ( executor_service_submit_to_partition_... | Executes a task on the owner of the specified key . |
41,893 | def execute_on_member ( self , member , task ) : uuid = self . _get_uuid ( ) address = member . address return self . _execute_on_member ( address , uuid , self . _to_data ( task ) ) | Executes a task on the specified member . |
41,894 | def execute_on_members ( self , members , task ) : task_data = self . _to_data ( task ) futures = [ ] uuid = self . _get_uuid ( ) for member in members : f = self . _execute_on_member ( member . address , uuid , task_data ) futures . append ( f ) return future . combine_futures ( * futures ) | Executes a task on each of the specified members . |
41,895 | def execute_on_all_members ( self , task ) : return self . execute_on_members ( self . _client . cluster . get_member_list ( ) , task ) | Executes a task on all of the known cluster members . |
41,896 | def add_listener ( self , on_lifecycle_change ) : id = str ( uuid . uuid4 ( ) ) self . _listeners [ id ] = on_lifecycle_change return id | Add a listener object to listen for lifecycle events . |
41,897 | def remove_listener ( self , registration_id ) : try : self . _listeners . pop ( registration_id ) return True except KeyError : return False | Removes a lifecycle listener . |
41,898 | def fire_lifecycle_event ( self , new_state ) : if new_state == LIFECYCLE_STATE_SHUTTING_DOWN : self . is_live = False self . state = new_state self . logger . info ( self . _git_info + "HazelcastClient is %s" , new_state , extra = self . _logger_extras ) for listener in list ( self . _listeners . values ( ) ) : try : ... | Called when instance s state changes . |
41,899 | def lock ( self , lease_time = - 1 ) : return self . _encode_invoke ( lock_lock_codec , invocation_timeout = MAX_SIZE , lease_time = to_millis ( lease_time ) , thread_id = thread_id ( ) , reference_id = self . reference_id_generator . get_and_increment ( ) ) | Acquires the lock . If a lease time is specified lock will be released after this lease time . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.