Git Product home page Git Product logo

python-patch's Introduction

Library to parse and apply unified diffs.

Build Status PyPI

Features

  • Python 2 and 3 compatible
  • Automatic correction of
    • Linefeeds according to patched file
    • Diffs broken by stripping trailing whitespace
    • a/ and b/ prefixes
  • Single file, which is a command line tool and a library
  • No dependencies outside Python stdlib
  • Patch format detection (SVN, HG, GIT)
  • Nice diffstat histogram
  • Linux / Windows / OS X
  • Test coverage

Things that don't work out of the box:

  • File renaming, creation and removal
  • Directory tree operations
  • Version control specific properties
  • Non-unified diff formats

Usage

Download patch.py and run it with Python. It is a self-contained module without external dependencies.

patch.py diff.patch

You can also run the .zip file.

python patch-1.16.zip diff.patch

Installation

patch.py is self sufficient. You can copy it into your repository and use it from here. This setup will always be repeatable. But if you need to add patch module as a dependency, make sure to use strict specifiers to avoid hitting an API break when version 2 is released:

pip install "patch==1.*"

Other stuff

python-patch's People

Contributors

ossdev07 avatar techtonik avatar tirkarthi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-patch's Issues

Add helper functions to configure logging

To enable logging when used as a library, you have to:

  import logging
  logger = logging.getLogger('patch')
  logger.setLevel(logging.DEBUG)
  loghandler = logging.StreamHandler()
  logger.addHandler(loghandler)

This suxx. The proposed change is to track logging system state and configure 
it with easier calls.


Original issue reported on code.google.com by [email protected] on 17 Jun 2013 at 5:43

Create binary files

Exported changesets from version control systems, such as Mercurial and Git often include binary files, so it would be nice if library could create them too.

Release 1.15

  • create package

    python ./other/pack.py patch.py

  • write changelog (46d95ed)

    * Project moved to GitHub
    * patch-1.15.zip archive is now executable
    * Improved Git patch detection thanks to @mspncp (#32)
    * Test suite now allows to extend coverage by adding new patches
    * New helper to turn on logging at any time for debug
    
  • Upload archive to PyPI (manually for now)

  • add Travis artifact (built per tag)

Patch: Python 3.x support

Hiho..  I wanted to use this as a library in a Python 3.x application, so I 
went ahead and made the necessary modifications to make it run under both 2.x 
and 3.x (patch is attached)

It passes all the provided tests, and works nicely for my project with the 
patch applied, but I do note that one of the things I had to fiddle with a bit 
is the different way that file IO is handled (particularly with respect to 
newlines) in Py3.  I think the changes I made should result in similar behavior 
in both versions, but I haven't done really extensive testing...

Original issue reported on code.google.com by [email protected] on 28 Aug 2010 at 2:20

Attachments:

Patch: clean up when messages are printed

The attached patch does a few things related to how/when messages are printed:

1. Changes the default loglevel when used as a library to WARN.  This is 
because since there's currently no other way for the caller to get any feedback 
about success/failure, it should at least default to a setting where somebody 
might notice if there's problems.  (Better to have the app developer have to 
explicitly turn off errors than have things fail silently by default)

2. Changes the "successfully patched..." message to INFO instead of WARN, since 
it's actually normal, not an error.

3. Adds a '--quiet' option to the command line, to suppress normal info 
messages if desired.

4. Changes the run_tests.py code to use the 'quiet' flag when invoking the 
patch.py program.  This is mainly just a cosmetic thing, but it gets rid of all 
the spammy messages from patch.py when running the test suite.

Original issue reported on code.google.com by [email protected] on 28 Aug 2010 at 2:29

Attachments:

Allow more flexibility in applying individual patches

I'm using patch in an app that needs to accept patch files and apply them 
safely contained within a certain directory. Namely, it needs to vet each file 
that is to be modified and fail if a patch attempts to modify any file outside 
the base directory that the patch is to be applied to - this could be due to 
symlinks, relative or absolute paths.

To enable this, I've split up the `apply` function into two parts:

patchset.file_patches()
 - returns a generator of (filename, patch) pairs - note that this is the filename that will be modified (so it may be either the source or target)

patchset.apply_patch(filename, i, p):
 - applies an inidivual patch to the given filename. I've left the variable names as-is for the sake of a minimal patch, but `fileno` and `patch` may be better names.

This makes `patchset.apply` a very simple piece of code that just hooks these 
two functions together. My app can now do the same thing, but insert some 
file-checking code before each patch gets applied. Previously it would have to 
duplicate the logic in `apply`, which is quite a huge undertaking.

Other bits:

 - I did have to move the `errors` count into a field on PatchSet, because there's no longer any shared scope between `apply` and `pply_patch`.

 - fixed `xstrip` function which never actually returned anything but `None`.

 - Added "normalize_filenames" params to `parse` (and init) function defaulting to True, to optionally prevent path normalization (which just confuses the matter for my application).


`patch` is the actual patch - I'm also attaching `patch_whitespace_indifferent` 
just for your information (since the change alters a lot of whitespace).

Original issue reported on code.google.com by [email protected] on 2 Jul 2012 at 10:02

Attachments:

Patch context is applied as well

Given file.txt:

a
b
c

And this patch (my.diff):

--- file.txt
+++ file.txt
@@ -1,3 +1,4 @@
 a
 b
+b1
 d

Which is applied using:

import patch
p = patch.fromfile("my.diff")
p.apply(".")

file.txt now looks like this:

a
b
b1
d

The patch only adds b1 but the following context was also put into the file. After applying the patch file.txt should not contain d but end with c.

off-by-one in line numbers when reporting error

$ python -m patch find_in_files_feature.diff 
file 1/1:    spyderlib/widgets/explorer.py
 hunk no.1 doesn't match source file at line 299
  expected:                                triggered=lambda fnames=fnames:
  actual  :         
diff --git a/spyderlib/widgets/explorer.py b/spyderlib/widgets/explorer.py
index c4081df..dfe8623 100644
--- a/spyderlib/widgets/explorer.py
+++ b/spyderlib/widgets/explorer.py
@@ -300,6 +300,11 @@ class DirView(QTreeView):
                                triggered=lambda fnames=fnames:
                                self.open_interpreter(fnames))
         actions.append(action)
+        _title = _("Find from here...")
+        action = create_action(self, _title, icon="find.png",
+                               triggered=lambda:
+                               self.find_from_here(fnames))
+        actions.append(action)
         return actions

     def create_context_menu_actions(self):

First context line is discarded from hunk text if it is at the end andon the same line as the hunk "@@ <...> @@" line

What version of the product are you using?  HEAD r158

What steps will reproduce the problem?

1.Use this patch (attached too):

See how the first context line is on the hunk header line
{{{
Index: linux-2.6.23/fs/Makefile
===================================================================
--- linux-2.6.23.orig/fs/Makefile
+++ linux-2.6.23/fs/Makefile
@@ -72,7 +72,6 @@ obj-$(CONFIG_JBD)     += jbd/
 obj-$(CONFIG_JBD2)     += jbd2/
 obj-$(CONFIG_EXT2_FS)      += ext2/
 obj-$(CONFIG_CRAMFS)       += cramfs/
-obj-$(CONFIG_SQUASHFS)     += squashfs/
 obj-$(CONFIG_RAMFS)        += ramfs/
 obj-$(CONFIG_HUGETLBFS)        += hugetlbfs/
 obj-$(CONFIG_CODA_FS)      += coda/

}}}

2. Then run this:
{{{
# python -c "import patch;p=patch.fromfile('sample.patch');from pprint import 
pprint as pp;pp( p.items[0].hunks[0].text)"
[' obj-$(CONFIG_JBD2)\t\t+= jbd2/\r\n',
 ' obj-$(CONFIG_EXT2_FS)\t\t+= ext2/\r\n',
 ' obj-$(CONFIG_CRAMFS)\t\t+= cramfs/\r\n',
 '-obj-$(CONFIG_SQUASHFS)\t\t+= squashfs/\r\n',
 ' obj-$(CONFIG_RAMFS)\t\t+= ramfs/\r\n',
 ' obj-$(CONFIG_HUGETLBFS)\t\t+= hugetlbfs/\r\n',
 ' obj-$(CONFIG_CODA_FS)\t\t+= coda/']
}}}

3. The expected results here should be:
{{{
[' obj-$(CONFIG_JBD)\t\t+= jbd/\r\n',
 ' obj-$(CONFIG_JBD2)\t\t+= jbd2/\r\n',
 ' obj-$(CONFIG_EXT2_FS)\t\t+= ext2/\r\n',
 ' obj-$(CONFIG_CRAMFS)\t\t+= cramfs/\r\n',
 '-obj-$(CONFIG_SQUASHFS)\t\t+= squashfs/\r\n',
 ' obj-$(CONFIG_RAMFS)\t\t+= ramfs/\r\n',
 ' obj-$(CONFIG_HUGETLBFS)\t\t+= hugetlbfs/\r\n',
 ' obj-$(CONFIG_CODA_FS)\t\t+= coda/']

}}}
Note that I have no idea how the patch was originally produced. It could have 
been manually edited and could be incorrect. I do not know either if that extra 
line would be used by GNU patch as context line or also discarded.



Original issue reported on code.google.com by [email protected] on 22 Aug 2012 at 1:42

Attachments:

Support "test" mode to see if patch will apply cleanly

As far as I can tell, there is no way to invoke the revert() or apply() methods in a "test" mode that would check to see if the patch can be applied successfully without actually modifying the target file. As it happens, I have an application for this. Obviously, I can do this externally by copying the target file in advance and reverting it after the patch is (or isn't) applied, but it would be convenient to have this built in.

If you think this would be useful but don't have the time or interest to work on it, I'd be happy to attempt it, as it looks to be trivial to implement.

On unix-base systems patched file mode is not preserved

What steps will reproduce the problem?
1.create a patch for an executable shell script
2.apply patch

What is the expected output? What do you see instead?
Target script must stay executable. Actually, its mode changes and executable 
permission

What version of the product are you using? On what operating system?
@146, python 2.6, Win and Mac

Original issue reported on code.google.com by [email protected] on 4 Apr 2011 at 7:19

Patch: move imports inside __main__ test

Just as a minor cleanup issue, I also have a patch (attached) to move the 
imports which are only used when running as an application inside the __main__ 
test so they don't get imported if you're just using it as a library.

Not a major issue, but no reason to load them if they're not going to be used..

Original issue reported on code.google.com by [email protected] on 28 Aug 2010 at 2:23

Attachments:

patch should create files (and folders) if the don't already exist

What steps will reproduce the problem?
1. attempt to run a patch where some of the hunks are non-existing files on the 
target

What is the expected output? What do you see instead?
patch should create these files - as does the linux patch utility, possibly 
creating directories as well

What version of the product are you using? On what operating system?


Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 12 Aug 2009 at 4:43

  • Blocking: #14
  • Blocked on: #13

Unable to apply patch using contextual information when line numbers don't match

I have a unified patch file which can be successfully applied using the GNU utility Patch. The line numbers of the source files do not match the patch, however there is enough context available around each hunk (three lines, as default) for the process to complete anyway.

When I try using the same patch file with python-patch, the apply() method fails with the debug log

INFO  hunk no.1 doesn't match source file at line 275

When looking through the source for apply(), I can't see any attempt to make corrections for non-matching line numbers.

Is this useful feature of the unified diff format beyond the scope of the project, something that hasn't been implemented yet, or am I just using it wrong?

Crash on SVN-created patch with only one binary file changed

What steps will reproduce the problem?
1. Add new or change existing binary file in svn repository.
2. Create svn diff.
3. Try to parse/apply patch with patch.py 

What is the expected output? What do you see instead?
I would expect binary file to be copied over; at the very least - some warning 
that this case cannot be processed.
I actually get AttributeError: 'NoneType' object has no attribute 'hunks'" in 
either line 440 or 444, depending on debugmode setting value.


What version of the product are you using? On what operating system?
@146, python 2.6, Win and Mac.

Please provide any additional information below.
The issue is due to incorrect processing of header in this case - code after 
line 220 ("if headscan:") doesn't stop and treats this whole thing as a header 
without any additional parsing:

Index: bin.png

===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: bin.png


___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Original issue reported on code.google.com by [email protected] on 31 Mar 2011 at 8:07

Add support for patchset/patch/hunk string representation

What do you want to do?

Print the representation of a parsed patch, for instance to split a large 
patchset in one patch per patch file.

How to test if it works as expected? Please describe step by step.

Given a PatchSet object, repr(PatchSet) should return a string that should be 
the same  (or almost the same) as the original parsed file.
Then for each Patch in the patchset, repr(Patch) should return a string that 
should be the same (or almost the same) as the original Patch in the parsed 
file.
Then for each Hunk in a patch, repr(Hunk) should return a string that should be 
the same  (or almost the same) as the original Hunk in the Patch in the parsed 
file.

It is OK if the line endings do not match exactly (i.e. hunkends may be 
ignored) and default to Posix, and it is OK if the repr is not exactly the same 
as the original one, but a good enough one.

Attached is a proposed patch with some tests, based on the latest HEAD @ r196



Original issue reported on code.google.com by [email protected] on 28 Mar 2013 at 11:00

Attachments:

Google style guide....?

Hi Anatoly:
I know that "inside" you still use the high density two spaces indentation, but 
I was wondering if the updated public style guide could make sense 
indentation-wise?
http://google-styleguide.googlecode.com/svn/trunk/pyguide.html#Indentation

I know this is a silly request... ignore and close asap if you feel so.

Original issue reported on code.google.com by [email protected] on 3 Mar 2014 at 8:17

fromstring() fails due to mismatch between import and usage of StringIO.

In svn HEAD (r90), on line 22 of patch.py, StringIO is imported using "from 
StringIO import StringIO".  But on line 70 (in fromstring()), the code tries to 
instantiate "StringIO.StringIO", which fails with an AttributeError.

This can be fixed by either changing the import to just "import StringIO" or by 
removing the initial "StringIO." from the place where StringIO is instantiated.

Original issue reported on code.google.com by john.stumpo on 29 Jun 2010 at 12:09

patch.py adds extra newline at EOF

I have observed that patch.py adds an extra newline at the end of the patched file even though the unified patch doesn't alter the line at all.

I know it is good behavior on Linux to have a newline at the end of the file. Some C/C++ coding standards make this even mandatory. But with PHP and some other web technologies, there are strong reasons to NOT have a newline at the end of the file, as it may result in undesired additional newline output to the client, possibly breaking everything.

Small example for illustration, including [LF] as newline ('\n') and [EOF] as the end of the file.

original file (old/test.php):

<?php[LF]
[LF]
echo "<html><title>asdf</title><body>asdf</body></html>";[LF]
[LF]
?>[EOF]

with patch file (without [LF] and [EOF], generated via diff -Naur old/test.php new/test.php > test.php.patch):

--- old/test.php	2017-03-29 11:19:36.103349100 +0200
+++ new/test.php	2017-03-29 11:20:16.270349100 +0200
@@ -1,5 +1,5 @@
 <?php
 
-echo "<html><title>asdf</title><body>asdf</body></html>";
+echo "<html><title>A real title</title><body>A real body</body></html>";
 
 ?>
\ No newline at end of file

becomes:

<?php[LF]
[LF]
echo "<html><title>A real title</title><body>A real body</body></html>";[LF]
[LF]
?>[LF][EOF]

but should be (new/test.php):

<?php[LF]
[LF]
echo "<html><title>A real title</title><body>A real body</body></html>";[LF]
[LF]
?>[EOF]

detect timestamp in diff header

What steps will reproduce the problem?
1.python diff.py -u patch.py.merge-left.r40 patch.py.merge-right.r41 >
portfix.diff

What is the expected output? What do you see instead?
filenames in diff header are not separated from timestamp by tab

--- patch.py.merge-left.r40 Sat Dec 26 11:39:47 2009
+++ patch.py.merge-right.r41 Sat Dec 26 11:39:47 2009
@@ -8,7 +8,7 @@
 """


patch.py fails:
reading patch from file portfix.diff
total files: 1  total hunks: 2
source/target file does not exist
--- patch.py.merge-left.r40 Sat Dec 26 11:39:47 2009
+++ patch.py.merge-right.r41 Sat Dec 26 11:39:47 2009


Need to detect all possible timestamp formats.

Original issue reported on code.google.com by [email protected] on 26 Dec 2009 at 9:55

accept urls - useful for applying patches directly from rietveld

What do you want to do?
I want to be able to enter URL of the patch or id of the issue on Rietveld to   
apply patch from it in current directory.

How to test if it works as expected? Please describe step by step.
python patch.py http://codereview.appspot.com/download/issue577041_2001.diff

Original issue reported on code.google.com by [email protected] on 20 Mar 2010 at 5:08

Patch to enhance functionality

I'm using python-patch in one of my projects, so to return the favor here are 
my changes:

1. Support -p<num> like GNU patch, to strip path components

2. Set exit code to 0 or 1 depending on errors occured (like GNU patch)

3. Support creating new files (source=/dev/null), like GNU patch

4. Don't touch global logging configuration on module load, unless used as 
__main__  (useful when embedding in a larger project)

A patch is attached (applies cleanly to SVN r111)

Original issue reported on code.google.com by [email protected] on 27 Nov 2010 at 6:05

  • Blocked on: #3

Attachments:

Default message about already patched files is too verbose

What steps will reproduce the problem?
1. run patch.py two times

What is the expected output? What do you see instead?
file 4/4:    templates/issue.html
 hunk no.2 doesn't match source file at line 203
  expected:       <input type="hidden" name="subject" value="{{issue.subject}}" />
  actual  :       <input type="hidden" name="in_reply_to" value="" />
already patched  templates/issue.html

this can be replaced with something like

file 4/4:    templates/issue.html
already patched  templates/issue.html

or even

file 4/4 already patched:    templates/issue.html

Original issue reported on code.google.com by [email protected] on 29 Nov 2011 at 4:40

CVE (security issues) of Linux patch utility

One of the reasons why patch.py was started was insecurity of running Unix patch utility on web server. In 2015 the Unix patch still has security issues. So it is important to put them into checklist and cover with tests to ensure that patch.py doesn't have those deficiencies. Here is the starting list that came today with Ubuntu update:

Version 2.7.1-4ubuntu2.3:

  • SECURITY UPDATE: Denial of service via crafted patch
  • SECURITY UPDATE: Directory traversal via crafted patch
  • SECURITY UPDATE: Directory traversal via crafted patch
  • SECURITY UPDATE: Directory traversal via crafted patch

Add Actions class

Actions class will allow customization of python-patch behavior like 
interactive/automatic mode, create/remove files, readonly check if the tree is 
patchable, show patch plan for confirmation by user.

Original issue reported on code.google.com by [email protected] on 27 Sep 2010 at 8:36

  • Blocking: #3

setup.py

Hi, while packaging this module for debian, we noticed that the setup.py file is missing.

This file is present in the ZIP from pip, but it would be nice for us if it were in the tarball from github as well.

Thanks, Paolo

trouble with strip level with git patches

Hi,
I have created patches using let's say git format-patch -1
To apply the patch using regular patch command line I apply: patch -p1 < patch

When trying to use instead patch.py I've tried
patch.py -p1 -- < patch
It fails

You have to apply: -p0 to get patch.py to work
This is very disturbing behaviour...
Would it be possible to use the same strip level as in regular patch

Best

Automatic GIT patch detection fails if filename contains non-word-constituent characters

Hi,

The attached example.zip contains an example where the patch type detection fails to detect a git patch because the filename contains a dash. See README.txt in the example directory for more details.

Note that I added three diagnostic lines of code to the path.py module in the example directory.

I suggest that the regular expression r'diff --git a/[\w/.]+ b/[\w/.]+' should be extended accordingly.

example.zip

P.S: Thanks for sharing your code!

Unit test possibly checking for wrong value

While running the unit tests on a modified branch of Python Patch, I've been trying to debug some of the failed tests I'm seeing. The first of these, test_multiline_false_on_other_file() would appear to be working correctly with the master branch, and failing with my branch, however, by manually checking the test patch and target files, I believe that the wrong value is being checked for.

The test uses the method assertFalse() on the return value of can_patch(), which in turn calls _match_file_hunks(). The False value here is coming from _match_file_hunks() when checking hunk 1 of the patch 01uni_multi.patch aginst updatedlg.cpp.

This is the hunk in question:

@@ -94,11 +94,13 @@
     lst->InsertColumn(1, _("Version"));
     lst->InsertColumn(2, _("Installed"));
     lst->InsertColumn(3, _("Size"), wxLIST_FORMAT_RIGHT);
+    lst->InsertColumn(4, _("Rev"));
 
-    lst->SetColumnWidth(0, lst->GetSize().x - (64 * 3) - 2); // 1st column takes all remaining space
+    lst->SetColumnWidth(0, lst->GetSize().x - (64 * 3 + 40) - 6 ); // 1st column takes all remaining space
     lst->SetColumnWidth(1, 64);
     lst->SetColumnWidth(2, 64);
     lst->SetColumnWidth(3, 64);
+    lst->SetColumnWidth(4, 40);
 }
 
 void UpdateDlg::AddRecordToList(UpdateRec* rec)

and here is the relevant section of updatedlg.cpp, starting from line 94:

    lst->InsertColumn(1, _("Version"));
    lst->InsertColumn(2, _("Installed"));
    lst->InsertColumn(3, _("Size"), wxLIST_FORMAT_RIGHT);

    lst->SetColumnWidth(0, lst->GetSize().x - (64 * 3) - 2); // 1st column takes all remaining space
    lst->SetColumnWidth(1, 64);
    lst->SetColumnWidth(2, 64);
    lst->SetColumnWidth(3, 64);
}

void UpdateDlg::AddRecordToList(UpdateRec* rec)

Checking still deeper I found that when it fails, _match_file_hunks() is in fact making the following comparison, between line 97 of the target file and the fourth line of the patch hunk, rather than the fifth:

b'' != b'    lst->InsertColumn(4, _("Rev"));'

As far as I can tell, a bug somewhere in patch.py is causing an addition line in the patch to be compared with the target file, and the unit test checking for this has been set up incorrectly, since the patch seems to be valid for the files it modifies.

Can anyone throw some light on to what exactly test_multiline_false_on_other_file() is intended to check? Am I correct in my deductions above, or have I overlooked something?

newlines at the end of source and target filenames

What steps will reproduce the problem?
1. test.py file as follows:

import patch
patch.apply_patch(patch.read_patch('my.patch'))

2. Run script with "C:\python26\python.exe test.py"

What is the expected output? What do you see instead?

Expected: 

WARNING:root:successfully patched htdocs/index.php

Received:

WARNING:root:source/target file does not exist
--- htdocs/index.php

+++ htdocs/index.php


What version of the product are you using? On what operating system?
Using patch-8.06-2, Python 2.6.2, Win XP SP3.


Fix seems to be simple, change line 133 from:

          files["source"].append(match.group(1))

to:

          files["source"].append(match.group(1).strip())

Not sure why this hasn't affected anyone before now.

Original issue reported on code.google.com by [email protected] on 14 May 2009 at 4:31

xnormapth is not cross platform @ r196

Hi Anatoly:

the code in 
http://code.google.com/p/python-patch/source/browse/trunk/patch.py#89 is not 
cross platform and will yield different results when running on posix or 
windows.

What steps will reproduce the problem?
Using a patch like this: http://drupal.org/files/issues/drupal_upload.patch

diff -Nup C:\Documents and Settings\Boki\Desktop\head\patches\drupal6/drupal.js 
C:\Documents and Settings\Boki\Desktop\head\patches\parallel uploads/drupal.js
--- C:\Documents and 
Settings\Boki\Desktop\head\patches\drupal6/drupal.js    2007-06-08 
14:52:00.000000000 +0200
+++ C:\Documents and Settings\Boki\Desktop\head\patches\parallel 
uploads/drupal.js   2007-06-16 19:27:20.953125000 +0200


We will get on posix after parsing the patch:

source: Documents and Settings\Boki\Desktop\head\patches\drupal6/drupal.js
target: Documents and Settings\Boki\Desktop\head\patches\parallel 
uploads/drupal.js


And on Windows:

source: Documents and Settings/Boki/Desktop/head/patches/drupal6/drupal.js
target: Documents and Settings/Boki/Desktop/head/patches/parallel 
uploads/drupal.js


What is the expected output? What do you see instead?
=>The output should be the same on all OS



Actual output on win:

Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import patch
>>> p=patch.fromurl('http://drupal.org/files/issues/drupal_upload.patch')
>>> p.items[0].source
'Documents and Settings/Boki/Desktop/head/patches/drupal6/drupal.js'
>>> p.items[0].target
'Documents and Settings/Boki/Desktop/head/patches/parallel uploads/drupal.js'


Actual output on posix (here with cugwin, but the same behavior has been 
verified on Linux and Macosx):
Python 2.6.5 (r265:79063, Jun 12 2010, 17:07:01)
[GCC 4.3.4 20090804 (release) 1] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import patch
>>> p=patch.fromurl('http://drupal.org/files/issues/drupal_upload.patch')
>>> p.items[0].source
'Documents and Settings\\Boki\\Desktop\\head\\patches\\drupal6/drupal.js'
>>> p.items[0].target
'Documents and Settings\\Boki\\Desktop\\head\\patches\\parallel 
uploads/drupal.js'


Tell me if you want a patch... The strategy I use in general for cross-os path 
handling is to convert at the boundaries any path to posix, and use internally 
the posixpath module for all path handling, converting back to os.path-specific 
path on demand for thing that require actual IOs to os files.

--
Cordially
Philippe

Original issue reported on code.google.com by [email protected] on 20 Apr 2013 at 11:01

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.