473,585 Members | 2,552 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

path backslash escaping trouble

Hi All,

I have these files; which are Merge Request (ClearCase) files that are
created by a Perl CGI script (being re-written in Python, as the HTML/
JavaScript have been mixed with Perl, maintainability is zero)

MergeType::::co defromlabel::::
BLname::::BUILD MODS::::
OldLname::::::: :
BaseVersion:::: 6.9.1.24A::::
RequiredRelease ::::6.10.1.3::: :
Description:::: ::::
FixRelation:::: ::::
Dependencies::: :::::
LpAffected::::N o::::
CodeReview::::F irstName LastName::::
Testing::::Comp ile/Build;Designer; Smoketests;::::
OtherTesting::: :::::
Vobs::::ipsuppo rt;::::
Elements::::\ip support\ipbuild \Wizard\build.p l@@\main\buildm ods\3::::

i read this whole file into a string so i can search for the value of
Elements which is
\ipsupport\ipbu ild\Wizard\buil d.pl@@\main\bui ldmods\3

but this path is escaped
\\ipsupport\\ip build\\Wizard\\ build.pl@@\\mai n\\buildmods\\3

so when i try to escape a string containing that same path using any
of the os.path escaping methods doesnt
result in the correct escaped path. It either appends "C:\\" in front
of the string with all the backslashes escaped
or it converts the three(3) at then end to "x03" and a match doesnt
occur!

My question is, is there a function in Python that only escapes
backslashes?

Cheers

Jul 10 '07 #1
3 3371
placid <Bu****@gmail.c omwrote:
>I have these files; [ ... ]

MergeType::::c odefromlabel::: :
BLname::::BUIL DMODS::::
OldLname:::::: ::
BaseVersion::: :6.9.1.24A::::
RequiredReleas e::::6.10.1.3:: ::
Description::: :::::
FixRelation::: :::::
Dependencies:: ::::::
LpAffected:::: No::::
CodeReview:::: FirstName LastName::::
Testing::::Com pile/Build;Designer; Smoketests;::::
OtherTesting:: ::::::
Vobs::::ipsupp ort;::::
Elements::::\i psupport\ipbuil d\Wizard\build. pl@@\main\build mods\3::::

i read this whole file into a string so i can search for the value of
Elements which is
\ipsupport\ipb uild\Wizard\bui ld.pl@@\main\bu ildmods\3

but this path is escaped
\\ipsupport\\i pbuild\\Wizard\ \build.pl@@\\ma in\\buildmods\\ 3
How are you reading the file in? Are you absolutely sure that the
escaping appears *in the string*, and isn't being done by whatever
you're using to inspect it?

Consider:
>>s = open('/tmp/Elements').read ()
s
'Elements::::\\ ipsupport\\ipbu ild\\Wizard\\bu ild.pl@@\\main\ \buildmods\\3:: ::\n'
>>len(s)
70

Now, if those backslashes had *really* been escaped, the string would be
length 77, wouldn't it?
>>s.find('\\\\' )
-1

And find() can't find any double-backslashes in there.

--
\S -- si***@chiark.gr eenend.org.uk -- http://www.chaos.org.uk/~sion/
"Frankly I have no feelings towards penguins one way or the other"
-- Arthur C. Clarke
her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
Jul 10 '07 #2
En Mon, 09 Jul 2007 22:40:04 -0300, placid <Bu****@gmail.c omescribió:
I have these files; which are Merge Request (ClearCase) files that are
created by a Perl CGI script (being re-written in Python, as the HTML/
JavaScript have been mixed with Perl, maintainability is zero)

MergeType::::co defromlabel::::
BLname::::BUILD MODS::::
OldLname::::::: :
BaseVersion:::: 6.9.1.24A::::
RequiredRelease ::::6.10.1.3::: :
Description:::: ::::
FixRelation:::: ::::
Dependencies::: :::::
LpAffected::::N o::::
CodeReview::::F irstName LastName::::
Testing::::Comp ile/Build;Designer; Smoketests;::::
OtherTesting::: :::::
Vobs::::ipsuppo rt;::::
Elements::::\ip support\ipbuild \Wizard\build.p l@@\main\buildm ods\3::::

i read this whole file into a string so i can search for the value of
Elements which is
\ipsupport\ipbu ild\Wizard\buil d.pl@@\main\bui ldmods\3

but this path is escaped
\\ipsupport\\ip build\\Wizard\\ build.pl@@\\mai n\\buildmods\\3

so when i try to escape a string containing that same path using any
of the os.path escaping methods doesnt
result in the correct escaped path. It either appends "C:\\" in front
of the string with all the backslashes escaped
or it converts the three(3) at then end to "x03" and a match doesnt
occur!
You may be confused about the actual string contents: "a\\b" contains
exactly 3 characters, the second being a single backslash. The \ is the
escape character; to include an actual \ inside a string, you have to
double it. Another way is to use raw string literals (supressing escape
processing): r"a\\b" contains four characters.
See section 3.1.2 in the Python tutorial or the Reference (more
technical): http://docs.python.org/ref/strings.html

--
Gabriel Genellina

Jul 11 '07 #3
On Jul 11, 10:37 am, "Gabriel Genellina" <gagsl-...@yahoo.com.a r>
wrote:
En Mon, 09 Jul 2007 22:40:04 -0300, placid <Bul...@gmail.c omescribió:
I have these files; which are Merge Request (ClearCase) files that are
created by a Perl CGI script (being re-written in Python, as the HTML/
JavaScript have been mixed with Perl, maintainability is zero)
MergeType::::co defromlabel::::
BLname::::BUILD MODS::::
OldLname::::::: :
BaseVersion:::: 6.9.1.24A::::
RequiredRelease ::::6.10.1.3::: :
Description:::: ::::
FixRelation:::: ::::
Dependencies::: :::::
LpAffected::::N o::::
CodeReview::::F irstName LastName::::
Testing::::Comp ile/Build;Designer; Smoketests;::::
OtherTesting::: :::::
Vobs::::ipsuppo rt;::::
Elements::::\ip support\ipbuild \Wizard\build.p l@@\main\buildm ods\3::::
i read this whole file into a string so i can search for the value of
Elements which is
\ipsupport\ipbu ild\Wizard\buil d.pl@@\main\bui ldmods\3
but this path is escaped
\\ipsupport\\ip build\\Wizard\\ build.pl@@\\mai n\\buildmods\\3
so when i try to escape a string containing that same path using any
of the os.path escaping methods doesnt
result in the correct escaped path. It either appends "C:\\" in front
of the string with all the backslashes escaped
or it converts the three(3) at then end to "x03" and a match doesnt
occur!

You may be confused about the actual string contents: "a\\b" contains
exactly 3 characters, the second being a single backslash. The \ is the
escape character; to include an actual \ inside a string, you have to
double it. Another way is to use raw string literals (supressing escape
processing): r"a\\b" contains four characters.
See section 3.1.2 in the Python tutorial or the Reference (more
technical):http://docs.python.org/ref/strings.html

--
Gabriel
When a user submits a merge request the Python script creats a
subprocess and reads the stdout via a pipe (cleartool find ...) which
returns elements that have a particular label. These elements appeared
like;

\ipsupport\ipbu ild\Wizard\buil d.pl@@\main\bui ldmods\3

these elements are then checked againts previously submitted merge
requests to see if there are any merge requests that require the
same elements to be merged too. When the elements are read from the
stdout pipe of the subprocess the backslashes aren't escaped and
because these "paths" aren't real windows paths non of the os.path...
path escaping methods work!

Well i've solved the problem just by using pycleartool "links directly
against ClearCase libraries" which returns a tuple
containing (status,output, error) and the element paths in output are
properly escaped.

Thanks for the replies
Jul 12 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
6898
by: Aloysio Figueiredo | last post by:
I need to replace every ocurrence of '/' in s by '\/' in order to create a file named s. My first attempt was: s = '\/'.join(s.split('/')) but it doesn't work: >>> s = 'a/b' >>> s = '\/'.join(s.split('/'))
1
4173
by: Rich Strang | last post by:
Hi I need to pass a path to FindFirstFile() that is specified by the user, problem is that all \ characters need to be prefixed with another \, what is the easiest way to do this short of scanning the entire string and replacing a \ with \\? Kind Regards Rich Strang
1
16343
by: Matt | last post by:
In test() method: var path="C:\test\hello.txt"; //returns -1 for path.lastIndexOf("\\"). why?? var pos=path.lastIndexOf("\\"); //return -1 But in showFile() method: We are able to get the filename. The only difference is test() hardcode the path, but in showFile() we gets the path from the file dialog.
3
2225
by: VK | last post by:
On Windows platforms path separator "\" collides with the script escape sign "\" Obvious and old way to prevent it is to double backslashes: "\\" But I'm curious if there is a reliable way to *restore* the right path is user occasionally forgets to double some slash? Naturally nothing we can do in a case like: getFolder("c:\docs\new\")...
2
3236
by: John Dann | last post by:
I guess there must be some convention or Windows specification for whether the backslash immediately preceding the file name in a full path string to a file is formally part of the path string or of the file name. I suppose the options are: 1. Part of the path string, ie all returned path strings should have a trailing backslash. 2. Part...
5
1791
by: Yansky | last post by:
Hi, I'm trying to write a backslash as a text node into the style tag of a web page, but IE is not letting me(perhaps because of security or something?). I need to write a backslash because it is part of the style rule needed to draw VML images. This is my current code at the moment: var theTextofStyle = document.createTextNode('v\:* {...
11
26556
by: cybervigilante | last post by:
I can't seem to change the include path on my local winmachine no matter what I do. It comes up as includ_path .;C:\php5\pear in phpinfo() but there is no such file. I installed the WAMP package and PEAR is in c:\wamp\php\pear I modified php.ini in the c:\wamp\php directory to reflect the actual path, but even stopping and restarting my...
6
1233
by: Konrad Hinsen | last post by:
I am trying to install Python from sources in my home directory on a Mac cluster (running MacOS X 10.4.8). The path to my home directory contains a blank, and since the installation procedure insists on getting an absolute path for the prefix, I cannot avoid installing to a path whose name contains a blank. Python does not seem to be prepared...
34
5327
by: Alexnb | last post by:
Gerhard Häring wrote: No, it didn't work, but it gave me some interesting feedback when I ran it in the shell. Heres what it told me: Traceback (most recent call last): File "<pyshell#10>", line 1, in <module> os.startfile("C:\Documents and Settings\Alex\My Documents\My
0
7908
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8199
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8336
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7950
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8212
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6606
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5389
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1447
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1175
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.