output
stringlengths
1
928k
instruction
stringlengths
7
928k
system
stringlengths
0
104k
Set a single style value for a view class and state.
Given the following Python 3 function, write the documentation def set(self, class_name, state, key, value): self._styles.setdefault(class_name, {}).setdefault(state, {}) self._styles[class_name][state][key] = value
You are a Python code generator, capable of creating scripts from specifications.
Returns the style dict for a given class and state.
Can you generate the documentation for the following Python 3 function def get_dict_for_class(self, class_name, state=None, base_name='View'): classes = [] klass = class_name while True: classes.append(klass) if klass.__name__ == base_name: break ...
As a Python code translator, you convert algorithms and pseudocode into Python.
Returns a dict of the style dict for a view instance.
Can you tell what is the following Python 3 function doing def get_dict(self, obj, state=None, base_name='View'): return self.get_dict_for_class(class_name=obj.__class__, state=obj.state, base_name=base_name)
As a Python code analyst, you investigate and solve complex coding mysteries
def get_value(self, class_name, attr, default_value=None, state='normal', base_name='View'): """Get a single style attribute value for the given class. """ styles = self.get_dict_for_class(class_name, state, base_name) try: return styles[attr] excep...
Can you implement a function in Python 3 that gets a single style attribute value for the given class.
As a python code expert, you are capable of creating scripts from specifications.
def current(self, fields=None): """Returns dict of current values for all tracked fields""" if fields is None: fields = self.fields return dict((f, self.get_field_value(f)) for f in fields)
Implement a Python 3 function for returning dict of current values for all tracked fields
You are a Python code generator, capable of creating scripts from specifications.
Instantiates and returns a model field for FieldHistory. object_id.
Can you generate a brief explanation for the following Python 3 code def instantiate_object_id_field(object_id_class_or_tuple=models.TextField): if isinstance(object_id_class_or_tuple, (list, tuple)): object_id_class, object_id_kwargs = object_id_class_or_tuple else: object_id_class = object_id_...
As a Python code composer, you craft elegant and concise scripts.
def has_expired(self, lifetime, now=None): """Report if the session key has expired. :param lifetime: A :class:`datetime.timedelta` that specifies the maximum age this :class:`SessionID` should be checked against. :param now: If specified, use t...
Write a Python 3 function for reporting if the session key has expired.
As a Python code translator, you convert algorithms and pseudocode into Python.
Destroys a session completely by deleting all keys and removing it from the internal store immediately.
Given the following Python 3 function, write the documentation def destroy(self): for k in list(self.keys()): del self[k] if getattr(self, 'sid_s', None): current_app.kvsession_store.delete(self.sid_s) self.sid_s = None self.modified = False self.new...
As a Python code translator, you convert algorithms and pseudocode into Python.
Generate a new session id for this session.
Can you generate a brief explanation for the following Python 3 code def regenerate(self): self.modified = True if getattr(self, 'sid_s', None): # delete old session current_app.kvsession_store.delete(self.sid_s) # remove sid_s, set modified self.sid_s =...
You are a Python code analyst, evaluating scripts for potential improvements.
def cleanup_sessions(self, app=None): """Removes all expired session from the store. Periodically, this function can be called to remove sessions from the backend store that have expired, as they are not removed automatically unless the backend supports time-to-live and has been ...
How would you code a function in Python 3 to remove all expired session from the store.
As a Python code translator, you convert algorithms and pseudocode into Python.
def init_app(self, app, session_kvstore=None): """Initialize application and KVSession. This will replace the session management of the application with Flask-KVSession's. :param app: The :class:`~flask.Flask` app to be initialized.""" app.config.setdefault('SESSION_KEY_BITS', ...
Create a Python 3 function to initialize application and KVSession. This will replace the session management of the application with the session management of the application with Flask - KVSession s.
As a Python code analyst, you investigate and solve complex coding mysteries
Transfer the values of the data dict to the SOAP object.
Explain what the following Python 3 code does def transfer_config_dict(soap_object, data_dict): for key, val in data_dict.items(): # Transfer each key to the matching attribute ont he SOAP object. setattr(soap_object, key, val)
You are a Python code generator, capable of creating scripts from specifications.
Assemble and send a request to FedexBaseService.
Make a summary of the following Python 3 code def _assemble_and_send_request(self): # Fire off the query. return self.client.service.createPickup( WebAuthenticationDetail=self.WebAuthenticationDetail, ClientDetail=self.ClientDetail, TransactionDetail=self.Transaction...
You are a Python code architect, reviewing and designing scalable and efficient code
def _assemble_and_send_request(self): """ Fires off the Fedex request. @warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(), WHICH RESIDES ON FedexBaseService AND IS INHERITED. """ # Fire off the query. return self.client.service.getPickupAvailabil...
Implement a Python 3 function for assembling and send a request to FedexBaseService.
As a Python code composer, you craft elegant and concise scripts.
Prepare the WSDL objects for the shipment.
Can you generate the documentation for the following Python 3 function def _prepare_wsdl_objects(self): # This is the primary data structure for processShipment requests. self.RequestedShipment = self.client.factory.create('RequestedShipment') self.RequestedShipment.ShipTimestamp = datetime.dat...
You are a Python code architect, reviewing and designing scalable and efficient code
Assemble and send a validation request.
Explain what the following Python 3 code does def _assemble_and_send_validation_request(self): # Fire off the query. return self.client.service.validateShipment( WebAuthenticationDetail=self.WebAuthenticationDetail, ClientDetail=self.ClientDetail, Transac...
As a python code expert, you are capable of creating scripts from specifications.
def _assemble_and_send_request(self): """ Fires off the Fedex request. @warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(), WHICH RESIDES ON FedexBaseService AND IS INHERITED. """ # Fire off the query. return self.client.service.processSh...
Write a Python 3 script for assembling the request and send it to FedexBaseService.
As a Python code translator, you convert algorithms and pseudocode into Python.
Adds a package to the shipment request.
Can you tell what is the following Python 3 function doing def add_package(self, package_item): self.RequestedShipment.RequestedPackageLineItems.append(package_item) package_weight = package_item.Weight.Value self.RequestedShipment.TotalWeight.Value += package_weight self.RequestedShipm...
As a Python code analyst, you investigate and solve complex coding mysteries
def _prepare_wsdl_objects(self): """ Preps the WSDL data structures for the user. """ self.DeletionControlType = self.client.factory.create('DeletionControlType') self.TrackingId = self.client.factory.create('TrackingId') self.TrackingId.TrackingIdType = self.client.fact...
Write a Python 3 function that can prepare the WSDL data structures for the user.
You are a Python code architect, reviewing and designing scalable and efficient code
def _assemble_and_send_request(self): """ Fires off the Fedex request. @warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(), WHICH RESIDES ON FedexBaseService AND IS INHERITED. """ client = self.client # Fire off the query. return c...
How would you code a function in Python 3 to assemble and send a request to FedexBaseService.
As a Python code translator, you convert algorithms and pseudocode into Python.
Prepare WSDL objects for the shipment.
How would you explain what the following Python 3 function does def _prepare_wsdl_objects(self): self.UploadDocumentsRequest = self.client.factory.create('UploadDocumentsRequest') self.OriginCountryCode =None self.DestinationCountryCode =None self.Usage ='ELECTRONIC_TR...
As a Python code translator, you convert algorithms and pseudocode into Python.
def _assemble_and_send_request(self): """ Fires off the Fedex request. @warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(), WHICH RESIDES ON FedexBaseService AND IS INHERITED. """ # Fire off the query. return self.clien...
Create a Python 3 function to assemble and send a request to Fedex.
You are a Python code generator, capable of creating scripts from specifications.
Sets up the WebAuthenticationCredential node. This is required for all the web authentication requests.
Explain what the following Python 3 code does def __set_web_authentication_detail(self): # Start of the authentication stuff. web_authentication_credential = self.client.factory.create('WebAuthenticationCredential') web_authentication_credential.Key = self.config_obj.key web_authenticat...
You are a Python code architect, reviewing and designing scalable and efficient code
Sets up the ClientDetail node which is required for all shipping resources related requests.
Explain what the following Python 3 code does def __set_client_detail(self, *args, **kwargs): client_detail = self.client.factory.create('ClientDetail') client_detail.AccountNumber = self.config_obj.account_number client_detail.MeterNumber = self.config_obj.meter_number client_detail.In...
You are a Python code generator, capable of creating scripts from specifications.
def __set_transaction_detail(self, *args, **kwargs): """ Checks kwargs for 'customer_transaction_id' and sets it if present. """ customer_transaction_id = kwargs.get('customer_transaction_id', None) if customer_transaction_id: transaction_detail = self.client.factory...
Write a Python 3 script to set the TransactionDetail attribute of the object.
You are a Python code architect, reviewing and designing scalable and efficient code
Sets the version_id of the child request.
How would you explain what the following Python 3 function does def __set_version_id(self): version_id = self.client.factory.create('VersionId') version_id.ServiceId = self._version_info['service_id'] version_id.Major = self._version_info['major'] version_id.Intermediate = self._version...
As a python code expert, you are capable of creating scripts from specifications.
def __check_response_for_fedex_error(self): """ This checks the response for general Fedex errors that aren't related to any one WSDL. """ if self.response.HighestSeverity == "FAILURE": for notification in self.response.Notifications: if notification....
Create a Python 3 function to check the response for Fedex errors and raises FedexFailure if any.
As a Python code analyst, you investigate and solve complex coding mysteries
def _check_response_for_request_errors(self): """ Override this in each service module to check for errors that are specific to that module. For example, invalid tracking numbers in a Tracking request. """ if self.response.HighestSeverity == "ERROR": for noti...
Implement a function in Python 3 to check for errors that are specific to the current service module.
You are a Python code analyst, evaluating scripts for potential improvements.
Check for any errors that are specific to a particular service module and log them if they are not.
Given the following Python 3 function, write the documentation def _check_response_for_request_warnings(self): if self.response.HighestSeverity in ("NOTE", "WARNING"): for notification in self.response.Notifications: if notification.Severity in ("NOTE", "WARNING"): ...
You are a Python code generator, capable of creating scripts from specifications.
def send_request(self, send_function=None): """ Sends the assembled request on the child object. @type send_function: function reference @keyword send_function: A function reference (passed without the parenthesis) to a function that will send the request. This al...
Write a Python 3 script to send the request to the child object.
As a Python code composer, you craft elegant and concise scripts.
def _assemble_and_send_request(self): """ Fires off the Fedex request. @warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(), WHICH RESIDES ON FedexBaseService AND IS INHERITED. """ # We get an exception like this when specifying an IntegratorId: ...
Implement a function in Python 3 to assemble and send the request.
You are a Python code analyst, evaluating scripts for potential improvements.
Sets up the WSDL objects for the current session.
Can you tell what is the following Python 3 function doing def _prepare_wsdl_objects(self): self.SelectionDetails = self.client.factory.create('TrackSelectionDetail') # Default to Fedex self.SelectionDetails.CarrierCode = 'FDXE' track_package_id = self.client.factory.create('TrackPack...
As a Python code translator, you convert algorithms and pseudocode into Python.
def _check_response_for_request_errors(self): """ Checks the response to see if there were any errors specific to this WSDL. """ if self.response.HighestSeverity == "ERROR": # pragma: no cover for notification in self.response.Notifications: if notifi...
Write a Python 3 function for checking the response to see if there were any errors specific to the current WSDL.
You are a Python code architect, reviewing and designing scalable and efficient code
Assemble the request and send it to Fedex.
Can you tell what is the following Python 3 function doing def _assemble_and_send_request(self): client = self.client # Fire off the query. return client.service.track( WebAuthenticationDetail=self.WebAuthenticationDetail, ClientDetail=self.ClientDetail, ...
As a Python code analyst, you investigate and solve complex coding mysteries
Prepare the WSDL objects for the shipment.
Given the following Python 3 function, write the documentation def _prepare_wsdl_objects(self): # Default behavior is to not request transit information self.ReturnTransitAndCommit = False # This is the primary data structure for processShipment requests. self.RequestedShipment = self....
You are a Python code analyst, evaluating scripts for potential improvements.
def _assemble_and_send_request(self): """ Fires off the Fedex request. @warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(), WHICH RESIDES ON FedexBaseService AND IS INHERITED. """ # Fire off the query. return self.client.service.getRates(...
How would you code a function in Python 3 to assemble and send a request to FedexBaseService.
As a Python code composer, you craft elegant and concise scripts.
Prints all of a shipment s labels or just one.
Given the following Python 3 function, write the documentation def print_label(self, package_num=None): if package_num: packages = [ self.shipment.response.CompletedShipmentDetail.CompletedPackageDetails[package_num] ] else: packages = self.shipment.r...
As a Python code composer, you craft elegant and concise scripts.
This is a helper method that writes the base64 encoded string to the label printer.
Given the following Python 3 function, write the documentation def _print_base64(self, base64_data): label_file = open(self.device, "w") label_file.write(base64_data) label_file.close()
You are a Python code generator, capable of creating scripts from specifications.
def _prepare_wsdl_objects(self): """ Create the data structure and get it ready for the WSDL request. """ # Service defaults for objects that are required. self.MultipleMatchesAction = 'RETURN_ALL' self.Constraints = self.create_wsdl_object_of_type('SearchLocationConstra...
How would you code a function in Python 3 to create the WSDL objects that are ready for the WSDL request.
You are a Python code generator, capable of creating scripts from specifications.
Assemble and send a request to FedexBaseService.
Make a summary of the following Python 3 code def _assemble_and_send_request(self): # We get an exception like this when specifying an IntegratorId: # suds.TypeNotFound: Type not found: 'IntegratorId' # Setting it to None does not seem to appease it. del self.ClientDetail.IntegratorId ...
You are a Python code analyst, evaluating scripts for potential improvements.
def _check_response_for_request_errors(self): """ Checks the response to see if there were any errors specific to this WSDL. """ if self.response.HighestSeverity == "ERROR": for notification in self.response.Notifications: # pragma: no cover if notifi...
Create a Python 3 function for checking the response to see if there were any errors specific to the current WSDL.
As a Python code composer, you craft elegant and concise scripts.
def _assemble_and_send_request(self): """ Fires off the Fedex request. @warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(), WHICH RESIDES ON FedexBaseService AND IS INHERITED. """ client = self.client # We get an exception like this when ...
How would you implement a function in Python 3 that assembles and send the request.
You are a Python code architect, reviewing and designing scalable and efficient code
Create the data structure and get it ready for the WSDL request.
Can you generate a brief explanation for the following Python 3 code def _prepare_wsdl_objects(self): self.CarrierCode = 'FDXE' self.Origin = self.client.factory.create('Address') self.Destination = self.client.factory.create('Address') self.ShipDate = datetime.date.today().isoformat() ...
As a python code expert, you are capable of creating scripts from specifications.
def _assemble_and_send_request(self): """ Fires off the Fedex request. @warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(), WHICH RESIDES ON FedexBaseService AND IS INHERITED. """ # We get an exception like this when specifying an IntegratorId: ...
Write a Python 3 script for assembling and send a request to FedexBaseService.
As a Python code translator, you convert algorithms and pseudocode into Python.
Converts basic suds object to dict very quickly.
Here you have a function in Python 3, explain what it does def basic_sobject_to_dict(obj): if not hasattr(obj, '__keylist__'): return obj data = {} fields = obj.__keylist__ for field in fields: val = getattr(obj, field) if isinstance(val, list): data[field] = [] ...
You are a Python code generator, capable of creating scripts from specifications.
Converts a suds object to a dict. Includes advanced features.
Explain what the following Python 3 code does def sobject_to_dict(obj, key_to_lower=False, json_serialize=False): import datetime if not hasattr(obj, '__keylist__'): if json_serialize and isinstance(obj, (datetime.datetime, datetime.time, datetime.date)): return obj.isoformat() else...
As a Python code translator, you convert algorithms and pseudocode into Python.
Converts a suds object to a JSON string.
Can you generate the documentation for the following Python 3 function def sobject_to_json(obj, key_to_lower=False): import json data = sobject_to_dict(obj, key_to_lower=key_to_lower, json_serialize=True) return json.dumps(data)
As a Python code analyst, you investigate and solve complex coding mysteries
def _prepare_wsdl_objects(self): """ Create the data structure and get it ready for the WSDL request. """ self.CarrierCode = 'FDXE' self.RoutingCode = 'FDSD' self.Address = self.client.factory.create('Address') self.ShipDateTime = datetime.datetime.now().isoformat...
Can you implement a function in Python 3 that creates the data structure and get it ready for the WSDL request.
You are a Python code architect, reviewing and designing scalable and efficient code
Assemble and send a request to FedexBaseService.
Can you tell what is the following Python 3 function doing def _assemble_and_send_request(self): # We get an exception like this when specifying an IntegratorId: # suds.TypeNotFound: Type not found: 'IntegratorId' # Setting it to None does not seem to appease it. del self.ClientDetail.I...
You are a Python code architect, reviewing and designing scalable and efficient code
def guess_tags(filename): """ Function to get potential tags for files using the file names. :param filename: This field is the name of file. """ tags = [] stripped_filename = strip_zip_suffix(filename) if stripped_filename.endswith('.vcf'): tags.append('vcf') if stripped_filena...
Can you create a Python 3 function that functions to get potential tags for files using the file names.
As a python code expert, you are capable of creating scripts from specifications.
def characterize_local_files(filedir, max_bytes=MAX_FILE_DEFAULT): """ Collate local file info as preperation for Open Humans upload. Note: Files with filesize > max_bytes are not included in returned info. :param filedir: This field is target directory to get files from. :param max_bytes: This fi...
Write a Python 3 function for collating local files as preperation for Open Humans upload.
As a Python code composer, you craft elegant and concise scripts.
def validate_metadata(target_dir, metadata): """ Check that the files listed in metadata exactly match files in target dir. :param target_dir: This field is the target directory from which to match metadata :param metadata: This field contains the metadata to be matched. """ if not os.p...
How would you code a function in Python 3 to check that the files listed in metadata exactly match files in target dir.
You are a Python code generator, capable of creating scripts from specifications.
Load the metadata as requested for a single user.
Here you have a function in Python 3, explain what it does def load_metadata_csv_single_user(csv_in, header, tags_idx): metadata = {} n_headers = len(header) for index, row in enumerate(csv_in, 2): if row[0] == "": raise ValueError('Error: In row number ' + str(index) + ':' + ...
You are a Python code architect, reviewing and designing scalable and efficient code
Load metadata from a CSV file.
Can you tell what is the following Python 3 function doing def load_metadata_csv(input_filepath): with open(input_filepath) as f: csv_in = csv.reader(f) header = next(csv_in) if 'tags' in header: tags_idx = header.index('tags') else: raise ValueError('"tags" i...
You are a Python code architect, reviewing and designing scalable and efficient code
Check if the date is in ISO 8601 format.
Explain what the following Python 3 code does def validate_date(date, project_member_id, filename): try: arrow.get(date) except Exception: return False return True
You are a Python code architect, reviewing and designing scalable and efficient code
Checks if the file metadata fields like project member id description tags md5 and creation date are valid for a single file.
Can you tell what is the following Python 3 function doing def is_single_file_metadata_valid(file_metadata, project_member_id, filename): if project_member_id is not None: if not project_member_id.isdigit() or len(project_member_id) != 8: raise ValueError( 'Error: for project mem...
You are a Python code generator, capable of creating scripts from specifications.
Check validity of metadata for single user.
Make a summary of the following Python 3 code def review_metadata_csv_single_user(filedir, metadata, csv_in, n_headers): try: if not validate_metadata(filedir, metadata): return False for filename, file_metadata in metadata.items(): is_single_file_metadata_valid(file_metadata...
You are a Python code architect, reviewing and designing scalable and efficient code
def validate_subfolders(filedir, metadata): """ Check that all folders in the given directory have a corresponding entry in the metadata file, and vice versa. :param filedir: This field is the target directory from which to match metadata :param metadata: This field contains the metadata to...
Can you write a function in Python 3 where it checks that all subfolders in the given directory are present in the metadata file.
As a Python code analyst, you investigate and solve complex coding mysteries
Check validity of metadata for multi user.
Here you have a function in Python 3, explain what it does def review_metadata_csv_multi_user(filedir, metadata, csv_in, n_headers): try: if not validate_subfolders(filedir, metadata): return False for project_member_id, member_metadata in metadata.items(): if not validate_me...
As a Python code composer, you craft elegant and concise scripts.
Check validity of metadata fields.
Given the following Python 3 function, write the documentation def review_metadata_csv(filedir, input_filepath): try: metadata = load_metadata_csv(input_filepath) except ValueError as e: print_error(e) return False with open(input_filepath) as f: csv_in = csv.reader(f) ...
You are a Python code architect, reviewing and designing scalable and efficient code
This function will write the metadata for all files in a directory and all subdirs of the file.
Can you generate the documentation for the following Python 3 function def write_metadata_to_filestream(filedir, filestream, max_bytes=MAX_FILE_DEFAULT): """ Make metadata file for all files in a directory(helper function) :param filedir: This field is the filepath of the d...
You are a Python code generator, capable of creating scripts from specifications.
Make metadata file for all files in a directory.
How would you explain what the following Python 3 function does def mk_metadata_csv(filedir, outputfilepath, max_bytes=MAX_FILE_DEFAULT): with open(outputfilepath, 'w') as filestream: write_metadata_to_filestream(filedir, filestream, max_bytes)
You are a Python code analyst, evaluating scripts for potential improvements.
Download a file from the url and save it to the target_filepath.
Explain what the following Python 3 code does def download_file(download_url, target_filepath, max_bytes=MAX_FILE_DEFAULT): response = requests.get(download_url, stream=True) size = int(response.headers['Content-Length']) if _exceeds_size(size, max_bytes, target_filepath) is True: return response ...
As a Python code translator, you convert algorithms and pseudocode into Python.
def read_id_list(filepath): """ Get project member id from a file. :param filepath: This field is the path of file to read. """ if not filepath: return None id_list = [] with open(filepath) as f: for line in f: line = line.rstrip() if not re.match('^[...
Create a Python 3 function to read the project member id from a file.
As a Python code analyst, you investigate and solve complex coding mysteries
Function for setting the logging level.
Make a summary of the following Python 3 code def set_log_level(debug, verbose): if debug: logging.basicConfig(level=logging.DEBUG) elif verbose: logging.basicConfig(level=logging.INFO)
As a Python code translator, you convert algorithms and pseudocode into Python.
def download_cli(directory, master_token=None, member=None, access_token=None, source=None, project_data=False, max_size='128m', verbose=False, debug=False, memberlist=None, excludelist=None, id_filename=False): """ Command line function for downloading data fr...
Write a Python 3 function for commanding line function for downloading data from the cluster members to the specified directory.
As a Python code analyst, you investigate and solve complex coding mysteries
Download data from project members to target directory.
Given the following Python 3 function, write the documentation def download(directory, master_token=None, member=None, access_token=None, source=None, project_data=False, max_size='128m', verbose=False, debug=False, memberlist=None, excludelist=None, id_filename=False): """ ...
You are a Python code analyst, evaluating scripts for potential improvements.
Command line function for downloading metadata.
Can you generate a brief explanation for the following Python 3 code def download_metadata_cli(master_token, output_csv, verbose=False, debug=False): """ Command line function for downloading metadata. For more information visit :func:`download_metadata<ohapi.command_line.downl...
As a Python code translator, you convert algorithms and pseudocode into Python.
def download_metadata(master_token, output_csv, verbose=False, debug=False): """ Output CSV with metadata for a project's downloadable files in Open Humans. :param master_token: This field is the master access token for the project. :param output_csv: This field is the target csv file to which metadata...
Create a Python 3 function to download metadata for a project in Open Humans.
You are a Python code generator, capable of creating scripts from specifications.
def upload_metadata_cli(directory, create_csv='', review='', max_size='128m', verbose=False, debug=False): """ Command line function for drafting or reviewing metadata files. For more information visit :func:`upload_metadata<ohapi.command_line.upload_metadata>`. """ retur...
Write a Python 3 function for commanding line function for uploading metadata files.
As a Python code analyst, you investigate and solve complex coding mysteries
Uploads metadata files to Open Humans.
Can you tell what is the following Python 3 function doing def upload_metadata(directory, create_csv='', review='', max_size='128m', verbose=False, debug=False): """ Draft or review metadata files for uploading files to Open Humans. The target directory should either represent files for ...
You are a Python code architect, reviewing and designing scalable and efficient code
Command line function for uploading files to OH.
Can you generate a brief explanation for the following Python 3 code def upload_cli(directory, metadata_csv, master_token=None, member=None, access_token=None, safe=False, sync=False, max_size='128m', mode='default', verbose=False, debug=False): """ Command line function for upload...
As a Python code analyst, you investigate and solve complex coding mysteries
def upload(directory, metadata_csv, master_token=None, member=None, access_token=None, safe=False, sync=False, max_size='128m', mode='default', verbose=False, debug=False): """ Upload files for the project to Open Humans member accounts. If using a master access token and not specifyi...
Create a Python 3 function for uploading files to Open Humans member accounts.
You are a Python code analyst, evaluating scripts for potential improvements.
Command line function for obtaining the refresh token.
Given the following Python 3 function, write the documentation def oauth_token_exchange_cli(client_id, client_secret, redirect_uri, base_url=OH_BASE_URL, code=None, refresh_token=None): """ Command line function for obtaining the refresh token/code. ...
You are a Python code generator, capable of creating scripts from specifications.
Command line function for obtaining the Oauth2 url.
Explain what the following Python 3 code does def oauth2_auth_url_cli(redirect_uri=None, client_id=None, base_url=OH_BASE_URL): """ Command line function for obtaining the Oauth2 url. For more information visit :func:`oauth2_auth_url<ohapi.api.oauth2_auth_url>`. """ resul...
As a Python code analyst, you investigate and solve complex coding mysteries
Command line function for sending email to a single user or in bulk.
Can you generate a brief explanation for the following Python 3 code def message_cli(subject, message_body, access_token, all_members=False, project_member_ids=None, base_url=OH_BASE_URL, verbose=False, debug=False): """ Command line function for sending email to a single user or...
As a Python code analyst, you investigate and solve complex coding mysteries
Command line function for deleting files.
Can you generate the documentation for the following Python 3 function def delete_cli(access_token, project_member_id, base_url=OH_BASE_URL, file_basename=None, file_id=None, all_files=False): """ Command line function for deleting files. For more information visit :func:`delete_file<ohap...
As a Python code analyst, you investigate and solve complex coding mysteries
Command line tools for downloading public data.
Can you generate a brief explanation for the following Python 3 code def public_data_download_cli(source, username, directory, max_size, quiet, debug): """ Command line tools for downloading public data. """ return public_download(source, username, directory, max_size, quiet...
You are a Python code architect, reviewing and designing scalable and efficient code
def download_url(result, directory, max_bytes): """ Download a file. :param result: This field contains a url from which data will be downloaded. :param directory: This field is the target directory to which data will be downloaded. :param max_bytes: This field is the maximum file s...
Write a Python 3 function for downloading a file from a url.
As a Python code composer, you craft elegant and concise scripts.
def download(source=None, username=None, directory='.', max_size='128m', quiet=None, debug=None): """ Download public data from Open Humans. :param source: This field is the data source from which to download. It's default value is None. :param username: This fiels is username of u...
Can you create a Python 3 function that downloads public data from Open Humans.
You are a Python code analyst, evaluating scripts for potential improvements.
def get_members_by_source(base_url=BASE_URL_API): """ Function returns which members have joined each activity. :param base_url: It is URL: `https://www.openhumans.org/api/public-data`. """ url = '{}members-by-source/'.format(base_url) response = get_page(url) return response
Write a Python 3 script to function returns which members have joined each activity.
As a Python code translator, you convert algorithms and pseudocode into Python.
Function returns which activities each member has joined.
Can you generate a brief explanation for the following Python 3 code def get_sources_by_member(base_url=BASE_URL_API, limit=LIMIT_DEFAULT): url = '{}sources-by-member/'.format(base_url) page = '{}?{}'.format(url, urlencode({'limit': limit})) results = [] while True: data = get_page(page) ...
You are a Python code analyst, evaluating scripts for potential improvements.
Helper function to get file data related to a member of a project.
Given the following Python 3 function, write the documentation def _get_member_file_data(member_data, id_filename=False): file_data = {} for datafile in member_data['data']: if id_filename: basename = '{}.{}'.format(datafile['id'], datafile['basename']) else: ...
As a python code expert, you are capable of creating scripts from specifications.
Returns data for all users including shared data files.
Given the following Python 3 function, write the documentation def update_data(self): url = ('https://www.openhumans.org/api/direct-sharing/project/' 'members/?access_token={}'.format(self.master_access_token)) results = get_all_results(url) self.project_data = dict() for ...
As a python code expert, you are capable of creating scripts from specifications.
Download the data related to a member in a project.
Can you generate the documentation for the following Python 3 function def download_member_project_data(cls, member_data, target_member_dir, max_size=MAX_SIZE_DEFAULT, id_filename=False): """ Download files to sync a local dir to ...
As a Python code translator, you convert algorithms and pseudocode into Python.
Download all files related to a member in a project that are shared by other users.
How would you explain what the following Python 3 function does def download_member_shared(cls, member_data, target_member_dir, source=None, max_size=MAX_SIZE_DEFAULT, id_filename=False): """ Download files to sync a local dir to match OH member shared data. Files...
As a python code expert, you are capable of creating scripts from specifications.
def download_all(self, target_dir, source=None, project_data=False, memberlist=None, excludelist=None, max_size=MAX_SIZE_DEFAULT, id_filename=False): """ Download data for all users including shared data files. :param target_dir: This field is the targe...
How would you implement a function in Python 3 that downloads all users from the specified project and member list.
You are a Python code analyst, evaluating scripts for potential improvements.
def upload_member_from_dir(member_data, target_member_dir, metadata, access_token, mode='default', max_size=MAX_SIZE_DEFAULT): """ Upload files in target directory to an Open Humans member's account. The default behavior is to overwr...
Create a Python 3 function to upload files from a target directory to an Open Humans member s account.
As a Python code composer, you craft elegant and concise scripts.
def oauth2_auth_url(redirect_uri=None, client_id=None, base_url=OH_BASE_URL): """ Returns an OAuth2 authorization URL for a project, given Client ID. This function constructs an authorization URL for a user to follow. The user will be redirected to Authorize Open Humans data for our external applica...
How would you code a function in Python 3 to return an OAuth2 authorization URL for a project, given Client ID. This function constructs an authorization URL for a user to follow. The user will be redirected to Authorize Open Humans data for our external application. An OAuth2 project on Open Humans is required for thi...
You are a Python code architect, reviewing and designing scalable and efficient code
def oauth2_token_exchange(client_id, client_secret, redirect_uri, base_url=OH_BASE_URL, code=None, refresh_token=None): """ Exchange code or refresh token for a new token and refresh token. For the first time when a project is created, code is required to generate refresh token...
Can you write a function in Python 3 where it exchanges code or refresh token for a new token and refresh token.
You are a Python code architect, reviewing and designing scalable and efficient code
Get a single page of results.
Can you generate the documentation for the following Python 3 function def get_page(url): response = requests.get(url) handle_error(response, 200) data = response.json() return data
As a python code expert, you are capable of creating scripts from specifications.
Iterate to get all results from Open Humans API query for Open Humans.
Given the following Python 3 function, write the documentation def get_all_results(starting_page): logging.info('Retrieving all results for {}'.format(starting_page)) page = starting_page results = [] while True: logging.debug('Getting data from: {}'.format(page)) data = get_page(page) ...
As a Python code analyst, you investigate and solve complex coding mysteries
Get data for a specific user including shared data files.
Given the following Python 3 function, write the documentation def exchange_oauth2_member(access_token, base_url=OH_BASE_URL, all_files=False): """ Returns data for a specific user, including shared data files. :param access_token: This field is the user specific access_token. ...
As a Python code composer, you craft elegant and concise scripts.
Delete a file from the specified project member.
Given the following Python 3 function, write the documentation def delete_file(access_token, project_member_id=None, base_url=OH_BASE_URL, file_basename=None, file_id=None, all_files=False): """ Delete project member files by file_basename, file_id, or all_files. To learn more about Open...
As a python code expert, you are capable of creating scripts from specifications.
def message(subject, message, access_token, all_members=False, project_member_ids=None, base_url=OH_BASE_URL): """ Send an email to individual users or in bulk. To learn more about Open Humans OAuth2 projects, go to: https://www.openhumans.org/direct-sharing/oauth2-features/ :param subj...
Create a Python 3 function to send an email to the user or group of users.
As a Python code translator, you convert algorithms and pseudocode into Python.
def upload_stream(stream, filename, metadata, access_token, base_url=OH_BASE_URL, remote_file_info=None, project_member_id=None, max_bytes=MAX_FILE_DEFAULT, file_identifier=None): """ Upload a file object using the "direct upload" feature, which uploads to ...
Write a Python 3 script to upload a file object to the specified keystone.
You are a Python code analyst, evaluating scripts for potential improvements.
def upload_file(target_filepath, metadata, access_token, base_url=OH_BASE_URL, remote_file_info=None, project_member_id=None, max_bytes=MAX_FILE_DEFAULT): """ Upload a file from a local filepath using the "direct upload" API. To learn more about this API endpoint see: * h...
Implement a Python 3 function for uploading a file from a local filepath using the direct upload API.
As a Python code composer, you craft elegant and concise scripts.
Uploads a file from a local filepath using the direct upload API.
Can you generate a brief explanation for the following Python 3 code def upload_aws(target_filepath, metadata, access_token, base_url=OH_BASE_URL, remote_file_info=None, project_member_id=None, max_bytes=MAX_FILE_DEFAULT): """ Upload a file from a local filepath using the "direct u...
You are a Python code analyst, evaluating scripts for potential improvements.
def pack_list(from_, pack_type): """ Return the wire packed version of `from_`. `pack_type` should be some subclass of `xcffib.Struct`, or a string that can be passed to `struct.pack`. You must pass `size` if `pack_type` is a struct.pack string. """ # We need from_ to not be empty if len(from_) ...
Write a Python 3 function for packing a list of items into a wire format.
You are a Python code analyst, evaluating scripts for potential improvements.
Decorator that ensures that the connection is valid.
Make a summary of the following Python 3 code def ensure_connected(f): @functools.wraps(f) def wrapper(*args): self = args[0] self.invalid() try: return f(*args) finally: self.invalid() return wrapper
As a python code expert, you are capable of creating scripts from specifications.