FogBugz » FogBugzPy A Python wrapper for the FogBugz API Read More
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.9.1, 0.9.2, and 0.9.3

some proposed changes to allow people to specify tokens rather than passwords.

Changeset baf67913559d

Parent 652ca60d67e2

by rich@geniusfc1.hq.fogcreek.com

Changes to one file · Browse files at baf67913559d Showing diff from parent 652ca60d67e2 Diff from another changeset...

Change 1 of 3 Show Entire File fogbugz.py Stacked
 
13
14
15
16
 
17
18
19
20
21
 
 
 
 
 
22
23
24
25
 
26
27
28
 
51
52
53
 
 
 
 
 
 
54
55
56
57
 
58
59
 
60
61
 
 
 
 
62
63
64
 
81
82
83
 
 
13
14
15
 
16
17
18
19
20
 
21
22
23
24
25
26
27
28
 
29
30
31
32
 
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
 
70
71
72
73
74
75
76
77
78
79
 
96
97
98
99
@@ -13,16 +13,20 @@
  pass    class FogBugz: - def __init__(self, url): + def __init__(self, url, token=None):   self.__handlerCache = {}   if not url.endswith('/'):   url += '/'   - self._token = None + if token: + self._token = token.encode('utf-8') + else: + self_token = None +   self._opener = urllib2.build_opener()   try:   soup = BeautifulSoup(self._opener.open(url + 'api.xml')) - except urllib2.URLError: + except URLError:   raise FogBugzConnectionError("Library could not connect to the FogBugz API. Either this installation of FogBugz does not support the API, or the url, %s, is incorrect." % (self._url,))   self._url = url + soup.response.url.string   self.currentFilter = None @@ -51,14 +55,25 @@
  self.__makerequest('logoff')   self._token = None   + def token(self,token): + """ + Set the token without actually logging on. More secure. + """ + self._token = token.encode('utf-8') +   def __makerequest(self, cmd, **kwargs):   kwargs["cmd"] = cmd   if self._token:   kwargs["token"] = self._token +   try: - response = BeautifulSoup(self._opener.open(self._url+urllib.urlencode(kwargs))).response + response = BeautifulSoup(self._opener.open(self._url+urllib.urlencode(dict([k, v.encode('utf-8') if isinstance(v,basestring) else v ] for k, v in kwargs.items())))).response   except urllib2.URLError, e:   raise FogBugzConnectionError(e) + except UnicodeDecodeError, e: + print kwargs + raise +   if response.error:   raise FogBugzAPIError('Error Code %s: %s' % (response.error['code'], response.error.string,))   return response @@ -81,3 +96,4 @@
  self.__handlerCache[name] = handler   return self.__handlerCache[name]   +