Changeset 6e63513 for fedd/federation/util.py
- Timestamp:
- Nov 23, 2010 6:42:19 PM (13 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master
- Children:
- 25f66c3
- Parents:
- 353db8c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/federation/util.py
r353db8c r6e63513 10 10 11 11 from socket import sslerror 12 from tempfile import mkstemp 12 13 13 14 from M2Crypto import SSL … … 267 268 cert_re = re.compile('\s*-----BEGIN CERTIFICATE-----$') 268 269 type = None 270 print cert 269 271 f = open(cert, 'r') 270 272 for line in f: … … 290 292 ''' 291 293 Wraps up the reqular expression to start and end a diversion, as well as 292 the open file that gets the lines. 294 the open file that gets the lines. If fd is passed in, use that system 295 file (probably from a mkstemp. Otherwise open the given filename. 293 296 ''' 294 def __init__(self, start, end, fn ):297 def __init__(self, start, end, fn=None, fd=None): 295 298 self.start = re.compile(start) 296 299 self.end = re.compile(end) 297 # Open the file securely with minimal permissions. NB file cannot 298 # exist before this call. 299 self.f = os.fdopen(os.open(fn, 300 (os.O_WRONLY | os.O_CREAT | os.O_TRUNC | os.O_EXCL), 0600), 301 'w') 300 301 if not fd: 302 # Open the file securely with minimal permissions. NB file 303 # cannot exist before this call. 304 fd = os.open(fn, 305 (os.O_WRONLY | os.O_CREAT | os.O_TRUNC | os.O_EXCL), 0600) 306 307 self.f = os.fdopen(fd, 'w') 302 308 303 309 def close(self): … … 305 311 306 312 if not keyfile: 307 f, keyfile = mkstemp(suffix=".pem") 308 os.close(f); 313 kf, rkeyfile = mkstemp(suffix=".pem") 314 else: 315 kf, rkeyfile = None, keyfile 316 309 317 if not certfile: 310 f, certfile = mkstemp(suffix=".pem") 311 os.close(f); 318 cf, rcertfile = mkstemp(suffix=".pem") 319 else: 320 cf, rcertfile = None, certfile 312 321 313 322 # Initialize the diversions 314 divs = [diversion(s, e, fn ) for s, e,fnin (323 divs = [diversion(s, e, fn=pfn, fd=pfd ) for s, e, pfn, pfd in ( 315 324 ('\s*-----BEGIN RSA PRIVATE KEY-----$', 316 325 '\s*-----END RSA PRIVATE KEY-----$', 317 keyfile ),326 keyfile, kf), 318 327 ('\s*-----BEGIN CERTIFICATE-----$', 319 328 '\s*-----END CERTIFICATE-----$', 320 certfile ))]329 certfile, cf))] 321 330 322 331 # walk through the file, beginning a diversion when a start regexp … … 340 349 # This is probably unnecessary. Close all the diversion files. 341 350 for d in divs: d.close() 342 return keyfile,certfile351 return rkeyfile, rcertfile 343 352 344 353 def find_pickle_problem(o, st=None):
Note: See TracChangeset
for help on using the changeset viewer.