38"""Parse a 0alias script, if possible. 39 This does the same as L{parse_script}, except with an existing stream. 40 The stream position at exit is undefined. 41 @type stream: file 42 @rtype: L{ScriptInfo} 43 @since: 1.12""" 44try: 45stream.seek(0) 46template_header=_template[:_template.index("%s'")] 47actual_header=stream.read(len(template_header)) 48stream.seek(0) 49iftemplate_header==actual_header: 50# If it's a 0alias script, it should be quite short! 51rest=stream.read() 52line=rest.split('\n')[1] 53else: 54old_template_header= \ 55_old_template[:_old_template.index("-gd '")] 56actual_header=stream.read(len(old_template_header)) 57ifold_template_header!=actual_header: 58returnNone 59rest=stream.read() 60line=rest.split('\n')[2] 61exceptUnicodeDecodeError: 62returnNone 63 64info=ScriptInfo() 65split=line.rfind("' '") 66ifsplit!=-1: 67# We have a --main or --command 68info.uri=line[split+3:].split("'")[0] 69start,value=line[:split].split("'",1) 70option=start.split('--',1)[1].strip() 71value=value.replace("'\\''","'") 72ifoption=='main': 73info.main=value 74elifoption=='command': 75info.command=valueorNone 76else: 77returnNone 78else: 79info.uri=line.split("'",2)[1] 80 81returninfo
84"""Extract the URI and main values from a 0alias script. 85 @param pathname: the script to be examined 86 @type pathname: str 87 @return: information about the alias script 88 @rtype: L{ScriptInfo} 89 @raise NotAnAliasScript: if we can't parse the script""" 90withopen(pathname,'rt')asstream: 91info=parse_script_header(stream) 92ifinfoisNone: 93raiseNotAnAliasScript(_("'%s' does not look like a script created by 0alias")%pathname) 94returninfo
97"""Write a shell script to stream that will launch the given program. 98 @param stream: the stream to write to 99 @type stream: file100 @param interface_uri: the program to launch101 @type interface_uri: str102 @param main: the --main argument to pass to 0launch, if any103 @type main: str | None104 @param command: the --command argument to pass to 0launch, if any105 @type command: str | None"""106assert"'"notininterface_uri107assert"\\"notininterface_uri108assertmainisNoneorcommandisNone,"Can't set --main and --command together"109110ifmainisnotNone:111option="--main '%s' "%main.replace("'","'\\''")112elifcommandisnotNone:113option="--command '%s' "%command.replace("'","'\\''")114else:115option=""116117stream.write(support.unicode(_template)%(option,interface_uri))