### Python usage: setup and addoptions Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/tcl/tix8.4.3/pref/WmDefault.txt For Tkinter, copy the WmDefault.* files and pkgIndex.tcl to a directory on PYTHONPATH. Then import Tkinter and WmDefault, create a root window, and call setup and addoptions. The example prints the current options. ```python import Tkinter root = Tkinter.Tk() import WmDefault WmDefault.setup(root) WmDefault.addoptions(root, {'foreground': 'red'}) print WmDefault.getoptions(root) ``` -------------------------------- ### Install idna with setup script Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/idna-2.0.dist-info/DESCRIPTION.rst Alternative installation method using the bundled setup script. ```bash $ python setup.py install ``` -------------------------------- ### Install setuptools via wget Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/setuptools-7.0.dist-info/DESCRIPTION.rst Download and run ez_setup.py using wget. May require superuser privileges for system-wide installation. ```bash > wget https://bootstrap.pypa.io/ez_setup.py -O - | python ``` -------------------------------- ### Install setuptools via wget with sudo Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/setuptools-7.0.dist-info/DESCRIPTION.rst Use sudo to install setuptools to the system Python with superuser privileges. ```bash > wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python ``` -------------------------------- ### Advanced installation with setup.py --prefix Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/setuptools-7.0.dist-info/DESCRIPTION.rst Install setuptools to a custom prefix by running setup.py with distutils options. Use --help for a full options list. ```bash setuptools-x.x$ python setup.py install --prefix=/opt/setuptools ``` -------------------------------- ### Bootstrap setuptools in setup.py using ez_setup Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/setuptools-7.0.dist-info/DESCRIPTION.rst Add this code to your setup.py to automatically bootstrap installation of setuptools as part of the setup process. It imports and calls use_setuptools() before importing setuptools, ensuring setuptools is available. ```python from ez_setup import use_setuptools use_setuptools() from setuptools import setup # etc... ``` -------------------------------- ### Install Python Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/README.txt Install the Python binary, library modules, shared library modules, include files, configuration files, and manual page. Files are installed under the prefix directory (default /usr/local). ```bash make install ``` -------------------------------- ### Install setuptools user-local via wget Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/setuptools-7.0.dist-info/DESCRIPTION.rst Use the --user flag to install setuptools for the current user without superuser privileges. ```bash > wget https://bootstrap.pypa.io/ez_setup.py -O - | python - --user ``` -------------------------------- ### Install setuptools to Python 3.3 via PowerShell py command Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/setuptools-7.0.dist-info/DESCRIPTION.rst Use the py launcher to install to a specific Python version, e.g., Python 3.3 when Python 2.7 is also installed. ```powershell > (Invoke-WebRequest https://bootstrap.pypa.io/ez_setup.py).Content | py -3 - ``` -------------------------------- ### Install a package from PyPI with pip install Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/pip-1.5.6.dist-info/DESCRIPTION.rst Use `pip install SomePackage` to install a package from PyPI. The output shows a success message after installation. ```shell $ pip install SomePackage [...] Successfully installed SomePackage ``` -------------------------------- ### Tk usage: package require and setup Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/tcl/tix8.4.3/pref/WmDefault.txt For Tk applications, at the beginning of a wish app, load the package and call setup and addoptions. The setup step finds the window manager settings; addoptions sets the Tk options database. ```tcl package require wm_default wm_default::setup wm_default::addoptions ``` -------------------------------- ### Install setuptools user-local via PowerShell Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/setuptools-7.0.dist-info/DESCRIPTION.rst Use the --user flag to install setuptools for the current user without administrative privileges. ```powershell > (Invoke-WebRequest https://bootstrap.pypa.io/ez_setup.py).Content | python - --user ``` -------------------------------- ### Start lightweight FTP server Source: https://github.com/aliyun/oss-ftp/blob/master/README.md Starts a lightweight FTP server without the web server. The server listens on 127.0.0.1:2048 by default. ```bash $ python ftpserver.py ``` -------------------------------- ### Install setuptools via PowerShell (Invoke-WebRequest) Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/setuptools-7.0.dist-info/DESCRIPTION.rst Use this PowerShell command to download and run ez_setup.py. Requires PowerShell 3 or later and administrative privileges unless using the --user flag for a user-local install. ```powershell > (Invoke-WebRequest https://bootstrap.pypa.io/ez_setup.py).Content | python - ``` -------------------------------- ### QNX: Build, test, and install Python 1.5.x Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/README.txt Use GNU bash and specific environment variables to configure, build, test, and install Python on QNX. Includes optional optimization flags and module list. ```shell CONFIG_SHELL=/usr/local/bin/bash CC=cc RANLIB=: \ ./configure --verbose --without-gcc --with-libm="" ``` ```shell array, audioop, binascii, cPickle, cStringIO, cmath, crypt, curses, errno, fcntl, gdbm, grp, imageop, _locale, math, md5, new, operator, parser, pcre, posix, pwd, readline, regex, reop, select, signal, socket, soundex, strop, struct, syslog, termios, time, timing, zlib, audioop, imageop ``` ```shell make SHELL=/usr/local/bin/bash ``` ```shell make SHELL=/usr/local/bin/bash OPT="-5 -Oil+nrt" ``` ```shell make SHELL=/usr/local/bin/bash test ``` ```shell make SHELL=/usr/local/bin/bash install ``` -------------------------------- ### Basic urllib3 PoolManager request example Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/urllib3-1.13.1.dist-info/DESCRIPTION.rst Shows how to use urllib3.PoolManager to make a GET request and print the status and data. The PoolManager automatically reuses connections for the same host. ```python import urllib3 http = urllib3.PoolManager() r = http.request('GET', 'http://google.com/') print r.status, r.data ``` -------------------------------- ### Install Requests with pip Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/requests-2.8.1.dist-info/DESCRIPTION.rst Command to install the Requests library using pip. ```bash $ pip install requests ``` -------------------------------- ### Install idna with pip Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/idna-2.0.dist-info/DESCRIPTION.rst Install the idna library using the pip package manager. ```bash $ pip install idna ``` -------------------------------- ### Tk usage: override addoptions settings Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/tcl/tix8.4.3/pref/WmDefault.txt You can override the settings found by setup by passing your own values to addoptions. This example sets the foreground to red and background to blue. ```tcl ::wm_default::addoptions -foreground red -background blue ``` -------------------------------- ### Build Python on UNIX: configure and make Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/README.txt Instructions to build Python from source on UNIX. Run './configure' in the current directory, then 'make' to create the './python' executable. To install in /usr/local, first run 'su root' and then 'make install'. ```shell ./configure ``` ```shell make ``` ```shell su root ``` ```shell make install ``` -------------------------------- ### Upgrade a package with pip install --upgrade Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/pip-1.5.6.dist-info/DESCRIPTION.rst Use `pip install --upgrade SomePackage` to upgrade an installed package. The output shows the existing installation being found and uninstalled, then the new version being installed. ```shell $ pip install --upgrade SomePackage [...] Found existing installation: SomePackage 1.0 Uninstalling SomePackage: Successfully uninstalled SomePackage Running setup.py install for SomePackage Successfully installed SomePackage ``` -------------------------------- ### Start FTP server on Linux Source: https://github.com/aliyun/oss-ftp/blob/master/README.md Starts the FTP server on Linux with a web server for monitoring. The system reads config.json in the root directory and listens on 127.0.0.1:2048 for FTP and 127.0.0.1:8192 for the web server. ```bash $ bash start.sh ``` -------------------------------- ### Install setuptools via curl Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/setuptools-7.0.dist-info/DESCRIPTION.rst Use curl instead of wget, replacing -O with -o. Follows the same instructions as the wget method. ```bash > curl https://bootstrap.pypa.io/ez_setup.py -o - | python ``` -------------------------------- ### Start FTP server on macOS Source: https://github.com/aliyun/oss-ftp/blob/master/README.md Starts the FTP server on macOS with a web server for monitoring. The system reads config.json in the root directory and listens on 127.0.0.1:2048 for FTP and 127.0.0.1:8192 for the web server. ```bash $ bash start.command ``` -------------------------------- ### Show installed files with pip show --files Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/pip-1.5.6.dist-info/DESCRIPTION.rst Use `pip show --files SomePackage` to display package metadata and the list of installed files. The output includes the package name, version, location, and file list. ```shell $ pip show --files SomePackage Name: SomePackage Version: 1.0 Location: /my/env/lib/pythonx.x/site-packages Files: ../somepackage/__init__.py [...] ``` -------------------------------- ### Import test.test_doctest and check sillySetup Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/test/test_doctest2.txt Doctest example that imports a module and checks a boolean attribute. The expected output is True. ```python >>> import test.test_doctest >>> test.test_doctest.sillySetup True ``` -------------------------------- ### Start FTP server with custom parameters Source: https://github.com/aliyun/oss-ftp/blob/master/README.md Starts the FTP server with custom parameters. The internal flag controls OSS access: True uses intranet domain, False uses internet domain, and if not specified, the server probes network status and prioritizes intranet. The loglevel sets the log detail level, with DEBUG providing more information. ```bash python ftpserver.py --listen_address= --port= --passive_ports_start= --passive_ports_end= --internal= --loglevel= ``` -------------------------------- ### Importing Fruit and pickle for pickling example Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/enum/doc/enum.pdf Imports the Fruit enum and pickle functions for the pickling demonstration. ```python >>> from enum.test_enum import Fruit >>> from pickle import dumps, loads ``` -------------------------------- ### Basic GET request with authentication Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/requests-2.8.1.dist-info/DESCRIPTION.rst Shows how to make a GET request to the GitHub API with basic authentication, then access the status code, headers, and response text. ```python >>> r = requests.get('https://api.github.com', auth=('user', 'pass')) >>> r.status_code 204 >>> r.headers['content-type'] 'application/json' >>> r.text ... ``` -------------------------------- ### Basic IDNA encode/decode example Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/idna-2.0.dist-info/DESCRIPTION.rst Shows how to use the idna.encode and idna.decode functions to convert between Unicode domain names and their ASCII-compatible A-label forms. The example uses a Japanese domain name and demonstrates round-trip conversion. ```pycon >>> import idna >>> idna.encode(u'ドメイン.テスト') 'xn--eckwd4c7c.xn--zckzah' >>> print idna.decode('xn--eckwd4c7c.xn--zckzah') ドメイン.テスト ``` -------------------------------- ### Create /usr/local directory on clean OSX Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/README.txt Run this command before 'make install' on a clean OSX system where /usr/local does not exist. ```bash sudo mkdir -m 775 /usr/local ``` -------------------------------- ### GUI test setUpClass and tearDownClass with requires('gui') Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/idlelib/idle_test/README.txt Example of guarding a GUI test with requires('gui') and creating/destroying a Tk root in class setup/teardown. Ensures tests are skipped when GUI is unavailable and cleans up objects. ```python @classmethod def setUpClass(cls): requires('gui') cls.root = tk.Tk() @classmethod def tearDownClass(cls): cls.root.destroy() del cls.root ``` -------------------------------- ### Equivalent class definition to functional API Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/enum/doc/enum.pdf Shows the equivalent class-based definition of the functional API example. ```python >>> class Animals(Enum): ... ant = 1 ... bee = 2 ... cat = 3 ... dog = 4 ``` -------------------------------- ### Doctest: Demonstrate blank-line feature with if statement Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/test/test_doctest.txt This doctest example shows how the blank-line feature works. The expected output includes a marker for the blank line printed by the code. ```python >>> if 1: ... print 'a' ... print ... print 'b' a b ``` -------------------------------- ### List outdated packages with pip list --outdated Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/pip-1.5.6.dist-info/DESCRIPTION.rst Use `pip list --outdated` to list installed packages that have newer versions available. The output shows the current and latest versions. ```shell $ pip list --outdated SomePackage (Current: 1.0 Latest: 2.0) ``` -------------------------------- ### Equivalent class definition for functional API Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/enum/doc/enum.rst Shows the equivalent class definition for the functional API example, using explicit member assignments. ```python >>> class Animals(Enum): ... ant = 1 ... bee = 2 ... cat = 3 ... dog = 4 ``` -------------------------------- ### Using inspector.Tkinspect to inspect an object Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/idlelib/TODO.txt Shows how to use the inspector module to visually navigate an object's attributes. The example creates a Tkinspect instance with a parent of None and the object to inspect. ```python >>> from inspector import Tkinspect >>> Tkinspect(None, myObject) ``` -------------------------------- ### Set PYTHONIOENCODING to utf8 for pip install numpy Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/setuptools-7.0.dist-info/DESCRIPTION.rst Workaround for packages that reference sys.__stdout__ (e.g., numpy) when the system encoding is not UTF-8. Set the PYTHONIOENCODING environment variable to utf8 before running pip install. ```bash PYTHONIOENCODING=utf8 pip install numpy ``` -------------------------------- ### Subclassing an Enum with behavior Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/enum/doc/enum.rst Shows how to define an enum with a method and then subclass it. The example demonstrates that subclassing an enum that defines members is not allowed, but sharing behavior is possible. ```python >>> class Foo(Enum): ... def some_behavior(self): ... pass ... >>> class Bar(Foo): ... happy = 1 ... sad = 2 ... ``` -------------------------------- ### Complete ZoomHeight extension example Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/idlelib/extend.txt Defines a class with a menudefs list that adds a 'Zoom Height' menu entry to the 'edit' menu, and a zoom_height_event method that is bound to the virtual event <>. The class is instantiated with an editwin argument and stores it for later use. ```python class ZoomHeight: menudefs = [ ('edit', [ None, # Separator ('_Zoom Height', '<>'), ]) ] def __init__(self, editwin): self.editwin = editwin def zoom_height_event(self, event): "...Do what you want here..." ``` -------------------------------- ### Enum with methods and special methods Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/enum/doc/enum.rst Enumerations can have methods and special methods. This example defines describe, __str__, and a classmethod. ```python >>> class Mood(Enum): ... funky = 1 ... happy = 3 ... ... def describe(self): ... # self is the member here ... return self.name, self.value ... ... def __str__(self): ... return 'my custom str! {0}'.format(self.value) ... ... @classmethod ... def favorite_mood(cls): ... # cls here is the enumeration ... return cls.happy ``` -------------------------------- ### Using __members__ to access all names including aliases Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/enum/doc/enum.rst The __members__ dictionary maps all names, including aliases, to members. This example iterates over sorted items. ```python >>> for name, member in sorted(Shape.__members__.items()): ... name, member ... ('alias_for_square', ) ('circle', ) ('diamond', ) ('square', ) ``` -------------------------------- ### FreeBSD curses module linking workaround Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/README.txt For FreeBSD 3.x and similar platforms with NCurses, remove '-ltermcap' from the readline entry in Setup and use this curses entry to ensure correct linking order. ```text curses cursesmodule.c -lmytinfo -lncurses -ltermcap ``` -------------------------------- ### Pickling and unpickling an enum Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/enum/doc/enum.rst Demonstrates that enums can be pickled and unpickled. The example shows that a pickled enum member is identical to the original after loading. ```python >>> from enum.test_enum import Fruit >>> from pickle import dumps, loads >>> Fruit.tomato is loads(dumps(Fruit.tomato, 2)) True ``` -------------------------------- ### UTS #46 compatibility mapping example Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/idna-2.0.dist-info/DESCRIPTION.rst Demonstrates the use of the uts46 parameter to enable Unicode IDNA Compatibility Processing, including transitional and non-transitional modes. Shows that without uts46, an InvalidCodepoint error is raised for certain characters. ```pycon >>> import idna >>> idna.encode(u'Königsgäßchen') ... idna.core.InvalidCodepoint: Codepoint U+004B at position 1 of u'K\xf6nigsg\xe4\xdfchen' not allowed >>> idna.encode(u'Königsgäßchen', uts46=True) 'xn--knigsgchen-b4a3dun' >>> idna.encode(u'Königsgäßchen', uts46=True, transitional=True) 'xn--knigsgsschen-lcb0w' ``` -------------------------------- ### Enum member attribute access example Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/enum/doc/enum.pdf Shows that accessing an attribute on an Enum member returns the member's attribute value, not the member itself. In the example, FieldTypes.value.size returns the member with value 2, while FieldTypes.size.value returns the integer 2. ```python >>> class FieldTypes(Enum): ... name = 0 ... value = 1 ... size = 2 ... >>> FieldTypes.value.size >>> FieldTypes.size.value 2 ``` -------------------------------- ### Run a single test manually in verbose mode Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/README.txt Run a failing test manually to get useful output for a bug report. Substitute the top of the source tree for '.' if built in a different directory. ```bash ./python Lib/test/regrtest.py -v test_whatever ``` -------------------------------- ### Access enum member by value Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/enum/doc/enum.rst Call the enum with a value to get the corresponding member. ```python >>> Color(1) >>> Color(3) ``` -------------------------------- ### Edit Tix.tcl configspec Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/tcl/tix8.4.3/pref/WmDefault.txt Edit the installed lib/8.1/Tix.tcl and change the -configspec in tixClass tixAppContext with the following lines. ```tcl {-fontset WmDefault} {-scheme WmDefault} ``` -------------------------------- ### Doctest: Unicode string with ą Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/test/test_doctest4.txt A doctest example showing the expected output for a Unicode string containing the character ą. The output is the escaped Unicode representation. ```python >>> u'bąr' u'b\u0105r' ``` -------------------------------- ### Get name and value of an enum member Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/enum/doc/enum.rst Given an enum member, access its name and value properties. ```python >>> member = Color.red >>> member.name 'red' >>> member.value 1 ``` -------------------------------- ### Functional API to create an enum Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/enum/doc/enum.rst Shows how to create an enum using the callable Enum class with a whitespace-separated string of names. The example also shows how to access members and list them. ```python >>> Animal = Enum('Animal', 'ant bee cat dog') >>> Animal >>> Animal.ant >>> Animal.ant.value 1 >>> list(Animal) [, , , ] ``` -------------------------------- ### Uninstall a package with pip uninstall Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/pip-1.5.6.dist-info/DESCRIPTION.rst Use `pip uninstall SomePackage` to remove an installed package. The command prompts for confirmation before uninstalling, and the output shows the uninstallation success. ```shell $ pip uninstall SomePackage Uninstalling SomePackage: /my/env/lib/pythonx.x/site-packages/somepackage Proceed (y/n)? y Successfully uninstalled SomePackage ``` -------------------------------- ### Doctest: Unicode string with ö Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/test/test_doctest4.txt A doctest example showing the expected output for a Unicode string containing the character ö. The output is the escaped Unicode representation. ```python >>> u'föö' u'f\xf6\xf6' ``` -------------------------------- ### Interpreter session for test_gestalt leak Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/test/leakers/README.txt Example interpreter session showing how to import a leak function and call it repeatedly, observing the ref count increase. The ref counts shown are [24275], [28936], [28938], [28940] after each call. ```python >>> from test.leakers.test_gestalt import leak [24275 refs] >>> leak() [28936 refs] >>> leak() [28938 refs] >>> leak() [28940 refs] >>> ``` -------------------------------- ### Doctest: Access global variable favorite_color Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/test/test_doctest.txt This doctest example relies on a global variable 'favorite_color' being set before the test runs. The expected output is the string 'blue'. ```python >>> favorite_color 'blue' ``` -------------------------------- ### Doctest: Byte string with ą Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/test/test_doctest4.txt A doctest example showing the expected output for a byte string containing the UTF-8 encoded character ą. The output is the escaped byte representation. ```python >>> 'bąr' 'b\xc4\x85r' ``` -------------------------------- ### Test module template for idlelib tests Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/idlelib/idle_test/README.txt Template for a test module in idlelib.idle_test. Each test file should start with this structure, filling in the module name and test class/method names. Uses unittest and requires from test.support. ```python import unittest from test.support import requires import idlelib. as class _Test(unittest.TestCase): def test_(self): if __name__ == '__main__': unittest.main(verbosity=2, exit=2) ``` -------------------------------- ### Doctest: Byte string with ö Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/test/test_doctest4.txt A doctest example showing the expected output for a byte string containing the UTF-8 encoded character ö. The output is the escaped byte representation. ```python >>> 'föö' 'f\xc3\xb6\xc3\xb6' ``` -------------------------------- ### Solaris dynamic loader error message Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/README.txt Example error message when the dynamic loader cannot find shared libraries on Solaris. Use this to identify missing library issues and apply one of the listed strategies. ```text ld.so.1: ./python: fatal: libstdc++.so.5: open failed: No such file or directory ``` -------------------------------- ### Custom enum with methods and special methods Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/enum/doc/enum.pdf Enumerations are Python classes and can have methods and special methods. This example defines a Mood enum with a describe method and a __str__ method, and a classmethod favorite_mood. ```python >>> class Mood(Enum): ... funky = 1 ... happy = 3 ... ... def describe(self): ... # self is the member here ... return self.name, self.value ... ... def __str__(self): ... return 'my custom str! {0}'.format(self.value) ... ... @classmethod ... def favorite_mood(cls): ``` ```python ... # cls here is the enumeration ... return cls.happy ``` -------------------------------- ### Duplicate member names in Python 2 vs 3 Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/enum/doc/enum.pdf In Python 2, duplicate names silently overwrite; in Python 3, they raise TypeError. This example shows both behaviors. ```python >>> # python 2.x >>> class Shape(Enum): ... square = 2 ... square = 3 ... >>> Shape.square >>> # python 3.x >>> class Shape(Enum): ... square = 2 ... square = 3 Traceback (most recent call last): ... TypeError: Attempted to reuse key: 'square' ``` -------------------------------- ### OrderedEnum with comparison operators Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/enum/doc/enum.rst Defines an Enum subclass that supports ordering comparisons (>=, >, <=, <) without using IntEnum. The example shows a Grade enum and verifies that Grade.C < Grade.A is True. ```python >>> class OrderedEnum(Enum): ... def __ge__(self, other): ... if self.__class__ is other.__class__: ... return self._value_ >= other._value_ ... return NotImplemented ... def __gt__(self, other): ... if self.__class__ is other.__class__: ... return self._value_ > other._value_ ... return NotImplemented ... def __le__(self, other): ... if self.__class__ is other.__class__: ... return self._value_ <= other._value_ ... return NotImplemented ... def __lt__(self, other): ... if self.__class__ is other.__class__: ... return self._value_ < other._value_ ... return NotImplemented ... >>> class Grade(OrderedEnum): ... __ordered__ = 'A B C D F' ... A = 5 ... B = 4 ... C = 3 ... D = 2 ... F = 1 ... >>> Grade.C < Grade.A True ``` -------------------------------- ### AutoNumber enum with __new__ for automatic values Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/enum/doc/enum.rst Defines an Enum subclass that automatically assigns sequential integer values to members via __new__. The example shows a Color enum with red, green, blue and verifies that green.value equals 2. ```python >>> class AutoNumber(Enum): ... def __new__(cls): ... value = len(cls.__members__) + 1 ... obj = object.__new__(cls) ... obj._value_ = value ... return obj ... >>> class Color(AutoNumber): ... __order__ = "red green blue" # only needed in 2.x ... red = () ... green = () ... blue = () ... >>> Color.green.value == 2 True ``` -------------------------------- ### UniqueEnum raises ValueError on duplicate member names Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/enum/doc/enum.rst Defines an Enum subclass that raises ValueError if a duplicate member name is found, instead of creating an alias. The example shows a Color enum with a duplicate value for 'grene' and the resulting error. ```python >>> class UniqueEnum(Enum): ... def __init__(self, *args): ... cls = self.__class__ ... if any(self.value == e.value for e in cls): ... a = self.name ... e = cls(self.value).name ... raise ValueError( ... "aliases not allowed in UniqueEnum: %r --> %r" ... % (a, e)) ... >>> class Color(UniqueEnum): ... red = 1 ... green = 2 ... blue = 3 ... grene = 2 Traceback (most recent call last): ... ValueError: aliases not allowed in UniqueEnum: 'grene' --> 'green' ``` -------------------------------- ### Uncomment SSL and socket module lines in Modules/Setup Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/README.txt In Modules/Setup, uncomment these lines to link the _socket module statically with SSL support. Remove 'local/' from the SSL variable as instructed. ```makefile #SSL=/usr/local/ssl #_socket socketmodule.c \ # -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \ # -L$(SSL)/lib -lssl -lcrypto ``` -------------------------------- ### Tk usage: examine settings with getoptions and parray Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/tcl/tix8.4.3/pref/WmDefault.txt Use getoptions to return a Tcl array of the current settings, and parray to return a string of the current settings, one value-pair per line. ```tcl ::wm_default::getoptions ``` ```tcl ::wm_default::parray ``` -------------------------------- ### Enable bsddb185 module in Modules/Setup Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/README.txt For Unix platforms using Berkeley DB 1.85, add this line to Modules/Setup to build the bsddb185 module. May require additional -I, -L, or -l flags for include files and libraries. ```text bsddb185 bsddbmodule.c ``` -------------------------------- ### Run make after configuring Cygwin build Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/README.txt After configuring and editing Modules/Setup, run make to build Python. ```bash make ``` -------------------------------- ### Configure with profiling using gcc -pg Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/README.txt Run configure with the CC environment variable set to 'gcc -pg' to enable C profiling with gprof on Linux. Note that gprof does not work for shared libraries on Linux. ```bash CC="gcc -pg" ./configure ``` -------------------------------- ### Use idna codec for encoding/decoding Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/idna-2.0.dist-info/DESCRIPTION.rst Demonstrates using the idna.codec module to encode and decode domain names using the 'idna' codec. ```pycon >>> import idna.codec >>> print u'домена.испытание'.encode('idna') xn--80ahd1agd.xn--80akhbyknj4f >>> print 'xn--80ahd1agd.xn--80akhbyknj4f'.decode('idna') домена.испытание ``` -------------------------------- ### Run tests on all platforms with make test-all Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/urllib3-1.13.1.dist-info/DESCRIPTION.rst Command to run the test suite across all supported platforms using tox. The output shows the success status for each Python version. ```bash $ make test-all [... tox creates a virtualenv for every platform and runs tests inside of each] py26: commands succeeded py27: commands succeeded py32: commands succeeded py33: commands succeeded py34: commands succeeded ``` -------------------------------- ### Using enum methods Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/enum/doc/enum.rst Demonstrates calling the methods defined on the Mood enum. ```python >>> Mood.favorite_mood() >>> Mood.happy.describe() ('happy', 3) >>> str(Mood.funky) 'my custom str! 1' ``` -------------------------------- ### Minimal Unix build commands Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/README.txt Commands to build Python in a separate directory, assuming the source is in ~guido/src/python. Run configure and make in the build directory. ```shell $ mkdir /usr/tmp/python $ cd /usr/tmp/python $ ~guido/src/python/configure [...] $ make [...] $ ``` -------------------------------- ### AIX 5.3: Build 64-bit Python with IBM compiler Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/README.txt Set environment variables and configure with specific compiler flags to build a 64-bit version on AIX 5.3 using IBM's compiler. ```shell export PATH=/usr/bin:/usr/vacpp/bin ./configure --with-gcc="xlc_r -q64" --with-cxx="xlC_r -q64" \ --disable-ipv6 AR="ar -X64" make ``` -------------------------------- ### Run individual test case or method Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/idlelib/idle_test/README.txt Command to run a specific test case or method by extending the dotted name. ```shell python -m unittest -v idlelib.idle_test.test_xyz.Test_case.test_meth ``` -------------------------------- ### Planet enumeration with __init__ and property Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/enum/doc/enum.pdf Defines a Planet enumeration where each member has mass and radius values, and a surface_gravity property calculates gravity using the universal gravitational constant. Shows accessing value and property. ```python >>> class Planet(Enum): ... MERCURY = (3.303e+23, 2.4397e6) ... VENUS = (4.869e+24, 6.0518e6) ... EARTH = (5.976e+24, 6.37814e6) ... MARS = (6.421e+23, 3.3972e6) ... JUPITER = (1.9e+27, 7.1492e7) ... SATURN = (5.688e+26, 6.0268e7) ... URANUS = (8.686e+25, 2.5559e7) ... NEPTUNE = (1.024e+26, 2.4746e7) ... def __init__(self, mass, radius): ... self.mass = mass # in kilograms ... self.radius = radius # in meters ... @property ... def surface_gravity(self): ... # universal gravitational constant (m3 kg-1 s-2) ... G = 6.67300E-11 ... return G * self.mass / (self.radius * self.radius) ... >>> Planet.EARTH.value (5.976e+24, 6378140.0) >>> Planet.EARTH.surface_gravity ``` -------------------------------- ### Import float_info and math functions Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/test/ieee754.txt Imports float_info from sys and math functions, and defines PI and E. ```python >>> from sys import float_info as FI >>> from math import * >>> PI = pi >>> E = e ``` -------------------------------- ### Run Pynche as a modal dialog with pyColorChooser.askcolor() Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Tools/pynche/README.txt Import pyColorChooser from the Pynche package and call askcolor() to popup Pynche as a modal dialog, returning the selected color. The return value is a tuple ((r, g, b), "name") where r, g, b are 0-255 and "name" is a color name or an X11 spec like "#rrggbb". ```python pyColorChooser.askcolor() ``` -------------------------------- ### Run gcov on a module Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/README.txt After building with 'make coverage' and running the code, run gcov on a source file to see coverage statistics. This creates a .gcov file in the current directory. Works only for statically compiled files. ```bash gcov -o Modules zlibmodule ``` -------------------------------- ### Minimum set of modules for Cray T3E Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/README.txt List of modules to add or uncomment in Modules/Setup for building Python on Cray T3E, which does not support dynamic linking. ```text posix, new, _sre, unicodedata ``` -------------------------------- ### Encrypt and decrypt with Fernet Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/cryptography-1.1.2.dist-info/DESCRIPTION.rst Shows how to use the high-level symmetric encryption recipe from the cryptography package. Generates a key, creates a Fernet object, encrypts a message, and decrypts it. The key should be stored safely. ```pycon >>> from cryptography.fernet import Fernet >>> # Put this somewhere safe! >>> key = Fernet.generate_key() >>> f = Fernet(key) >>> token = f.encrypt(b"A really secret message. Not for prying eyes.") >>> token '...' >>> f.decrypt(token) 'A really secret message. Not for prying eyes.' ``` -------------------------------- ### Configure Python with Unicode UCS4 on Cray T3E Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/README.txt Run configure with this option to enable Unicode support using UCS4 on Cray T3E. ```bash configure --enable-unicode=ucs4 ``` -------------------------------- ### HP-UX ia64: Build 64-bit executable on Itanium 2 Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/README.txt Set environment variables and configure without GCC to build a 64-bit executable on HP-UX ia64. Unset the variables before running make, and remove -O from the OPT line in the Makefile. ```shell CC=cc CXX=aCC BASECFLAGS="+DD64" LDFLAGS="+DD64 -lxnet" ``` ```shell ./configure --without-gcc ``` -------------------------------- ### Run all idle tests interactively with unittest.main Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/idlelib/idle_test/README.txt Command to run all idle_test tests from an interactive Python session. Requires unittest imported. ```python >>> unittest.main('idlelib.idle_test', verbosity=2, exit=False) ``` -------------------------------- ### Run tests with make test Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/urllib3-1.13.1.dist-info/DESCRIPTION.rst Command to run the test suite inside a virtualenv. The output shows the number of tests run and any skipped tests. Code coverage less than 100% is considered a failure. ```bash $ make test [... magically installs dependencies and runs tests on your virtualenv] Ran 182 tests in 1.633s OK (SKIP=6) ``` -------------------------------- ### Per-label conversion with alabel Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/idna-2.0.dist-info/DESCRIPTION.rst Shows how to convert a single label to its A-label form using the alabel function. ```pycon >>> idna.alabel(u'测试') 'xn--0zwm56d' ``` -------------------------------- ### Compile Tix with WmDefault as default scheme Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/tcl/tix8.4.3/pref/WmDefault.txt To make a previous Tix use WmDefault as the default scheme, compile Tix with these defines, or change the defines in generic/tixInit.c. ```c -DTIX_DEF_SCHEME "WmDefault" -DTIX_DEF_FONTSET "WmDefault" ``` ```c #define TIX_DEF_SCHEME "WmDefault" #define TIX_DEF_FONTSET "WmDefault" ``` -------------------------------- ### Decimal constructor accepts float directly Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/NEWS.txt Shows that Decimal(1.1) now converts a float to a Decimal of equal value, producing a long binary expansion. ```python >>> Decimal(1.1) Decimal('1.100000000000000088817841970012523233890533447265625') ``` -------------------------------- ### Add package ifneeded to pkgIndex.tcl Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/tcl/tix8.4.3/pref/WmDefault.txt Make or edit the file lib/tix8.1/pkgIndex.tcl and add these lines to register the wm_default package. ```tcl package ifneeded wm_default 1.0 \ [list source [file join $dir pref WmDefault.tcl]] ``` -------------------------------- ### Import future_builtins hex and oct Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/NEWS.txt Shows the expected usage of the future_builtins module, which provides PEP 3127 versions of hex() and oct() that are compatible with Python 3.0. The output formats differ slightly from the existing Python 2.6 builtins. ```python from future_builtins import hex, oct ``` -------------------------------- ### Implementing IntEnum independently Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/enum/doc/enum.rst Shows a simple implementation of IntEnum by subclassing int and Enum, demonstrating how to create derived enumerations. ```python class IntEnum(int, Enum): pass ``` -------------------------------- ### Run all idle tests from command line Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/idlelib/idle_test/README.txt Command-line commands to run all idle tests. The third command runs unittest indirectly through regrtest; -v and -ugui can be omitted where present. ```shell python -m unittest -v idlelib.idle_test ``` ```shell python -m test -v -ugui test_idle ``` ```shell python -m test.test_idle ``` -------------------------------- ### Set stack size limit in tcsh/csh for MacOSX tests Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/README.txt Use this shell command to set the stack size to 2048 before running 'make test' on MacOSX to avoid SEGV crashes in test_re and test_sre. ```bash limit stacksize 2048 ``` -------------------------------- ### SCO 3: Set LIBS for crypt library Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/README.txt Set the LIBS variable to include the socket and crypt libraries, required due to U.S. export restrictions on SCO 3. ```shell LIBS=' -lsocket -lcrypt_i' ``` -------------------------------- ### Specifying module for pickling functional API enums Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/enum/doc/enum.rst Shows how to specify the module name explicitly when creating an enum with the functional API to ensure pickling works correctly. ```python >>> Animals = Enum('Animals', 'ant bee cat dog', module=__name__) ``` -------------------------------- ### Set stack size limit in bash for MacOSX tests Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/README.txt Use this shell command to set the stack size to 2048 before running 'make test' on MacOSX (default shell as of OSX 10.3) to avoid SEGV crashes. ```bash ulimit -s 2048 ``` -------------------------------- ### Set MACHDEP environment variable for Cray T3E Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/README.txt Pass this environment variable to the configure script to set sys.platform to something sensible on Cray T3E. ```bash MACHDEP=unicosmk ``` -------------------------------- ### Run regression tests excluding test_select on 9X/Me Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/README.txt Use this command to run the regression test suite while skipping test_select, which hangs on Windows 9X/Me. ```bash make TESTOPTS='-l -x test_select' test ``` -------------------------------- ### FTP connection error: 530 Can't list buckets Source: https://github.com/aliyun/oss-ftp/blob/master/README.md Error message displayed when the FTP server cannot list buckets, indicating incorrect access_key credentials or insufficient RAM permissions. ```bash $ 530 Can't list buckets, check your access_key. ``` -------------------------------- ### Construct INF, NINF, and NAN from strings Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/test/ieee754.txt Constructs infinity and NaN values using float('inf'), float('-inf'), and float('nan'). ```python >>> INF = float('inf') >>> NINF = float('-inf') >>> NAN = float('nan') ``` -------------------------------- ### Display INF, NINF, and NAN values Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/test/ieee754.txt Shows the string representations of INF, NINF, and NAN. ```python >>> INF inf >>> NINF -inf >>> NAN nan ``` -------------------------------- ### Add unittest main to module under test Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/idlelib/idle_test/README.txt Snippet to add at the end of the module under test (e.g., xyz.py) to allow running its tests from the module itself. Uses unittest.main with the test module name. ```python if __name__ == "__main__": import unittest unittest.main('idlelib.idle_test.test_', verbosity=2, exit=False) ``` -------------------------------- ### Custom IntEnum implementation Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/enum/doc/enum.pdf Shows a minimal implementation of IntEnum by subclassing int and Enum. This demonstrates how to define similar derived enumerations, such as a StrEnum mixing in str. ```python class IntEnum(int, Enum): pass ``` -------------------------------- ### Finding aliases with __members__ Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/enum/doc/enum.rst Using __members__ to programmatically find aliases by comparing member names. ```python >>> [name for name, member in Shape.__members__.items() if member.name != name] ['alias_for_square'] ``` -------------------------------- ### Configure with threads disabled for Cygwin Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/README.txt Run this configure command to disable threading support, which is required to work around Cygwin build failures. The command is part of the band-aid fix for dynamic linking and fork() issues. ```bash ./configure --with-threads=no ``` -------------------------------- ### IntEnum behaves like an integer Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/enum/doc/enum.rst Demonstrates that IntEnum members can be used as integers, such as converting to int, indexing a list, and using in range. ```python >>> int(Shape.circle) 1 >>> ['a', 'b', 'c'][Shape.circle] 'b' >>> [i for i in range(Shape.square)] [0, 1] ``` -------------------------------- ### Detect INF and NAN with isinf and isnan Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/test/ieee754.txt Uses math.isinf and math.isnan to detect infinity and NaN, and shows INF equals -NINF. ```python >>> isinf(INF), isinf(NINF), isnan(NAN) (True, True, True) >>> INF == -NINF True ``` -------------------------------- ### Test FTP server connectivity with telnet Source: https://github.com/aliyun/oss-ftp/blob/master/README.md Telnet command to test if the FTP server is reachable on the default port 2048. ```bash telnet 127.0.0.1 2048 ``` -------------------------------- ### IntEnum comparison with integers and other IntEnums Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/enum/doc/enum.rst Demonstrates that IntEnum members can be compared to integers and to members of other IntEnum types, but not to standard Enum members. ```python >>> from enum import IntEnum >>> class Shape(IntEnum): ... circle = 1 ... square = 2 ... >>> class Request(IntEnum): ... post = 1 ... get = 2 ... >>> Shape == 1 False >>> Shape.circle == 1 True >>> Shape.circle == Request.post True ``` -------------------------------- ### Define equal helper for float comparison Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/test/ieee754.txt Defines an epsilon-based equality helper for floats, as direct == comparison is unreliable. ```python >>> EPS = 1E-15 >>> def equal(x, y): ... """Almost equal helper for floats""" ... return abs(x - y) < EPS ``` -------------------------------- ### pow(0, x) behavior for positive, negative, and NaN exponents Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/test/ieee754.txt pow(0, 0) is 1.0, pow(0, INF) is 0.0, pow(0, -INF) raises ValueError, 0**-1 raises ZeroDivisionError, and pow(0, NAN) returns nan. ```python >>> pow(0, 0) 1.0 >>> pow(0, INF) 0.0 >>> pow(0, -INF) Traceback (most recent call last): ... ValueError: math domain error >>> 0 ** -1 Traceback (most recent call last): ... ZeroDivisionError: 0.0 cannot be raised to a negative power >>> pow(0, NAN) nan ``` -------------------------------- ### Additional modules successfully included on NIWA's T3E Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/README.txt Additional modules that have been successfully included on NIWA's vanilla T3E system, in addition to the minimum set. ```text _codecs, _locale, _socket, _symtable, _testcapi, _weakref array, binascii, cmath, cPickle, crypt, cStringIO, dbm errno, fcntl, grp, math, md5, operator, parser, pcre, pwd regex, rotor, select, struct, strop, syslog, termios time, timing, xreadlines ``` -------------------------------- ### Fix FTP encoding error: export LC_ALL and LANG Source: https://github.com/aliyun/oss-ftp/blob/master/README.md Command to set the locale to UTF-8, resolving the '501 can't decode path' error on Linux when using FileZilla with Chinese encoding. ```bash $ export LC_ALL=en_US.UTF-8; export LANG="en_US.UTF-8"; locale ``` -------------------------------- ### Equality comparisons for enum members Source: https://github.com/aliyun/oss-ftp/blob/master/python27/win32/Lib/site-packages/enum/doc/enum.rst Equality comparisons work as expected for enum members. ```python >>> Color.blue == Color.red False >>> Color.blue != Color.red True >>> Color.blue == Color.blue True ```