updated on Wed Jan 11 00:07:16 UTC 2012
[aur-mirror.git] / zopeedit / zopeedit.py-0.10.2.patch
blob432aa108d40bc113d17673ef9ac91e26c7772660
1 --- old/zopeedit.py 2010-04-19 12:06:41.000000000 +0200
2 +++ zopeedit.py 2010-04-19 12:06:52.000000000 +0200
3 @@ -1,4 +1,4 @@
4 -#!/usr/bin/env python2.5
5 +#!/usr/bin/env python
6 ##############################################################################
8 # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
9 @@ -34,6 +34,7 @@
10 import rfc822
11 import traceback
12 import logging
13 +import hashlib
14 import urllib
15 import shutil
16 import glob
17 @@ -45,6 +46,7 @@
18 import socket
19 import base64
20 from urlparse import urlparse
21 +from urllib2 import parse_http_list, parse_keqv_list
23 LOG_LEVELS = {'debug': logging.DEBUG,
24 'info': logging.INFO,
25 @@ -119,6 +121,7 @@
27 def __init__(self, input_file):
28 self.input_file = input_file
29 + self.identity = None
30 # Setup logging.
31 global log_file
32 #log_file = NamedTemporaryFile(suffix='-zopeedit-log.txt')
33 @@ -794,7 +797,72 @@
34 headers = {'Lock-Token':self.lock_token}
35 response = self.zopeRequest('UNLOCK', headers)
36 return response
39 + def _get_authorization(self, host, method, selector, cookie, ssl,
40 + old_response):
41 + #get the challenge
42 + if ssl is True:
43 + h = HTTPSConnection(host)
44 + else:
45 + h = HTTPConnection(host)
46 + if cookie is not None:
47 + headers = {'Cookie': cookie}
48 + else:
49 + headers = {}
50 + h.request('HEAD', selector, headers=headers)
51 + r = h.getresponse()
52 + if r.status != 401:
53 + return None
54 + auth_header = r.getheader('www-authenticate').strip()
55 + if auth_header is None or not auth_header.lower().startswith('digest'):
56 + return None
57 + # XXX undocumented functions
58 + chal = parse_keqv_list(parse_http_list(auth_header[7:]))
60 + #get the user/password
61 + if self.identity is not None:
62 + username, password = self.identity
63 + else:
64 + # XXX undocumented functions
65 + username = parse_keqv_list(parse_http_list(old_response[7:])
66 + )['username']
67 + password = askPassword(chal['realm'], username)
68 + self.identity = (username, password)
70 + #compute the authorization
71 + algorithm = chal.get('algorithm', 'MD5')
72 + if algorithm == 'MD5':
73 + H = lambda x: hashlib.md5(x).hexdigest()
74 + elif algorithm == 'SHA':
75 + H = lambda x: hashlib.sha1(x).hexdigest()
76 + # XXX MD5-sess not implemented
77 + KD = lambda s, d: H("%s:%s" % (s, d))
79 + nonce = chal['nonce']
80 + res = ('Digest username="%s", realm="%s", nonce="%s", algorithm="%s", '
81 + 'uri="%s"' % (username, chal['realm'], nonce, chal['algorithm'],
82 + selector))
83 + if 'opaque' in chal:
84 + res += ', opaque="%s"' % chal['opaque']
86 + A1 = '%s:%s:%s' % (username, chal['realm'], password)
87 + A2 = '%s:%s' % (method, selector)
89 + if 'qop' in chal:
90 + # XXX auth-int not implemented
91 + qop = chal['qop']
92 + nc = '00000001'
93 + cnonce = '12345678'
94 + res += ', qop="%s", nc="%s", cnonce="%s"' % (qop, nc, cnonce)
96 + response = KD( H(A1), '%s:%s:%s:%s:%s' % (nonce, nc, cnonce, qop,
97 + H(A2)))
98 + else:
99 + response = KD( H(A1), '%s:%s' % (nonce, H(A2)) )
101 + res += ', response="%s"' % response
102 + return res
104 def zopeRequest(self, method, headers={}, body='', command=''):
105 """Send a request back to Zope"""
106 if self.proxy == '':
107 @@ -851,8 +919,17 @@
108 for header, value in headers.items():
109 h.putheader(header, value)
110 h.putheader("Content-Length", str(len(body)))
111 - if self.metadata.get('auth','').lower().startswith('basic'):
112 + #authentication
113 + auth_header = self.metadata.get('auth','')
114 + if auth_header.lower().startswith('basic'):
115 h.putheader("Authorization", self.metadata['auth'])
116 + if auth_header.lower().startswith('digest'):
117 + authorization = self._get_authorization(host, method, url,
118 + self.metadata.get('cookie'),
119 + False, auth_header)
120 + if authorization is not None:
121 + h.putheader("Authorization", authorization)
122 + #cookie
123 if self.metadata.get('cookie'):
124 h.putheader("Cookie", self.metadata['cookie'])
126 @@ -872,8 +949,18 @@
127 for header, value in headers.items():
128 h.putheader(header, value)
129 h.putheader("Content-Length", str(len(body)))
130 - if self.metadata.get('auth','').lower().startswith('basic'):
131 + #authentication
132 + auth_header = self.metadata.get('auth','')
133 + if auth_header.lower().startswith('basic'):
134 h.putheader("Authorization", self.metadata['auth'])
135 + if auth_header.lower().startswith('digest'):
136 + authorization = self._get_authorization(host, method, url,
137 + self.metadata.get('cookie'),
138 + self.ssl and not self.proxy,
139 + auth_header)
140 + if authorization is not None:
141 + h.putheader("Authorization", authorization)
142 + #cookie
143 if self.metadata.get('cookie'):
144 h.putheader("Cookie", self.metadata['cookie'])
146 @@ -1100,6 +1187,30 @@
147 return False
149 ## Platform specific declarations ##
150 +def has_tk():
151 + """Sets up a suitable tk root window if one has not
152 + already been setup. Returns true if tk is happy,
153 + false if tk throws an error (like its not available)"""
154 + # create a hidden root window to make Tk happy
155 + if not locals().has_key('tk_root'):
156 + try:
157 + global tk_root
158 + from Tkinter import Tk
159 + tk_root = Tk()
160 + tk_root.withdraw()
161 + return 1
162 + except:
163 + return 0
164 + return 1
166 +#askPassword is common to win32 and Posix
167 +def askPassword(realm, username):
168 + if has_tk():
169 + from tkSimpleDialog import askstring
170 + r = askstring(title, "Please enter the password for '%s' in '%s'" %
171 + (username, realm), show='*')
172 + has_tk()
173 + return r
175 if win32:
176 import Plugins # Assert dependancy
177 @@ -1130,22 +1241,6 @@
178 from time import sleep
179 import re
181 - def has_tk():
182 - """Sets up a suitable tk root window if one has not
183 - already been setup. Returns true if tk is happy,
184 - false if tk throws an error (like its not available)"""
185 - # create a hidden root window to make Tk happy
186 - if not locals().has_key('tk_root'):
187 - try:
188 - global tk_root
189 - from Tkinter import Tk
190 - tk_root = Tk()
191 - tk_root.withdraw()
192 - return 1
193 - except:
194 - return 0
195 - return 1
197 def errorDialog(message):
198 """Error dialog box"""
199 try: