<s> try : <EOL> import config <EOL> except ImportError : <EOL> print ( "<STR_LIT>" ) ; exit ( ) ; <EOL> debug_communication = <NUM_LIT:0> <EOL> import urllib3 <EOL> import json <EOL> def register_device_type ( device_type_name ) : <EOL> global debug_communication <EOL> global http <EOL> global register_device_type_url <EOL> global device_type_id <EOL> global device_type_token <EOL> headers = urllib3 . util . make_headers ( basic_auth = config . hcp_user_credentials ) <EOL> headers [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> body = '<STR_LIT>' + device_type_name + '<STR_LIT>' <EOL> r = http . urlopen ( '<STR_LIT:POST>' , register_device_type_url , body = body , headers = headers ) <EOL> if ( debug_communication == <NUM_LIT:1> ) : <EOL> print ( "<STR_LIT>" + body ) <EOL> print ( "<STR_LIT>" + str ( r . status ) ) <EOL> print ( r . data ) <EOL> json_string = ( r . data ) . decode ( "<STR_LIT:utf-8>" ) <EOL> try : <EOL> json_string_parsed = json . loads ( json_string ) <EOL> device_type_id = json_string_parsed [ "<STR_LIT:id>" ] <EOL> device_type_token = json_string_parsed [ "<STR_LIT>" ] <EOL> except KeyError : <EOL> print ( "<STR_LIT>" + ( r . data ) . decode ( "<STR_LIT:utf-8>" ) + "<STR_LIT>" ) <EOL> def register_message_type ( device_type_id , message_type_name , specifics ) : <EOL> global debug_communication <EOL> global http <EOL> global register_message_type_url <EOL> global message_type_id <EOL> headers = urllib3 . util . make_headers ( basic_auth = config . hcp_user_credentials ) <EOL> headers [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> body = '<STR_LIT>' + device_type_id + '<STR_LIT>' + message_type_name + '<STR_LIT>' + specifics + '<STR_LIT:}>' <EOL> r = http . urlopen ( '<STR_LIT:POST>' , register_message_type_url , body = body , headers = headers ) <EOL> if ( debug_communication == <NUM_LIT:1> ) : <EOL> print ( "<STR_LIT>" + body ) <EOL> print ( "<STR_LIT>" + str ( r . status ) ) <EOL> print ( r . data ) <EOL> json_string = ( r . data ) . decode ( "<STR_LIT:utf-8>" ) <EOL> try : <EOL> json_string_parsed = json . loads ( json_string ) <EOL> message_type_id = json_string_parsed [ "<STR_LIT:id>" ] <EOL> except KeyError : <EOL> print ( "<STR_LIT>" + ( r . data ) . decode ( "<STR_LIT:utf-8>" ) + "<STR_LIT>" ) <EOL> def register_device_instance ( device_type_id , device_name , oauth_credential_for_device_type ) : <EOL> global debug_communication <EOL> global http <EOL> global register_device_url <EOL> global device_instance_id <EOL> global device_instance_token <EOL> headers = urllib3 . util . make_headers ( user_agent = None ) <EOL> headers [ '<STR_LIT>' ] = '<STR_LIT>' + oauth_credential_for_device_type <EOL> headers [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> body = '<STR_LIT>' + device_name + '<STR_LIT>' + device_type_id + '<STR_LIT>' <EOL> r = http . urlopen ( '<STR_LIT:POST>' , register_device_url , body = body , headers = headers ) <EOL> if ( debug_communication == <NUM_LIT:1> ) : <EOL> print ( "<STR_LIT>" + body ) <EOL> print ( "<STR_LIT>" + str ( r . status ) ) <EOL> print ( r . data ) <EOL> json_string = ( r . data ) . decode ( "<STR_LIT:utf-8>" ) <EOL> try : <EOL> json_string_parsed = json . loads ( json_string ) <EOL> device_instance_id = json_string_parsed [ "<STR_LIT:id>" ] <EOL> device_instance_token = json_string_parsed [ "<STR_LIT>" ] <EOL> except ValueError : <EOL> print ( "<STR_LIT>" + ( r . data ) . decode ( "<STR_LIT:utf-8>" ) + "<STR_LIT>" ) <EOL> except KeyError : <EOL> print ( "<STR_LIT>" + ( r . data ) . decode ( "<STR_LIT:utf-8>" ) + "<STR_LIT>" ) <EOL> try : <EOL> urllib3 . disable_warnings ( ) <EOL> except : <EOL> print ( "<STR_LIT>" ) <EOL> if ( config . proxy_url == '<STR_LIT>' ) : <EOL> http = urllib3 . PoolManager ( ) <EOL> else : <EOL> http = urllib3 . proxy_from_url ( config . proxy_url ) <EOL> register_device_type_url = '<STR_LIT>' + config . hcp_account_id + config . hcp_landscape_host + '<STR_LIT>' <EOL> register_message_type_url = '<STR_LIT>' + config . hcp_account_id + config . hcp_landscape_host + '<STR_LIT>' <EOL> register_device_url = '<STR_LIT>' + config . hcp_account_id + config . hcp_landscape_host + '<STR_LIT>' <EOL> device_type_name = "<STR_LIT>" <EOL> device_type_id = "<STR_LIT>" <EOL> device_type_token = "<STR_LIT>" <EOL> message_type_id = "<STR_LIT>" <EOL> message_type_name_upstream = "<STR_LIT>" <EOL> message_type_id_upstream = "<STR_LIT>" <EOL> message_type_name_downstream = "<STR_LIT>" <EOL> message_type_id_downstream = "<STR_LIT>" <EOL> device_instance_name = "<STR_LIT>" <EOL> device_instance_id = "<STR_LIT>" <EOL> device_instance_token = "<STR_LIT>" <EOL> register_device_type ( device_type_name ) <EOL> register_message_type ( device_type_id , message_type_name_upstream , '<STR_LIT>' ) <EOL> message_type_id_upstream = message_type_id <EOL> register_message_type ( device_type_id , message_type_name_downstream , '<STR_LIT>' ) <EOL> message_type_id_downstream = message_type_id <EOL> register_device_instance ( device_type_id , device_instance_name , device_type_token ) <EOL> print ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" + device_instance_name + "<STR_LIT>" + device_instance_id + "<STR_LIT>" + device_type_name + "<STR_LIT>" + device_type_id + "<STR_LIT>" + device_instance_token + "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" + message_type_name_upstream + "<STR_LIT>" + message_type_id_upstream + "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" + message_type_name_downstream + "<STR_LIT>" + message_type_id_downstream + "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" ) </s>
