001.doctests-compatible-py2and3.patch 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. Description: Make doctest examples compatible with Python 2 and Python 3.
  2. .
  3. Existing doctests were written only for Python 2 and have not yet
  4. been updated upstream to work with Python 3.
  5. Author: Ben Finney <bignose@debian.org>
  6. Last-Update: 2015-05-16
  7. diff --git a/doc/source/index.rst b/doc/source/index.rst
  8. index f76173d..b4bfd4d 100644
  9. --- a/doc/source/index.rst
  10. +++ b/doc/source/index.rst
  11. @@ -224,14 +224,14 @@ This example is the "hello world" for the :mod:`lockfile` package::
  12. from lockfile import LockFile
  13. lock = LockFile("/some/file/or/other")
  14. with lock:
  15. - print lock.path, 'is locked.'
  16. + print(lock.path, "is locked.")
  17. To use this with Python 2.4, you can execute::
  18. from lockfile import LockFile
  19. lock = LockFile("/some/file/or/other")
  20. lock.acquire()
  21. - print lock.path, 'is locked.'
  22. + print(lock.path, "is locked.")
  23. lock.release()
  24. If you don't want to wait forever, you might try::
  25. @@ -244,7 +244,7 @@ If you don't want to wait forever, you might try::
  26. except LockTimeout:
  27. lock.break_lock()
  28. lock.acquire()
  29. - print "I locked", lock.path
  30. + print("I locked", lock.path)
  31. lock.release()
  32. You can also insure that a lock is always held when appropriately decorated
  33. diff --git a/lockfile/__init__.py b/lockfile/__init__.py
  34. index 419d122..339a205 100644
  35. --- a/lockfile/__init__.py
  36. +++ b/lockfile/__init__.py
  37. @@ -12,23 +12,23 @@ Usage:
  38. >>> try:
  39. ... lock.acquire()
  40. ... except AlreadyLocked:
  41. -... print 'somefile', 'is locked already.'
  42. +... print('somefile', "is locked already.")
  43. ... except LockFailed:
  44. -... print 'somefile', 'can\\'t be locked.'
  45. +... print('somefile', "can't be locked.")
  46. ... else:
  47. -... print 'got lock'
  48. +... print("got lock")
  49. got lock
  50. ->>> print lock.is_locked()
  51. +>>> lock.is_locked()
  52. True
  53. >>> lock.release()
  54. >>> lock = LockFile('somefile')
  55. ->>> print lock.is_locked()
  56. +>>> lock.is_locked()
  57. False
  58. >>> with lock:
  59. -... print lock.is_locked()
  60. +... lock.is_locked()
  61. True
  62. ->>> print lock.is_locked()
  63. +>>> lock.is_locked()
  64. False
  65. >>> lock = LockFile('somefile')
  66. @@ -37,7 +37,7 @@ False
  67. ... lock.acquire()
  68. ...
  69. >>> # Though no counter is kept, so you can't unlock multiple times...
  70. ->>> print lock.is_locked()
  71. +>>> lock.is_locked()
  72. False
  73. Exceptions:
  74. Local variables:
  75. coding: utf-8
  76. mode: diff
  77. time-stamp-format: "%:y-%02m-%02d"
  78. time-stamp-start: "^Last-Update:[ ]+"
  79. time-stamp-end: "$"
  80. time-stamp-line-limit: 20
  81. End:
  82. vim: fileencoding=utf-8 filetype=diff :