Ignore:
Timestamp:
Nov 23, 2010 6:42:19 PM (13 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master
Children:
25f66c3
Parents:
353db8c
Message:

Checkpoint

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/federation/util.py

    r353db8c r6e63513  
    1010
    1111from socket import sslerror
     12from tempfile import mkstemp
    1213
    1314from M2Crypto import SSL
     
    267268    cert_re = re.compile('\s*-----BEGIN CERTIFICATE-----$')
    268269    type = None
     270    print cert
    269271    f = open(cert, 'r')
    270272    for line in f:
     
    290292        '''
    291293        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.
    293296        '''
    294         def __init__(self, start, end, fn):
     297        def __init__(self, start, end, fn=None, fd=None):
    295298            self.start = re.compile(start)
    296299            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')
    302308
    303309        def close(self):
     
    305311
    306312    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
    309317    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
    312321
    313322    # Initialize the diversions
    314     divs = [diversion(s, e, fn) for s, e,fn in (
     323    divs = [diversion(s, e, fn=pfn, fd=pfd ) for s, e, pfn, pfd in (
    315324        ('\s*-----BEGIN RSA PRIVATE KEY-----$',
    316325            '\s*-----END RSA PRIVATE KEY-----$',
    317             keyfile),
     326            keyfile, kf),
    318327        ('\s*-----BEGIN CERTIFICATE-----$',
    319328            '\s*-----END CERTIFICATE-----$',
    320             certfile))]
     329            certfile, cf))]
    321330
    322331    # walk through the file, beginning a diversion when a start regexp
     
    340349    # This is probably unnecessary.  Close all the diversion files.
    341350    for d in divs: d.close()
    342     return keyfile, certfile
     351    return rkeyfile, rcertfile
    343352
    344353def find_pickle_problem(o, st=None):
Note: See TracChangeset for help on using the changeset viewer.