Skip to content

Commit

Permalink
Bug fix in cxx_parser.
Browse files Browse the repository at this point in the history
Conditionally declare relpath in cxxtest_misc
  • Loading branch information
whart222 committed Mar 24, 2013
1 parent 99b94b2 commit b8e063a
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 114 deletions.
5 changes: 1 addition & 4 deletions python/cxxtest/cxx_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2138,12 +2138,10 @@ def parse_cpp(data=None, filename=None, debug=0, optimize=0, verbose=False, func
#
# Build lexer
#
global lexer
lexer = lex.lex()
#
# Initialize parse object
#
global _parse_info
_parse_info = CppInfo(filter=func_filter)
_parse_info.verbose=verbose
#
Expand All @@ -2154,7 +2152,6 @@ def parse_cpp(data=None, filename=None, debug=0, optimize=0, verbose=False, func
#
# Parse the file
#
global _parsedata
if not data is None:
_parsedata=data
ply_init(_parsedata)
Expand Down Expand Up @@ -2184,7 +2181,7 @@ def parse_cpp(data=None, filename=None, debug=0, optimize=0, verbose=False, func

import sys

if __name__ == '__main__':
if __name__ == '__main__': #pragma: no cover
#
# This MAIN routine parses a sequence of files provided at the command
# line. If '-v' is included, then a verbose parsing output is
Expand Down
107 changes: 54 additions & 53 deletions python/cxxtest/cxxtest_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,61 +17,62 @@ def abort( problem ):
sys.stderr.write( '\n\n' )
sys.exit(2)

def resolve_symlinks(orig_path):
drive,tmp = os.path.splitdrive(os.path.normpath(orig_path))
if not drive:
drive = os.path.sep
parts = tmp.split(os.path.sep)
actual_path = [drive]
while parts:
actual_path.append(parts.pop(0))
if not os.path.islink(os.path.join(*actual_path)):
continue
actual_path[-1] = os.readlink(os.path.join(*actual_path))
tmp_drive, tmp_path = os.path.splitdrive(
dereference_path(os.path.join(*actual_path)) )
if tmp_drive:
drive = tmp_drive
actual_path = [drive] + tmp_path.split(os.path.sep)
return os.path.join(*actual_path)
if sys.version_info < (2,6):
def resolve_symlinks(orig_path):
drive,tmp = os.path.splitdrive(os.path.normpath(orig_path))
if not drive:
drive = os.path.sep
parts = tmp.split(os.path.sep)
actual_path = [drive]
while parts:
actual_path.append(parts.pop(0))
if not os.path.islink(os.path.join(*actual_path)):
continue
actual_path[-1] = os.readlink(os.path.join(*actual_path))
tmp_drive, tmp_path = os.path.splitdrive(
dereference_path(os.path.join(*actual_path)) )
if tmp_drive:
drive = tmp_drive
actual_path = [drive] + tmp_path.split(os.path.sep)
return os.path.join(*actual_path)

def relpath(path, start=None):
"""Return a relative version of a path.
(provides compatibility with Python < 2.6)"""
# Some notes on implementation:
# - We rely on resolve_symlinks to correctly resolve any symbolic
# links that may be present in the paths
# - The explicit handling od the drive name is critical for proper
# function on Windows (because os.path.join('c:','foo') yields
# "c:foo"!).
if not start:
start = os.getcwd()
ref_drive, ref_path = os.path.splitdrive(
resolve_symlinks(os.path.abspath(start)) )
if not ref_drive:
ref_drive = os.path.sep
start = [ref_drive] + ref_path.split(os.path.sep)
while '' in start:
start.remove('')
def relpath(path, start=None):
"""Return a relative version of a path.
(provides compatibility with Python < 2.6)"""
# Some notes on implementation:
# - We rely on resolve_symlinks to correctly resolve any symbolic
# links that may be present in the paths
# - The explicit handling od the drive name is critical for proper
# function on Windows (because os.path.join('c:','foo') yields
# "c:foo"!).
if not start:
start = os.getcwd()
ref_drive, ref_path = os.path.splitdrive(
resolve_symlinks(os.path.abspath(start)) )
if not ref_drive:
ref_drive = os.path.sep
start = [ref_drive] + ref_path.split(os.path.sep)
while '' in start:
start.remove('')

pth_drive, pth_path = os.path.splitdrive(
resolve_symlinks(os.path.abspath(path)) )
if not pth_drive:
pth_drive = os.path.sep
path = [pth_drive] + pth_path.split(os.path.sep)
while '' in path:
path.remove('')
pth_drive, pth_path = os.path.splitdrive(
resolve_symlinks(os.path.abspath(path)) )
if not pth_drive:
pth_drive = os.path.sep
path = [pth_drive] + pth_path.split(os.path.sep)
while '' in path:
path.remove('')

i = 0
max = min(len(path), len(start))
while i < max and path[i] == start[i]:
i += 1
i = 0
max = min(len(path), len(start))
while i < max and path[i] == start[i]:
i += 1

if i < 2:
return os.path.join(*path)
else:
rel = ['..']*(len(start)-i) + path[i:]
if rel:
return os.path.join(*rel)
if i < 2:
return os.path.join(*path)
else:
return '.'
rel = ['..']*(len(start)-i) + path[i:]
if rel:
return os.path.join(*rel)
else:
return '.'
5 changes: 1 addition & 4 deletions python/python3/cxxtest/cxx_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2138,12 +2138,10 @@ def parse_cpp(data=None, filename=None, debug=0, optimize=0, verbose=False, func
#
# Build lexer
#
global lexer
lexer = lex.lex()
#
# Initialize parse object
#
global _parse_info
_parse_info = CppInfo(filter=func_filter)
_parse_info.verbose=verbose
#
Expand All @@ -2154,7 +2152,6 @@ def parse_cpp(data=None, filename=None, debug=0, optimize=0, verbose=False, func
#
# Parse the file
#
global _parsedata
if not data is None:
_parsedata=data
ply_init(_parsedata)
Expand Down Expand Up @@ -2184,7 +2181,7 @@ def parse_cpp(data=None, filename=None, debug=0, optimize=0, verbose=False, func

import sys

if __name__ == '__main__':
if __name__ == '__main__': #pragma: no cover
#
# This MAIN routine parses a sequence of files provided at the command
# line. If '-v' is included, then a verbose parsing output is
Expand Down
107 changes: 54 additions & 53 deletions python/python3/cxxtest/cxxtest_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,61 +17,62 @@ def abort( problem ):
sys.stderr.write( '\n\n' )
sys.exit(2)

def resolve_symlinks(orig_path):
drive,tmp = os.path.splitdrive(os.path.normpath(orig_path))
if not drive:
drive = os.path.sep
parts = tmp.split(os.path.sep)
actual_path = [drive]
while parts:
actual_path.append(parts.pop(0))
if not os.path.islink(os.path.join(*actual_path)):
continue
actual_path[-1] = os.readlink(os.path.join(*actual_path))
tmp_drive, tmp_path = os.path.splitdrive(
dereference_path(os.path.join(*actual_path)) )
if tmp_drive:
drive = tmp_drive
actual_path = [drive] + tmp_path.split(os.path.sep)
return os.path.join(*actual_path)
if sys.version_info < (2,6):
def resolve_symlinks(orig_path):
drive,tmp = os.path.splitdrive(os.path.normpath(orig_path))
if not drive:
drive = os.path.sep
parts = tmp.split(os.path.sep)
actual_path = [drive]
while parts:
actual_path.append(parts.pop(0))
if not os.path.islink(os.path.join(*actual_path)):
continue
actual_path[-1] = os.readlink(os.path.join(*actual_path))
tmp_drive, tmp_path = os.path.splitdrive(
dereference_path(os.path.join(*actual_path)) )
if tmp_drive:
drive = tmp_drive
actual_path = [drive] + tmp_path.split(os.path.sep)
return os.path.join(*actual_path)

def relpath(path, start=None):
"""Return a relative version of a path.
(provides compatibility with Python < 2.6)"""
# Some notes on implementation:
# - We rely on resolve_symlinks to correctly resolve any symbolic
# links that may be present in the paths
# - The explicit handling od the drive name is critical for proper
# function on Windows (because os.path.join('c:','foo') yields
# "c:foo"!).
if not start:
start = os.getcwd()
ref_drive, ref_path = os.path.splitdrive(
resolve_symlinks(os.path.abspath(start)) )
if not ref_drive:
ref_drive = os.path.sep
start = [ref_drive] + ref_path.split(os.path.sep)
while '' in start:
start.remove('')
def relpath(path, start=None):
"""Return a relative version of a path.
(provides compatibility with Python < 2.6)"""
# Some notes on implementation:
# - We rely on resolve_symlinks to correctly resolve any symbolic
# links that may be present in the paths
# - The explicit handling od the drive name is critical for proper
# function on Windows (because os.path.join('c:','foo') yields
# "c:foo"!).
if not start:
start = os.getcwd()
ref_drive, ref_path = os.path.splitdrive(
resolve_symlinks(os.path.abspath(start)) )
if not ref_drive:
ref_drive = os.path.sep
start = [ref_drive] + ref_path.split(os.path.sep)
while '' in start:
start.remove('')

pth_drive, pth_path = os.path.splitdrive(
resolve_symlinks(os.path.abspath(path)) )
if not pth_drive:
pth_drive = os.path.sep
path = [pth_drive] + pth_path.split(os.path.sep)
while '' in path:
path.remove('')
pth_drive, pth_path = os.path.splitdrive(
resolve_symlinks(os.path.abspath(path)) )
if not pth_drive:
pth_drive = os.path.sep
path = [pth_drive] + pth_path.split(os.path.sep)
while '' in path:
path.remove('')

i = 0
max = min(len(path), len(start))
while i < max and path[i] == start[i]:
i += 1
i = 0
max = min(len(path), len(start))
while i < max and path[i] == start[i]:
i += 1

if i < 2:
return os.path.join(*path)
else:
rel = ['..']*(len(start)-i) + path[i:]
if rel:
return os.path.join(*rel)
if i < 2:
return os.path.join(*path)
else:
return '.'
rel = ['..']*(len(start)-i) + path[i:]
if rel:
return os.path.join(*rel)
else:
return '.'

0 comments on commit b8e063a

Please sign in to comment.