2
# Copyright (c) 2007-2011 Cyrus Daboo. All rights reserved.
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
8
# http://www.apache.org/licenses/LICENSE-2.0
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.
17
from hashlib import md5
19
def strduptokenstr(txt, tokens):
24
# First punt over any leading space
33
# Handle quoted string
34
if txt[start] == '\"':
48
elif txt[end] == '\\':
56
return txt[start:end], txt[end + 1:]
58
for relend, s in enumerate(txt[start:]):
61
result = txt[start:start+relend]
64
return result, txt[start+relend:]
65
return txt[start:], ""
67
def strtoul(s, offset=0):
72
if s[offset] in "0123456789":
78
return int(s[startoffset:offset]), offset
83
return int(s[startoffset:]), offset
85
def strindexfind(s, ss, default_index):
96
def strnindexfind(s, ss, default_index):
101
if s.startswith(ss[i]):
107
def compareStringsSafe(s1, s2):
108
if s1 is None and s2 is None:
110
elif (s1 is None and s2 is not None) or (s1 is not None and s2 is None):
116
return md5.new(txt).hexdigest()