diff options
Diffstat (limited to 'beinc_weechat.py')
| -rw-r--r-- | beinc_weechat.py | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/beinc_weechat.py b/beinc_weechat.py index 52e83b6..1e8afb8 100644 --- a/beinc_weechat.py +++ b/beinc_weechat.py | |||
| @@ -120,11 +120,15 @@ class WeechatTarget(object): | |||
| 120 | """ | 120 | """ |
| 121 | target_dict: the config-dictionary node that represents this instance | 121 | target_dict: the config-dictionary node that represents this instance |
| 122 | """ | 122 | """ |
| 123 | self.__name = target_dict.get( | 123 | self.__name = target_dict.get('name', '') |
| 124 | 'name', | 124 | if self.__name == '': |
| 125 | ''.join([chr(random.randrange(97, 123)) for x in range(4)])) | 125 | beinc_prnt('WARNING: Adding a target with no name ' |
| 126 | self.__url = target_dict.get('target_url') | 126 | 'will make the target useless') |
| 127 | self.__password = target_dict.get('target_password') | 127 | self.__url = target_dict.get('target_url', '') |
| 128 | if self.__url == '': | ||
| 129 | beinc_prnt('WARNING: Adding a target with no URL ' | ||
| 130 | 'will make the target useless') | ||
| 131 | self.__password = target_dict.get('target_password', '') | ||
| 128 | self.__pm_title_template = target_dict.get('pm_title_template', | 132 | self.__pm_title_template = target_dict.get('pm_title_template', |
| 129 | '%s @ %S') | 133 | '%s @ %S') |
| 130 | self.__pm_message_template = target_dict.get('pm_message_template', | 134 | self.__pm_message_template = target_dict.get('pm_message_template', |
| @@ -158,6 +162,7 @@ class WeechatTarget(object): | |||
| 158 | self.__disable_hostname_check = bool( | 162 | self.__disable_hostname_check = bool( |
| 159 | target_dict.get('disable-hostname-check', False)) | 163 | target_dict.get('disable-hostname-check', False)) |
| 160 | self.__ssl_version = target_dict.get('ssl_version', 'auto') | 164 | self.__ssl_version = target_dict.get('ssl_version', 'auto') |
| 165 | self.__last_message = None # datetime.datetime instance | ||
| 161 | self.__connection = None # xmlrpclib.ServerProxy instance | 166 | self.__connection = None # xmlrpclib.ServerProxy instance |
| 162 | self.__connection_setup() | 167 | self.__connection_setup() |
| 163 | 168 | ||
| @@ -227,11 +232,14 @@ class WeechatTarget(object): | |||
| 227 | def __repr__(self): | 232 | def __repr__(self): |
| 228 | """ | 233 | """ |
| 229 | """ | 234 | """ |
| 235 | last_message = 'never' | ||
| 236 | if self.__last_message is not None: | ||
| 237 | last_message = self.__last_message.strftime('%Y-%m-%d %H:%M:%S') | ||
| 230 | return ('name: {0}\nurl: {1}\nenabled: {2}\nchannel_list: {3}\n' | 238 | return ('name: {0}\nurl: {1}\nenabled: {2}\nchannel_list: {3}\n' |
| 231 | 'nick_list: {4}\nchannel_messages_policy: {5}\n' | 239 | 'nick_list: {4}\nchannel_messages_policy: {5}\n' |
| 232 | 'private_messages_policy: {6}\nnotifications_policy: {7}\n' | 240 | 'private_messages_policy: {6}\nnotifications_policy: {7}\n' |
| 233 | 'connected: {8}\nsocket timeout: {9}\nssl-version: {10}\n' | 241 | 'last message: {8}\nsocket timeout: {9}\nssl-version: {10}\n' |
| 234 | 'ciphers: {11}\ndisable_hostname_check: {12}\n' | 242 | 'ciphers: {11}\ndisable hostname check: {12}\n' |
| 235 | 'debug: {13}\n\n'.format( | 243 | 'debug: {13}\n\n'.format( |
| 236 | self.__name, | 244 | self.__name, |
| 237 | self.__url, | 245 | self.__url, |
| @@ -241,11 +249,11 @@ class WeechatTarget(object): | |||
| 241 | self.__chan_messages_policy, | 249 | self.__chan_messages_policy, |
| 242 | self.__priv_messages_policy, | 250 | self.__priv_messages_policy, |
| 243 | self.__notifications_policy, | 251 | self.__notifications_policy, |
| 244 | 'no' if self.__connection is None else 'yes', | 252 | last_message, |
| 245 | self.__socket_timeout, | 253 | self.__socket_timeout, |
| 246 | self.__ssl_version, | 254 | self.__ssl_version, |
| 247 | self.__ssl_ciphers or 'default', | 255 | self.__ssl_ciphers or 'auto', |
| 248 | 'yes' if self.__disable_hostname_check else 'no' | 256 | 'yes' if self.__disable_hostname_check else 'no', |
| 249 | 'yes' if self.__debug else 'no')) | 257 | 'yes' if self.__debug else 'no')) |
| 250 | 258 | ||
| 251 | def send_private_message_notification(self, values): | 259 | def send_private_message_notification(self, values): |
| @@ -357,7 +365,7 @@ class WeechatTarget(object): | |||
| 357 | self.__cert_file)) | 365 | self.__cert_file)) |
| 358 | context.check_hostname = bool( | 366 | context.check_hostname = bool( |
| 359 | not self.__disable_hostname_check) | 367 | not self.__disable_hostname_check) |
| 360 | if self.__ssl_ciphers: | 368 | if self.__ssl_ciphers and self.__ssl_ciphers != 'auto': |
| 361 | context.set_ciphers(self.__ssl_ciphers) | 369 | context.set_ciphers(self.__ssl_ciphers) |
| 362 | transport = xmlrpclib.SafeTransport(context=context) | 370 | transport = xmlrpclib.SafeTransport(context=context) |
| 363 | else: | 371 | else: |
| @@ -368,7 +376,7 @@ class WeechatTarget(object): | |||
| 368 | ssl_options['ca_certs'] = os.path.expanduser( | 376 | ssl_options['ca_certs'] = os.path.expanduser( |
| 369 | self.__cert_file) | 377 | self.__cert_file) |
| 370 | ssl_options['cert_reqs'] = ssl.CERT_REQUIRED | 378 | ssl_options['cert_reqs'] = ssl.CERT_REQUIRED |
| 371 | if self.__ssl_ciphers: | 379 | if self.__ssl_ciphers and self.__ssl_ciphers != 'auto': |
| 372 | ssl_options['ciphers'] = self.__ssl_ciphers | 380 | ssl_options['ciphers'] = self.__ssl_ciphers |
| 373 | transport = BEINCCustomSafeTransport( | 381 | transport = BEINCCustomSafeTransport( |
| 374 | custom_ssl_options=ssl_options) | 382 | custom_ssl_options=ssl_options) |
| @@ -432,6 +440,7 @@ class WeechatTarget(object): | |||
| 432 | message) | 440 | message) |
| 433 | if self.__debug: | 441 | if self.__debug: |
| 434 | beinc_prnt('BEINC DEBUG: Server responded: {0}'.format(result)) | 442 | beinc_prnt('BEINC DEBUG: Server responded: {0}'.format(result)) |
| 443 | self.__last_message = datetime.datetime.now() | ||
| 435 | return True | 444 | return True |
| 436 | except xmlrpclib.Fault as fault: | 445 | except xmlrpclib.Fault as fault: |
| 437 | if self.__debug: | 446 | if self.__debug: |
