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

Source Code for Module caldavclientlibrary.protocol.http.util

 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   
18 -def parsetoken(text, delimiters=" \t"):
19 20 if not text: 21 return "", "" 22 23 if text[0] == '"': 24 return parsequoted(text, delimiters) 25 else: 26 for pos, c in enumerate(text): 27 if c in delimiters: 28 token = text[0:pos] 29 break 30 else: 31 return text, "" 32 33 return token, lstripdelimiters(text[pos:], delimiters)
34
35 -def parsequoted(text, delimiters=" \t"):
36 37 assert(text) 38 assert(text[0] == '"') 39 40 pos = 1 41 while True: 42 next_pos = text.find('"', pos) 43 if next_pos == -1: 44 return text[1:].replace("\\\\", "\\").replace("\\\"", "\""), "" 45 if text[next_pos - 1] == '\\': 46 pos = next_pos + 1 47 else: 48 return ( 49 text[1:next_pos].replace("\\\\", "\\").replace("\\\"", "\""), 50 lstripdelimiters(text[next_pos+1:], delimiters) 51 )
52
53 -def lstripdelimiters(text, delimiters):
54 for pos, c in enumerate(text): 55 if c not in delimiters: 56 return text[pos:] 57 else: 58 return ""
59
60 -def parseStatusLine(status):
61 62 status = status.strip() 63 64 # Must have 'HTTP/1.1' version at start 65 if status[0:9] != "HTTP/1.1 ": 66 return 0 67 68 # Must have three digits followed by nothing or one space 69 if not status[9:12].isdigit() or (len(status) > 12 and status[12] != " "): 70 return 0 71 72 # Read in the status code 73 return int(status[9:12])
74