diff -Nru poster-20050907/ChangeLog poster-0.8.1/ChangeLog --- poster-20050907/ChangeLog 2005-09-08 00:58:54.000000000 +0000 +++ poster-0.8.1/ChangeLog 1970-01-01 00:00:00.000000000 +0000 @@ -1,13 +0,0 @@ -2005-09-07 Cristian Tibirna - * option: don't crash when specifying -s option (scaling) -2002-08-26 Michael Goffioul - * gets: avoid the use of gets, replaced by fgets - * input: allow input from STDIN - * pages: allow poster printing of more than one page - -2002-08-28 Michael Goffioul - * pages: allow selection of tile pages to print - -2002-08-30 Michael Goffioul - * option: added a "fake" option to pre-calculate the - tile pages (used within KDEPrint). diff -Nru poster-20050907/COPYING poster-0.8.1/COPYING --- poster-20050907/COPYING 2002-09-17 08:42:32.000000000 +0000 +++ poster-0.8.1/COPYING 1970-01-01 00:00:00.000000000 +0000 @@ -1,341 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 675 Mass Ave, Cambridge, MA 02139, USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) 19yy - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) 19yy name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. diff -Nru poster-20050907/debian/changelog poster-0.8.1/debian/changelog --- poster-20050907/debian/changelog 2011-05-20 00:24:25.000000000 +0000 +++ poster-0.8.1/debian/changelog 2011-05-20 00:24:25.000000000 +0000 @@ -1,100 +1,17 @@ -poster (1:20050907-1) unstable; urgency=low +poster (0.8.1-0ubuntu4) natty; urgency=low - [ Daniel Hermann ] - * New upstream version introducing command line options necessary for - kdeprint (Closes: #379378, #379422, #464096) - * reapplying patches that previously fixed #255718, #323535 - * not applying patch that previously fixed #339038, since it no - longer fixes the problem. Instead introducing "/setpagedevice { - pop } def" (line 968), taken from diff between 19990428 and 20050907). - * could not check #361088, test file no longer available - * multi-page poster printing may be broken to allow for non-DSC-compliant - single-page poster printing (e.g. containing "%%Page:" comments from - embedded EPS images). + * For Natty - -- Peter S Galbraith Thu, 27 Mar 2008 08:57:17 -0400 + -- Martin Owens (DoctorMO) Thu, 19 May 2011 20:13:46 -0400 -poster (1:19990428-8) unstable; urgency=low +poster (0.8.1-0ubuntu2) maverick; urgency=low - * Bug fix: "poster: Lines starting with '%' stripped from output ", - thanks to Antal K for the report and the patch (Closes: #255718). - * Bug fix: "Output of poster is not the correct Postscript file", thanks - to Wojtek Zabolotny for the report and the patch (Closes: #339038). + * Fix cdbc dependancy. - -- Peter S Galbraith Wed, 17 May 2006 19:54:03 -0400 + -- Martin Owens (DoctorMO) Thu, 19 May 2011 13:10:17 -0400 -poster (1:19990428-7) unstable; urgency=low - - * Reverting back to original version since replacement has bugs and was - abandoned upstream. Introduced epoch in version number. - * Bug fix: "'man poster' typos: "multipier", "unpractical"; and - "uncarefully", thanks to A Costa (Closes: #323535). - - -- Peter S Galbraith Thu, 6 Apr 2006 21:34:18 -0400 - -poster (20020830-3) unstable; urgency=low - - * Bug fix: "poster: FTBFS: Build dependency on libpaperg-dev", changed to - libpaper-dev thanks to Kurt Roeckx (Closes: #346402). - * Bumped Standards-Version to 3.6.2 - - -- Peter S Galbraith Tue, 17 Jan 2006 20:42:47 -0500 - -poster (20020830-2) unstable; urgency=low - - * Applied band-aid patch for scale factor with the '-s' option - contributed by Dylan Thurston (closes: #186637) - * Use libpaper patch, which somehow didn't get applied in previous - upload (closes: #188349) - * Bumped Standards-Version to 3.5.9 (okay except for optimization). - - -- Peter S Galbraith Wed, 9 Apr 2003 13:01:36 -0400 - -poster (20020830-1) unstable; urgency=low - - * New upstream release with new upstream maintainer (closes: #158795). - * debian/control: better description (closes: #149914) - * Switch to debhelper (for easier handling of DEB_BUILD_OPTIONS) - * Upgraded Standards-Version to 3.5.7 (except for optimization). - - -- Peter S Galbraith Wed, 25 Sep 2002 14:36:35 -0400 - -poster (19990428-6) unstable; urgency=low - - * Upgraded Standards-Version to 3.2.1 (Added Build-Depends) - - -- Peter S Galbraith Wed, 21 Feb 2001 13:50:51 -0500 - -poster (19990428-5) unstable; urgency=low - - * New maintainer. - - -- Peter S Galbraith Sun, 21 May 2000 23:14:14 -0400 - -poster (19990428-4) unstable; urgency=low - - * debian/{rules,postinst,prerm}: Implement the /usr/doc transition. - * debian/rules: Use -isp with dpkg-gencontrol. - - -- Antti-Juhani Kaijanaho Fri, 8 Oct 1999 00:53:12 +0300 - -poster (19990428-3) unstable; urgency=low - - * Signed the changes and dsc. - - -- Antti-Juhani Kaijanaho Thu, 1 Jul 1999 15:39:05 +0300 - -poster (19990428-2) unstable; urgency=low - - * Upgraded Standards-Version to 3.0.0.0 with necessary - changes to debian/rules and debian/changelog - - -- Antti-Juhani Kaijanaho Thu, 1 Jul 1999 15:21:34 +0300 - -poster (19990428-1) unstable; urgency=low - - * Initial release. - - -- Antti-Juhani Kaijanaho Thu, 20 May 1999 17:28:45 +0300 +poster (0.8.1-0ubuntu1) maverick; urgency=low + * Poster provides http multi-form access. + -- Martin Owens (DoctorMO) Thu, 12 May 2011 15:28:01 -0400 diff -Nru poster-20050907/debian/compat poster-0.8.1/debian/compat --- poster-20050907/debian/compat 1970-01-01 00:00:00.000000000 +0000 +++ poster-0.8.1/debian/compat 2011-05-20 00:24:25.000000000 +0000 @@ -0,0 +1 @@ +5 diff -Nru poster-20050907/debian/control poster-0.8.1/debian/control --- poster-20050907/debian/control 2011-05-20 00:24:25.000000000 +0000 +++ poster-0.8.1/debian/control 2011-05-20 00:24:25.000000000 +0000 @@ -1,18 +1,21 @@ Source: poster -Maintainer: Peter S Galbraith -Section: text +Section: python Priority: optional -Build-Depends: debhelper (>> 4.0.0), libpaper-dev -Standards-Version: 3.7.3 +Maintainer: Martin Owens +Standards-Version: 3.9.0 +XS-Python-Version: all +Build-Depends: debhelper (>= 4.1.13), python, python-central, python-setuptools, python-support +Homepage: http://www.google.com/ -Package: poster -Architecture: any -Section: text -Priority: optional -Depends: ${shlibs:Depends} -Description: Create large posters out of PostScript pages - Poster takes a one-page PostScript file and scales it to a specified - size. It can tile the resulting image into multiple smaller pages - that can be pasted together to form the big poster. Poster prefers - EPS as its input although freer forms of PostScript are also - understood. +Package: python-poster +Architecture: all +XB-Python-Version: ${python:Versions} +Depends: ${python:Depends} +Provides: ${python:Provides} +Description: Streaming HTTP uploads and multipart/form-data encoding + . + The modules in the Python standard library don't provide a way to upload large + files via HTTP without having to load the entire file into memory first. + . + poster provides support for both streaming POST requests as well as + multipart/form-data encoding of string or file parameters. diff -Nru poster-20050907/debian/copyright poster-0.8.1/debian/copyright --- poster-20050907/debian/copyright 2011-05-20 00:24:25.000000000 +0000 +++ poster-0.8.1/debian/copyright 2011-05-20 00:24:25.000000000 +0000 @@ -1,27 +1,28 @@ -This package was debianized by Antti-Juhani Kaijanaho -on 1999-05-20 at the request from J.H.M Dassen (Ray). +This package was created by Martin Owens on +Thu, 19 May 2011 12:47:24 -0500. -The original source was fetched from - ftp://ftp.ics.ele.tue.nl/pub/users/jos/poster/poster.tar.gz -and the newer version (20050907) was downloaded from - ftp://ftp.kde.org/pub/kde/printing/poster-20050907.tar.bz2 +Copyright 2011, Chris AtLee -The program has the following copyright notice: +License: -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public -# License version 2 as published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU Library General Public License -# along with this library; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: +. + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. +. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + +The Debian packaging is (C) 2011, Martin Owens +is licensed under the GPL, see license online. -The file COPYING in the source distribution contains Version 2 of the -GNU General Public License. The same version of the license is -included in Debian systems as the file /usr/share/common-licenses/GPL . diff -Nru poster-20050907/debian/pycompat poster-0.8.1/debian/pycompat --- poster-20050907/debian/pycompat 1970-01-01 00:00:00.000000000 +0000 +++ poster-0.8.1/debian/pycompat 2011-05-20 00:24:25.000000000 +0000 @@ -0,0 +1 @@ +2 diff -Nru poster-20050907/debian/pyversions poster-0.8.1/debian/pyversions --- poster-20050907/debian/pyversions 1970-01-01 00:00:00.000000000 +0000 +++ poster-0.8.1/debian/pyversions 2011-05-20 00:24:25.000000000 +0000 @@ -0,0 +1 @@ +2.5- diff -Nru poster-20050907/debian/rules poster-0.8.1/debian/rules --- poster-20050907/debian/rules 2011-05-20 00:24:25.000000000 +0000 +++ poster-0.8.1/debian/rules 2011-05-20 00:24:25.000000000 +0000 @@ -1,62 +1,6 @@ #!/usr/bin/make -f -# Sample debian/rules that uses debhelper. -# GNU copyright 1997 to 1999 by Joey Hess. -# Uncomment this to turn on verbose mode. -#export DH_VERBOSE=1 +%: + dh $@ -# This is the debhelper compatibility version to use. -export DH_COMPAT=4 -ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS))) - CFLAGS += -g -endif -ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS))) - STRIP += -s -endif - -build: build-stamp - -build-stamp: - dh_testdir - $(MAKE) - touch build-stamp - -clean: - dh_testdir - dh_testroot - rm -f build-stamp - -$(MAKE) clean - dh_clean - -install: build - dh_testdir - dh_testroot - dh_clean -k - dh_installdirs - install -d debian/poster/usr/bin - install $(STRIP) poster debian/poster/usr/bin - -# Build architecture-independent files here. -binary-indep: build install -# We have nothing to do by default. - -# Build architecture-dependent files here. -binary-arch: build install - dh_testdir - dh_testroot - dh_installdocs README - dh_installman poster.1 - dh_installchangelogs - dh_link - dh_strip - dh_compress - dh_fixperms - dh_installdeb - dh_shlibdeps - dh_gencontrol - dh_md5sums - dh_builddeb - -binary: binary-indep binary-arch -.PHONY: build clean binary-indep binary-arch binary install diff -Nru poster-20050907/getopt.c poster-0.8.1/getopt.c --- poster-20050907/getopt.c 1995-09-20 09:41:40.000000000 +0000 +++ poster-0.8.1/getopt.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,110 +0,0 @@ -/* transcript/src/getopt.c - * - * public domain getopt from mod.sources - * RCSID: $Header: getopt.c,v 2.1 85/11/24 11:49:10 shore Rel $ - */ - -/* -** This is a public domain version of getopt(3). -** Bugs, fixes to: -** Keith Bostic -** ARPA: keith@seismo -** UUCP: seismo!keith -** Added NO_STDIO, opterr handling, Rich $alz (mirror!rs). -*/ - -#include -#include - -/* -** Error macro. Maybe we want stdio, maybe we don't. -** The (undocumented?) variable opterr tells us whether or not -** to print errors. -*/ - -#ifdef NO_STDIO - -#define tell(s) \ - if (opterr) \ - { \ - char ebuf[2]; \ - (void)write(2, nargv, (unsigned int)strlen(nargv)); \ - (void)write(2, s, (unsigned int)strlen(s)); \ - ebuf[0] = optopt; \ - ebuf[1] = '\n'; \ - (void)write(2, ebuf, 2); \ - } - -#else - -#define tell(s) \ - if (opterr) \ - (void)fputs(*nargv, stderr), \ - (void)fputs(s,stderr), \ - (void)fputc(optopt, stderr), \ - (void)fputc('\n', stderr) - -#endif - - -/* Global variables. */ -static char EMSG[] = ""; -int opterr = 1; /* undocumented error-suppressor*/ -int optind = 1; /* index into argv vector */ -int optopt; /* char checked for validity */ -char *optarg; /* arg associated with option */ - - - -getopt(nargc, nargv, ostr) - int nargc; - char **nargv; - char *ostr; -{ - static char *place = EMSG; /* option letter processing */ - register char *oli; /* option letter list index */ - - if (!*place) /* update scanning pointer */ - { - if (optind >= nargc || *(place = nargv[optind]) != '-' || !*++place) - return(EOF); - if (*place == '-') /* found "--" */ - { - optind++; - return(EOF); - } - } - /* option letter okay? */ - if ((optopt = *place++) == ':' || (oli = strchr(ostr, optopt)) == NULL) - { - if (!*place) - optind++; - tell(": illegal option -- "); - goto Bad; - } - if (*++oli != ':') /* don't need argument */ - { - optarg = NULL; - if (!*place) - optind++; - } - else /* need an argument */ - { - if (*place) - optarg = place; /* no white space */ - else - if (nargc <= ++optind) - { - place = EMSG; - tell(": option requires an argument -- "); - goto Bad; - } - else - optarg = nargv[optind]; /* white space */ - place = EMSG; - optind++; - } - return(optopt); /* dump back option letter */ -Bad: - return('?'); -} diff -Nru poster-20050907/Makefile poster-0.8.1/Makefile --- poster-20050907/Makefile 2011-05-20 00:24:25.000000000 +0000 +++ poster-0.8.1/Makefile 1970-01-01 00:00:00.000000000 +0000 @@ -1,30 +0,0 @@ -# on Debian: -DEFINES = -DHAVE_LIBPAPER -CFLAGS = -O2 -g -Wall -LIBS = -lm -lpaper -# elsewhere -#DEFINES = # nothing -#CFLAGS = -g -Wall -#LIBS = -lm - -poster: poster.c - gcc $(CFLAGS) -o poster $(DEFINES) poster.c $(LIBS) - -# HPUX: cc -O -Aa -D_POSIX_SOURCE -o poster poster.c -lm -# Note that this program might trigger a stupid bug in the HPUX C library, -# causing the sscanf() call to produce a core dump. -# For proper operation, DON'T give the `+ESlit' option to the HP cc, -# or use gcc WITH the `-fwritable-strings' option. - -install: poster - strip poster - cp poster /usr/local/bin - cp poster.1 /usr/local/man/man1 - -clean: - rm -f poster core poster.o getopt.o - -tar: - tar -cvf poster.tar README Makefile poster.c poster.1 manual.ps - rm -f poster.tar.gz - gzip poster.tar diff -Nru poster-20050907/MANIFEST.in poster-0.8.1/MANIFEST.in --- poster-20050907/MANIFEST.in 1970-01-01 00:00:00.000000000 +0000 +++ poster-0.8.1/MANIFEST.in 2011-04-16 13:36:56.000000000 +0000 @@ -0,0 +1,2 @@ +include tests/*.py +exclude setup.cfg diff -Nru poster-20050907/manual.ps poster-0.8.1/manual.ps --- poster-20050907/manual.ps 1995-08-24 10:22:26.000000000 +0000 +++ poster-0.8.1/manual.ps 1970-01-01 00:00:00.000000000 +0000 @@ -1,528 +0,0 @@ -%!PS-Adobe-3.0 -%%Creator: groff version 1.09 -%%CreationDate: Thu Aug 24 12:22:26 1995 -%%DocumentNeededResources: font Times-Roman -%%+ font Times-Bold -%%+ font Times-Italic -%%DocumentFonts: Times-Roman -%%+ Times-Bold -%%+ Times-Italic -%%DocumentSuppliedResources: procset grops 1.09 0 -%%Pages: 4 -%%PageOrder: Ascend -%%Orientation: Portrait -%%EndComments -%%BeginProlog -%%BeginResource: procset grops 1.09 0 -/setpacking where{ -pop -currentpacking -true setpacking -}if -/grops 120 dict dup begin -/SC 32 def -/A/show load def -/B{0 SC 3 -1 roll widthshow}bind def -/C{0 exch ashow}bind def -/D{0 exch 0 SC 5 2 roll awidthshow}bind def -/E{0 rmoveto show}bind def -/F{0 rmoveto 0 SC 3 -1 roll widthshow}bind def -/G{0 rmoveto 0 exch ashow}bind def -/H{0 rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def -/I{0 exch rmoveto show}bind def -/J{0 exch rmoveto 0 SC 3 -1 roll widthshow}bind def -/K{0 exch rmoveto 0 exch ashow}bind def -/L{0 exch rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def -/M{rmoveto show}bind def -/N{rmoveto 0 SC 3 -1 roll widthshow}bind def -/O{rmoveto 0 exch ashow}bind def -/P{rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def -/Q{moveto show}bind def -/R{moveto 0 SC 3 -1 roll widthshow}bind def -/S{moveto 0 exch ashow}bind def -/T{moveto 0 exch 0 SC 5 2 roll awidthshow}bind def -/SF{ -findfont exch -[exch dup 0 exch 0 exch neg 0 0]makefont -dup setfont -[exch/setfont cvx]cvx bind def -}bind def -/MF{ -findfont -[5 2 roll -0 3 1 roll -neg 0 0]makefont -dup setfont -[exch/setfont cvx]cvx bind def -}bind def -/level0 0 def -/RES 0 def -/PL 0 def -/LS 0 def -/A5 0 def -/leftpage true def -/settumble true def -/PLG{ -gsave newpath clippath pathbbox grestore -exch pop add exch pop -}bind def -/BP{ -/level0 save def -1 setlinecap -1 setlinejoin -72 RES div dup scale -LS{ -90 rotate -A5{ -2 sqrt 2 div dup scale -leftpage{ -clippath pathbbox pop exch pop add 2 div 0 translate 0 0 moveto -newpath -}if -}if -}{ -0 PL translate -}ifelse -1 -1 scale -}bind def -/EP{ -level0 restore -A5{ -leftpage{ -showpage -/leftpage false def -}{ -/leftpage true def -}ifelse -}{ -showpage -}ifelse -}bind def -/DA{ -newpath arcn stroke -}bind def -/SN{ -transform -.25 sub exch .25 sub exch -round .25 add exch round .25 add exch -itransform -}bind def -/DL{ -SN -moveto -SN -lineto stroke -}bind def -/DC{ -newpath 0 360 arc closepath -}bind def -/TM matrix def -/DE{ -TM currentmatrix pop -translate scale newpath 0 0 .5 0 360 arc closepath -TM setmatrix -}bind def -/RC/rcurveto load def -/RL/rlineto load def -/ST/stroke load def -/MT/moveto load def -/CL/closepath load def -/FL{ -currentgray exch setgray fill setgray -}bind def -/BL/fill load def -/LW/setlinewidth load def -/RE{ -findfont -dup maxlength 1 index/FontName known not{1 add}if dict begin -{ -1 index/FID ne{def}{pop pop}ifelse -}forall -/Encoding exch def -dup/FontName exch def -currentdict end definefont pop -}bind def -/DEFS 0 def -/EBEGIN{ -moveto -DEFS begin -}bind def -/EEND/end load def -/CNT 0 def -/level1 0 def -/PBEGIN{ -/level1 save def -translate -div 3 1 roll div exch scale -neg exch neg exch translate -0 setgray -0 setlinecap -1 setlinewidth -0 setlinejoin -10 setmiterlimit -[]0 setdash -/setstrokeadjust where{ -pop -false setstrokeadjust -}if -/setoverprint where{ -pop -false setoverprint -}if -newpath -/CNT countdictstack def -userdict begin -/showpage{}def -}bind def -/PEND{ -clear -countdictstack CNT sub{end}repeat -level1 restore -}bind def -end def -/setpacking where{ -pop -setpacking -}if -%%EndResource -%%IncludeResource: font Times-Roman -%%IncludeResource: font Times-Bold -%%IncludeResource: font Times-Italic -grops begin/DEFS 1 dict def DEFS begin/u{.001 mul}bind def end/RES 72 -def/PL 841.89 def/LS false def/A5 false def/katern false def/ENC0[ -/asciicircum/asciitilde/Scaron/Zcaron/scaron/zcaron/Ydieresis/trademark -/quotesingle/ellipsis/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef -/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef -/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/space/exclam -/quotedbl/numbersign/dollar/percent/ampersand/quoteright/parenleft -/parenright/asterisk/plus/comma/hyphen/period/slash/zero/one/two/three -/four/five/six/seven/eight/nine/colon/semicolon/less/equal/greater -/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R/S/T/U/V/W/X/Y/Z -/bracketleft/backslash/bracketright/circumflex/underscore/quoteleft/a/b -/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar -/braceright/tilde/.notdef/quotesinglbase/guillemotleft/guillemotright -/bullet/florin/fraction/perthousand/dagger/daggerdbl/endash/emdash/ff/fi -/fl/ffi/ffl/dotlessi/dotlessj/grave/hungarumlaut/dotaccent/breve/caron -/ring/ogonek/quotedblleft/quotedblright/oe/lslash/quotedblbase/OE/Lslash -/.notdef/exclamdown/cent/sterling/currency/yen/brokenbar/section -/dieresis/copyright/ordfeminine/guilsinglleft/logicalnot/minus -/registered/macron/degree/plusminus/twosuperior/threesuperior/acute/mu -/paragraph/periodcentered/cedilla/onesuperior/ordmasculine -/guilsinglright/onequarter/onehalf/threequarters/questiondown/Agrave -/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla/Egrave/Eacute -/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex/Idieresis/Eth/Ntilde -/Ograve/Oacute/Ocircumflex/Otilde/Odieresis/multiply/Oslash/Ugrave -/Uacute/Ucircumflex/Udieresis/Yacute/Thorn/germandbls/agrave/aacute -/acircumflex/atilde/adieresis/aring/ae/ccedilla/egrave/eacute -/ecircumflex/edieresis/igrave/iacute/icircumflex/idieresis/eth/ntilde -/ograve/oacute/ocircumflex/otilde/odieresis/divide/oslash/ugrave/uacute -/ucircumflex/udieresis/yacute/thorn/ydieresis]def/Times-Italic@0 ENC0 -/Times-Italic RE/Times-Bold@0 ENC0/Times-Bold RE/Times-Roman@0 ENC0 -/Times-Roman RE -%%EndProlog -%%Page: 1 1 -%%BeginPageSetup -BP -%%EndPageSetup -/F0 10/Times-Roman@0 SF 367.72(POSTER\(1\) POSTER\(1\))72 48 R/F1 9 -/Times-Bold@0 SF -.18(NA)72 84 S(ME).18 E F0(poster \255 Scale and tile\ - a postscript image to print on multiple pages)108 96 Q F1(SYNOPSIS)72 -112.8 Q F0(poster in\214le)108 124.8 Q F1(DESCRIPTION)72 141.6 -Q/F2 10/Times-Italic@0 SF -.8(Po)108 153.6 S(ster).8 E F0 1.072 -(can be used to create a lar)3.572 F 1.072(ge poster by b)-.18 F 1.071 -(uilding it from multiple pages and/or printing it on lar)-.2 F(ge)-.18 -E 2.864(media. It)108 165.6 R -.15(ex)2.864 G .364(pects as input a gen\ -eric \(encapsulated\) postscript \214le, normally printing on a single \ -page.).15 F(The)5.365 E .596(output is ag)108 177.6 R .595 -(ain a postscript \214le, maybe containing multiple pages together b) --.05 F .595(uilding the poster)-.2 F 5.595(.T)-.55 G .595(he output) --5.595 F .348(pages bear cutmarks and ha)108 189.6 R .648 -.15(ve s)-.2 -H .348(lightly o).15 F -.15(ve)-.15 G .348 -(rlapping images for easier assembling.).15 F .348 -(The input picture will be)5.348 F(scaled to obtain the desired size.) -108 201.6 Q .069(The program uses a brute-force method: it copies the e\ -ntire input \214le for each output page, hence the output)108 218.4 R -1.352(\214le can be v)108 230.4 R 1.352(ery lar)-.15 F 3.852(ge. Since) --.18 F 1.352(the program does not really bother about the input \214le \ -contents, it clearly)3.852 F -.1(wo)108 242.4 S -(rks for both black-and-white and color postscript.).1 E 2.542 -.8(To c) -108 259.2 T .942(ontrol its operation, you need to specify either the s\ -ize of the desired poster or a scale f).8 F .941(actor for the)-.1 F -(image:)108 271.2 Q 6.67(-G)108 288 S -2.15 -.25(iv e)-6.67 H 2.826(nt) -.25 G .326(he poster size, it calculates the required number of sheets \ -to print on, and from that a scale f)-2.826 F(actor)-.1 E -(to \214ll these sheets optimally with the input image.)118 300 Q 6.67 -(-G)108 316.8 S -2.15 -.25(iv e)-6.67 H 2.75(nas).25 G .25(cale f)-2.75 -F(actor)-.1 E 2.75(,i)-.4 G 2.75(td)-2.75 G(eri)-2.75 E -.15(ve)-.25 G -2.75(st).15 G .249(he required number of pages from the input image siz\ -e, and positions the)-2.75 F(scaled image centered on this area.)118 -328.8 Q .848(Its input \214le should best be a real `Encapsulated Posts\ -cript' \214le \(often denoted with the e)108 345.6 R .849 -(xtension .eps or)-.15 F 3.722(.epsf\). Such)108 357.6 R 1.221 -(\214les can be generated from about all current dra)3.722 F 1.221 -(wing applications, and te)-.15 F 1.221(xt processors lik)-.15 F(e)-.1 E --.8(Wo)108 369.6 S(rd, Interleaf and Framemak).8 E(er)-.1 E(.)-.55 E(Ho) -108 381.6 Q(we)-.25 E -.15(ve)-.25 G(r).15 E F2(poster)3.344 E F0 .844 -(tries to beha)3.344 F 1.144 -.15(ve p)-.2 H .845 -(roperly also on more relax).15 F .845 -(ed, general postscript \214les containing a single)-.15 F -(page de\214nition.)108 393.6 Q(Proper operation is obtained for instan\ -ce on pages generated by \(La\)T)5 E(eX and \(g\)trof)-.7 E(f.)-.25 E -.021(The media to print on can be selected independently from the input\ - image size and/or the poster size.)108 410.4 R F2 -.8(Po)2.52 G(ster).8 -E F0(will determine by itself whether it is bene\214cial to rotate the \ -output image on the media.)108 422.4 Q 3.612 -.8(To p)108 439.2 T(re).8 -E(vie)-.25 E 4.512(wt)-.25 G 2.012(he output results of)-4.512 F F2 -(poster)4.512 E F0 2.013(and/or to \(re-\)print indi)4.512 F 2.013 -(vidual output pages, you should use a)-.25 F(postscript pre)108 451.2 Q -(vie)-.25 E(wer lik)-.25 E 2.5(eg)-.1 G(hostvie)-2.5 E(w\(1\).)-.25 E F1 -(OPTIONS)72 480 Q F0 4.17(-v Be)108 492 R -.15(ve)2.5 G(rbose. T).15 E -(ell about scaling, rotation and number of pages.)-.7 E(Def)123 504 Q -(ault is silent operation.)-.1 E 5.84(-f Ask)108 520.8 R -(manual media feed on the plotting/printing de)2.5 E -(vice, instead of using its standard paper tray)-.25 E(.)-.65 E(Def)123 -532.8 Q(ault is adhering to the de)-.1 E(vice settings.)-.25 E(-i ) -108 549.6 Q(Specify the size of the input image.)123 561.6 Q(Def)123 -573.6 Q(ault is reading the image size from the `%%BoundingBox' speci\ -\214cation in the input \214le header)-.1 E(.)-.55 E(-m )108 590.4 -Q(Specify the desired media size to print on. See belo)123 602.4 Q 2.5 -(wf)-.25 G(or .)-2.5 E(The def)123 614.4 Q -(ault is set at compile time, being A4 in the standard package.)-.1 E -(-p )108 631.2 Q 1.62(Specify the poster size. See belo)123 643.2 R -4.12(wf)-.25 G 1.62(or .)-4.12 F(Since)6.62 E F2(poster)4.12 E F0 -1.62(will autonomously choose for rotation,)4.12 F(al)123 655.2 Q -.1 -(wa)-.1 G -(ys specify a `portrait' poster size \(i.e. higher then wide\).).1 E -(If you don')123 667.2 Q 2.5(tg)-.18 G -2.15 -.25(iv e)-2.5 H -(the -s option, the def)2.75 E -(ault poster size is identical to the media size.)-.1 E(-s )108 -684 Q .845(Specify a linear scaling f)123 696 R .845 -(actor to produce the poster)-.1 F 5.845(.T)-.55 G .845 -(ogether with the input image size and optional)-6.645 F(mar)123 708 Q -(gins, this induces an output poster size. So don')-.18 E 2.5(ts)-.18 G -(pecify both -s and -p.)-2.5 E(Def)123 720 Q(ault is deri)-.1 E -(ving the scale f)-.25 E(actor to \214t a gi)-.1 E -.15(ve)-.25 G 2.5 -(np).15 G(oster size.)-2.5 E(1)535 768 Q EP -%%Page: 2 2 -%%BeginPageSetup -BP -%%EndPageSetup -/F0 10/Times-Roman@0 SF 367.72(POSTER\(1\) POSTER\(1\))72 48 R(-c ) -108 84 Q/F1 10/Times-Italic@0 SF(or)2.5 E F0(-c %)2.5 E .743 -(Specify the cut mar)123 96 R .742(gin. This is the distance between th\ -e cutmarks and the paper edge. If the output is)-.18 F .301(really tile\ -d on multiple sheets, the cut marks indicate where to cut the paper for\ - assembly)123 108 R 5.301(.T)-.65 G .301(his mar)-5.301 F(gin)-.18 E -1.03(must be big enough to co)123 120 R -.15(ve)-.15 G 3.53(rt).15 G -1.029(he non-printable mar)-3.53 F 1.029 -(gin which almost all printers ha)-.18 F -.15(ve)-.2 G 3.529(.F).15 G -1.029(or see)-3.679 F(belo)123 132 Q -.65(w.)-.25 G(Def)123 144 Q -.257(ault is 5%. Only when you specify identical poster and media sizes\ -, the def)-.1 F .258(ault cut mar)-.1 F .258(gin becomes)-.18 F(0, ef) -123 156 Q(fecti)-.25 E -.15(ve)-.25 G(ly remo).15 E(ving the cutmarks.) --.15 E(-w )108 172.8 Q F1(or)2.5 E F0(-w %)2.5 E -(Specify a white mar)123 184.8 Q(gin around the output image.)-.18 E -.391 -(In the `ideal' situation \(when an input `eps' \214le speci\214es an e) -123 196.8 R .391(xact BoundingBox in its header\), the out-)-.15 F .36 -(put image will be scaled e)123 208.8 R .36 -(xactly to the edges of the resulting poster \(minus cut mar)-.15 F .36 -(gin\). If you desire a)-.18 F(certain mar)123 220.8 Q -(gin to remain around the picture after poster assembly)-.18 E 2.5(,y) --.65 G(ou can specify this with `-w'.)-2.5 E .862(\(This option is actu\ -ally redundant, since you can obtain the same result using -s or -i. Ho) -123 232.8 R(we)-.25 E -.15(ve)-.25 G 3.361(rs).15 G(ome)-3.361 E -(might \214nd this more con)123 244.8 Q -.15(ve)-.4 G(nient.\)).15 E -(Def)123 256.8 Q(ault is 0.)-.1 E(-o )108 273.6 Q -(Specify the name of the \214le to write the output into.)123 285.6 Q -.416(\(Only added for those poor people who cannot specify output redir\ -ection from their command line due)123 297.6 R(to a silly OS.\))123 -309.6 Q(Def)123 321.6 Q(ault is writing to standard output.)-.1 E .077 -(The mentioned abo)108 338.4 R .377 -.15(ve i)-.15 H 2.576(sas).15 -G .076(peci\214cation of horizontal and v)-2.576 F .076(ertical size.) --.15 F .076(Only in combination with the)5.076 F -(`-i' option, the program also understands the of)108 350.4 Q -(fset speci\214cation in the .)-.25 E(In general:)108 362.4 Q -( = [][])-.25 E -(with multipier and of)108 386.4 Q(fset being speci\214ed optionally) --.25 E(.)-.65 E( = *)120.5 398.4 Q( = +,)-.25 E -( = or )120.5 422.4 Q(Man)108 439.2 Q -2.696(yi)-.15 G .196(nternational media names are recognised by the pro\ -gram, in upper and lo)-2.696 F .197(wer case, and can be short-)-.25 F -(ened to their \214rst fe)108 451.2 Q 2.5(wc)-.25 G -(haracters, as long as unique.)-2.5 E -.15(Fo)5 G 2.5(ri).15 G -(nstance `)-2.5 E(A0', `Let'.)-.8 E(Distance names are lik)108 463.2 Q -2.5(e`)-.1 G(cm', `i', `ft'.)-2.5 E/F2 9/Times-Bold@0 SF(EXAMPLES)72 492 -Q F0(The follo)108 504 Q(wing command prints an A4 input \214le on 8 A3\ - pages, forming an A0 poster:)-.25 E -(poster -v -iA4 -mA3 -pA0 in\214le >out\214le)130.5 516 Q(The ne)108 540 -Q(xt command prints an eps input image on a poster of 3x3 Letter pages:) --.15 E(poster -v -mLet -p3x3Let)130.5 552 Q(image.eps > out\214le)5 E -.233(The ne)108 576 R .233(xt command enlar)-.15 F .232 -(ges an eps input image to print on a lar)-.18 F .232 -(ge-media A0 capable de)-.18 F .232(vice, maintaining 2)-.25 F(inch mar) -108 588 Q(gins:)-.18 E(poster -v -mA0 -w2x2i image.eps > out\214le)130.5 -600 Q(Enlar)108 624 Q 1.371(ge a postscript image e)-.18 F 1.372 -(xactly 4 times, print on the def)-.15 F 1.372(ault A4 media, and let) --.1 F F1(poster)3.872 E F0 1.372(determine the)3.872 F -(number of pages required:)108 636 Q -(poster -v -s4 image.eps > out\214le)130.5 648 Q(2)535 768 Q EP -%%Page: 3 3 -%%BeginPageSetup -BP -%%EndPageSetup -/F0 10/Times-Roman@0 SF 367.72(POSTER\(1\) POSTER\(1\))72 48 R .334 -(Scale a postscript image to a poster of about 1 square meter)108 84 R -2.833(,p)-.4 G .333(rinting on `Le)-2.833 F -.05(ga)-.15 G .333 -(l' media, maintaining a 10%).05 F(of `Le)108 96 Q -.05(ga)-.15 G -(l' size as white mar).05 E(gin around the poster)-.18 E(.)-.55 E -(poster -v -mLe)130.5 108 Q -.05(ga)-.15 G 2.5(l-).05 G -(p1x1m -w10% in\214le.ps >out\214le)-2.5 E/F1 9/Times-Bold@0 SF(PR)72 -136.8 Q(OBLEMS & Q)-.27 E(UESTIONS)-.09 E/F2 10/Times-Bold@0 SF 2.5(Ig) -87 148.8 S(et a blurry image and/or interfer)-2.5 E(ence patter)-.18 E -(ns)-.15 E F0 .562(If your input \214le contains -or consists of- pix) -108 160.8 R .562(el images \(as opposed to just v)-.15 F .563 -(ector data which is essentially)-.15 F .523 -(resolution independent\), you might ha)108 172.8 R .823 -.15(ve t)-.2 H -.523(his problem.).15 F .523(Such pix)5.523 F .522 -(el images are normally made to \214t well to)-.15 F .167 -(standard 300 \(or 600\) dpi de)108 184.8 R 2.667(vices. Scaling)-.25 F -.168(such a picture with an uncarefully chosen f)2.668 F(actor)-.1 E -2.668(,c)-.4 G .168(an easily lead)-2.668 F .348 -(to hazy edges and interference patterns on the output.)108 196.8 R .348 -(The solution is to pro)5.348 F(vide)-.15 E/F3 10/Times-Italic@0 SF -(poster)2.848 E F0 .347(with an e)2.847 F .347(xact scal-)-.15 F 1.681 -(ing f)108 208.8 R 1.682 -(actor \(with the -s option\), chosen as an inte)-.1 F(ger)-.15 E 4.182 -(.I)-.55 G 4.182(fi)-4.182 G(nte)-4.182 E 1.682 -(ger scaling is unpractical for your purpose,)-.15 F -(choose a fractional number made from a small inte)108 220.8 Q -(ger denominator \(2, 3, 4\).)-.15 E F2 -(Can I select only a small part of a gi)87 237.6 Q -.1(ve)-.1 G 2.5(ni) -.1 G(nput pictur)-2.5 E(e?)-.18 E F0 -1(Ye)108 249.6 S .375(s, for this\ - purpose you can de\214ne both the size \(width and height\) and of)1 F -.374(fset \(from left and bottom\) of a)-.25 F(windo)108 261.6 Q 2.5(wo) --.25 G 2.5(nt)-2.5 G(he input image.)-2.5 E(Specify these numbers as ar) -5 E(gument to a `-i' command line option.)-.18 E .425(One w)108 273.6 R -.425(ay to obtain such numbers is pre)-.1 F(vie)-.25 E .426 -(wing the original image with ghostvie)-.25 F 1.726 -.65(w, a)-.25 H -.426(nd observing the coor).65 F(-)-.2 E 1.316 -(dinate numbers which it continually displays.)108 285.6 R 1.316 -(These numbers are in postscript units \(points\), named by)6.316 F F3 -(poster)108 297.6 Q F0(as just `p'.)2.5 E F2 -.2(Po)87 314.4 S -(ster doesn't seem to w).2 E(ork pr)-.1 E(operly)-.18 E 2.5(,o)-.55 G -(utput pages ar)-2.5 E 2.5(ee)-.18 G(mpty)-2.5 E F0 .287 -(The major cause for poster not to w)108 326.4 R .288(ork correctly)-.1 -F 2.788(,i)-.65 G 2.788(sg)-2.788 G -.25(iv)-2.788 G .288 -(ing it postscript \214les which don').25 F 2.788(tc)-.18 G .288 -(onform to proper)-2.788 F 2.756('eps' beha)108 338.4 R(viour)-.2 E -7.756(.T)-.55 G 2.756(ry whether your application \(or printer dri) --8.106 F -.15(ve)-.25 G 2.756(r\) cannot generate real 'encapsulated).15 -F(postscript'.)108 350.4 Q F2(If I ask f)87 367.2 Q(or a 50x50cm poster) --.25 E 2.5(,i)-.92 G 2.5(ta)-2.5 G(lways generates something bigger)-2.5 -E F0 -1(Ye)108 379.2 S .631(s, probably)1 F 3.131(.W)-.65 G .632 -(hen specifying a desired output size with the `-p' option,)-3.131 F F3 -(poster)3.132 E F0 .632(\214rst determines an array)3.132 F .958 -(of sheets to co)108 391.2 R -.15(ve)-.15 G 3.458(rs).15 G .958 -(uch an area.)-3.458 F .958(Then it determines a scale f)5.958 F .958 -(actor for the picture to \214ll these sheets upto)-.1 F 1.223 -(their edge. As result your requested size is used as rough guess only) -108 403.2 R 6.224(.I)-.65 G 3.724(fy)-6.224 G 1.224(ou w)-3.724 F 1.224 -(ant an e)-.1 F 1.224(xact output size,)-.15 F(specify the scaling f)108 -415.2 Q(actor yourself with the `-s' option \(and omit the `-p'\).)-.1 E -F2 2.5(Iw)87 432 S(ant to k)-2.5 E(eep the white space ar)-.1 E -(ound the poster as in my original)-.18 E F3 -.8(Po)108 444 S(ster).8 E -F0 .133(will as def)2.633 F .133(ault use the input image bounding box,\ - and scale/translate that to the edges of your poster)-.1 F(.)-.55 E -1.554(If the program which generated your input \214le speci\214es an e) -108 456 R 1.554(xact and tight %%BoundingBox, you will)-.15 F 1.023 -(indeed loose your white mar)108 468 R 3.523(gin. T)-.18 F 3.523(ok)-.8 -G 1.023(eep the original mar)-3.623 F 1.023 -(gin, specify a `-i' option with as ar)-.18 F 1.022(gument the)-.18 F -.661(papersize on which the original document w)108 480 R .661 -(as formatted \(such as `-iA4'\).)-.1 F(Alternati)5.662 E -.15(ve)-.25 G -.662(ly specify a smaller).15 F(scale f)108 492 Q -(actor \(with -s\) or an e)-.1 E(xplicit ne)-.15 E 2.5(wm)-.25 G(ar)-2.5 -E(gin \(with -w\).)-.18 E F1(POSTER ASSEMBL)72 520.8 Q(Y)-.828 E F0(Our\ - preferred method for the assembly of a poster from multiple sheets is \ -as follo)108 532.8 Q(ws:)-.25 E 6.67(-A)108 549.6 S -(rrange the sheets in the proper order on a lar)-6.67 E -(ge table or on the \215oor)-.18 E(.)-.55 E 6.67(-R)108 566.4 S(emo) --6.67 E 1.039 -.15(ve f)-.15 H .739(rom all sheets, e).15 F .738 -(xcept from those in the leftmost column or bottom ro)-.15 F 2.038 -.65 -(w, t)-.25 H .738(heir left and bottom).65 F(cutmar)118 578.4 Q(gin.) --.18 E 6.67(-I)108 595.2 S 2.682(nl)-6.67 G .182 -(eft-to-right and bottom-to-top order)-2.682 F 2.682(,g)-.4 G .182 -(lue the right \(and top\) cutmar)-2.682 F .183 -(gin and stick the right \(and upper\))-.18 F -(neighbouring page on top of that.)118 607.2 Q 6.67(-T)108 624 S .31 -(urn the glued-together poster f)-7.12 F .31(ace bottom, and put adhesi) --.1 F .609 -.15(ve t)-.25 H .309 -(ape on the sheet edges \(on the backside of).15 F -(the poster\) for more strength.)118 636 Q 6.67(-R)108 652.8 S(emo)-6.67 -E .3 -.15(ve t)-.15 H(he remaining cutmar).15 E(gin around the poster) --.18 E(.)-.55 E F1(DEVICE SETTINGS)72 681.6 Q F0 -.15(Fo)108 693.6 S -3.388(rp).15 G .888(ostscript le)-3.388 F -.15(ve)-.25 G .888 -(l-2 capable printers/plotters, which is about all modern postscript de) -.15 F .889(vices today)-.25 F(,)-.65 E F3(poster)3.389 E F0 -(will send de)108 705.6 Q(vice settings in its output \214le.)-.25 E -(This consists of a `setpagede)5 E(vice' call, setting:)-.25 E(3)535 768 -Q EP -%%Page: 4 4 -%%BeginPageSetup -BP -%%EndPageSetup -/F0 10/Times-Roman@0 SF 367.72(POSTER\(1\) POSTER\(1\))72 48 R 6.67(-t) -108 84 S(he media size.)-6.67 E(This is required for all printers I kno) -118 96 Q 2.5(wt)-.25 G 2.5(og)-2.5 G(et correct beha)-2.5 E -(viour on dif)-.2 E(ferent media/picture sizes.)-.25 E 6.67(-d)108 112.8 -S(uple)-6.67 E(xing of)-.15 E(f.)-.25 E .39 -(Some printers will otherwise perform double-side printing by def)118 -124.8 R 2.89(ault. Clearly)-.1 F .39(that is not what you w)2.89 F(ant) --.1 E(to print a poster)118 136.8 Q(.)-.55 E 6.67(-m)108 153.6 S -(anual media feed.)-6.67 E .295(This is gi)118 165.6 R -.15(ve)-.25 G -2.795(no).15 G .295(nly when)-2.795 F/F1 10/Times-Italic@0 SF(poster) -2.796 E F0 .296(is gi)2.796 F -.15(ve)-.25 G 2.796(nt).15 G .296(he `-f) --2.796 F 2.796('c).55 G .296(ommand line option. This is a con)-2.796 F --.15(ve)-.4 G .296(nient feature if you).15 F -.1(wa)118 177.6 S .679 -(nt to print your job on dif).1 F .679 -(ferent media than normally installed in the paper tray)-.25 F 3.179(,a) --.65 G .678(nd you are submit-)-3.179 F -(ting your job through a multi-user netw)118 189.6 Q -(orking and spooling en)-.1 E(vironment.)-.4 E 1.084 -(These settings cause proper de)108 206.4 R 1.084(vice beha)-.25 F -(viour)-.2 E 3.584(,w)-.4 G 1.084 -(ithout the need to manually interact with the printer set-)-3.584 F -(tings, and has been here locally tested to w)108 218.4 Q(ork on de)-.1 -E(vices lik)-.25 E 2.5(et)-.1 G(he HP300XL and HP650C.)-2.5 E -(The settings thus passed in the postscript \214le, will af)108 235.2 Q -(fect the de)-.25 E(vice for this job only)-.25 E(.)-.65 E/F2 9 -/Times-Bold@0 SF(DSC CONFORMANCE)72 264 Q F1 -.8(Po)108 276 S(ster).8 E -F0 .673(will generate its o)3.173 F .672(wn DSC header and other DSC li\ -nes in the output \214le, according the `Document)-.25 F .115 -(Structuring Con)108 288 R -.15(ve)-.4 G .115(ntions - v).15 F .116 -(ersion 3.0', as written do)-.15 F .116 -(wn in the `Postscript Language Reference Manual, 2nd)-.25 F(ed.)108 300 -Q 2.5('f)-.7 G(rom Adobe Systems Inc, Addison W)-2.5 E(esle)-.8 E 2.5 -(yP)-.15 G(ubl comp., 1990.)-2.5 E 1.137(It will cop)108 316.8 R 3.637 -(ya)-.1 G 1.437 -.15(ny `)-3.637 H(%%Document...).15 E 3.637('l)-.7 G -1.137(ine from the input \214le DSC header to its o)-3.637 F 1.136 -(wn header output. This is)-.25 F -(used here in particular for required nonresident fonts.)108 328.8 Q(Ho) -108 345.6 Q(we)-.25 E -.15(ve)-.25 G 2.896(rt).15 G .396(he cop)-2.896 F -.396(y\(s\) of the input \214le included in the output, are stripped fr\ -om all lines starting with a `%',)-.1 F(since the)108 357.6 Q 2.5(yt) --.15 G(end to disturb our `ghostvie)-2.5 E(w' pre)-.25 E(vie)-.25 E -(wer and tak)-.25 E 2.5(eu)-.1 G(seless space an)-2.5 E(yho)-.15 E -.65 -(w.)-.25 G F2(SEE ALSO)72 386.4 Q F0(ghostvie)108 398.4 Q(w\(1\))-.25 E -F2(CONTRIB)72 427.2 Q(UTED BY)-.09 E F0(Jos v)108 439.2 Q(an Eijndho) --.25 E -.15(ve)-.15 G 2.5(n\().15 G(email: J.T)-2.5 E(.J.v)-.74 E -(.Eijndho)-.65 E -.15(ve)-.15 G(n@ele.tue.nl\)).15 E -(Design Automation Section \(http://www)108 451.2 Q(.es.ele.tue.nl\)) --.65 E(Dept. of Elec. Eng.)108 463.2 Q(Eindho)108 475.2 Q -.15(ve)-.15 G -2.5(nU).15 G(ni)-2.5 E 2.5(vo)-.25 G 2.5(fT)-2.5 G(echnology)-3.2 E -(The Netherlands)108 487.2 Q(24 August, 1995)108 499.2 Q(4)535 768 Q EP -%%Trailer -end -%%EOF diff -Nru poster-20050907/PKG-INFO poster-0.8.1/PKG-INFO --- poster-20050907/PKG-INFO 1970-01-01 00:00:00.000000000 +0000 +++ poster-0.8.1/PKG-INFO 2011-04-16 13:40:23.000000000 +0000 @@ -0,0 +1,22 @@ +Metadata-Version: 1.0 +Name: poster +Version: 0.8.1 +Summary: Streaming HTTP uploads and multipart/form-data encoding +Home-page: http://atlee.ca/software/poster +Author: Chris AtLee +Author-email: chris@atlee.ca +License: MIT +Download-URL: http://atlee.ca/software/poster/dist/0.8.1 +Description: The modules in the Python standard library don't provide a way to upload large + files via HTTP without having to load the entire file into memory first. + + poster provides support for both streaming POST requests as well as + multipart/form-data encoding of string or file parameters +Keywords: python http post multipart/form-data file upload +Platform: UNKNOWN +Classifier: Intended Audience :: Developers +Classifier: License :: OSI Approved :: MIT License +Classifier: Natural Language :: English +Classifier: Programming Language :: Python +Classifier: Topic :: Internet :: WWW/HTTP +Classifier: Topic :: Software Development :: Libraries :: Python Modules diff -Nru poster-20050907/poster/encode.py poster-0.8.1/poster/encode.py --- poster-20050907/poster/encode.py 1970-01-01 00:00:00.000000000 +0000 +++ poster-0.8.1/poster/encode.py 2010-12-03 05:25:52.000000000 +0000 @@ -0,0 +1,414 @@ +"""multipart/form-data encoding module + +This module provides functions that faciliate encoding name/value pairs +as multipart/form-data suitable for a HTTP POST or PUT request. + +multipart/form-data is the standard way to upload files over HTTP""" + +__all__ = ['gen_boundary', 'encode_and_quote', 'MultipartParam', + 'encode_string', 'encode_file_header', 'get_body_size', 'get_headers', + 'multipart_encode'] + +try: + import uuid + def gen_boundary(): + """Returns a random string to use as the boundary for a message""" + return uuid.uuid4().hex +except ImportError: + import random, sha + def gen_boundary(): + """Returns a random string to use as the boundary for a message""" + bits = random.getrandbits(160) + return sha.new(str(bits)).hexdigest() + +import urllib, re, os, mimetypes +try: + from email.header import Header +except ImportError: + # Python 2.4 + from email.Header import Header + +def encode_and_quote(data): + """If ``data`` is unicode, return urllib.quote_plus(data.encode("utf-8")) + otherwise return urllib.quote_plus(data)""" + if data is None: + return None + + if isinstance(data, unicode): + data = data.encode("utf-8") + return urllib.quote_plus(data) + +def _strify(s): + """If s is a unicode string, encode it to UTF-8 and return the results, + otherwise return str(s), or None if s is None""" + if s is None: + return None + if isinstance(s, unicode): + return s.encode("utf-8") + return str(s) + +class MultipartParam(object): + """Represents a single parameter in a multipart/form-data request + + ``name`` is the name of this parameter. + + If ``value`` is set, it must be a string or unicode object to use as the + data for this parameter. + + If ``filename`` is set, it is what to say that this parameter's filename + is. Note that this does not have to be the actual filename any local file. + + If ``filetype`` is set, it is used as the Content-Type for this parameter. + If unset it defaults to "text/plain; charset=utf8" + + If ``filesize`` is set, it specifies the length of the file ``fileobj`` + + If ``fileobj`` is set, it must be a file-like object that supports + .read(). + + Both ``value`` and ``fileobj`` must not be set, doing so will + raise a ValueError assertion. + + If ``fileobj`` is set, and ``filesize`` is not specified, then + the file's size will be determined first by stat'ing ``fileobj``'s + file descriptor, and if that fails, by seeking to the end of the file, + recording the current position as the size, and then by seeking back to the + beginning of the file. + + ``cb`` is a callable which will be called from iter_encode with (self, + current, total), representing the current parameter, current amount + transferred, and the total size. + """ + def __init__(self, name, value=None, filename=None, filetype=None, + filesize=None, fileobj=None, cb=None): + self.name = Header(name).encode() + self.value = _strify(value) + if filename is None: + self.filename = None + else: + if isinstance(filename, unicode): + # Encode with XML entities + self.filename = filename.encode("ascii", "xmlcharrefreplace") + else: + self.filename = str(filename) + self.filename = self.filename.encode("string_escape").\ + replace('"', '\\"') + self.filetype = _strify(filetype) + + self.filesize = filesize + self.fileobj = fileobj + self.cb = cb + + if self.value is not None and self.fileobj is not None: + raise ValueError("Only one of value or fileobj may be specified") + + if fileobj is not None and filesize is None: + # Try and determine the file size + try: + self.filesize = os.fstat(fileobj.fileno()).st_size + except (OSError, AttributeError): + try: + fileobj.seek(0, 2) + self.filesize = fileobj.tell() + fileobj.seek(0) + except: + raise ValueError("Could not determine filesize") + + def __cmp__(self, other): + attrs = ['name', 'value', 'filename', 'filetype', 'filesize', 'fileobj'] + myattrs = [getattr(self, a) for a in attrs] + oattrs = [getattr(other, a) for a in attrs] + return cmp(myattrs, oattrs) + + def reset(self): + if self.fileobj is not None: + self.fileobj.seek(0) + elif self.value is None: + raise ValueError("Don't know how to reset this parameter") + + @classmethod + def from_file(cls, paramname, filename): + """Returns a new MultipartParam object constructed from the local + file at ``filename``. + + ``filesize`` is determined by os.path.getsize(``filename``) + + ``filetype`` is determined by mimetypes.guess_type(``filename``)[0] + + ``filename`` is set to os.path.basename(``filename``) + """ + + return cls(paramname, filename=os.path.basename(filename), + filetype=mimetypes.guess_type(filename)[0], + filesize=os.path.getsize(filename), + fileobj=open(filename, "rb")) + + @classmethod + def from_params(cls, params): + """Returns a list of MultipartParam objects from a sequence of + name, value pairs, MultipartParam instances, + or from a mapping of names to values + + The values may be strings or file objects, or MultipartParam objects. + MultipartParam object names must match the given names in the + name,value pairs or mapping, if applicable.""" + if hasattr(params, 'items'): + params = params.items() + + retval = [] + for item in params: + if isinstance(item, cls): + retval.append(item) + continue + name, value = item + if isinstance(value, cls): + assert value.name == name + retval.append(value) + continue + if hasattr(value, 'read'): + # Looks like a file object + filename = getattr(value, 'name', None) + if filename is not None: + filetype = mimetypes.guess_type(filename)[0] + else: + filetype = None + + retval.append(cls(name=name, filename=filename, + filetype=filetype, fileobj=value)) + else: + retval.append(cls(name, value)) + return retval + + def encode_hdr(self, boundary): + """Returns the header of the encoding of this parameter""" + boundary = encode_and_quote(boundary) + + headers = ["--%s" % boundary] + + if self.filename: + disposition = 'form-data; name="%s"; filename="%s"' % (self.name, + self.filename) + else: + disposition = 'form-data; name="%s"' % self.name + + headers.append("Content-Disposition: %s" % disposition) + + if self.filetype: + filetype = self.filetype + else: + filetype = "text/plain; charset=utf-8" + + headers.append("Content-Type: %s" % filetype) + + headers.append("") + headers.append("") + + return "\r\n".join(headers) + + def encode(self, boundary): + """Returns the string encoding of this parameter""" + if self.value is None: + value = self.fileobj.read() + else: + value = self.value + + if re.search("^--%s$" % re.escape(boundary), value, re.M): + raise ValueError("boundary found in encoded string") + + return "%s%s\r\n" % (self.encode_hdr(boundary), value) + + def iter_encode(self, boundary, blocksize=4096): + """Yields the encoding of this parameter + If self.fileobj is set, then blocks of ``blocksize`` bytes are read and + yielded.""" + total = self.get_size(boundary) + current = 0 + if self.value is not None: + block = self.encode(boundary) + current += len(block) + yield block + if self.cb: + self.cb(self, current, total) + else: + block = self.encode_hdr(boundary) + current += len(block) + yield block + if self.cb: + self.cb(self, current, total) + last_block = "" + encoded_boundary = "--%s" % encode_and_quote(boundary) + boundary_exp = re.compile("^%s$" % re.escape(encoded_boundary), + re.M) + while True: + block = self.fileobj.read(blocksize) + if not block: + current += 2 + yield "\r\n" + if self.cb: + self.cb(self, current, total) + break + last_block += block + if boundary_exp.search(last_block): + raise ValueError("boundary found in file data") + last_block = last_block[-len(encoded_boundary)-2:] + current += len(block) + yield block + if self.cb: + self.cb(self, current, total) + + def get_size(self, boundary): + """Returns the size in bytes that this param will be when encoded + with the given boundary.""" + if self.filesize is not None: + valuesize = self.filesize + else: + valuesize = len(self.value) + + return len(self.encode_hdr(boundary)) + 2 + valuesize + +def encode_string(boundary, name, value): + """Returns ``name`` and ``value`` encoded as a multipart/form-data + variable. ``boundary`` is the boundary string used throughout + a single request to separate variables.""" + + return MultipartParam(name, value).encode(boundary) + +def encode_file_header(boundary, paramname, filesize, filename=None, + filetype=None): + """Returns the leading data for a multipart/form-data field that contains + file data. + + ``boundary`` is the boundary string used throughout a single request to + separate variables. + + ``paramname`` is the name of the variable in this request. + + ``filesize`` is the size of the file data. + + ``filename`` if specified is the filename to give to this field. This + field is only useful to the server for determining the original filename. + + ``filetype`` if specified is the MIME type of this file. + + The actual file data should be sent after this header has been sent. + """ + + return MultipartParam(paramname, filesize=filesize, filename=filename, + filetype=filetype).encode_hdr(boundary) + +def get_body_size(params, boundary): + """Returns the number of bytes that the multipart/form-data encoding + of ``params`` will be.""" + size = sum(p.get_size(boundary) for p in MultipartParam.from_params(params)) + return size + len(boundary) + 6 + +def get_headers(params, boundary): + """Returns a dictionary with Content-Type and Content-Length headers + for the multipart/form-data encoding of ``params``.""" + headers = {} + boundary = urllib.quote_plus(boundary) + headers['Content-Type'] = "multipart/form-data; boundary=%s" % boundary + headers['Content-Length'] = str(get_body_size(params, boundary)) + return headers + +class multipart_yielder: + def __init__(self, params, boundary, cb): + self.params = params + self.boundary = boundary + self.cb = cb + + self.i = 0 + self.p = None + self.param_iter = None + self.current = 0 + self.total = get_body_size(params, boundary) + + def __iter__(self): + return self + + def next(self): + """generator function to yield multipart/form-data representation + of parameters""" + if self.param_iter is not None: + try: + block = self.param_iter.next() + self.current += len(block) + if self.cb: + self.cb(self.p, self.current, self.total) + return block + except StopIteration: + self.p = None + self.param_iter = None + + if self.i is None: + raise StopIteration + elif self.i >= len(self.params): + self.param_iter = None + self.p = None + self.i = None + block = "--%s--\r\n" % self.boundary + self.current += len(block) + if self.cb: + self.cb(self.p, self.current, self.total) + return block + + self.p = self.params[self.i] + self.param_iter = self.p.iter_encode(self.boundary) + self.i += 1 + return self.next() + + def reset(self): + self.i = 0 + self.current = 0 + for param in self.params: + param.reset() + +def multipart_encode(params, boundary=None, cb=None): + """Encode ``params`` as multipart/form-data. + + ``params`` should be a sequence of (name, value) pairs or MultipartParam + objects, or a mapping of names to values. + Values are either strings parameter values, or file-like objects to use as + the parameter value. The file-like objects must support .read() and either + .fileno() or both .seek() and .tell(). + + If ``boundary`` is set, then it as used as the MIME boundary. Otherwise + a randomly generated boundary will be used. In either case, if the + boundary string appears in the parameter values a ValueError will be + raised. + + If ``cb`` is set, it should be a callback which will get called as blocks + of data are encoded. It will be called with (param, current, total), + indicating the current parameter being encoded, the current amount encoded, + and the total amount to encode. + + Returns a tuple of `datagen`, `headers`, where `datagen` is a + generator that will yield blocks of data that make up the encoded + parameters, and `headers` is a dictionary with the assoicated + Content-Type and Content-Length headers. + + Examples: + + >>> datagen, headers = multipart_encode( [("key", "value1"), ("key", "value2")] ) + >>> s = "".join(datagen) + >>> assert "value2" in s and "value1" in s + + >>> p = MultipartParam("key", "value2") + >>> datagen, headers = multipart_encode( [("key", "value1"), p] ) + >>> s = "".join(datagen) + >>> assert "value2" in s and "value1" in s + + >>> datagen, headers = multipart_encode( {"key": "value1"} ) + >>> s = "".join(datagen) + >>> assert "value2" not in s and "value1" in s + + """ + if boundary is None: + boundary = gen_boundary() + else: + boundary = urllib.quote_plus(boundary) + + headers = get_headers(params, boundary) + params = MultipartParam.from_params(params) + + return multipart_yielder(params, boundary, cb), headers diff -Nru poster-20050907/poster/__init__.py poster-0.8.1/poster/__init__.py --- poster-20050907/poster/__init__.py 1970-01-01 00:00:00.000000000 +0000 +++ poster-0.8.1/poster/__init__.py 2011-02-13 19:12:47.000000000 +0000 @@ -0,0 +1,32 @@ +# Copyright (c) 2011 Chris AtLee +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +"""poster module + +Support for streaming HTTP uploads, and multipart/form-data encoding + +```poster.version``` is a 3-tuple of integers representing the version number. +New releases of poster will always have a version number that compares greater +than an older version of poster. +New in version 0.6.""" + +import poster.streaminghttp +import poster.encode + +version = (0, 8, 1) # Thanks JP! diff -Nru poster-20050907/poster/streaminghttp.py poster-0.8.1/poster/streaminghttp.py --- poster-20050907/poster/streaminghttp.py 1970-01-01 00:00:00.000000000 +0000 +++ poster-0.8.1/poster/streaminghttp.py 2011-04-16 13:24:30.000000000 +0000 @@ -0,0 +1,199 @@ +"""Streaming HTTP uploads module. + +This module extends the standard httplib and urllib2 objects so that +iterable objects can be used in the body of HTTP requests. + +In most cases all one should have to do is call :func:`register_openers()` +to register the new streaming http handlers which will take priority over +the default handlers, and then you can use iterable objects in the body +of HTTP requests. + +**N.B.** You must specify a Content-Length header if using an iterable object +since there is no way to determine in advance the total size that will be +yielded, and there is no way to reset an interator. + +Example usage: + +>>> from StringIO import StringIO +>>> import urllib2, poster.streaminghttp + +>>> opener = poster.streaminghttp.register_openers() + +>>> s = "Test file data" +>>> f = StringIO(s) + +>>> req = urllib2.Request("http://localhost:5000", f, +... {'Content-Length': str(len(s))}) +""" + +import httplib, urllib2, socket +from httplib import NotConnected + +__all__ = ['StreamingHTTPConnection', 'StreamingHTTPRedirectHandler', + 'StreamingHTTPHandler', 'register_openers'] + +if hasattr(httplib, 'HTTPS'): + __all__.extend(['StreamingHTTPSHandler', 'StreamingHTTPSConnection']) + +class _StreamingHTTPMixin: + """Mixin class for HTTP and HTTPS connections that implements a streaming + send method.""" + def send(self, value): + """Send ``value`` to the server. + + ``value`` can be a string object, a file-like object that supports + a .read() method, or an iterable object that supports a .next() + method. + """ + # Based on python 2.6's httplib.HTTPConnection.send() + if self.sock is None: + if self.auto_open: + self.connect() + else: + raise NotConnected() + + # send the data to the server. if we get a broken pipe, then close + # the socket. we want to reconnect when somebody tries to send again. + # + # NOTE: we DO propagate the error, though, because we cannot simply + # ignore the error... the caller will know if they can retry. + if self.debuglevel > 0: + print "send:", repr(value) + try: + blocksize = 8192 + if hasattr(value, 'read') : + if hasattr(value, 'seek'): + value.seek(0) + if self.debuglevel > 0: + print "sendIng a read()able" + data = value.read(blocksize) + while data: + self.sock.sendall(data) + data = value.read(blocksize) + elif hasattr(value, 'next'): + if hasattr(value, 'reset'): + value.reset() + if self.debuglevel > 0: + print "sendIng an iterable" + for data in value: + self.sock.sendall(data) + else: + self.sock.sendall(value) + except socket.error, v: + if v[0] == 32: # Broken pipe + self.close() + raise + +class StreamingHTTPConnection(_StreamingHTTPMixin, httplib.HTTPConnection): + """Subclass of `httplib.HTTPConnection` that overrides the `send()` method + to support iterable body objects""" + +class StreamingHTTPRedirectHandler(urllib2.HTTPRedirectHandler): + """Subclass of `urllib2.HTTPRedirectHandler` that overrides the + `redirect_request` method to properly handle redirected POST requests + + This class is required because python 2.5's HTTPRedirectHandler does + not remove the Content-Type or Content-Length headers when requesting + the new resource, but the body of the original request is not preserved. + """ + + handler_order = urllib2.HTTPRedirectHandler.handler_order - 1 + + # From python2.6 urllib2's HTTPRedirectHandler + def redirect_request(self, req, fp, code, msg, headers, newurl): + """Return a Request or None in response to a redirect. + + This is called by the http_error_30x methods when a + redirection response is received. If a redirection should + take place, return a new Request to allow http_error_30x to + perform the redirect. Otherwise, raise HTTPError if no-one + else should try to handle this url. Return None if you can't + but another Handler might. + """ + m = req.get_method() + if (code in (301, 302, 303, 307) and m in ("GET", "HEAD") + or code in (301, 302, 303) and m == "POST"): + # Strictly (according to RFC 2616), 301 or 302 in response + # to a POST MUST NOT cause a redirection without confirmation + # from the user (of urllib2, in this case). In practice, + # essentially all clients do redirect in this case, so we + # do the same. + # be conciliant with URIs containing a space + newurl = newurl.replace(' ', '%20') + newheaders = dict((k, v) for k, v in req.headers.items() + if k.lower() not in ( + "content-length", "content-type") + ) + return urllib2.Request(newurl, + headers=newheaders, + origin_req_host=req.get_origin_req_host(), + unverifiable=True) + else: + raise urllib2.HTTPError(req.get_full_url(), code, msg, headers, fp) + +class StreamingHTTPHandler(urllib2.HTTPHandler): + """Subclass of `urllib2.HTTPHandler` that uses + StreamingHTTPConnection as its http connection class.""" + + handler_order = urllib2.HTTPHandler.handler_order - 1 + + def http_open(self, req): + """Open a StreamingHTTPConnection for the given request""" + return self.do_open(StreamingHTTPConnection, req) + + def http_request(self, req): + """Handle a HTTP request. Make sure that Content-Length is specified + if we're using an interable value""" + # Make sure that if we're using an iterable object as the request + # body, that we've also specified Content-Length + if req.has_data(): + data = req.get_data() + if hasattr(data, 'read') or hasattr(data, 'next'): + if not req.has_header('Content-length'): + raise ValueError( + "No Content-Length specified for iterable body") + return urllib2.HTTPHandler.do_request_(self, req) + +if hasattr(httplib, 'HTTPS'): + class StreamingHTTPSConnection(_StreamingHTTPMixin, + httplib.HTTPSConnection): + """Subclass of `httplib.HTTSConnection` that overrides the `send()` + method to support iterable body objects""" + + class StreamingHTTPSHandler(urllib2.HTTPSHandler): + """Subclass of `urllib2.HTTPSHandler` that uses + StreamingHTTPSConnection as its http connection class.""" + + handler_order = urllib2.HTTPSHandler.handler_order - 1 + + def https_open(self, req): + return self.do_open(StreamingHTTPSConnection, req) + + def https_request(self, req): + # Make sure that if we're using an iterable object as the request + # body, that we've also specified Content-Length + if req.has_data(): + data = req.get_data() + if hasattr(data, 'read') or hasattr(data, 'next'): + if not req.has_header('Content-length'): + raise ValueError( + "No Content-Length specified for iterable body") + return urllib2.HTTPSHandler.do_request_(self, req) + + +def get_handlers(): + handlers = [StreamingHTTPHandler, StreamingHTTPRedirectHandler] + if hasattr(httplib, "HTTPS"): + handlers.append(StreamingHTTPSHandler) + return handlers + +def register_openers(): + """Register the streaming http handlers in the global urllib2 default + opener object. + + Returns the created OpenerDirector object.""" + opener = urllib2.build_opener(*get_handlers()) + + urllib2.install_opener(opener) + + return opener diff -Nru poster-20050907/poster.1 poster-0.8.1/poster.1 --- poster-20050907/poster.1 2011-05-20 00:24:25.000000000 +0000 +++ poster-0.8.1/poster.1 1970-01-01 00:00:00.000000000 +0000 @@ -1,328 +0,0 @@ -.TH POSTER 1 -.fi -.SH NAME -poster \- Scale and tile a postscript image to print on multiple pages -.SH SYNOPSIS -.in +7n -.ti -7n -poster infile -.in -7n -.SH DESCRIPTION -\fIPoster\fP can be used to create a large poster by building it -from multiple pages and/or printing it on large media. -It expects as input a generic (encapsulated) postscript -file, normally printing on a single page. -The output is again a postscript file, maybe containing multiple pages -together building the poster. -The output pages bear cutmarks and have slightly overlapping images -for easier assembling. -The input picture will be scaled to obtain the desired size. -.P -The program uses a brute-force method: it copies the entire input -file for each output page, hence the output file can be very large. -Since the program does not really bother about the input file contents, -it clearly works for both black-and-white and color postscript. -.P -To control its operation, you need to specify either the size -of the desired poster or a scale factor for the image: -.TP 2n -- -Given the poster size, it calculates the required number of sheets -to print on, and from that a scale factor to fill these sheets optimally with the -input image. -.TP -- -Given a scale factor, it derives the required number of pages from the input -image size, and positions the scaled image centered on this area. -.P -Its input file should best be a real `Encapsulated Postscript' file -(often denoted with the extension .eps or .epsf). -Such files can be generated from about all current drawing applications, -and text processors like Word, Interleaf and Framemaker. -.br -However \fIposter\fP tries to behave properly also on more relaxed, -general postscript files containing a single page definition. -Proper operation is obtained for instance on pages generated -by (La)TeX and (g)troff. -.P -The media to print on can be selected independently from the input image size -and/or the poster size. \fIPoster\fP will determine by itself whether it -is beneficial to rotate the output image on the media. -.P -To preview the output results of \fIposter\fP and/or to (re-)print individual -output pages, you should use a postscript previewer like ghostview(1). - -.ne 5 -.SH OPTIONS -.TP 3n --v -Be verbose. Tell about scaling, rotation and number of pages. -.br -Default is silent operation. -.TP --f -Ask manual media feed on the plotting/printing device, -instead of using its standard paper tray. -.br -Default is adhering to the device settings. -.TP --i -Specify the size of the input image. -.br -Default is reading the image size from the `%%BoundingBox' specification -in the input file header. -.TP --m -Specify the desired media size to print on. See below for . -.br -The default is obtained from the PAPERCONF environment variable. If -it is not set, it is read from the file whose name is in the PAPERSIZE -environment variable. If that too is not set, the default is read -from the file /etc/papersize. See -.BR papersize (5) -for a full description of the format of the config file. -.TP --p -Specify the poster size. See below for . -Since \fIposter\fP will autonomously choose for rotation, -always specify a `portrait' poster size (i.e. higher then wide). -.br -If you don't give the -s option, the default poster size is identical to the -media size. -.TP --s -Specify a linear scaling factor to produce the poster. -Together with the input image size and optional margins, this induces -an output poster size. So don't specify both -s and -p. -.br -Default is deriving the scale factor to fit a given poster size. -.TP --c \fIor\fP -c % -.br -Specify the cut margin. This is the distance between the cutmarks and -the paper edge. If the output is really tiled on multiple sheets, -the cut marks indicate where to cut the paper for assembly. -This margin must be big enough to cover the non-printable margin which almost -all printers have. For see below. -.br -Default is 5%. Only when you specify identical poster and media sizes, -the default cut margin becomes 0, effectively removing the cutmarks. -.TP --w \fIor\fP -w % -.br -Specify a white margin around the output image. -.br -In the `ideal' situation (when an input `eps' file specifies an exact -BoundingBox in its header), the output image will be scaled exactly to -the edges of the resulting poster (minus cut margin). If you desire -a certain margin to remain around the picture after poster assembly, -you can specify this with `-w'. -.br -(This option is actually redundant, since you can obtain the same result -using -s or -i. However some might find this more convenient.) -.br -Default is 0. -.TP --P -.br -Specify which pages of the poster to print. It consists of a comma-separated -list of single pages or page ranges (using the dash). The order in which -page number appears determines the final page order in the result PostScript -file. Page numbering starts at 1, from left to right and bottom-up. -.br -Examples: 1-2 or 1,3-4,7 -.TP --o -Specify the name of the file to write the output into. -.br -(Only added for those poor people who cannot specify output redirection -from their command line due to a silly OS.) -.br -Default is writing to standard output. -.P -The mentioned above is a specification of horizontal and vertical size. -Only in combination with the `-i' option, the program also understands the -offset specification in the . -.br -In general: - = [][] -.br -with multiplier and offset being specified optionally. - = * -.br - = +, -.br - = or -.P -Many international media names are recognised by the program, in upper and lower case, -and can be shortened to their first few characters, as long as unique. -For instance `A0', `Let'. -.br -Distance names are like `cm', `i', `ft'. - -.ne 5 -.SH EXAMPLES -The following command prints an A4 input file on 8 A3 pages, forming an A0 -poster: - poster -v -iA4 -mA3 -pA0 infile >outfile - -.ne 3 -The next command prints an eps input image on a poster of 3x3 Letter pages: - poster -v -mLet -p3x3Let image.eps > outfile - -.ne 3 -The next command enlarges an eps input image to print on a -large-media A0 capable device, maintaining 2 inch margins: - poster -v -mA0 -w2x2i image.eps > outfile - -.ne 3 -Enlarge a postscript image exactly 4 times, print on the default A4 media, -and let \fIposter\fP determine the number of pages required: - poster -v -s4 image.eps > outfile - -.ne 6 -Scale a postscript image to a poster of about 1 square meter, printing -on `Legal' media, maintaining a 10% of `Legal' size as white margin -around the poster. - poster -v -mLegal -p1x1m -w10% infile.ps >outfile - -.ne 5 -.SH "PROBLEMS & QUESTIONS" -.SS "I get a blurry image and/or interference patterns" -If your input file contains -or consists of- pixel images (as opposed -to just vector data which is essentially resolution independent), -you might have this problem. -Such pixel images are normally made to fit well to standard 300 (or 600) dpi devices. -Scaling such a picture with an carelessly chosen factor, -can easily lead to hazy edges and interference patterns on the output. -The solution is to provide \fIposter\fP with an exact scaling factor -(with the -s option), chosen as an integer. If integer scaling is -impractical for your purpose, -choose a fractional number made from a small integer denominator (2, 3, 4). -.SS "Can I select only a small part of a given input picture?" -Yes, for this purpose you can define both the size (width and height) -and offset (from left and bottom) of a window on the input image. -Specify these numbers as argument to a `-i' command line option. -.br -One way to obtain such numbers is previewing the original image with -ghostview, -and observing the coordinate numbers which it continually displays. -These numbers are in postscript units (points), -named by \fIposter\fP as just `p'. -.SS "Poster doesn't seem to work properly, output pages are empty" -The major cause for poster not to work correctly, is giving it -postscript files which don't conform to proper 'eps' behaviour. -Try whether your application (or printer driver) cannot generate -real 'encapsulated postscript'. -.SS "If I ask for a 50x50cm poster, it always generates something bigger" -Yes, probably. When specifying a desired output size with the `-p' option, -\fIposter\fP first determines an array of sheets to cover such an area. -Then it determines a scale factor for the picture to fill these sheets upto -their edge. As result your requested size is used as rough guess only. -If you want an exact output size, specify the scaling factor yourself -with the `-s' option (and omit the `-p'). -.SS "I want to keep the white space around the poster as in my original" -\fIPoster\fP will as default use the input image bounding box, and -scale/translate that to the edges of your poster. -If the program which generated your input file specifies an exact and tight -%%BoundingBox, you will indeed loose your white margin. -To keep the original margin, specify a `-i' option with as argument the papersize -on which the original document was formatted (such as `-iA4'). -Alternatively specify a smaller scale factor (with -s) or an explicit new -margin (with -w). - -.ne 4 -.SH "POSTER ASSEMBLY" -Our preferred method for the assembly of a poster from multiple sheets -is as follows: -.TP 2n -- -Arrange the sheets in the proper order on a large table or on the floor. -.TP -- -Remove from all sheets, except from those in the leftmost column or -bottom row, their left and bottom cutmargin. -.TP -- -In left-to-right and bottom-to-top order, glue the right (and top) cutmargin -and stick the right (and upper) neighbouring page on top of that. -.TP -- -Turn the glued-together poster face bottom, and put adhesive tape on the sheet -edges (on the backside of the poster) for more strength. -.TP -- -Remove the remaining cutmargin around the poster. - -.ne 4 -.SH "DEVICE SETTINGS" -For postscript level-2 capable printers/plotters, which is about all modern postscript -devices today, \fIposter\fP will send device settings in its output file. -This consists of a `setpagedevice' call, setting: -.TP 2n -- -the media size. -.br -This is required for all printers I know to get correct -behaviour on different media/picture sizes. -.TP -- -duplexing off. -.br -Some printers will otherwise perform double-side printing by default. -Clearly that is not what you want to print a poster. -.TP -- -manual media feed. -.br -This is given only when \fIposter\fP was executed with the `-f' -command line option. This is a convenient feature if you want to print -your job on different media than normally installed in the paper tray, -and you are submitting your job through a multi-user networking and -spooling environment. -.P -These settings cause proper device behaviour, without the need to -manually interact with the printer settings, and has been here locally -tested to work on devices like the HP300XL and HP650C. -.P -The settings thus passed in the postscript file, will affect the device -for this job only. - -.SH "DSC CONFORMANCE" -\fIPoster\fP will generate its own DSC header and other DSC lines -in the output file, according the `Document Structuring Conventions - version -3.0', -as written down in the `Postscript Language Reference Manual, 2nd ed.' from -Adobe Systems Inc, Addison Wesley Publ comp., 1990. -.P -It will copy any `%%Document...' line from the input file DSC header to its -own header output. This is used here in particular for required nonresident -fonts. -.P -However the copy(s) of the input file included in the output, -are stripped from all lines starting with a `%%', since they tend to -disturb our `ghostview' previewer and take useless space anyhow. - -.SH "SEE ALSO" -.BR ghostview "(1), " papersize (5) - -.SH "CONTRIBUTED BY" -.nf -.na -Jos van Eijndhoven (email: J.T.J.v.Eijndhoven@ele.tue.nl) -Design Automation Section (http://www.es.ele.tue.nl) -Dept. of Elec. Eng. -Eindhoven Univ of Technology -The Netherlands -24 August, 1995 - - - - - - - - - - - diff -Nru poster-20050907/poster.c poster-0.8.1/poster.c --- poster-20050907/poster.c 2011-05-20 00:24:25.000000000 +0000 +++ poster-0.8.1/poster.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,1080 +0,0 @@ -/* -# poster.c - a generic PS scaling program -# This program scales a PostScript page to a given size (a poster). -# The output can be tiled on multiple sheets, and output -# media size can be chosen independently. -# Each tile (sheet) of a will bear cropmarks and slightly overlapping -# image for easier poster assembly. -# -# Compile this program with: -# cc -O -o poster poster.c -lm -# or something alike. -# -# Maybe you want to change the `DefaultMedia' and `DefaultImage' -# settings in the few lines below, to reflect your local situation. -# Names can to be chosen from the `mediatable' further down. -# -# The `Gv_gs_orientbug 1' disables a feature of this program to -# ask for landscape previewing of rotated images. -# Our currently installed combination of ghostview 1.5 with ghostscript 3.33 -# cannot properly do a landscape viewing of the `poster' output. -# The problem does not exist in combination with an older ghostscript 2.x, -# and has the attention of the ghostview authors. -# (The problem is in the evaluation of the `setpagedevice' call.) -# If you have a different previewing environment, -# you might want to set `Gv_gs_orientbug 0' -# -# Jos van Eijndhoven, Eindhoven University of Technology -# email: J.T.J.v.Eijndhoven@ele.tue.nl -# September 7, 1995 -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public -# License version 2 as published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU Library General Public License -# along with this library; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. -# -# Modification for Debian by Antti-Juhani Kaijanaho -# on 1999-05-20 -# -# Adaptation of version 20050907 by Daniel Hermann -# -*/ - -#define Gv_gs_orientbug 1 -#ifdef HAVE_LIBPAPER -# include -# define DefaultMedia (systempapername()) -#else /* HAVE_LIBPAPER */ -# define DefaultMedia "A4" -#endif /* HAVE_LIBPAPER */ -#define DefaultImage "A4" -#define DefaultCutMargin "5%" -#define DefaultWhiteMargin "0" -#define BUFSIZE 1024 - -#include -#include -#include -#include -#include -#include - - -extern char *optarg; /* silently set by getopt() */ -extern int optind, opterr; /* silently set by getopt() */ - -static void usage(); -static void dsc_head1(); -static int dsc_infile( double ps_bb[4]); -static void dsc_head2( void); -static void printposter( void); -static void printprolog(); -static void tile ( int row, int col, int pagetoprint); -static void printfile( int pagetoprint); -static void postersize( char *scalespec, char *posterspec); -static void box_convert( char *boxspec, double psbox[4]); -static void boxerr( char *spec); -static void margin_convert( char *spec, double margin[2]); -static int mystrncasecmp( const char *s1, const char *s2, int n); -static char* tmpinfile( void ); -static int parsepagespec( int **page_array, int *len, int *size, char *pagespec ); -static void do_fake_mode( void ); - -int verbose; -char *myname; -char *infile; -int rotate, nrows, ncols; -int manualfeed = 0; -int tail_cntl_D = 0; -#define Xl 0 -#define Yb 1 -#define Xr 2 -#define Yt 3 -#define X 0 -#define Y 1 -double posterbb[4]; /* final image in ps units */ -double imagebb[4]; /* original image in ps units */ -double mediasize[4]; /* [34] = size of media to print on, [01] not used! */ -double cutmargin[2]; -double whitemargin[2]; -double scale; /* linear scaling factor */ -int number_pages = 1; -int *pages = NULL; -int pages_size = 0; -int pages_length = 0; -int fake_mode = 0; - -/* defaults: */ -char *imagespec = NULL; -char *posterspec = NULL; -char *mediaspec = NULL; -char *cutmarginspec = NULL; -char *whitemarginspec = NULL; -char *scalespec = NULL; -char *filespec = NULL; -char *pagespec = NULL; - -/* media sizes in ps units (1/72 inch) */ -static char *mediatable[][2] = -{ { "Letter", "612,792"}, - { "Legal", "612,1008"}, - { "Tabloid", "792,1224"}, - { "Ledger", "792,1224"}, - { "Executive","540,720"}, - { "Monarch", "279,540"}, - { "Statement","396,612"}, - { "Folio", "612,936"}, - { "Quarto", "610,780"}, - { "C5", "459,649"}, - { "C5E", "459,649"}, - { "EnvC5", "459,649"}, - { "B0", "2916,4128"}, - { "B1", "2064,2916"}, - { "B2", "1458,2064"}, - { "B3", "1032,1458"}, - { "B4", "729,1032"}, - { "B5", "516,729"}, - { "B6", "365,516"}, - { "B7", "258,365"}, - { "B8", "183,258"}, - { "B9", "129,183"}, - { "B10", "92,129"}, - { "Dl", "312,624"}, - { "A0", "2380,3368"}, - { "A1", "1684,2380"}, - { "A2", "1190,1684"}, - { "A3", "842,1190"}, - { "A4", "595,842"}, - { "A5", "421,595"}, - { "A6", "297,421"}, - { "A7", "210,297"}, - { "A8", "148,210"}, - { "A9", "105,148"}, - { "Comm10", "298,684"}, - { "COM10", "298,684"}, - { "Env10", "298,684"}, - { "DL", "312,624"}, - { "DLE", "312,624"}, - { "EnvDL", "312,624"}, - - /* as fall-back: linear units of measurement: */ - { "p", "1,1"}, - { "i", "72,72"}, - { "ft", "864,864"}, - { "mm", "2.83465,2.83465"}, - { "cm", "28.3465,28.3465"}, - { "m", "2834.65,2834.65"}, - { NULL, NULL} -}; - - -int main( int argc, char *argv[]) -{ - int opt; - double ps_bb[4]; - int got_bb; - int need_remove = 0; - - myname = argv[0]; - - while ((opt = getopt( argc, argv, "vfi:c:w:m:p:s:o:P:F")) != EOF) - { switch( opt) - { case 'v': verbose++; break; - case 'f': manualfeed = 1; break; - case 'i': imagespec = optarg; break; - case 'c': cutmarginspec = optarg; break; - case 'w': whitemarginspec = optarg; break; - case 'm': mediaspec = optarg; break; - case 'p': posterspec = optarg; break; - case 's': scalespec = optarg; break; - case 'o': filespec = optarg; break; - case 'P': pagespec = optarg; break; - case 'F': fake_mode = 1; break; - default: usage(); break; - } - } - - /*** check command line arguments ***/ - if (scalespec && posterspec) - { fprintf( stderr, "Please don't specify both -s and -p, ignoring -s!\n"); - scalespec = NULL; - } - - if (optind < argc) - infile = argv[ optind]; - else if ( !fake_mode ) - { - infile = tmpinfile(); - need_remove = 1; - } - /* - { fprintf( stderr, "Filename argument missing!\n"); - usage(); - } - */ - - /*** decide on media size ***/ - if (!mediaspec) - { mediaspec = DefaultMedia; - if (verbose) - fprintf( stderr, - "Using default media of %s\n", - mediaspec); - } - box_convert( mediaspec, mediasize); - if (mediasize[3] < mediasize[2]) - { fprintf( stderr, "Media should always be specified in portrait format!\n"); - exit(1); - } - if (mediasize[2]-mediasize[0] <= 10.0 || mediasize[3]-mediasize[1] <= 10.0) - { fprintf( stderr, "Media size is ridiculous!\n"); - exit(1); - } - - /*** defaulting poster size ? **/ - if (!scalespec && !posterspec) - { /* inherit postersize from given media size */ - posterspec = mediaspec; - if (verbose) - fprintf( stderr, - "Defaulting poster size to media size of %s\n", - mediaspec); - } - - /*** decide the cutmargin size, after knowing media size ***/ - if (!cutmarginspec) - { if (posterspec && (!strcmp( posterspec, mediaspec))) - /* zero cutmargin if printing to 1 sheet */ - cutmarginspec = "0%"; - else - cutmarginspec = DefaultCutMargin; - if (verbose) - fprintf( stderr, - "Using default cutmargin of %s\n", - cutmarginspec); - } - margin_convert( cutmarginspec, cutmargin); - - /*** decide the whitemargin size, after knowing media size ***/ - if (!whitemarginspec) - { whitemarginspec = DefaultWhiteMargin; - if (verbose) - fprintf( stderr, - "Using default whitemargin of %s\n", - whitemarginspec); - } - margin_convert( whitemarginspec, whitemargin); - - /*** parse page specification ***/ - if ( pagespec && parsepagespec( &pages, &pages_length, &pages_size, pagespec ) == 0 ) - { - fprintf( stderr, "Wrong page set specification: %s\n", pagespec ); - exit( 1 ); - } - - if ( fake_mode ) - { - do_fake_mode(); - exit( 0 ); - } - - /******************* now start doing things **************************/ - /* open output file */ - if (filespec) - { if (!freopen( filespec, "w", stdout)) - { fprintf( stderr, "Cannot open '%s' for writing!\n", - filespec); - exit(1); - } else if (verbose) - fprintf( stderr, "Opened '%s' for writing\n", - filespec); - } - - /******* I might need to read some input to find picture size ********/ - /* start DSC header on output */ - dsc_head1(); - - /* pass input DSC lines to output, get BoundingBox spec if there */ - got_bb = dsc_infile( ps_bb); - - /**** decide the input image bounding box ****/ - if (!got_bb && !imagespec) - { imagespec = DefaultImage; - if (verbose) - fprintf( stderr, - "Using default input image of %s\n", - imagespec); - } - if (imagespec) - box_convert( imagespec, imagebb); - else - { int i; - for (i=0; i<4; i++) - imagebb[i] = ps_bb[i]; - } - - if (verbose > 1) - fprintf( stderr, " Input image is: [%g,%g,%g,%g]\n", - imagebb[0], imagebb[1], imagebb[2], imagebb[3]); - - if (imagebb[2]-imagebb[0] <= 0.0 || imagebb[3]-imagebb[1] <= 0.0) - { fprintf( stderr, "Input image should have positive size!\n"); - exit(1); - } - - - /*** decide on the scale factor and poster size ***/ - postersize( scalespec, posterspec); - - if (verbose > 1) - fprintf( stderr, " Output image is: [%g,%g,%g,%g]\n", - posterbb[0], posterbb[1], posterbb[2], posterbb[3]); - - - dsc_head2(); - - printposter(); - - if ( need_remove ) - remove( infile ); - - exit (0); -} - -static void addpages( int **page_array, int p1, int p2, int n, int *size ) -{ - int i; - - while ( p2-p1+1+n > *size ) - { - *size += 100; - *page_array = ( int* )realloc( *page_array, sizeof( int ) * ( *size ) ); - } - for ( i=n+p2-p1; i>=n; i-- ) - ( *page_array )[ i ] = i+p1-n; -} - -static void do_fake_mode( void ) -{ - if ( !imagespec ) - imagespec = posterspec; - box_convert( imagespec, imagebb ); - - postersize( scalespec, posterspec ); - - fprintf( stderr, "%d %d %d %g %g %g %g %g %g %g %g %g\n", nrows, ncols, rotate, mediasize[ 2 ], mediasize[ 3 ], - cutmargin[ 0 ], cutmargin[ 1 ], posterbb[ 0 ], posterbb[ 1 ], posterbb[ 2 ], posterbb[ 3 ], scale ); - - exit( 0 ); -} - -static int parsepagespec( int **page_array, int *len, int *size, char *pagespec ) -{ - char *c = pagespec, *r = NULL; - int p1, p2; - - if ( *page_array != NULL ) - return 1; - - *size = 100; - *len = 0; - *page_array = ( int* )malloc( sizeof( int ) * ( *size ) ); - - while ( *c != '\0' ) - { - p1 = p2 = 0; - p1 = ( int )strtol( c, &r, 10 ); - if ( *r == '\0' || *r == ',' ) - p2 = p1; - else if ( *r == '-' ) - { - c = r+1; - p2 = ( int )strtol( c, &r, 10 ); - if ( *r != '\0' && *r != ',' ) - goto error; - } - else - goto error; - if ( p1 > 0 && p2 > 0 && p2 >= p1 ) - { - addpages( page_array, p1, p2, *len, size ); - *len += ( p2-p1+1 ); - } - else - goto error; - if ( *r == '\0' ) - break; - c = r+1; - } - - return 1; - -error: - free( *page_array ); - *size = 0; - return 0; -} - -static char* tmpinfile() -{ - char filename[ 256 ] = {0}; - int fd = -1; - - if ( getenv( "TEMP" ) == NULL ) - strcat( filename, "/tmp" ); - else - strcat( filename, getenv( "TEMP" ) ); - strcat( filename, "/poster.XXXXXX" ); - - fd = mkstemp( filename ); - if ( fd == -1 ) - { - fprintf( stderr, "Cannot create temporary file.\n" ); - exit( 1 ); - } - else - { - char buffer[ 4096 ]; - int n; - - do - { - n = fread( buffer, sizeof( char ), 4096, stdin ); - if ( n > 0 ) - write( fd, buffer, n ); - } while ( n == 4096 ); - - close( fd ); - return strdup( filename ); - } -} - -static void usage() -{ - fprintf( stderr, "Usage: %s infile\n\n", myname); - fprintf( stderr, "options are:\n"); - fprintf( stderr, " -v: be verbose\n"); - fprintf( stderr, " -f: ask manual feed on plotting/printing device\n"); - fprintf( stderr, " -i: specify input image size\n"); - fprintf( stderr, " -c: horizontal and vertical cutmargin\n"); - fprintf( stderr, " -w: horizontal and vertical additional white margin\n"); - fprintf( stderr, " -m: media paper size\n"); - fprintf( stderr, " -p: output poster size\n"); - fprintf( stderr, " -s: linear scale factor for poster\n"); - fprintf( stderr, " -P: comma-separated list of tile pages to print\n" ); - fprintf( stderr, " -o: output redirection to named file\n\n"); - fprintf( stderr, " At least one of -s -p -m is mandatory, and don't give both -s and -p\n"); - fprintf( stderr, " is like 'A4', '3x3letter', '10x25cm', '200x200+10,10p'\n"); - fprintf( stderr, " is either a simple or %%. Page lists are comma-\n" ); - fprintf( stderr, " separated, each element being a single page or a page range.\n" ); - fprintf( stderr, " (ex: 1,2-5,8,10-34)\n\n"); - - fprintf( stderr, " Defaults are: '-m%s', '-c%s', '-i' read from input file.\n", - DefaultMedia, DefaultCutMargin); - fprintf( stderr, " and output written to stdout.\n"); - - exit(1); -} - -#define exch( x, y) {double h; h=x; x=y; y=h;} - -static void postersize( char *scalespec, char *posterspec) -{ /* exactly one the arguments is NULL ! */ - /* media and image sizes are fixed already */ - - int nx0, ny0, nx1, ny1; - double sizex, sizey; /* size of the scaled image in ps units */ - double drawablex, drawabley; /* effective drawable size of media */ - double mediax, mediay; - double tmpposter[4]; - - /* available drawing area per sheet: */ - drawablex = mediasize[2] - 2.0*cutmargin[0]; - drawabley = mediasize[3] - 2.0*cutmargin[1]; - - /*** decide on number of pages ***/ - if (scalespec) - { /* user specified scale factor */ - scale = atof( scalespec); - if (scale < 0.01 || scale > 1.0e6) - { fprintf( stderr, "Illegal scale value %s!\n", scalespec); - exit(1); - } - sizex = (imagebb[2] - imagebb[0]) * scale + 2*whitemargin[0]; - sizey = (imagebb[3] - imagebb[1]) * scale + 2*whitemargin[1]; - - /* without rotation */ - nx0 = ceil( sizex / drawablex); - ny0 = ceil( sizey / drawabley); - - /* with rotation */ - nx1 = ceil( sizex / drawabley); - ny1 = ceil( sizey / drawablex); - - } else - { /* user specified output size */ - box_convert( posterspec, tmpposter); - if (tmpposter[0]!=0.0 || tmpposter[1]!=0.0) - { fprintf( stderr, "Poster lower-left coordinates are assumed 0!\n"); - tmpposter[0] = tmpposter[1] = 0.0; - } - if (tmpposter[2]-tmpposter[0] <= 0.0 || tmpposter[3]-tmpposter[1] <= 0.0) - { fprintf( stderr, "Poster should have positive size!\n"); - exit(1); - } - - if ((tmpposter[3]-tmpposter[1]) < (tmpposter[2]-tmpposter[0])) - { /* hmmm... landscape spec, change to portrait for now */ - exch( tmpposter[0], tmpposter[1]); - exch( tmpposter[2], tmpposter[3]); - } - - - /* Should we tilt the poster to landscape style? */ - if ((imagebb[3] - imagebb[1]) < (imagebb[2] - imagebb[0])) - { /* image has landscape format ==> make landscape poster */ - exch( tmpposter[0], tmpposter[1]); - exch( tmpposter[2], tmpposter[3]); - } - - /* without rotation */ /* assuming tmpposter[0],[1] = 0,0 */ - nx0 = ceil( 0.95 * tmpposter[2] / mediasize[2]); - ny0 = ceil( 0.95 * tmpposter[3] / mediasize[3]); - - /* with rotation */ - nx1 = ceil( 0.95 * tmpposter[2] / mediasize[3]); - ny1 = ceil( 0.95 * tmpposter[3] / mediasize[2]); - /* (rotation is considered as media versus image, which is totally */ - /* independent of the portrait or landscape style of the final poster) */ - } - - /* decide for rotation to get the minimum page count */ - rotate = nx0*ny0 > nx1*ny1; - - ncols = rotate ? nx1 : nx0; - nrows = rotate ? ny1 : ny0; - - if (verbose) - fprintf( stderr, - "Deciding for %d column%s and %d row%s of %s pages.\n", - ncols, (ncols==1)?"":"s", nrows, (nrows==1)?"":"s", - rotate?"landscape":"portrait"); - - if (nrows * ncols > 400) - { fprintf( stderr, "However %dx%d pages seems ridiculous to me!\n", - ncols, nrows); - exit(1); - } - - mediax = ncols * (rotate ? drawabley : drawablex); - mediay = nrows * (rotate ? drawablex : drawabley); - - if (!scalespec) /* no scaling number given by user */ - { double scalex, scaley; - scalex = (mediax - 2*whitemargin[0]) / (imagebb[2] - imagebb[0]); - scaley = (mediay - 2*whitemargin[1]) / (imagebb[3] - imagebb[1]); - //scalex = (tmpposter[ 2 ]-tmpposter[ 0 ]) / (imagebb[2] - imagebb[0]); - //scaley = (tmpposter[ 3 ]-tmpposter[ 1 ]) / (imagebb[3] - imagebb[1]); - scale = (scalex < scaley) ? scalex : scaley; - - if (verbose) - fprintf( stderr, - "Deciding for a scale factor of %g\n", scale); - sizex = scale * (imagebb[2] - imagebb[0]); - sizey = scale * (imagebb[3] - imagebb[1]); - } - - /* set poster size as if it were a continuous surface without margins */ - posterbb[0] = (mediax - sizex) / 2.0; /* center picture on paper */ - posterbb[1] = (mediay - sizey) / 2.0; /* center picture on paper */ - posterbb[2] = posterbb[0] + sizex; - posterbb[3] = posterbb[1] + sizey; - -} - -static void margin_convert( char *spec, double margin[2]) -{ double x; - int i, n; - - if (1==sscanf( spec, "%lf%n", &x, &n) && x==0.0 && n==strlen(spec)) - { /* margin spec of 0, dont bother about a otherwise mandatory unit */ - margin[0] = margin[1] = 0.0; - } else if (spec[ strlen( spec) - 1] == '%') - { /* margin relative to media size */ - if (1 != sscanf( spec, "%lf%%", &x)) - { fprintf( stderr, "Illegal margin specification!\n"); - exit( 1); - } - margin[0] = 0.01 * x * mediasize[2]; - margin[1] = 0.01 * x * mediasize[3]; - } else - { /* absolute margin value */ - double marg[4]; - box_convert( spec, marg); - margin[0] = marg[2]; - margin[1] = marg[3]; - } - - for (i=0; i<2; i++) - { if (margin[i] < 0 || 2.0*margin[i] >= mediasize[i+2]) - { fprintf( stderr, "Margin value '%s' out of range!\n", - spec); - exit(1); - } - } -} - -static void box_convert( char *boxspec, double psbox[4]) -{ /* convert user textual box spec into numbers in ps units */ - /* box = [fixed x fixed][+ fixed , fixed] unit */ - /* fixed = digits [ . digits] */ - /* unit = medianame | i | cm | mm | m | p */ - - double mx, my, ox, oy, ux, uy; - int n, r, i, l, inx; - char *spec; - - mx = my = 1.0; - ox = oy = 0.0; - - spec = boxspec; - /* read 'fixed x fixed' */ - if (isdigit( spec[0])) - { r = sscanf( spec, "%lfx%lf%n", &mx, &my, &n); - if (r != 2) - { r = sscanf( spec, "%lf*%lf%n", &mx, &my, &n); - if (r != 2) boxerr( boxspec); - } - spec += n; - } - - /* read '+ fixed , fixed' */ - if (1 < (r = sscanf( spec, "+%lf,%lf%n", &ox, &oy, &n))) - { if (r != 2) boxerr( boxspec); - spec += n; - } - - /* read unit */ - l = strlen( spec); - for (n=i=0; mediatable[i][0]; i++) - { if (!mystrncasecmp( mediatable[i][0], spec, l)) - { /* found */ - n++; - inx = i; - if (l == strlen( mediatable[i][0])) - { /* match is exact */ - n = 1; - break; - } - } - } - if (!n) boxerr( boxspec); - if (n>1) - { fprintf( stderr, "Your box spec '%s' is not unique! (give more chars)\n", - spec); - exit(1); - } - sscanf( mediatable[inx][1], "%lf,%lf", &ux, &uy); - - psbox[0] = ox * ux; - psbox[1] = oy * uy; - psbox[2] = mx * ux; - psbox[3] = my * uy; - - if (verbose > 1) - fprintf( stderr, " Box_convert: '%s' into [%g,%g,%g,%g]\n", - boxspec, psbox[0], psbox[1], psbox[2], psbox[3]); - - for (i=0; i<2; i++) - { if (psbox[i] < 0.0 || psbox[i+2] < psbox[i]) - { fprintf( stderr, "Your specification `%s' leads to " - "negative values!\n", boxspec); - exit(1); - } - } -} - -static void boxerr( char *spec) -{ int i; - - fprintf( stderr, "I don't understand your box specification `%s'!\n", - spec); - - fprintf( stderr, "The proper format is: ([text] meaning optional text)\n"); - fprintf( stderr, " [multiplier][offset]unit\n"); - fprintf( stderr, " with multiplier: numberxnumber\n"); - fprintf( stderr, " with offset: +number,number\n"); - fprintf( stderr, " with unit one of:"); - - for (i=0; mediatable[i][0]; i++) - fprintf( stderr, "%c%-10s", (i%7)?' ':'\n', mediatable[i][0]); - fprintf( stderr, "\nYou can use a shorthand for these unit names,\n" - "provided it resolves unique.\n"); - exit( 1); -} - -/*********************************************/ -/* output first part of DSC header */ -/*********************************************/ -static void dsc_head1() -{ - printf ("%%!PS-Adobe-3.0\n"); - printf ("%%%%Creator: %s\n", myname); -} - -/*********************************************/ -/* pass some DSC info from the infile in the new DSC header */ -/* such as document fonts and */ -/* extract BoundingBox info from the PS file */ -/*********************************************/ -static int dsc_infile( double ps_bb[4]) -{ - char *c, buf[BUFSIZE]; - int gotall, atend, level, dsc_cont, inbody, got_bb, n; - - if (freopen (infile, "r", stdin) == NULL) { - fprintf (stderr, "%s: fail to open file '%s'!\n", - myname, infile); - exit (1); - } - - got_bb = 0; - dsc_cont = inbody = gotall = level = atend = 0; - while (!gotall && (fgets(buf, BUFSIZE, stdin) != NULL)) - /*while (!gotall && (gets(buf) != NULL))*/ - { - n = strlen( buf ); - if ( buf[ n-1 ] == '\n' ) - buf[ n-1 ] = 0; - - if (buf[0] != '%') - { dsc_cont = 0; - if (!inbody) inbody = 1; - if (!atend) gotall = 1; - continue; - } - - if (!strncmp( buf, "%%+",3) && dsc_cont) - { puts( buf); - continue; - } - - dsc_cont = 0; - if (!strncmp( buf, "%%EndComments", 13)) - { inbody = 1; - if (!atend) gotall = 1; - } - else if (!strncmp( buf, "%%BeginDocument", 15) || - !strncmp( buf, "%%BeginData", 11)) level++; - else if (!strncmp( buf, "%%EndDocument", 13) || - !strncmp( buf, "%%EndData", 9)) level--; - else if (!strncmp( buf, "%%Trailer", 9) && level == 0) - inbody = 2; - else if (!strncmp( buf, "%%BoundingBox:", 14) && - inbody!=1 && !level) - { for (c=buf+14; *c==' ' || *c=='\t'; c++); - if (!strncmp( c, "(atend)", 7)) atend = 1; - else - { sscanf( c, "%lf %lf %lf %lf", - ps_bb, ps_bb+1, ps_bb+2, ps_bb+3); - got_bb = 1; - } - } - else if (!strncmp( buf, "%%Document", 10) && - inbody!=1 && !level) /* several kinds of doc props */ - { for (c=buf+10; *c && *c!=' ' && *c!='\t'; c++); - for (; *c==' ' || *c=='\t'; c++); - if (!strncmp( c, "(atend)", 7)) atend = 1; - else - { /* pass this DSC to output */ - puts( buf); - dsc_cont = 1; - } - } - else if ( !strncmp( buf, "%%Pages:", 8 ) ) - { - int n; - if ( sscanf( buf+8, "%d", &n ) == 1 ) - number_pages = n; - } - } - return got_bb; -} - -/*********************************************/ -/* output last part of DSC header */ -/*********************************************/ -static void dsc_head2() -{ - if ( pages == NULL ) - printf ("%%%%Pages: %d\n", nrows*ncols*number_pages); - else - printf ("%%%%Pages: %d\n", pages_length*number_pages); - -#ifndef Gv_gs_orientbug - printf ("%%%%Orientation: %s\n", rotate?"Landscape":"Portrait"); -#endif - printf ("%%%%DocumentMedia: %s %d %d 0 white ()\n", - mediaspec, (int)(mediasize[2]), (int)(mediasize[3])); - printf ("%%%%BoundingBox: 0 0 %d %d\n", (int)(mediasize[2]), (int)(mediasize[3])); - printf ("%%%%EndComments\n\n"); - - printf ("%% Print poster %s in %dx%d tiles with %.3g magnification\n", - infile, nrows, ncols, scale); -} - -/*********************************************/ -/* output the poster, create tiles if needed */ -/*********************************************/ -static void printposter() -{ - int row, col, page; - - printprolog(); - if ( pages == NULL ) - for ( page = 0; page < number_pages; page++ ) - for (row = 1; row <= nrows; row++) - for (col = 1; col <= ncols; col++) - tile( row, col, page); - else - for ( page = 0; page < number_pages; page++ ) - for ( row = 0; row < pages_length; row++ ) - { - int p = pages[ row ]-1; - if ( p+1 > nrows*ncols ) - fprintf( stderr, "Warning: page index out of range: %d\n", p+1 ); - tile( p/ncols+1, p%ncols+1, page ); - } - printf ("%%%%EOF\n"); - - if (tail_cntl_D) - { printf("%c", 0x4); - } -} - -/*******************************************************/ -/* output PS prolog of the scaling and tiling routines */ -/*******************************************************/ -static void printprolog() -{ - printf( "%%%%BeginProlog\n"); - - printf( "/cutmark %% - cutmark -\n" - "{ %% draw cutline\n" - " 0.23 setlinewidth 0 setgray\n" - " clipmargin\n" - " dup 0 moveto\n" - " dup neg leftmargin add 0 rlineto stroke\n" - " %% draw sheet alignment mark\n" - " dup dup neg moveto\n" - " dup 0 rlineto\n" - " dup dup lineto\n" - " 0 rlineto\n" - " closepath fill\n" - "} bind def\n\n"); - - printf( "%% usage: row col tileprolog ps-code tilepilog\n" - "%% these procedures output the tile specified by row & col\n" - "/tileprolog\n" - "{ %%def\n" - " gsave\n" - " leftmargin botmargin translate\n" - " do_turn {exch} if\n" - " /colcount exch def\n" - " /rowcount exch def\n" - " %% clip page contents\n" - " clipmargin neg dup moveto\n" - " pagewidth clipmargin 2 mul add 0 rlineto\n" - " 0 pageheight clipmargin 2 mul add rlineto\n" - " pagewidth clipmargin 2 mul add neg 0 rlineto\n" - " closepath clip\n" - " %% set page contents transformation\n" - " do_turn\n" - " { pagewidth 0 translate\n" - " 90 rotate\n" - " } if\n" - " pagewidth colcount 1 sub mul neg\n" - " pageheight rowcount 1 sub mul neg\n" - " do_turn {exch} if\n" - " translate\n" - " posterxl posteryb translate\n" - " sfactor dup scale\n" - " imagexl neg imageyb neg translate\n" - " tiledict begin\n" - " 0 setgray 0 setlinecap 1 setlinewidth\n" - " 0 setlinejoin 10 setmiterlimit [] 0 setdash newpath\n" - "} bind def\n\n"); - - printf( "/tileepilog\n" - "{ end %% of tiledict\n" - " grestore\n" - " %% print the cutmarks\n" - " gsave\n" - " leftmargin botmargin translate\n" - " pagewidth pageheight translate cutmark 90 rotate cutmark\n" - " 0 pagewidth translate cutmark 90 rotate cutmark\n" - " 0 pageheight translate cutmark 90 rotate cutmark\n" - " 0 pagewidth translate cutmark 90 rotate cutmark\n" - " grestore\n" - " %% print the page label\n" - " 0 setgray\n" - " leftmargin clipmargin 3 mul add clipmargin labelsize add neg botmargin add moveto\n" - " (Grid \\( ) show\n" - " rowcount strg cvs show\n" - " ( , ) show\n" - " colcount strg cvs show\n" - " ( \\)) show\n" - " showpage\n" - "} bind def\n\n"); - - printf( "%%%%EndProlog\n\n"); - printf( "%%%%BeginSetup\n"); - printf( "%% Try to inform the printer about the desired media size:\n" - "/setpagedevice where %% level-2 page commands available...\n" - "{ pop %% ignore where found\n" - " 3 dict dup /PageSize [ %d %d ] put\n" - " dup /Duplex false put\n%s" - " setpagedevice\n" - "} if\n", - (int)(mediasize[2]), (int)(mediasize[3]), - manualfeed?" dup /ManualFeed true put\n":""); - - printf( "/sfactor %.10f def\n" - "/leftmargin %d def\n" - "/botmargin %d def\n" - "/pagewidth %d def\n" - "/pageheight %d def\n" - "/imagexl %d def\n" - "/imageyb %d def\n" - "/posterxl %d def\n" - "/posteryb %d def\n" - "/do_turn %s def\n" - "/strg 10 string def\n" - "/clipmargin 6 def\n" - "/labelsize 9 def\n" - "/tiledict 250 dict def\n" - "tiledict begin\n" - "%% delay users showpage until cropmark is printed.\n" - "/showpage {} def\n" - "/setpagedevice { pop } def\n" - "end\n", - scale, (int)(cutmargin[0]), (int)(cutmargin[1]), - (int)(mediasize[2]-2.0*cutmargin[0]), (int)(mediasize[3]-2.0*cutmargin[1]), - (int)imagebb[0], (int)imagebb[1], (int)posterbb[0], (int)posterbb[1], - rotate?"true":"false"); - - printf( "/Helvetica findfont labelsize scalefont setfont\n"); - - printf( "%%%%EndSetup\n"); -} - -/*****************************/ -/* output one tile at a time */ -/*****************************/ -static void tile ( int row, int col, int pagetoprint) -{ - static int page=1; - - if (verbose) fprintf( stderr, "print page %d\n", page); - - printf ("\n%%%%Page: (%d,%d) %d\n", pagetoprint+1, ((row-1)*ncols+col), page); - printf ("%d %d tileprolog\n", row, col); - printf ("%%%%BeginDocument: %s\n", infile); - printfile (pagetoprint); - printf ("\n%%%%EndDocument\n"); - printf ("tileepilog\n"); - - page++; -} - -/******************************/ -/* copy the PS file to output */ -/******************************/ -static void printfile (int pagetoprint) -{ - /* use a double line buffer, so that when I print */ - /* a line, I know whether it is the last or not */ - /* I surely dont want to print a 'cntl_D' on the last line */ - /* The double buffer removes the need to scan each line for each page*/ - /* Furthermore allows cntl_D within binary transmissions */ - - char buf[2][BUFSIZE]; - int bp; - char *c; - int currentpage = -1; - - if (freopen (infile, "r", stdin) == NULL) { - fprintf (stderr, "%s: fail to open file '%s'!\n", - myname, infile); - printf ("/systemdict /showpage get exec\n"); - printf ("%%%%EOF\n"); - exit (1); - } - - /* fill first buffer for the first time */ - fgets( buf[bp=0], BUFSIZE, stdin); - -/* DSC comment starts with %% and has at least 1 more character. */ -#define IS_DSC(x) ( x[0]&&x[1]&&x[2] && (x[0]=='%')&&(x[1]=='%') ) - - /* read subsequent lines by rotating the buffers */ - while (fgets(buf[1-bp], BUFSIZE, stdin)) - { - /* We can not rely on DSC compliant input that correctly - uses "%%Page:" comments. Embedded figures may also have - such comments. So multi-page poster printing seems to be - broken anyway. Break it a little more in favour of - single-page posters until a better page separator is - implemented (DH). - */ - /* if ( !strncmp( buf[ bp ], "%%Page:", 7 ) ) - currentpage++; */ - - /* print line from the previous fgets */ - /* do not print postscript comment lines: those (DSC) lines */ - /* sometimes disturb proper previewing of the result with ghostview */ - if (!IS_DSC(buf[bp]) && ( currentpage == -1 || currentpage == pagetoprint )) - fputs( buf[bp], stdout); - bp = 1-bp; - } - - /* print buf from last successfull fgets, after removing cntlD */ - for (c=buf[bp]; *c && *c != '\04'; c++); - if (*c == '\04') - { tail_cntl_D = 1; - *c = '\0'; - } - if (!IS_DSC(buf[bp]) && strlen( buf[bp])) - fputs( buf[bp], stdout); -#undef IS_DSC -} - -static int mystrncasecmp( const char *s1, const char *s2, int n) -{ /* compare case-insensitive s1 and s2 for at most n chars */ - /* return 0 if equal. */ - /* Although standard available on some machines, */ - /* this function seems not everywhere around... */ - - char c1, c2; - int i; - - if (!s1) s1 = ""; - if (!s2) s2 = ""; - - for (i=0; i include file, - if your environment supports none of the SVID, XPG or POSIX standards. - If you have this problem, you can comment out the '#include ' - line in `poster.c', fetch `getopt.c' from the poster directory, - and compile and link these two files together.) - -(Note that this program might trigger a stupid bug in the HPUX 9.? C library, - causing the sscanf() call to produce a core dump. - For proper operation, DON'T give the `+ESlit' option to the HP cc, - or use gcc WITH the `-fwritable-strings' option.) - -The resulting executable is fully self-contained, -and doesn't require you to install other files at -`special' places in the OS. - -(For DOS users without C compiler, an executable - `poster.exe' is available) - -For UNIX environments (the primary target for the program) -there is a man page available `poster.1', which you can copy -to /usr/local/man/man1/ to obtain online manual support for -the users. - -The formatted version of this manual is available as a -postscript file `manual.ps', such that people who -don't know how to format unix man pages, still have -documentation to read and print. - -Success! - -Jos van Eijndhoven -Dept. of Elec. Eng. -Eindhoven Univ of Technology -The Netherlands -email: J.T.J.v.Eijndhoven@ele.tue.nl - -Sept 20, 1995 diff -Nru poster-20050907/setup.cfg poster-0.8.1/setup.cfg --- poster-20050907/setup.cfg 1970-01-01 00:00:00.000000000 +0000 +++ poster-0.8.1/setup.cfg 2011-04-16 13:40:23.000000000 +0000 @@ -0,0 +1,5 @@ +[egg_info] +tag_build = +tag_date = 0 +tag_svn_revision = 0 + diff -Nru poster-20050907/setup.py poster-0.8.1/setup.py --- poster-20050907/setup.py 1970-01-01 00:00:00.000000000 +0000 +++ poster-0.8.1/setup.py 2010-10-23 15:38:27.000000000 +0000 @@ -0,0 +1,39 @@ +from setuptools import setup, find_packages +import poster + +# To update version number, edit: +# poster/__init__.py +# docs/index.rst +version = ".".join(str(x) for x in poster.version) + +setup(name='poster', + version=version, + description="Streaming HTTP uploads and multipart/form-data encoding", + long_description="""\ +The modules in the Python standard library don't provide a way to upload large +files via HTTP without having to load the entire file into memory first. + +poster provides support for both streaming POST requests as well as +multipart/form-data encoding of string or file parameters""", + classifiers=[ + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Natural Language :: English", + "Programming Language :: Python", + "Topic :: Internet :: WWW/HTTP", + "Topic :: Software Development :: Libraries :: Python Modules", + ], + keywords='python http post multipart/form-data file upload', + author='Chris AtLee', + author_email='chris@atlee.ca', + url='http://atlee.ca/software/poster', + download_url='http://atlee.ca/software/poster/dist/%s' % version, + license='MIT', + packages=find_packages(exclude='tests'), + include_package_data=True, + zip_safe=True, + extras_require = {'poster': ["buildutils", "sphinx"]}, + tests_require = ["nose", "webob", "paste"], + test_suite = 'nose.collector', + #entry_points="", + ) diff -Nru poster-20050907/tests/test_encode.py poster-0.8.1/tests/test_encode.py --- poster-20050907/tests/test_encode.py 1970-01-01 00:00:00.000000000 +0000 +++ poster-0.8.1/tests/test_encode.py 2010-12-03 05:35:48.000000000 +0000 @@ -0,0 +1,372 @@ +# -*- coding: utf-8 -*- +from unittest import TestCase +import mimetypes +import poster.encode +import StringIO +import sys + +def unix2dos(s): + return s.replace("\n", "\r\n") + +class TestEncode_String(TestCase): + def test_simple(self): + expected = unix2dos("""--XXXXXXXXX +Content-Disposition: form-data; name="foo" +Content-Type: text/plain; charset=utf-8 + +bar +""") + self.assertEqual(expected, + poster.encode.encode_string("XXXXXXXXX", "foo", "bar")) + + def test_quote_name_space(self): + expected = unix2dos("""--XXXXXXXXX +Content-Disposition: form-data; name="foo baz" +Content-Type: text/plain; charset=utf-8 + +bar +""") + self.assertEqual(expected, + poster.encode.encode_string("XXXXXXXXX", "foo baz", "bar")) + + def test_quote_name_phparray(self): + expected = unix2dos("""--XXXXXXXXX +Content-Disposition: form-data; name="files[]" +Content-Type: text/plain; charset=utf-8 + +bar +""") + self.assertEqual(expected, + poster.encode.encode_string("XXXXXXXXX", "files[]", "bar")) + + def test_quote_unicode_name(self): + expected = unix2dos("""--XXXXXXXXX +Content-Disposition: form-data; name="=?utf-8?b?4piD?=" +Content-Type: text/plain; charset=utf-8 + +bar +""") + self.assertEqual(expected, + poster.encode.encode_string("XXXXXXXXX", u"\N{SNOWMAN}", "bar")) + + def test_quote_value(self): + expected = unix2dos("""--XXXXXXXXX +Content-Disposition: form-data; name="foo" +Content-Type: text/plain; charset=utf-8 + +bar baz@bat +""") + self.assertEqual(expected, + poster.encode.encode_string("XXXXXXXXX", "foo", "bar baz@bat")) + + def test_boundary(self): + expected = unix2dos("""--ABC+DEF +Content-Disposition: form-data; name="foo" +Content-Type: text/plain; charset=utf-8 + +bar +""") + self.assertEqual(expected, + poster.encode.encode_string("ABC DEF", "foo", "bar")) + + def test_unicode(self): + expected = unix2dos("""--XXXXXXXXX +Content-Disposition: form-data; name="foo" +Content-Type: text/plain; charset=utf-8 + +b\xc3\xa1r +""") + self.assertEqual(expected, + poster.encode.encode_string("XXXXXXXXX", "foo", u"bár")) + + +class TestEncode_File(TestCase): + def test_simple(self): + expected = unix2dos("""--XXXXXXXXX +Content-Disposition: form-data; name="foo" +Content-Type: text/plain; charset=utf-8 + +""") + self.assertEqual(expected, + poster.encode.encode_file_header("XXXXXXXXX", "foo", 42)) + + def test_content_type(self): + expected = unix2dos("""--XXXXXXXXX +Content-Disposition: form-data; name="foo" +Content-Type: text/html + +""") + self.assertEqual(expected, + poster.encode.encode_file_header("XXXXXXXXX", "foo", 42, filetype="text/html")) + + def test_filename_simple(self): + expected = unix2dos("""--XXXXXXXXX +Content-Disposition: form-data; name="foo"; filename="test.txt" +Content-Type: text/plain; charset=utf-8 + +""") + self.assertEqual(expected, + poster.encode.encode_file_header("XXXXXXXXX", "foo", 42, + "test.txt")) + + def test_quote_filename(self): + expected = unix2dos("""--XXXXXXXXX +Content-Disposition: form-data; name="foo"; filename="test file.txt" +Content-Type: text/plain; charset=utf-8 + +""") + self.assertEqual(expected, + poster.encode.encode_file_header("XXXXXXXXX", "foo", 42, + "test file.txt")) + + expected = unix2dos("""--XXXXXXXXX +Content-Disposition: form-data; name="foo"; filename="test\\"file.txt" +Content-Type: text/plain; charset=utf-8 + +""") + self.assertEqual(expected, + poster.encode.encode_file_header("XXXXXXXXX", "foo", 42, + "test\"file.txt")) + + def test_unicode_filename(self): + expected = unix2dos("""--XXXXXXXXX +Content-Disposition: form-data; name="foo"; filename="☃.txt" +Content-Type: text/plain; charset=utf-8 + +""") + self.assertEqual(expected, + poster.encode.encode_file_header("XXXXXXXXX", "foo", 42, + u"\N{SNOWMAN}.txt")) + +class TestEncodeAndQuote(TestCase): + def test(self): + self.assertEqual("foo+bar", poster.encode.encode_and_quote("foo bar")) + self.assertEqual("foo%40bar", poster.encode.encode_and_quote("foo@bar")) + self.assertEqual("%28%C2%A9%29+2008", + poster.encode.encode_and_quote(u"(©) 2008")) + +class TestMultiparam(TestCase): + def test_from_params(self): + fp = open("tests/test_encode.py") + expected = [poster.encode.MultipartParam("foo", "bar"), + poster.encode.MultipartParam("baz", fileobj=fp, + filename=fp.name, + filetype=mimetypes.guess_type(fp.name)[0])] + + self.assertEqual(poster.encode.MultipartParam.from_params( + [("foo", "bar"), ("baz", fp)]), expected) + + self.assertEqual(poster.encode.MultipartParam.from_params( + (("foo", "bar"), ("baz", fp))), expected) + + self.assertEqual(poster.encode.MultipartParam.from_params( + {"foo": "bar", "baz": fp}), expected) + + self.assertEqual(poster.encode.MultipartParam.from_params( + [expected[0], expected[1]]), expected) + + def test_from_params_dict(self): + + p = poster.encode.MultipartParam('file', fileobj=open("tests/test_encode.py")) + params = {"foo": "bar", "file": p} + + expected = [poster.encode.MultipartParam("foo", "bar"), p] + retval = poster.encode.MultipartParam.from_params(params) + + expected.sort() + retval.sort() + + self.assertEqual(retval, expected) + + def test_from_params_assertion(self): + p = poster.encode.MultipartParam('file', fileobj=open("tests/test_encode.py")) + params = {"foo": "bar", "baz": p} + + self.assertRaises(AssertionError, poster.encode.MultipartParam.from_params, + params) + + def test_simple(self): + p = poster.encode.MultipartParam("foo", "bar") + boundary = "XYZXYZXYZ" + expected = unix2dos("""--XYZXYZXYZ +Content-Disposition: form-data; name="foo" +Content-Type: text/plain; charset=utf-8 + +bar +--XYZXYZXYZ-- +""") + self.assertEqual(p.encode(boundary), expected[:-len(boundary)-6]) + self.assertEqual(p.get_size(boundary), len(expected)-len(boundary)-6) + self.assertEqual(poster.encode.get_body_size([p], boundary), + len(expected)) + self.assertEqual(poster.encode.get_headers([p], boundary), + {'Content-Length': str(len(expected)), + 'Content-Type': 'multipart/form-data; boundary=%s' % boundary}) + + datagen, headers = poster.encode.multipart_encode([p], boundary) + self.assertEqual(headers, {'Content-Length': str(len(expected)), + 'Content-Type': 'multipart/form-data; boundary=%s' % boundary}) + self.assertEqual("".join(datagen), expected) + + def test_multiple_keys(self): + params = poster.encode.MultipartParam.from_params( + [("key", "value1"), ("key", "value2")]) + boundary = "XYZXYZXYZ" + datagen, headers = poster.encode.multipart_encode(params, boundary) + encoded = "".join(datagen) + + expected = unix2dos("""--XYZXYZXYZ +Content-Disposition: form-data; name="key" +Content-Type: text/plain; charset=utf-8 + +value1 +--XYZXYZXYZ +Content-Disposition: form-data; name="key" +Content-Type: text/plain; charset=utf-8 + +value2 +--XYZXYZXYZ-- +""") + self.assertEqual(encoded, expected) + + + def test_stringio(self): + fp = StringIO.StringIO("file data") + params = poster.encode.MultipartParam.from_params( [("foo", fp)] ) + boundary = "XYZXYZXYZ" + datagen, headers = poster.encode.multipart_encode(params, boundary) + encoded = "".join(datagen) + + expected = unix2dos("""--XYZXYZXYZ +Content-Disposition: form-data; name="foo" +Content-Type: text/plain; charset=utf-8 + +file data +--XYZXYZXYZ-- +""") + self.assertEqual(encoded, expected) + + def test_reset_string(self): + p = poster.encode.MultipartParam("foo", "bar") + boundary = "XYZXYZXYZ" + + datagen, headers = poster.encode.multipart_encode([p], boundary) + + expected = unix2dos("""--XYZXYZXYZ +Content-Disposition: form-data; name="foo" +Content-Type: text/plain; charset=utf-8 + +bar +--XYZXYZXYZ-- +""") + + self.assertEquals("".join(datagen), expected) + datagen.reset() + self.assertEquals("".join(datagen), expected) + + def test_reset_multiple_keys(self): + params = poster.encode.MultipartParam.from_params( + [("key", "value1"), ("key", "value2")]) + boundary = "XYZXYZXYZ" + datagen, headers = poster.encode.multipart_encode(params, boundary) + expected = unix2dos("""--XYZXYZXYZ +Content-Disposition: form-data; name="key" +Content-Type: text/plain; charset=utf-8 + +value1 +--XYZXYZXYZ +Content-Disposition: form-data; name="key" +Content-Type: text/plain; charset=utf-8 + +value2 +--XYZXYZXYZ-- +""") + + encoded = "".join(datagen) + self.assertEqual(encoded, expected) + datagen.reset() + encoded = "".join(datagen) + self.assertEqual(encoded, expected) + + def test_reset_file(self): + fp = StringIO.StringIO("file data") + params = poster.encode.MultipartParam.from_params( [("foo", fp)] ) + boundary = "XYZXYZXYZ" + datagen, headers = poster.encode.multipart_encode(params, boundary) + + expected = unix2dos("""--XYZXYZXYZ +Content-Disposition: form-data; name="foo" +Content-Type: text/plain; charset=utf-8 + +file data +--XYZXYZXYZ-- +""") + encoded = "".join(datagen) + self.assertEqual(encoded, expected) + datagen.reset() + encoded = "".join(datagen) + self.assertEqual(encoded, expected) + + def test_MultipartParam_cb(self): + log = [] + def cb(p, current, total): + log.append( (p, current, total) ) + p = poster.encode.MultipartParam("foo", "bar", cb=cb) + boundary = "XYZXYZXYZ" + + datagen, headers = poster.encode.multipart_encode([p], boundary) + + "".join(datagen) + + l = p.get_size(boundary) + self.assertEquals(log[-1], (p, l, l)) + + def test_MultipartParam_file_cb(self): + log = [] + def cb(p, current, total): + log.append( (p, current, total) ) + p = poster.encode.MultipartParam("foo", fileobj=open("tests/test_encode.py"), + cb=cb) + boundary = poster.encode.gen_boundary() + + list(p.iter_encode(boundary)) + + l = p.get_size(boundary) + self.assertEquals(log[-1], (p, l, l)) + + def test_multipart_encode_cb(self): + log = [] + def cb(p, current, total): + log.append( (p, current, total) ) + p = poster.encode.MultipartParam("foo", "bar") + boundary = "XYZXYZXYZ" + + datagen, headers = poster.encode.multipart_encode([p], boundary, cb=cb) + + "".join(datagen) + + l = int(headers['Content-Length']) + self.assertEquals(log[-1], (None, l, l)) + +class TestGenBoundary(TestCase): + def testGenBoundary(self): + boundary1 = poster.encode.gen_boundary() + boundary2 = poster.encode.gen_boundary() + + self.assertNotEqual(boundary1, boundary2) + self.assert_(len(boundary1) > 0) + +class TestBackupGenBoundary(TestGenBoundary): + _orig_import = __import__ + def setUp(self): + # Make import uuid fail + def my_import(name, *args, **kwargs): + if name == 'uuid': + raise ImportError("Disabled for testing") + return self._orig_import(name, *args, **kwargs) + __builtins__['__import__'] = my_import + reload(poster.encode) + + def tearDown(self): + __builtins__['__import__'] = self._orig_import + reload(poster.encode) diff -Nru poster-20050907/tests/test_server.py poster-0.8.1/tests/test_server.py --- poster-20050907/tests/test_server.py 1970-01-01 00:00:00.000000000 +0000 +++ poster-0.8.1/tests/test_server.py 2010-10-23 14:59:01.000000000 +0000 @@ -0,0 +1,43 @@ +#!/usr/bin/env python +import webob + +def app(environ, start_response): + request = webob.Request(environ) + if request.path == '/redirect': + start_response("301 MOVED", [("Location", "/foo")]) + return "301 MOVED" + elif request.path == '/needs_auth': + auth = request.headers.get('Authorization') + if auth and auth.startswith("Basic"): + user,passwd = auth.split()[-1].decode("base64").split(":") + else: + user = None + + if user != 'john': + start_response("401 Unauthorized", [('WWW-Authenticate', "Basic realm=\"default\"")]) + return "401 Unauthorized" + + start_response("200 OK", [("Content-Type", "text/plain")]) + retval = ["Path: %s" % request.path] + keys = request.params.keys() + keys.sort() + for k in keys: + v = request.params[k] + if hasattr(v, 'file'): + v = v.file.read() + retval.append("%s: %s" % (k, v)) + return "\n".join(retval) + +if __name__ == '__main__': + import sys + from paste.httpserver import serve + port = int(sys.argv[1]) + if len(sys.argv) == 3 and sys.argv[2] == "ssl": + ssl_pem = "*" + else: + ssl_pem = None + + try: + serve(app, "localhost", port, ssl_pem=ssl_pem) + except KeyboardInterrupt: + pass diff -Nru poster-20050907/tests/test_streaming.py poster-0.8.1/tests/test_streaming.py --- poster-20050907/tests/test_streaming.py 1970-01-01 00:00:00.000000000 +0000 +++ poster-0.8.1/tests/test_streaming.py 2010-10-23 15:03:20.000000000 +0000 @@ -0,0 +1,159 @@ +# -*- coding: utf-8 -*- +from unittest import TestCase +import httplib +import poster +import urllib2, urllib +import threading, time, signal +import sys +import os +import subprocess +import tempfile + +port = 5123 + +class TestStreaming(TestCase): + disable_https = True + def setUp(self): + self.opener = poster.streaminghttp.register_openers() + if self.disable_https: + # Disable HTTPS support for these tests to excercise the non-https code + # HTTPS is tested in test_streaming_https.py + if hasattr(httplib, "HTTPS"): + self.https = getattr(httplib, "HTTPS") + delattr(httplib, "HTTPS") + reload(poster.streaminghttp) + else: + self.https = None + else: + self.https = None + + # Hard code to python2.6 for now, since python2.7 can't run the test server reliably + cmd = ["python2.6", os.path.join(os.path.dirname(__file__), 'test_server.py'), str(port)] + if not self.disable_https: + cmd.append("ssl") + null = open(os.devnull, "w") + self.server_output = tempfile.TemporaryFile() + self.server_proc = None + try: + self.server_proc = subprocess.Popen(cmd, stdout=self.server_output, stderr=self.server_output, close_fds=True) + for i in range(20): + try: + if self.disable_https: + urllib2.urlopen("http://localhost:%i/" % port).read() + else: + urllib2.urlopen("https://localhost:%i/" % port).read() + time.sleep(0.1) + break + except: + #import traceback + #traceback.print_exc() + time.sleep(0.1) + else: + self.server_output.seek(0) + print self.server_output.read() + raise OSError("Error starting server") + except: + if self.server_proc: + os.kill(self.server_proc.pid, signal.SIGINT) + self.server_proc.wait() + raise + + def tearDown(self): + if self.https: + setattr(httplib, "HTTPS", self.https) + + os.kill(self.server_proc.pid, signal.SIGINT) + self.server_proc.wait() + self.server_output.seek(0) + print self.server_output.read() + + def _open(self, url, params=None, headers=None): + try: + if headers is None: + headers = {} + req = urllib2.Request("http://localhost:%i/%s" % (port, url), params, + headers) + return urllib2.urlopen(req).read() + except: + self._opened = False + raise + + def test_basic(self): + response = self._open("testing123") + + self.assertEqual(response, "Path: /testing123") + + def test_basic2(self): + response = self._open("testing?foo=bar") + + self.assertEqual(response, "Path: /testing\nfoo: bar") + + def test_nonstream_uploadfile(self): + datagen, headers = poster.encode.multipart_encode([ + poster.encode.MultipartParam.from_file("file", __file__), + poster.encode.MultipartParam("foo", "bar")]) + + data = "".join(datagen) + + response = self._open("upload", data, headers) + self.assertEqual(response, "Path: /upload\nfile: %s\nfoo: bar" % open(__file__).read()) + + def test_stream_upload_generator(self): + datagen, headers = poster.encode.multipart_encode([ + poster.encode.MultipartParam.from_file("file", __file__), + poster.encode.MultipartParam("foo", "bar")]) + + response = self._open("upload", datagen, headers) + self.assertEqual(response, "Path: /upload\nfile: %s\nfoo: bar" % open(__file__).read()) + + def test_stream_upload_file(self): + data = open("poster/__init__.py") + headers = {"Content-Length": str(os.path.getsize("poster/__init__.py"))} + + response = self._open("upload", data, headers) + self.assertEquals(response, "Path: /upload\n%s" % open("poster/__init__.py").read().replace(" = ", " : ")) + + def test_stream_upload_file_no_len(self): + data = open(__file__) + self.assertRaises(ValueError, self._open, "upload", data, {}) + + def test_stream_upload_generator_no_len(self): + def data(): + yield "" + + self.assertRaises(ValueError, self._open, "upload", data(), {}) + + def test_redirect(self): + response = self._open("redirect") + + self.assertEqual(response, "Path: /foo") + + def test_login(self): + password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm() + password_manager.add_password( + None, "http://localhost:%i/needs_auth" % port, 'john', 'secret' + ) + + auth_handler = urllib2.HTTPBasicAuthHandler(password_manager) + auth_handler.handler_order = 0 + + self.opener.add_handler(auth_handler) + + data = open("poster/__init__.py") + headers = {"Content-Length": str(os.path.getsize("poster/__init__.py"))} + + response = self._open("needs_auth", data, headers) + self.assertEqual(response, "Path: /needs_auth\n%s" % open("poster/__init__.py").read().replace(" = ", " : ")) + +class TestStreamingHTTPS(TestStreaming): + disable_https = False + def _open(self, url, params=None, headers=None): + try: + if headers is None: + headers = {} + req = urllib2.Request("https://localhost:%i/%s" % (port, url), params, + headers) + return urllib2.urlopen(req).read() + except: + self._opened = False + raise