~inspirated/arsenal/send-attachments-upstream-ajax

« back to all changes in this revision

Viewing changes to arsenal/bugzilla_adapter.py

  • Committer: Kamran Riaz Khan
  • Date: 2010-08-13 16:45:12 UTC
  • Revision ID: krkhan@inspirated.com-20100813164512-3g9dq5soda060m8u
Code cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
from StringIO import StringIO
10
10
 
 
11
from arsenal.info import BugzillaInfo
 
12
 
11
13
DEBUG=1
12
14
 
13
15
class BugzillaLoginError(Exception):
17
19
    pass
18
20
 
19
21
class BugzillaAdapter:
 
22
    def __init__(self, bugzilla, tmpdir):
 
23
        assert(isinstance(bugzilla, BugzillaInfo))
20
24
 
21
 
    def __init__(self, tmpdir):
 
25
        self.bugzilla = bugzilla
22
26
        self.tmpdir = tmpdir
23
27
        self.cookiejar = os.path.join(self.tmpdir, 'cookiejar')
24
28
        with open(self.cookiejar, 'w+b') as fd:
98
102
        # No email was found
99
103
        return None
100
104
 
101
 
    def upload_attachment(self, attachment, url, bugid):
 
105
    def upload_attachment(self, attachment):
102
106
        tmpfile = os.path.join(self.tmpdir, attachment.title)
103
107
 
104
108
        pattern = r'<input\s*type="hidden"\s*name="(.*?)"\s*value="(.*?)"'
105
 
        formdata = self.findall_in_url(pattern, url)
 
109
        formdata = self.findall_in_url(pattern, self.bugzilla.attachurl)
106
110
 
107
111
        formdata.extend([
108
112
            ('data', (pycurl.FORM_FILE, tmpfile)),
117
121
            formdata.extend([
118
122
                ('contenttypemethod', 'autodetect')])
119
123
 
120
 
        headers, response = self.get_response(url,
 
124
        headers, response = self.get_response(self.bugzilla.attachurl,
121
125
                                        opts=[(pycurl.HTTPPOST, formdata),])
122
126
        title = re.escape(cgi.escape(attachment.title))
123
127
        pattern = re.compile(
124
128
            r'<dt>.*<a.*title="%s".*'
125
129
            r'<a.*href="show_bug\.cgi\?id=%s.*</dt>' %
126
 
            (title, bugid),
 
130
            (title, self.bugzilla.bugid),
127
131
            re.DOTALL)
128
132
        if not pattern.search(response):
129
133
            pattern = re.compile(r'<title>(.*?)</title>')