Commits

Arno Hautala committed 726c236

replaced 'page' parameter with 'terms' dict

  • Participants
  • Parent commits eeb897d

Comments (0)

Files changed (4)

File examples/getsms.py

 page = 0
 while True:
     page += 1
-    voice.sms(page)
+    voice.sms(terms={ 'page':('p%d' % page) })
     
     count = 0
     for conv in nextConversation(voice.sms.data, voice.sms.html):

File examples/getvm.py

 page = 0
 while True:
     page += 1
-    voice.voicemail(page)
+    voice.voicemail(terms={ 'page':('p%d' % page) })
     
     count = 0
     for conv in nextConversation(voice.voicemail.data, voice.voicemail.html):

File googlevoice/util.py

         self.voice = voice
         self.name = name
         
-    def __call__(self, p=None):
+    def __call__(self, terms={}):
         self.json, self.html = '',''
         parser = ParserCreate()
         parser.StartElementHandler = self.start_element
         parser.EndElementHandler = self.end_element
         parser.CharacterDataHandler = self.char_data
         try:
-            data = self.datafunc(p)
+            data = self.datafunc(terms)
             parser.Parse(data, 1)
         except:
             raise ParsingError

File googlevoice/voice.py

     ######################
 
     
-    def __do_page(self, page, data=None, headers={}, p=None):
+    def __do_page(self, page, data=None, headers={}, terms={}):
         """
         Loads a page out of the settings and pass it on to urllib Request
         """
         if data:
             headers.update({'Content-type': 'application/x-www-form-urlencoded;charset=utf-8'})
         pageuri = getattr(settings, page)
-        if p is not None:
+        if len (terms) > 0:
             m = qpat.match(page)
             if m:
                 pageuri += '&'
             else:
                 pageuri += '?'
-            pageuri += ('page=p%d' % p)
+            for i,k in enumerate(terms.keys()):
+                pageuri += k+'='+terms[k]
+                if i < len(terms)-1:
+                    pageuri += '&'
+        print Request(pageuri, data, headers).get_full_url()
         return urlopen(Request(pageuri, data, headers))
 
     def __validate_special_page(self, page, data={}, **kwargs):
 
     _Phone__validate_special_page = __validate_special_page
     
-    def __do_special_page(self, page, data=None, headers={}, p=None):
+    def __do_special_page(self, page, data=None, headers={}, terms={}):
         """
         Add self.special to request data
         """
             data += ('_rnr_se', self.special)
         elif isinstance(data, dict):
             data.update({'_rnr_se': self.special})
-        return self.__do_page(page, data, headers, p)
+        return self.__do_page(page, data, headers, terms)
         
     _Phone__do_special_page = __do_special_page
     
         """
         Return XMLParser instance generated from given page
         """
-        return XMLParser(self, page, lambda p=None: self.__do_special_page('XML_%s' % page.upper(), data, headers, p).read())
+        return XMLParser(self, page, lambda terms={}: self.__do_special_page('XML_%s' % page.upper(), data, headers, terms).read())
       
     def __messages_post(self, page, *msgs, **kwargs):
         """