idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
21,700 | def split ( self ) : key = '%s/split' % self . key return self . _server . query ( key , method = self . _server . _session . put ) | Split a duplicate . |
21,701 | def unmatch ( self ) : key = '%s/unmatch' % self . key return self . _server . query ( key , method = self . _server . _session . put ) | Unmatch a media file . |
21,702 | def download ( self , savepath = None , keep_original_name = False , ** kwargs ) : filepaths = [ ] locations = [ i for i in self . iterParts ( ) if i ] for location in locations : filename = location . file if keep_original_name is False : filename = '%s.%s' % ( self . _prettyfilename ( ) , location . container ) if kw... | Downloads this items media to the specified location . Returns a list of filepaths that have been saved to disk . |
21,703 | def stop ( self , reason = '' ) : key = '/status/sessions/terminate?sessionId=%s&reason=%s' % ( self . session [ 0 ] . id , quote_plus ( reason ) ) return self . _server . query ( key ) | Stop playback for a media item . |
21,704 | def updateProgress ( self , time , state = 'stopped' ) : key = '/:/progress?key=%s&identifier=com.plexapp.plugins.library&time=%d&state=%s' % ( self . ratingKey , time , state ) self . _server . query ( key ) self . reload ( ) | Set the watched progress for this video . |
21,705 | def updateTimeline ( self , time , state = 'stopped' , duration = None ) : durationStr = '&duration=' if duration is not None : durationStr = durationStr + str ( duration ) else : durationStr = durationStr + str ( self . duration ) key = '/:/timeline?ratingKey=%s&key=%s&identifier=com.plexapp.plugins.library&time=%d&st... | Set the timeline progress for this video . |
21,706 | def all ( self , ** kwargs ) : items = [ ] for section in self . sections ( ) : for item in section . all ( ** kwargs ) : items . append ( item ) return items | Returns a list of all media from all library sections . This may be a very large dataset to retrieve . |
21,707 | def search ( self , title = None , libtype = None , ** kwargs ) : args = { } if title : args [ 'title' ] = title if libtype : args [ 'type' ] = utils . searchType ( libtype ) for attr , value in kwargs . items ( ) : args [ attr ] = value key = '/library/all%s' % utils . joinArgs ( args ) return self . fetchItems ( key ... | Searching within a library section is much more powerful . It seems certain attributes on the media objects can be targeted to filter this search down a bit but I havent found the documentation for it . |
21,708 | def add ( self , name = '' , type = '' , agent = '' , scanner = '' , location = '' , language = 'en' , * args , ** kwargs ) : part = '/library/sections?name=%s&type=%s&agent=%s&scanner=%s&language=%s&location=%s' % ( quote_plus ( name ) , type , agent , quote_plus ( scanner ) , language , quote_plus ( location ) ) if k... | Simplified add for the most common options . |
21,709 | def delete ( self ) : try : return self . _server . query ( '/library/sections/%s' % self . key , method = self . _server . _session . delete ) except BadRequest : msg = 'Failed to delete library %s' % self . key msg += 'You may need to allow this permission in your Plex settings.' log . error ( msg ) raise | Delete a library section . |
21,710 | def get ( self , title ) : key = '/library/sections/%s/all' % self . key return self . fetchItem ( key , title__iexact = title ) | Returns the media item with the specified title . |
21,711 | def all ( self , sort = None , ** kwargs ) : sortStr = '' if sort is not None : sortStr = '?sort=' + sort key = '/library/sections/%s/all%s' % ( self . key , sortStr ) return self . fetchItems ( key , ** kwargs ) | Returns a list of media from this library section . |
21,712 | def emptyTrash ( self ) : key = '/library/sections/%s/emptyTrash' % self . key self . _server . query ( key , method = self . _server . _session . put ) | If a section has items in the Trash use this option to empty the Trash . |
21,713 | def cancelUpdate ( self ) : key = '/library/sections/%s/refresh' % self . key self . _server . query ( key , method = self . _server . _session . delete ) | Cancel update of this Library Section . |
21,714 | def deleteMediaPreviews ( self ) : key = '/library/sections/%s/indexes' % self . key self . _server . query ( key , method = self . _server . _session . delete ) | Delete the preview thumbnails for items in this library . This cannot be undone . Recreating media preview files can take hours or even days . |
21,715 | def recentlyAdded ( self , libtype = 'episode' , maxresults = 50 ) : return self . search ( sort = 'addedAt:desc' , libtype = libtype , maxresults = maxresults ) | Returns a list of recently added episodes from this library section . |
21,716 | def inviteFriend ( self , user , server , sections = None , allowSync = False , allowCameraUpload = False , allowChannels = False , filterMovies = None , filterTelevision = None , filterMusic = None ) : username = user . username if isinstance ( user , MyPlexUser ) else user machineId = server . machineIdentifier if is... | Share library content with the specified user . |
21,717 | def removeFriend ( self , user ) : user = self . user ( user ) url = self . FRIENDUPDATE if user . friend else self . REMOVEINVITE url = url . format ( userId = user . id ) return self . query ( url , self . _session . delete ) | Remove the specified user from all sharing . |
21,718 | def updateFriend ( self , user , server , sections = None , removeSections = False , allowSync = None , allowCameraUpload = None , allowChannels = None , filterMovies = None , filterTelevision = None , filterMusic = None ) : response_filters = '' response_servers = '' user = user if isinstance ( user , MyPlexUser ) els... | Update the specified user s share settings . |
21,719 | def _getSectionIds ( self , server , sections ) : if not sections : return [ ] allSectionIds = { } machineIdentifier = server . machineIdentifier if isinstance ( server , PlexServer ) else server url = self . PLEXSERVERS . replace ( '{machineId}' , machineIdentifier ) data = self . query ( url , self . _session . get )... | Converts a list of section objects or names to sectionIds needed for library sharing . |
21,720 | def _filterDictToStr ( self , filterDict ) : values = [ ] for key , vals in filterDict . items ( ) : if key not in ( 'contentRating' , 'label' ) : raise BadRequest ( 'Unknown filter key: %s' , key ) values . append ( '%s=%s' % ( key , '%2C' . join ( vals ) ) ) return '|' . join ( values ) | Converts friend filters to a string representation for transport . |
21,721 | def delete ( self ) : key = 'https://plex.tv/devices/%s.xml' % self . id self . _server . query ( key , self . _server . _session . delete ) | Remove this device from your account . |
21,722 | def thumbUrl ( self ) : key = self . firstAttr ( 'thumb' , 'parentThumb' , 'granparentThumb' ) return self . _server . url ( key , includeToken = True ) if key else None | Return url to for the thumbnail image . |
21,723 | def keep_episodes ( show , keep ) : deleted = 0 print ( '%s Cleaning %s to %s episodes.' % ( datestr ( ) , show . title , keep ) ) sort = lambda x : x . originallyAvailableAt or x . addedAt items = sorted ( show . episodes ( ) , key = sort , reverse = True ) for episode in items [ keep : ] : delete_episode ( episode ) ... | Delete all but last count episodes in show . |
21,724 | def keep_season ( show , keep ) : deleted = 0 print ( '%s Cleaning %s to latest season.' % ( datestr ( ) , show . title ) ) for season in show . seasons ( ) [ : - 1 ] : for episode in season . episodes ( ) : delete_episode ( episode ) deleted += 1 return deleted | Keep only the latest season . |
21,725 | def _create_sg_attachment ( self , django_attch ) : def set_prop ( attachment , prop_name , value ) : if SENDGRID_VERSION < '6' : setattr ( attachment , prop_name , value ) else : if prop_name == "filename" : prop_name = "name" setattr ( attachment , 'file_{}' . format ( prop_name ) , value ) sg_attch = Attachment ( ) ... | Handles the conversion between a django attachment object and a sendgrid attachment object . Due to differences between sendgrid s API versions use this method when constructing attachments to ensure that attachments get properly instantiated . |
21,726 | def validate ( path , regex = None ) : validated = [ ] for elem in path : key = elem [ 0 ] strkey = str ( key ) if ( regex and ( not regex . findall ( strkey ) ) ) : raise dpath . exceptions . InvalidKeyName ( "{} at {} does not match the expression {}" "" . format ( strkey , validated , regex . pattern ) ) validated .... | Validate that all the keys in the given list of path components are valid given that they do not contain the separator and match any optional regex given . |
21,727 | def paths ( obj , dirs = True , leaves = True , path = [ ] , skip = False ) : if isinstance ( obj , MutableMapping ) : if PY3 : iteritems = obj . items ( ) string_class = str else : iteritems = obj . iteritems ( ) string_class = basestring for ( k , v ) in iteritems : if issubclass ( k . __class__ , ( string_class ) ) ... | Yield all paths of the object . |
21,728 | def match ( path , glob ) : path_len = len ( path ) glob_len = len ( glob ) ss = - 1 ss_glob = glob if '**' in glob : ss = glob . index ( '**' ) if '**' in glob [ ss + 1 : ] : raise dpath . exceptions . InvalidGlob ( "Invalid glob. Only one '**' is permitted per glob." ) if path_len >= glob_len : more_stars = [ '*' ] *... | Match the path with the glob . |
21,729 | def set ( obj , path , value , create_missing = True , afilter = None ) : cur = obj traversed = [ ] def _presence_test_dict ( obj , elem ) : return ( elem [ 0 ] in obj ) def _create_missing_dict ( obj , elem ) : obj [ elem [ 0 ] ] = elem [ 1 ] ( ) def _presence_test_list ( obj , elem ) : return ( int ( str ( elem [ 0 ]... | Set the value of the given path in the object . Path must be a list of specific path elements not a glob . You can use dpath . util . set for globs but the paths must slready exist . |
21,730 | def get ( obj , path , view = False , afilter = None ) : index = 0 path_count = len ( path ) - 1 target = obj head = type ( target ) ( ) tail = head up = None for pair in path : key = pair [ 0 ] target = target [ key ] if view : if isinstance ( tail , MutableMapping ) : if issubclass ( pair [ 1 ] , ( MutableSequence , ... | Get the value of the given path . |
21,731 | def delete ( obj , glob , separator = "/" , afilter = None ) : deleted = 0 paths = [ ] globlist = __safe_path__ ( glob , separator ) for path in _inner_search ( obj , globlist , separator ) : paths . append ( path ) for path in paths : cur = obj prev = None for item in path : prev = cur try : cur = cur [ item [ 0 ] ] e... | Given a path glob delete all elements that match the glob . |
21,732 | def set ( obj , glob , value , separator = "/" , afilter = None ) : changed = 0 globlist = __safe_path__ ( glob , separator ) for path in _inner_search ( obj , globlist , separator ) : changed += 1 dpath . path . set ( obj , path , value , create_missing = False , afilter = afilter ) return changed | Given a path glob set all existing elements in the document to the given value . Returns the number of elements changed . |
21,733 | def get ( obj , glob , separator = "/" ) : ret = None found = False for item in search ( obj , glob , yielded = True , separator = separator ) : if ret is not None : raise ValueError ( "dpath.util.get() globs must match only one leaf : %s" % glob ) ret = item [ 1 ] found = True if found is False : raise KeyError ( glob... | Given an object which contains only one possible match for the given glob return the value for the leaf matching the given glob . |
21,734 | def search ( obj , glob , yielded = False , separator = "/" , afilter = None , dirs = True ) : def _search_view ( obj , glob , separator , afilter , dirs ) : view = { } globlist = __safe_path__ ( glob , separator ) for path in _inner_search ( obj , globlist , separator , dirs = dirs ) : try : val = dpath . path . get (... | Given a path glob return a dictionary containing all keys that matched the given glob . |
21,735 | def _inner_search ( obj , glob , separator , dirs = True , leaves = False ) : for path in dpath . path . paths ( obj , dirs , leaves , skip = True ) : if dpath . path . match ( path , glob ) : yield path | Search the object paths that match the glob . |
21,736 | def decode ( code , encoding_type = 'default' ) : reversed_morsetab = { symbol : character for character , symbol in list ( getattr ( encoding , 'morsetab' ) . items ( ) ) } encoding_type = encoding_type . lower ( ) allowed_encoding_type = [ 'default' , 'binary' ] if encoding_type == 'default' : letters = 0 words = 0 i... | Converts a string of morse code into English message |
21,737 | def compute_samples ( channels , nsamples = None ) : return islice ( izip ( * ( imap ( sum , izip ( * channel ) ) for channel in channels ) ) , nsamples ) | create a generator which computes the samples . essentially it creates a sequence of the sum of each function in the channel at each sample in the file for each channel . |
21,738 | def write_wavefile ( f , samples , nframes = None , nchannels = 2 , sampwidth = 2 , framerate = 44100 , bufsize = 2048 ) : "Write samples to a wavefile." if nframes is None : nframes = 0 w = wave . open ( f , 'wb' ) w . setparams ( ( nchannels , sampwidth , framerate , nframes , 'NONE' , 'not compressed' ) ) max_amplit... | Write samples to a wavefile . |
21,739 | def sine_wave ( i , frequency = FREQUENCY , framerate = FRAMERATE , amplitude = AMPLITUDE ) : omega = 2.0 * pi * float ( frequency ) sine = sin ( omega * ( float ( i ) / float ( framerate ) ) ) return float ( amplitude ) * sine | Returns value of a sine wave at a given frequency and framerate for a given sample i |
21,740 | def generate_wave ( message , wpm = WPM , framerate = FRAMERATE , skip_frame = 0 , amplitude = AMPLITUDE , frequency = FREQUENCY , word_ref = WORD ) : lst_bin = _encode_binary ( message ) if amplitude > 1.0 : amplitude = 1.0 if amplitude < 0.0 : amplitude = 0.0 seconds_per_dot = _seconds_per_dot ( word_ref ) for i in c... | Generate binary Morse code of message at a given code speed wpm and framerate |
21,741 | def encode ( message , encoding_type = 'default' , letter_sep = ' ' * 3 , strip = True ) : if strip : message = message . strip ( ) encoding_type = encoding_type . lower ( ) allowed_encoding_type = [ 'default' , 'binary' ] if encoding_type == 'default' : return _encode_to_morse_string ( message , letter_sep ) elif enco... | Converts a string of message into morse |
21,742 | def plot ( message , duration = 1 , ax = None ) : lst_bin = _encode_binary ( message ) x , y = _create_x_y ( lst_bin , duration ) ax = _create_ax ( ax ) ax . plot ( x , y , linewidth = 2.0 ) delta_y = 0.1 ax . set_ylim ( - delta_y , 1 + delta_y ) ax . set_yticks ( [ 0 , 1 ] ) delta_x = 0.5 * duration ax . set_xlim ( - ... | Plot a message |
21,743 | def _repeat_word ( word , N , word_space = " " ) : message = ( word_space + word ) * N message = message [ len ( word_space ) : ] return message | Return a repeated string |
21,744 | def mlength ( message , N = 1 , word_spaced = True ) : message = _repeat_word ( message , N ) if word_spaced : message = message + " E" lst_bin = _encode_binary ( message ) N = len ( lst_bin ) if word_spaced : N -= 1 return N | Returns Morse length |
21,745 | def _timing_representation ( message ) : s = _encode_to_binary_string ( message , on = "=" , off = "." ) N = len ( s ) s += '\n' + _numbers_decades ( N ) s += '\n' + _numbers_units ( N ) s += '\n' s += '\n' + _timing_char ( message ) return s | Returns timing representation of a message like |
21,746 | def display ( message , wpm , element_duration , word_ref , strip = False ) : fmt = "{0:>8s}: '{1}'" key = "text" if strip : print ( fmt . format ( key , message . strip ( ) ) ) else : print ( fmt . format ( key , message . strip ( ) ) ) print ( fmt . format ( "morse" , mtalk . encode ( message , strip = strip ) ) ) pr... | Display text message morse code binary morse code |
21,747 | def lookup ( self , label ) : if self . is_child : try : return self . _children [ label ] except KeyError : self . _children [ label ] = ChildFieldPicklist ( self . parent , label , self . field_name ) return self . _children [ label ] else : return get_label_value ( label , self . _picklist ) | take a field_name_label and return the id |
21,748 | def reverse_lookup ( self , value , condition = is_active ) : label = get_value_label ( value , self . _picklist , condition = condition ) return label | take a field_name_id and return the label |
21,749 | def build_item ( title , key = None , synonyms = None , description = None , img_url = None , alt_text = None ) : item = { "info" : { "key" : key or title , "synonyms" : synonyms or [ ] } , "title" : title , "description" : description , "image" : { "imageUri" : img_url or "" , "accessibilityText" : alt_text or "{} img... | Builds an item that may be added to List or Carousel |
21,750 | def suggest ( self , * replies ) : chips = [ ] for r in replies : chips . append ( { "title" : r } ) self . _messages . append ( { "platform" : "ACTIONS_ON_GOOGLE" , "suggestions" : { "suggestions" : chips } } ) return self | Use suggestion chips to hint at responses to continue or pivot the conversation |
21,751 | def link_out ( self , name , url ) : self . _messages . append ( { "platform" : "ACTIONS_ON_GOOGLE" , "linkOutSuggestion" : { "destinationName" : name , "uri" : url } , } ) return self | Presents a chip similar to suggestion but instead links to a url |
21,752 | def build_list ( self , title = None , items = None ) : list_card = _ListSelector ( self . _speech , display_text = self . _display_text , title = title , items = items ) return list_card | Presents the user with a vertical list of multiple items . |
21,753 | def add_item ( self , title , key , synonyms = None , description = None , img_url = None ) : item = build_item ( title , key , synonyms , description , img_url ) self . _items . append ( item ) return self | Adds item to a list or carousel card . |
21,754 | def get_intent ( self , intent_id ) : endpoint = self . _intent_uri ( intent_id = intent_id ) return self . _get ( endpoint ) | Returns the intent object with the given intent_id |
21,755 | def post_intent ( self , intent_json ) : endpoint = self . _intent_uri ( ) return self . _post ( endpoint , data = intent_json ) | Sends post request to create a new intent |
21,756 | def put_intent ( self , intent_id , intent_json ) : endpoint = self . _intent_uri ( intent_id ) return self . _put ( endpoint , intent_json ) | Send a put request to update the intent with intent_id |
21,757 | def find_assistant ( ) : if hasattr ( current_app , "assist" ) : return getattr ( current_app , "assist" ) else : if hasattr ( current_app , "blueprints" ) : blueprints = getattr ( current_app , "blueprints" ) for blueprint_name in blueprints : if hasattr ( blueprints [ blueprint_name ] , "assist" ) : return getattr ( ... | Find our instance of Assistant navigating Local s and possible blueprints . |
21,758 | def action ( self , intent_name , is_fallback = False , mapping = { } , convert = { } , default = { } , with_context = [ ] , events = [ ] , * args , ** kw ) : def decorator ( f ) : action_funcs = self . _intent_action_funcs . get ( intent_name , [ ] ) action_funcs . append ( f ) self . _intent_action_funcs [ intent_nam... | Decorates an intent_name s Action view function . |
21,759 | def prompt_for ( self , next_param , intent_name ) : def decorator ( f ) : prompts = self . _intent_prompts . get ( intent_name ) if prompts : prompts [ next_param ] = f else : self . _intent_prompts [ intent_name ] = { } self . _intent_prompts [ intent_name ] [ next_param ] = f @ wraps ( f ) def wrapper ( * args , ** ... | Decorates a function to prompt for an action s required parameter . |
21,760 | def _context_views ( self ) : possible_views = [ ] for func in self . _func_contexts : if self . _context_satified ( func ) : logger . debug ( "{} context conditions satisified" . format ( func . __name__ ) ) possible_views . append ( func ) return possible_views | Returns view functions for which the context requirements are met |
21,761 | def get_assistant ( filename ) : agent_name = os . path . splitext ( filename ) [ 0 ] try : agent_module = import_with_3 ( agent_name , os . path . join ( os . getcwd ( ) , filename ) ) except ImportError : agent_module = import_with_2 ( agent_name , os . path . join ( os . getcwd ( ) , filename ) ) for name , obj in a... | Imports a module from filename as a string returns the contained Assistant object |
21,762 | def _annotate_params ( self , word ) : annotation = { } annotation [ 'text' ] = word annotation [ 'meta' ] = '@' + self . entity_map [ word ] annotation [ 'alias' ] = self . entity_map [ word ] . replace ( 'sys.' , '' ) annotation [ 'userDefined' ] = True self . data . append ( annotation ) | Annotates a given word for the UserSays data field of an Intent object . |
21,763 | def app_intents ( self ) : from_app = [ ] for intent_name in self . assist . _intent_action_funcs : intent = self . build_intent ( intent_name ) from_app . append ( intent ) return from_app | Returns a list of Intent objects created from the assistant s acion functions |
21,764 | def build_intent ( self , intent_name ) : is_fallback = self . assist . _intent_fallbacks [ intent_name ] contexts = self . assist . _required_contexts [ intent_name ] events = self . assist . _intent_events [ intent_name ] new_intent = Intent ( intent_name , fallback_intent = is_fallback , contexts = contexts , events... | Builds an Intent object of the given name |
21,765 | def parse_params ( self , intent_name ) : params = [ ] action_func = self . assist . _intent_action_funcs [ intent_name ] [ 0 ] argspec = inspect . getargspec ( action_func ) param_entity_map = self . assist . _intent_mappings . get ( intent_name ) args , defaults = argspec . args , argspec . defaults default_map = { }... | Parses params from an intent s action decorator and view function . |
21,766 | def push_intent ( self , intent ) : if intent . id : print ( 'Updating {} intent' . format ( intent . name ) ) self . update ( intent ) else : print ( 'Registering {} intent' . format ( intent . name ) ) intent = self . register ( intent ) return intent | Registers or updates an intent and returns the intent_json with an ID |
21,767 | def register ( self , intent ) : response = self . api . post_intent ( intent . serialize ) print ( response ) print ( ) if response [ 'status' ] [ 'code' ] == 200 : intent . id = response [ 'id' ] elif response [ 'status' ] [ 'code' ] == 409 : intent . id = next ( i . id for i in self . api . agent_intents if i . name... | Registers a new intent and returns the Intent object with an ID |
21,768 | def register ( self , entity ) : response = self . api . post_entity ( entity . serialize ) print ( response ) print ( ) if response [ 'status' ] [ 'code' ] == 200 : entity . id = response [ 'id' ] if response [ 'status' ] [ 'code' ] == 409 : entity . id = next ( i . id for i in self . api . agent_entities if i . name ... | Registers a new entity and returns the entity object with an ID |
21,769 | def push_entity ( self , entity ) : if entity . id : print ( 'Updating {} entity' . format ( entity . name ) ) self . update ( entity ) else : print ( 'Registering {} entity' . format ( entity . name ) ) entity = self . register ( entity ) return entity | Registers or updates an entity and returns the entity_json with an ID |
21,770 | def set_state ( self , entity_id , new_state , ** kwargs ) : "Updates or creates the current state of an entity." return remote . set_state ( self . api , new_state , ** kwargs ) | Updates or creates the current state of an entity . |
21,771 | def is_state ( self , entity_id , state ) : return remote . is_state ( self . api , entity_id , state ) | Checks if the entity has the given state |
21,772 | def etag ( self , etag ) : if not isinstance ( etag , bytes ) : etag = bytes ( etag , "utf-8" ) self . _etag . append ( etag ) | Set the ETag of the resource . |
21,773 | def payload ( self , p ) : if isinstance ( p , tuple ) : k = p [ 0 ] v = p [ 1 ] self . actual_content_type = k self . _payload [ k ] = v else : self . _payload = { defines . Content_types [ "text/plain" ] : p } | Set the payload of the resource . |
21,774 | def content_type ( self ) : value = "" lst = self . _attributes . get ( "ct" ) if lst is not None and len ( lst ) > 0 : value = "ct=" for v in lst : value += str ( v ) + " " if len ( value ) > 0 : value = value [ : - 1 ] return value | Get the CoRE Link Format ct attribute of the resource . |
21,775 | def content_type ( self , lst ) : value = [ ] if isinstance ( lst , str ) : ct = defines . Content_types [ lst ] self . add_content_type ( ct ) elif isinstance ( lst , list ) : for ct in lst : self . add_content_type ( ct ) | Set the CoRE Link Format ct attribute of the resource . |
21,776 | def add_content_type ( self , ct ) : lst = self . _attributes . get ( "ct" ) if lst is None : lst = [ ] if isinstance ( ct , str ) : ct = defines . Content_types [ ct ] lst . append ( ct ) self . _attributes [ "ct" ] = lst | Add a CoRE Link Format ct attribute to the resource . |
21,777 | def resource_type ( self ) : value = "rt=" lst = self . _attributes . get ( "rt" ) if lst is None : value = "" else : value += "\"" + str ( lst ) + "\"" return value | Get the CoRE Link Format rt attribute of the resource . |
21,778 | def resource_type ( self , rt ) : if not isinstance ( rt , str ) : rt = str ( rt ) self . _attributes [ "rt" ] = rt | Set the CoRE Link Format rt attribute of the resource . |
21,779 | def interface_type ( self ) : value = "if=" lst = self . _attributes . get ( "if" ) if lst is None : value = "" else : value += "\"" + str ( lst ) + "\"" return value | Get the CoRE Link Format if attribute of the resource . |
21,780 | def interface_type ( self , ift ) : if not isinstance ( ift , str ) : ift = str ( ift ) self . _attributes [ "if" ] = ift | Set the CoRE Link Format if attribute of the resource . |
21,781 | def maximum_size_estimated ( self ) : value = "sz=" lst = self . _attributes . get ( "sz" ) if lst is None : value = "" else : value += "\"" + str ( lst ) + "\"" return value | Get the CoRE Link Format sz attribute of the resource . |
21,782 | def maximum_size_estimated ( self , sz ) : if not isinstance ( sz , str ) : sz = str ( sz ) self . _attributes [ "sz" ] = sz | Set the CoRE Link Format sz attribute of the resource . |
21,783 | def init_resource ( self , request , res ) : res . location_query = request . uri_query res . payload = ( request . content_type , request . payload ) return res | Helper function to initialize a new resource . |
21,784 | def edit_resource ( self , request ) : self . location_query = request . uri_query self . payload = ( request . content_type , request . payload ) | Helper function to edit a resource |
21,785 | def receive_request ( self , transaction ) : if transaction . request . block2 is not None : host , port = transaction . request . source key_token = hash ( str ( host ) + str ( port ) + str ( transaction . request . token ) ) num , m , size = transaction . request . block2 if key_token in self . _block2_receive : self... | Handles the Blocks option in a incoming request . |
21,786 | def send_response ( self , transaction ) : host , port = transaction . request . source key_token = hash ( str ( host ) + str ( port ) + str ( transaction . request . token ) ) if ( key_token in self . _block2_receive and transaction . response . payload is not None ) or ( transaction . response . payload is not None a... | Handles the Blocks option in a outgoing response . |
21,787 | def send_request ( self , request ) : assert isinstance ( request , Request ) if request . block1 or ( request . payload is not None and len ( request . payload ) > defines . MAX_PAYLOAD ) : host , port = request . destination key_token = hash ( str ( host ) + str ( port ) + str ( request . token ) ) if request . block... | Handles the Blocks option in a outgoing request . |
21,788 | def incomplete ( transaction ) : transaction . block_transfer = True transaction . response = Response ( ) transaction . response . destination = transaction . request . source transaction . response . token = transaction . request . token transaction . response . code = defines . Codes . REQUEST_ENTITY_INCOMPLETE . nu... | Notifies incomplete blockwise exchange . |
21,789 | def error ( transaction , code ) : transaction . block_transfer = True transaction . response = Response ( ) transaction . response . destination = transaction . request . source transaction . response . type = defines . Types [ "RST" ] transaction . response . token = transaction . request . token transaction . respon... | Notifies generic error on blockwise exchange . |
21,790 | def send_request ( self , request ) : if request . observe == 0 : host , port = request . destination key_token = hash ( str ( host ) + str ( port ) + str ( request . token ) ) self . _relations [ key_token ] = ObserveItem ( time . time ( ) , None , True , None ) return request | Add itself to the observing list |
21,791 | def receive_response ( self , transaction ) : host , port = transaction . response . source key_token = hash ( str ( host ) + str ( port ) + str ( transaction . response . token ) ) if key_token in self . _relations and transaction . response . type == defines . Types [ "CON" ] : transaction . notification = True retur... | Sets notification s parameters . |
21,792 | def send_empty ( self , message ) : host , port = message . destination key_token = hash ( str ( host ) + str ( port ) + str ( message . token ) ) if key_token in self . _relations and message . type == defines . Types [ "RST" ] : del self . _relations [ key_token ] return message | Eventually remove from the observer list in case of a RST message . |
21,793 | def receive_request ( self , transaction ) : if transaction . request . observe == 0 : host , port = transaction . request . source key_token = hash ( str ( host ) + str ( port ) + str ( transaction . request . token ) ) non_counter = 0 if key_token in self . _relations : allowed = True else : allowed = False self . _r... | Manage the observe option in the request end eventually initialize the client for adding to the list of observers or remove from the list . |
21,794 | def receive_empty ( self , empty , transaction ) : if empty . type == defines . Types [ "RST" ] : host , port = transaction . request . source key_token = hash ( str ( host ) + str ( port ) + str ( transaction . request . token ) ) logger . info ( "Remove Subscriber" ) try : del self . _relations [ key_token ] except K... | Manage the observe feature to remove a client in case of a RST message receveide in reply to a notification . |
21,795 | def send_response ( self , transaction ) : host , port = transaction . request . source key_token = hash ( str ( host ) + str ( port ) + str ( transaction . request . token ) ) if key_token in self . _relations : if transaction . response . code == defines . Codes . CONTENT . number : if transaction . resource is not N... | Finalize to add the client to the list of observer . |
21,796 | def notify ( self , resource , root = None ) : ret = [ ] if root is not None : resource_list = root . with_prefix_resource ( resource . path ) else : resource_list = [ resource ] for key in list ( self . _relations . keys ( ) ) : if self . _relations [ key ] . transaction . resource in resource_list : if self . _relati... | Prepare notification for the resource to all interested observers . |
21,797 | def remove_subscriber ( self , message ) : logger . debug ( "Remove Subcriber" ) host , port = message . destination key_token = hash ( str ( host ) + str ( port ) + str ( message . token ) ) try : self . _relations [ key_token ] . transaction . completed = True del self . _relations [ key_token ] except KeyError : log... | Remove a subscriber based on token . |
21,798 | def purge ( self ) : while not self . stopped . isSet ( ) : self . stopped . wait ( timeout = defines . EXCHANGE_LIFETIME ) self . _messageLayer . purge ( ) | Clean old transactions |
21,799 | def send_datagram ( self , message ) : if not self . stopped . isSet ( ) : host , port = message . destination logger . debug ( "send_datagram - " + str ( message ) ) serializer = Serializer ( ) message = serializer . serialize ( message ) self . _socket . sendto ( message , ( host , port ) ) | Send a message through the udp socket . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.