Package caldavclientlibrary :: Package protocol :: Package http :: Package data :: Module file
[hide private]
[frames] | no frames]

Source Code for Module caldavclientlibrary.protocol.http.data.file

 1  ## 
 2  # Copyright (c) 2006-2016 Apple Inc. All rights reserved. 
 3  # 
 4  # Licensed under the Apache License, Version 2.0 (the "License"); 
 5  # you may not use this file except in compliance with the License. 
 6  # You may obtain a copy of the License at 
 7  # 
 8  # http://www.apache.org/licenses/LICENSE-2.0 
 9  # 
10  # Unless required by applicable law or agreed to in writing, software 
11  # distributed under the License is distributed on an "AS IS" BASIS, 
12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13  # See the License for the specific language governing permissions and 
14  # limitations under the License. 
15  ## 
16   
17  from caldavclientlibrary.protocol.http.data.data import ResponseData 
18  from caldavclientlibrary.protocol.http.data.data import RequestData 
19  import stat 
20  import os 
21   
22 -class RequestDataFile(RequestData):
23
24 - def __init__(self, fname, content_type):
25 26 # Cache file name 27 self.fname = fname 28 29 # Determine size of stream 30 self.content_length = os.stat(self.fname)[stat.ST_SIZE] 31 32 self.content_type = content_type
33
34 - def start(self):
35 # Create an input file stream 36 self.stream = open(self.fname, "r")
37
38 - def stop(self):
39 self.stream.close() 40 self.stream = None
41
42 - def read(self):
43 data = self.stream.read(8192) 44 if data: 45 return data, True 46 else: 47 return data, False
48
49 -class ResponseDataFile(ResponseData):
50
51 - def __init__(self, fname):
52 self.fname = fname
53
54 - def start(self):
55 # Create an input file stream 56 self.stream = open(self.fname, "w")
57
58 - def stop(self):
59 self.stream.close() 60 self.stream = None
61
62 - def write(self, data):
63 self.stream.write(data)
64
65 - def clear(self):
66 # Throw out existing data and start from scratch 67 self.stop() 68 self.start()
69