path backslash escaping trouble

Discussion in 'Python' started by placid, Jul 10, 2007.

  1. placid

    placid Guest

    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::::codefromlabel::::
    BLname::::BUILDMODS::::
    OldLname::::::::
    BaseVersion::::6.9.1.24A::::
    RequiredRelease::::6.10.1.3::::
    Description::::::::
    FixRelation::::::::
    Dependencies::::::::
    LpAffected::::No::::
    CodeReview::::FirstName LastName::::
    Testing::::Compile/Build;Designer;Smoketests;::::
    OtherTesting::::::::
    Vobs::::ipsupport;::::
    Elements::::\ipsupport\ipbuild\Wizard\build.pl@@\main\buildmods\3::::

    i read this whole file into a string so i can search for the value of
    Elements which is
    \ipsupport\ipbuild\Wizard\build.pl@@\main\buildmods\3

    but this path is escaped
    \\ipsupport\\ipbuild\\Wizard\\build.pl@@\\main\\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
     
    placid, Jul 10, 2007
    #1
    1. Advertising

  2. placid <> wrote:
    >I have these files; [ ... ]
    >
    >MergeType::::codefromlabel::::
    >BLname::::BUILDMODS::::
    >OldLname::::::::
    >BaseVersion::::6.9.1.24A::::
    >RequiredRelease::::6.10.1.3::::
    >Description::::::::
    >FixRelation::::::::
    >Dependencies::::::::
    >LpAffected::::No::::
    >CodeReview::::FirstName LastName::::
    >Testing::::Compile/Build;Designer;Smoketests;::::
    >OtherTesting::::::::
    >Vobs::::ipsupport;::::
    >Elements::::\ipsupport\ipbuild\Wizard\build.pl@@\main\buildmods\3::::
    >
    >i read this whole file into a string so i can search for the value of
    >Elements which is
    >\ipsupport\ipbuild\Wizard\build.pl@@\main\buildmods\3
    >
    >but this path is escaped
    >\\ipsupport\\ipbuild\\Wizard\\build.pl@@\\main\\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\\ipbuild\\Wizard\\build.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 -- -- 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
     
    Sion Arrowsmith, Jul 10, 2007
    #2
    1. Advertising

  3. En Mon, 09 Jul 2007 22:40:04 -0300, placid <> escribió:

    > 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::::codefromlabel::::
    > BLname::::BUILDMODS::::
    > OldLname::::::::
    > BaseVersion::::6.9.1.24A::::
    > RequiredRelease::::6.10.1.3::::
    > Description::::::::
    > FixRelation::::::::
    > Dependencies::::::::
    > LpAffected::::No::::
    > CodeReview::::FirstName LastName::::
    > Testing::::Compile/Build;Designer;Smoketests;::::
    > OtherTesting::::::::
    > Vobs::::ipsupport;::::
    > Elements::::\ipsupport\ipbuild\Wizard\build.pl@@\main\buildmods\3::::
    >
    > i read this whole file into a string so i can search for the value of
    > Elements which is
    > \ipsupport\ipbuild\Wizard\build.pl@@\main\buildmods\3
    >
    > but this path is escaped
    > \\ipsupport\\ipbuild\\Wizard\\build.pl@@\\main\\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
     
    Gabriel Genellina, Jul 11, 2007
    #3
  4. placid

    placid Guest

    On Jul 11, 10:37 am, "Gabriel Genellina" <>
    wrote:
    > En Mon, 09 Jul 2007 22:40:04 -0300, placid <> escribió:
    >
    >
    >
    > > 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::::codefromlabel::::
    > > BLname::::BUILDMODS::::
    > > OldLname::::::::
    > > BaseVersion::::6.9.1.24A::::
    > > RequiredRelease::::6.10.1.3::::
    > > Description::::::::
    > > FixRelation::::::::
    > > Dependencies::::::::
    > > LpAffected::::No::::
    > > CodeReview::::FirstName LastName::::
    > > Testing::::Compile/Build;Designer;Smoketests;::::
    > > OtherTesting::::::::
    > > Vobs::::ipsupport;::::
    > > Elements::::\ipsupport\ipbuild\Wizard\build.pl@@\main\buildmods\3::::

    >
    > > i read this whole file into a string so i can search for the value of
    > > Elements which is
    > > \ipsupport\ipbuild\Wizard\build.pl@@\main\buildmods\3

    >
    > > but this path is escaped
    > > \\ipsupport\\ipbuild\\Wizard\\build.pl@@\\main\\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\ipbuild\Wizard\build.pl@@\main\buildmods\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
     
    placid, Jul 12, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Prabh
    Replies:
    2
    Views:
    510
    Chris Smith
    May 13, 2004
  2. Razvan

    slash vs backslash

    Razvan, Jul 7, 2004, in forum: Java
    Replies:
    7
    Views:
    17,519
    Razvan
    Jul 8, 2004
  3. Skinny Guy
    Replies:
    1
    Views:
    1,717
  4. Harry George
    Replies:
    5
    Views:
    770
    Gerrit Holl
    Jan 19, 2004
  5. Vincent Texier
    Replies:
    3
    Views:
    2,370
    Vincent Texier
    Jul 1, 2004
Loading...

Share This Page