idx int64 0 252k | question stringlengths 48 5.28k | target stringlengths 5 1.23k |
|---|---|---|
238,700 | def search ( self , q , resolve = True , result_type = None , account_id = None , offset = None , min_id = None , max_id = None ) : return self . search_v2 ( q , resolve = resolve , result_type = result_type , account_id = account_id , offset = offset , min_id = min_id , max_id = max_id ) | Fetch matching hashtags accounts and statuses . Will perform webfinger lookups if resolve is True . Full - text search is only enabled if the instance supports it and is restricted to statuses the logged - in user wrote or was mentioned in . result_type can be one of accounts hashtags or statuses to only search for tha... |
238,701 | def list ( self , id ) : id = self . __unpack_id ( id ) return self . __api_request ( 'GET' , '/api/v1/lists/{0}' . format ( id ) ) | Fetch info about a specific list . Returns a list dict _ . |
238,702 | def list_accounts ( self , id , max_id = None , min_id = None , since_id = None , limit = None ) : id = self . __unpack_id ( id ) if max_id != None : max_id = self . __unpack_id ( max_id ) if min_id != None : min_id = self . __unpack_id ( min_id ) if since_id != None : since_id = self . __unpack_id ( since_id ) params ... | Get the accounts that are on the given list . A limit of 0 can be specified to get all accounts without pagination . Returns a list of user dicts _ . |
238,703 | def status_reply ( self , to_status , status , media_ids = None , sensitive = False , visibility = None , spoiler_text = None , language = None , idempotency_key = None , content_type = None , scheduled_at = None , poll = None , untag = False ) : user_id = self . __get_logged_in_id ( ) mentioned_accounts = collections ... | Helper function - acts like status_post but prepends the name of all the users that are being replied to to the status text and retains CW and visibility if not explicitly overridden . Set untag to True if you want the reply to only go to the user you are replying to removing every other mentioned user from the convers... |
238,704 | def status_delete ( self , id ) : id = self . __unpack_id ( id ) url = '/api/v1/statuses/{0}' . format ( str ( id ) ) self . __api_request ( 'DELETE' , url ) | Delete a status |
238,705 | def status_unreblog ( self , id ) : id = self . __unpack_id ( id ) url = '/api/v1/statuses/{0}/unreblog' . format ( str ( id ) ) return self . __api_request ( 'POST' , url ) | Un - reblog a status . |
238,706 | def status_favourite ( self , id ) : id = self . __unpack_id ( id ) url = '/api/v1/statuses/{0}/favourite' . format ( str ( id ) ) return self . __api_request ( 'POST' , url ) | Favourite a status . |
238,707 | def status_unfavourite ( self , id ) : id = self . __unpack_id ( id ) url = '/api/v1/statuses/{0}/unfavourite' . format ( str ( id ) ) return self . __api_request ( 'POST' , url ) | Un - favourite a status . |
238,708 | def status_mute ( self , id ) : id = self . __unpack_id ( id ) url = '/api/v1/statuses/{0}/mute' . format ( str ( id ) ) return self . __api_request ( 'POST' , url ) | Mute notifications for a status . |
238,709 | def status_unmute ( self , id ) : id = self . __unpack_id ( id ) url = '/api/v1/statuses/{0}/unmute' . format ( str ( id ) ) return self . __api_request ( 'POST' , url ) | Unmute notifications for a status . |
238,710 | def status_pin ( self , id ) : id = self . __unpack_id ( id ) url = '/api/v1/statuses/{0}/pin' . format ( str ( id ) ) return self . __api_request ( 'POST' , url ) | Pin a status for the logged - in user . |
238,711 | def status_unpin ( self , id ) : id = self . __unpack_id ( id ) url = '/api/v1/statuses/{0}/unpin' . format ( str ( id ) ) return self . __api_request ( 'POST' , url ) | Unpin a pinned status for the logged - in user . |
238,712 | def scheduled_status_update ( self , id , scheduled_at ) : scheduled_at = self . __consistent_isoformat_utc ( scheduled_at ) id = self . __unpack_id ( id ) params = self . __generate_params ( locals ( ) , [ 'id' ] ) url = '/api/v1/scheduled_statuses/{0}' . format ( str ( id ) ) return self . __api_request ( 'PUT' , url... | Update the scheduled time of a scheduled status . New time must be at least 5 minutes into the future . Returns a scheduled toot dict _ |
238,713 | def scheduled_status_delete ( self , id ) : id = self . __unpack_id ( id ) url = '/api/v1/scheduled_statuses/{0}' . format ( str ( id ) ) self . __api_request ( 'DELETE' , url ) | Deletes a scheduled status . |
238,714 | def poll_vote ( self , id , choices ) : id = self . __unpack_id ( id ) if not isinstance ( choices , list ) : choices = [ choices ] params = self . __generate_params ( locals ( ) , [ 'id' ] ) url = '/api/v1/polls/{0}/votes' . format ( id ) self . __api_request ( 'POST' , url , params ) | Vote in the given poll . choices is the index of the choice you wish to register a vote for ( i . e . its index in the corresponding polls options field . In case of a poll that allows selection of more than one option a list of indices can be passed . You can only submit choices for any given poll once in case of sing... |
238,715 | def notifications_dismiss ( self , id ) : id = self . __unpack_id ( id ) params = self . __generate_params ( locals ( ) ) self . __api_request ( 'POST' , '/api/v1/notifications/dismiss' , params ) | Deletes a single notification |
238,716 | def account_block ( self , id ) : id = self . __unpack_id ( id ) url = '/api/v1/accounts/{0}/block' . format ( str ( id ) ) return self . __api_request ( 'POST' , url ) | Block a user . |
238,717 | def account_unblock ( self , id ) : id = self . __unpack_id ( id ) url = '/api/v1/accounts/{0}/unblock' . format ( str ( id ) ) return self . __api_request ( 'POST' , url ) | Unblock a user . |
238,718 | def account_mute ( self , id , notifications = True ) : id = self . __unpack_id ( id ) params = self . __generate_params ( locals ( ) , [ 'id' ] ) url = '/api/v1/accounts/{0}/mute' . format ( str ( id ) ) return self . __api_request ( 'POST' , url , params ) | Mute a user . |
238,719 | def account_unmute ( self , id ) : id = self . __unpack_id ( id ) url = '/api/v1/accounts/{0}/unmute' . format ( str ( id ) ) return self . __api_request ( 'POST' , url ) | Unmute a user . |
238,720 | def account_update_credentials ( self , display_name = None , note = None , avatar = None , avatar_mime_type = None , header = None , header_mime_type = None , locked = None , fields = None ) : params_initial = collections . OrderedDict ( locals ( ) ) if not avatar is None : if avatar_mime_type is None and ( isinstance... | Update the profile for the currently logged - in user . |
238,721 | def filter_create ( self , phrase , context , irreversible = False , whole_word = True , expires_in = None ) : params = self . __generate_params ( locals ( ) ) for context_val in context : if not context_val in [ 'home' , 'notifications' , 'public' , 'thread' ] : raise MastodonIllegalArgumentError ( 'Invalid filter con... | Creates a new keyword filter . phrase is the phrase that should be filtered out context specifies from where to filter the keywords . Valid contexts are home notifications public and thread . Set irreversible to True if you want the filter to just delete statuses server side . This works only for the home and notificat... |
238,722 | def filter_delete ( self , id ) : id = self . __unpack_id ( id ) url = '/api/v1/filters/{0}' . format ( str ( id ) ) self . __api_request ( 'DELETE' , url ) | Deletes the filter with the given id . |
238,723 | def suggestion_delete ( self , account_id ) : account_id = self . __unpack_id ( account_id ) url = '/api/v1/suggestions/{0}' . format ( str ( account_id ) ) self . __api_request ( 'DELETE' , url ) | Remove the user with the given account_id from the follow suggestions . |
238,724 | def list_create ( self , title ) : params = self . __generate_params ( locals ( ) ) return self . __api_request ( 'POST' , '/api/v1/lists' , params ) | Create a new list with the given title . Returns the list dict _ of the created list . |
238,725 | def list_update ( self , id , title ) : id = self . __unpack_id ( id ) params = self . __generate_params ( locals ( ) , [ 'id' ] ) return self . __api_request ( 'PUT' , '/api/v1/lists/{0}' . format ( id ) , params ) | Update info about a list where info is really the lists title . Returns the list dict _ of the modified list . |
238,726 | def list_delete ( self , id ) : id = self . __unpack_id ( id ) self . __api_request ( 'DELETE' , '/api/v1/lists/{0}' . format ( id ) ) | Delete a list . |
238,727 | def report ( self , account_id , status_ids = None , comment = None , forward = False ) : account_id = self . __unpack_id ( account_id ) if not status_ids is None : if not isinstance ( status_ids , list ) : status_ids = [ status_ids ] status_ids = list ( map ( lambda x : self . __unpack_id ( x ) , status_ids ) ) params... | Report statuses to the instances administrators . |
238,728 | def follow_request_authorize ( self , id ) : id = self . __unpack_id ( id ) url = '/api/v1/follow_requests/{0}/authorize' . format ( str ( id ) ) self . __api_request ( 'POST' , url ) | Accept an incoming follow request . |
238,729 | def follow_request_reject ( self , id ) : id = self . __unpack_id ( id ) url = '/api/v1/follow_requests/{0}/reject' . format ( str ( id ) ) self . __api_request ( 'POST' , url ) | Reject an incoming follow request . |
238,730 | def domain_block ( self , domain = None ) : params = self . __generate_params ( locals ( ) ) self . __api_request ( 'POST' , '/api/v1/domain_blocks' , params ) | Add a block for all statuses originating from the specified domain for the logged - in user . |
238,731 | def domain_unblock ( self , domain = None ) : params = self . __generate_params ( locals ( ) ) self . __api_request ( 'DELETE' , '/api/v1/domain_blocks' , params ) | Remove a domain block for the logged - in user . |
238,732 | def push_subscription_update ( self , follow_events = None , favourite_events = None , reblog_events = None , mention_events = None ) : params = { } if follow_events != None : params [ 'data[alerts][follow]' ] = follow_events if favourite_events != None : params [ 'data[alerts][favourite]' ] = favourite_events if reblo... | Modifies what kind of events the app wishes to subscribe to . Returns the updated push subscription dict _ . |
238,733 | def stream_user ( self , listener , run_async = False , timeout = __DEFAULT_STREAM_TIMEOUT , reconnect_async = False , reconnect_async_wait_sec = __DEFAULT_STREAM_RECONNECT_WAIT_SEC ) : return self . __stream ( '/api/v1/streaming/user' , listener , run_async = run_async , timeout = timeout , reconnect_async = reconnect... | Streams events that are relevant to the authorized user i . e . home timeline and notifications . |
238,734 | def stream_hashtag ( self , tag , listener , run_async = False , timeout = __DEFAULT_STREAM_TIMEOUT , reconnect_async = False , reconnect_async_wait_sec = __DEFAULT_STREAM_RECONNECT_WAIT_SEC ) : if tag . startswith ( "#" ) : raise MastodonIllegalArgumentError ( "Tag parameter should omit leading #" ) return self . __st... | Stream for all public statuses for the hashtag tag seen by the connected instance . |
238,735 | def stream_list ( self , id , listener , run_async = False , timeout = __DEFAULT_STREAM_TIMEOUT , reconnect_async = False , reconnect_async_wait_sec = __DEFAULT_STREAM_RECONNECT_WAIT_SEC ) : id = self . __unpack_id ( id ) return self . __stream ( "/api/v1/streaming/list?list={}" . format ( id ) , listener , run_async =... | Stream events for the current user restricted to accounts on the given list . |
238,736 | def __datetime_to_epoch ( self , date_time ) : date_time_utc = None if date_time . tzinfo is None : date_time_utc = date_time . replace ( tzinfo = pytz . utc ) else : date_time_utc = date_time . astimezone ( pytz . utc ) epoch_utc = datetime . datetime . utcfromtimestamp ( 0 ) . replace ( tzinfo = pytz . utc ) return (... | Converts a python datetime to unix epoch accounting for time zones and such . |
238,737 | def __get_logged_in_id ( self ) : if self . __logged_in_id == None : self . __logged_in_id = self . account_verify_credentials ( ) . id return self . __logged_in_id | Fetch the logged in users ID with caching . ID is reset on calls to log_in . |
238,738 | def __json_date_parse ( json_object ) : known_date_fields = [ "created_at" , "week" , "day" , "expires_at" , "scheduled_at" ] for k , v in json_object . items ( ) : if k in known_date_fields : if v != None : try : if isinstance ( v , int ) : json_object [ k ] = datetime . datetime . fromtimestamp ( v , pytz . utc ) els... | Parse dates in certain known json fields if possible . |
238,739 | def __json_strnum_to_bignum ( json_object ) : for key in ( 'id' , 'week' , 'in_reply_to_id' , 'in_reply_to_account_id' , 'logins' , 'registrations' , 'statuses' ) : if ( key in json_object and isinstance ( json_object [ key ] , six . text_type ) ) : try : json_object [ key ] = int ( json_object [ key ] ) except ValueEr... | Converts json string numerals to native python bignums . |
238,740 | def __json_hooks ( json_object ) : json_object = Mastodon . __json_strnum_to_bignum ( json_object ) json_object = Mastodon . __json_date_parse ( json_object ) json_object = Mastodon . __json_truefalse_parse ( json_object ) json_object = Mastodon . __json_allow_dict_attrs ( json_object ) return json_object | All the json hooks . Used in request parsing . |
238,741 | def __consistent_isoformat_utc ( datetime_val ) : isotime = datetime_val . astimezone ( pytz . utc ) . strftime ( "%Y-%m-%dT%H:%M:%S%z" ) if isotime [ - 2 ] != ":" : isotime = isotime [ : - 2 ] + ":" + isotime [ - 2 : ] return isotime | Function that does what isoformat does but it actually does the same every time instead of randomly doing different things on some systems and also it represents that time as the equivalent UTC time . |
238,742 | def __generate_params ( self , params , exclude = [ ] ) : params = collections . OrderedDict ( params ) del params [ 'self' ] param_keys = list ( params . keys ( ) ) for key in param_keys : if isinstance ( params [ key ] , bool ) and params [ key ] == False : params [ key ] = '0' if isinstance ( params [ key ] , bool )... | Internal named - parameters - to - dict helper . |
238,743 | def __decode_webpush_b64 ( self , data ) : missing_padding = len ( data ) % 4 if missing_padding != 0 : data += '=' * ( 4 - missing_padding ) return base64 . urlsafe_b64decode ( data ) | Re - pads and decodes urlsafe base64 . |
238,744 | def __set_token_expired ( self , value ) : self . _token_expired = datetime . datetime . now ( ) + datetime . timedelta ( seconds = value ) return | Internal helper for oauth code |
238,745 | def __protocolize ( base_url ) : if not base_url . startswith ( "http://" ) and not base_url . startswith ( "https://" ) : base_url = "https://" + base_url base_url = base_url . rstrip ( "/" ) return base_url | Internal add - protocol - to - url helper |
238,746 | def status ( self ) : if self . report == None : return SentSms . ENROUTE else : return SentSms . DELIVERED if self . report . deliveryStatus == StatusReport . DELIVERED else SentSms . FAILED | Status of this SMS . Can be ENROUTE DELIVERED or FAILED The actual status report object may be accessed via the report attribute if status is DELIVERED or FAILED |
238,747 | def write ( self , data , waitForResponse = True , timeout = 5 , parseError = True , writeTerm = '\r' , expectedResponseTermSeq = None ) : self . log . debug ( 'write: %s' , data ) responseLines = super ( GsmModem , self ) . write ( data + writeTerm , waitForResponse = waitForResponse , timeout = timeout , expectedResp... | Write data to the modem . |
238,748 | def smsTextMode ( self , textMode ) : if textMode != self . _smsTextMode : if self . alive : self . write ( 'AT+CMGF={0}' . format ( 1 if textMode else 0 ) ) self . _smsTextMode = textMode self . _compileSmsRegexes ( ) | Set to True for the modem to use text mode for SMS or False for it to use PDU mode |
238,749 | def _compileSmsRegexes ( self ) : if self . _smsTextMode : if self . CMGR_SM_DELIVER_REGEX_TEXT == None : self . CMGR_SM_DELIVER_REGEX_TEXT = re . compile ( r'^\+CMGR: "([^"]+)","([^"]+)",[^,]*,"([^"]+)"$' ) self . CMGR_SM_REPORT_REGEXT_TEXT = re . compile ( r'^\+CMGR: ([^,]*),\d+,(\d+),"{0,1}([^"]*)"{0,1},\d*,"([^"]+)... | Compiles regular expression used for parsing SMS messages based on current mode |
238,750 | def smsc ( self , smscNumber ) : if smscNumber != self . _smscNumber : if self . alive : self . write ( 'AT+CSCA="{0}"' . format ( smscNumber ) ) self . _smscNumber = smscNumber | Set the default SMSC number to use when sending SMS messages |
238,751 | def dial ( self , number , timeout = 5 , callStatusUpdateCallbackFunc = None ) : if self . _waitForCallInitUpdate : self . _dialEvent = threading . Event ( ) try : self . write ( 'ATD{0};' . format ( number ) , timeout = timeout , waitForResponse = self . _waitForAtdResponse ) except Exception : self . _dialEvent = Non... | Calls the specified phone number using a voice phone call |
238,752 | def _handleCallInitiated ( self , regexMatch , callId = None , callType = 1 ) : if self . _dialEvent : if regexMatch : groups = regexMatch . groups ( ) if len ( groups ) >= 2 : self . _dialResponse = ( int ( groups [ 0 ] ) , int ( groups [ 1 ] ) ) else : self . _dialResponse = ( int ( groups [ 0 ] ) , 1 ) else : self .... | Handler for outgoing call initiated event notification line |
238,753 | def _handleCallAnswered ( self , regexMatch , callId = None ) : if regexMatch : groups = regexMatch . groups ( ) if len ( groups ) > 1 : callId = int ( groups [ 0 ] ) self . activeCalls [ callId ] . answered = True else : for call in dictValuesIter ( self . activeCalls ) : if call . answered == False and type ( call ) ... | Handler for outgoing call answered event notification line |
238,754 | def _handleSmsReceived ( self , notificationLine ) : self . log . debug ( 'SMS message received' ) cmtiMatch = self . CMTI_REGEX . match ( notificationLine ) if cmtiMatch : msgMemory = cmtiMatch . group ( 1 ) msgIndex = cmtiMatch . group ( 2 ) sms = self . readStoredSms ( msgIndex , msgMemory ) self . deleteStoredSms (... | Handler for new SMS unsolicited notification line |
238,755 | def _handleSmsStatusReport ( self , notificationLine ) : self . log . debug ( 'SMS status report received' ) cdsiMatch = self . CDSI_REGEX . match ( notificationLine ) if cdsiMatch : msgMemory = cdsiMatch . group ( 1 ) msgIndex = cdsiMatch . group ( 2 ) report = self . readStoredSms ( msgIndex , msgMemory ) self . dele... | Handler for SMS status reports |
238,756 | def hangup ( self ) : if self . active : self . _gsmModem . write ( 'ATH' ) self . answered = False self . active = False if self . id in self . _gsmModem . activeCalls : del self . _gsmModem . activeCalls [ self . id ] | End the phone call . Does nothing if the call is already inactive . |
238,757 | def _color ( self , color , msg ) : if self . useColor : return '{0}{1}{2}' . format ( color , msg , self . RESET_SEQ ) else : return msg | Converts a message to be printed to the user s terminal in red |
238,758 | def _cursorLeft ( self ) : if self . cursorPos > 0 : self . cursorPos -= 1 sys . stdout . write ( console . CURSOR_LEFT ) sys . stdout . flush ( ) | Handles cursor left events |
238,759 | def _cursorRight ( self ) : if self . cursorPos < len ( self . inputBuffer ) : self . cursorPos += 1 sys . stdout . write ( console . CURSOR_RIGHT ) sys . stdout . flush ( ) | Handles cursor right events |
238,760 | def _cursorUp ( self ) : if self . historyPos > 0 : self . historyPos -= 1 clearLen = len ( self . inputBuffer ) self . inputBuffer = list ( self . history [ self . historyPos ] ) self . cursorPos = len ( self . inputBuffer ) self . _refreshInputPrompt ( clearLen ) | Handles cursor up events |
238,761 | def _handleBackspace ( self ) : if self . cursorPos > 0 : self . inputBuffer = self . inputBuffer [ 0 : self . cursorPos - 1 ] + self . inputBuffer [ self . cursorPos : ] self . cursorPos -= 1 self . _refreshInputPrompt ( len ( self . inputBuffer ) + 1 ) | Handles backspace characters |
238,762 | def _handleDelete ( self ) : if self . cursorPos < len ( self . inputBuffer ) : self . inputBuffer = self . inputBuffer [ 0 : self . cursorPos ] + self . inputBuffer [ self . cursorPos + 1 : ] self . _refreshInputPrompt ( len ( self . inputBuffer ) + 1 ) | Handles delete characters |
238,763 | def _handleEnd ( self ) : self . cursorPos = len ( self . inputBuffer ) self . _refreshInputPrompt ( len ( self . inputBuffer ) ) | Handles end character |
238,764 | def _doCommandCompletion ( self ) : prefix = '' . join ( self . inputBuffer ) . strip ( ) . upper ( ) matches = self . completion . keys ( prefix ) matchLen = len ( matches ) if matchLen == 0 and prefix [ - 1 ] == '=' : try : command = prefix [ : - 1 ] except KeyError : pass else : self . __printCommandSyntax ( command... | Command - completion method |
238,765 | def connect ( self ) : self . serial = serial . Serial ( port = self . port , baudrate = self . baudrate , timeout = self . timeout ) self . alive = True self . rxThread = threading . Thread ( target = self . _readLoop ) self . rxThread . daemon = True self . rxThread . start ( ) | Connects to the device and starts the read thread |
238,766 | def close ( self ) : self . alive = False self . rxThread . join ( ) self . serial . close ( ) | Stops the read thread waits for it to exit cleanly then closes the underlying serial port |
238,767 | def _readLoop ( self ) : try : readTermSeq = list ( self . RX_EOL_SEQ ) readTermLen = len ( readTermSeq ) rxBuffer = [ ] while self . alive : data = self . serial . read ( 1 ) if data != '' : rxBuffer . append ( data ) if rxBuffer [ - readTermLen : ] == readTermSeq : line = '' . join ( rxBuffer [ : - readTermLen ] ) rx... | Read thread main loop Reads lines from the connected device |
238,768 | def _decodeTimestamp ( byteIter ) : dateStr = decodeSemiOctets ( byteIter , 7 ) timeZoneStr = dateStr [ - 2 : ] return datetime . strptime ( dateStr [ : - 2 ] , '%y%m%d%H%M%S' ) . replace ( tzinfo = SmsPduTzInfo ( timeZoneStr ) ) | Decodes a 7 - octet timestamp |
238,769 | def decodeUcs2 ( byteIter , numBytes ) : userData = [ ] i = 0 try : while i < numBytes : userData . append ( unichr ( ( next ( byteIter ) << 8 ) | next ( byteIter ) ) ) i += 2 except StopIteration : pass return '' . join ( userData ) | Decodes UCS2 - encoded text from the specified byte iterator up to a maximum of numBytes |
238,770 | def encode ( self ) : result = bytearray ( ) result . append ( self . id ) result . append ( self . dataLength ) result . extend ( self . data ) return result | Encodes this IE and returns the resulting bytes |
238,771 | def parseArgsPy26 ( ) : from gsmtermlib . posoptparse import PosOptionParser , Option parser = PosOptionParser ( description = 'Simple script for sending SMS messages' ) parser . add_option ( '-i' , '--port' , metavar = 'PORT' , help = 'port to which the GSM modem is connected; a number or a device name.' ) parser . ad... | Argument parser for Python 2 . 6 |
238,772 | def lineMatching ( regexStr , lines ) : regex = re . compile ( regexStr ) for line in lines : m = regex . match ( line ) if m : return m else : return None | Searches through the specified list of strings and returns the regular expression match for the first line that matches the specified regex string or None if no match was found |
238,773 | def lineMatchingPattern ( pattern , lines ) : for line in lines : m = pattern . match ( line ) if m : return m else : return None | Searches through the specified list of strings and returns the regular expression match for the first line that matches the specified pre - compiled regex pattern or None if no match was found |
238,774 | def allLinesMatchingPattern ( pattern , lines ) : result = [ ] for line in lines : m = pattern . match ( line ) if m : result . append ( m ) return result | Like lineMatchingPattern but returns all lines that match the specified pattern |
238,775 | def clean ( decrypted : bytes ) -> str : r last = decrypted [ - 1 ] if isinstance ( last , int ) : return decrypted [ : - last ] . decode ( 'utf8' ) return decrypted [ : - ord ( last ) ] . decode ( 'utf8' ) | r Strip padding from decrypted value . |
238,776 | def set_pattern_step_setpoint ( self , patternnumber , stepnumber , setpointvalue ) : _checkPatternNumber ( patternnumber ) _checkStepNumber ( stepnumber ) _checkSetpointValue ( setpointvalue , self . setpoint_max ) address = _calculateRegisterAddress ( 'setpoint' , patternnumber , stepnumber ) self . write_register ( ... | Set the setpoint value for a step . |
238,777 | def get_pattern_step_time ( self , patternnumber , stepnumber ) : _checkPatternNumber ( patternnumber ) _checkStepNumber ( stepnumber ) address = _calculateRegisterAddress ( 'time' , patternnumber , stepnumber ) return self . read_register ( address , 0 ) | Get the step time . |
238,778 | def set_pattern_step_time ( self , patternnumber , stepnumber , timevalue ) : _checkPatternNumber ( patternnumber ) _checkStepNumber ( stepnumber ) _checkTimeValue ( timevalue , self . time_max ) address = _calculateRegisterAddress ( 'time' , patternnumber , stepnumber ) self . write_register ( address , timevalue , 0 ... | Set the step time . |
238,779 | def get_pattern_actual_step ( self , patternnumber ) : _checkPatternNumber ( patternnumber ) address = _calculateRegisterAddress ( 'actualstep' , patternnumber ) return self . read_register ( address , 0 ) | Get the actual step parameter for a given pattern . |
238,780 | def set_pattern_actual_step ( self , patternnumber , value ) : _checkPatternNumber ( patternnumber ) _checkStepNumber ( value ) address = _calculateRegisterAddress ( 'actualstep' , patternnumber ) self . write_register ( address , value , 0 ) | Set the actual step parameter for a given pattern . |
238,781 | def get_pattern_additional_cycles ( self , patternnumber ) : _checkPatternNumber ( patternnumber ) address = _calculateRegisterAddress ( 'cycles' , patternnumber ) return self . read_register ( address ) | Get the number of additional cycles for a given pattern . |
238,782 | def set_pattern_additional_cycles ( self , patternnumber , value ) : _checkPatternNumber ( patternnumber ) minimalmodbus . _checkInt ( value , minvalue = 0 , maxvalue = 99 , description = 'number of additional cycles' ) address = _calculateRegisterAddress ( 'cycles' , patternnumber ) self . write_register ( address , v... | Set the number of additional cycles for a given pattern . |
238,783 | def get_pattern_link_topattern ( self , patternnumber ) : _checkPatternNumber ( patternnumber ) address = _calculateRegisterAddress ( 'linkpattern' , patternnumber ) return self . read_register ( address ) | Get the linked pattern value for a given pattern . |
238,784 | def get_all_pattern_variables ( self , patternnumber ) : _checkPatternNumber ( patternnumber ) outputstring = '' for stepnumber in range ( 8 ) : outputstring += 'SP{0}: {1} Time{0}: {2}\n' . format ( stepnumber , self . get_pattern_step_setpoint ( patternnumber , stepnumber ) , self . get_pattern_step_time ( patternnu... | Get all variables for a given pattern at one time . |
238,785 | def set_all_pattern_variables ( self , patternnumber , sp0 , ti0 , sp1 , ti1 , sp2 , ti2 , sp3 , ti3 , sp4 , ti4 , sp5 , ti5 , sp6 , ti6 , sp7 , ti7 , actual_step , additional_cycles , link_pattern ) : _checkPatternNumber ( patternnumber ) self . set_pattern_step_setpoint ( patternnumber , 0 , sp0 ) self . set_pattern_... | Set all variables for a given pattern at one time . |
238,786 | def close ( self ) : if VERBOSE : _print_out ( '\nDummy_serial: Closing port\n' ) if not self . _isOpen : raise IOError ( 'Dummy_serial: The port is already closed' ) self . _isOpen = False self . port = None | Close a port on dummy_serial . |
238,787 | def write ( self , inputdata ) : if VERBOSE : _print_out ( '\nDummy_serial: Writing to port. Given:' + repr ( inputdata ) + '\n' ) if sys . version_info [ 0 ] > 2 : if not type ( inputdata ) == bytes : raise TypeError ( 'The input must be type bytes. Given:' + repr ( inputdata ) ) inputstring = str ( inputdata , encodi... | Write to a port on dummy_serial . |
238,788 | def read ( self , numberOfBytes ) : if VERBOSE : _print_out ( '\nDummy_serial: Reading from port (max length {!r} bytes)' . format ( numberOfBytes ) ) if numberOfBytes < 0 : raise IOError ( 'Dummy_serial: The numberOfBytes to read must not be negative. Given: {!r}' . format ( numberOfBytes ) ) if not self . _isOpen : r... | Read from a port on dummy_serial . |
238,789 | def _embedPayload ( slaveaddress , mode , functioncode , payloaddata ) : _checkSlaveaddress ( slaveaddress ) _checkMode ( mode ) _checkFunctioncode ( functioncode , None ) _checkString ( payloaddata , description = 'payload' ) firstPart = _numToOneByteString ( slaveaddress ) + _numToOneByteString ( functioncode ) + pay... | Build a request from the slaveaddress the function code and the payload data . |
238,790 | def _extractPayload ( response , slaveaddress , mode , functioncode ) : BYTEPOSITION_FOR_ASCII_HEADER = 0 BYTEPOSITION_FOR_SLAVEADDRESS = 0 BYTEPOSITION_FOR_FUNCTIONCODE = 1 NUMBER_OF_RESPONSE_STARTBYTES = 2 NUMBER_OF_CRC_BYTES = 2 NUMBER_OF_LRC_BYTES = 1 BITNUMBER_FUNCTIONCODE_ERRORINDICATION = 7 MINIMAL_RESPONSE_LENG... | Extract the payload data part from the slave s response . |
238,791 | def _predictResponseSize ( mode , functioncode , payloadToSlave ) : MIN_PAYLOAD_LENGTH = 4 BYTERANGE_FOR_GIVEN_SIZE = slice ( 2 , 4 ) NUMBER_OF_PAYLOAD_BYTES_IN_WRITE_CONFIRMATION = 4 NUMBER_OF_PAYLOAD_BYTES_FOR_BYTECOUNTFIELD = 1 RTU_TO_ASCII_PAYLOAD_FACTOR = 2 NUMBER_OF_RTU_RESPONSE_STARTBYTES = 2 NUMBER_OF_RTU_RESPO... | Calculate the number of bytes that should be received from the slave . |
238,792 | def _calculate_minimum_silent_period ( baudrate ) : _checkNumerical ( baudrate , minvalue = 1 , description = 'baudrate' ) BITTIMES_PER_CHARACTERTIME = 11 MINIMUM_SILENT_CHARACTERTIMES = 3.5 bittime = 1 / float ( baudrate ) return bittime * BITTIMES_PER_CHARACTERTIME * MINIMUM_SILENT_CHARACTERTIMES | Calculate the silent period length to comply with the 3 . 5 character silence between messages . |
238,793 | def _numToTwoByteString ( value , numberOfDecimals = 0 , LsbFirst = False , signed = False ) : _checkNumerical ( value , description = 'inputvalue' ) _checkInt ( numberOfDecimals , minvalue = 0 , description = 'number of decimals' ) _checkBool ( LsbFirst , description = 'LsbFirst' ) _checkBool ( signed , description = ... | Convert a numerical value to a two - byte string possibly scaling it . |
238,794 | def _twoByteStringToNum ( bytestring , numberOfDecimals = 0 , signed = False ) : _checkString ( bytestring , minlength = 2 , maxlength = 2 , description = 'bytestring' ) _checkInt ( numberOfDecimals , minvalue = 0 , description = 'number of decimals' ) _checkBool ( signed , description = 'signed parameter' ) formatcode... | Convert a two - byte string to a numerical value possibly scaling it . |
238,795 | def _pack ( formatstring , value ) : _checkString ( formatstring , description = 'formatstring' , minlength = 1 ) try : result = struct . pack ( formatstring , value ) except : errortext = 'The value to send is probably out of range, as the num-to-bytestring conversion failed.' errortext += ' Value: {0!r} Struct format... | Pack a value into a bytestring . |
238,796 | def _unpack ( formatstring , packed ) : _checkString ( formatstring , description = 'formatstring' , minlength = 1 ) _checkString ( packed , description = 'packed string' , minlength = 1 ) if sys . version_info [ 0 ] > 2 : packed = bytes ( packed , encoding = 'latin1' ) try : value = struct . unpack ( formatstring , pa... | Unpack a bytestring into a value . |
238,797 | def _hexencode ( bytestring , insert_spaces = False ) : _checkString ( bytestring , description = 'byte string' ) separator = '' if not insert_spaces else ' ' byte_representions = [ ] for c in bytestring : byte_representions . append ( '{0:02X}' . format ( ord ( c ) ) ) return separator . join ( byte_representions ) . ... | Convert a byte string to a hex encoded string . |
238,798 | def _hexdecode ( hexstring ) : _checkString ( hexstring , description = 'hexstring' ) if len ( hexstring ) % 2 != 0 : raise ValueError ( 'The input hexstring must be of even length. Given: {!r}' . format ( hexstring ) ) if sys . version_info [ 0 ] > 2 : by = bytes ( hexstring , 'latin1' ) try : return str ( binascii . ... | Convert a hex encoded string to a byte string . |
238,799 | def _bitResponseToValue ( bytestring ) : _checkString ( bytestring , description = 'bytestring' , minlength = 1 , maxlength = 1 ) RESPONSE_ON = '\x01' RESPONSE_OFF = '\x00' if bytestring == RESPONSE_ON : return 1 elif bytestring == RESPONSE_OFF : return 0 else : raise ValueError ( 'Could not convert bit response to a v... | Convert a response string to a numerical value . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.