예제 #1
0
 def validate_host(self, field, value):
     if not value:
         return value
     url = PING_URL % {'host':value, 'apikey':1234}
     response = utils.http_request(url, timeout=2).get('response')
     if not response:
         raise ValidationError('Host not reachable.')
     if response.status != 200:
         raise ValidationError('Invalid response from server: %s' % response.status)
     return value
예제 #2
0
 def validate_host(self, field, value):
     if not value:
         return value
     url = PING_URL % {'host': value, 'apikey': 1234}
     response = utils.http_request(url, timeout=2).get('response')
     if not response:
         raise ValidationError('Host not reachable.')
     content = json.loads(response.read().decode('utf-8'))
     if 'result' not in content:
         raise ValidationError('Invalid response from server.')
     return value
예제 #3
0
 def validate_apikey(self, field, value):
     if not value:
         return value
     url = UPDATE_URL % {'apikey': value, 'location': 'autoip'}
     response = utils.http_request(url, timeout=2).get('response')
     if not response:
         raise ValidationError('No response from Weather Underground.')
     content = json.loads(response.read().decode('utf-8'))
     if 'response' not in content:
         raise ValidationError('Invalid response from Weather Underground.')
     if 'current_observation' not in content:
         raise ValidationError('Invalid API key specified.')
     return value
예제 #4
0
 def validate_apikey(self, field, value):
     if not value:
         return value
     host = self.fields.host.value
     if host is None:
         host = self.pkconfig.get(self.namespace, 'host')
     url = UPDATE_URL % {'host': host, 'apikey': value, 'end': '2000-01-01'}
     response = utils.http_request(url, timeout=2).get('response')
     if utils.rget(response, 'error.code') == 401:
         raise ValidationError('Invalid API key specified.')
     content = json.loads(response.read().decode('utf-8'))
     if not isinstance(content, list):
         raise ValidationError('Invalid response from server.')
     return value
예제 #5
0
 def _validate_cal(self, field, value):
     if not value:
         field.help.setText(field.help_default)
         return value
     url = Plugin.build_url(value)
     response = utils.http_request(url, timeout=2).get('response')
     if not response:
         raise ValidationError('No response from Google.')
     ical = Calendar.from_ical(response.read().decode('utf-8'))
     title = ical.get('x-wr-calname', ical.get('version', ''))
     if not title:
         raise ValidationError('Invalid response from Google.')
     field.help.setText(title)
     return value
예제 #6
0
 def validate_host(self, field, value):
     if not value:
         return value
     try:
         username = self.fields.username.value
         password = self.fields.password.value
         fetch_plex_instance(self.pkmeter, username, password, value)
         return value
     except Unauthorized:
         raise ValidationError('Invalid username or password.')
     except NotFound:
         raise ValidationError('Server host or name not found.')
     except:
         raise ValidationError('Invalid server.')
예제 #7
0
 def validate_apikey(self, field, value):
     if not value:
         return value
     host = self.fields.host.value
     if host is None:
         host = self.pkconfig.get(self.namespace, 'host')
     url = PING_URL % {'host':host, 'apikey':value}
     response = utils.http_request(url, timeout=2).get('response')
     if not response:
         raise ValidationError('Host not reachable.')
     if response.status != 200:
         raise ValidationError('Invalid response from server: %s' % response.status)
     content = json.loads(response.read().decode('utf-8'))
     if content.get('result') != 'success':
         raise ValidationError('Invalid API key specified.')
     return value
예제 #8
0
 def validate_interval(self, field, value):
     try:
         interval = int(value)
         assert 1 <= interval <= 3600, 'Value out of bounds.'
         return interval
     except:
         raise ValidationError('Interval seconds must be a number 1-3600.')
예제 #9
0
 def validate_query(self, field, value):
     if not value or value == 'autoip':
         self.fields.location.value = 'autoip'
         field.help.setText(field.help_default)
         return value
     url = QUERY_URL % {'query': value}
     response = utils.http_request(url, timeout=2).get('response')
     if not response:
         raise ValidationError('No response from Weather Underground.')
     content = json.loads(response.read().decode('utf-8'))
     if not content.get('RESULTS'):
         raise ValidationError('Unable to determine specified location.')
     result = content['RESULTS'][0]
     self.fields.location.value = result['ll'].replace(' ', ',')
     field.help.setText(result['name'])
     return value
예제 #10
0
 def validate_host(self, field, value):
     if not value:
         return value
     url = UPDATE_URL % {'host': value, 'apikey': 1234, 'end': '2000-01-01'}
     response = utils.http_request(url, timeout=2)
     if utils.rget(response, 'error.code') != 401:
         raise ValidationError('Host not reachable.')
     return value
예제 #11
0
 def validate_password(self, field, value):
     if not value:
         return value
     try:
         MyPlexAccount.signin(self.fields.username.value, value)
         return value
     except Unauthorized:
         raise ValidationError('Invalid username or password.')