App Engine Python SDK version 1.7.7
[gae.git] / python / google / appengine / dist / tempfile.py
blob9cc78584e8ad7d209399cbaea333cdf39ca0439d
1 #!/usr/bin/env python
3 # Copyright 2007 Google Inc.
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
22 """Temporary files.
24 This module is a replacement for the stock tempfile module in Python,
25 and provides only in-memory temporary files as implemented by
26 cStringIO. The only functionality provided is the TemporaryFile
27 function.
28 """
30 try:
31 from cStringIO import StringIO
32 except ImportError:
33 from StringIO import StringIO
35 __all__ = [
36 "TemporaryFile",
38 "NamedTemporaryFile", "mkstemp", "mkdtemp", "mktemp",
39 "TMP_MAX", "gettempprefix", "tempdir", "gettempdir",
42 TMP_MAX = 10000
44 template = "tmp"
46 tempdir = None
48 def TemporaryFile(mode='w+b', bufsize=-1, suffix="",
49 prefix=template, dir=None):
50 """Create and return a temporary file.
51 Arguments:
52 'prefix', 'suffix', 'dir', 'mode', 'bufsize' are all ignored.
54 Returns an object with a file-like interface. The file is in memory
55 only, and does not exist on disk.
56 """
58 return StringIO()
60 def PlaceHolder(*args, **kwargs):
61 raise NotImplementedError("Only tempfile.TemporaryFile is available for use")
63 NamedTemporaryFile = PlaceHolder
64 mkstemp = PlaceHolder
65 mkdtemp = PlaceHolder
66 mktemp = PlaceHolder
67 gettempprefix = PlaceHolder
68 tempdir = PlaceHolder
69 gettempdir = PlaceHolder