Commits

Jeffrey Goettsch  committed 1f22850

Backed out changeset 4b571d1dc104; decided against httplib2.

  • Participants
  • Parent commits 4b571d1

Comments (0)

Files changed (7)

 ------------
 
 If you have already downloaded pushnotify, run the following
-commands inside this directory::
+command inside this directory::
 
     $ python setup.py install
-    $ pip install -r requirements.txt
-
 
 If you have not yet downloaded pushnotify, it would be easier to do
 the following::
 
     $ pip install pushnotify
 
-Either method will install pushnotify into your current environment.
+Either method will install pushnotify into your current environment.

File pushnotify/abstract.py

 
 """
 
-import httplib2
 import logging
 import urllib
+import urllib2
 
 
 class AbstractClient(object):
         self.application = application
         self.apikeys = {}
 
-        # as of 2012-10-06, the pushover server does not pass SSL validation
-        # because httplib2 uses its own certificate store
-        # see: http://code.google.com/p/httplib2/issues/detail?id=154
-
-        self._browser = httplib2.Http(
-            '.cache', disable_ssl_certificate_validation=True)
+        self._browser = urllib2.build_opener(urllib2.HTTPSHandler())
         self._last = {}
         self._urls = {'notify': '', 'verify': ''}
 
 
         self.logger.debug('_get requesting url: {0}'.format(url))
 
-        return self._browser.request(url, 'GET')
+        request = urllib2.Request(url)
+        try:
+            response_stream = self._browser.open(request)
+        except urllib2.HTTPError, exc:
+            return exc
+        else:
+            return response_stream
 
     def _post(self, url, data):
 
-        body = urllib.urlencode(data)
+        data = urllib.urlencode(data)
 
-        self.logger.debug('_post sending data: {0}'.format(body))
+        self.logger.debug('_post sending data: {0}'.format(data))
         self.logger.debug('_post sending to url: {0}'.format(url))
 
-        return self._browser.request(
-            url, 'POST', body,
-            headers={'Content-Type': 'application/x-www-form-urlencoded'})
+        request = urllib2.Request(url, data)
+        try:
+            response_stream = self._browser.open(request)
+        except urllib2.HTTPError, exc:
+            return exc
+        else:
+            return response_stream
 
     def add_key(self, apikey, device_key=''):
         """Add the given key to self.apikeys.

File pushnotify/nma.py

         self._type = 'nma'
         self._urls = {'notify': NOTIFY_URL, 'verify': VERIFY_URL}
 
-    def _parse_response(self, content, verify=False):
+    def _parse_response_stream(self, response_stream, verify=False):
 
-        root = ElementTree.fromstring(content)
+        xmlresp = response_stream.read()
+        root = ElementTree.fromstring(xmlresp)
 
         self._last['type'] = root[0].tag.lower()
         self._last['code'] = root[0].attrib['code']
                         self._last['code'] != '401')):
                 self._raise_exception()
         else:
-            raise exceptions.UnrecognizedResponseError(content, -1)
+            raise exceptions.UnrecognizedResponseError(xmlresp, -1)
 
         return root
 
             if kwargs:
                 data.update(kwargs)
 
-            response = self._post(self._urls['notify'], data)
-            self._parse_response(response[1])
+            response_stream = self._post(self._urls['notify'], data)
+            self._parse_response_stream(response_stream)
 
         if not self.apikeys:
             self.logger.warn('notify called with no users set')
         if self.developerkey:
             data['developerkey'] = self.developerkey
 
-        response = self._get(self._urls['verify'], data)
-        self._parse_response(response[1], True)
+        response_stream = self._get(self._urls['verify'], data)
+        self._parse_response_stream(response_stream, True)
 
         return self._last['code'] == '200'
 

File pushnotify/prowl.py

                       'retrieve_token': RETRIEVE_TOKEN_URL,
                       'retrieve_apikey': RETRIEVE_APIKEY_URL}
 
-    def _parse_response(self, content, verify=False):
+    def _parse_response_stream(self, response_stream, verify=False):
 
-        self.logger.info('received response: {0}'.format(content))
+        xmlresp = response_stream.read()
+        self.logger.info('received response: {0}'.format(xmlresp))
 
-        root = ElementTree.fromstring(content)
+        root = ElementTree.fromstring(xmlresp)
 
         self._last['type'] = root[0].tag.lower()
         self._last['code'] = root[0].attrib['code']
                         self._last['code'] != '401')):
                 self._raise_exception()
         else:
-            raise exceptions.UnrecognizedResponseError(content, -1)
+            raise exceptions.UnrecognizedResponseError(xmlresp, -1)
 
         if len(root) > 1:
             if root[1].tag.lower() == 'retrieve':
                     self._last['token_url'] = None
                     self._last['apikey'] = root[1].attrib['apikey']
                 else:
-                    raise exceptions.UnrecognizedResponseError(content, -1)
+                    raise exceptions.UnrecognizedResponseError(xmlresp, -1)
             else:
-                raise exceptions.UnrecognizedResponseError(content, -1)
+                raise exceptions.UnrecognizedResponseError(xmlresp, -1)
 
         return root
 
             if kwargs:
                 data.update(kwargs)
 
-            response = self._post(self._urls['notify'], data)
-            self._parse_response(response[1])
+            response_stream = self._post(self._urls['notify'], data)
+            self._parse_response_stream(response_stream)
 
         if not self.apikeys:
             self.logger.warn('notify called with no users set')
         data = {'providerkey': self.developerkey,
                 'token': reg_token}
 
-        response = self._get(self._urls['retrieve_apikey'], data)
-        self._parse_response(response[1])
+        response_stream = self._get(self._urls['retrieve_apikey'], data)
+        self._parse_response_stream(response_stream)
 
         return self._last['apikey']
 
 
         data = {'providerkey': self.developerkey}
 
-        response = self._get(self._urls['retrieve_token'], data)
-        self._parse_response(response[1])
+        response_stream = self._get(self._urls['retrieve_token'], data)
+        self._parse_response_stream(response_stream)
 
         return self._last['token'], self._last['token_url']
 
         if self.developerkey:
             data['providerkey'] = self.developerkey
 
-        response = self._get(self._urls['verify'], data)
-        self._parse_response(response[1], True)
+        response_stream = self._get(self._urls['verify'], data)
+        self._parse_response_stream(response_stream, True)
 
         return self._last['code'] == '200'
 

File pushnotify/pushover.py

         self._type = 'pushover'
         self._urls = {'notify': NOTIFY_URL, 'verify': VERIFY_URL}
 
-    def _parse_response(self, response, content, verify=False):
+    def _parse_response_stream(self, stream, verify=False):
 
-        self.logger.info('received response: {0}'.format(content))
+        response = stream.read()
+        self.logger.info('received response: {0}'.format(response))
 
-        content = json.loads(content)
+        response = json.loads(response)
 
-        self._last['code'] = response
-        self._last['device'] = content.get('device', None)
-        self._last['errors'] = content.get('errors', None)
-        self._last['status'] = content.get('status', None)
-        self._last['token'] = content.get('token', None)
-        self._last['user'] = content.get('user', None)
+        self._last['code'] = stream.code
+        self._last['device'] = response.get('device', None)
+        self._last['errors'] = response.get('errors', None)
+        self._last['status'] = response.get('status', None)
+        self._last['token'] = response.get('token', None)
+        self._last['user'] = response.get('user', None)
 
         return self._last['status']
 
                 if kwargs:
                     data.update(kwargs)
 
-                response, content = self._post(self._urls['notify'], data)
-                this_successful = self._parse_response(response, content)
+                response_stream = self._post(self._urls['notify'], data)
+                this_successful = self._parse_response_stream(response_stream)
 
                 all_successful = all_successful and this_successful
 
 
         data = {'token': self.developerkey, 'user': apikey}
 
-        response, content = self._post(self._urls['verify'], data)
+        response_stream = self._post(self._urls['verify'], data)
 
-        self._parse_response(response, content, True)
+        self._parse_response_stream(response_stream, True)
 
         return self._last['status']
 
         data = {'token': self.developerkey, 'user': apikey,
                 'device': device_key}
 
-        response, content = self._post(self._urls['verify'], data)
+        response_stream = self._post(self._urls['verify'], data)
 
-        self._parse_response(response, content, True)
+        self._parse_response_stream(response_stream, True)
 
         if self._last['user'] and 'invalid' in self._last['user'].lower():
             self._raise_exception()

File requirements.txt

-httplib2==0.7.6
 #!/usr/bin/env python
 # vim: set fileencoding=utf-8
 
-import re
 from setuptools import setup
 
 
-def parse_requirements():
-
-    requirements = []
-
-    with open('requirements.txt') as fh:
-        for line in fh.read().split('\n'):
-            if re.match(r'(\s*#)|(\s*$)', line):
-                continue
-            if re.match(r'\s*-e\s+', line):
-                requirements.append(
-                    re.sub(r'\s*-e\s+.*#egg=(.*)$', r'\1', line))
-            elif re.match(r'\s*-f\s+', line):
-                pass
-            else:
-                requirements.append(line)
-
-    return requirements
-
 version = '0.5p'
 
 with open('README.rst') as fh:
 setup(
     name='pushnotify',
     packages=['pushnotify', 'pushnotify.tests'],
-    install_requires=parse_requirements(),
     version=version,
     author='Jeffrey Goettsch',
     author_email='jgoettsch+pypushnotify@gmail.com',