Commits

Alexandr Levayev committed 1ae3b97 Draft

Removed tabs.

Comments (0)

Files changed (5)

         self.api = api
         self.url = 'repositories/%s/%s/' % (username, repository)
         if data is not None:
-	    for i in data:
-	        if i not in ['last_updated', 'created_on']:
-	            setattr(self, i, data[i])
-	        else:
-		    setattr(self, i, datetime.datetime.strptime(data[i], "%Y-%m-%d %H:%M:%S"))
+            for i in data:
+                if i not in ['last_updated', 'created_on']:
+                    setattr(self, i, data[i])
+                else:
+                    setattr(self, i, datetime.datetime.strptime(data[i], "%Y-%m-%d %H:%M:%S"))
 
     def __repr__(self):
         return "<Repository: %s>" % self.name
 
     def get_issues(self):
         if self.has_issues:
-	    return self.api.get_issues(self.owner, self.slug)
+            return self.api.get_issues(self.owner, self.slug)
 
     def get_changesets(self, limit=15):
         return self.api.get_changesets(self.owner, self.slug, limit)
 
     def get_changeset(self, changeset):
         return self.api.get_changesets(self.owner, self.slug, changeset)
-    
+
     def get_file(self, filename, revision="tip"):
         return self.api.get_file(self.owner, self.slug, filename, revision)
-    
+
     def new_issue(self):
         return self.api.new_issue(self.owner, self.slug)
 
         self.filename = data['file']
         self.api = api
         self._handler = None
-    
+
     def __repr__(self):
         return "<BBFile: %s>" % self.filename
-    
+
     def __getattr__(self, name):
         if name == 'handler':
-	    if self._handler == None:
-	        self._handler = self.api.get_raw(self.url)
-	    return self._handler
-	raise AttributeError
+            if self._handler == None:
+                self._handler = self.api.get_raw(self.url)
+            return self._handler
+        raise AttributeError
 
     def read(self, size=-1):
         return self.handler.read(size)
-    
+
     def readline(self, size=-1):
         return self.handler.readline(size)
 
 class Changeset(object):
     def __init__(self, api, username, repository, data):
         for i in data:
-	    if i not in ['files', 'timestamp']:
-	        setattr(self, i, data[i])
-	self.timestamp = datetime.datetime.strptime(data['timestamp'], "%Y-%m-%d %H:%M:%S")
-	self.files = []
-	for f in data['files']:
-	    self.files.append(BBFile(api, username, repository, data['node'], f))
+            if i not in ['files', 'timestamp']:
+                setattr(self, i, data[i])
+        self.timestamp = datetime.datetime.strptime(data['timestamp'], "%Y-%m-%d %H:%M:%S")
+        self.files = []
+        for f in data['files']:
+            self.files.append(BBFile(api, username, repository, data['node'], f))
 
     def __repr__(self):
         return "<Changeset: %s>" % self.node
         self.responsible = username
         self.url = 'repositories/%s/%s/issues/' % (username, repository)
         if data:
-	    self.url = 'repositories/%s/%s/issues/%s/' % (username, repository, data['local_id'])
-	    self.title = data['title']
-	    self.content = data['content']
-	    self.component = data['metadata']['component']
-	    self.milestone = data['metadata']['milestone']
-	    self.version = data['metadata']['version']
-	    try:
-	        self.responsible = data['responsible']['username']
-	    except KeyError:
-	        self.responsible = None
-	    self.priority = data['priority']
-	    self.status = data['status']
-	    self.kind = data['metadata']['kind']
+            self.url = 'repositories/%s/%s/issues/%s/' % (username, repository, data['local_id'])
+            self.title = data['title']
+            self.content = data['content']
+            self.component = data['metadata']['component']
+            self.milestone = data['metadata']['milestone']
+            self.version = data['metadata']['version']
+            try:
+                self.responsible = data['responsible']['username']
+            except KeyError:
+                self.responsible = None
+            self.priority = data['priority']
+            self.status = data['status']
+            self.kind = data['metadata']['kind']
 
     def __repr__(self):
         return "<Issue: %s>" % self.title
         data = {'title':self.title, 'content':self.content, 'priority':self.priority, 'status':self.status, 'kind':self.kind}
         data.update({'responsible':self.responsible})
         if self.component:
-	    data.update({'component':self.component})
-	if self.milestone:
-	    data.update({'milestone':self.milestone})
-	if self.version:
-	    data.update({'version':self.version})
-	return data
+            data.update({'component':self.component})
+        if self.milestone:
+            data.update({'milestone':self.milestone})
+        if self.version:
+            data.update({'version':self.version})
+        return data
 
     def save(self):
         self.json = self.api.post(self.url, self.as_dict())
     def _raw_request(self, url, data=None):
         query_url = self.api_url + url
         if data:
-	  data = urlencode(data)
+          data = urlencode(data)
         try:
-	    req = urllib2.Request(query_url, data, {"Authorization": self._auth })
-	    handler = self._opener.open(req)
-	except urllib2.HTTPError, e:
-	    print e.headers
-	    raise e
-	return handler
+            req = urllib2.Request(query_url, data, {"Authorization": self._auth })
+            handler = self._opener.open(req)
+        except urllib2.HTTPError, e:
+            print e.headers
+            raise e
+        return handler
 
     def _request(self, url, data=None):
-	return json.load(self._raw_request(url, data))
+        return json.load(self._raw_request(url, data))
 
     def post(self, url, data):
         return self._request(url, data)
 
     def get(self, url):
         return self._request(url, None)
-    
+
     def get_raw(self, url):
         return self._raw_request(url, None)
-    
+
     def get_issues(self, username, repository):
         json = self.get('repositories/%s/%s/issues/' % (username, repository))
         issues = []
         for i in json['issues']:
-	    issue = Issue(self, username, repository, i)
-	    issues.append(issue)
-	return issues
-        
+            issue = Issue(self, username, repository, i)
+            issues.append(issue)
+        return issues
+
     def new_issue(self, username, repository):
         return Issue(self, username, repository)
-    
+
     def get_changesets(self, username, repository, limit=15):
         json = self.get('repositories/%s/%s/changesets?limit=%s' % (username, repository, limit))
         changesets = []
         for i in json['changesets']:
-	    changesets.append(Changeset(self, username, repository, i))
-	return changesets
+            changesets.append(Changeset(self, username, repository, i))
+        return changesets
 
     def get_changeset(self, username, repository, changeset):
         json = self.get('repositories/%s/%s/changesets/%s' % (username, repository, changeset))
     def get_repositories(self, username=None):
         repos = []
         if username == None:
-	    json = self.get('user/repositories/')
-	    for repo in json:
-	        repos.append(self.get_repository(repo['owner'], repo['slug']))
-	else:
-	    repo_list = self.get('users/%s/' % username)['repositories']
-	    for repo in repo_list:
-	        repos.append(self.get_repository(username, repo['slug']))
-	return repos
+            json = self.get('user/repositories/')
+            for repo in json:
+                repos.append(self.get_repository(repo['owner'], repo['slug']))
+        else:
+            repo_list = self.get('users/%s/' % username)['repositories']
+            for repo in repo_list:
+                repos.append(self.get_repository(username, repo['slug']))
+        return repos

examples/get_changesets.py

 cs = api.get_changesets("kveroneau", "python-bitbucket", limit=10)
 
 for change in cs:
-  print "Revision/Node: %d:%s" % (change.revision, change.node)
-  # Since change.timestamp is a datetime object, we can use formatting on it.
-  print "Timestamp: %s" % datetime.datetime.strftime(change.timestamp, "%c")
-  print "Commit message:\n%s" % change.message
-  print "Affected files: %s" % len(change.files)
-  for f in change.files:
-    print f.filename
-  print "\n"
+    print "Revision/Node: %d:%s" % (change.revision, change.node)
+    # Since change.timestamp is a datetime object, we can use formatting on it.
+    print "Timestamp: %s" % datetime.datetime.strftime(change.timestamp, "%c")
+    print "Commit message:\n%s" % change.message
+    print "Affected files: %s" % len(change.files)
+    for f in change.files:
+        print f.filename
+    print "\n"

examples/get_issues.py

 issues = api.get_issues("kveroneau", "python-bitbucket")
 
 for issue in issues:
-  print "Issue title: %s" % issue.title
-  print "Issue priority: %s" % issue.priority
-  print "Issue content:\n%s\n\n" % issue.content
+    print "Issue title: %s" % issue.title
+    print "Issue priority: %s" % issue.priority
+    print "Issue content:\n%s\n\n" % issue.content

examples/get_repository.py

 repos = api.get_repositories()
 
 for repo in repos:
-  print "Name: %s" % repo.name
-  print "Owner: %s" % repo.owner
-  print "Website: %s" % repo.website
-  print "Description: %s" % repo.description
-  print "Created on: %s" % datetime.datetime.strftime(repo.created_on, "%c")
-  print "Language: %s" % repo.language
-  print "SCM: %s" % repo.scm
-  for issue in repo.get_issues():
-    # Yes, this works too!
-    print "Issue title: %s" % issue.title
-    print "Issue priority: %s" % issue.priority
-    print "Issue content:\n%s\n\n" % issue.content
-  for change in repo.get_changesets(limit=5):
-    print "Revision/Node: %d:%s" % (change.revision, change.node)
-    # Since change.timestamp is a datetime object, we can use formatting on it.
-    print "Timestamp: %s" % datetime.datetime.strftime(change.timestamp, "%c")
-    print "Commit message:\n%s" % change.message
-    print "Affected files: %s" % len(change.files)
-    for f in change.files:
-      print f.filename
-    print "\n"
+    print "Name: %s" % repo.name
+    print "Owner: %s" % repo.owner
+    print "Website: %s" % repo.website
+    print "Description: %s" % repo.description
+    print "Created on: %s" % datetime.datetime.strftime(repo.created_on, "%c")
+    print "Language: %s" % repo.language
+    print "SCM: %s" % repo.scm
+    for issue in repo.get_issues():
+        # Yes, this works too!
+        print "Issue title: %s" % issue.title
+        print "Issue priority: %s" % issue.priority
+        print "Issue content:\n%s\n\n" % issue.content
+    for change in repo.get_changesets(limit=5):
+        print "Revision/Node: %d:%s" % (change.revision, change.node)
+        # Since change.timestamp is a datetime object, we can use formatting on it.
+        print "Timestamp: %s" % datetime.datetime.strftime(change.timestamp, "%c")
+        print "Commit message:\n%s" % change.message
+        print "Affected files: %s" % len(change.files)
+        for f in change.files:
+            print f.filename
+        print "\n"

loggers/handler.py

     def __init__(self):
         logging.Handler.__init__(self)
         self.include_html = False
-        
+
     def emit(self, record):
         try:
-	    request = record.request
-	    title = '%s (%s IP): %s' % (record.levelname, (request.META.get('REMOTE_ADDR') or 'EXTERNAL'), record.getMessage())
-	    filter = get_exception_reporter_filter(request)
-	    request_repr = filter.get_request_repr(request)
-	except Exception:
-	    title = '%s: %s' % (record.levelname, record.getMessage())
-	    request = None
-	    request_repr = "Request repr() unavailable."
-	title = title.replace("\n", "").replace("\r", "")
-	if record.exc_info:
-	    exc_info = record.exc_info
-	    stack_trace = "\n".join(traceback.format_exception(*record.exc_info))
-	else:
-	    exc_info = (None, record.getMessage(), None)
-	    stack_trace = 'No stack trace available'
-	content = "%s\n\n%s" % (stack_trace, request_repr)
-	api = API("kveroneau", "**password**")
-	issue = api.new_issue(self, "kveroneau", "python-bitbucket")
-	issue.title = title
-	issue.content = content
-	json = issue.save()
+            request = record.request
+            title = '%s (%s IP): %s' % (record.levelname, (request.META.get('REMOTE_ADDR') or 'EXTERNAL'), record.getMessage())
+            filter = get_exception_reporter_filter(request)
+            request_repr = filter.get_request_repr(request)
+        except Exception:
+            title = '%s: %s' % (record.levelname, record.getMessage())
+            request = None
+            request_repr = "Request repr() unavailable."
+        title = title.replace("\n", "").replace("\r", "")
+        if record.exc_info:
+            exc_info = record.exc_info
+            stack_trace = "\n".join(traceback.format_exception(*record.exc_info))
+        else:
+            exc_info = (None, record.getMessage(), None)
+            stack_trace = 'No stack trace available'
+        content = "%s\n\n%s" % (stack_trace, request_repr)
+        api = API("kveroneau", "**password**")
+        issue = api.new_issue(self, "kveroneau", "python-bitbucket")
+        issue.title = title
+        issue.content = content
+        json = issue.save()