thirdparty/google_appengine/google/appengine/dist/tempfile.py
changeset 1278 a7766286a7be
equal deleted inserted replaced
1277:5c931bd3dc1e 1278:a7766286a7be
       
     1 #!/usr/bin/env python
       
     2 #
       
     3 # Copyright 2007 Google Inc.
       
     4 #
       
     5 # Licensed under the Apache License, Version 2.0 (the "License");
       
     6 # you may not use this file except in compliance with the License.
       
     7 # You may obtain a copy of the License at
       
     8 #
       
     9 #     http://www.apache.org/licenses/LICENSE-2.0
       
    10 #
       
    11 # Unless required by applicable law or agreed to in writing, software
       
    12 # distributed under the License is distributed on an "AS IS" BASIS,
       
    13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    14 # See the License for the specific language governing permissions and
       
    15 # limitations under the License.
       
    16 #
       
    17 
       
    18 """Temporary files.
       
    19 
       
    20 This module is a replacement for the stock tempfile module in Python,
       
    21 and provides only in-memory temporary files as implemented by
       
    22 cStringIO. The only functionality provided is the TemporaryFile
       
    23 function.
       
    24 """
       
    25 
       
    26 try:
       
    27   from cStringIO import StringIO
       
    28 except ImportError:
       
    29   from StringIO import StringIO
       
    30 
       
    31 __all__ = [
       
    32   "TemporaryFile",
       
    33 
       
    34   "NamedTemporaryFile", "mkstemp", "mkdtemp", "mktemp",
       
    35   "TMP_MAX", "gettempprefix", "tempdir", "gettempdir",
       
    36 ]
       
    37 
       
    38 TMP_MAX = 10000
       
    39 
       
    40 template = "tmp"
       
    41 
       
    42 tempdir = None
       
    43 
       
    44 def TemporaryFile(mode='w+b', bufsize=-1, suffix="",
       
    45                   prefix=template, dir=None):
       
    46   """Create and return a temporary file.
       
    47   Arguments:
       
    48   'prefix', 'suffix', 'dir', 'mode', 'bufsize' are all ignored.
       
    49 
       
    50   Returns an object with a file-like interface.  The file is in memory
       
    51   only, and does not exist on disk.
       
    52   """
       
    53 
       
    54   return StringIO()
       
    55 
       
    56 def PlaceHolder(*args, **kwargs):
       
    57   raise NotImplementedError("Only tempfile.TemporaryFile is available for use")
       
    58 
       
    59 NamedTemporaryFile = PlaceHolder
       
    60 mkstemp = PlaceHolder
       
    61 mkdtemp = PlaceHolder
       
    62 mktemp = PlaceHolder
       
    63 gettempprefix = PlaceHolder
       
    64 tempdir = PlaceHolder
       
    65 gettempdir = PlaceHolder