Mercurial and Git clients can push and pull from this alias URL to interact with this repository. You can change to which repository an alias points by going to the Aliases link on the project page.
importsystry:fromemail.generatorimport_make_boundaryexceptImportError:frommimetoolsimportchoose_boundaryas_make_boundarytry:importurllib.requestasurllib_requestexceptImportError:importurllib2asurllib_requesttry:fromioimportBytesIOexceptImportError:fromStringIOimportStringIOasBytesIOtry:basestringexceptNameError:basestring=strfrombs4importBeautifulSoup,CDataDEBUG=False# Set to True for debugging output.classFogBugzAPIError(Exception):passclassFogBugzLogonError(FogBugzAPIError):passclassFogBugzConnectionError(FogBugzAPIError):passclassFogBugz:def__init__(self,url,token=None):self.__handlerCache={}ifnoturl.endswith('/'):url+='/'iftoken:self._token=token.encode('utf-8')else:self._token=Noneself._opener=urllib_request.build_opener()try:soup=BeautifulSoup(self._opener.open(url+'api.xml'))except(urllib_request.URLError,urllib_request.HTTPError):e=sys.exc_info()[1]raiseFogBugzConnectionError("Library could not connect to the FogBugz API. Either this installation of FogBugz does not support the API, or the url, %s, is incorrect.\n\nError: %s"%(self._url,e))self._url=url+soup.response.url.stringself.currentFilter=Nonedeflogon(self,username,password):""" Logs the user on to FogBugz. Returns None for a successful login. """ifself._token:self.logoff()try:response=self.__makerequest('logon',email=username,password=password)exceptFogBugzAPIError:e=sys.exc_info()[1]raiseFogBugzLogonError(e)self._token=response.token.stringiftype(self._token)==CData:self._token=self._token.encode('utf-8')deflogoff(self):""" Logs off the current user. """self.__makerequest('logoff')self._token=Nonedeftoken(self,token):""" Set the token without actually logging on. More secure. """self._token=token.encode('utf-8')def__encode_multipart_formdata(self,fields,files):""" fields is a sequence of (key, value) elements for regular form fields. files is a sequence of (filename, filehandle) files to be uploaded returns (content_type, body) """BOUNDARY=_make_boundary()iflen(files)>0:fields['nFileCount']=str(len(files))crlf='\r\n'buf=BytesIO() for k, v in fields.items():
if DEBUG:
print("field: %s: %s"% (repr(k), repr(v)))
-buf.write(crlf.join([ '--' + BOUNDARY, 'Content-disposition: form-data; name="%s"' % k, '', v, '' ]).encode('utf-8'))
+lines = [
+ '--' + BOUNDARY,
+ 'Content-disposition: form-data; name="%s"' % k,
+ '',
+ v,
+ '',+ ]
+ buf.write(crlf.join(lines).encode('utf-8'))
n = 0
for f, h in files.items():
n += 1
-buf.write(crlf.join([ '--' + BOUNDARY, 'Content-disposition: form-data; name="File%d"; filename="%s"' % (n, f), '' ]).encode('utf-8'))
-buf.write(crlf.join([ 'Content-type: application/octet-stream', '', '' ]).encode('utf-8'))
+lines = [
+ '--' + BOUNDARY,
+ 'Content-disposition: form-data; name="File%d"; '+ 'filename="%s"' % (n, f),
+ '',+ ]
+ buf.write(crlf.join(lines).encode('utf-8'))
+lines = [
+ 'Content-type: application/octet-stream',
+ '',+ '',+ ]
+ buf.write(crlf.join(lines).encode('utf-8'))
buf.write(h.read().encode('utf-8'))
buf.write(crlf.encode('utf-8'))
buf.write(('--'+BOUNDARY+'--'+crlf).encode('utf-8'))content_type="multipart/form-data; boundary=%s"%BOUNDARYreturncontent_type,buf.getvalue()def__makerequest(self,cmd,**kwargs):kwargs["cmd"]=cmdifself._token:kwargs["token"]=self._tokenfields=kwargsfiles=fields.get('Files',{})if'Files'infields:delfields['Files']content_type,body=self.__encode_multipart_formdata(fields,files)ifDEBUG:print(body)headers={'Content-Type':content_type,'Content-Length':str(len(body))}try:url=self._urlifsys.version_info<(3,):url=self._url.encode('utf-8')request=urllib_request.Request(url,body,headers)resp_stream=self._opener.open(request)response=BeautifulSoup(resp_stream,"xml").responseexcepturllib_request.URLError:e=sys.exc_info()[1]raiseFogBugzConnectionError(e)exceptUnicodeDecodeError:e=sys.exc_info()[1]print(kwargs)raiseifresponse.error:raiseFogBugzAPIError('Error Code %s: %s'%(response.error['code'],response.error.string,))returnresponsedef__getattr__(self,name):""" Handle all FogBugz API calls. >>> fb.logon(email@example.com, password) >>> response = fb.search(q="assignedto:email") """# Let's leave the private stuff to Pythonifname.startswith("__"):raiseAttributeError("No such attribute '%s'"%name)ifnamenotinself.__handlerCache:defhandler(**kwargs):returnself.__makerequest(name,**kwargs)self.__handlerCache[name]=handlerreturnself.__handlerCache[name]
Attach a Trello Card
Add a tag
Your session has expired
You are no longer logged in. Please log in and try your request again.
Filter RSS Feed
This RSS feed URL allows you to see the contents of your current filter using any feed reader.
This link includes a special authentication token. If you share the URL with anyone else, they can see this RSS feed's activity. You can disable these tokens when needed.
Your current filter is unsaved; changing it won't affect this RSS feed.