mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
Merged revisions 59407-59422 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r59407 | armin.rigo | 2007-12-07 20:19:55 +0100 (Fri, 07 Dec 2007) | 2 lines This is probably what was meant here. ........ r59410 | guido.van.rossum | 2007-12-08 05:38:23 +0100 (Sat, 08 Dec 2007) | 2 lines Be (just a bit :) more specific about release date. ........ r59411 | alexandre.vassalotti | 2007-12-08 05:49:22 +0100 (Sat, 08 Dec 2007) | 3 lines Fix issue #1530. Return an error exit status if not all tests passes. ........ r59413 | georg.brandl | 2007-12-08 11:56:39 +0100 (Sat, 08 Dec 2007) | 2 lines Fix tpyo. ........ r59414 | georg.brandl | 2007-12-08 12:05:05 +0100 (Sat, 08 Dec 2007) | 2 lines Fix markup in whatsnew, use new directive in ACKS. ........ r59415 | georg.brandl | 2007-12-08 12:05:36 +0100 (Sat, 08 Dec 2007) | 2 lines Fix Eren's name. ........ r59416 | georg.brandl | 2007-12-08 12:23:13 +0100 (Sat, 08 Dec 2007) | 2 lines Add examples to the datetime documentation. Written for GHOP by "h4wk.cz". ........ r59417 | skip.montanaro | 2007-12-08 15:37:43 +0100 (Sat, 08 Dec 2007) | 2 lines Note that open() is the preferred way to open files (issue 1510). ........ r59418 | skip.montanaro | 2007-12-08 16:23:31 +0100 (Sat, 08 Dec 2007) | 1 line + "context manager" ........ r59419 | skip.montanaro | 2007-12-08 16:26:16 +0100 (Sat, 08 Dec 2007) | 1 line correct email address ........ r59420 | skip.montanaro | 2007-12-08 16:33:24 +0100 (Sat, 08 Dec 2007) | 3 lines When splitting, avoid making a copy of the string if the split doesn't find anything (issue 1538). ........
This commit is contained in:
parent
576bf65fea
commit
895627ff27
18 changed files with 568 additions and 284 deletions
399
Doc/ACKS.txt
399
Doc/ACKS.txt
|
@ -1,206 +1,207 @@
|
||||||
Contributors to the Python Documentation
|
Contributors to the Python Documentation
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
|
|
||||||
This file lists people who have contributed in some way to the Python
|
This section lists people who have contributed in some way to the Python
|
||||||
documentation. It is probably not complete -- if you feel that you or
|
documentation. It is probably not complete -- if you feel that you or
|
||||||
anyone else should be on this list, please let us know (send email to
|
anyone else should be on this list, please let us know (send email to
|
||||||
docs@python.org), and we'll be glad to correct the problem.
|
docs@python.org), and we'll be glad to correct the problem.
|
||||||
|
|
||||||
* Aahz
|
.. acks::
|
||||||
* Michael Abbott
|
|
||||||
* Steve Alexander
|
* Aahz
|
||||||
* Jim Ahlstrom
|
* Michael Abbott
|
||||||
* Fred Allen
|
* Steve Alexander
|
||||||
* A. Amoroso
|
* Jim Ahlstrom
|
||||||
* Pehr Anderson
|
* Fred Allen
|
||||||
* Oliver Andrich
|
* A. Amoroso
|
||||||
* Jesús Cea Avión
|
* Pehr Anderson
|
||||||
* Daniel Barclay
|
* Oliver Andrich
|
||||||
* Chris Barker
|
* Jesús Cea Avión
|
||||||
* Don Bashford
|
* Daniel Barclay
|
||||||
* Anthony Baxter
|
* Chris Barker
|
||||||
* Bennett Benson
|
* Don Bashford
|
||||||
* Jonathan Black
|
* Anthony Baxter
|
||||||
* Robin Boerdijk
|
* Bennett Benson
|
||||||
* Michal Bozon
|
* Jonathan Black
|
||||||
* Aaron Brancotti
|
* Robin Boerdijk
|
||||||
* Georg Brandl
|
* Michal Bozon
|
||||||
* Keith Briggs
|
* Aaron Brancotti
|
||||||
* Lee Busby
|
* Georg Brandl
|
||||||
* Lorenzo M. Catucci
|
* Keith Briggs
|
||||||
* Carl Cerecke
|
* Lee Busby
|
||||||
* Mauro Cicognini
|
* Lorenzo M. Catucci
|
||||||
* Gilles Civario
|
* Carl Cerecke
|
||||||
* Mike Clarkson
|
* Mauro Cicognini
|
||||||
* Steve Clift
|
* Gilles Civario
|
||||||
* Dave Cole
|
* Mike Clarkson
|
||||||
* Matthew Cowles
|
* Steve Clift
|
||||||
* Jeremy Craven
|
* Dave Cole
|
||||||
* Andrew Dalke
|
* Matthew Cowles
|
||||||
* Ben Darnell
|
* Jeremy Craven
|
||||||
* L. Peter Deutsch
|
* Andrew Dalke
|
||||||
* Robert Donohue
|
* Ben Darnell
|
||||||
* Fred L. Drake, Jr.
|
* L. Peter Deutsch
|
||||||
* Josip Dzolonga
|
* Robert Donohue
|
||||||
* Jeff Epler
|
* Fred L. Drake, Jr.
|
||||||
* Michael Ernst
|
* Josip Dzolonga
|
||||||
* Blame Andy Eskilsson
|
* Jeff Epler
|
||||||
* Carey Evans
|
* Michael Ernst
|
||||||
* Martijn Faassen
|
* Blame Andy Eskilsson
|
||||||
* Carl Feynman
|
* Carey Evans
|
||||||
* Dan Finnie
|
* Martijn Faassen
|
||||||
* Hernán Martínez Foffani
|
* Carl Feynman
|
||||||
* Stefan Franke
|
* Dan Finnie
|
||||||
* Jim Fulton
|
* Hernán Martínez Foffani
|
||||||
* Peter Funk
|
* Stefan Franke
|
||||||
* Lele Gaifax
|
* Jim Fulton
|
||||||
* Matthew Gallagher
|
* Peter Funk
|
||||||
* Ben Gertzfield
|
* Lele Gaifax
|
||||||
* Nadim Ghaznavi
|
* Matthew Gallagher
|
||||||
* Jonathan Giddy
|
* Ben Gertzfield
|
||||||
* Shelley Gooch
|
* Nadim Ghaznavi
|
||||||
* Nathaniel Gray
|
* Jonathan Giddy
|
||||||
* Grant Griffin
|
* Shelley Gooch
|
||||||
* Thomas Guettler
|
* Nathaniel Gray
|
||||||
* Anders Hammarquist
|
* Grant Griffin
|
||||||
* Mark Hammond
|
* Thomas Guettler
|
||||||
* Harald Hanche-Olsen
|
* Anders Hammarquist
|
||||||
* Manus Hand
|
* Mark Hammond
|
||||||
* Gerhard Häring
|
* Harald Hanche-Olsen
|
||||||
* Peter Harris
|
* Manus Hand
|
||||||
* Travis B. Hartwell
|
* Gerhard Häring
|
||||||
* Tim Hatch
|
* Travis B. Hartwell
|
||||||
* Janko Hauser
|
* Tim Hatch
|
||||||
* Bernhard Herzog
|
* Janko Hauser
|
||||||
* Magnus L. Hetland
|
* Bernhard Herzog
|
||||||
* Konrad Hinsen
|
* Magnus L. Hetland
|
||||||
* Stefan Hoffmeister
|
* Konrad Hinsen
|
||||||
* Albert Hofkamp
|
* Stefan Hoffmeister
|
||||||
* Gregor Hoffleit
|
* Albert Hofkamp
|
||||||
* Steve Holden
|
* Gregor Hoffleit
|
||||||
* Thomas Holenstein
|
* Steve Holden
|
||||||
* Gerrit Holl
|
* Thomas Holenstein
|
||||||
* Rob Hooft
|
* Gerrit Holl
|
||||||
* Brian Hooper
|
* Rob Hooft
|
||||||
* Randall Hopper
|
* Brian Hooper
|
||||||
* Michael Hudson
|
* Randall Hopper
|
||||||
* Eric Huss
|
* Michael Hudson
|
||||||
* Jeremy Hylton
|
* Eric Huss
|
||||||
* Roger Irwin
|
* Jeremy Hylton
|
||||||
* Jack Jansen
|
* Roger Irwin
|
||||||
* Philip H. Jensen
|
* Jack Jansen
|
||||||
* Pedro Diaz Jimenez
|
* Philip H. Jensen
|
||||||
* Kent Johnson
|
* Pedro Diaz Jimenez
|
||||||
* Lucas de Jonge
|
* Kent Johnson
|
||||||
* Andreas Jung
|
* Lucas de Jonge
|
||||||
* Robert Kern
|
* Andreas Jung
|
||||||
* Jim Kerr
|
* Robert Kern
|
||||||
* Jan Kim
|
* Jim Kerr
|
||||||
* Greg Kochanski
|
* Jan Kim
|
||||||
* Guido Kollerie
|
* Greg Kochanski
|
||||||
* Peter A. Koren
|
* Guido Kollerie
|
||||||
* Daniel Kozan
|
* Peter A. Koren
|
||||||
* Andrew M. Kuchling
|
* Daniel Kozan
|
||||||
* Dave Kuhlman
|
* Andrew M. Kuchling
|
||||||
* Erno Kuusela
|
* Dave Kuhlman
|
||||||
* Thomas Lamb
|
* Erno Kuusela
|
||||||
* Detlef Lannert
|
* Thomas Lamb
|
||||||
* Piers Lauder
|
* Detlef Lannert
|
||||||
* Glyph Lefkowitz
|
* Piers Lauder
|
||||||
* Robert Lehmann
|
* Glyph Lefkowitz
|
||||||
* Marc-André Lemburg
|
* Robert Lehmann
|
||||||
* Ross Light
|
* Marc-André Lemburg
|
||||||
* Ulf A. Lindgren
|
* Ross Light
|
||||||
* Everett Lipman
|
* Ulf A. Lindgren
|
||||||
* Mirko Liss
|
* Everett Lipman
|
||||||
* Martin von Löwis
|
* Mirko Liss
|
||||||
* Fredrik Lundh
|
* Martin von Löwis
|
||||||
* Jeff MacDonald
|
* Fredrik Lundh
|
||||||
* John Machin
|
* Jeff MacDonald
|
||||||
* Andrew MacIntyre
|
* John Machin
|
||||||
* Vladimir Marangozov
|
* Andrew MacIntyre
|
||||||
* Vincent Marchetti
|
* Vladimir Marangozov
|
||||||
* Laura Matson
|
* Vincent Marchetti
|
||||||
* Daniel May
|
* Laura Matson
|
||||||
* Rebecca McCreary
|
* Daniel May
|
||||||
* Doug Mennella
|
* Rebecca McCreary
|
||||||
* Paolo Milani
|
* Doug Mennella
|
||||||
* Skip Montanaro
|
* Paolo Milani
|
||||||
* Paul Moore
|
* Skip Montanaro
|
||||||
* Ross Moore
|
* Paul Moore
|
||||||
* Sjoerd Mullender
|
* Ross Moore
|
||||||
* Dale Nagata
|
* Sjoerd Mullender
|
||||||
* Ng Pheng Siong
|
* Dale Nagata
|
||||||
* Koray Oner
|
* Ng Pheng Siong
|
||||||
* Tomas Oppelstrup
|
* Koray Oner
|
||||||
* Denis S. Otkidach
|
* Tomas Oppelstrup
|
||||||
* Zooko O'Whielacronx
|
* Denis S. Otkidach
|
||||||
* William Park
|
* Zooko O'Whielacronx
|
||||||
* Joonas Paalasmaa
|
* William Park
|
||||||
* Harri Pasanen
|
* Joonas Paalasmaa
|
||||||
* Bo Peng
|
* Harri Pasanen
|
||||||
* Tim Peters
|
* Bo Peng
|
||||||
* Christopher Petrilli
|
* Tim Peters
|
||||||
* Justin D. Pettit
|
* Christopher Petrilli
|
||||||
* Chris Phoenix
|
* Justin D. Pettit
|
||||||
* François Pinard
|
* Chris Phoenix
|
||||||
* Paul Prescod
|
* François Pinard
|
||||||
* Eric S. Raymond
|
* Paul Prescod
|
||||||
* Edward K. Ream
|
* Eric S. Raymond
|
||||||
* Sean Reifschneider
|
* Edward K. Ream
|
||||||
* Bernhard Reiter
|
* Sean Reifschneider
|
||||||
* Armin Rigo
|
* Bernhard Reiter
|
||||||
* Wes Rishel
|
* Armin Rigo
|
||||||
* Jim Roskind
|
* Wes Rishel
|
||||||
* Guido van Rossum
|
* Jim Roskind
|
||||||
* Donald Wallace Rouse II
|
* Guido van Rossum
|
||||||
* Nick Russo
|
* Donald Wallace Rouse II
|
||||||
* Chris Ryland
|
* Nick Russo
|
||||||
* Constantina S.
|
* Chris Ryland
|
||||||
* Hugh Sasse
|
* Constantina S.
|
||||||
* Bob Savage
|
* Hugh Sasse
|
||||||
* Scott Schram
|
* Bob Savage
|
||||||
* Neil Schemenauer
|
* Scott Schram
|
||||||
* Barry Scott
|
* Neil Schemenauer
|
||||||
* Joakim Sernbrant
|
* Barry Scott
|
||||||
* Justin Sheehy
|
* Joakim Sernbrant
|
||||||
* Charlie Shepherd
|
* Justin Sheehy
|
||||||
* Michael Simcich
|
* Charlie Shepherd
|
||||||
* Ionel Simionescu
|
* Michael Simcich
|
||||||
* Michael Sloan
|
* Ionel Simionescu
|
||||||
* Gregory P. Smith
|
* Michael Sloan
|
||||||
* Roy Smith
|
* Gregory P. Smith
|
||||||
* Clay Spence
|
* Roy Smith
|
||||||
* Nicholas Spies
|
* Clay Spence
|
||||||
* Tage Stabell-Kulo
|
* Nicholas Spies
|
||||||
* Frank Stajano
|
* Tage Stabell-Kulo
|
||||||
* Anthony Starks
|
* Frank Stajano
|
||||||
* Greg Stein
|
* Anthony Starks
|
||||||
* Peter Stoehr
|
* Greg Stein
|
||||||
* Mark Summerfield
|
* Peter Stoehr
|
||||||
* Reuben Sumner
|
* Mark Summerfield
|
||||||
* Kalle Svensson
|
* Reuben Sumner
|
||||||
* Jim Tittsler
|
* Kalle Svensson
|
||||||
* Ville Vainio
|
* Jim Tittsler
|
||||||
* Martijn Vries
|
* Ville Vainio
|
||||||
* Charles G. Waldman
|
* Martijn Vries
|
||||||
* Greg Ward
|
* Charles G. Waldman
|
||||||
* Barry Warsaw
|
* Greg Ward
|
||||||
* Corran Webster
|
* Barry Warsaw
|
||||||
* Glyn Webster
|
* Corran Webster
|
||||||
* Bob Weiner
|
* Glyn Webster
|
||||||
* Eddy Welbourne
|
* Bob Weiner
|
||||||
* Jeff Wheeler
|
* Eddy Welbourne
|
||||||
* Mats Wichmann
|
* Jeff Wheeler
|
||||||
* Gerry Wiener
|
* Mats Wichmann
|
||||||
* Timothy Wild
|
* Gerry Wiener
|
||||||
* Collin Winter
|
* Timothy Wild
|
||||||
* Blake Winton
|
* Collin Winter
|
||||||
* Dan Wolfe
|
* Blake Winton
|
||||||
* Steven Work
|
* Dan Wolfe
|
||||||
* Thomas Wouters
|
* Steven Work
|
||||||
* Ka-Ping Yee
|
* Thomas Wouters
|
||||||
* Rory Yorke
|
* Ka-Ping Yee
|
||||||
* Moshe Zadka
|
* Rory Yorke
|
||||||
* Milan Zamazal
|
* Moshe Zadka
|
||||||
* Cheng Zhang
|
* Milan Zamazal
|
||||||
|
* Cheng Zhang
|
||||||
|
|
|
@ -55,6 +55,11 @@ Glossary
|
||||||
advanced mathematical feature. If you're not aware of a need for them,
|
advanced mathematical feature. If you're not aware of a need for them,
|
||||||
it's almost certain you can safely ignore them.
|
it's almost certain you can safely ignore them.
|
||||||
|
|
||||||
|
context manager
|
||||||
|
Objects which control the environment seen in a :keyword:`with`
|
||||||
|
statement by defining :meth:`__enter__` and :meth:`__exit__` methods.
|
||||||
|
See :pep:`343`.
|
||||||
|
|
||||||
decorator
|
decorator
|
||||||
A function returning another function, usually applied as a function
|
A function returning another function, usually applied as a function
|
||||||
transformation using the ``@wrapper`` syntax. Common examples for
|
transformation using the ``@wrapper`` syntax. Common examples for
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
.. module:: atexit
|
.. module:: atexit
|
||||||
:synopsis: Register and execute cleanup functions.
|
:synopsis: Register and execute cleanup functions.
|
||||||
.. moduleauthor:: Skip Montanaro <skip@mojam.com>
|
.. moduleauthor:: Skip Montanaro <skip@pobox.com>
|
||||||
.. sectionauthor:: Skip Montanaro <skip@mojam.com>
|
.. sectionauthor:: Skip Montanaro <skip@pobox.com>
|
||||||
|
|
||||||
|
|
||||||
The :mod:`atexit` module defines functions to register and unregister cleanup
|
The :mod:`atexit` module defines functions to register and unregister cleanup
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
.. module:: bsddb
|
.. module:: bsddb
|
||||||
:synopsis: Interface to Berkeley DB database library
|
:synopsis: Interface to Berkeley DB database library
|
||||||
.. sectionauthor:: Skip Montanaro <skip@mojam.com>
|
.. sectionauthor:: Skip Montanaro <skip@pobox.com>
|
||||||
|
|
||||||
|
|
||||||
The :mod:`bsddb` module provides an interface to the Berkeley DB library. Users
|
The :mod:`bsddb` module provides an interface to the Berkeley DB library. Users
|
||||||
|
|
|
@ -161,6 +161,7 @@ dates or times.
|
||||||
Note that normalization of negative values may be surprising at first. For
|
Note that normalization of negative values may be surprising at first. For
|
||||||
example, ::
|
example, ::
|
||||||
|
|
||||||
|
>>> from datetime import timedelta
|
||||||
>>> d = timedelta(microseconds=-1)
|
>>> d = timedelta(microseconds=-1)
|
||||||
>>> (d.days, d.seconds, d.microseconds)
|
>>> (d.days, d.seconds, d.microseconds)
|
||||||
(-1, 86399, 999999)
|
(-1, 86399, 999999)
|
||||||
|
@ -264,6 +265,26 @@ comparison is ``==`` or ``!=``. The latter cases return :const:`False` or
|
||||||
efficient pickling, and in Boolean contexts, a :class:`timedelta` object is
|
efficient pickling, and in Boolean contexts, a :class:`timedelta` object is
|
||||||
considered to be true if and only if it isn't equal to ``timedelta(0)``.
|
considered to be true if and only if it isn't equal to ``timedelta(0)``.
|
||||||
|
|
||||||
|
Example usage::
|
||||||
|
|
||||||
|
>>> from datetime import timedelta
|
||||||
|
>>> year = timedelta(days=365)
|
||||||
|
>>> another_year = timedelta(weeks=40, days=84, hours=23,
|
||||||
|
... minutes=50, seconds=600) # adds up to 365 days
|
||||||
|
>>> year == another_year
|
||||||
|
True
|
||||||
|
>>> ten_years = 10 * year
|
||||||
|
>>> ten_years, ten_years.days // 365
|
||||||
|
(datetime.timedelta(3650), 10)
|
||||||
|
>>> nine_years = ten_years - year
|
||||||
|
>>> nine_years, nine_years.days // 365
|
||||||
|
(datetime.timedelta(3285), 9)
|
||||||
|
>>> three_years = nine_years // 3;
|
||||||
|
>>> three_years, three_years.days // 365
|
||||||
|
(datetime.timedelta(1095), 3)
|
||||||
|
>>> abs(three_years - ten_years) == 2 * three_years + year
|
||||||
|
True
|
||||||
|
|
||||||
|
|
||||||
.. _datetime-date:
|
.. _datetime-date:
|
||||||
|
|
||||||
|
@ -485,6 +506,55 @@ Instance methods:
|
||||||
Format codes referring to hours, minutes or seconds will see 0 values. See
|
Format codes referring to hours, minutes or seconds will see 0 values. See
|
||||||
section :ref:`strftime-behavior`.
|
section :ref:`strftime-behavior`.
|
||||||
|
|
||||||
|
Example of counting days to an event::
|
||||||
|
|
||||||
|
>>> import time
|
||||||
|
>>> from datetime import date
|
||||||
|
>>> today = date.today()
|
||||||
|
>>> today
|
||||||
|
datetime.date(2007, 12, 5)
|
||||||
|
>>> today == date.fromtimestamp(time.time())
|
||||||
|
True
|
||||||
|
>>> my_birthday = date(today.year, 6, 24)
|
||||||
|
>>> if my_birthday < today:
|
||||||
|
... my_birthday = my_birthday.replace(year=today.year + 1)
|
||||||
|
>>> my_birthday
|
||||||
|
datetime.date(2008, 6, 24)
|
||||||
|
>>> time_to_birthday = abs(my_birthday - today)
|
||||||
|
>>> time_to_birthday.days
|
||||||
|
202
|
||||||
|
|
||||||
|
Example of working with :class:`date`::
|
||||||
|
|
||||||
|
>>> from datetime import date
|
||||||
|
>>> d = date.fromordinal(730920) # 730920th day after 1. 1. 0001
|
||||||
|
>>> d
|
||||||
|
datetime.date(2002, 3, 11)
|
||||||
|
>>> t = d.timetuple()
|
||||||
|
>>> for i in t:
|
||||||
|
... print i
|
||||||
|
2002 # year
|
||||||
|
3 # month
|
||||||
|
11 # day
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0 # weekday (0 = Monday)
|
||||||
|
70 # 70th day in the year
|
||||||
|
-1
|
||||||
|
>>> ic = d.isocalendar()
|
||||||
|
>>> for i in ic:
|
||||||
|
... print i # doctest: +SKIP
|
||||||
|
2002 # ISO year
|
||||||
|
11 # ISO week number
|
||||||
|
1 # ISO day number ( 1 = Monday )
|
||||||
|
>>> d.isoformat()
|
||||||
|
'2002-03-11'
|
||||||
|
>>> d.strftime("%d/%m/%y")
|
||||||
|
'11/03/02'
|
||||||
|
>>> d.strftime("%A %d. %B %Y")
|
||||||
|
'Monday 11. March 2002'
|
||||||
|
|
||||||
|
|
||||||
.. _datetime-datetime:
|
.. _datetime-datetime:
|
||||||
|
|
||||||
|
@ -919,6 +989,106 @@ Instance methods:
|
||||||
Return a string representing the date and time, controlled by an explicit format
|
Return a string representing the date and time, controlled by an explicit format
|
||||||
string. See section :ref:`strftime-behavior`.
|
string. See section :ref:`strftime-behavior`.
|
||||||
|
|
||||||
|
Examples of working with datetime objects::
|
||||||
|
|
||||||
|
>>> from datetime import datetime, date, time
|
||||||
|
>>> # Using datetime.combine()
|
||||||
|
>>> d = date(2005, 7, 14)
|
||||||
|
>>> t = time(12, 30)
|
||||||
|
>>> datetime.combine(d, t)
|
||||||
|
datetime.datetime(2005, 7, 14, 12, 30)
|
||||||
|
>>> # Using datetime.now() or datetime.utcnow()
|
||||||
|
>>> datetime.now()
|
||||||
|
datetime.datetime(2007, 12, 6, 16, 29, 43, 79043) # GMT +1
|
||||||
|
>>> datetime.utcnow()
|
||||||
|
datetime.datetime(2007, 12, 6, 15, 29, 43, 79060)
|
||||||
|
>>> # Using datetime.strptime()
|
||||||
|
>>> dt = datetime.strptime("21/11/06 16:30", "%d/%m/%y %H:%M")
|
||||||
|
>>> dt
|
||||||
|
datetime.datetime(2006, 11, 21, 16, 30)
|
||||||
|
>>> # Using datetime.timetuple() to get tuple of all attributes
|
||||||
|
>>> tt = dt.timetuple()
|
||||||
|
>>> for it in tt:
|
||||||
|
... print it
|
||||||
|
...
|
||||||
|
2006 # year
|
||||||
|
11 # month
|
||||||
|
21 # day
|
||||||
|
16 # hour
|
||||||
|
30 # minute
|
||||||
|
0 # second
|
||||||
|
1 # weekday (0 = Monday)
|
||||||
|
325 # number of days since 1st January
|
||||||
|
-1 # dst - method tzinfo.dst() returned None
|
||||||
|
>>> # Date in ISO format
|
||||||
|
>>> ic = dt.isocalendar()
|
||||||
|
>>> for it in ic:
|
||||||
|
... print it
|
||||||
|
...
|
||||||
|
2006 # ISO year
|
||||||
|
47 # ISO week
|
||||||
|
2 # ISO weekday
|
||||||
|
>>> # Formatting datetime
|
||||||
|
>>> dt.strftime("%A, %d. %B %Y %I:%M%p")
|
||||||
|
'Tuesday, 21. November 2006 04:30PM'
|
||||||
|
|
||||||
|
Using datetime with tzinfo::
|
||||||
|
|
||||||
|
>>> from datetime import timedelta, datetime, tzinfo
|
||||||
|
>>> class GMT1(tzinfo):
|
||||||
|
... def __init__(self): # DST starts last Sunday in March
|
||||||
|
... d = datetime(dt.year, 4, 1) # ends last Sunday in October
|
||||||
|
... self.dston = d - timedelta(days=d.weekday() + 1)
|
||||||
|
... d = datetime(dt.year, 11, 1)
|
||||||
|
... self.dstoff = d - timedelta(days=d.weekday() + 1)
|
||||||
|
... def utcoffset(self, dt):
|
||||||
|
... return timedelta(hours=1) + self.dst(dt)
|
||||||
|
... def dst(self, dt):
|
||||||
|
... if self.dston <= dt.replace(tzinfo=None) < self.dstoff:
|
||||||
|
... return timedelta(hours=1)
|
||||||
|
... else:
|
||||||
|
... return timedelta(0)
|
||||||
|
... def tzname(self,dt):
|
||||||
|
... return "GMT +1"
|
||||||
|
...
|
||||||
|
>>> class GMT2(tzinfo):
|
||||||
|
... def __init__(self):
|
||||||
|
... d = datetime(dt.year, 4, 1)
|
||||||
|
... self.dston = d - timedelta(days=d.weekday() + 1)
|
||||||
|
... d = datetime(dt.year, 11, 1)
|
||||||
|
... self.dstoff = d - timedelta(days=d.weekday() + 1)
|
||||||
|
... def utcoffset(self, dt):
|
||||||
|
... return timedelta(hours=1) + self.dst(dt)
|
||||||
|
... def dst(self, dt):
|
||||||
|
... if self.dston <= dt.replace(tzinfo=None) < self.dstoff:
|
||||||
|
... return timedelta(hours=2)
|
||||||
|
... else:
|
||||||
|
... return timedelta(0)
|
||||||
|
... def tzname(self,dt):
|
||||||
|
... return "GMT +2"
|
||||||
|
...
|
||||||
|
>>> gmt1 = GMT1()
|
||||||
|
>>> # Daylight Saving Time
|
||||||
|
>>> dt1 = datetime(2006, 11, 21, 16, 30, tzinfo=gmt1)
|
||||||
|
>>> dt1.dst()
|
||||||
|
datetime.timedelta(0)
|
||||||
|
>>> dt1.utcoffset()
|
||||||
|
datetime.timedelta(0, 3600)
|
||||||
|
>>> dt2 = datetime(2006, 6, 14, 13, 0, tzinfo=gmt1)
|
||||||
|
>>> dt2.dst()
|
||||||
|
datetime.timedelta(0, 3600)
|
||||||
|
>>> dt2.utcoffset()
|
||||||
|
datetime.timedelta(0, 7200)
|
||||||
|
>>> # Convert datetime to another time zone
|
||||||
|
>>> dt3 = dt2.astimezone(GMT2())
|
||||||
|
>>> dt3 # doctest: +ELLIPSIS
|
||||||
|
datetime.datetime(2006, 6, 14, 14, 0, tzinfo=<GMT2 object at 0x...>)
|
||||||
|
>>> dt2 # doctest: +ELLIPSIS
|
||||||
|
datetime.datetime(2006, 6, 14, 13, 0, tzinfo=<GMT1 object at 0x...>)
|
||||||
|
>>> dt2.utctimetuple() == dt3.utctimetuple()
|
||||||
|
True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.. _datetime-time:
|
.. _datetime-time:
|
||||||
|
|
||||||
|
@ -1064,6 +1234,30 @@ Instance methods:
|
||||||
``self.tzinfo.tzname(None)``, or raises an exception if the latter doesn't
|
``self.tzinfo.tzname(None)``, or raises an exception if the latter doesn't
|
||||||
return ``None`` or a string object.
|
return ``None`` or a string object.
|
||||||
|
|
||||||
|
Example::
|
||||||
|
|
||||||
|
>>> from datetime import time, tzinfo
|
||||||
|
>>> class GMT1(tzinfo):
|
||||||
|
... def utcoffset(self, dt):
|
||||||
|
... return timedelta(hours=1)
|
||||||
|
... def dst(self, dt):
|
||||||
|
... return timedelta(0)
|
||||||
|
... def tzname(self,dt):
|
||||||
|
... return "Europe/Prague"
|
||||||
|
...
|
||||||
|
>>> t = time(12, 10, 30, tzinfo=GMT1())
|
||||||
|
>>> t # doctest: +ELLIPSIS
|
||||||
|
datetime.time(12, 10, 30, tzinfo=<GMT1 object at 0x...>)
|
||||||
|
>>> gmt = GMT1()
|
||||||
|
>>> t.isoformat()
|
||||||
|
'12:10:30+01:00'
|
||||||
|
>>> t.dst()
|
||||||
|
datetime.timedelta(0)
|
||||||
|
>>> t.tzname()
|
||||||
|
'Europe/Prague'
|
||||||
|
>>> t.strftime("%H:%M:%S %Z")
|
||||||
|
'12:10:30 Europe/Prague'
|
||||||
|
|
||||||
|
|
||||||
.. _datetime-tzinfo:
|
.. _datetime-tzinfo:
|
||||||
|
|
||||||
|
@ -1277,7 +1471,7 @@ Applications that can't bear such ambiguities should avoid using hybrid
|
||||||
:class:`tzinfo` subclasses; there are no ambiguities when using UTC, or any
|
:class:`tzinfo` subclasses; there are no ambiguities when using UTC, or any
|
||||||
other fixed-offset :class:`tzinfo` subclass (such as a class representing only
|
other fixed-offset :class:`tzinfo` subclass (such as a class representing only
|
||||||
EST (fixed offset -5 hours), or only EDT (fixed offset -4 hours)).
|
EST (fixed offset -5 hours), or only EDT (fixed offset -4 hours)).
|
||||||
|
|
||||||
|
|
||||||
.. _strftime-behavior:
|
.. _strftime-behavior:
|
||||||
|
|
||||||
|
@ -1298,48 +1492,113 @@ For :class:`date` objects, the format codes for hours, minutes, and seconds
|
||||||
should not be used, as :class:`date` objects have no such values. If they're
|
should not be used, as :class:`date` objects have no such values. If they're
|
||||||
used anyway, ``0`` is substituted for them.
|
used anyway, ``0`` is substituted for them.
|
||||||
|
|
||||||
For a naive object, the ``%z`` and ``%Z`` format codes are replaced by empty
|
|
||||||
strings.
|
|
||||||
|
|
||||||
For an aware object:
|
|
||||||
|
|
||||||
``%z``
|
|
||||||
:meth:`utcoffset` is transformed into a 5-character string of the form +HHMM or
|
|
||||||
-HHMM, where HH is a 2-digit string giving the number of UTC offset hours, and
|
|
||||||
MM is a 2-digit string giving the number of UTC offset minutes. For example, if
|
|
||||||
:meth:`utcoffset` returns ``timedelta(hours=-3, minutes=-30)``, ``%z`` is
|
|
||||||
replaced with the string ``'-0330'``.
|
|
||||||
|
|
||||||
``%Z``
|
|
||||||
If :meth:`tzname` returns ``None``, ``%Z`` is replaced by an empty string.
|
|
||||||
Otherwise ``%Z`` is replaced by the returned value, which must be a string.
|
|
||||||
|
|
||||||
The full set of format codes supported varies across platforms, because Python
|
The full set of format codes supported varies across platforms, because Python
|
||||||
calls the platform C library's :func:`strftime` function, and platform
|
calls the platform C library's :func:`strftime` function, and platform
|
||||||
variations are common. The documentation for Python's :mod:`time` module lists
|
variations are common.
|
||||||
the format codes that the C standard (1989 version) requires, and those work on
|
|
||||||
all platforms with a standard C implementation. Note that the 1999 version of
|
The following is a list of all the format codes that the C standard (1989
|
||||||
the C standard added additional format codes.
|
version) requires, and these work on all platforms with a standard C
|
||||||
|
implementation. Note that the 1999 version of the C standard added additional
|
||||||
|
format codes.
|
||||||
|
|
||||||
The exact range of years for which :meth:`strftime` works also varies across
|
The exact range of years for which :meth:`strftime` works also varies across
|
||||||
platforms. Regardless of platform, years before 1900 cannot be used.
|
platforms. Regardless of platform, years before 1900 cannot be used.
|
||||||
|
|
||||||
.. % %% This example is obsolete, since strptime is now supported by datetime.
|
+-----------+--------------------------------+-------+
|
||||||
.. %
|
| Directive | Meaning | Notes |
|
||||||
.. % \subsection{Examples}
|
+===========+================================+=======+
|
||||||
.. %
|
| ``%a`` | Locale's abbreviated weekday | |
|
||||||
.. % \subsubsection{Creating Datetime Objects from Formatted Strings}
|
| | name. | |
|
||||||
.. %
|
+-----------+--------------------------------+-------+
|
||||||
.. % The \class{datetime} class does not directly support parsing formatted time
|
| ``%A`` | Locale's full weekday name. | |
|
||||||
.. % strings. You can use \function{time.strptime} to do the parsing and create
|
+-----------+--------------------------------+-------+
|
||||||
.. % a \class{datetime} object from the tuple it returns:
|
| ``%b`` | Locale's abbreviated month | |
|
||||||
.. %
|
| | name. | |
|
||||||
.. % \begin{verbatim}
|
+-----------+--------------------------------+-------+
|
||||||
.. % >>> s = "2005-12-06T12:13:14"
|
| ``%B`` | Locale's full month name. | |
|
||||||
.. % >>> from datetime import datetime
|
+-----------+--------------------------------+-------+
|
||||||
.. % >>> from time import strptime
|
| ``%c`` | Locale's appropriate date and | |
|
||||||
.. % >>> datetime(*strptime(s, "%Y-%m-%dT%H:%M:%S")[0:6])
|
| | time representation. | |
|
||||||
.. % datetime.datetime(2005, 12, 6, 12, 13, 14)
|
+-----------+--------------------------------+-------+
|
||||||
.. % \end{verbatim}
|
| ``%d`` | Day of the month as a decimal | |
|
||||||
.. %
|
| | number [01,31]. | |
|
||||||
|
+-----------+--------------------------------+-------+
|
||||||
|
| ``%H`` | Hour (24-hour clock) as a | |
|
||||||
|
| | decimal number [00,23]. | |
|
||||||
|
+-----------+--------------------------------+-------+
|
||||||
|
| ``%I`` | Hour (12-hour clock) as a | |
|
||||||
|
| | decimal number [01,12]. | |
|
||||||
|
+-----------+--------------------------------+-------+
|
||||||
|
| ``%j`` | Day of the year as a decimal | |
|
||||||
|
| | number [001,366]. | |
|
||||||
|
+-----------+--------------------------------+-------+
|
||||||
|
| ``%m`` | Month as a decimal number | |
|
||||||
|
| | [01,12]. | |
|
||||||
|
+-----------+--------------------------------+-------+
|
||||||
|
| ``%M`` | Minute as a decimal number | |
|
||||||
|
| | [00,59]. | |
|
||||||
|
+-----------+--------------------------------+-------+
|
||||||
|
| ``%p`` | Locale's equivalent of either | \(1) |
|
||||||
|
| | AM or PM. | |
|
||||||
|
+-----------+--------------------------------+-------+
|
||||||
|
| ``%S`` | Second as a decimal number | \(2) |
|
||||||
|
| | [00,61]. | |
|
||||||
|
+-----------+--------------------------------+-------+
|
||||||
|
| ``%U`` | Week number of the year | \(3) |
|
||||||
|
| | (Sunday as the first day of | |
|
||||||
|
| | the week) as a decimal number | |
|
||||||
|
| | [00,53]. All days in a new | |
|
||||||
|
| | year preceding the first | |
|
||||||
|
| | Sunday are considered to be in | |
|
||||||
|
| | week 0. | |
|
||||||
|
+-----------+--------------------------------+-------+
|
||||||
|
| ``%w`` | Weekday as a decimal number | |
|
||||||
|
| | [0(Sunday),6]. | |
|
||||||
|
+-----------+--------------------------------+-------+
|
||||||
|
| ``%W`` | Week number of the year | \(3) |
|
||||||
|
| | (Monday as the first day of | |
|
||||||
|
| | the week) as a decimal number | |
|
||||||
|
| | [00,53]. All days in a new | |
|
||||||
|
| | year preceding the first | |
|
||||||
|
| | Monday are considered to be in | |
|
||||||
|
| | week 0. | |
|
||||||
|
+-----------+--------------------------------+-------+
|
||||||
|
| ``%x`` | Locale's appropriate date | |
|
||||||
|
| | representation. | |
|
||||||
|
+-----------+--------------------------------+-------+
|
||||||
|
| ``%X`` | Locale's appropriate time | |
|
||||||
|
| | representation. | |
|
||||||
|
+-----------+--------------------------------+-------+
|
||||||
|
| ``%y`` | Year without century as a | |
|
||||||
|
| | decimal number [00,99]. | |
|
||||||
|
+-----------+--------------------------------+-------+
|
||||||
|
| ``%Y`` | Year with century as a decimal | |
|
||||||
|
| | number. | |
|
||||||
|
+-----------+--------------------------------+-------+
|
||||||
|
| ``%z`` | UTC offset in the form +HHMM | \(4) |
|
||||||
|
| | or -HHMM (empty string if the | |
|
||||||
|
| | the object is naive). | |
|
||||||
|
+-----------+--------------------------------+-------+
|
||||||
|
| ``%Z`` | Time zone name (empty string | |
|
||||||
|
| | if the object is naive). | |
|
||||||
|
+-----------+--------------------------------+-------+
|
||||||
|
| ``%%`` | A literal ``'%'`` character. | |
|
||||||
|
+-----------+--------------------------------+-------+
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
|
||||||
|
(1)
|
||||||
|
When used with the :func:`strptime` function, the ``%p`` directive only affects
|
||||||
|
the output hour field if the ``%I`` directive is used to parse the hour.
|
||||||
|
|
||||||
|
(2)
|
||||||
|
The range really is ``0`` to ``61``; this accounts for leap seconds and the
|
||||||
|
(very rare) double leap seconds.
|
||||||
|
|
||||||
|
(3)
|
||||||
|
When used with the :func:`strptime` function, ``%U`` and ``%W`` are only used in
|
||||||
|
calculations when the day of the week and the year are specified.
|
||||||
|
|
||||||
|
(4)
|
||||||
|
For example, if :meth:`utcoffset` returns ``timedelta(hours=-3, minutes=-30)``,
|
||||||
|
``%z`` is replaced with the string ``'-0330'``.
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
|
|
||||||
.. % LaTeX'ized from the comments in the module by Skip Montanaro
|
.. % LaTeX'ized from the comments in the module by Skip Montanaro
|
||||||
.. % <skip@mojam.com>.
|
.. % <skip@pobox.com>.
|
||||||
|
|
||||||
The :mod:`mhlib` module provides a Python interface to MH folders and their
|
The :mod:`mhlib` module provides a Python interface to MH folders and their
|
||||||
contents.
|
contents.
|
||||||
|
|
|
@ -155,7 +155,7 @@ Finally, :class:`MultiFile` instances have two public instance variables:
|
||||||
:class:`MultiFile` Example
|
:class:`MultiFile` Example
|
||||||
--------------------------
|
--------------------------
|
||||||
|
|
||||||
.. sectionauthor:: Skip Montanaro <skip@mojam.com>
|
.. sectionauthor:: Skip Montanaro <skip@pobox.com>
|
||||||
|
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
.. module:: readline
|
.. module:: readline
|
||||||
:platform: Unix
|
:platform: Unix
|
||||||
:synopsis: GNU readline support for Python.
|
:synopsis: GNU readline support for Python.
|
||||||
.. sectionauthor:: Skip Montanaro <skip@mojam.com>
|
.. sectionauthor:: Skip Montanaro <skip@pobox.com>
|
||||||
|
|
||||||
|
|
||||||
The :mod:`readline` module defines a number of functions to facilitate
|
The :mod:`readline` module defines a number of functions to facilitate
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
.. module:: robotparser
|
.. module:: robotparser
|
||||||
:synopsis: Loads a robots.txt file and answers questions about fetchability of other URLs.
|
:synopsis: Loads a robots.txt file and answers questions about fetchability of other URLs.
|
||||||
.. sectionauthor:: Skip Montanaro <skip@mojam.com>
|
.. sectionauthor:: Skip Montanaro <skip@pobox.com>
|
||||||
|
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
.. module:: telnetlib
|
.. module:: telnetlib
|
||||||
:synopsis: Telnet client class.
|
:synopsis: Telnet client class.
|
||||||
.. sectionauthor:: Skip Montanaro <skip@mojam.com>
|
.. sectionauthor:: Skip Montanaro <skip@pobox.com>
|
||||||
|
|
||||||
|
|
||||||
.. index:: single: protocol; Telnet
|
.. index:: single: protocol; Telnet
|
||||||
|
|
|
@ -363,7 +363,7 @@ Restrictions:
|
||||||
URLopener Objects
|
URLopener Objects
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
.. sectionauthor:: Skip Montanaro <skip@mojam.com>
|
.. sectionauthor:: Skip Montanaro <skip@pobox.com>
|
||||||
|
|
||||||
|
|
||||||
:class:`URLopener` and :class:`FancyURLopener` objects have the following
|
:class:`URLopener` and :class:`FancyURLopener` objects have the following
|
||||||
|
|
|
@ -545,9 +545,9 @@ complete list of changes, or look through the CVS logs for all the details.
|
||||||
(Contributed by Raymond Hettinger.)
|
(Contributed by Raymond Hettinger.)
|
||||||
|
|
||||||
* Another change to the :mod:`collections` module is that the
|
* Another change to the :mod:`collections` module is that the
|
||||||
:class:`deque` type now supports an optional `maxlen` parameter;
|
:class:`deque` type now supports an optional *maxlen* parameter;
|
||||||
if supplied, the deque's size will be restricted to no more
|
if supplied, the deque's size will be restricted to no more
|
||||||
than ``maxlen`` items. Adding more items to a full deque causes
|
than *maxlen* items. Adding more items to a full deque causes
|
||||||
old items to be discarded.
|
old items to be discarded.
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
|
@ -2651,12 +2651,15 @@ def _test():
|
||||||
sys.path.insert(0, dirname)
|
sys.path.insert(0, dirname)
|
||||||
m = __import__(filename[:-3])
|
m = __import__(filename[:-3])
|
||||||
del sys.path[0]
|
del sys.path[0]
|
||||||
testmod(m)
|
failures, _ = testmod(m)
|
||||||
else:
|
else:
|
||||||
testfile(filename, module_relative=False)
|
failures, _ = testfile(filename, module_relative=False)
|
||||||
|
if failures:
|
||||||
|
return 1
|
||||||
else:
|
else:
|
||||||
r = unittest.TextTestRunner()
|
r = unittest.TextTestRunner()
|
||||||
r.run(DocTestSuite())
|
r.run(DocTestSuite())
|
||||||
|
return 0
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
_test()
|
sys.exit(_test())
|
||||||
|
|
|
@ -478,7 +478,7 @@ class HTTPResponse:
|
||||||
# Some HTTP/1.0 implementations have support for persistent
|
# Some HTTP/1.0 implementations have support for persistent
|
||||||
# connections, using rules different than HTTP/1.1.
|
# connections, using rules different than HTTP/1.1.
|
||||||
|
|
||||||
# For older HTTP, Keep-Alive indiciates persistent connection.
|
# For older HTTP, Keep-Alive indicates persistent connection.
|
||||||
if self.msg.getheader("keep-alive"):
|
if self.msg.getheader("keep-alive"):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ Writing Python Regression Tests
|
||||||
+++++++++++++++++++++++++++++++
|
+++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
:Author: Skip Montanaro
|
:Author: Skip Montanaro
|
||||||
:Contact: skip@mojam.com
|
:Contact: skip@pobox.com
|
||||||
|
|
||||||
Introduction
|
Introduction
|
||||||
============
|
============
|
||||||
|
@ -382,15 +382,6 @@ test_support provides the following useful objects:
|
||||||
statement is *not* correct Python syntax.
|
statement is *not* correct Python syntax.
|
||||||
|
|
||||||
|
|
||||||
Python and C statement coverage results are currently available at
|
|
||||||
|
|
||||||
http://www.musi-cal.com/~skip/python/Python/dist/src/
|
|
||||||
|
|
||||||
As of this writing (July, 2000) these results are being generated nightly.
|
|
||||||
You can refer to the summaries and the test coverage output files to see
|
|
||||||
where coverage is adequate or lacking and write test cases to beef up the
|
|
||||||
coverage.
|
|
||||||
|
|
||||||
Some Non-Obvious regrtest Features
|
Some Non-Obvious regrtest Features
|
||||||
==================================
|
==================================
|
||||||
* Automagic test detection: When you create a new test file
|
* Automagic test detection: When you create a new test file
|
||||||
|
|
|
@ -299,7 +299,7 @@ class test__mkstemp_inner(TC):
|
||||||
# On Windows a spawn* /path/ with embedded spaces shouldn't be quoted,
|
# On Windows a spawn* /path/ with embedded spaces shouldn't be quoted,
|
||||||
# but an arg with embedded spaces should be decorated with double
|
# but an arg with embedded spaces should be decorated with double
|
||||||
# quotes on each end
|
# quotes on each end
|
||||||
if sys.platform in ('win32'):
|
if sys.platform in ('win32',):
|
||||||
decorated = '"%s"' % sys.executable
|
decorated = '"%s"' % sys.executable
|
||||||
tester = '"%s"' % tester
|
tester = '"%s"' % tester
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -190,7 +190,6 @@ David Ely
|
||||||
Jeff Epler
|
Jeff Epler
|
||||||
Tom Epperly
|
Tom Epperly
|
||||||
Stoffel Erasmus
|
Stoffel Erasmus
|
||||||
Turkay Eren
|
|
||||||
Jürgen A. Erhard
|
Jürgen A. Erhard
|
||||||
Michael Ernst
|
Michael Ernst
|
||||||
Ben Escoto
|
Ben Escoto
|
||||||
|
@ -665,6 +664,7 @@ Anthony Tuininga
|
||||||
Christopher Tur Lesniewski-Laas
|
Christopher Tur Lesniewski-Laas
|
||||||
Stephen Turner
|
Stephen Turner
|
||||||
Bill Tutt
|
Bill Tutt
|
||||||
|
Eren Türkay
|
||||||
Doobee R. Tzeck
|
Doobee R. Tzeck
|
||||||
Lionel Ulmer
|
Lionel Ulmer
|
||||||
Roger Upole
|
Roger Upole
|
||||||
|
|
|
@ -1061,8 +1061,9 @@ static const char *stripformat[] = {"|O:lstrip", "|O:rstrip", "|O:strip"};
|
||||||
#define RSKIP_NONSPACE(s, i) { while (i>=0 && !ISSPACE(s[i])) i--; }
|
#define RSKIP_NONSPACE(s, i) { while (i>=0 && !ISSPACE(s[i])) i--; }
|
||||||
|
|
||||||
Py_LOCAL_INLINE(PyObject *)
|
Py_LOCAL_INLINE(PyObject *)
|
||||||
split_whitespace(const char *s, Py_ssize_t len, Py_ssize_t maxsplit)
|
split_whitespace(PyStringObject *self, Py_ssize_t len, Py_ssize_t maxsplit)
|
||||||
{
|
{
|
||||||
|
const char *s = PyString_AS_STRING(self);
|
||||||
Py_ssize_t i, j, count=0;
|
Py_ssize_t i, j, count=0;
|
||||||
PyObject *str;
|
PyObject *str;
|
||||||
PyObject *list = PyList_New(PREALLOC_SIZE(maxsplit));
|
PyObject *list = PyList_New(PREALLOC_SIZE(maxsplit));
|
||||||
|
@ -1077,6 +1078,13 @@ split_whitespace(const char *s, Py_ssize_t len, Py_ssize_t maxsplit)
|
||||||
if (i==len) break;
|
if (i==len) break;
|
||||||
j = i; i++;
|
j = i; i++;
|
||||||
SKIP_NONSPACE(s, i, len);
|
SKIP_NONSPACE(s, i, len);
|
||||||
|
if (j == 0 && i == len && PyString_CheckExact(self)) {
|
||||||
|
/* No whitespace in self, so just use it as list[0] */
|
||||||
|
Py_INCREF(self);
|
||||||
|
PyList_SET_ITEM(list, 0, (PyObject *)self);
|
||||||
|
count++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
SPLIT_ADD(s, j, i);
|
SPLIT_ADD(s, j, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1095,8 +1103,9 @@ split_whitespace(const char *s, Py_ssize_t len, Py_ssize_t maxsplit)
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_LOCAL_INLINE(PyObject *)
|
Py_LOCAL_INLINE(PyObject *)
|
||||||
split_char(const char *s, Py_ssize_t len, char ch, Py_ssize_t maxcount)
|
split_char(PyStringObject *self, Py_ssize_t len, char ch, Py_ssize_t maxcount)
|
||||||
{
|
{
|
||||||
|
const char *s = PyString_AS_STRING(self);
|
||||||
register Py_ssize_t i, j, count=0;
|
register Py_ssize_t i, j, count=0;
|
||||||
PyObject *str;
|
PyObject *str;
|
||||||
PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
|
PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
|
||||||
|
@ -1115,7 +1124,13 @@ split_char(const char *s, Py_ssize_t len, char ch, Py_ssize_t maxcount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i <= len) {
|
if (i == 0 && count == 0 && PyString_CheckExact(self)) {
|
||||||
|
/* ch not in self, so just use self as list[0] */
|
||||||
|
Py_INCREF(self);
|
||||||
|
PyList_SET_ITEM(list, 0, (PyObject *)self);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
else if (i <= len) {
|
||||||
SPLIT_ADD(s, i, len);
|
SPLIT_ADD(s, i, len);
|
||||||
}
|
}
|
||||||
FIX_PREALLOC_SIZE(list);
|
FIX_PREALLOC_SIZE(list);
|
||||||
|
@ -1151,7 +1166,7 @@ string_split(PyStringObject *self, PyObject *args)
|
||||||
if (maxsplit < 0)
|
if (maxsplit < 0)
|
||||||
maxsplit = PY_SSIZE_T_MAX;
|
maxsplit = PY_SSIZE_T_MAX;
|
||||||
if (subobj == Py_None)
|
if (subobj == Py_None)
|
||||||
return split_whitespace(s, len, maxsplit);
|
return split_whitespace(self, len, maxsplit);
|
||||||
if (_getbuffer(subobj, &vsub) < 0)
|
if (_getbuffer(subobj, &vsub) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
sub = vsub.buf;
|
sub = vsub.buf;
|
||||||
|
@ -1162,11 +1177,8 @@ string_split(PyStringObject *self, PyObject *args)
|
||||||
PyObject_ReleaseBuffer(subobj, &vsub);
|
PyObject_ReleaseBuffer(subobj, &vsub);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
else if (n == 1) {
|
else if (n == 1)
|
||||||
char ch = sub[0];
|
return split_char(self, len, sub[0], maxsplit);
|
||||||
PyObject_ReleaseBuffer(subobj, &vsub);
|
|
||||||
return split_char(s, len, ch, maxsplit);
|
|
||||||
}
|
|
||||||
|
|
||||||
list = PyList_New(PREALLOC_SIZE(maxsplit));
|
list = PyList_New(PREALLOC_SIZE(maxsplit));
|
||||||
if (list == NULL) {
|
if (list == NULL) {
|
||||||
|
@ -1263,8 +1275,9 @@ string_rpartition(PyStringObject *self, PyObject *sep_obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_LOCAL_INLINE(PyObject *)
|
Py_LOCAL_INLINE(PyObject *)
|
||||||
rsplit_whitespace(const char *s, Py_ssize_t len, Py_ssize_t maxsplit)
|
rsplit_whitespace(PyStringObject *self, Py_ssize_t len, Py_ssize_t maxsplit)
|
||||||
{
|
{
|
||||||
|
const char *s = PyString_AS_STRING(self);
|
||||||
Py_ssize_t i, j, count=0;
|
Py_ssize_t i, j, count=0;
|
||||||
PyObject *str;
|
PyObject *str;
|
||||||
PyObject *list = PyList_New(PREALLOC_SIZE(maxsplit));
|
PyObject *list = PyList_New(PREALLOC_SIZE(maxsplit));
|
||||||
|
@ -1279,6 +1292,13 @@ rsplit_whitespace(const char *s, Py_ssize_t len, Py_ssize_t maxsplit)
|
||||||
if (i<0) break;
|
if (i<0) break;
|
||||||
j = i; i--;
|
j = i; i--;
|
||||||
RSKIP_NONSPACE(s, i);
|
RSKIP_NONSPACE(s, i);
|
||||||
|
if (j == len-1 && i < 0 && PyString_CheckExact(self)) {
|
||||||
|
/* No whitespace in self, so just use it as list[0] */
|
||||||
|
Py_INCREF(self);
|
||||||
|
PyList_SET_ITEM(list, 0, (PyObject *)self);
|
||||||
|
count++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
SPLIT_ADD(s, i + 1, j + 1);
|
SPLIT_ADD(s, i + 1, j + 1);
|
||||||
}
|
}
|
||||||
if (i >= 0) {
|
if (i >= 0) {
|
||||||
|
@ -1299,8 +1319,9 @@ rsplit_whitespace(const char *s, Py_ssize_t len, Py_ssize_t maxsplit)
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_LOCAL_INLINE(PyObject *)
|
Py_LOCAL_INLINE(PyObject *)
|
||||||
rsplit_char(const char *s, Py_ssize_t len, char ch, Py_ssize_t maxcount)
|
rsplit_char(PyStringObject *self, Py_ssize_t len, char ch, Py_ssize_t maxcount)
|
||||||
{
|
{
|
||||||
|
const char *s = PyString_AS_STRING(self);
|
||||||
register Py_ssize_t i, j, count=0;
|
register Py_ssize_t i, j, count=0;
|
||||||
PyObject *str;
|
PyObject *str;
|
||||||
PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
|
PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
|
||||||
|
@ -1318,7 +1339,13 @@ rsplit_char(const char *s, Py_ssize_t len, char ch, Py_ssize_t maxcount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (j >= -1) {
|
if (i < 0 && count == 0 && PyString_CheckExact(self)) {
|
||||||
|
/* ch not in self, so just use self as list[0] */
|
||||||
|
Py_INCREF(self);
|
||||||
|
PyList_SET_ITEM(list, 0, (PyObject *)self);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
else if (j >= -1) {
|
||||||
SPLIT_ADD(s, 0, j + 1);
|
SPLIT_ADD(s, 0, j + 1);
|
||||||
}
|
}
|
||||||
FIX_PREALLOC_SIZE(list);
|
FIX_PREALLOC_SIZE(list);
|
||||||
|
@ -1346,7 +1373,7 @@ string_rsplit(PyStringObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
Py_ssize_t len = PyString_GET_SIZE(self), n, i, j;
|
Py_ssize_t len = PyString_GET_SIZE(self), n, i, j;
|
||||||
Py_ssize_t maxsplit = -1, count=0;
|
Py_ssize_t maxsplit = -1, count=0;
|
||||||
const char *s = PyString_AS_STRING(self), *sub;
|
const char *s, *sub;
|
||||||
Py_buffer vsub;
|
Py_buffer vsub;
|
||||||
PyObject *list, *str, *subobj = Py_None;
|
PyObject *list, *str, *subobj = Py_None;
|
||||||
|
|
||||||
|
@ -1355,7 +1382,7 @@ string_rsplit(PyStringObject *self, PyObject *args)
|
||||||
if (maxsplit < 0)
|
if (maxsplit < 0)
|
||||||
maxsplit = PY_SSIZE_T_MAX;
|
maxsplit = PY_SSIZE_T_MAX;
|
||||||
if (subobj == Py_None)
|
if (subobj == Py_None)
|
||||||
return rsplit_whitespace(s, len, maxsplit);
|
return rsplit_whitespace(self, len, maxsplit);
|
||||||
if (_getbuffer(subobj, &vsub) < 0)
|
if (_getbuffer(subobj, &vsub) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
sub = vsub.buf;
|
sub = vsub.buf;
|
||||||
|
@ -1366,11 +1393,8 @@ string_rsplit(PyStringObject *self, PyObject *args)
|
||||||
PyObject_ReleaseBuffer(subobj, &vsub);
|
PyObject_ReleaseBuffer(subobj, &vsub);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
else if (n == 1) {
|
else if (n == 1)
|
||||||
char ch = sub[0];
|
return rsplit_char(self, len, sub[0], maxsplit);
|
||||||
PyObject_ReleaseBuffer(subobj, &vsub);
|
|
||||||
return rsplit_char(s, len, ch, maxsplit);
|
|
||||||
}
|
|
||||||
|
|
||||||
list = PyList_New(PREALLOC_SIZE(maxsplit));
|
list = PyList_New(PREALLOC_SIZE(maxsplit));
|
||||||
if (list == NULL) {
|
if (list == NULL) {
|
||||||
|
@ -1381,6 +1405,7 @@ string_rsplit(PyStringObject *self, PyObject *args)
|
||||||
j = len;
|
j = len;
|
||||||
i = j - n;
|
i = j - n;
|
||||||
|
|
||||||
|
s = PyString_AS_STRING(self);
|
||||||
while ( (i >= 0) && (maxsplit-- > 0) ) {
|
while ( (i >= 0) && (maxsplit-- > 0) ) {
|
||||||
for (; i>=0; i--) {
|
for (; i>=0; i--) {
|
||||||
if (Py_STRING_MATCH(s, i, sub, n)) {
|
if (Py_STRING_MATCH(s, i, sub, n)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue