diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..4db5d095 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,23 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "nuget" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "weekly" + + # Maintain dependencies for GitHub Actions + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + + # Maintain dependencies for submodules + - package-ecosystem: "gitsubmodule" + directory: "/" + schedule: + interval: "monthly" \ No newline at end of file diff --git a/.github/workflows/CI_build.yml b/.github/workflows/CI_build.yml new file mode 100644 index 00000000..453e08b0 --- /dev/null +++ b/.github/workflows/CI_build.yml @@ -0,0 +1,50 @@ +name: Continuous Integration + +on: [push, pull_request] + +jobs: + build: + + runs-on: windows-latest + strategy: + matrix: + build_configuration: [Release, Debug] + build_platform: [x64, Win32] + + steps: + - name: Checkout repo + uses: actions/checkout@v6 + with: + submodules: 'true' + + - name: Add msbuild to PATH + uses: microsoft/setup-msbuild@v2 + + - name: Setup NuGet.exe + uses: nuget/setup-nuget@v2 + + - name: Restore + working-directory: . + run: nuget restore PythonScript.sln + + - name: MSBuild of solution + working-directory: . + run: msbuild PythonScript.sln /m /verbosity:minimal /p:configuration="${{ matrix.build_configuration }}" /p:platform="${{ matrix.build_platform }}" + + - name: Build docs + if: matrix.build_configuration == 'Release' + working-directory: docs + run: | + python -m pip install --upgrade pip + pip install -U sphinx + .\make.bat html + + - name: Build installer and release zips + if: matrix.build_configuration == 'Release' + working-directory: installer + run: | + $env:PYTHONBUILDDIR_X64='${{ github.workspace }}\packages\python.3.12.10\tools' + $env:PYTHONBUILDDIR='${{ github.workspace }}\packages\pythonx86.3.12.10\tools' + Rename-Item -Path ".\buildPaths.bat.orig" -NewName "buildPaths.bat" + dotnet tool install --global wix + .\buildAll.bat ${{ matrix.build_platform }} diff --git a/.github/workflows/msvc_analysis.yml b/.github/workflows/msvc_analysis.yml new file mode 100644 index 00000000..934be96d --- /dev/null +++ b/.github/workflows/msvc_analysis.yml @@ -0,0 +1,51 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# +# Find more information at: +# https://github.com/microsoft/msvc-code-analysis-action + +name: Microsoft C++ Code Analysis + +on: [push, pull_request] + +jobs: + Analyze: + runs-on: windows-latest + + strategy: + fail-fast: false + + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + submodules: recursive + + - name: Add msbuild to PATH + uses: microsoft/setup-msbuild@v2 + + - name: Setup NuGet.exe + uses: nuget/setup-nuget@v2 + + - name: Restore + working-directory: . + run: nuget restore PythonScript.sln + + - name: Run MSVC Code Analysis + working-directory: . + run: msbuild PythonScript.sln /m /verbosity:minimal /p:configuration="Debug" /p:platform="x64" /p:RunCodeAnalysis=true + + # Upload SARIF file to GitHub Code Scanning Alerts + #- name: Upload SARIF to GitHub + # uses: github/codeql-action/upload-sarif@v1 + # with: + # sarif_file: ${{ steps.run-analysis.outputs.sarif }} + + # Upload SARIF file as an Artifact to download and view + # - name: Upload SARIF as an Artifact + # uses: actions/upload-artifact@v2 + # with: + # name: sarif-file + # path: ${{ steps.run-analysis.outputs.sarif }} diff --git a/.gitignore b/.gitignore index a3e7ea74..f3228bb3 100644 --- a/.gitignore +++ b/.gitignore @@ -17,12 +17,15 @@ *.vcxproj.user *.sdf *.opensdf +*.VC.db BuildLog.htm +packages/ bin/ obj/ Debug/ Release/ PythonDebug/ +x64/ ipch/ *.pyc _ReSharper.*/ @@ -35,4 +38,5 @@ Release_Archive/ installer/build/ installer/temp/ Thumbs.db -installer/buildPaths.bat \ No newline at end of file +installer/buildPaths.bat +.vs/ \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..cd1791a7 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "PythonScript.Tests/gtest"] + path = PythonScript.Tests/gtest + url = https://github.com/google/googletest.git diff --git a/NppPlugin/include/Common.h b/NppPlugin/include/Common.h index ec2604dc..782ec971 100644 --- a/NppPlugin/include/Common.h +++ b/NppPlugin/include/Common.h @@ -1,138 +1,342 @@ -//this file is part of notepad++ -//Copyright (C)2003 Don HO ( donho@altern.org ) -// -//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 file is part of Notepad++ project +// Copyright (C)2021 Don HO + +// 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 3 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. +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. - -#ifndef M30_IDE_COMMUN_H -#define M30_IDE_COMMUN_H +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . -#include -#include +#pragma once #include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -#ifdef UNICODE -#include -#endif +#pragma deprecated(PathFileExists) // Use doesFileExist, doesDirectoryExist or doesPathExist (for file or directory) instead. +#pragma deprecated(PathIsDirectory) // Use doesDirectoryExist instead. + + +const bool dirUp = true; +const bool dirDown = false; + +#define NPP_CP_WIN_1252 1252 +#define NPP_CP_DOS_437 437 +#define NPP_CP_BIG5 950 -#define CP_ANSI_LATIN_1 1252 -#define CP_BIG5 950 - -#ifdef UNICODE - #define NppMainEntry wWinMain - #define generic_strtol wcstol - #define generic_strncpy wcsncpy - #define generic_stricmp wcsicmp - #define generic_strncmp wcsncmp - #define generic_strnicmp wcsnicmp - #define generic_strncat wcsncat - #define generic_strchr wcschr - #define generic_atoi _wtoi - #define generic_itoa _itow - #define generic_atof _wtof - #define generic_strtok wcstok - #define generic_strftime wcsftime - #define generic_fprintf fwprintf - #define generic_sscanf swscanf - #define generic_fopen _wfopen - #define generic_fgets fgetws - #define generic_stat _wstat - #define generic_string wstring - #define COPYDATA_FILENAMES COPYDATA_FILENAMESW +#define LINKTRIGGERED WM_USER+555 + +#define BCKGRD_COLOR (RGB(255,102,102)) +#define TXT_COLOR (RGB(255,255,255)) + +#ifndef __MINGW32__ +#define WCSTOK wcstok #else - #define NppMainEntry WinMain - #define generic_strtol strtol - #define generic_strncpy strncpy - #define generic_stricmp stricmp - #define generic_strncmp strncmp - #define generic_strnicmp strnicmp - #define generic_strncat strncat - #define generic_strchr strchr - #define generic_atoi atoi - #define generic_itoa itoa - #define generic_atof atof - #define generic_strtok strtok - #define generic_strftime strftime - #define generic_fprintf fprintf - #define generic_sscanf sscanf - #define generic_fopen fopen - #define generic_fgets fgets - #define generic_stat _stat - #define generic_string string - #define COPYDATA_FILENAMES COPYDATA_FILENAMESA +#define WCSTOK wcstok_s #endif -void folderBrowser(HWND parent, int outputCtrlID, const TCHAR *defaultStr = NULL); -// Set a call back with the handle after init to set the path. -// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/callbackfunctions/browsecallbackproc.asp -static int __stdcall BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM, LPARAM pData) -{ - if (uMsg == BFFM_INITIALIZED) - ::SendMessage(hwnd, BFFM_SETSELECTION, TRUE, pData); - return 0; -}; +#define NPP_INTERNAL_FUNCTION_STR L"Notepad++::InternalFunction" + + +std::wstring folderBrowser(HWND parent, const std::wstring & title = L"", int outputCtrlID = 0, const wchar_t *defaultStr = NULL); +std::wstring getFolderName(HWND parent, const wchar_t *defaultDir = NULL); -void systemMessage(const TCHAR *title); -//DWORD ShortToLongPathName(LPCTSTR lpszShortPath, LPTSTR lpszLongPath, DWORD cchBuffer); void printInt(int int2print); -void printStr(const TCHAR *str2print); +void printStr(const wchar_t *str2print); +std::wstring commafyInt(size_t n); -void writeLog(const TCHAR *logFileName, const char *log2write); +void writeLog(const wchar_t* logFileName, const char* log2write); +void writeLog(const wchar_t* logFileName, const wchar_t* log2write); int filter(unsigned int code, struct _EXCEPTION_POINTERS *ep); -int getCpFromStringValue(const char * encodingStr); -std::generic_string purgeMenuItemString(const TCHAR * menuItemStr, bool keepAmpersand = false); -std::vector tokenizeString(const std::generic_string & tokenString, const char delim); +std::wstring purgeMenuItemString(const wchar_t* menuItemStr, bool keepAmpersand = false); +std::vector tokenizeString(const std::wstring & tokenString, const char delim); void ClientRectToScreenRect(HWND hWnd, RECT* rect); void ScreenRectToClientRect(HWND hWnd, RECT* rect); std::wstring string2wstring(const std::string & rString, UINT codepage); std::string wstring2string(const std::wstring & rwString, UINT codepage); +bool isInList(const wchar_t *token, const wchar_t *list); +std::wstring BuildMenuFileName(int filenameLen, unsigned int pos, const std::wstring &filename, bool ordinalNumber = true); -TCHAR *BuildMenuFileName(TCHAR *buffer, int len, int pos, const TCHAR *filename); +std::string getFileContent(const wchar_t *file2read); +std::wstring relativeFilePathToFullFilePath(const wchar_t *relativeFilePath); +void writeFileContent(const wchar_t *file2write, const char *content2write); +bool matchInList(const wchar_t *fileName, const std::vector & patterns); +bool matchInExcludeDirList(const wchar_t* dirName, const std::vector& patterns, size_t level); +bool allPatternsAreExclusion(const std::vector& patterns); -class WcharMbcsConvertor { +class WcharMbcsConvertor final +{ public: - static WcharMbcsConvertor * getInstance() {return _pSelf;}; - static void destroyInstance() {delete _pSelf;}; + static WcharMbcsConvertor& getInstance() { + static WcharMbcsConvertor instance; + return instance; + } + + const wchar_t* char2wchar(const char* mbStr, size_t codepage, int lenMbcs = -1, int* pLenOut = NULL, int* pBytesNotProcessed = NULL); + const wchar_t* char2wchar(const char* mbcs2Convert, size_t codepage, intptr_t* mstart, intptr_t* mend, int len = 0); + size_t getSizeW() { return _wideCharStr.size(); }; + const char* wchar2char(const wchar_t* wcStr, size_t codepage, int lenIn = -1, int* pLenOut = NULL); + const char* wchar2char(const wchar_t* wcStr, size_t codepage, intptr_t* mstart, intptr_t* mend, int lenIn = 0, int* lenOut = nullptr); + size_t getSizeA() { return _multiByteStr.size(); }; - const wchar_t * char2wchar(const char* mbStr, UINT codepage); - const wchar_t * char2wchar(const char * mbcs2Convert, UINT codepage, int *mstart, int *mend); - const char * wchar2char(const wchar_t* wcStr, UINT codepage); - const char * wchar2char(const wchar_t * wcStr, UINT codepage, long *mstart, long *mend); + const char* encode(UINT fromCodepage, UINT toCodepage, const char* txt2Encode, int lenIn = -1, int* pLenOut = NULL, int* pBytesNotProcessed = NULL) { + int lenWc = 0; + const wchar_t* strW = char2wchar(txt2Encode, fromCodepage, lenIn, &lenWc, pBytesNotProcessed); + return wchar2char(strW, toCodepage, lenWc, pLenOut); + } protected: - WcharMbcsConvertor() : _multiByteStr(NULL), _wideCharStr(NULL), _multiByteAllocLen(0), _wideCharAllocLen(0), initSize(1024) { + WcharMbcsConvertor() = default; + ~WcharMbcsConvertor() = default; + + // Since there's no public ctor, we need to void the default assignment operator and copy ctor. + // Since these are marked as deleted does not matter under which access specifier are kept + WcharMbcsConvertor(const WcharMbcsConvertor&) = delete; + WcharMbcsConvertor& operator= (const WcharMbcsConvertor&) = delete; + + // No move ctor and assignment + WcharMbcsConvertor(WcharMbcsConvertor&&) = delete; + WcharMbcsConvertor& operator= (WcharMbcsConvertor&&) = delete; + + template class StringBuffer final + { + public: + ~StringBuffer() { if (_allocLen) delete[] _str; } + + void sizeTo(size_t size) { + if (_allocLen < size + 1) + { + if (_allocLen) + delete[] _str; + _allocLen = std::max(size + 1, initSize); + _str = new T[_allocLen]{}; + } + _dataLen = size; + } + + void empty() { + static T nullStr = 0; // routines may return an empty string, with null terminator, without allocating memory; a pointer to this null character will be returned in that case + if (_allocLen == 0) + _str = &nullStr; + else + _str[0] = 0; + _dataLen = 0; + } + + size_t size() const { return _dataLen; } + operator T* () { return _str; } + operator const T* () const { return _str; } + + protected: + static const int initSize = 1024; + size_t _allocLen = 0; + size_t _dataLen = 0; + T* _str = nullptr; + }; + + StringBuffer _multiByteStr; + StringBuffer _wideCharStr; +}; + +#define REBARBAND_SIZE sizeof(REBARBANDINFO) + +std::wstring pathRemoveFileSpec(std::wstring & path); +std::wstring pathAppend(std::wstring &strDest, const std::wstring & str2append); +COLORREF getCtrlBgColor(HWND hWnd); +std::wstring stringToUpper(std::wstring strToConvert); +std::wstring stringToLower(std::wstring strToConvert); +std::wstring stringReplace(std::wstring subject, const std::wstring& search, const std::wstring& replace); +void stringSplit(const std::wstring& input, const std::wstring& delimiter, std::vector& output); +bool str2numberVector(std::wstring str2convert, std::vector& numVect); +void stringJoin(const std::vector& strings, const std::wstring& separator, std::wstring& joinedString); +std::wstring stringTakeWhileAdmissable(const std::wstring& input, const std::wstring& admissable); +double stodLocale(const std::wstring& str, _locale_t loc, size_t* idx = NULL); + +bool str2Clipboard(const std::wstring &str2cpy, HWND hwnd); +std::wstring strFromClipboard(); +class Buffer; +bool buf2Clipboard(const std::vector& buffers, bool isFullPath, HWND hwnd); + +std::wstring GetLastErrorAsString(DWORD errorCode = 0); + +std::wstring intToString(int val); +std::wstring uintToString(unsigned int val); + +HWND CreateToolTip(int toolID, HWND hDlg, HINSTANCE hInst, const PTSTR pszText, bool isRTL); +HWND CreateToolTipRect(int toolID, HWND hWnd, HINSTANCE hInst, const PTSTR pszText, const RECT rc); + +bool isCertificateValidated(const std::wstring & fullFilePath, const std::wstring & subjectName2check); +bool isAssoCommandExisting(LPCTSTR FullPathName); + +bool deleteFileOrFolder(const std::wstring& f2delete); + +void getFilesInFolder(std::vector& files, const std::wstring& extTypeFilter, const std::wstring& inFolder); + +template size_t vecRemoveDuplicates(std::vector& vec, bool isSorted = false, bool canSort = false) +{ + if (!isSorted && canSort) + { + std::sort(vec.begin(), vec.end()); + isSorted = true; + } + + if (isSorted) + { + typename std::vector::iterator it; + it = std::unique(vec.begin(), vec.end()); + vec.resize(distance(vec.begin(), it)); // unique() does not shrink the vector + } + else + { + std::unordered_set seen; + auto newEnd = std::remove_if(vec.begin(), vec.end(), [&seen](const T& value) + { + return !seen.insert(value).second; + }); + vec.erase(newEnd, vec.end()); + } + return vec.size(); +} + +void trim(std::wstring& str); + +int nbDigitsFromNbLines(size_t nbLines); + +std::wstring getDateTimeStrFrom(const std::wstring& dateTimeFormat, const SYSTEMTIME& st); + +HFONT createFont(const wchar_t* fontName, int fontSize, bool isBold, HWND hDestParent); +bool removeReadOnlyFlagFromFileAttributes(const wchar_t* fileFullPath); +bool toggleReadOnlyFlagFromFileAttributes(const wchar_t* fileFullPath, bool& isChangedToReadOnly); + +bool isWin32NamespacePrefixedFileName(const std::wstring& fileName); +bool isWin32NamespacePrefixedFileName(const wchar_t* szFileName); +bool isUnsupportedFileName(const std::wstring& fileName); +bool isUnsupportedFileName(const wchar_t* szFileName); + +class Version final +{ +public: + Version() = default; + Version(const std::wstring& versionStr); + + void setVersionFrom(const std::wstring& filePath); + std::wstring toString(); + bool isNumber(const std::wstring& s) const { + return !s.empty() && + find_if(s.begin(), s.end(), [](wchar_t c) { return !_istdigit(c); }) == s.end(); + }; + + int compareTo(const Version& v2c) const; + + bool operator < (const Version& v2c) const { + return compareTo(v2c) == -1; + }; + + bool operator <= (const Version& v2c) const { + int r = compareTo(v2c); + return r == -1 || r == 0; + }; + + bool operator > (const Version& v2c) const { + return compareTo(v2c) == 1; + }; + + bool operator >= (const Version& v2c) const { + int r = compareTo(v2c); + return r == 1 || r == 0; + }; + + bool operator == (const Version& v2c) const { + return compareTo(v2c) == 0; + }; + + bool operator != (const Version& v2c) const { + return compareTo(v2c) != 0; }; - ~WcharMbcsConvertor() { - if (_multiByteStr) - delete [] _multiByteStr; - if (_wideCharStr) - delete [] _wideCharStr; + + bool empty() const { + return _major == 0 && _minor == 0 && _patch == 0 && _build == 0; + } + + bool isCompatibleTo(const Version& from, const Version& to) const; + +private: + unsigned long _major = 0; + unsigned long _minor = 0; + unsigned long _patch = 0; + unsigned long _build = 0; +}; + + +BOOL getDiskFreeSpaceWithTimeout(const wchar_t* dirPath, ULARGE_INTEGER* freeBytesForUser, + DWORD milliSec2wait = 0, bool* isTimeoutReached = nullptr); +BOOL getFileAttributesExWithTimeout(const wchar_t* filePath, WIN32_FILE_ATTRIBUTE_DATA* fileAttr, + DWORD milliSec2wait = 0, bool* isTimeoutReached = nullptr, DWORD* pdwWin32ApiError = nullptr); + +bool doesFileExist(const wchar_t* filePath, DWORD milliSec2wait = 0, bool* isTimeoutReached = nullptr); +bool doesDirectoryExist(const wchar_t* dirPath, DWORD milliSec2wait = 0, bool* isTimeoutReached = nullptr); +bool doesPathExist(const wchar_t* path, DWORD milliSec2wait = 0, bool* isTimeoutReached = nullptr); + + +// check if the window rectangle intersects with any currently active monitor's working area +bool isWindowVisibleOnAnyMonitor(const RECT& rectWndIn); + +bool isCoreWindows(); + + +#define IDT_HIDE_TOOLTIP 1001 + +class ControlInfoTip final +{ +public: + ControlInfoTip() {}; + ~ControlInfoTip() { + if (_hWndInfoTip) { + hide(); + } + }; + bool init(HINSTANCE hInst, HWND ctrl2attached, HWND ctrl2attachedParent, const std::wstring& tipStr, bool isRTL, unsigned int remainTimeMillisecond = 0, int maxWidth = 200); // remainTimeMillisecond = 0: no timeout + + bool isValid() const { + return _hWndInfoTip != nullptr; + }; + + HWND getTipHandle() const { + return _hWndInfoTip; }; - static WcharMbcsConvertor * _pSelf; - const int initSize; - char *_multiByteStr; - size_t _multiByteAllocLen; - wchar_t *_wideCharStr; - size_t _wideCharAllocLen; + enum showPosition {beginning, middle, end}; + void show(showPosition pos = middle) const; + void hide(); + +private: + HWND _hWndInfoTip = nullptr; + TOOLINFO _toolInfo = {}; + + ControlInfoTip(const ControlInfoTip&) = delete; + ControlInfoTip& operator=(const ControlInfoTip&) = delete; }; -#endif //M30_IDE_COMMUN_H +#define NPP_UAC_SAVE_SIGN L"#UAC-SAVE#" +#define NPP_UAC_SETFILEATTRIBUTES_SIGN L"#UAC-SETFILEATTRIBUTES#" +#define NPP_UAC_MOVEFILE_SIGN L"#UAC-MOVEFILE#" +#define NPP_UAC_CREATEEMPTYFILE_SIGN L"#UAC-CREATEEMPTYFILE#" +DWORD invokeNppUacOp(std::wstring& strCmdLineParams); diff --git a/NppPlugin/include/Docking.h b/NppPlugin/include/Docking.h index 7af615d4..ad65f812 100644 --- a/NppPlugin/include/Docking.h +++ b/NppPlugin/include/Docking.h @@ -1,24 +1,23 @@ -/* -this file is part of Function List Plugin for Notepad++ -Copyright (C)2005 Jens Lorenz +// This file is part of Notepad++ project +// Copyright (C)2025 Don HO -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 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 3 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, see . -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., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ +#pragma once -#ifndef DOCKING_H -#define DOCKING_H +#include // ATTENTION : It's a part of interface header, so don't include the others header here @@ -37,6 +36,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #define DWS_ICONTAB 0x00000001 // Icon for tabs are available #define DWS_ICONBAR 0x00000002 // Icon for icon bar are available (currently not supported) #define DWS_ADDINFO 0x00000004 // Additional information are in use +#define DWS_USEOWNDARKMODE 0x00000008 // Use plugin's own dark mode #define DWS_PARAMSALL (DWS_ICONTAB|DWS_ICONBAR|DWS_ADDINFO) // default docking values for first call of plugin @@ -47,33 +47,29 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #define DWS_DF_FLOATING 0x80000000 // default state is floating -struct tTbData -{ - HWND hClient; // client Window Handle - TCHAR *pszName; // name of plugin (shown in window) - int dlgID; // a funcItem provides the function pointer to start a dialog. Please parse here these ID +struct tTbData { + HWND hClient = nullptr; // client Window Handle + const wchar_t* pszName = nullptr; // name of plugin (shown in window) + int dlgID = 0; // a funcItem provides the function pointer to start a dialog. Please parse here these ID // user modifications - UINT uMask; // mask params: look to above defines - HICON hIconTab; // icon for tabs - TCHAR *pszAddInfo; // for plugin to display additional informations + UINT uMask = 0; // mask params: look to above defines + HICON hIconTab = nullptr; // icon for tabs + const wchar_t* pszAddInfo = nullptr; // for plugin to display additional information // internal data, do not use !!! - RECT rcFloat; // floating position - int iPrevCont; // stores the privious container (toggling between float and dock) - const TCHAR* pszModuleName; // it's the plugin file name. It's used to identify the plugin + RECT rcFloat = {}; // floating position + int iPrevCont = 0; // stores the privious container (toggling between float and dock) + const wchar_t* pszModuleName = nullptr; // it's the plugin file name. It's used to identify the plugin }; -struct tDockMgr -{ - HWND hWnd; // the docking manager wnd - RECT rcRegion[DOCKCONT_MAX]; // position of docked dialogs -} ; +struct tDockMgr { + HWND hWnd = nullptr; // the docking manager wnd + RECT rcRegion[DOCKCONT_MAX] = {{}}; // position of docked dialogs +}; #define HIT_TEST_THICKNESS 20 #define SPLITTER_WIDTH 4 - -#endif // DOCKING_H diff --git a/NppPlugin/include/DockingDlgInterface.h b/NppPlugin/include/DockingDlgInterface.h index 47e23526..e2b47cb7 100644 --- a/NppPlugin/include/DockingDlgInterface.h +++ b/NppPlugin/include/DockingDlgInterface.h @@ -1,54 +1,153 @@ -/* -this file is part of Function List Plugin for Notepad++ -Copyright (C)2005 Jens Lorenz +// This file is part of Notepad++ project +// Copyright (C)2006 Jens Lorenz -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 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 3 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, see . -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., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ +#pragma once -#ifndef DOCKINGDLGINTERFACE_H -#define DOCKINGDLGINTERFACE_H +#include "dockingResource.h" +#include "Docking.h" -#ifndef STATIC_DIALOG_H +#include +#include +#include +#include "Common.h" #include "StaticDialog.h" -#endif +#include "NppDarkMode.h" + -struct tTbData; class DockingDlgInterface : public StaticDialog { public: - DockingDlgInterface(); - DockingDlgInterface(int dlgID); - - virtual void init(HINSTANCE hInst, HWND parent); - void create(tTbData * data, bool isRTL = false); - virtual void updateDockingDlg(); - virtual void display(bool toShow = true) const; - const TCHAR * getPluginFileName() const; + DockingDlgInterface() = default; + explicit DockingDlgInterface(int dlgID): _dlgID(dlgID) {} + + void init(HINSTANCE hInst, HWND parent) override { + StaticDialog::init(hInst, parent); + wchar_t temp[MAX_PATH]; + ::GetModuleFileName(hInst, temp, MAX_PATH); + _moduleName = ::PathFindFileName(temp); + } + + virtual void create(tTbData* data, bool isRTL = false) { + assert(data != nullptr); + StaticDialog::create(_dlgID, isRTL); + wchar_t temp[MAX_PATH]; + ::GetWindowText(_hSelf, temp, MAX_PATH); + _pluginName = temp; + + // user information + data->hClient = _hSelf; + data->pszName = _pluginName.c_str(); + + // supported features by plugin + data->uMask = 0; + + // additional info + data->pszAddInfo = nullptr; + } + + virtual void create(tTbData* data, std::array iconIDs, bool isRTL = false) { + create(data, isRTL); + _iconIDs = iconIDs; + } + + virtual void updateDockingDlg() { + ::SendMessage(_hParent, NPPM_DMMUPDATEDISPINFO, 0, reinterpret_cast(_hSelf)); + } + + virtual void setBackgroundColor(COLORREF) {} + virtual void setForegroundColor(COLORREF) {} + + void display(bool toShow = true) const override { + ::SendMessage(_hParent, toShow ? NPPM_DMMSHOW : NPPM_DMMHIDE, 0, reinterpret_cast(_hSelf)); + } + + bool isClosed() const { + return _isClosed; + } + + void setClosed(bool toClose) { + _isClosed = toClose; + } + + const wchar_t * getPluginFileName() const { + return _moduleName.c_str(); + } + + const std::array& getIconIDs() const { + return _iconIDs; + } protected : - virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM, LPARAM lParam); - - // Handles - HWND _HSource; - tTbData* _data; - int _dlgID; - bool _isFloating; - int _iDockedPos; - tstring _moduleName; - tstring _pluginName; -}; + int _dlgID = -1; + int _iDockedPos = 0; + std::wstring _moduleName; + std::wstring _pluginName; + std::array _iconIDs{}; + bool _isFloating = true; + bool _isClosed = false; + + intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) override { + switch (message) + { + case WM_ERASEBKGND: + { + if (!NppDarkMode::isEnabled()) + { + break; + } -#endif // DOCKINGDLGINTERFACE_H + RECT rc{}; + getClientRect(rc); + ::FillRect(reinterpret_cast(wParam), &rc, NppDarkMode::getDlgBackgroundBrush()); + return TRUE; + } + case WM_NOTIFY: + { + auto* pnmh = reinterpret_cast(lParam); + + if (pnmh->hwndFrom == _hParent) + { + switch (LOWORD(pnmh->code)) + { + case DMN_CLOSE: + { + break; + } + case DMN_FLOAT: + { + _isFloating = true; + break; + } + case DMN_DOCK: + { + _iDockedPos = HIWORD(pnmh->code); + _isFloating = false; + break; + } + default: + break; + } + } + break; + } + default: + break; + } + return FALSE; + }; +}; diff --git a/NppPlugin/include/Notepad_plus_msgs.h b/NppPlugin/include/Notepad_plus_msgs.h index 312971ba..03e1cbff 100644 --- a/NppPlugin/include/Notepad_plus_msgs.h +++ b/NppPlugin/include/Notepad_plus_msgs.h @@ -1,338 +1,1060 @@ -//this file is part of notepad++ -//Copyright (C)2003 Don HO ( donho@altern.org ) -// -//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 file is part of Notepad++ project +// Copyright (C)2025 Don HO + +// 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 3 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. +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + + -#ifndef NOTEPAD_PLUS_MSGS_H -#define NOTEPAD_PLUS_MSGS_H +// For more comprehensive information on plugin communication, please refer to the following resource: +// https://npp-user-manual.org/docs/plugin-communication/ -//#include "menuCmdID.h" -enum LangType {L_TXT, L_PHP , L_C, L_CPP, L_CS, L_OBJC, L_JAVA, L_RC,\ - L_HTML, L_XML, L_MAKEFILE, L_PASCAL, L_BATCH, L_INI, L_NFO, L_USER,\ - L_ASP, L_SQL, L_VB, L_JS, L_CSS, L_PERL, L_PYTHON, L_LUA,\ +#pragma once + +#include + +enum LangType {L_TEXT, L_PHP , L_C, L_CPP, L_CS, L_OBJC, L_JAVA, L_RC,\ + L_HTML, L_XML, L_MAKEFILE, L_PASCAL, L_BATCH, L_INI, L_ASCII, L_USER,\ + L_ASP, L_SQL, L_VB, L_JS_EMBEDDED, L_CSS, L_PERL, L_PYTHON, L_LUA, \ L_TEX, L_FORTRAN, L_BASH, L_FLASH, L_NSIS, L_TCL, L_LISP, L_SCHEME,\ L_ASM, L_DIFF, L_PROPS, L_PS, L_RUBY, L_SMALLTALK, L_VHDL, L_KIX, L_AU3,\ L_CAML, L_ADA, L_VERILOG, L_MATLAB, L_HASKELL, L_INNO, L_SEARCHRESULT,\ - L_CMAKE, L_YAML,\ - // The end of enumated language type, so it should be always at the end + L_CMAKE, L_YAML, L_COBOL, L_GUI4CLI, L_D, L_POWERSHELL, L_R, L_JSP,\ + L_COFFEESCRIPT, L_JSON, L_JAVASCRIPT, L_FORTRAN_77, L_BAANC, L_SREC,\ + L_IHEX, L_TEHEX, L_SWIFT,\ + L_ASN1, L_AVS, L_BLITZBASIC, L_PUREBASIC, L_FREEBASIC, \ + L_CSOUND, L_ERLANG, L_ESCRIPT, L_FORTH, L_LATEX, \ + L_MMIXAL, L_NIM, L_NNCRONTAB, L_OSCRIPT, L_REBOL, \ + L_REGISTRY, L_RUST, L_SPICE, L_TXT2TAGS, L_VISUALPROLOG,\ + L_TYPESCRIPT, L_JSON5, L_MSSQL, L_GDSCRIPT, L_HOLLYWOOD,\ + L_GOLANG, L_RAKU, L_TOML, L_SAS, L_ERRORLIST, \ + // Don't use L_JS_EMBEDDED, use L_JAVASCRIPT instead + // The end of enumerated language type, so it should be always at the end L_EXTERNAL}; -enum winVer{WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV_S2003, WV_XPX64, WV_VISTA}; +enum class ExternalLexerAutoIndentMode { Standard, C_Like, Custom }; +enum class MacroStatus { Idle, RecordInProgress, RecordingStopped, PlayingBack }; +enum winVer { WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV_S2003, WV_XPX64, WV_VISTA, WV_WIN7, WV_WIN8, WV_WIN81, WV_WIN10, WV_WIN11 }; +enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64, PF_ARM64 }; -//#include "deprecatedSymbols.h" -//Here you can find how to use these messages : http://notepad-plus.sourceforge.net/uk/plugins-HOWTO.php -#define NPPMSG (WM_USER + 1000) - - #define NPPM_GETCURRENTSCINTILLA (NPPMSG + 4) - #define NPPM_GETCURRENTLANGTYPE (NPPMSG + 5) - #define NPPM_SETCURRENTLANGTYPE (NPPMSG + 6) - - #define NPPM_GETNBOPENFILES (NPPMSG + 7) - #define ALL_OPEN_FILES 0 - #define PRIMARY_VIEW 1 - #define SECOND_VIEW 2 - - #define NPPM_GETOPENFILENAMES (NPPMSG + 8) +#define NPPMSG (WM_USER + 1000) - #define NPPM_MODELESSDIALOG (NPPMSG + 12) - #define MODELESSDIALOGADD 0 - #define MODELESSDIALOGREMOVE 1 + #define NPPM_GETCURRENTSCINTILLA (NPPMSG + 4) + // BOOL NPPM_GETCURRENTSCINTILLA(0, int* iScintillaView) + // Get current Scintilla view. + // wParam: 0 (not used) + // lParam[out]: iScintillaView could be 0 (Main View) or 1 (Sub View) + // return TRUE + + #define NPPM_GETCURRENTLANGTYPE (NPPMSG + 5) + // BOOL NPPM_GETCURRENTLANGTYPE(0, int* langType) + // Get the programming language type from the current used document. + // wParam: 0 (not used) + // lParam[out]: langType - see "enum LangType" for all valid values + // return TRUE + + #define NPPM_SETCURRENTLANGTYPE (NPPMSG + 6) + // BOOL NPPM_SETCURRENTLANGTYPE(0, int langType) + // Set a new programming language type to the current used document. + // wParam: 0 (not used) + // lParam[in]: langType - see "enum LangType" for all valid values + // return TRUE + + #define NPPM_GETNBOPENFILES (NPPMSG + 7) + #define ALL_OPEN_FILES 0 + #define PRIMARY_VIEW 1 + #define SECOND_VIEW 2 + // int NPPM_GETNBOPENFILES(0, int iViewType) + // Get the number of files currently open. + // wParam: 0 (not used) + // lParam[in]: iViewType - could be PRIMARY_VIEW (value 1), SECOND_VIEW (value 2) or ALL_OPEN_FILES (value 0) + // return the number of opened files + + #define NPPM_GETOPENFILENAMES_DEPRECATED (NPPMSG + 8) + // BOOL NPPM_GETOPENFILENAMES_DEPRECATED(wchar_t** fileNames, int nbFileNames) - DEPRECATED: It is kept for the compatibility. Use NPPM_GETBUFFERIDFROMPOS & NPPM_GETFULLPATHFROMBUFFERID instead. + // Get the open files full paths of both views. User is responsible to allocate a big enough fileNames array by using NPPM_GETNBOPENFILES. + // wParam[out]: fileNames - array of file path + // lParam[in]: nbFileNames is the number of file path. + // return value: The number of files copied into fileNames array + + #define NPPM_MODELESSDIALOG (NPPMSG + 12) + #define MODELESSDIALOGADD 0 + #define MODELESSDIALOGREMOVE 1 + // HWND NPPM_MODELESSDIALOG(int action, HWND hDlg) + // Register (or unregister) plugin's dialog handle. + // For each created dialog in your plugin, you should register it (and unregister while destroy it) to Notepad++ by using this message. + // If this message is ignored, then your dialog won't react with the key stroke messages such as TAB, Ctrl-C or Ctrl-V key. + // For the good functioning of your plugin dialog, you're recommended to not ignore this message. + // wParam[in]: action is MODELESSDIALOGADD (for registering your hDlg) or MODELESSDIALOGREMOVE (for unregistering your hDlg) + // lParam[in]: hDlg is the handle of dialog to register/unregister + // return hDlg (HWND) on success, NULL on failure #define NPPM_GETNBSESSIONFILES (NPPMSG + 13) + // int NPPM_GETNBSESSIONFILES (BOOL* pbIsValidXML, wchar_t* sessionFileName) + // Get the number of files to load in the session sessionFileName. sessionFileName should be a full path name of an xml file. + // wParam[out]: pbIsValidXML, if the lParam pointer is null, then this parameter will be ignored. TRUE if XML is valid, otherwise FALSE. + // lParam[in]: sessionFileName is XML session full path + // return value: The number of files in XML session file + #define NPPM_GETSESSIONFILES (NPPMSG + 14) - #define NPPM_SAVESESSION (NPPMSG + 15) - #define NPPM_SAVECURRENTSESSION (NPPMSG + 16) + // BOOL NPPM_GETSESSIONFILES (wchar_t** sessionFileArray, wchar_t* sessionFileName) + // the files' full path name from a session file. + // wParam[out]: sessionFileArray is the array in which the files' full path of the same group are written. To allocate the array with the proper size, send message NPPM_GETNBSESSIONFILES. + // lParam[in]: sessionFileName is XML session full path + // Return FALSE on failure, TRUE on success + #define NPPM_SAVESESSION (NPPMSG + 15) struct sessionInfo { - TCHAR* sessionFilePathName; - int nbFile; - TCHAR** files; + wchar_t* sessionFilePathName; // Full session file path name to be saved + int nbFile; // Size of "files" array - number of files to be saved in session + wchar_t** files; // Array of file name (full path) to be saved in session }; + // NPPM_SAVESESSION(0, sessionInfo* si) + // Creates an session file for a defined set of files. + // Contrary to NPPM_SAVECURRENTSESSION (see below), which saves the current opened files, this call can be used to freely define any file which should be part of a session. + // wParam: 0 (not used) + // lParam[in]: si is a pointer to sessionInfo structure + // Returns sessionFileName on success, NULL otherwise + + #define NPPM_SAVECURRENTSESSION (NPPMSG + 16) + // wchar_t* NPPM_SAVECURRENTSESSION(0, wchar_t* sessionFileName) + // Saves the current opened files in Notepad++ as a group of files (session) as an xml file. + // wParam: 0 (not used) + // lParam[in]: sessionFileName is the xml full path name + // Returns sessionFileName on success, NULL otherwise + + + #define NPPM_GETOPENFILENAMESPRIMARY_DEPRECATED (NPPMSG + 17) + // BOOL NPPM_GETOPENFILENAMESPRIMARY_DEPRECATED(wchar_t** fileNames, int nbFileNames) - DEPRECATED: It is kept for the compatibility. Use NPPM_GETBUFFERIDFROMPOS & NPPM_GETFULLPATHFROMBUFFERID instead. + // Get the open files full paths of main view. User is responsible to allocate an big enough fileNames array by using NPPM_GETNBOPENFILES. + // wParam[out]: fileNames - array of file path + // lParam[in]: nbFileNames is the number of file path. + // return value: The number of files copied into fileNames array + + #define NPPM_GETOPENFILENAMESSECOND_DEPRECATED (NPPMSG + 18) + // BOOL NPPM_GETOPENFILENAMESSECOND_DEPRECATED(wchar_t** fileNames, int nbFileNames) - DEPRECATED: It is kept for the compatibility. Use NPPM_GETBUFFERIDFROMPOS & NPPM_GETFULLPATHFROMBUFFERID instead. + // Get the open files full paths of sub-view. User is responsible to allocate an big enough fileNames array by using NPPM_GETNBOPENFILES. + // wParam[out]: fileNames - array of file path + // lParam[in]: nbFileNames is the number of file path. + // return value: The number of files copied into fileNames array - #define NPPM_GETOPENFILENAMESPRIMARY (NPPMSG + 17) - #define NPPM_GETOPENFILENAMESSECOND (NPPMSG + 18) - #define NPPM_CREATESCINTILLAHANDLE (NPPMSG + 20) - #define NPPM_DESTROYSCINTILLAHANDLE (NPPMSG + 21) + // HWND NPPM_CREATESCINTILLAHANDLE(0, HWND hParent) + // A plugin can create a Scintilla for its usage by sending this message to Notepad++. + // wParam: 0 (not used) + // lParam[in]: hParent - If set (non NULL), it will be the parent window of this created Scintilla handle, otherwise the parent window is Notepad++ + // return the handle of created Scintilla handle + + #define NPPM_DESTROYSCINTILLAHANDLE_DEPRECATED (NPPMSG + 21) + // BOOL NPPM_DESTROYSCINTILLAHANDLE_DEPRECATED(0, HWND hScintilla) - DEPRECATED: It is kept for the compatibility. + // Notepad++ will deallocate every created Scintilla control on exit, this message returns TRUE but does nothing. + // wParam: 0 (not used) + // lParam[in]: hScintilla is Scintilla handle + // Return TRUE + #define NPPM_GETNBUSERLANG (NPPMSG + 22) + // int NPPM_GETNBUSERLANG(0, int* udlID) + // Get the number of user defined languages and, optionally, the starting menu id. + // wParam: 0 (not used) + // lParam[out]: udlID is optional, if not used set it to 0, otherwise an integer pointer is needed to retrieve the menu identifier. + // Return the number of user defined languages identified #define NPPM_GETCURRENTDOCINDEX (NPPMSG + 23) #define MAIN_VIEW 0 #define SUB_VIEW 1 + // int NPPM_GETCURRENTDOCINDEX(0, int inView) + // Get the current index of the given view. + // wParam: 0 (not used) + // lParam[in]: inView, should be 0 (main view) or 1 (sub-view) + // Return -1 if the view is invisible (hidden), otherwise is the current index. #define NPPM_SETSTATUSBAR (NPPMSG + 24) - #define STATUSBAR_DOC_TYPE 0 - #define STATUSBAR_DOC_SIZE 1 - #define STATUSBAR_CUR_POS 2 - #define STATUSBAR_EOF_FORMAT 3 + #define STATUSBAR_DOC_TYPE 0 + #define STATUSBAR_DOC_SIZE 1 + #define STATUSBAR_CUR_POS 2 + #define STATUSBAR_EOF_FORMAT 3 #define STATUSBAR_UNICODE_TYPE 4 - #define STATUSBAR_TYPING_MODE 5 + #define STATUSBAR_TYPING_MODE 5 + // BOOL NPPM_SETSTATUSBAR(int whichPart, wchar_t *str2set) + // Set string in the specified field of a statusbar. + // wParam[in]: whichPart for indicating the statusbar part you want to set. It can be only the above value (0 - 5) + // lParam[in]: str2set is the string you want to write to the part of statusbar. + // Return FALSE on failure, TRUE on success #define NPPM_GETMENUHANDLE (NPPMSG + 25) #define NPPPLUGINMENU 0 + #define NPPMAINMENU 1 + // int NPPM_GETMENUHANDLE(int menuChoice, 0) + // Get menu handle (HMENU) of choice. + // wParam[in]: menuChoice could be main menu (NPPMAINMENU) or Plugin menu (NPPPLUGINMENU) + // lParam: 0 (not used) + // Return: menu handle (HMENU) of choice (plugin menu handle or Notepad++ main menu handle) #define NPPM_ENCODESCI (NPPMSG + 26) - //ascii file to unicode - //int NPPM_ENCODESCI(MAIN_VIEW/SUB_VIEW, 0) - //return new unicodeMode - + // int NPPM_ENCODESCI(int inView, 0) + // Changes current buffer in view to UTF-8. + // wParam[in]: inView - main view (0) or sub-view (1) + // lParam: 0 (not used) + // return new UniMode, with the following value: + // 0: ANSI + // 1: UTF-8 with BOM + // 2: UTF-16 Big Ending with BOM + // 3: UTF-16 Little Ending with BOM + // 4: UTF-8 without BOM + // 5: uni7Bit + // 6: UTF-16 Big Ending without BOM + // 7: UTF-16 Little Ending without BOM + #define NPPM_DECODESCI (NPPMSG + 27) - //unicode file to ascii - //int NPPM_DECODESCI(MAIN_VIEW/SUB_VIEW, 0) - //return old unicodeMode + // int NPPM_DECODESCI(int inView, 0) + // Changes current buffer in view to ANSI. + // wParam[in]: inView - main view (0) or sub-view (1) + // lParam: 0 (not used) + // return old UniMode - see above #define NPPM_ACTIVATEDOC (NPPMSG + 28) - //void NPPM_ACTIVATEDOC(int view, int index2Activate) + // BOOL NPPM_ACTIVATEDOC(int inView, int index2Activate) + // Switch to the document by the given view and index. + // wParam[in]: inView - main view (0) or sub-view (1) + // lParam[in]: index2Activate - index (in the view indicated above) where is the document to be activated + // Return TRUE #define NPPM_LAUNCHFINDINFILESDLG (NPPMSG + 29) - //void NPPM_LAUNCHFINDINFILESDLG(TCHAR * dir2Search, TCHAR * filtre) + // BOOL NPPM_LAUNCHFINDINFILESDLG(wchar_t * dir2Search, wchar_t * filtre) + // Launch Find in Files dialog and set "Find in" directory and filters with the given arguments. + // wParam[in]: if dir2Search is not NULL, it will be set as working directory in which Notepad++ will search + // lParam[in]: if filtre is not NULL, filtre string will be set into filter field + // Return TRUE #define NPPM_DMMSHOW (NPPMSG + 30) + // BOOL NPPM_DMMSHOW(0, HWND hDlg) + // Show the dialog which was previously registered by NPPM_DMMREGASDCKDLG. + // wParam: 0 (not used) + // lParam[in]: hDlg is the handle of dialog to show + // Return TRUE + #define NPPM_DMMHIDE (NPPMSG + 31) + // BOOL NPPM_DMMHIDE(0, HWND hDlg) + // Hide the dialog which was previously registered by NPPM_DMMREGASDCKDLG. + // wParam: 0 (not used) + // lParam[in]: hDlg is the handle of dialog to hide + // Return TRUE + #define NPPM_DMMUPDATEDISPINFO (NPPMSG + 32) - //void NPPM_DMMxxx(0, tTbData->hClient) + // BOOL NPPM_DMMUPDATEDISPINFO(0, HWND hDlg) + // Redraw the dialog. + // wParam: 0 (not used) + // lParam[in]: hDlg is the handle of dialog to redraw + // Return TRUE #define NPPM_DMMREGASDCKDLG (NPPMSG + 33) - //void NPPM_DMMREGASDCKDLG(0, &tTbData) + // BOOL NPPM_DMMREGASDCKDLG(0, tTbData* pData) + // Pass the necessary dockingData to Notepad++ in order to make your dialog dockable. + // wParam: 0 (not used) + // lParam[in]: pData is the pointer of tTbData. Please check tTbData structure in "Docking.h" + // Minimum information which needs to be filled out are hClient, pszName, dlgID, uMask and pszModuleName. + // Notice that rcFloat and iPrevCont shouldn't be filled. They are used internally. + // Return TRUE #define NPPM_LOADSESSION (NPPMSG + 34) - //void NPPM_LOADSESSION(0, const TCHAR* file name) + // BOOL NPPM_LOADSESSION(0, wchar_t* sessionFileName) + // Open all files of same session in Notepad++ via a xml format session file sessionFileName. + // wParam: 0 (not used) + // lParam[in]: sessionFileName is the full file path of session file to reload + // Return TRUE #define NPPM_DMMVIEWOTHERTAB (NPPMSG + 35) - //void WM_DMM_VIEWOTHERTAB(0, tTbData->pszName) + // BOOL WM_DMM_VIEWOTHERTAB(0, wchar_t* name) + // Show the plugin dialog (switch to plugin tab) with the given name. + // wParam: 0 (not used) + // lParam[in]: name should be the same value as previously used to register the dialog (pszName of tTbData) + // Return TRUE #define NPPM_RELOADFILE (NPPMSG + 36) - //BOOL NPPM_RELOADFILE(BOOL withAlert, TCHAR *filePathName2Reload) + // BOOL NPPM_RELOADFILE(BOOL withAlert, wchar_t *filePathName2Reload) + // Reload the document which matches with the given filePathName2Reload. + // wParam: 0 (not used) + // lParam[in]: filePathName2Reload is the full file path of document to reload + // Return TRUE if reloading file succeeds, otherwise FALSE #define NPPM_SWITCHTOFILE (NPPMSG + 37) - //BOOL NPPM_SWITCHTOFILE(0, TCHAR *filePathName2switch) + // BOOL NPPM_SWITCHTOFILE(0, wchar_t* filePathName2switch) + // Switch to the document which matches with the given filePathName2switch. + // wParam: 0 (not used) + // lParam[in]: filePathName2switch is the full file path of document to switch + // Return TRUE #define NPPM_SAVECURRENTFILE (NPPMSG + 38) - //BOOL WM_SWITCHTOFILE(0, 0) + // BOOL NPPM_SAVECURRENTFILE(0, 0) + // Save current activated document. + // wParam: 0 (not used) + // lParam: 0 (not used) + // Return TRUE if file is saved, otherwise FALSE (the file doesn't need to be saved, or other reasons). #define NPPM_SAVEALLFILES (NPPMSG + 39) - //BOOL NPPM_SAVEALLFILES(0, 0) + // BOOL NPPM_SAVEALLFILES(0, 0) + // Save all opened document. + // wParam: 0 (not used) + // lParam: 0 (not used) + // Return FALSE when no file needs to be saved, else TRUE if there is at least one file saved. #define NPPM_SETMENUITEMCHECK (NPPMSG + 40) - //void WM_PIMENU_CHECK(UINT funcItem[X]._cmdID, TRUE/FALSE) + // BOOL NPPM_SETMENUITEMCHECK(UINT pluginCmdID, BOOL doCheck) + // Set or remove the check on a item of plugin menu and tool bar (if any). + // wParam[in]: pluginCmdID is the plugin command ID which corresponds to the menu item: funcItem[X]._cmdID + // lParam[in]: if doCheck value is TRUE, item will be checked, FALSE makes item unchecked. + // Return TRUE - #define NPPM_ADDTOOLBARICON (NPPMSG + 41) - //void WM_ADDTOOLBARICON(UINT funcItem[X]._cmdID, toolbarIcons icon) + #define NPPM_ADDTOOLBARICON_DEPRECATED (NPPMSG + 41) struct toolbarIcons { HBITMAP hToolbarBmp; HICON hToolbarIcon; }; + // BOOL NPPM_ADDTOOLBARICON_DEPRECATED(UINT pluginCmdID, toolbarIcons* iconHandles) -- DEPRECATED: use NPPM_ADDTOOLBARICON_FORDARKMODE instead + // Add an icon to the toolbar. + // wParam[in]: pluginCmdID is the plugin command ID which corresponds to the menu item: funcItem[X]._cmdID + // lParam[in]: iconHandles of toolbarIcons structure. 2 formats ".ico" & ".bmp" are needed + // Both handles should be set so the icon will be displayed correctly if toolbar icon sets are changed by users + // Return TRUE + #define NPPM_GETWINDOWSVERSION (NPPMSG + 42) - //winVer NPPM_GETWINDOWSVERSION(0, 0) + // winVer NPPM_GETWINDOWSVERSION(0, 0) + // Get OS (Windows) version. + // wParam: 0 (not used) + // lParam: 0 (not used) + // Return enum winVer, which is defined at the beginning of this file #define NPPM_DMMGETPLUGINHWNDBYNAME (NPPMSG + 43) - //HWND WM_DMM_GETPLUGINHWNDBYNAME(const TCHAR *windowName, const TCHAR *moduleName) - // if moduleName is NULL, then return value is NULL - // if windowName is NULL, then the first found window handle which matches with the moduleName will be returned - - #define NPPM_MAKECURRENTBUFFERDIRTY (NPPMSG + 44) - //BOOL NPPM_MAKECURRENTBUFFERDIRTY(0, 0) + // HWND NPPM_DMMGETPLUGINHWNDBYNAME(const wchar_t *windowName, const wchar_t *moduleName) + // Retrieve the dialog handle corresponds to the windowName and moduleName. You may need this message if you want to communicate with another plugin "dockable" dialog. + // wParam[in]: windowName - if windowName is NULL, then the first found window handle which matches with the moduleName will be returned + // lParam[in] : moduleName - if moduleName is NULL, then return value is NULL + // Return NULL if moduleName is NULL. If windowName is NULL, then the first found window handle which matches with the moduleName will be returned. - #define NPPM_GETENABLETHEMETEXTUREFUNC (NPPMSG + 45) - //BOOL NPPM_GETENABLETHEMETEXTUREFUNC(0, 0) + #define NPPM_MAKECURRENTBUFFERDIRTY (NPPMSG + 44) + // BOOL NPPM_MAKECURRENTBUFFERDIRTY(0, 0) + // Make the current document dirty, aka set the save state to unsaved. + // wParam: 0 (not used) + // lParam: 0 (not used) + // Return TRUE + + #define NPPM_GETENABLETHEMETEXTUREFUNC_DEPRECATED (NPPMSG + 45) + // THEMEAPI NPPM_GETENABLETHEMETEXTUREFUNC(0, 0) -- DEPRECATED: plugin can use EnableThemeDialogTexture directly from uxtheme.h instead + // Get "EnableThemeDialogTexture" function address. + // wParam: 0 (not used) + // lParam: 0 (not used) + // Return a proc address or NULL #define NPPM_GETPLUGINSCONFIGDIR (NPPMSG + 46) - //void NPPM_GETPLUGINSCONFIGDIR(int strLen, TCHAR *str) + // int NPPM_GETPLUGINSCONFIGDIR(int strLen, wchar_t *str) + // Get user's plugin config directory path. It's useful if plugins want to save/load parameters for the current user + // wParam[in]: strLen is length of allocated buffer in which directory path is copied + // lParam[out] : str is the allocated buffere. User should call this message twice - + // The 1st call with "str" be NULL to get the required number of wchar_t (not including the terminating nul character) + // The 2nd call to allocate "str" buffer with the 1st call's return value + 1, then call it again to get the path + // Return value: The 1st call - the number of wchar_t to copy. + // The 2nd call - FALSE on failure, TRUE on success #define NPPM_MSGTOPLUGIN (NPPMSG + 47) - //BOOL NPPM_MSGTOPLUGIN(TCHAR *destModuleName, CommunicationInfo *info) - // return value is TRUE when the message arrive to the destination plugins. - // if destModule or info is NULL, then return value is FALSE struct CommunicationInfo { - long internalMsg; - const TCHAR * srcModuleName; - void * info; // defined by plugin + long internalMsg; // an integer defined by plugin Y, known by plugin X, identifying the message being sent. + const wchar_t * srcModuleName; // the complete module name (with the extension .dll) of caller (plugin X). + void* info; // defined by plugin, the information to be exchanged between X and Y. It's a void pointer so it should be defined by plugin Y and known by plugin X. }; + // BOOL NPPM_MSGTOPLUGIN(wchar_t *destModuleName, CommunicationInfo *info) + // Send a private information to a plugin with given plugin name. This message allows the communication between 2 plugins. + // For example, plugin X can execute a command of plugin Y if plugin X knows the command ID and the file name of plugin Y. + // wParam[in]: destModuleName is the destination complete module file name (with the file extension ".dll") + // lParam[in]: info - See above "CommunicationInfo" structure + // The returned value is TRUE if Notepad++ found the plugin by its module name (destModuleName), and pass the info (communicationInfo) to the module. + // The returned value is FALSE if no plugin with such name is found. #define NPPM_MENUCOMMAND (NPPMSG + 48) - //void NPPM_MENUCOMMAND(0, int cmdID) - // uncomment //#include "menuCmdID.h" - // in the beginning of this file then use the command symbols defined in "menuCmdID.h" file - // to access all the Notepad++ menu command items - + // BOOL NPPM_MENUCOMMAND(0, int cmdID) + // Run Notepad++ command with the given command ID. + // wParam: 0 (not used) + // lParam[in]: cmdID - See "menuCmdID.h" for all the Notepad++ menu command items + // Return TRUE + #define NPPM_TRIGGERTABBARCONTEXTMENU (NPPMSG + 49) - //void NPPM_TRIGGERTABBARCONTEXTMENU(int view, int index2Activate) + // BOOL NPPM_TRIGGERTABBARCONTEXTMENU(int inView, int index2Activate) + // Switch to the document by the given view and index and trigger the context menu + // wParam[in]: inView - main view (0) or sub-view (1) + // lParam[in]: index2Activate - index (in the view indicated above) where is the document to have the context menu + // Return TRUE #define NPPM_GETNPPVERSION (NPPMSG + 50) - // int NPPM_GETNPPVERSION(0, 0) - // return version - // ex : v4.6 - // HIWORD(version) == 4 - // LOWORD(version) == 6 + // int NPPM_GETNPPVERSION(BOOL ADD_ZERO_PADDING, 0) + // Get Notepad++ version. + // wParam[in]: ADD_ZERO_PADDING (see below) + // lParam: 0 (not used) + // return value: + // HIWORD(returned_value) is major part of version: the 1st number + // LOWORD(returned_value) is minor part of version: the 3 last numbers + // + // ADD_ZERO_PADDING == TRUE + // + // version | HIWORD | LOWORD + //------------------------------ + // 8.9.6.4 | 8 | 964 + // 9 | 9 | 0 + // 6.9 | 6 | 900 + // 6.6.6 | 6 | 660 + // 13.6.6.6 | 13 | 666 + // + // + // ADD_ZERO_PADDING == FALSE + // + // version | HIWORD | LOWORD + //------------------------------ + // 8.9.6.4 | 8 | 964 + // 9 | 9 | 0 + // 6.9 | 6 | 9 + // 6.6.6 | 6 | 66 + // 13.6.6.6 | 13 | 666 #define NPPM_HIDETABBAR (NPPMSG + 51) // BOOL NPPM_HIDETABBAR(0, BOOL hideOrNot) - // if hideOrNot is set as TRUE then tab bar will be hidden - // otherwise it'll be shown. - // return value : the old status value + // Hide (or show) tab bar. + // wParam: 0 (not used) + // lParam[in]: if hideOrNot is set as TRUE then tab bar will be hidden, otherwise it'll be shown. + // return value: the old status value #define NPPM_ISTABBARHIDDEN (NPPMSG + 52) // BOOL NPPM_ISTABBARHIDDEN(0, 0) - // returned value : TRUE if tab bar is hidden, otherwise FALSE + // Get tab bar status. + // wParam: 0 (not used) + // lParam: 0 (not used) + // return value: TRUE if tool bar is hidden, otherwise FALSE #define NPPM_GETPOSFROMBUFFERID (NPPMSG + 57) - // INT NPPM_GETPOSFROMBUFFERID(INT bufferID, 0) - // Return VIEW|INDEX from a buffer ID. -1 if the bufferID non existing + // int NPPM_GETPOSFROMBUFFERID(UINT_PTR bufferID, int priorityView) + // Get document position (VIEW and INDEX) from a buffer ID, according priorityView. + // wParam[in]: BufferID of document + // lParam[in]: priorityView is the target VIEW. However, if the given bufferID cannot be found in the target VIEW, the other VIEW will be searched. + // Return -1 if the bufferID non existing, else return value contains VIEW & INDEX: // - // VIEW takes 2 highest bits and INDEX (0 based) takes the rest (30 bits) - // Here's the values for the view : + // VIEW takes 2 highest bits and INDEX (0 based) takes the rest (30 bits) + // Here's the values for the view: // MAIN_VIEW 0 // SUB_VIEW 1 + // + // if priorityView set to SUB_VIEW, then SUB_VIEW will be search firstly #define NPPM_GETFULLPATHFROMBUFFERID (NPPMSG + 58) - // INT NPPM_GETFULLPATHFROMBUFFERID(INT bufferID, TCHAR *fullFilePath) - // Get full path file name from a bufferID. - // Return -1 if the bufferID non existing, otherwise the number of TCHAR copied/to copy - // User should call it with fullFilePath be NULL to get the number of TCHAR (not including the nul character), - // allocate fullFilePath with the return values + 1, then call it again to get full path file name + // int NPPM_GETFULLPATHFROMBUFFERID(UINT_PTR bufferID, wchar_t* fullFilePath) + // Get full path file name from a bufferID (the pointer of buffer). + // wParam[in]: bufferID + // lParam[out]: fullFilePath - User should call it with fullFilePath be NULL to get the number of wchar_t (not including the nul character), + // allocate fullFilePath with the return values + 1, then call it again to get full path file name + // Return -1 if the bufferID non existing, otherwise the number of wchar_t copied/to copy #define NPPM_GETBUFFERIDFROMPOS (NPPMSG + 59) - //wParam: Position of document - //lParam: View to use, 0 = Main, 1 = Secondary - //Returns 0 if invalid + // UINT_PTR NPPM_GETBUFFERIDFROMPOS(int index, int iView) + // Get the document bufferID from the given position (iView & index). + // wParam[in]: Position (0 based) of document + // lParam[in]: Main or sub View in which document is, 0 = Main, 1 = Sub + // Returns NULL if invalid, otherwise bufferID #define NPPM_GETCURRENTBUFFERID (NPPMSG + 60) - //Returns active Buffer + // UINT_PTR NPPM_GETCURRENTBUFFERID(0, 0) + // Get active document BufferID. + // wParam: 0 (not used) + // lParam: 0 (not used) + // Return active document BufferID #define NPPM_RELOADBUFFERID (NPPMSG + 61) - //Reloads Buffer - //wParam: Buffer to reload - //lParam: 0 if no alert, else alert - - - #define NPPM_SETFILENAME (NPPMSG + 63) - // wParam: BufferID - // lParam: filename - // Returns: TRUE if successful (only for unnamed documents) - + // BOOL NPPM_RELOADBUFFERID(UINT_PTR bufferID, BOOL alert) + // Reloads document with the given BufferID + // wParam[in]: BufferID of document to reload + // lParam[in]: set TRUE to let user confirm or reject the reload; setting FALSE will reload with no alert. + // Returns TRUE on success, FALSE otherwise #define NPPM_GETBUFFERLANGTYPE (NPPMSG + 64) - //wParam: BufferID to get LangType from - //lParam: 0 - //Returns as int, see LangType. -1 on error + // int NPPM_GETBUFFERLANGTYPE(UINT_PTR bufferID, 0) + // Retrieves the language type of the document with the given bufferID. + // wParam[in]: BufferID of document to get LangType from + // lParam: 0 (not used) + // Returns as int, see LangType. -1 on error #define NPPM_SETBUFFERLANGTYPE (NPPMSG + 65) - //wParam: BufferID to set LangType of - //lParam: LangType - //Returns TRUE on success, FALSE otherwise - //use int, see LangType for possible values - //L_USER and L_EXTERNAL are not supported + // BOOL NPPM_SETBUFFERLANGTYPE(UINT_PTR bufferID, int langType) + // Set the language type of the document based on the given bufferID. + // wParam[in]: BufferID to set LangType of + // lParam[in]: langType as int, enum LangType for valid values (L_USER and L_EXTERNAL are not supported) + // Returns TRUE on success, FALSE otherwise #define NPPM_GETBUFFERENCODING (NPPMSG + 66) - //wParam: BufferID to get encoding from - //lParam: 0 - //returns as int, see UniMode. -1 on error + // int NPPM_GETBUFFERENCODING(UINT_PTR bufferID, 0) + // Get encoding from the document with the given bufferID + // wParam[in]: BufferID to get encoding from + // lParam: 0 (not used) + // returns -1 on error, otherwise UniMode, with the following value: + // 0: ANSI + // 1: UTF-8 with BOM + // 2: UTF-16 Big Ending with BOM + // 3: UTF-16 Little Ending with BOM + // 4: UTF-8 without BOM + // 5: uni7Bit + // 6: UTF-16 Big Ending without BOM + // 7: UTF-16 Little Ending without BOM #define NPPM_SETBUFFERENCODING (NPPMSG + 67) - //wParam: BufferID to set encoding of - //lParam: format - //Returns TRUE on success, FALSE otherwise - //use int, see UniMode - //Can only be done on new, unedited files + // BOOL NPPM_SETBUFFERENCODING(UINT_PTR bufferID, int encoding) + // Set encoding to the document with the given bufferID + // wParam: BufferID to set encoding of + // lParam: encoding, see UniMode value in NPPM_GETBUFFERENCODING (above) + // Returns TRUE on success, FALSE otherwise + // Can only be done on new, unedited files #define NPPM_GETBUFFERFORMAT (NPPMSG + 68) - //wParam: BufferID to get format from - //lParam: 0 - //returns as int, see formatType. -1 on error + // int NPPM_GETBUFFERFORMAT(UINT_PTR bufferID, 0) + // Get the EOL format of the document with given bufferID. + // wParam[in]: BufferID to get EolType format from + // lParam: 0 (not used) + // Returned value is -1 on error, otherwise EolType format: + // 0: Windows (CRLF) + // 1: Macos (CR) + // 2: Unix (LF) + // 3. Unknown #define NPPM_SETBUFFERFORMAT (NPPMSG + 69) - //wParam: BufferID to set format of - //lParam: format - //Returns TRUE on success, FALSE otherwise - //use int, see formatType - -/* - #define NPPM_ADDREBAR (NPPMSG + 57) - // BOOL NPPM_ADDREBAR(0, REBARBANDINFO *) - // Returns assigned ID in wID value of struct pointer - #define NPPM_UPDATEREBAR (NPPMSG + 58) - // BOOL NPPM_ADDREBAR(INT ID, REBARBANDINFO *) - //Use ID assigned with NPPM_ADDREBAR - #define NPPM_REMOVEREBAR (NPPMSG + 59) - // BOOL NPPM_ADDREBAR(INT ID, 0) - //Use ID assigned with NPPM_ADDREBAR -*/ + // BOOL NPPM_SETBUFFERFORMAT(UINT_PTR bufferID, int format) + // Set the EOL format to the document with given bufferID. + // wParam[in]: BufferID to set EolType format of + // lParam[in]: EolType format. For EolType format value, see NPPM_GETBUFFERFORMAT (above) + // Returns TRUE on success, FALSE otherwise + #define NPPM_HIDETOOLBAR (NPPMSG + 70) // BOOL NPPM_HIDETOOLBAR(0, BOOL hideOrNot) - // if hideOrNot is set as TRUE then tool bar will be hidden - // otherwise it'll be shown. - // return value : the old status value + // Hide (or show) the toolbar. + // wParam: 0 (not used) + // lParam[in]: if hideOrNot is set as TRUE then tool bar will be hidden, otherwise it'll be shown. + // return value: the old status value #define NPPM_ISTOOLBARHIDDEN (NPPMSG + 71) // BOOL NPPM_ISTOOLBARHIDDEN(0, 0) - // returned value : TRUE if tool bar is hidden, otherwise FALSE + // Get toolbar status. + // wParam: 0 (not used) + // lParam: 0 (not used) + // return value: TRUE if tool bar is hidden, otherwise FALSE #define NPPM_HIDEMENU (NPPMSG + 72) // BOOL NPPM_HIDEMENU(0, BOOL hideOrNot) - // if hideOrNot is set as TRUE then menu will be hidden - // otherwise it'll be shown. - // return value : the old status value + // Hide (or show) menu bar. + // wParam: 0 (not used) + // lParam[in]: if hideOrNot is set as TRUE then menu will be hidden, otherwise it'll be shown. + // return value: the old status value #define NPPM_ISMENUHIDDEN (NPPMSG + 73) // BOOL NPPM_ISMENUHIDDEN(0, 0) - // returned value : TRUE if menu is hidden, otherwise FALSE + // Get menu bar status. + // wParam: 0 (not used) + // lParam: 0 (not used) + // return value: TRUE if menu bar is hidden, otherwise FALSE #define NPPM_HIDESTATUSBAR (NPPMSG + 74) // BOOL NPPM_HIDESTATUSBAR(0, BOOL hideOrNot) - // if hideOrNot is set as TRUE then STATUSBAR will be hidden - // otherwise it'll be shown. - // return value : the old status value + // Hide (or show) status bar. + // wParam: 0 (not used) + // lParam[in]: if hideOrNot is set as TRUE then status bar will be hidden, otherwise it'll be shown. + // return value: the old status value #define NPPM_ISSTATUSBARHIDDEN (NPPMSG + 75) // BOOL NPPM_ISSTATUSBARHIDDEN(0, 0) - // returned value : TRUE if STATUSBAR is hidden, otherwise FALSE + // Get status bar status. + // wParam: 0 (not used) + // lParam: 0 (not used) + // return value: TRUE if status bar is hidden, otherwise FALSE #define NPPM_GETSHORTCUTBYCMDID (NPPMSG + 76) - // BOOL NPPM_GETSHORTCUTBYCMDID(int cmdID, ShortcutKey *sk) - // get your plugin command current mapped shortcut into sk via cmdID - // You may need it after getting NPPN_READY notification - // returned value : TRUE if this function call is successful and shorcut is enable, otherwise FALSE + // BOOL NPPM_GETSHORTCUTBYCMDID(int cmdID, ShortcutKey* sk) + // Get your plugin command current mapped shortcut into sk via cmdID. + // wParam[in]: cmdID is your plugin command ID + // lParam[out]: sk is a pointer of ShortcutKey strcture which will receive the requested CMD shortcut. It should be allocated in the plugin before being used. + // For ShortcutKey strcture, see in "PluginInterface.h". You may need it after getting NPPN_READY notification. + // return value: TRUE if this function call is successful and shortcut is enable, otherwise FALSE #define NPPM_DOOPEN (NPPMSG + 77) - // BOOL NPPM_DOOPEN(0, const TCHAR *fullPathName2Open) - // fullPathName2Open indicates the full file path name to be opened. - // The return value is TRUE (1) if the operation is successful, otherwise FALSE (0). - + // BOOL NPPM_DOOPEN(0, const wchar_t* fullPathName2Open) + // Open a file with given fullPathName2Open. + // If fullPathName2Open has been already opened in Notepad++, the it will be activated and becomes the current document. + // wParam: 0 (not used) + // lParam[in]: fullPathName2Open indicates the full file path name to be opened + // The return value is TRUE if the operation is successful, otherwise FALSE + #define NPPM_SAVECURRENTFILEAS (NPPMSG + 78) - // BOOL NPPM_SAVECURRENTFILEAS (BOOL asCopy, const TCHAR* filename) + // BOOL NPPM_SAVECURRENTFILEAS (BOOL saveAsCopy, const wchar_t* filename) + // Save the current activated document. + // wParam[in]: saveAsCopy must be either FALSE to save, or TRUE to save a copy of the current filename ("Save a Copy As..." action) + // lParam[in]: filename indicates the full file path name to be saved + // The return value is TRUE if the operation is successful, otherwise FALSE + + #define NPPM_GETCURRENTNATIVELANGENCODING (NPPMSG + 79) + // int NPPM_GETCURRENTNATIVELANGENCODING(0, 0) + // Get the code page associated with the current localisation of Notepad++. + // wParam: 0 (not used) + // lParam: 0 (not used) + // return value: the current native language encoding + + #define NPPM_ALLOCATESUPPORTED_DEPRECATED (NPPMSG + 80) + // DEPRECATED: the message has been made (since 2010 AD) for checking if NPPM_ALLOCATECMDID is supported. This message is no more needed. + // BOOL NPPM_ALLOCATESUPPORTED_DEPRECATED(0, 0) + // Get NPPM_ALLOCATECMDID supported status. Use to identify if subclassing is necessary + // wParam: 0 (not used) + // lParam: 0 (not used) + // returns TRUE if NPPM_ALLOCATECMDID is supported - #define NPPM_ALLOCATESUPPORTED (NPPMSG + 80) - // returns TRUE if NPPM_ALLOCATECMDID is supported - // Use to identify if subclassing is necessary #define NPPM_ALLOCATECMDID (NPPMSG + 81) - // BOOL NPPM_ALLOCATECMDID(int numberRequested, int* startNumber) - // sets startNumber to the initial command ID if successful - // Returns: TRUE if successful, FALSE otherwise. startNumber will also be set to 0 if unsuccessful + // BOOL NPPM_ALLOCATECMDID(int numberRequested, int* startNumber) + // Obtain a number of consecutive menu item IDs for creating menus dynamically, with the guarantee of these IDs not clashing with any other plugins. + // wParam[in]: numberRequested is the number of ID you request for the reservation + // lParam[out]: startNumber will be set to the initial command ID if successful + // Returns: TRUE if successful, FALSE otherwise. startNumber will also be set to 0 if unsuccessful + // + // Example: If a plugin needs 4 menu item ID, the following code can be used: + // + // int idBegin; + // BOOL isAllocatedSuccessful = ::SendMessage(nppData._nppHandle, NPPM_ALLOCATECMDID, 4, &idBegin); + // + // if isAllocatedSuccessful is TRUE, and value of idBegin is 46581 + // then menu item ID 46581, 46582, 46583 and 46584 are preserved by Notepad++, and they are safe to be used by the plugin. #define NPPM_ALLOCATEMARKER (NPPMSG + 82) // BOOL NPPM_ALLOCATEMARKER(int numberRequested, int* startNumber) - // sets startNumber to the initial command ID if successful - // Allocates a marker number to a plugin - // Returns: TRUE if successful, FALSE otherwise. startNumber will also be set to 0 if unsuccessful + // Allocate a number of consecutive marker IDs to a plugin: if a plugin need to add a marker on Notepad++'s Scintilla marker margin, + // it has to use this message to get marker number, in order to prevent from the conflict with the other plugins. + // wParam[in]: numberRequested is the number of ID you request for the reservation + // lParam[out]: startNumber will be set to the initial command ID if successful + // Return TRUE if successful, FALSE otherwise. startNumber will also be set to 0 if unsuccessful + // + // Example: If a plugin needs 3 marker ID, the following code can be used: + // + // int idBegin; + // BOOL isAllocatedSuccessful = ::SendMessage(nppData._nppHandle, NPPM_ALLOCATEMARKER, 3, &idBegin); + // + // if isAllocatedSuccessful is TRUE, and value of idBegin is 16 + // then marker ID 16, 17 and 18 are preserved by Notepad++, and they are safe to be used by the plugin. + + #define NPPM_GETLANGUAGENAME (NPPMSG + 83) + // int NPPM_GETLANGUAGENAME(LangType langType, wchar_t* langName) + // Get programming language name from the given language type (enum LangType). + // wParam[in]: langType is the number of LangType + // lParam[out]: langName is the buffer to receive the language name string + // Return value is the number of copied character / number of character to copy (\0 is not included) + // + // You should call this function 2 times - the first time you pass langName as NULL to get the number of characters to copy. + // You allocate a buffer of the length of (the number of characters + 1) then call NPPM_GETLANGUAGENAME function the 2nd time + // by passing allocated buffer as argument langName + + #define NPPM_GETLANGUAGEDESC (NPPMSG + 84) + // INT NPPM_GETLANGUAGEDESC(int langType, wchar_t *langDesc) + // Get programming language short description from the given language type (enum LangType) + // wParam[in]: langType is the number of LangType + // lParam[out]: langDesc is the buffer to receive the language description string + // Return value is the number of copied character / number of character to copy (\0 is not included) + // + // You should call this function 2 times - the first time you pass langDesc as NULL to get the number of characters to copy. + // You allocate a buffer of the length of (the number of characters + 1) then call NPPM_GETLANGUAGEDESC function the 2nd time + // by passing allocated buffer as argument langDesc + + #define NPPM_SHOWDOCLIST (NPPMSG + 85) + // BOOL NPPM_SHOWDOCLIST(0, BOOL toShowOrNot) + // Show or hide the Document List panel. + // wParam: 0 (not used) + // lParam[in]: toShowOrNot - if toShowOrNot is TRUE, the Document List panel is shown otherwise it is hidden. + // Return TRUE + + #define NPPM_ISDOCLISTSHOWN (NPPMSG + 86) + // BOOL NPPM_ISDOCLISTSHOWN(0, 0) + // Checks the visibility of the Document List panel. + // wParam: 0 (not used) + // lParam: 0 (not used) + // return value: TRUE if the Document List panel is currently shown, FALSE otherwise + + #define NPPM_GETAPPDATAPLUGINSALLOWED (NPPMSG + 87) + // BOOL NPPM_GETAPPDATAPLUGINSALLOWED(0, 0) + // Check to see if loading plugins from "%APPDATA%\..\Local\Notepad++\plugins" is allowed. + // wParam: 0 (not used) + // lParam: 0 (not used) + // return value: TRUE if loading plugins from %APPDATA% is allowed, FALSE otherwise + + #define NPPM_GETCURRENTVIEW (NPPMSG + 88) + // int NPPM_GETCURRENTVIEW(0, 0) + // Get the current used view. + // wParam: 0 (not used) + // lParam: 0 (not used) + // Return: current edit view of Notepad++. Only 2 possible values: 0 = Main, 1 = Secondary + + #define NPPM_DOCLISTDISABLEEXTCOLUMN (NPPMSG + 89) + // BOOL NPPM_DOCLISTDISABLEEXTCOLUMN(0, BOOL disableOrNot) + // Disable or enable extension column of Document List + // wParam: 0 (not used) + // lParam[in]: disableOrNot - if disableOrNot is TRUE, extension column is hidden otherwise it is visible. + // Return TRUE + + #define NPPM_DOCLISTDISABLEPATHCOLUMN (NPPMSG + 102) + // BOOL NPPM_DOCLISTDISABLEPATHCOLUMN(0, BOOL disableOrNot) + // Disable or enable path column of Document List + // wParam: 0 (not used) + // lParam[in]: disableOrNot - if disableOrNot is TRUE, extension column is hidden otherwise it is visible. + // Return TRUE + + #define NPPM_GETEDITORDEFAULTFOREGROUNDCOLOR (NPPMSG + 90) + // int NPPM_GETEDITORDEFAULTFOREGROUNDCOLOR(0, 0) + // Get the current editor default foreground color. + // wParam: 0 (not used) + // lParam: 0 (not used) + // Return: the color as integer with hex format being 0x00bbggrr + + #define NPPM_GETEDITORDEFAULTBACKGROUNDCOLOR (NPPMSG + 91) + // int NPPM_GETEDITORDEFAULTBACKGROUNDCOLOR(0, 0) + // Get the current editor default background color. + // wParam: 0 (not used) + // lParam: 0 (not used) + // Return: the color as integer with hex format being 0x00bbggrr + + #define NPPM_SETSMOOTHFONT (NPPMSG + 92) + // BOOL NPPM_SETSMOOTHFONT(0, BOOL setSmoothFontOrNot) + // Set (or remove) smooth font. The API uses underlying Scintilla command SCI_SETFONTQUALITY to manage the font quality. + // wParam: 0 (not used) + // lParam[in]: setSmoothFontOrNot - if value is TRUE, this message sets SC_EFF_QUALITY_LCD_OPTIMIZED else SC_EFF_QUALITY_DEFAULT + // Return TRUE + + #define NPPM_SETEDITORBORDEREDGE (NPPMSG + 93) + // BOOL NPPM_SETEDITORBORDEREDGE(0, BOOL withEditorBorderEdgeOrNot) + // Add (or remove) an additional sunken edge style to the Scintilla window else it removes the extended style from the window. + // wParam: 0 (not used) + // lParam[in]: withEditorBorderEdgeOrNot - TRUE for adding border edge on Scintilla window, FALSE for removing it + // Return TRUE + + #define NPPM_SAVEFILE (NPPMSG + 94) + // BOOL NPPM_SAVEFILE(0, const wchar_t *fileNameToSave) + // Save the file (opened in Notepad++) with the given full file name path. + // wParam: 0 (not used) + // lParam[in]: fileNameToSave must be the full file path for the file to be saved. + // Return TRUE on success, FALSE on fileNameToSave is not found + + #define NPPM_DISABLEAUTOUPDATE (NPPMSG + 95) // 2119 in decimal + // BOOL NPPM_DISABLEAUTOUPDATE(0, 0) + // Disable Notepad++ auto-update. + // wParam: 0 (not used) + // lParam: 0 (not used) + // Return TRUE + + #define NPPM_REMOVESHORTCUTBYCMDID (NPPMSG + 96) // 2120 in decimal + // BOOL NPPM_REMOVESHORTCUTBYCMDID(int pluginCmdID, 0) + // Remove the assigned shortcut mapped to pluginCmdID + // wParam[in]: pluginCmdID + // lParam: 0 (not used) + // return value: TRUE if function call is successful, otherwise FALSE + + #define NPPM_GETPLUGINHOMEPATH (NPPMSG + 97) + // int NPPM_GETPLUGINHOMEPATH(size_t strLen, wchar_t* pluginRootPath) + // Get plugin home root path. It's useful if plugins want to get its own path by appending which is the name of plugin without extension part. + // wParam[in]: strLen - size of allocated buffer "pluginRootPath" + // lParam[out]: pluginRootPath - Users should call it with pluginRootPath be NULL to get the required number of wchar_t (not including the terminating nul character), + // allocate pluginRootPath buffer with the return value + 1, then call it again to get the path. + // Return the number of wchar_t copied/to copy, 0 on copy failed + + #define NPPM_GETSETTINGSONCLOUDPATH (NPPMSG + 98) + // int NPPM_GETSETTINGSCLOUDPATH(size_t strLen, wchar_t *settingsOnCloudPath) + // Get settings on cloud path. It's useful if plugins want to store its settings on Cloud, if this path is set. + // wParam[in]: strLen - size of allocated buffer "settingsOnCloudPath" + // lParam[out]: settingsOnCloudPath - Users should call it with settingsOnCloudPath be NULL to get the required number of wchar_t (not including the terminating nul character), + // allocate settingsOnCloudPath buffer with the return value + 1, then call it again to get the path. + // Returns the number of wchar_t copied/to copy. If the return value is 0, then this path is not set, or the "strLen" is not enough to copy the path. + + #define NPPM_SETLINENUMBERWIDTHMODE (NPPMSG + 99) + #define LINENUMWIDTH_DYNAMIC 0 + #define LINENUMWIDTH_CONSTANT 1 + // BOOL NPPM_SETLINENUMBERWIDTHMODE(0, int widthMode) + // Set line number margin width in dynamic width mode (LINENUMWIDTH_DYNAMIC) or constant width mode (LINENUMWIDTH_CONSTANT) + // It may help some plugins to disable non-dynamic line number margins width to have a smoothly visual effect while vertical scrolling the content in Notepad++ + // wParam: 0 (not used) + // lParam[in]: widthMode should be LINENUMWIDTH_DYNAMIC or LINENUMWIDTH_CONSTANT + // return TRUE if calling is successful, otherwise return FALSE + + #define NPPM_GETLINENUMBERWIDTHMODE (NPPMSG + 100) + // int NPPM_GETLINENUMBERWIDTHMODE(0, 0) + // Get line number margin width in dynamic width mode (LINENUMWIDTH_DYNAMIC) or constant width mode (LINENUMWIDTH_CONSTANT) + // wParam: 0 (not used) + // lParam: 0 (not used) + // Return current line number margin width mode (LINENUMWIDTH_DYNAMIC or LINENUMWIDTH_CONSTANT) + + #define NPPM_ADDTOOLBARICON_FORDARKMODE (NPPMSG + 101) + struct toolbarIconsWithDarkMode { + HBITMAP hToolbarBmp; + HICON hToolbarIcon; + HICON hToolbarIconDarkMode; + }; + // BOOL NPPM_ADDTOOLBARICON_FORDARKMODE(UINT pluginCmdID, toolbarIconsWithDarkMode* iconHandles) + // Use NPPM_ADDTOOLBARICON_FORDARKMODE instead obsolete NPPM_ADDTOOLBARICON (DEPRECATED) which doesn't support the dark mode + // wParam[in]: pluginCmdID + // lParam[in]: iconHandles is the pointer of toolbarIconsWithDarkMode structure + // All 3 handles below should be set so the icon will be displayed correctly if toolbar icon sets are changed by users, also in dark mode + // Return TRUE + + #define NPPM_GETEXTERNALLEXERAUTOINDENTMODE (NPPMSG + 103) + // BOOL NPPM_GETEXTERNALLEXERAUTOINDENTMODE(const wchar_t* languageName, ExternalLexerAutoIndentMode* autoIndentMode) + // Get ExternalLexerAutoIndentMode for an installed external programming language. + // wParam[in]: languageName is external language name to search + // lParam[out]: autoIndentMode could receive one of three following values + // - Standard (0) means Notepad++ will keep the same TAB indentation between lines; + // - C_Like (1) means Notepad++ will perform a C-Language style indentation for the selected external language; + // - Custom (2) means a Plugin will be controlling auto-indentation for the current language. + // returned values: TRUE for successful searches, otherwise FALSE. + + #define NPPM_SETEXTERNALLEXERAUTOINDENTMODE (NPPMSG + 104) + // BOOL NPPM_SETEXTERNALLEXERAUTOINDENTMODE(const wchar_t* languageName, ExternalLexerAutoIndentMode autoIndentMode) + // Set ExternalLexerAutoIndentMode for an installed external programming language. + // wParam[in]: languageName is external language name to set + // lParam[in]: autoIndentMode could receive one of three following values + // - Standard (0) means Notepad++ will keep the same TAB indentation between lines; + // - C_Like (1) means Notepad++ will perform a C-Language style indentation for the selected external language; + // - Custom (2) means a Plugin will be controlling auto-indentation for the current language. + // return value: TRUE if function call was successful, otherwise FALSE. + + #define NPPM_ISAUTOINDENTON (NPPMSG + 105) + // BOOL NPPM_ISAUTOINDENTON(0, 0) + // Get the current use Auto-Indentation setting in Notepad++ Preferences. + // wParam: 0 (not used) + // lParam: 0 (not used) + // Return TRUE if Auto-Indentation is on, FALSE otherwise + + #define NPPM_GETCURRENTMACROSTATUS (NPPMSG + 106) + // MacroStatus NPPM_GETCURRENTMACROSTATUS(0, 0) + // Get current enum class MacroStatus { Idle, RecordInProgress, RecordingStopped, PlayingBack } + // wParam: 0 (not used) + // lParam: 0 (not used) + // Return MacroStatus as int: + // 0: Idle - macro is not in use and it's empty + // 1: RecordInProgress - macro is currently being recorded + // 2: RecordingStopped - macro recording has been stopped + // 3: PlayingBack - macro is currently being played back + + #define NPPM_ISDARKMODEENABLED (NPPMSG + 107) + // BOOL NPPM_ISDARKMODEENABLED(0, 0) + // Get Notepad++ Dark Mode status (ON or OFF). + // wParam: 0 (not used) + // lParam: 0 (not used) + // Return TRUE if Dark Mode is enable, otherwise FALSE + + #define NPPM_GETDARKMODECOLORS (NPPMSG + 108) + // BOOL NPPM_GETDARKMODECOLORS (size_t cbSize, NppDarkMode::Colors* returnColors) + // Get the colors used in Dark Mode. + // wParam[in]: cbSize must be filled with sizeof(NppDarkMode::Colors). + // lParam[out]: returnColors must be a pre-allocated NppDarkMode::Colors struct. + // Return TRUE when successful, FALSE otherwise. + // You need to uncomment the following code to use NppDarkMode::Colors structure: + // + // namespace NppDarkMode + // { + // struct Colors + // { + // COLORREF background = 0; + // COLORREF softerBackground = 0; + // COLORREF hotBackground = 0; + // COLORREF pureBackground = 0; + // COLORREF errorBackground = 0; + // COLORREF text = 0; + // COLORREF darkerText = 0; + // COLORREF disabledText = 0; + // COLORREF linkText = 0; + // COLORREF edge = 0; + // COLORREF hotEdge = 0; + // COLORREF disabledEdge = 0; + // }; + // } + // + // Note: in the case of calling failure ("false" is returned), you may need to change NppDarkMode::Colors structure to: + // https://github.com/notepad-plus-plus/notepad-plus-plus/blob/master/PowerEditor/src/NppDarkMode.h#L32 + + #define NPPM_GETCURRENTCMDLINE (NPPMSG + 109) + // int NPPM_GETCURRENTCMDLINE(size_t strLen, wchar_t *commandLineStr) + // Get the Current Command Line string. + // Users should call it with commandLineStr as NULL to get the required number of wchar_t (not including the terminating nul character), + // allocate commandLineStr buffer with the return value + 1, then call it again to get the current command line string. + // wParam[in]: strLen is "commandLineStr" buffer length + // lParam[out]: commandLineStr receives all copied command line string + // Return the number of wchar_t copied/to copy + + + #define NPPM_CREATELEXER (NPPMSG + 110) + // void* NPPM_CREATELEXER(0, const wchar_t* lexer_name) + // Get the ILexer pointer created by Lexilla. Call the lexilla "CreateLexer()" function to allow plugins to set the lexer for a Scintilla instance created by NPPM_CREATESCINTILLAHANDLE. + // wParam: 0 (not used) + // lParam[in]: lexer_name is the name of the lexer + // Return the ILexer pointer + + #define NPPM_GETBOOKMARKID (NPPMSG + 111) + // int NPPM_GETBOOKMARKID(0, 0) + // Get the bookmark ID - use this API to get bookmark ID dynamically that guarantees you get always the right bookmark ID even it's been changed through the different versions. + // wParam: 0 (not used) + // lParam: 0 (not used) + // Return bookmark ID + + #define NPPM_DARKMODESUBCLASSANDTHEME (NPPMSG + 112) + namespace NppDarkMode + { + // Standard flags for main parent after its children are initialized. + constexpr ULONG dmfInit = 0x0000000BUL; + + // Standard flags for main parent usually used in NPPN_DARKMODECHANGED. + constexpr ULONG dmfHandleChange = 0x0000000CUL; + }; + + // ULONG NPPM_DARKMODESUBCLASSANDTHEME(ULONG dmFlags, HWND hwnd) + // Add support for generic dark mode to plugin dialog. Subclassing is applied automatically unless DWS_USEOWNDARKMODE flag is used. + // Might not work properly in C# plugins. + // wParam[in]: dmFlags has 2 possible value dmfInit (0x0000000BUL) & dmfHandleChange (0x0000000CUL) - see above definition + // lParam[in]: hwnd is the dialog handle of plugin - Docking panels don't need to call NPPM_DARKMODESUBCLASSANDTHEME + // Returns successful combinations of flags. + + // Examples: + // + // - after controls initializations in WM_INITDIALOG, in WM_CREATE or after CreateWindow: + // + //auto success = static_cast(::SendMessage(nppData._nppHandle, NPPM_DARKMODESUBCLASSANDTHEME, static_cast(NppDarkMode::dmfInit), reinterpret_cast(mainHwnd))); + // + // - handling dark mode change: + // + //extern "C" __declspec(dllexport) void beNotified(SCNotification * notifyCode) + //{ + // switch (notifyCode->nmhdr.code) + // { + // case NPPN_DARKMODECHANGED: + // { + // ::SendMessage(nppData._nppHandle, NPPM_DARKMODESUBCLASSANDTHEME, static_cast(dmfHandleChange), reinterpret_cast(mainHwnd)); + // ::SetWindowPos(mainHwnd, nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); // to redraw titlebar and window + // break; + // } + // } + //} + + #define NPPM_ALLOCATEINDICATOR (NPPMSG + 113) + // BOOL NPPM_ALLOCATEINDICATOR(int numberRequested, int* startNumber) + // Allocates an indicator number to a plugin: if a plugin needs to add an indicator, + // it has to use this message to get the indicator number, in order to prevent a conflict with the other plugins. + // wParam[in]: numberRequested is the number of ID you request for the reservation + // lParam[out]: startNumber will be set to the initial command ID if successful + // Return TRUE if successful, FALSE otherwise. startNumber will also be set to 0 if unsuccessful + // + // Example: If a plugin needs 1 indicator ID, the following code can be used : + // + // int idBegin; + // BOOL isAllocatedSuccessful = ::SendMessage(nppData._nppHandle, NPPM_ALLOCATEINDICATOR, 1, &idBegin); + // + // if isAllocatedSuccessful is TRUE, and value of idBegin is 7 + // then indicator ID 7 is preserved by Notepad++, and it is safe to be used by the plugin. + + #define NPPM_GETTABCOLORID (NPPMSG + 114) + // int NPPM_GETTABCOLORID(int view, int tabIndex) + // Get the tab color ID with given tab index and view. + // wParam[in]: view - main view (0) or sub-view (1) or -1 (active view) + // lParam[in]: tabIndex - index (in the view indicated above). -1 for currently active tab + // Return tab color ID which contains the following values: 0 (yellow), 1 (green), 2 (blue), 3 (orange), 4 (pink) or -1 (no color) + // + // Note: there's no symmetric command NPPM_SETTABCOLORID. Plugins can use NPPM_MENUCOMMAND to set current tab color with the desired tab color ID. + + #define NPPM_SETUNTITLEDNAME (NPPMSG + 115) + // BOOL NPPM_SETUNTITLEDNAME(BufferID id, const wchar_t* newName) + // Rename the tab name for an untitled tab. + // wParam[in]: id - BufferID of the tab. -1 for currently active tab + // lParam[in]: newName - the desired new name of the tab + // Return TRUE upon success; FALSE upon failure + + #define NPPM_GETNATIVELANGFILENAME (NPPMSG + 116) + // int NPPM_GETNATIVELANGFILENAME(size_t strLen, char* nativeLangFileName) + // Get the Current native language file name string. Use it after getting NPPN_READY notification to find out which native language is used. + // Users should call it with nativeLangFileName as NULL to get the required number of char (not including the terminating nul character), + // allocate language file name string buffer with the return value + 1, then call it again to get the current native language file name string. + // If there's no localization file applied, the returned value is 0. + // wParam[in]: strLen is "language file name string" buffer length + // lParam[out]: language file name string receives all copied native language file name string + // Return the number of char copied/to copy + + #define NPPM_ADDSCNMODIFIEDFLAGS (NPPMSG + 117) + // BOOL NPPM_ADDSCNMODIFIEDFLAGS(0, unsigned long scnModifiedFlags2Add) + // Add the necessary SCN_MODIFIED flags so that your plugin will receive the SCN_MODIFIED notification for these events, enabling your specific treatments. + // By default, Notepad++ only forwards SCN_MODIFIED with the following 5 flags/events: + // SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT | SC_PERFORMED_UNDO | SC_PERFORMED_REDO | SC_MOD_CHANGEINDICATOR to plugins. + // If your plugin needs to process other SCN_MODIFIED events, you should add the required flags by sending this message to Notepad++. You can send it immediately after receiving NPPN_READY, + // or only when your plugin needs to listen to specific events (to avoid penalizing Notepad++'s performance). Just ensure that the message is sent only once. + // wParam: 0 (not used) + // lParam[in]: scnModifiedFlags2Add - Scintilla SCN_MODIFIED flags to add. + // Return TRUE + // + // Example: + // + // extern "C" __declspec(dllexport) void beNotified(SCNotification* notifyCode) + // { + // switch (notifyCode->nmhdr.code) + // { + // case NPPN_READY: + // { + // // Add SC_MOD_BEFOREDELETE and SC_MOD_BEFOREINSERT to listen to the 2 events of SCN_MODIFIED + // ::SendMessage(nppData._nppHandle, NPPM_ADDSCNMODIFIEDFLAGS, 0, SC_MOD_BEFOREDELETE | SC_MOD_BEFOREINSERT); + // } + // break; + // ... + // } + // ... + // } + + #define NPPM_GETTOOLBARICONSETCHOICE (NPPMSG + 118) + // BOOL NPPM_GETTOOLBARICONSETCHOICE(0, 0) + // Get Notepad++ toolbar icon set choice (Fluent UI: small, Fluent UI: large, Filled Fluent UI: small, Filled Fluent UI: large and Standard icons: small. + // wParam: 0 (not used) + // lParam: 0 (not used) + // Return toolbar icon set choice as an integer value. Here are 5 possible values: + // 0 (Fluent UI: small), 1 (Fluent UI: large), 2 (Filled Fluent UI: small), 3 (Filled Fluent UI: large) and 4 (Standard icons: small). + + #define NPPM_GETNPPSETTINGSDIRPATH (NPPMSG + 119) + // int NPPM_GETNPPSETTINGSDIRPATH(size_t strLen, wchar_t *settingsDirPath) + // Get path for the active Notepad++ settings: it will use -settingsDir path if that's defined; if not, it will use Cloud directory if that's defined; + // if not, it will use the AppData settings directory, or finally the installation path. This allows plugins to have one interface to find out + // where the active Notepad++ settings are stored, whichever location they are currently set to. + // wParam[in]: strLen - size of allocated buffer "settingsDirPath" + // lParam[out]: settingsDirPath - Users should call it with settingsDirPath be NULL to get the required number of wchar_t (not including the terminating nul character), + // allocate settingsDirPath buffer with the return value + 1, then call it again to get the path. + // Returns the number of wchar_t copied/to copy. If the return value is 0, then the "strLen" is not enough to copy the path, or the settings path could not be determined. + // + // Note: This message is for the active Notepad++ configuration location. If you are looking for the settings directory for plugins (...\Plugins\Config\), + // use NPPM_GETPLUGINSCONFIGDIR instead. + +// For RUNCOMMAND_USER + #define VAR_NOT_RECOGNIZED 0 + #define FULL_CURRENT_PATH 1 + #define CURRENT_DIRECTORY 2 + #define FILE_NAME 3 + #define NAME_PART 4 + #define EXT_PART 5 + #define CURRENT_WORD 6 + #define NPP_DIRECTORY 7 + #define CURRENT_LINE 8 + #define CURRENT_COLUMN 9 + #define NPP_FULL_FILE_PATH 10 + #define GETFILENAMEATCURSOR 11 + #define CURRENT_LINESTR 12 + + #define RUNCOMMAND_USER (WM_USER + 3000) -#define RUNCOMMAND_USER (WM_USER + 3000) #define NPPM_GETFULLCURRENTPATH (RUNCOMMAND_USER + FULL_CURRENT_PATH) #define NPPM_GETCURRENTDIRECTORY (RUNCOMMAND_USER + CURRENT_DIRECTORY) #define NPPM_GETFILENAME (RUNCOMMAND_USER + FILE_NAME) @@ -340,40 +1062,41 @@ enum winVer{WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV #define NPPM_GETEXTPART (RUNCOMMAND_USER + EXT_PART) #define NPPM_GETCURRENTWORD (RUNCOMMAND_USER + CURRENT_WORD) #define NPPM_GETNPPDIRECTORY (RUNCOMMAND_USER + NPP_DIRECTORY) - // BOOL NPPM_GETXXXXXXXXXXXXXXXX(size_t strLen, TCHAR *str) - // where str is the allocated TCHAR array, - // strLen is the allocated array size - // The return value is TRUE when get generic_string operation success - // Otherwise (allocated array size is too small) FALSE + #define NPPM_GETNPPFULLFILEPATH (RUNCOMMAND_USER + NPP_FULL_FILE_PATH) + #define NPPM_GETFILENAMEATCURSOR (RUNCOMMAND_USER + GETFILENAMEATCURSOR) + #define NPPM_GETCURRENTLINESTR (RUNCOMMAND_USER + CURRENT_LINESTR) + // BOOL NPPM_GETXXXXXXXXXXXXXXXX(size_t strLen, wchar_t *str) + // Get XXX string operations. + // wParam[in]: strLen is the allocated array size + // lParam[out]: str is the allocated wchar_t array + // The return value is TRUE when get std::wstring operation success, otherwise FALSE (allocated array size is too small) + #define NPPM_GETCURRENTLINE (RUNCOMMAND_USER + CURRENT_LINE) - // INT NPPM_GETCURRENTLINE(0, 0) + // int NPPM_GETCURRENTLINE(0, 0) + // Get current line number. + // wParam: 0 (not used) + // lParam: 0 (not used) // return the caret current position line + #define NPPM_GETCURRENTCOLUMN (RUNCOMMAND_USER + CURRENT_COLUMN) - // INT NPPM_GETCURRENTCOLUMN(0, 0) + // int NPPM_GETCURRENTCOLUMN(0, 0) + // Get current column number. + // wParam: 0 (not used) + // lParam: 0 (not used) // return the caret current position column - #define VAR_NOT_RECOGNIZED 0 - #define FULL_CURRENT_PATH 1 - #define CURRENT_DIRECTORY 2 - #define FILE_NAME 3 - #define NAME_PART 4 - #define EXT_PART 5 - #define CURRENT_WORD 6 - #define NPP_DIRECTORY 7 - #define CURRENT_LINE 8 - #define CURRENT_COLUMN 9 // Notification code #define NPPN_FIRST 1000 - #define NPPN_READY (NPPN_FIRST + 1) // To notify plugins that all the procedures of launchment of notepad++ are done. + #define NPPN_READY (NPPN_FIRST + 1) // To notify plugins that all the initialization for launching Notepad++ is complete. //scnNotification->nmhdr.code = NPPN_READY; //scnNotification->nmhdr.hwndFrom = hwndNpp; //scnNotification->nmhdr.idFrom = 0; #define NPPN_TBMODIFICATION (NPPN_FIRST + 2) // To notify plugins that toolbar icons can be registered - //scnNotification->nmhdr.code = NPPN_TB_MODIFICATION; + //scnNotification->nmhdr.code = NPPN_TBMODIFICATION; //scnNotification->nmhdr.hwndFrom = hwndNpp; //scnNotification->nmhdr.idFrom = 0; @@ -396,14 +1119,14 @@ enum winVer{WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV //scnNotification->nmhdr.code = NPPN_FILEBEFOREOPEN; //scnNotification->nmhdr.hwndFrom = hwndNpp; //scnNotification->nmhdr.idFrom = BufferID; - + #define NPPN_FILEBEFORESAVE (NPPN_FIRST + 7) // To notify plugins that the current file is about to be saved - //scnNotification->nmhdr.code = NPPN_FILEBEFOREOPEN; + //scnNotification->nmhdr.code = NPPN_FILEBEFORESAVE; //scnNotification->nmhdr.hwndFrom = hwndNpp; //scnNotification->nmhdr.idFrom = BufferID; - + #define NPPN_FILESAVED (NPPN_FIRST + 8) // To notify plugins that the current file is just saved - //scnNotification->nmhdr.code = NPPN_FILECLOSED; + //scnNotification->nmhdr.code = NPPN_FILESAVED; //scnNotification->nmhdr.hwndFrom = hwndNpp; //scnNotification->nmhdr.idFrom = BufferID; @@ -428,7 +1151,7 @@ enum winVer{WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV //scnNotification->nmhdr.idFrom = currentBufferID; #define NPPN_SHORTCUTREMAPPED (NPPN_FIRST + 13) // To notify plugins that plugin command shortcut is remapped. - //scnNotification->nmhdr.code = NPPN_SHORTCUTSREMAPPED; + //scnNotification->nmhdr.code = NPPN_SHORTCUTREMAPPED; //scnNotification->nmhdr.hwndFrom = ShortcutKeyStructurePointer; //scnNotification->nmhdr.idFrom = cmdID; //where ShortcutKeyStructurePointer is pointer of struct ShortcutKey: @@ -440,12 +1163,12 @@ enum winVer{WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV //}; #define NPPN_FILEBEFORELOAD (NPPN_FIRST + 14) // To notify plugins that the current file is about to be loaded - //scnNotification->nmhdr.code = NPPN_FILEBEFOREOPEN; + //scnNotification->nmhdr.code = NPPN_FILEBEFORELOAD; //scnNotification->nmhdr.hwndFrom = hwndNpp; //scnNotification->nmhdr.idFrom = NULL; #define NPPN_FILELOADFAILED (NPPN_FIRST + 15) // To notify plugins that file open operation failed - //scnNotification->nmhdr.code = NPPN_FILEOPENFAILED; + //scnNotification->nmhdr.code = NPPN_FILELOADFAILED; //scnNotification->nmhdr.hwndFrom = hwndNpp; //scnNotification->nmhdr.idFrom = BufferID; @@ -454,9 +1177,112 @@ enum winVer{WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV //scnNotification->nmhdr.hwndFrom = bufferID; //scnNotification->nmhdr.idFrom = docStatus; // where bufferID is BufferID - // docStatus can be combined by DOCSTAUS_READONLY and DOCSTAUS_BUFFERDIRTY + // docStatus can be combined by DOCSTATUS_READONLY and DOCSTATUS_BUFFERDIRTY + + #define DOCSTATUS_READONLY 1 + #define DOCSTATUS_BUFFERDIRTY 2 + + #define NPPN_DOCORDERCHANGED (NPPN_FIRST + 17) // To notify plugins that document order is changed + //scnNotification->nmhdr.code = NPPN_DOCORDERCHANGED; + //scnNotification->nmhdr.hwndFrom = newIndex; + //scnNotification->nmhdr.idFrom = BufferID; + + #define NPPN_SNAPSHOTDIRTYFILELOADED (NPPN_FIRST + 18) // To notify plugins that a snapshot dirty file is loaded on startup + //scnNotification->nmhdr.code = NPPN_SNAPSHOTDIRTYFILELOADED; + //scnNotification->nmhdr.hwndFrom = NULL; + //scnNotification->nmhdr.idFrom = BufferID; + + #define NPPN_BEFORESHUTDOWN (NPPN_FIRST + 19) // To notify plugins that Npp shutdown has been triggered, files have not been closed yet + //scnNotification->nmhdr.code = NPPN_BEFORESHUTDOWN; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = 0; + + #define NPPN_CANCELSHUTDOWN (NPPN_FIRST + 20) // To notify plugins that Npp shutdown has been cancelled + //scnNotification->nmhdr.code = NPPN_CANCELSHUTDOWN; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = 0; + + #define NPPN_FILEBEFORERENAME (NPPN_FIRST + 21) // To notify plugins that file is to be renamed + //scnNotification->nmhdr.code = NPPN_FILEBEFORERENAME; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = BufferID; + + #define NPPN_FILERENAMECANCEL (NPPN_FIRST + 22) // To notify plugins that file rename has been cancelled + //scnNotification->nmhdr.code = NPPN_FILERENAMECANCEL; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = BufferID; + + #define NPPN_FILERENAMED (NPPN_FIRST + 23) // To notify plugins that file has been renamed + //scnNotification->nmhdr.code = NPPN_FILERENAMED; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = BufferID; + + #define NPPN_FILEBEFOREDELETE (NPPN_FIRST + 24) // To notify plugins that file is to be deleted + //scnNotification->nmhdr.code = NPPN_FILEBEFOREDELETE; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = BufferID; + + #define NPPN_FILEDELETEFAILED (NPPN_FIRST + 25) // To notify plugins that file deletion has failed + //scnNotification->nmhdr.code = NPPN_FILEDELETEFAILED; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = BufferID; + + #define NPPN_FILEDELETED (NPPN_FIRST + 26) // To notify plugins that file has been deleted + //scnNotification->nmhdr.code = NPPN_FILEDELETED; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = BufferID; - #define DOCSTAUS_READONLY 1 - #define DOCSTAUS_BUFFERDIRTY 2 + #define NPPN_DARKMODECHANGED (NPPN_FIRST + 27) // To notify plugins that Dark Mode was enabled/disabled + //scnNotification->nmhdr.code = NPPN_DARKMODECHANGED; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = 0; -#endif //NOTEPAD_PLUS_MSGS_H + #define NPPN_CMDLINEPLUGINMSG (NPPN_FIRST + 28) // To notify plugins that there are plugin arguments pluginMessage (wchar_t*) is available + //scnNotification->nmhdr.code = NPPN_CMDLINEPLUGINMSG; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = pluginMessage; //where pluginMessage is pointer of type wchar_t + // + // User can pass arguments to plugins via command line argument using: + // -pluginMessage="PLUGIN1_ARG1=V1;PLUGIN1_ARG2=V2;PLUGIN2_ARG=V;..." + // + // The full string (wchar_t*) will be delivered to all plugins via the NPPN_CMDLINEPLUGINMSG notification. Each plugins can parse and extract the arguments relevant to itself. + // + // To avoid the collisions among plugins, the following protocol should be followed: + // 1. Each plugin must use its unique namespace (its folder name in plugins directory) as a prefix for its argument names. + // 2. The symbol ';' must be used as the delimiter between arguments when there are 2 or more arguments in the pluginMessage string. + // 3. The symbol '=' must be used as delimiter between argument names and their values. + // + // Example (via the command line): + // -pluginMessage="NppExecScriptPath=C:\Program Files\Notepad++\plugins\NppExec\init.py;NppExecArg2=arg2Value;mimeToolsSettings=disable;pluginYInfo=show" + // + // Interpretation: + // - Plugin "NppExec" processes: NppExecScriptPath=C:\Program Files\Notepad++\plugins\NppExec\init.py & NppExecArg2=arg2Value + // - Plugin "mimeTools" processes: mimeToolsSettings=disable + // - Plugin "pluginY" processes: pluginYInfo=show + + #define NPPN_EXTERNALLEXERBUFFER (NPPN_FIRST + 29) // To notify lexer plugins that the buffer (in idFrom) is just applied to a external lexer + //scnNotification->nmhdr.code = NPPN_EXTERNALLEXERBUFFER; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = BufferID; //where pluginMessage is pointer of type wchar_t + + #define NPPN_GLOBALMODIFIED (NPPN_FIRST + 30) // To notify plugins that the current document is just modified by Replace All action. + // For solving the performance issue (from v8.6.4), Notepad++ doesn't trigger SCN_MODIFIED during Replace All action anymore. + // As a result, the plugins which monitor SCN_MODIFIED should also monitor NPPN_GLOBALMODIFIED. + // This notification is implemented in Notepad++ v8.6.5. + //scnNotification->nmhdr.code = NPPN_GLOBALMODIFIED; + //scnNotification->nmhdr.hwndFrom = BufferID; + //scnNotification->nmhdr.idFrom = 0; // preserved for the future use, must be zero + + #define NPPN_NATIVELANGCHANGED (NPPN_FIRST + 31) // To notify plugins that the current native language is just changed to another one. + // Use NPPM_GETNATIVELANGFILENAME to get current native language file name. + // Use NPPM_GETMENUHANDLE(NPPPLUGINMENU, 0) to get submenu "Plugins" handle (HMENU) + //scnNotification->nmhdr.code = NPPN_NATIVELANGCHANGED; + //scnNotification->nmhdr.hwndFrom = hwndNpp + //scnNotification->nmhdr.idFrom = 0; // preserved for the future use, must be zero + + #define NPPN_TOOLBARICONSETCHANGED (NPPN_FIRST + 32) // To notify plugins that toolbar icon set selection has changed + //scnNotification->nmhdr.code = NPPN_TOOLBARICONSETCHANGED; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = iconSetChoice; + // where iconSetChoice could be 1 of 5 possible values: + // 0 (Fluent UI: small), 1 (Fluent UI: large), 2 (Filled Fluent UI: small), 3 (Filled Fluent UI: large) and 4 (Standard icons: small). diff --git a/NppPlugin/include/NppDarkMode.h b/NppPlugin/include/NppDarkMode.h new file mode 100644 index 00000000..676d772b --- /dev/null +++ b/NppPlugin/include/NppDarkMode.h @@ -0,0 +1,244 @@ +// This file is part of Notepad++ project +// Copyright (c) 2021 adzm / Adam D. Walling + +// 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 3 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, see . + +#pragma once + +#include +#include + +enum class FluentColor; +struct TbIconInfo; +struct AdvancedOptions; + +namespace NppDarkMode +{ + struct Colors + { + COLORREF background = 0; + COLORREF softerBackground = 0; // ctrl background color + COLORREF hotBackground = 0; + COLORREF pureBackground = 0; // dlg background color + COLORREF errorBackground = 0; + COLORREF text = 0; + COLORREF darkerText = 0; + COLORREF disabledText = 0; + COLORREF linkText = 0; + COLORREF edge = 0; + COLORREF hotEdge = 0; + COLORREF disabledEdge = 0; + }; + + struct Options + { + bool enable = false; + bool enableMenubar = false; + bool enablePlugin = false; + }; + + struct NppDarkModeParams + { + const wchar_t* _themeClassName = nullptr; + bool _subclass = false; + bool _theme = false; + }; + + enum class ToolTipsType + { + tooltip, + toolbar, + listview, + treeview, + tabbar + }; + + enum ColorTone { + blackTone = 0, + redTone = 1, + greenTone = 2, + blueTone = 3, + purpleTone = 4, + cyanTone = 5, + oliveTone = 6, + customizedTone = 32 + }; + + enum class TreeViewStyle + { + classic = 0, + light = 1, + dark = 2 + }; + + constexpr UINT WM_SETBUTTONIDEALSIZE = (WM_USER + 4200); + + void initDarkMode(); // pulls options from NppParameters + void refreshDarkMode(HWND hwnd, bool forceRefresh = false); // attempts to apply new options from NppParameters, sends NPPM_INTERNAL_REFRESHDARKMODE to hwnd's top level parent + + void initAdvancedOptions(); + + bool isEnabled(); + bool isDarkMenuEnabled(); + bool isEnabledForPlugins(); + bool isExperimentalActive(); + bool isExperimentalSupported(); + + bool isWindowsModeEnabled(); + void setWindowsMode(bool enable); + std::wstring getThemeName(); + void setThemeName(const std::wstring& newThemeName); + TbIconInfo getToolbarIconInfo(bool useDark); + TbIconInfo getToolbarIconInfo(); + void setToolbarIconSet(int state2Set, bool useDark); + void setToolbarIconSet(int state2Set); + void setToolbarFluentColor(FluentColor color2Set, bool useDark); + void setToolbarFluentColor(FluentColor color2Set); + void setToolbarFluentMonochrome(bool setMonochrome, bool useDark); + void setToolbarFluentMonochrome(bool setMonochrome); + void setToolbarFluentCustomColor(COLORREF color, bool useDark); + void setToolbarFluentCustomColor(COLORREF color); + int getTabIconSet(bool useDark); + void setTabIconSet(bool useAltIcons, bool useDark); + bool useTabTheme(); + void setAdvancedOptions(); + + bool isWindows10(); + bool isWindows11(); + DWORD getWindowsBuildNumber(); + + COLORREF invertLightness(COLORREF c); + double calculatePerceivedLightness(COLORREF c); + + void setDarkTone(ColorTone colorToneChoice); + + COLORREF getAccentColor(bool useDark); + COLORREF getAccentColor(); + + COLORREF getBackgroundColor(); + COLORREF getCtrlBackgroundColor(); + COLORREF getHotBackgroundColor(); + COLORREF getDlgBackgroundColor(); + COLORREF getErrorBackgroundColor(); + + COLORREF getTextColor(); + COLORREF getDarkerTextColor(); + COLORREF getDisabledTextColor(); + COLORREF getLinkTextColor(); + + COLORREF getEdgeColor(); + COLORREF getHotEdgeColor(); + COLORREF getDisabledEdgeColor(); + + HBRUSH getBackgroundBrush(); + HBRUSH getDlgBackgroundBrush(); + HBRUSH getCtrlBackgroundBrush(); + HBRUSH getHotBackgroundBrush(); + HBRUSH getErrorBackgroundBrush(); + + HBRUSH getEdgeBrush(); + HBRUSH getHotEdgeBrush(); + HBRUSH getDisabledEdgeBrush(); + + HPEN getDarkerTextPen(); + HPEN getEdgePen(); + HPEN getHotEdgePen(); + HPEN getDisabledEdgePen(); + + void setBackgroundColor(COLORREF c); + void setCtrlBackgroundColor(COLORREF c); + void setHotBackgroundColor(COLORREF c); + void setDlgBackgroundColor(COLORREF c); + void setErrorBackgroundColor(COLORREF c); + void setTextColor(COLORREF c); + void setDarkerTextColor(COLORREF c); + void setDisabledTextColor(COLORREF c); + void setLinkTextColor(COLORREF c); + void setEdgeColor(COLORREF c); + void setHotEdgeColor(COLORREF c); + void setDisabledEdgeColor(COLORREF c); + + Colors getDarkModeDefaultColors(ColorTone colorTone = ColorTone::blackTone); + void changeCustomTheme(const Colors& colors); + + // handle events + void handleSettingChange(HWND hwnd, LPARAM lParam, bool isFromBtn = false); + bool isDarkModeReg(); + + // processes messages related to UAH / custom menubar drawing. + // return true if handled, false to continue with normal processing in your wndproc + bool runUAHWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT* lr); + void drawUAHMenuNCBottomLine(HWND hWnd); + + // from DarkMode.h + void initExperimentalDarkMode(); + void setDarkMode(bool useDark, bool fixDarkScrollbar); + void allowDarkModeForApp(bool allow); + bool allowDarkModeForWindow(HWND hWnd, bool allow); + void setTitleBarThemeColor(HWND hWnd); + + // enhancements to DarkMode.h + void enableDarkScrollBarForWindowAndChildren(HWND hwnd); + + void paintRoundRect(HDC hdc, const RECT rect, const HPEN hpen, const HBRUSH hBrush, int width = 0, int height = 0); + inline void paintRoundFrameRect(HDC hdc, const RECT rect, const HPEN hpen, int width = 0, int height = 0); + + void subclassButtonControl(HWND hwnd); + void subclassGroupboxControl(HWND hwnd); + void subclassTabControl(HWND hwnd); + void subclassComboBoxControl(HWND hwnd); + + bool subclassTabUpDownControl(HWND hwnd); + + void subclassAndThemeButton(HWND hwnd, NppDarkModeParams p); + void subclassAndThemeComboBox(HWND hwnd, NppDarkModeParams p); + void subclassAndThemeListBoxOrEditControl(HWND hwnd, NppDarkModeParams p, bool isListBox); + void subclassAndThemeListView(HWND hwnd, NppDarkModeParams p); + void themeTreeView(HWND hwnd, NppDarkModeParams p); + void themeToolbar(HWND hwnd, NppDarkModeParams p); + void themeRichEdit(HWND hwnd, NppDarkModeParams p); + + void autoSubclassAndThemeChildControls(HWND hwndParent, bool subclass = true, bool theme = true); + void autoThemeChildControls(HWND hwndParent); + + void autoSubclassAndThemePluginDockWindow(HWND hwnd); + ULONG autoSubclassAndThemePlugin(HWND hwnd, ULONG dmFlags); + void autoSubclassCtlColor(HWND hWnd); + void autoSubclassAndThemeWindowNotify(HWND hwnd); + + void setDarkTitleBar(HWND hwnd); + void setDarkExplorerTheme(HWND hwnd); + void setDarkScrollBar(HWND hwnd); + void setDarkTooltips(HWND hwnd, ToolTipsType type); + void setDarkLineAbovePanelToolbar(HWND hwnd); + void setDarkListView(HWND hwnd); + + void disableVisualStyle(HWND hwnd, bool doDisable); + void calculateTreeViewStyle(); + void updateTreeViewStylePrev(); + TreeViewStyle getTreeViewStyle(); + void setTreeViewStyle(HWND hWnd, bool force = false); + bool isThemeDark(); + void setBorder(HWND hwnd, bool border = true); + + void setDarkAutoCompletion(); + + LRESULT onCtlColor(HDC hdc); + LRESULT onCtlColorCtrl(HDC hdc); + LRESULT onCtlColorDlg(HDC hdc); + LRESULT onCtlColorError(HDC hdc); + LRESULT onCtlColorDlgStaticText(HDC hdc, bool isTextEnabled); + LRESULT onCtlColorDlgLinkText(HDC hdc, bool isTextEnabled = true); + LRESULT onCtlColorListbox(WPARAM wParam, LPARAM lParam); +} diff --git a/NppPlugin/include/PluginInterface.h b/NppPlugin/include/PluginInterface.h index 38e53e21..b05ad1b9 100644 --- a/NppPlugin/include/PluginInterface.h +++ b/NppPlugin/include/PluginInterface.h @@ -1,33 +1,37 @@ -//this file is part of notepad++ -//Copyright (C)2003 Don HO ( donho@altern.org ) -// -//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 file is part of Notepad++ project +// Copyright (C)2025 Don HO + +// 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 3 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. +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + -#ifndef PLUGININTERFACE_H -#define PLUGININTERFACE_H -struct SCNotification; +// For more comprehensive information on plugin communication, please refer to the following resource: +// https://npp-user-manual.org/docs/plugin-communication/ -const int nbChar = 64; +#pragma once -typedef const TCHAR * (__cdecl * PFUNCGETNAME)(); +#include "Scintilla.h" +#include "Notepad_plus_msgs.h" -struct NppData { - HWND _nppHandle; - HWND _scintillaMainHandle; - HWND _scintillaSecondHandle; + +typedef const wchar_t * (__cdecl * PFUNCGETNAME)(); + +struct NppData +{ + HWND _nppHandle = nullptr; + HWND _scintillaMainHandle = nullptr; + HWND _scintillaSecondHandle = nullptr; }; typedef void (__cdecl * PFUNCSETINFO)(NppData); @@ -36,32 +40,34 @@ typedef void (__cdecl * PBENOTIFIED)(SCNotification *); typedef LRESULT (__cdecl * PMESSAGEPROC)(UINT Message, WPARAM wParam, LPARAM lParam); -struct ShortcutKey { - bool _isCtrl; - bool _isAlt; - bool _isShift; - UCHAR _key; +struct ShortcutKey +{ + bool _isCtrl = false; + bool _isAlt = false; + bool _isShift = false; + UCHAR _key = 0; }; -struct FuncItem { - TCHAR _itemName[nbChar]; - PFUNCPLUGINCMD _pFunc; - int _cmdID; - bool _init2Check; - ShortcutKey *_pShKey; +const int menuItemSize = 64; + +struct FuncItem +{ + wchar_t _itemName[menuItemSize] = { '\0' }; + PFUNCPLUGINCMD _pFunc = nullptr; + int _cmdID = 0; + bool _init2Check = false; + ShortcutKey *_pShKey = nullptr; }; typedef FuncItem * (__cdecl * PFUNCGETFUNCSARRAY)(int *); // You should implement (or define an empty function body) those functions which are called by Notepad++ plugin manager extern "C" __declspec(dllexport) void setInfo(NppData); -extern "C" __declspec(dllexport) const TCHAR * getName(); +extern "C" __declspec(dllexport) const wchar_t * getName(); extern "C" __declspec(dllexport) FuncItem * getFuncsArray(int *); extern "C" __declspec(dllexport) void beNotified(SCNotification *); extern "C" __declspec(dllexport) LRESULT messageProc(UINT Message, WPARAM wParam, LPARAM lParam); -#ifdef UNICODE +// This API return always true now, since Notepad++ isn't compiled in ANSI mode anymore extern "C" __declspec(dllexport) BOOL isUnicode(); -#endif //UNICODE -#endif //PLUGININTERFACE_H diff --git a/NppPlugin/include/PluginsManager.h b/NppPlugin/include/PluginsManager.h deleted file mode 100644 index 66770e09..00000000 --- a/NppPlugin/include/PluginsManager.h +++ /dev/null @@ -1,155 +0,0 @@ -//this file is part of notepad++ -//Copyright (C)2003 Don HO ( donho@altern.org ) -// -//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., 675 Mass Ave, Cambridge, MA 02139, USA. - -#ifndef PLUGINSMANAGER_H -#define PLUGINSMANAGER_H - -#include "resource.h" -#include "Parameters.h" -#include "PluginInterface.h" - -typedef BOOL (__cdecl * PFUNCISUNICODE)(); - -struct PluginCommand { - TCHAR _pluginName[64]; - int _funcID; - PFUNCPLUGINCMD _pFunc; - PluginCommand(const TCHAR *pluginName, int funcID, PFUNCPLUGINCMD pFunc): _funcID(funcID), _pFunc(pFunc){ - lstrcpy(_pluginName, pluginName); - }; -}; - -struct PluginInfo { - PluginInfo() :_hLib(NULL), _pluginMenu(NULL), _pFuncSetInfo(NULL),\ - _pFuncGetFuncsArray(NULL), _pFuncGetName(NULL), _funcItems(NULL),\ - _nbFuncItem(0){}; - ~PluginInfo(){ - if (_pluginMenu) - ::DestroyMenu(_pluginMenu); - - if (_hLib) - ::FreeLibrary(_hLib); - }; - - HINSTANCE _hLib; - HMENU _pluginMenu; - - PFUNCSETINFO _pFuncSetInfo; - PFUNCGETNAME _pFuncGetName; - PBENOTIFIED _pBeNotified; - PFUNCGETFUNCSARRAY _pFuncGetFuncsArray; - PMESSAGEPROC _pMessageProc; - PFUNCISUNICODE _pFuncIsUnicode; - - FuncItem *_funcItems; - int _nbFuncItem; - TCHAR _moduleName[64]; -}; - -class PluginsManager { -public: - PluginsManager() : _hPluginsMenu(NULL), _isDisabled(false) {}; - ~PluginsManager() { - - for (size_t i = 0 ; i < _pluginInfos.size() ; i++) - delete _pluginInfos[i]; - - if (_hPluginsMenu) - DestroyMenu(_hPluginsMenu); - }; - void init(const NppData & nppData) { - _nppData = nppData; - }; - bool loadPlugins(const TCHAR *dir = NULL); - - void runPluginCommand(size_t i) { - if (i < _pluginsCommands.size()) - if (_pluginsCommands[i]._pFunc != NULL) - _pluginsCommands[i]._pFunc(); - }; - - void runPluginCommand(const TCHAR *pluginName, int commandID) { - for (size_t i = 0 ; i < _pluginsCommands.size() ; i++) - { - if (!generic_stricmp(_pluginsCommands[i]._pluginName, pluginName)) - { - if (_pluginsCommands[i]._funcID == commandID) - _pluginsCommands[i]._pFunc(); - } - } - }; - - void setMenu(HMENU hMenu, const TCHAR *menuName); - bool getShortcutByCmdID(int cmdID, ShortcutKey *sk); - - void notify(SCNotification *notification) { - for (size_t i = 0 ; i < _pluginInfos.size() ; i++) - { - // To avoid the plugin change the data in SCNotification - // Each notification to pass to a plugin is a copy of SCNotification instance - SCNotification scNotif = *notification; - _pluginInfos[i]->_pBeNotified(&scNotif); - } - }; - - void relayNppMessages(UINT Message, WPARAM wParam, LPARAM lParam) { - for (size_t i = 0 ; i < _pluginInfos.size() ; i++) - { - _pluginInfos[i]->_pMessageProc(Message, wParam, lParam); - } - }; - - bool relayPluginMessages(UINT Message, WPARAM wParam, LPARAM lParam) { - const TCHAR * moduleName = (const TCHAR *)wParam; - if (!moduleName || !moduleName[0] || !lParam) - return false; - - for (size_t i = 0 ; i < _pluginInfos.size() ; i++) - { - if (generic_stricmp(_pluginInfos[i]->_moduleName, moduleName) == 0) - { - _pluginInfos[i]->_pMessageProc(Message, wParam, lParam); - return true; - } - } - return false; - }; - - HMENU getMenuHandle() { - return _hPluginsMenu; - }; - - void disable() {_isDisabled = true;}; - bool hasPlugins(){return (_pluginInfos.size()!= 0);}; - -private: - NppData _nppData; - HMENU _hPluginsMenu; - - vector _pluginInfos; - vector _pluginsCommands; - bool _isDisabled; -}; - -#define EXT_LEXER_DECL __stdcall - -// External Lexer function definitions... -typedef int (EXT_LEXER_DECL *GetLexerCountFn)(); -typedef void (EXT_LEXER_DECL *GetLexerNameFn)(unsigned int Index, char *name, int buflength); -typedef void (EXT_LEXER_DECL *GetLexerStatusTextFn)(unsigned int Index, TCHAR *desc, int buflength); - -#endif //PLUGINSMANAGER_H diff --git a/NppPlugin/include/SciLexer.h b/NppPlugin/include/SciLexer.h index 3aa2c385..820d92c0 100644 --- a/NppPlugin/include/SciLexer.h +++ b/NppPlugin/include/SciLexer.h @@ -112,6 +112,50 @@ #define SCLEX_SML 97 #define SCLEX_MARKDOWN 98 #define SCLEX_TXT2TAGS 99 +#define SCLEX_A68K 100 +#define SCLEX_MODULA 101 +#define SCLEX_COFFEESCRIPT 102 +#define SCLEX_TCMD 103 +#define SCLEX_AVS 104 +#define SCLEX_ECL 105 +#define SCLEX_OSCRIPT 106 +#define SCLEX_VISUALPROLOG 107 +#define SCLEX_LITERATEHASKELL 108 +#define SCLEX_STTXT 109 +#define SCLEX_KVIRC 110 +#define SCLEX_RUST 111 +#define SCLEX_DMAP 112 +#define SCLEX_AS 113 +#define SCLEX_DMIS 114 +#define SCLEX_REGISTRY 115 +#define SCLEX_BIBTEX 116 +#define SCLEX_SREC 117 +#define SCLEX_IHEX 118 +#define SCLEX_TEHEX 119 +#define SCLEX_JSON 120 +#define SCLEX_EDIFACT 121 +#define SCLEX_INDENT 122 +#define SCLEX_MAXIMA 123 +#define SCLEX_STATA 124 +#define SCLEX_SAS 125 +#define SCLEX_NIM 126 +#define SCLEX_CIL 127 +#define SCLEX_X12 128 +#define SCLEX_DATAFLEX 129 +#define SCLEX_HOLLYWOOD 130 +#define SCLEX_RAKU 131 +#define SCLEX_FSHARP 132 +#define SCLEX_JULIA 133 +#define SCLEX_ASCIIDOC 134 +#define SCLEX_GDSCRIPT 135 +#define SCLEX_TOML 136 +#define SCLEX_TROFF 137 +#define SCLEX_DART 138 +#define SCLEX_ZIG 139 +#define SCLEX_NIX 140 +#define SCLEX_SEARCHRESULT 150 +#define SCLEX_OBJC 151 +#define SCLEX_USER 152 #define SCLEX_AUTOMATIC 1000 #define SCE_P_DEFAULT 0 #define SCE_P_COMMENTLINE 1 @@ -129,6 +173,11 @@ #define SCE_P_STRINGEOL 13 #define SCE_P_WORD2 14 #define SCE_P_DECORATOR 15 +#define SCE_P_FSTRING 16 +#define SCE_P_FCHARACTER 17 +#define SCE_P_FTRIPLE 18 +#define SCE_P_FTRIPLEDOUBLE 19 +#define SCE_P_ATTRIBUTE 20 #define SCE_C_DEFAULT 0 #define SCE_C_COMMENT 1 #define SCE_C_COMMENTLINE 2 @@ -149,6 +198,27 @@ #define SCE_C_COMMENTDOCKEYWORD 17 #define SCE_C_COMMENTDOCKEYWORDERROR 18 #define SCE_C_GLOBALCLASS 19 +#define SCE_C_STRINGRAW 20 +#define SCE_C_TRIPLEVERBATIM 21 +#define SCE_C_HASHQUOTEDSTRING 22 +#define SCE_C_PREPROCESSORCOMMENT 23 +#define SCE_C_PREPROCESSORCOMMENTDOC 24 +#define SCE_C_USERLITERAL 25 +#define SCE_C_TASKMARKER 26 +#define SCE_C_ESCAPESEQUENCE 27 +#define SCE_COBOL_DEFAULT 0 +#define SCE_COBOL_COMMENT 1 +#define SCE_COBOL_COMMENTLINE 2 +#define SCE_COBOL_COMMENTDOC 3 +#define SCE_COBOL_NUMBER 4 +#define SCE_COBOL_WORD 5 +#define SCE_COBOL_STRING 6 +#define SCE_COBOL_CHARACTER 7 +#define SCE_COBOL_WORD3 8 +#define SCE_COBOL_PREPROCESSOR 9 +#define SCE_COBOL_OPERATOR 10 +#define SCE_COBOL_IDENTIFIER 11 +#define SCE_COBOL_WORD2 16 #define SCE_D_DEFAULT 0 #define SCE_D_COMMENT 1 #define SCE_D_COMMENTLINE 2 @@ -239,6 +309,7 @@ #define SCE_HJ_SYMBOLS 50 #define SCE_HJ_STRINGEOL 51 #define SCE_HJ_REGEX 52 +#define SCE_HJ_TEMPLATELITERAL 53 #define SCE_HJA_START 55 #define SCE_HJA_DEFAULT 56 #define SCE_HJA_COMMENT 57 @@ -252,6 +323,7 @@ #define SCE_HJA_SYMBOLS 65 #define SCE_HJA_STRINGEOL 66 #define SCE_HJA_REGEX 67 +#define SCE_HJA_TEMPLATELITERAL 68 #define SCE_HB_START 70 #define SCE_HB_DEFAULT 71 #define SCE_HB_COMMENTLINE 72 @@ -340,6 +412,16 @@ #define SCE_PL_SUB_PROTOTYPE 40 #define SCE_PL_FORMAT_IDENT 41 #define SCE_PL_FORMAT 42 +#define SCE_PL_STRING_VAR 43 +#define SCE_PL_XLAT 44 +#define SCE_PL_REGEX_VAR 54 +#define SCE_PL_REGSUBST_VAR 55 +#define SCE_PL_BACKTICKS_VAR 57 +#define SCE_PL_HERE_QQ_VAR 61 +#define SCE_PL_HERE_QX_VAR 62 +#define SCE_PL_STRING_QQ_VAR 64 +#define SCE_PL_STRING_QX_VAR 65 +#define SCE_PL_STRING_QR_VAR 66 #define SCE_RB_DEFAULT 0 #define SCE_RB_ERROR 1 #define SCE_RB_COMMENTLINE 2 @@ -373,7 +455,11 @@ #define SCE_RB_STDIN 30 #define SCE_RB_STDOUT 31 #define SCE_RB_STDERR 40 -#define SCE_RB_UPPER_BOUND 41 +#define SCE_RB_STRING_W 41 +#define SCE_RB_STRING_I 42 +#define SCE_RB_STRING_QI 43 +#define SCE_RB_STRING_QS 44 +#define SCE_RB_UPPER_BOUND 45 #define SCE_B_DEFAULT 0 #define SCE_B_COMMENT 1 #define SCE_B_NUMBER 2 @@ -393,6 +479,10 @@ #define SCE_B_ERROR 16 #define SCE_B_HEXNUMBER 17 #define SCE_B_BINNUMBER 18 +#define SCE_B_COMMENTBLOCK 19 +#define SCE_B_DOCLINE 20 +#define SCE_B_DOCBLOCK 21 +#define SCE_B_DOCKEYWORD 22 #define SCE_PROPS_DEFAULT 0 #define SCE_PROPS_COMMENT 1 #define SCE_PROPS_SECTION 2 @@ -404,6 +494,14 @@ #define SCE_L_TAG 2 #define SCE_L_MATH 3 #define SCE_L_COMMENT 4 +#define SCE_L_TAG2 5 +#define SCE_L_MATH2 6 +#define SCE_L_COMMENT2 7 +#define SCE_L_VERBATIM 8 +#define SCE_L_SHORTCMD 9 +#define SCE_L_SPECIAL 10 +#define SCE_L_CMDOPT 11 +#define SCE_L_ERROR 12 #define SCE_LUA_DEFAULT 0 #define SCE_LUA_COMMENT 1 #define SCE_LUA_COMMENTLINE 2 @@ -424,6 +522,7 @@ #define SCE_LUA_WORD6 17 #define SCE_LUA_WORD7 18 #define SCE_LUA_WORD8 19 +#define SCE_LUA_LABEL 20 #define SCE_ERR_DEFAULT 0 #define SCE_ERR_PYTHON 1 #define SCE_ERR_GCC 2 @@ -446,6 +545,27 @@ #define SCE_ERR_TIDY 19 #define SCE_ERR_JAVA_STACK 20 #define SCE_ERR_VALUE 21 +#define SCE_ERR_GCC_INCLUDED_FROM 22 +#define SCE_ERR_ESCSEQ 23 +#define SCE_ERR_ESCSEQ_UNKNOWN 24 +#define SCE_ERR_GCC_EXCERPT 25 +#define SCE_ERR_BASH 26 +#define SCE_ERR_ES_BLACK 40 +#define SCE_ERR_ES_RED 41 +#define SCE_ERR_ES_GREEN 42 +#define SCE_ERR_ES_BROWN 43 +#define SCE_ERR_ES_BLUE 44 +#define SCE_ERR_ES_MAGENTA 45 +#define SCE_ERR_ES_CYAN 46 +#define SCE_ERR_ES_GRAY 47 +#define SCE_ERR_ES_DARK_GRAY 48 +#define SCE_ERR_ES_BRIGHT_RED 49 +#define SCE_ERR_ES_BRIGHT_GREEN 50 +#define SCE_ERR_ES_YELLOW 51 +#define SCE_ERR_ES_BRIGHT_BLUE 52 +#define SCE_ERR_ES_BRIGHT_MAGENTA 53 +#define SCE_ERR_ES_BRIGHT_CYAN 54 +#define SCE_ERR_ES_WHITE 55 #define SCE_BAT_DEFAULT 0 #define SCE_BAT_COMMENT 1 #define SCE_BAT_WORD 2 @@ -454,6 +574,18 @@ #define SCE_BAT_COMMAND 5 #define SCE_BAT_IDENTIFIER 6 #define SCE_BAT_OPERATOR 7 +#define SCE_BAT_AFTER_LABEL 8 +#define SCE_TCMD_DEFAULT 0 +#define SCE_TCMD_COMMENT 1 +#define SCE_TCMD_WORD 2 +#define SCE_TCMD_LABEL 3 +#define SCE_TCMD_HIDE 4 +#define SCE_TCMD_COMMAND 5 +#define SCE_TCMD_IDENTIFIER 6 +#define SCE_TCMD_OPERATOR 7 +#define SCE_TCMD_ENVIRONMENT 8 +#define SCE_TCMD_EXPANSION 9 +#define SCE_TCMD_CLABEL 10 #define SCE_MAKE_DEFAULT 0 #define SCE_MAKE_COMMENT 1 #define SCE_MAKE_PREPROCESSOR 2 @@ -469,6 +601,10 @@ #define SCE_DIFF_DELETED 5 #define SCE_DIFF_ADDED 6 #define SCE_DIFF_CHANGED 7 +#define SCE_DIFF_PATCH_ADD 8 +#define SCE_DIFF_PATCH_DELETE 9 +#define SCE_DIFF_REMOVED_PATCH_ADD 10 +#define SCE_DIFF_REMOVED_PATCH_DELETE 11 #define SCE_CONF_DEFAULT 0 #define SCE_CONF_COMMENT 1 #define SCE_CONF_NUMBER 2 @@ -517,6 +653,20 @@ #define SCE_BAAN_IDENTIFIER 8 #define SCE_BAAN_STRINGEOL 9 #define SCE_BAAN_WORD2 10 +#define SCE_BAAN_WORD3 11 +#define SCE_BAAN_WORD4 12 +#define SCE_BAAN_WORD5 13 +#define SCE_BAAN_WORD6 14 +#define SCE_BAAN_WORD7 15 +#define SCE_BAAN_WORD8 16 +#define SCE_BAAN_WORD9 17 +#define SCE_BAAN_TABLEDEF 18 +#define SCE_BAAN_TABLESQL 19 +#define SCE_BAAN_FUNCTION 20 +#define SCE_BAAN_DOMDEF 21 +#define SCE_BAAN_FUNCDEF 22 +#define SCE_BAAN_OBJECTDEF 23 +#define SCE_BAAN_DEFINEDEF 24 #define SCE_LISP_DEFAULT 0 #define SCE_LISP_COMMENT 1 #define SCE_LISP_NUMBER 2 @@ -570,6 +720,14 @@ #define SCE_MATLAB_OPERATOR 6 #define SCE_MATLAB_IDENTIFIER 7 #define SCE_MATLAB_DOUBLEQUOTESTRING 8 +#define SCE_MAXIMA_OPERATOR 0 +#define SCE_MAXIMA_COMMANDENDING 1 +#define SCE_MAXIMA_COMMENT 2 +#define SCE_MAXIMA_NUMBER 3 +#define SCE_MAXIMA_STRING 4 +#define SCE_MAXIMA_COMMAND 5 +#define SCE_MAXIMA_VARIABLE 6 +#define SCE_MAXIMA_UNKNOWN 7 #define SCE_SCRIPTOL_DEFAULT 0 #define SCE_SCRIPTOL_WHITE 1 #define SCE_SCRIPTOL_COMMENTLINE 2 @@ -601,6 +759,7 @@ #define SCE_ASM_CHARACTER 12 #define SCE_ASM_STRINGEOL 13 #define SCE_ASM_EXTINSTRUCTION 14 +#define SCE_ASM_COMMENTDIRECTIVE 15 #define SCE_F_DEFAULT 0 #define SCE_F_COMMENT 1 #define SCE_F_NUMBER 2 @@ -638,7 +797,8 @@ #define SCE_CSS_EXTENDED_IDENTIFIER 19 #define SCE_CSS_EXTENDED_PSEUDOCLASS 20 #define SCE_CSS_EXTENDED_PSEUDOELEMENT 21 -#define SCE_CSS_MEDIA 22 +#define SCE_CSS_GROUP_RULE 22 +#define SCE_CSS_VARIABLE 23 #define SCE_POV_DEFAULT 0 #define SCE_POV_COMMENT 1 #define SCE_POV_COMMENTLINE 2 @@ -805,6 +965,28 @@ #define SCE_ERLANG_MODULES 23 #define SCE_ERLANG_MODULES_ATT 24 #define SCE_ERLANG_UNKNOWN 31 +#define SCE_JULIA_DEFAULT 0 +#define SCE_JULIA_COMMENT 1 +#define SCE_JULIA_NUMBER 2 +#define SCE_JULIA_KEYWORD1 3 +#define SCE_JULIA_KEYWORD2 4 +#define SCE_JULIA_KEYWORD3 5 +#define SCE_JULIA_CHAR 6 +#define SCE_JULIA_OPERATOR 7 +#define SCE_JULIA_BRACKET 8 +#define SCE_JULIA_IDENTIFIER 9 +#define SCE_JULIA_STRING 10 +#define SCE_JULIA_SYMBOL 11 +#define SCE_JULIA_MACRO 12 +#define SCE_JULIA_STRINGINTERP 13 +#define SCE_JULIA_DOCSTRING 14 +#define SCE_JULIA_STRINGLITERAL 15 +#define SCE_JULIA_COMMAND 16 +#define SCE_JULIA_COMMANDLITERAL 17 +#define SCE_JULIA_TYPEANNOT 18 +#define SCE_JULIA_LEXERROR 19 +#define SCE_JULIA_KEYWORD4 20 +#define SCE_JULIA_TYPEOPERATOR 21 #define SCE_MSSQL_DEFAULT 0 #define SCE_MSSQL_COMMENT 1 #define SCE_MSSQL_LINE_COMMENT 2 @@ -836,6 +1018,11 @@ #define SCE_V_IDENTIFIER 11 #define SCE_V_STRINGEOL 12 #define SCE_V_USER 19 +#define SCE_V_COMMENT_WORD 20 +#define SCE_V_INPUT 21 +#define SCE_V_OUTPUT 22 +#define SCE_V_INOUT 23 +#define SCE_V_PORT_CONNECT 24 #define SCE_KIX_DEFAULT 0 #define SCE_KIX_COMMENT 1 #define SCE_KIX_STRING1 2 @@ -846,6 +1033,7 @@ #define SCE_KIX_KEYWORD 7 #define SCE_KIX_FUNCTIONS 8 #define SCE_KIX_OPERATOR 9 +#define SCE_KIX_COMMENTSTREAM 10 #define SCE_KIX_IDENTIFIER 31 #define SCE_GC_DEFAULT 0 #define SCE_GC_COMMENTLINE 1 @@ -942,6 +1130,7 @@ #define SCE_VHDL_STDPACKAGE 12 #define SCE_VHDL_STDTYPE 13 #define SCE_VHDL_USERWORD 14 +#define SCE_VHDL_BLOCK_COMMENT 15 #define SCE_CAML_DEFAULT 0 #define SCE_CAML_IDENTIFIER 1 #define SCE_CAML_TAGNAME 2 @@ -975,6 +1164,12 @@ #define SCE_HA_COMMENTBLOCK 14 #define SCE_HA_COMMENTBLOCK2 15 #define SCE_HA_COMMENTBLOCK3 16 +#define SCE_HA_PRAGMA 17 +#define SCE_HA_PREPROCESSOR 18 +#define SCE_HA_STRINGEOL 19 +#define SCE_HA_RESERVED_OPERATOR 20 +#define SCE_HA_LITERATE_COMMENT 21 +#define SCE_HA_LITERATE_CODEDELIM 22 #define SCE_T3_DEFAULT 0 #define SCE_T3_X_DEFAULT 1 #define SCE_T3_PREPROCESSOR 2 @@ -1047,6 +1242,7 @@ #define SCE_SQL_USER3 21 #define SCE_SQL_USER4 22 #define SCE_SQL_QUOTEDIDENTIFIER 23 +#define SCE_SQL_QOPERATOR 24 #define SCE_ST_DEFAULT 0 #define SCE_ST_STRING 1 #define SCE_ST_NUMBER 2 @@ -1179,38 +1375,19 @@ #define SCE_PLM_OPERATOR 5 #define SCE_PLM_CONTROL 6 #define SCE_PLM_KEYWORD 7 -#define SCE_4GL_DEFAULT 0 -#define SCE_4GL_NUMBER 1 -#define SCE_4GL_WORD 2 -#define SCE_4GL_STRING 3 -#define SCE_4GL_CHARACTER 4 -#define SCE_4GL_PREPROCESSOR 5 -#define SCE_4GL_OPERATOR 6 -#define SCE_4GL_IDENTIFIER 7 -#define SCE_4GL_BLOCK 8 -#define SCE_4GL_END 9 -#define SCE_4GL_COMMENT1 10 -#define SCE_4GL_COMMENT2 11 -#define SCE_4GL_COMMENT3 12 -#define SCE_4GL_COMMENT4 13 -#define SCE_4GL_COMMENT5 14 -#define SCE_4GL_COMMENT6 15 -#define SCE_4GL_DEFAULT_ 16 -#define SCE_4GL_NUMBER_ 17 -#define SCE_4GL_WORD_ 18 -#define SCE_4GL_STRING_ 19 -#define SCE_4GL_CHARACTER_ 20 -#define SCE_4GL_PREPROCESSOR_ 21 -#define SCE_4GL_OPERATOR_ 22 -#define SCE_4GL_IDENTIFIER_ 23 -#define SCE_4GL_BLOCK_ 24 -#define SCE_4GL_END_ 25 -#define SCE_4GL_COMMENT1_ 26 -#define SCE_4GL_COMMENT2_ 27 -#define SCE_4GL_COMMENT3_ 28 -#define SCE_4GL_COMMENT4_ 29 -#define SCE_4GL_COMMENT5_ 30 -#define SCE_4GL_COMMENT6_ 31 +#define SCE_ABL_DEFAULT 0 +#define SCE_ABL_NUMBER 1 +#define SCE_ABL_WORD 2 +#define SCE_ABL_STRING 3 +#define SCE_ABL_CHARACTER 4 +#define SCE_ABL_PREPROCESSOR 5 +#define SCE_ABL_OPERATOR 6 +#define SCE_ABL_IDENTIFIER 7 +#define SCE_ABL_BLOCK 8 +#define SCE_ABL_END 9 +#define SCE_ABL_COMMENT 10 +#define SCE_ABL_TASKMARKER 11 +#define SCE_ABL_LINECOMMENT 12 #define SCE_ABAQUS_DEFAULT 0 #define SCE_ABAQUS_COMMENT 1 #define SCE_ABAQUS_COMMENTBLOCK 2 @@ -1248,6 +1425,10 @@ #define SCE_R_IDENTIFIER 9 #define SCE_R_INFIX 10 #define SCE_R_INFIXEOL 11 +#define SCE_R_BACKTICKS 12 +#define SCE_R_RAWSTRING 13 +#define SCE_R_RAWSTRING2 14 +#define SCE_R_ESCAPESEQUENCE 15 #define SCE_MAGIK_DEFAULT 0 #define SCE_MAGIK_COMMENT 1 #define SCE_MAGIK_HYPER_COMMENT 16 @@ -1279,6 +1460,9 @@ #define SCE_POWERSHELL_FUNCTION 11 #define SCE_POWERSHELL_USER1 12 #define SCE_POWERSHELL_COMMENTSTREAM 13 +#define SCE_POWERSHELL_HERE_STRING 14 +#define SCE_POWERSHELL_HERE_CHARACTER 15 +#define SCE_POWERSHELL_COMMENTDOCKEYWORD 16 #define SCE_MYSQL_DEFAULT 0 #define SCE_MYSQL_COMMENT 1 #define SCE_MYSQL_COMMENTLINE 2 @@ -1301,6 +1485,7 @@ #define SCE_MYSQL_USER2 19 #define SCE_MYSQL_USER3 20 #define SCE_MYSQL_HIDDENCOMMAND 21 +#define SCE_MYSQL_PLACEHOLDER 22 #define SCE_PO_DEFAULT 0 #define SCE_PO_COMMENT 1 #define SCE_PO_MSGID 2 @@ -1310,6 +1495,13 @@ #define SCE_PO_MSGCTXT 6 #define SCE_PO_MSGCTXT_TEXT 7 #define SCE_PO_FUZZY 8 +#define SCE_PO_PROGRAMMER_COMMENT 9 +#define SCE_PO_REFERENCE 10 +#define SCE_PO_FLAGS 11 +#define SCE_PO_MSGID_TEXT_EOL 12 +#define SCE_PO_MSGSTR_TEXT_EOL 13 +#define SCE_PO_MSGCTXT_TEXT_EOL 14 +#define SCE_PO_ERROR 15 #define SCE_PAS_DEFAULT 0 #define SCE_PAS_IDENTIFIER 1 #define SCE_PAS_COMMENT 2 @@ -1415,6 +1607,713 @@ #define SCE_TXT2TAGS_OPTION 23 #define SCE_TXT2TAGS_PREPROC 24 #define SCE_TXT2TAGS_POSTPROC 25 +#define SCE_A68K_DEFAULT 0 +#define SCE_A68K_COMMENT 1 +#define SCE_A68K_NUMBER_DEC 2 +#define SCE_A68K_NUMBER_BIN 3 +#define SCE_A68K_NUMBER_HEX 4 +#define SCE_A68K_STRING1 5 +#define SCE_A68K_OPERATOR 6 +#define SCE_A68K_CPUINSTRUCTION 7 +#define SCE_A68K_EXTINSTRUCTION 8 +#define SCE_A68K_REGISTER 9 +#define SCE_A68K_DIRECTIVE 10 +#define SCE_A68K_MACRO_ARG 11 +#define SCE_A68K_LABEL 12 +#define SCE_A68K_STRING2 13 +#define SCE_A68K_IDENTIFIER 14 +#define SCE_A68K_MACRO_DECLARATION 15 +#define SCE_A68K_COMMENT_WORD 16 +#define SCE_A68K_COMMENT_SPECIAL 17 +#define SCE_A68K_COMMENT_DOXYGEN 18 +#define SCE_MODULA_DEFAULT 0 +#define SCE_MODULA_COMMENT 1 +#define SCE_MODULA_DOXYCOMM 2 +#define SCE_MODULA_DOXYKEY 3 +#define SCE_MODULA_KEYWORD 4 +#define SCE_MODULA_RESERVED 5 +#define SCE_MODULA_NUMBER 6 +#define SCE_MODULA_BASENUM 7 +#define SCE_MODULA_FLOAT 8 +#define SCE_MODULA_STRING 9 +#define SCE_MODULA_STRSPEC 10 +#define SCE_MODULA_CHAR 11 +#define SCE_MODULA_CHARSPEC 12 +#define SCE_MODULA_PROC 13 +#define SCE_MODULA_PRAGMA 14 +#define SCE_MODULA_PRGKEY 15 +#define SCE_MODULA_OPERATOR 16 +#define SCE_MODULA_BADSTR 17 +#define SCE_COFFEESCRIPT_DEFAULT 0 +#define SCE_COFFEESCRIPT_COMMENT 1 +#define SCE_COFFEESCRIPT_COMMENTLINE 2 +#define SCE_COFFEESCRIPT_COMMENTDOC 3 +#define SCE_COFFEESCRIPT_NUMBER 4 +#define SCE_COFFEESCRIPT_WORD 5 +#define SCE_COFFEESCRIPT_STRING 6 +#define SCE_COFFEESCRIPT_CHARACTER 7 +#define SCE_COFFEESCRIPT_UUID 8 +#define SCE_COFFEESCRIPT_PREPROCESSOR 9 +#define SCE_COFFEESCRIPT_OPERATOR 10 +#define SCE_COFFEESCRIPT_IDENTIFIER 11 +#define SCE_COFFEESCRIPT_STRINGEOL 12 +#define SCE_COFFEESCRIPT_VERBATIM 13 +#define SCE_COFFEESCRIPT_REGEX 14 +#define SCE_COFFEESCRIPT_COMMENTLINEDOC 15 +#define SCE_COFFEESCRIPT_WORD2 16 +#define SCE_COFFEESCRIPT_COMMENTDOCKEYWORD 17 +#define SCE_COFFEESCRIPT_COMMENTDOCKEYWORDERROR 18 +#define SCE_COFFEESCRIPT_GLOBALCLASS 19 +#define SCE_COFFEESCRIPT_STRINGRAW 20 +#define SCE_COFFEESCRIPT_TRIPLEVERBATIM 21 +#define SCE_COFFEESCRIPT_COMMENTBLOCK 22 +#define SCE_COFFEESCRIPT_VERBOSE_REGEX 23 +#define SCE_COFFEESCRIPT_VERBOSE_REGEX_COMMENT 24 +#define SCE_COFFEESCRIPT_INSTANCEPROPERTY 25 +#define SCE_AVS_DEFAULT 0 +#define SCE_AVS_COMMENTBLOCK 1 +#define SCE_AVS_COMMENTBLOCKN 2 +#define SCE_AVS_COMMENTLINE 3 +#define SCE_AVS_NUMBER 4 +#define SCE_AVS_OPERATOR 5 +#define SCE_AVS_IDENTIFIER 6 +#define SCE_AVS_STRING 7 +#define SCE_AVS_TRIPLESTRING 8 +#define SCE_AVS_KEYWORD 9 +#define SCE_AVS_FILTER 10 +#define SCE_AVS_PLUGIN 11 +#define SCE_AVS_FUNCTION 12 +#define SCE_AVS_CLIPPROP 13 +#define SCE_AVS_USERDFN 14 +#define SCE_ECL_DEFAULT 0 +#define SCE_ECL_COMMENT 1 +#define SCE_ECL_COMMENTLINE 2 +#define SCE_ECL_NUMBER 3 +#define SCE_ECL_STRING 4 +#define SCE_ECL_WORD0 5 +#define SCE_ECL_OPERATOR 6 +#define SCE_ECL_CHARACTER 7 +#define SCE_ECL_UUID 8 +#define SCE_ECL_PREPROCESSOR 9 +#define SCE_ECL_UNKNOWN 10 +#define SCE_ECL_IDENTIFIER 11 +#define SCE_ECL_STRINGEOL 12 +#define SCE_ECL_VERBATIM 13 +#define SCE_ECL_REGEX 14 +#define SCE_ECL_COMMENTLINEDOC 15 +#define SCE_ECL_WORD1 16 +#define SCE_ECL_COMMENTDOCKEYWORD 17 +#define SCE_ECL_COMMENTDOCKEYWORDERROR 18 +#define SCE_ECL_WORD2 19 +#define SCE_ECL_WORD3 20 +#define SCE_ECL_WORD4 21 +#define SCE_ECL_WORD5 22 +#define SCE_ECL_COMMENTDOC 23 +#define SCE_ECL_ADDED 24 +#define SCE_ECL_DELETED 25 +#define SCE_ECL_CHANGED 26 +#define SCE_ECL_MOVED 27 +#define SCE_OSCRIPT_DEFAULT 0 +#define SCE_OSCRIPT_LINE_COMMENT 1 +#define SCE_OSCRIPT_BLOCK_COMMENT 2 +#define SCE_OSCRIPT_DOC_COMMENT 3 +#define SCE_OSCRIPT_PREPROCESSOR 4 +#define SCE_OSCRIPT_NUMBER 5 +#define SCE_OSCRIPT_SINGLEQUOTE_STRING 6 +#define SCE_OSCRIPT_DOUBLEQUOTE_STRING 7 +#define SCE_OSCRIPT_CONSTANT 8 +#define SCE_OSCRIPT_IDENTIFIER 9 +#define SCE_OSCRIPT_GLOBAL 10 +#define SCE_OSCRIPT_KEYWORD 11 +#define SCE_OSCRIPT_OPERATOR 12 +#define SCE_OSCRIPT_LABEL 13 +#define SCE_OSCRIPT_TYPE 14 +#define SCE_OSCRIPT_FUNCTION 15 +#define SCE_OSCRIPT_OBJECT 16 +#define SCE_OSCRIPT_PROPERTY 17 +#define SCE_OSCRIPT_METHOD 18 +#define SCE_VISUALPROLOG_DEFAULT 0 +#define SCE_VISUALPROLOG_KEY_MAJOR 1 +#define SCE_VISUALPROLOG_KEY_MINOR 2 +#define SCE_VISUALPROLOG_KEY_DIRECTIVE 3 +#define SCE_VISUALPROLOG_COMMENT_BLOCK 4 +#define SCE_VISUALPROLOG_COMMENT_LINE 5 +#define SCE_VISUALPROLOG_COMMENT_KEY 6 +#define SCE_VISUALPROLOG_COMMENT_KEY_ERROR 7 +#define SCE_VISUALPROLOG_IDENTIFIER 8 +#define SCE_VISUALPROLOG_VARIABLE 9 +#define SCE_VISUALPROLOG_ANONYMOUS 10 +#define SCE_VISUALPROLOG_NUMBER 11 +#define SCE_VISUALPROLOG_OPERATOR 12 +#define SCE_VISUALPROLOG_UNUSED1 13 +#define SCE_VISUALPROLOG_UNUSED2 14 +#define SCE_VISUALPROLOG_UNUSED3 15 +#define SCE_VISUALPROLOG_STRING_QUOTE 16 +#define SCE_VISUALPROLOG_STRING_ESCAPE 17 +#define SCE_VISUALPROLOG_STRING_ESCAPE_ERROR 18 +#define SCE_VISUALPROLOG_UNUSED4 19 +#define SCE_VISUALPROLOG_STRING 20 +#define SCE_VISUALPROLOG_UNUSED5 21 +#define SCE_VISUALPROLOG_STRING_EOL 22 +#define SCE_VISUALPROLOG_EMBEDDED 23 +#define SCE_VISUALPROLOG_PLACEHOLDER 24 +#define SCE_STTXT_DEFAULT 0 +#define SCE_STTXT_COMMENT 1 +#define SCE_STTXT_COMMENTLINE 2 +#define SCE_STTXT_KEYWORD 3 +#define SCE_STTXT_TYPE 4 +#define SCE_STTXT_FUNCTION 5 +#define SCE_STTXT_FB 6 +#define SCE_STTXT_NUMBER 7 +#define SCE_STTXT_HEXNUMBER 8 +#define SCE_STTXT_PRAGMA 9 +#define SCE_STTXT_OPERATOR 10 +#define SCE_STTXT_CHARACTER 11 +#define SCE_STTXT_STRING1 12 +#define SCE_STTXT_STRING2 13 +#define SCE_STTXT_STRINGEOL 14 +#define SCE_STTXT_IDENTIFIER 15 +#define SCE_STTXT_DATETIME 16 +#define SCE_STTXT_VARS 17 +#define SCE_STTXT_PRAGMAS 18 +#define SCE_KVIRC_DEFAULT 0 +#define SCE_KVIRC_COMMENT 1 +#define SCE_KVIRC_COMMENTBLOCK 2 +#define SCE_KVIRC_STRING 3 +#define SCE_KVIRC_WORD 4 +#define SCE_KVIRC_KEYWORD 5 +#define SCE_KVIRC_FUNCTION_KEYWORD 6 +#define SCE_KVIRC_FUNCTION 7 +#define SCE_KVIRC_VARIABLE 8 +#define SCE_KVIRC_NUMBER 9 +#define SCE_KVIRC_OPERATOR 10 +#define SCE_KVIRC_STRING_FUNCTION 11 +#define SCE_KVIRC_STRING_VARIABLE 12 +#define SCE_RUST_DEFAULT 0 +#define SCE_RUST_COMMENTBLOCK 1 +#define SCE_RUST_COMMENTLINE 2 +#define SCE_RUST_COMMENTBLOCKDOC 3 +#define SCE_RUST_COMMENTLINEDOC 4 +#define SCE_RUST_NUMBER 5 +#define SCE_RUST_WORD 6 +#define SCE_RUST_WORD2 7 +#define SCE_RUST_WORD3 8 +#define SCE_RUST_WORD4 9 +#define SCE_RUST_WORD5 10 +#define SCE_RUST_WORD6 11 +#define SCE_RUST_WORD7 12 +#define SCE_RUST_STRING 13 +#define SCE_RUST_STRINGR 14 +#define SCE_RUST_CHARACTER 15 +#define SCE_RUST_OPERATOR 16 +#define SCE_RUST_IDENTIFIER 17 +#define SCE_RUST_LIFETIME 18 +#define SCE_RUST_MACRO 19 +#define SCE_RUST_LEXERROR 20 +#define SCE_RUST_BYTESTRING 21 +#define SCE_RUST_BYTESTRINGR 22 +#define SCE_RUST_BYTECHARACTER 23 +#define SCE_RUST_CSTRING 24 +#define SCE_RUST_CSTRINGR 25 +#define SCE_DMAP_DEFAULT 0 +#define SCE_DMAP_COMMENT 1 +#define SCE_DMAP_NUMBER 2 +#define SCE_DMAP_STRING1 3 +#define SCE_DMAP_STRING2 4 +#define SCE_DMAP_STRINGEOL 5 +#define SCE_DMAP_OPERATOR 6 +#define SCE_DMAP_IDENTIFIER 7 +#define SCE_DMAP_WORD 8 +#define SCE_DMAP_WORD2 9 +#define SCE_DMAP_WORD3 10 +#define SCE_DMIS_DEFAULT 0 +#define SCE_DMIS_COMMENT 1 +#define SCE_DMIS_STRING 2 +#define SCE_DMIS_NUMBER 3 +#define SCE_DMIS_KEYWORD 4 +#define SCE_DMIS_MAJORWORD 5 +#define SCE_DMIS_MINORWORD 6 +#define SCE_DMIS_UNSUPPORTED_MAJOR 7 +#define SCE_DMIS_UNSUPPORTED_MINOR 8 +#define SCE_DMIS_LABEL 9 +#define SCE_REG_DEFAULT 0 +#define SCE_REG_COMMENT 1 +#define SCE_REG_VALUENAME 2 +#define SCE_REG_STRING 3 +#define SCE_REG_HEXDIGIT 4 +#define SCE_REG_VALUETYPE 5 +#define SCE_REG_ADDEDKEY 6 +#define SCE_REG_DELETEDKEY 7 +#define SCE_REG_ESCAPED 8 +#define SCE_REG_KEYPATH_GUID 9 +#define SCE_REG_STRING_GUID 10 +#define SCE_REG_PARAMETER 11 +#define SCE_REG_OPERATOR 12 +#define SCE_BIBTEX_DEFAULT 0 +#define SCE_BIBTEX_ENTRY 1 +#define SCE_BIBTEX_UNKNOWN_ENTRY 2 +#define SCE_BIBTEX_KEY 3 +#define SCE_BIBTEX_PARAMETER 4 +#define SCE_BIBTEX_VALUE 5 +#define SCE_BIBTEX_COMMENT 6 +#define SCE_HEX_DEFAULT 0 +#define SCE_HEX_RECSTART 1 +#define SCE_HEX_RECTYPE 2 +#define SCE_HEX_RECTYPE_UNKNOWN 3 +#define SCE_HEX_BYTECOUNT 4 +#define SCE_HEX_BYTECOUNT_WRONG 5 +#define SCE_HEX_NOADDRESS 6 +#define SCE_HEX_DATAADDRESS 7 +#define SCE_HEX_RECCOUNT 8 +#define SCE_HEX_STARTADDRESS 9 +#define SCE_HEX_ADDRESSFIELD_UNKNOWN 10 +#define SCE_HEX_EXTENDEDADDRESS 11 +#define SCE_HEX_DATA_ODD 12 +#define SCE_HEX_DATA_EVEN 13 +#define SCE_HEX_DATA_UNKNOWN 14 +#define SCE_HEX_DATA_EMPTY 15 +#define SCE_HEX_CHECKSUM 16 +#define SCE_HEX_CHECKSUM_WRONG 17 +#define SCE_HEX_GARBAGE 18 +#define SCE_JSON_DEFAULT 0 +#define SCE_JSON_NUMBER 1 +#define SCE_JSON_STRING 2 +#define SCE_JSON_STRINGEOL 3 +#define SCE_JSON_PROPERTYNAME 4 +#define SCE_JSON_ESCAPESEQUENCE 5 +#define SCE_JSON_LINECOMMENT 6 +#define SCE_JSON_BLOCKCOMMENT 7 +#define SCE_JSON_OPERATOR 8 +#define SCE_JSON_URI 9 +#define SCE_JSON_COMPACTIRI 10 +#define SCE_JSON_KEYWORD 11 +#define SCE_JSON_LDKEYWORD 12 +#define SCE_JSON_ERROR 13 +#define SCE_EDI_DEFAULT 0 +#define SCE_EDI_SEGMENTSTART 1 +#define SCE_EDI_SEGMENTEND 2 +#define SCE_EDI_SEP_ELEMENT 3 +#define SCE_EDI_SEP_COMPOSITE 4 +#define SCE_EDI_SEP_RELEASE 5 +#define SCE_EDI_UNA 6 +#define SCE_EDI_UNH 7 +#define SCE_EDI_BADSEGMENT 8 +#define SCE_STATA_DEFAULT 0 +#define SCE_STATA_COMMENT 1 +#define SCE_STATA_COMMENTLINE 2 +#define SCE_STATA_COMMENTBLOCK 3 +#define SCE_STATA_NUMBER 4 +#define SCE_STATA_OPERATOR 5 +#define SCE_STATA_IDENTIFIER 6 +#define SCE_STATA_STRING 7 +#define SCE_STATA_TYPE 8 +#define SCE_STATA_WORD 9 +#define SCE_STATA_GLOBAL_MACRO 10 +#define SCE_STATA_MACRO 11 +#define SCE_SAS_DEFAULT 0 +#define SCE_SAS_COMMENT 1 +#define SCE_SAS_COMMENTLINE 2 +#define SCE_SAS_COMMENTBLOCK 3 +#define SCE_SAS_NUMBER 4 +#define SCE_SAS_OPERATOR 5 +#define SCE_SAS_IDENTIFIER 6 +#define SCE_SAS_STRING 7 +#define SCE_SAS_TYPE 8 +#define SCE_SAS_WORD 9 +#define SCE_SAS_GLOBAL_MACRO 10 +#define SCE_SAS_MACRO 11 +#define SCE_SAS_MACRO_KEYWORD 12 +#define SCE_SAS_BLOCK_KEYWORD 13 +#define SCE_SAS_MACRO_FUNCTION 14 +#define SCE_SAS_STATEMENT 15 +#define SCE_NIM_DEFAULT 0 +#define SCE_NIM_COMMENT 1 +#define SCE_NIM_COMMENTDOC 2 +#define SCE_NIM_COMMENTLINE 3 +#define SCE_NIM_COMMENTLINEDOC 4 +#define SCE_NIM_NUMBER 5 +#define SCE_NIM_STRING 6 +#define SCE_NIM_CHARACTER 7 +#define SCE_NIM_WORD 8 +#define SCE_NIM_TRIPLE 9 +#define SCE_NIM_TRIPLEDOUBLE 10 +#define SCE_NIM_BACKTICKS 11 +#define SCE_NIM_FUNCNAME 12 +#define SCE_NIM_STRINGEOL 13 +#define SCE_NIM_NUMERROR 14 +#define SCE_NIM_OPERATOR 15 +#define SCE_NIM_IDENTIFIER 16 +#define SCE_CIL_DEFAULT 0 +#define SCE_CIL_COMMENT 1 +#define SCE_CIL_COMMENTLINE 2 +#define SCE_CIL_WORD 3 +#define SCE_CIL_WORD2 4 +#define SCE_CIL_WORD3 5 +#define SCE_CIL_STRING 6 +#define SCE_CIL_LABEL 7 +#define SCE_CIL_OPERATOR 8 +#define SCE_CIL_IDENTIFIER 9 +#define SCE_CIL_STRINGEOL 10 +#define SCE_X12_DEFAULT 0 +#define SCE_X12_BAD 1 +#define SCE_X12_ENVELOPE 2 +#define SCE_X12_FUNCTIONGROUP 3 +#define SCE_X12_TRANSACTIONSET 4 +#define SCE_X12_SEGMENTHEADER 5 +#define SCE_X12_SEGMENTEND 6 +#define SCE_X12_SEP_ELEMENT 7 +#define SCE_X12_SEP_SUBELEMENT 8 +#define SCE_DF_DEFAULT 0 +#define SCE_DF_IDENTIFIER 1 +#define SCE_DF_METATAG 2 +#define SCE_DF_IMAGE 3 +#define SCE_DF_COMMENTLINE 4 +#define SCE_DF_PREPROCESSOR 5 +#define SCE_DF_PREPROCESSOR2 6 +#define SCE_DF_NUMBER 7 +#define SCE_DF_HEXNUMBER 8 +#define SCE_DF_WORD 9 +#define SCE_DF_STRING 10 +#define SCE_DF_STRINGEOL 11 +#define SCE_DF_SCOPEWORD 12 +#define SCE_DF_OPERATOR 13 +#define SCE_DF_ICODE 14 +#define SCE_HOLLYWOOD_DEFAULT 0 +#define SCE_HOLLYWOOD_COMMENT 1 +#define SCE_HOLLYWOOD_COMMENTBLOCK 2 +#define SCE_HOLLYWOOD_NUMBER 3 +#define SCE_HOLLYWOOD_KEYWORD 4 +#define SCE_HOLLYWOOD_STDAPI 5 +#define SCE_HOLLYWOOD_PLUGINAPI 6 +#define SCE_HOLLYWOOD_PLUGINMETHOD 7 +#define SCE_HOLLYWOOD_STRING 8 +#define SCE_HOLLYWOOD_STRINGBLOCK 9 +#define SCE_HOLLYWOOD_PREPROCESSOR 10 +#define SCE_HOLLYWOOD_OPERATOR 11 +#define SCE_HOLLYWOOD_IDENTIFIER 12 +#define SCE_HOLLYWOOD_CONSTANT 13 +#define SCE_HOLLYWOOD_HEXNUMBER 14 +#define SCE_RAKU_DEFAULT 0 +#define SCE_RAKU_ERROR 1 +#define SCE_RAKU_COMMENTLINE 2 +#define SCE_RAKU_COMMENTEMBED 3 +#define SCE_RAKU_POD 4 +#define SCE_RAKU_CHARACTER 5 +#define SCE_RAKU_HEREDOC_Q 6 +#define SCE_RAKU_HEREDOC_QQ 7 +#define SCE_RAKU_STRING 8 +#define SCE_RAKU_STRING_Q 9 +#define SCE_RAKU_STRING_QQ 10 +#define SCE_RAKU_STRING_Q_LANG 11 +#define SCE_RAKU_STRING_VAR 12 +#define SCE_RAKU_REGEX 13 +#define SCE_RAKU_REGEX_VAR 14 +#define SCE_RAKU_ADVERB 15 +#define SCE_RAKU_NUMBER 16 +#define SCE_RAKU_PREPROCESSOR 17 +#define SCE_RAKU_OPERATOR 18 +#define SCE_RAKU_WORD 19 +#define SCE_RAKU_FUNCTION 20 +#define SCE_RAKU_IDENTIFIER 21 +#define SCE_RAKU_TYPEDEF 22 +#define SCE_RAKU_MU 23 +#define SCE_RAKU_POSITIONAL 24 +#define SCE_RAKU_ASSOCIATIVE 25 +#define SCE_RAKU_CALLABLE 26 +#define SCE_RAKU_GRAMMAR 27 +#define SCE_RAKU_CLASS 28 +#define SCE_FSHARP_DEFAULT 0 +#define SCE_FSHARP_KEYWORD 1 +#define SCE_FSHARP_KEYWORD2 2 +#define SCE_FSHARP_KEYWORD3 3 +#define SCE_FSHARP_KEYWORD4 4 +#define SCE_FSHARP_KEYWORD5 5 +#define SCE_FSHARP_IDENTIFIER 6 +#define SCE_FSHARP_QUOT_IDENTIFIER 7 +#define SCE_FSHARP_COMMENT 8 +#define SCE_FSHARP_COMMENTLINE 9 +#define SCE_FSHARP_PREPROCESSOR 10 +#define SCE_FSHARP_LINENUM 11 +#define SCE_FSHARP_OPERATOR 12 +#define SCE_FSHARP_NUMBER 13 +#define SCE_FSHARP_CHARACTER 14 +#define SCE_FSHARP_STRING 15 +#define SCE_FSHARP_VERBATIM 16 +#define SCE_FSHARP_QUOTATION 17 +#define SCE_FSHARP_ATTRIBUTE 18 +#define SCE_FSHARP_FORMAT_SPEC 19 +#define SCE_ASCIIDOC_DEFAULT 0 +#define SCE_ASCIIDOC_STRONG1 1 +#define SCE_ASCIIDOC_STRONG2 2 +#define SCE_ASCIIDOC_EM1 3 +#define SCE_ASCIIDOC_EM2 4 +#define SCE_ASCIIDOC_HEADER1 5 +#define SCE_ASCIIDOC_HEADER2 6 +#define SCE_ASCIIDOC_HEADER3 7 +#define SCE_ASCIIDOC_HEADER4 8 +#define SCE_ASCIIDOC_HEADER5 9 +#define SCE_ASCIIDOC_HEADER6 10 +#define SCE_ASCIIDOC_ULIST_ITEM 11 +#define SCE_ASCIIDOC_OLIST_ITEM 12 +#define SCE_ASCIIDOC_BLOCKQUOTE 13 +#define SCE_ASCIIDOC_LINK 14 +#define SCE_ASCIIDOC_CODEBK 15 +#define SCE_ASCIIDOC_PASSBK 16 +#define SCE_ASCIIDOC_COMMENT 17 +#define SCE_ASCIIDOC_COMMENTBK 18 +#define SCE_ASCIIDOC_LITERAL 19 +#define SCE_ASCIIDOC_LITERALBK 20 +#define SCE_ASCIIDOC_ATTRIB 21 +#define SCE_ASCIIDOC_ATTRIBVAL 22 +#define SCE_ASCIIDOC_MACRO 23 +#define SCE_GD_DEFAULT 0 +#define SCE_GD_COMMENTLINE 1 +#define SCE_GD_NUMBER 2 +#define SCE_GD_STRING 3 +#define SCE_GD_CHARACTER 4 +#define SCE_GD_WORD 5 +#define SCE_GD_TRIPLE 6 +#define SCE_GD_TRIPLEDOUBLE 7 +#define SCE_GD_CLASSNAME 8 +#define SCE_GD_FUNCNAME 9 +#define SCE_GD_OPERATOR 10 +#define SCE_GD_IDENTIFIER 11 +#define SCE_GD_COMMENTBLOCK 12 +#define SCE_GD_STRINGEOL 13 +#define SCE_GD_WORD2 14 +#define SCE_GD_ANNOTATION 15 +#define SCE_GD_NODEPATH 16 +#define SCE_TOML_DEFAULT 0 +#define SCE_TOML_COMMENT 1 +#define SCE_TOML_IDENTIFIER 2 +#define SCE_TOML_KEYWORD 3 +#define SCE_TOML_NUMBER 4 +#define SCE_TOML_TABLE 5 +#define SCE_TOML_KEY 6 +#define SCE_TOML_ERROR 7 +#define SCE_TOML_OPERATOR 8 +#define SCE_TOML_STRING_SQ 9 +#define SCE_TOML_STRING_DQ 10 +#define SCE_TOML_TRIPLE_STRING_SQ 11 +#define SCE_TOML_TRIPLE_STRING_DQ 12 +#define SCE_TOML_ESCAPECHAR 13 +#define SCE_TOML_DATETIME 14 +#define SCE_TOML_STRINGEOL 15 +#define SCE_TROFF_DEFAULT 0 +#define SCE_TROFF_REQUEST 1 +#define SCE_TROFF_COMMAND 2 +#define SCE_TROFF_NUMBER 3 +#define SCE_TROFF_OPERATOR 4 +#define SCE_TROFF_STRING 5 +#define SCE_TROFF_COMMENT 6 +#define SCE_TROFF_IGNORE 7 +#define SCE_TROFF_ESCAPE_STRING 8 +#define SCE_TROFF_ESCAPE_MACRO 9 +#define SCE_TROFF_ESCAPE_FONT 10 +#define SCE_TROFF_ESCAPE_NUMBER 11 +#define SCE_TROFF_ESCAPE_COLOUR 12 +#define SCE_TROFF_ESCAPE_GLYPH 13 +#define SCE_TROFF_ESCAPE_ENV 14 +#define SCE_TROFF_ESCAPE_SUPPRESSION 15 +#define SCE_TROFF_ESCAPE_SIZE 16 +#define SCE_TROFF_ESCAPE_TRANSPARENT 17 +#define SCE_TROFF_ESCAPE_ISVALID 18 +#define SCE_TROFF_ESCAPE_DRAW 19 +#define SCE_TROFF_ESCAPE_MOVE 20 +#define SCE_TROFF_ESCAPE_HEIGHT 21 +#define SCE_TROFF_ESCAPE_OVERSTRIKE 22 +#define SCE_TROFF_ESCAPE_SLANT 23 +#define SCE_TROFF_ESCAPE_WIDTH 24 +#define SCE_TROFF_ESCAPE_VSPACING 25 +#define SCE_TROFF_ESCAPE_DEVICE 26 +#define SCE_TROFF_ESCAPE_NOMOVE 27 +#define SCE_DART_DEFAULT 0 +#define SCE_DART_COMMENTLINE 1 +#define SCE_DART_COMMENTLINEDOC 2 +#define SCE_DART_COMMENTBLOCK 3 +#define SCE_DART_COMMENTBLOCKDOC 4 +#define SCE_DART_STRING_SQ 5 +#define SCE_DART_STRING_DQ 6 +#define SCE_DART_TRIPLE_STRING_SQ 7 +#define SCE_DART_TRIPLE_STRING_DQ 8 +#define SCE_DART_RAWSTRING_SQ 9 +#define SCE_DART_RAWSTRING_DQ 10 +#define SCE_DART_TRIPLE_RAWSTRING_SQ 11 +#define SCE_DART_TRIPLE_RAWSTRING_DQ 12 +#define SCE_DART_ESCAPECHAR 13 +#define SCE_DART_IDENTIFIER 14 +#define SCE_DART_IDENTIFIER_STRING 15 +#define SCE_DART_OPERATOR 16 +#define SCE_DART_OPERATOR_STRING 17 +#define SCE_DART_SYMBOL_IDENTIFIER 18 +#define SCE_DART_SYMBOL_OPERATOR 19 +#define SCE_DART_NUMBER 20 +#define SCE_DART_KEY 21 +#define SCE_DART_METADATA 22 +#define SCE_DART_KW_PRIMARY 23 +#define SCE_DART_KW_SECONDARY 24 +#define SCE_DART_KW_TERTIARY 25 +#define SCE_DART_KW_TYPE 26 +#define SCE_DART_STRINGEOL 27 +#define SCE_ZIG_DEFAULT 0 +#define SCE_ZIG_COMMENTLINE 1 +#define SCE_ZIG_COMMENTLINEDOC 2 +#define SCE_ZIG_COMMENTLINETOP 3 +#define SCE_ZIG_NUMBER 4 +#define SCE_ZIG_OPERATOR 5 +#define SCE_ZIG_CHARACTER 6 +#define SCE_ZIG_STRING 7 +#define SCE_ZIG_MULTISTRING 8 +#define SCE_ZIG_ESCAPECHAR 9 +#define SCE_ZIG_IDENTIFIER 10 +#define SCE_ZIG_FUNCTION 11 +#define SCE_ZIG_BUILTIN_FUNCTION 12 +#define SCE_ZIG_KW_PRIMARY 13 +#define SCE_ZIG_KW_SECONDARY 14 +#define SCE_ZIG_KW_TERTIARY 15 +#define SCE_ZIG_KW_TYPE 16 +#define SCE_ZIG_IDENTIFIER_STRING 17 +#define SCE_ZIG_STRINGEOL 18 +#define SCE_NIX_DEFAULT 0 +#define SCE_NIX_COMMENTLINE 1 +#define SCE_NIX_COMMENTBLOCK 2 +#define SCE_NIX_STRING 3 +#define SCE_NIX_STRING_MULTILINE 4 +#define SCE_NIX_ESCAPECHAR 5 +#define SCE_NIX_IDENTIFIER 6 +#define SCE_NIX_OPERATOR 7 +#define SCE_NIX_OPERATOR_STRING 8 +#define SCE_NIX_NUMBER 9 +#define SCE_NIX_KEY 10 +#define SCE_NIX_PATH 11 +#define SCE_NIX_KEYWORD1 12 +#define SCE_NIX_KEYWORD2 13 +#define SCE_NIX_KEYWORD3 14 +#define SCE_NIX_KEYWORD4 15 +#define SCE_NIX_STRINGEOL 16 /* --Autogenerated -- end of section automatically generated from Scintilla.iface */ + + + +//For All lexer +#define SCE_UNIVERSAL_FOUND_STYLE 31 +#define SCE_UNIVERSAL_FOUND_STYLE_SMART 29 +#define SCE_UNIVERSAL_FOUND_STYLE_INC 28 +#define SCE_UNIVERSAL_TAGMATCH 27 +#define SCE_UNIVERSAL_TAGATTR 26 +#define SCE_UNIVERSAL_FOUND_STYLE_EXT1 25 +#define SCE_UNIVERSAL_FOUND_STYLE_EXT2 24 +#define SCE_UNIVERSAL_FOUND_STYLE_EXT3 23 +#define SCE_UNIVERSAL_FOUND_STYLE_EXT4 22 +#define SCE_UNIVERSAL_FOUND_STYLE_EXT5 21 + +#define SCE_UDL_VERSION_MAJOR 2 +#define SCE_UDL_VERSION_MINOR 1 +#define SCE_UDL_VERSION_BUILD 0 +#define SCE_UDL_VERSION_REVISION 12 + +#define SCE_USER_KWLIST_COMMENTS 0 +#define SCE_USER_KWLIST_NUMBER_PREFIX1 1 +#define SCE_USER_KWLIST_NUMBER_PREFIX2 2 +#define SCE_USER_KWLIST_NUMBER_EXTRAS1 3 +#define SCE_USER_KWLIST_NUMBER_EXTRAS2 4 +#define SCE_USER_KWLIST_NUMBER_SUFFIX1 5 +#define SCE_USER_KWLIST_NUMBER_SUFFIX2 6 +#define SCE_USER_KWLIST_NUMBER_RANGE 7 +#define SCE_USER_KWLIST_OPERATORS1 8 +#define SCE_USER_KWLIST_OPERATORS2 9 +#define SCE_USER_KWLIST_FOLDERS_IN_CODE1_OPEN 10 +#define SCE_USER_KWLIST_FOLDERS_IN_CODE1_MIDDLE 11 +#define SCE_USER_KWLIST_FOLDERS_IN_CODE1_CLOSE 12 +#define SCE_USER_KWLIST_FOLDERS_IN_CODE2_OPEN 13 +#define SCE_USER_KWLIST_FOLDERS_IN_CODE2_MIDDLE 14 +#define SCE_USER_KWLIST_FOLDERS_IN_CODE2_CLOSE 15 +#define SCE_USER_KWLIST_FOLDERS_IN_COMMENT_OPEN 16 +#define SCE_USER_KWLIST_FOLDERS_IN_COMMENT_MIDDLE 17 +#define SCE_USER_KWLIST_FOLDERS_IN_COMMENT_CLOSE 18 +#define SCE_USER_KWLIST_KEYWORDS1 19 +#define SCE_USER_KWLIST_KEYWORDS2 20 +#define SCE_USER_KWLIST_KEYWORDS3 21 +#define SCE_USER_KWLIST_KEYWORDS4 22 +#define SCE_USER_KWLIST_KEYWORDS5 23 +#define SCE_USER_KWLIST_KEYWORDS6 24 +#define SCE_USER_KWLIST_KEYWORDS7 25 +#define SCE_USER_KWLIST_KEYWORDS8 26 +#define SCE_USER_KWLIST_DELIMITERS 27 +#define SCE_USER_KWLIST_TOTAL 28 // must always be <= KEYWORDSET_MAX + +#define SCE_USER_TOTAL_DELIMITERS 8 +#define SCE_USER_TOTAL_KEYWORD_GROUPS 8 +#define SCE_USER_TOTAL_FOLDERS 6 + +#define SCE_USER_STYLE_DEFAULT 0 +#define SCE_USER_STYLE_COMMENT 1 +#define SCE_USER_STYLE_COMMENTLINE 2 +#define SCE_USER_STYLE_NUMBER 3 +#define SCE_USER_STYLE_KEYWORD1 4 +#define SCE_USER_STYLE_KEYWORD2 5 +#define SCE_USER_STYLE_KEYWORD3 6 +#define SCE_USER_STYLE_KEYWORD4 7 +#define SCE_USER_STYLE_KEYWORD5 8 +#define SCE_USER_STYLE_KEYWORD6 9 +#define SCE_USER_STYLE_KEYWORD7 10 +#define SCE_USER_STYLE_KEYWORD8 11 +#define SCE_USER_STYLE_OPERATOR 12 +#define SCE_USER_STYLE_FOLDER_IN_CODE1 13 +#define SCE_USER_STYLE_FOLDER_IN_CODE2 14 +#define SCE_USER_STYLE_FOLDER_IN_COMMENT 15 +#define SCE_USER_STYLE_DELIMITER1 16 +#define SCE_USER_STYLE_DELIMITER2 17 +#define SCE_USER_STYLE_DELIMITER3 18 +#define SCE_USER_STYLE_DELIMITER4 19 +#define SCE_USER_STYLE_DELIMITER5 20 +#define SCE_USER_STYLE_DELIMITER6 21 +#define SCE_USER_STYLE_DELIMITER7 22 +#define SCE_USER_STYLE_DELIMITER8 23 +#define SCE_USER_STYLE_IDENTIFIER 24 +#define SCE_USER_STYLE_TOTAL_STYLES SCE_USER_STYLE_IDENTIFIER +#define SCE_USER_STYLE_MAPPER_TOTAL 17 + +#define SCE_USER_MASK_NESTING_NONE 0 +#define SCE_USER_MASK_NESTING_DELIMITER1 0x1 +#define SCE_USER_MASK_NESTING_DELIMITER2 0x2 +#define SCE_USER_MASK_NESTING_DELIMITER3 0x4 +#define SCE_USER_MASK_NESTING_DELIMITER4 0x8 +#define SCE_USER_MASK_NESTING_DELIMITER5 0x10 +#define SCE_USER_MASK_NESTING_DELIMITER6 0x20 +#define SCE_USER_MASK_NESTING_DELIMITER7 0x40 +#define SCE_USER_MASK_NESTING_DELIMITER8 0x80 +#define SCE_USER_MASK_NESTING_COMMENT 0x100 +#define SCE_USER_MASK_NESTING_COMMENT_LINE 0x200 +#define SCE_USER_MASK_NESTING_KEYWORD1 0x400 +#define SCE_USER_MASK_NESTING_KEYWORD2 0x800 +#define SCE_USER_MASK_NESTING_KEYWORD3 0x1000 +#define SCE_USER_MASK_NESTING_KEYWORD4 0x2000 +#define SCE_USER_MASK_NESTING_KEYWORD5 0x4000 +#define SCE_USER_MASK_NESTING_KEYWORD6 0x8000 +#define SCE_USER_MASK_NESTING_KEYWORD7 0x10000 +#define SCE_USER_MASK_NESTING_KEYWORD8 0x20000 +#define SCE_USER_MASK_NESTING_FOLDERS_IN_CODE2_OPEN 0x40000 +#define SCE_USER_MASK_NESTING_FOLDERS_IN_CODE2_MIDDLE 0x80000 +#define SCE_USER_MASK_NESTING_FOLDERS_IN_CODE2_CLOSE 0x100000 +#define SCE_USER_MASK_NESTING_FOLDERS_IN_COMMENT_OPEN 0x200000 +#define SCE_USER_MASK_NESTING_FOLDERS_IN_COMMENT_MIDDLE 0x400000 +#define SCE_USER_MASK_NESTING_FOLDERS_IN_COMMENT_CLOSE 0x800000 +#define SCE_USER_MASK_NESTING_OPERATORS1 0x1000000 +#define SCE_USER_MASK_NESTING_OPERATORS2 0x2000000 +#define SCE_USER_MASK_NESTING_NUMBERS 0x4000000 + + +#define SCE_SEARCHRESULT_DEFAULT 0 +#define SCE_SEARCHRESULT_SEARCH_HEADER 1 +#define SCE_SEARCHRESULT_FILE_HEADER 2 +#define SCE_SEARCHRESULT_LINE_NUMBER 3 +#define SCE_SEARCHRESULT_WORD2SEARCH 4 +//#define SCE_SEARCHRESULT_HIGHLIGHT_LINE 5 // (no use anymore) +#define SCE_SEARCHRESULT_CURRENT_LINE 6 +#define SCE_OBJC_DIRECTIVE 20 +#define SCE_OBJC_QUALIFIER 21 + + #endif diff --git a/NppPlugin/include/Sci_Position.h b/NppPlugin/include/Sci_Position.h new file mode 100644 index 00000000..88ad5132 --- /dev/null +++ b/NppPlugin/include/Sci_Position.h @@ -0,0 +1,29 @@ +// Scintilla source code edit control +/** @file Sci_Position.h + ** Define the Sci_Position type used in Scintilla's external interfaces. + ** These need to be available to clients written in C so are not in a C++ namespace. + **/ +// Copyright 2015 by Neil Hodgson +// The License.txt file describes the conditions under which this software may be distributed. + +#ifndef SCI_POSITION_H +#define SCI_POSITION_H + +#include + +// Basic signed type used throughout interface +typedef ptrdiff_t Sci_Position; + +// Unsigned variant used for ILexer::Lex and ILexer::Fold +typedef size_t Sci_PositionU; + +// For Sci_CharacterRange which is defined as long to be compatible with Win32 CHARRANGE +typedef intptr_t Sci_PositionCR; + +#ifdef _WIN32 + #define SCI_METHOD __stdcall +#else + #define SCI_METHOD +#endif + +#endif diff --git a/NppPlugin/include/Scintilla.h b/NppPlugin/include/Scintilla.h index c20a063f..db768a88 100644 --- a/NppPlugin/include/Scintilla.h +++ b/NppPlugin/include/Scintilla.h @@ -18,29 +18,27 @@ extern "C" { #if defined(_WIN32) /* Return false on failure: */ int Scintilla_RegisterClasses(void *hInstance); -int Scintilla_ReleaseResources(); +int Scintilla_ReleaseResources(void); #endif -int Scintilla_LinkLexers(); #ifdef __cplusplus } #endif -/* Here should be placed typedefs for uptr_t, an unsigned integer type large enough to - * hold a pointer and sptr_t, a signed integer large enough to hold a pointer. - * May need to be changed for 64 bit platforms. */ -#if defined(_WIN32) -#include -#endif -#ifdef MAXULONG_PTR -typedef ULONG_PTR uptr_t; -typedef LONG_PTR sptr_t; -#else -typedef unsigned long uptr_t; -typedef long sptr_t; -#endif +// Include header that defines basic numeric types. +#include + +// Define uptr_t, an unsigned integer type large enough to hold a pointer. +typedef uintptr_t uptr_t; +// Define sptr_t, a signed integer large enough to hold a pointer. +typedef intptr_t sptr_t; + +#include "Sci_Position.h" typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, sptr_t lParam); +typedef sptr_t (*SciFnDirectStatus)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, sptr_t lParam, int *pStatus); + +#ifndef SCI_DISABLE_AUTOGENERATED /* ++Autogenerated -- start of section automatically generated from Scintilla.iface */ #define INVALID_POSITION -1 @@ -50,27 +48,40 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_ADDTEXT 2001 #define SCI_ADDSTYLEDTEXT 2002 #define SCI_INSERTTEXT 2003 +#define SCI_CHANGEINSERTION 2672 #define SCI_CLEARALL 2004 +#define SCI_DELETERANGE 2645 #define SCI_CLEARDOCUMENTSTYLE 2005 #define SCI_GETLENGTH 2006 #define SCI_GETCHARAT 2007 #define SCI_GETCURRENTPOS 2008 #define SCI_GETANCHOR 2009 #define SCI_GETSTYLEAT 2010 +#define SCI_GETSTYLEINDEXAT 2038 #define SCI_REDO 2011 #define SCI_SETUNDOCOLLECTION 2012 #define SCI_SELECTALL 2013 #define SCI_SETSAVEPOINT 2014 -#define SCI_GETSTYLEDTEXT 2015 +//deprecated by N++ 2GB+ support via new scintilla interfaces from 5.2.3 (see https://www.scintilla.org/ScintillaHistory.html), +//please use SCI_GETTEXTRANGEFULL, SCI_FINDTEXTFULL,SCI_GETSTYLEDTEXTFULL and SCI_FORMATRANGEFULL and corresponding defines/structs +//#define SCI_GETSTYLEDTEXT 2015 +#define SCI_GETSTYLEDTEXTFULL 2778 #define SCI_CANREDO 2016 #define SCI_MARKERLINEFROMHANDLE 2017 #define SCI_MARKERDELETEHANDLE 2018 +#define SCI_MARKERHANDLEFROMLINE 2732 +#define SCI_MARKERNUMBERFROMLINE 2733 #define SCI_GETUNDOCOLLECTION 2019 #define SCWS_INVISIBLE 0 #define SCWS_VISIBLEALWAYS 1 #define SCWS_VISIBLEAFTERINDENT 2 +#define SCWS_VISIBLEONLYININDENT 3 #define SCI_GETVIEWWS 2020 #define SCI_SETVIEWWS 2021 +#define SCTD_LONGARROW 0 +#define SCTD_STRIKEOUT 1 +#define SCI_GETTABDRAWMODE 2698 +#define SCI_SETTABDRAWMODE 2699 #define SCI_POSITIONFROMPOINT 2022 #define SCI_POSITIONFROMPOINTCLOSE 2023 #define SCI_GOTOLINE 2024 @@ -90,9 +101,26 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_SETBUFFEREDDRAW 2035 #define SCI_SETTABWIDTH 2036 #define SCI_GETTABWIDTH 2121 +#define SCI_SETTABMINIMUMWIDTH 2724 +#define SCI_GETTABMINIMUMWIDTH 2725 +#define SCI_CLEARTABSTOPS 2675 +#define SCI_ADDTABSTOP 2676 +#define SCI_GETNEXTTABSTOP 2677 #define SC_CP_UTF8 65001 #define SCI_SETCODEPAGE 2037 -#define SCI_SETUSEPALETTE 2039 +#define SCI_SETFONTLOCALE 2760 +#define SCI_GETFONTLOCALE 2761 +#define SC_IME_WINDOWED 0 +#define SC_IME_INLINE 1 +#define SCI_GETIMEINTERACTION 2678 +#define SCI_SETIMEINTERACTION 2679 +#define SC_ALPHA_TRANSPARENT 0 +#define SC_ALPHA_OPAQUE 255 +#define SC_ALPHA_NOALPHA 256 +#define SC_CURSORNORMAL -1 +#define SC_CURSORARROW 2 +#define SC_CURSORWAIT 4 +#define SC_CURSORREVERSEARROW 7 #define MARKER_MAX 31 #define SC_MARK_CIRCLE 0 #define SC_MARK_ROUNDRECT 1 @@ -124,7 +152,15 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SC_MARK_LEFTRECT 27 #define SC_MARK_AVAILABLE 28 #define SC_MARK_UNDERLINE 29 +#define SC_MARK_RGBAIMAGE 30 +#define SC_MARK_BOOKMARK 31 +#define SC_MARK_VERTICALBOOKMARK 32 +#define SC_MARK_BAR 33 #define SC_MARK_CHARACTER 10000 +#define SC_MARKNUM_HISTORY_REVERTED_TO_ORIGIN 21 +#define SC_MARKNUM_HISTORY_SAVED 22 +#define SC_MARKNUM_HISTORY_MODIFIED 23 +#define SC_MARKNUM_HISTORY_REVERTED_TO_MODIFIED 24 #define SC_MARKNUM_FOLDEREND 25 #define SC_MARKNUM_FOLDEROPENMID 26 #define SC_MARKNUM_FOLDERMIDTAIL 27 @@ -132,10 +168,17 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SC_MARKNUM_FOLDERSUB 29 #define SC_MARKNUM_FOLDER 30 #define SC_MARKNUM_FOLDEROPEN 31 +#define SC_MASK_HISTORY 0x01E00000 #define SC_MASK_FOLDERS 0xFE000000 #define SCI_MARKERDEFINE 2040 #define SCI_MARKERSETFORE 2041 #define SCI_MARKERSETBACK 2042 +#define SCI_MARKERSETBACKSELECTED 2292 +#define SCI_MARKERSETFORETRANSLUCENT 2294 +#define SCI_MARKERSETBACKTRANSLUCENT 2295 +#define SCI_MARKERSETBACKSELECTEDTRANSLUCENT 2296 +#define SCI_MARKERSETSTROKEWIDTH 2297 +#define SCI_MARKERENABLEHIGHLIGHT 2293 #define SCI_MARKERADD 2043 #define SCI_MARKERDELETE 2044 #define SCI_MARKERDELETEALL 2045 @@ -145,12 +188,16 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_MARKERDEFINEPIXMAP 2049 #define SCI_MARKERADDSET 2466 #define SCI_MARKERSETALPHA 2476 +#define SCI_MARKERGETLAYER 2734 +#define SCI_MARKERSETLAYER 2735 +#define SC_MAX_MARGIN 4 #define SC_MARGIN_SYMBOL 0 #define SC_MARGIN_NUMBER 1 #define SC_MARGIN_BACK 2 #define SC_MARGIN_FORE 3 #define SC_MARGIN_TEXT 4 #define SC_MARGIN_RTEXT 5 +#define SC_MARGIN_COLOUR 6 #define SCI_SETMARGINTYPEN 2240 #define SCI_GETMARGINTYPEN 2241 #define SCI_SETMARGINWIDTHN 2242 @@ -159,6 +206,12 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_GETMARGINMASKN 2245 #define SCI_SETMARGINSENSITIVEN 2246 #define SCI_GETMARGINSENSITIVEN 2247 +#define SCI_SETMARGINCURSORN 2248 +#define SCI_GETMARGINCURSORN 2249 +#define SCI_SETMARGINBACKN 2250 +#define SCI_GETMARGINBACKN 2251 +#define SCI_SETMARGINS 2252 +#define SCI_GETMARGINS 2253 #define STYLE_DEFAULT 32 #define STYLE_LINENUMBER 33 #define STYLE_BRACELIGHT 34 @@ -166,6 +219,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define STYLE_CONTROLCHAR 36 #define STYLE_INDENTGUIDE 37 #define STYLE_CALLTIP 38 +#define STYLE_FOLDDISPLAYTEXT 39 #define STYLE_LASTPREDEFINED 39 #define STYLE_MAX 255 #define SC_CHARSET_ANSI 0 @@ -179,6 +233,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SC_CHARSET_MAC 77 #define SC_CHARSET_OEM 255 #define SC_CHARSET_RUSSIAN 204 +#define SC_CHARSET_OEM866 866 #define SC_CHARSET_CYRILLIC 1251 #define SC_CHARSET_SHIFTJIS 128 #define SC_CHARSET_SYMBOL 2 @@ -202,6 +257,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SC_CASE_MIXED 0 #define SC_CASE_UPPER 1 #define SC_CASE_LOWER 2 +#define SC_CASE_CAMEL 3 #define SCI_STYLEGETFORE 2481 #define SCI_STYLEGETBACK 2482 #define SCI_STYLEGETBOLD 2483 @@ -216,14 +272,75 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_STYLEGETCHANGEABLE 2492 #define SCI_STYLEGETHOTSPOT 2493 #define SCI_STYLESETCASE 2060 +#define SC_FONT_SIZE_MULTIPLIER 100 +#define SCI_STYLESETSIZEFRACTIONAL 2061 +#define SCI_STYLEGETSIZEFRACTIONAL 2062 +#define SC_WEIGHT_NORMAL 400 +#define SC_WEIGHT_SEMIBOLD 600 +#define SC_WEIGHT_BOLD 700 +#define SCI_STYLESETWEIGHT 2063 +#define SCI_STYLEGETWEIGHT 2064 #define SCI_STYLESETCHARACTERSET 2066 #define SCI_STYLESETHOTSPOT 2409 +#define SCI_STYLESETCHECKMONOSPACED 2254 +#define SCI_STYLEGETCHECKMONOSPACED 2255 +#define SC_STRETCH_ULTRA_CONDENSED 1 +#define SC_STRETCH_EXTRA_CONDENSED 2 +#define SC_STRETCH_CONDENSED 3 +#define SC_STRETCH_SEMI_CONDENSED 4 +#define SC_STRETCH_NORMAL 5 +#define SC_STRETCH_SEMI_EXPANDED 6 +#define SC_STRETCH_EXPANDED 7 +#define SC_STRETCH_EXTRA_EXPANDED 8 +#define SC_STRETCH_ULTRA_EXPANDED 9 +#define SCI_STYLESETSTRETCH 2258 +#define SCI_STYLEGETSTRETCH 2259 +#define SCI_STYLESETINVISIBLEREPRESENTATION 2256 +#define SCI_STYLEGETINVISIBLEREPRESENTATION 2257 +#define SC_ELEMENT_LIST 0 +#define SC_ELEMENT_LIST_BACK 1 +#define SC_ELEMENT_LIST_SELECTED 2 +#define SC_ELEMENT_LIST_SELECTED_BACK 3 +#define SC_ELEMENT_SELECTION_TEXT 10 +#define SC_ELEMENT_SELECTION_BACK 11 +#define SC_ELEMENT_SELECTION_ADDITIONAL_TEXT 12 +#define SC_ELEMENT_SELECTION_ADDITIONAL_BACK 13 +#define SC_ELEMENT_SELECTION_SECONDARY_TEXT 14 +#define SC_ELEMENT_SELECTION_SECONDARY_BACK 15 +#define SC_ELEMENT_SELECTION_INACTIVE_TEXT 16 +#define SC_ELEMENT_SELECTION_INACTIVE_BACK 17 +#define SC_ELEMENT_SELECTION_INACTIVE_ADDITIONAL_TEXT 18 +#define SC_ELEMENT_SELECTION_INACTIVE_ADDITIONAL_BACK 19 +#define SC_ELEMENT_CARET 40 +#define SC_ELEMENT_CARET_ADDITIONAL 41 +#define SC_ELEMENT_CARET_LINE_BACK 50 +#define SC_ELEMENT_WHITE_SPACE 60 +#define SC_ELEMENT_WHITE_SPACE_BACK 61 +#define SC_ELEMENT_HOT_SPOT_ACTIVE 70 +#define SC_ELEMENT_HOT_SPOT_ACTIVE_BACK 71 +#define SC_ELEMENT_FOLD_LINE 80 +#define SC_ELEMENT_HIDDEN_LINE 81 +#define SCI_SETELEMENTCOLOUR 2753 +#define SCI_GETELEMENTCOLOUR 2754 +#define SCI_RESETELEMENTCOLOUR 2755 +#define SCI_GETELEMENTISSET 2756 +#define SCI_GETELEMENTALLOWSTRANSLUCENT 2757 +#define SCI_GETELEMENTBASECOLOUR 2758 #define SCI_SETSELFORE 2067 #define SCI_SETSELBACK 2068 #define SCI_GETSELALPHA 2477 #define SCI_SETSELALPHA 2478 #define SCI_GETSELEOLFILLED 2479 #define SCI_SETSELEOLFILLED 2480 +#define SC_LAYER_BASE 0 +#define SC_LAYER_UNDER_TEXT 1 +#define SC_LAYER_OVER_TEXT 2 +#define SCI_GETSELECTIONLAYER 2762 +#define SCI_SETSELECTIONLAYER 2763 +#define SCI_GETCARETLINELAYER 2764 +#define SCI_SETCARETLINELAYER 2765 +#define SCI_GETCARETLINEHIGHLIGHTSUBLINE 2773 +#define SCI_SETCARETLINEHIGHLIGHTSUBLINE 2774 #define SCI_SETCARETFORE 2069 #define SCI_ASSIGNCMDKEY 2070 #define SCI_CLEARCMDKEY 2071 @@ -233,8 +350,26 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_GETCARETPERIOD 2075 #define SCI_SETCARETPERIOD 2076 #define SCI_SETWORDCHARS 2077 +#define SCI_GETWORDCHARS 2646 +#define SCI_SETCHARACTERCATEGORYOPTIMIZATION 2720 +#define SCI_GETCHARACTERCATEGORYOPTIMIZATION 2721 #define SCI_BEGINUNDOACTION 2078 #define SCI_ENDUNDOACTION 2079 +#define SCI_GETUNDOSEQUENCE 2799 +#define SCI_GETUNDOACTIONS 2790 +#define SCI_SETUNDOSAVEPOINT 2791 +#define SCI_GETUNDOSAVEPOINT 2792 +#define SCI_SETUNDODETACH 2793 +#define SCI_GETUNDODETACH 2794 +#define SCI_SETUNDOTENTATIVE 2795 +#define SCI_GETUNDOTENTATIVE 2796 +#define SCI_SETUNDOCURRENT 2797 +#define SCI_GETUNDOCURRENT 2798 +#define SCI_PUSHUNDOACTIONTYPE 2800 +#define SCI_CHANGELASTUNDOACTIONTEXT 2801 +#define SCI_GETUNDOACTIONTYPE 2802 +#define SCI_GETUNDOACTIONPOSITION 2803 +#define SCI_GETUNDOACTIONTEXT 2804 #define INDIC_PLAIN 0 #define INDIC_SQUIGGLE 1 #define INDIC_TT 2 @@ -243,24 +378,60 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define INDIC_HIDDEN 5 #define INDIC_BOX 6 #define INDIC_ROUNDBOX 7 -#define INDIC_MAX 31 +#define INDIC_STRAIGHTBOX 8 +#define INDIC_DASH 9 +#define INDIC_DOTS 10 +#define INDIC_SQUIGGLELOW 11 +#define INDIC_DOTBOX 12 +#define INDIC_SQUIGGLEPIXMAP 13 +#define INDIC_COMPOSITIONTHICK 14 +#define INDIC_COMPOSITIONTHIN 15 +#define INDIC_FULLBOX 16 +#define INDIC_TEXTFORE 17 +#define INDIC_POINT 18 +#define INDIC_POINTCHARACTER 19 +#define INDIC_GRADIENT 20 +#define INDIC_GRADIENTCENTRE 21 +#define INDIC_POINT_TOP 22 +#define INDIC_EXPLORERLINK 23 #define INDIC_CONTAINER 8 -#define INDIC0_MASK 0x20 -#define INDIC1_MASK 0x40 -#define INDIC2_MASK 0x80 -#define INDICS_MASK 0xE0 +#define INDIC_IME 32 +#define INDIC_IME_MAX 35 +#define INDIC_MAX 35 +#define INDICATOR_CONTAINER 8 +#define INDICATOR_IME 32 +#define INDICATOR_IME_MAX 35 +#define INDICATOR_HISTORY_REVERTED_TO_ORIGIN_INSERTION 36 +#define INDICATOR_HISTORY_REVERTED_TO_ORIGIN_DELETION 37 +#define INDICATOR_HISTORY_SAVED_INSERTION 38 +#define INDICATOR_HISTORY_SAVED_DELETION 39 +#define INDICATOR_HISTORY_MODIFIED_INSERTION 40 +#define INDICATOR_HISTORY_MODIFIED_DELETION 41 +#define INDICATOR_HISTORY_REVERTED_TO_MODIFIED_INSERTION 42 +#define INDICATOR_HISTORY_REVERTED_TO_MODIFIED_DELETION 43 +#define INDICATOR_MAX 43 #define SCI_INDICSETSTYLE 2080 #define SCI_INDICGETSTYLE 2081 #define SCI_INDICSETFORE 2082 #define SCI_INDICGETFORE 2083 #define SCI_INDICSETUNDER 2510 #define SCI_INDICGETUNDER 2511 +#define SCI_INDICSETHOVERSTYLE 2680 +#define SCI_INDICGETHOVERSTYLE 2681 +#define SCI_INDICSETHOVERFORE 2682 +#define SCI_INDICGETHOVERFORE 2683 +#define SC_INDICVALUEBIT 0x1000000 +#define SC_INDICVALUEMASK 0xFFFFFF +#define SC_INDICFLAG_NONE 0 +#define SC_INDICFLAG_VALUEFORE 1 +#define SCI_INDICSETFLAGS 2684 +#define SCI_INDICGETFLAGS 2685 +#define SCI_INDICSETSTROKEWIDTH 2751 +#define SCI_INDICGETSTROKEWIDTH 2752 #define SCI_SETWHITESPACEFORE 2084 #define SCI_SETWHITESPACEBACK 2085 #define SCI_SETWHITESPACESIZE 2086 #define SCI_GETWHITESPACESIZE 2087 -#define SCI_SETSTYLEBITS 2090 -#define SCI_GETSTYLEBITS 2091 #define SCI_SETLINESTATE 2092 #define SCI_GETLINESTATE 2093 #define SCI_GETMAXLINESTATE 2094 @@ -268,6 +439,8 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_SETCARETLINEVISIBLE 2096 #define SCI_GETCARETLINEBACK 2097 #define SCI_SETCARETLINEBACK 2098 +#define SCI_GETCARETLINEFRAME 2704 +#define SCI_SETCARETLINEFRAME 2705 #define SCI_STYLESETCHANGEABLE 2099 #define SCI_AUTOCSHOW 2100 #define SCI_AUTOCCANCEL 2101 @@ -288,6 +461,11 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_USERLISTSHOW 2117 #define SCI_AUTOCSETAUTOHIDE 2118 #define SCI_AUTOCGETAUTOHIDE 2119 +#define SC_AUTOCOMPLETE_NORMAL 0 +#define SC_AUTOCOMPLETE_FIXED_SIZE 1 +#define SC_AUTOCOMPLETE_SELECT_FIRST_ITEM 2 +#define SCI_AUTOCSETOPTIONS 2638 +#define SCI_AUTOCGETOPTIONS 2639 #define SCI_AUTOCSETDROPRESTOFWORD 2270 #define SCI_AUTOCGETDROPRESTOFWORD 2271 #define SCI_REGISTERIMAGE 2405 @@ -298,6 +476,10 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_AUTOCGETMAXWIDTH 2209 #define SCI_AUTOCSETMAXHEIGHT 2210 #define SCI_AUTOCGETMAXHEIGHT 2211 +#define SCI_AUTOCSETSTYLE 2109 +#define SCI_AUTOCGETSTYLE 2120 +#define SCI_AUTOCSETIMAGESCALE 2815 +#define SCI_AUTOCGETIMAGESCALE 2816 #define SCI_SETINDENT 2122 #define SCI_GETINDENT 2123 #define SCI_SETUSETABS 2124 @@ -306,6 +488,8 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_GETLINEINDENTATION 2127 #define SCI_GETLINEINDENTPOSITION 2128 #define SCI_GETCOLUMN 2129 +#define SCI_COUNTCHARACTERS 2633 +#define SCI_COUNTCODEUNITS 2715 #define SCI_SETHSCROLLBAR 2130 #define SCI_GETHSCROLLBAR 2131 #define SC_IV_NONE 0 @@ -319,13 +503,13 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_GETLINEENDPOSITION 2136 #define SCI_GETCODEPAGE 2137 #define SCI_GETCARETFORE 2138 -#define SCI_GETUSEPALETTE 2139 #define SCI_GETREADONLY 2140 #define SCI_SETCURRENTPOS 2141 #define SCI_SETSELECTIONSTART 2142 #define SCI_GETSELECTIONSTART 2143 #define SCI_SETSELECTIONEND 2144 #define SCI_GETSELECTIONEND 2145 +#define SCI_SETEMPTYSELECTION 2556 #define SCI_SETPRINTMAGNIFICATION 2146 #define SCI_GETPRINTMAGNIFICATION 2147 #define SC_PRINT_NORMAL 0 @@ -333,18 +517,41 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SC_PRINT_BLACKONWHITE 2 #define SC_PRINT_COLOURONWHITE 3 #define SC_PRINT_COLOURONWHITEDEFAULTBG 4 +#define SC_PRINT_SCREENCOLOURS 5 #define SCI_SETPRINTCOLOURMODE 2148 #define SCI_GETPRINTCOLOURMODE 2149 -#define SCFIND_WHOLEWORD 2 -#define SCFIND_MATCHCASE 4 +#define SCFIND_NONE 0x0 +#define SCFIND_WHOLEWORD 0x2 +#define SCFIND_MATCHCASE 0x4 #define SCFIND_WORDSTART 0x00100000 #define SCFIND_REGEXP 0x00200000 #define SCFIND_POSIX 0x00400000 -#define SCI_FINDTEXT 2150 -#define SCI_FORMATRANGE 2151 +#define SCFIND_CXX11REGEX 0x00800000 +//deprecated by N++ 2GB+ support via new scintilla interfaces from 5.2.3 (see https://www.scintilla.org/ScintillaHistory.html), +//please use SCI_GETTEXTRANGEFULL, SCI_FINDTEXTFULL,SCI_GETSTYLEDTEXTFULL and SCI_FORMATRANGEFULL and corresponding defines/structs +//#define SCI_FINDTEXT 2150 +#define SCI_FINDTEXTFULL 2196 +//deprecated by N++ 2GB+ support via new scintilla interfaces from 5.2.3 (see https://www.scintilla.org/ScintillaHistory.html), +//please use SCI_GETTEXTRANGEFULL, SCI_FINDTEXTFULL,SCI_GETSTYLEDTEXTFULL and SCI_FORMATRANGEFULL and corresponding defines/structs +//#define SCI_FORMATRANGE 2151 +#define SCI_FORMATRANGEFULL 2777 +#define SC_CHANGE_HISTORY_DISABLED 0 +#define SC_CHANGE_HISTORY_ENABLED 1 +#define SC_CHANGE_HISTORY_MARKERS 2 +#define SC_CHANGE_HISTORY_INDICATORS 4 +#define SCI_SETCHANGEHISTORY 2780 +#define SCI_GETCHANGEHISTORY 2781 +#define SC_UNDO_SELECTION_HISTORY_DISABLED 0 +#define SC_UNDO_SELECTION_HISTORY_ENABLED 1 +#define SC_UNDO_SELECTION_HISTORY_SCROLL 2 +#define SCI_SETUNDOSELECTIONHISTORY 2782 +#define SCI_GETUNDOSELECTIONHISTORY 2783 +#define SCI_SETSELECTIONSERIALIZED 2784 +#define SCI_GETSELECTIONSERIALIZED 2785 #define SCI_GETFIRSTVISIBLELINE 2152 #define SCI_GETLINE 2153 #define SCI_GETLINECOUNT 2154 +#define SCI_ALLOCATELINES 2089 #define SCI_SETMARGINLEFT 2155 #define SCI_GETMARGINLEFT 2156 #define SCI_SETMARGINRIGHT 2157 @@ -352,14 +559,20 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_GETMODIFY 2159 #define SCI_SETSEL 2160 #define SCI_GETSELTEXT 2161 -#define SCI_GETTEXTRANGE 2162 +//deprecated by N++ 2GB+ support via new scintilla interfaces from 5.2.3 (see https://www.scintilla.org/ScintillaHistory.html), +//please use SCI_GETTEXTRANGEFULL, SCI_FINDTEXTFULL,SCI_GETSTYLEDTEXTFULL and SCI_FORMATRANGEFULL and corresponding defines/structs +//#define SCI_GETTEXTRANGE 2162 +#define SCI_GETTEXTRANGEFULL 2039 #define SCI_HIDESELECTION 2163 +#define SCI_GETSELECTIONHIDDEN 2088 #define SCI_POINTXFROMPOSITION 2164 #define SCI_POINTYFROMPOSITION 2165 #define SCI_LINEFROMPOSITION 2166 #define SCI_POSITIONFROMLINE 2167 #define SCI_LINESCROLL 2168 +#define SCI_SCROLLVERTICAL 2817 #define SCI_SCROLLCARET 2169 +#define SCI_SCROLLRANGE 2569 #define SCI_REPLACESEL 2170 #define SCI_SETREADONLY 2171 #define SCI_NULL 2172 @@ -375,6 +588,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_GETTEXT 2182 #define SCI_GETTEXTLENGTH 2183 #define SCI_GETDIRECTFUNCTION 2184 +#define SCI_GETDIRECTSTATUSFUNCTION 2772 #define SCI_GETDIRECTPOINTER 2185 #define SCI_SETOVERTYPE 2186 #define SCI_GETOVERTYPE 2187 @@ -382,10 +596,19 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_GETCARETWIDTH 2189 #define SCI_SETTARGETSTART 2190 #define SCI_GETTARGETSTART 2191 +#define SCI_SETTARGETSTARTVIRTUALSPACE 2728 +#define SCI_GETTARGETSTARTVIRTUALSPACE 2729 #define SCI_SETTARGETEND 2192 #define SCI_GETTARGETEND 2193 +#define SCI_SETTARGETENDVIRTUALSPACE 2730 +#define SCI_GETTARGETENDVIRTUALSPACE 2731 +#define SCI_SETTARGETRANGE 2686 +#define SCI_GETTARGETTEXT 2687 +#define SCI_TARGETFROMSELECTION 2287 +#define SCI_TARGETWHOLEDOCUMENT 2690 #define SCI_REPLACETARGET 2194 #define SCI_REPLACETARGETRE 2195 +#define SCI_REPLACETARGETMINIMAL 2779 #define SCI_SEARCHINTARGET 2197 #define SCI_SETSEARCHFLAGS 2198 #define SCI_GETSEARCHFLAGS 2199 @@ -393,14 +616,17 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_CALLTIPCANCEL 2201 #define SCI_CALLTIPACTIVE 2202 #define SCI_CALLTIPPOSSTART 2203 +#define SCI_CALLTIPSETPOSSTART 2214 #define SCI_CALLTIPSETHLT 2204 #define SCI_CALLTIPSETBACK 2205 #define SCI_CALLTIPSETFORE 2206 #define SCI_CALLTIPSETFOREHLT 2207 #define SCI_CALLTIPUSESTYLE 2212 +#define SCI_CALLTIPSETPOSITION 2213 #define SCI_VISIBLEFROMDOCLINE 2220 #define SCI_DOCLINEFROMVISIBLE 2221 #define SCI_WRAPCOUNT 2235 +#define SC_FOLDLEVELNONE 0x0 #define SC_FOLDLEVELBASE 0x400 #define SC_FOLDLEVELWHITEFLAG 0x1000 #define SC_FOLDLEVELHEADERFLAG 0x2000 @@ -412,15 +638,40 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_SHOWLINES 2226 #define SCI_HIDELINES 2227 #define SCI_GETLINEVISIBLE 2228 +#define SCI_GETALLLINESVISIBLE 2236 #define SCI_SETFOLDEXPANDED 2229 #define SCI_GETFOLDEXPANDED 2230 #define SCI_TOGGLEFOLD 2231 +#define SCI_TOGGLEFOLDSHOWTEXT 2700 +#define SC_FOLDDISPLAYTEXT_HIDDEN 0 +#define SC_FOLDDISPLAYTEXT_STANDARD 1 +#define SC_FOLDDISPLAYTEXT_BOXED 2 +#define SCI_FOLDDISPLAYTEXTSETSTYLE 2701 +#define SCI_FOLDDISPLAYTEXTGETSTYLE 2707 +#define SCI_SETDEFAULTFOLDDISPLAYTEXT 2722 +#define SCI_GETDEFAULTFOLDDISPLAYTEXT 2723 +#define SC_FOLDACTION_CONTRACT 0 +#define SC_FOLDACTION_EXPAND 1 +#define SC_FOLDACTION_TOGGLE 2 +#define SC_FOLDACTION_CONTRACT_EVERY_LEVEL 4 +#define SCI_FOLDLINE 2237 +#define SCI_FOLDCHILDREN 2238 +#define SCI_EXPANDCHILDREN 2239 +#define SCI_FOLDALL 2662 #define SCI_ENSUREVISIBLE 2232 +#define SC_AUTOMATICFOLD_NONE 0x0000 +#define SC_AUTOMATICFOLD_SHOW 0x0001 +#define SC_AUTOMATICFOLD_CLICK 0x0002 +#define SC_AUTOMATICFOLD_CHANGE 0x0004 +#define SCI_SETAUTOMATICFOLD 2663 +#define SCI_GETAUTOMATICFOLD 2664 +#define SC_FOLDFLAG_NONE 0x0000 #define SC_FOLDFLAG_LINEBEFORE_EXPANDED 0x0002 #define SC_FOLDFLAG_LINEBEFORE_CONTRACTED 0x0004 #define SC_FOLDFLAG_LINEAFTER_EXPANDED 0x0008 #define SC_FOLDFLAG_LINEAFTER_CONTRACTED 0x0010 #define SC_FOLDFLAG_LEVELNUMBERS 0x0040 +#define SC_FOLDFLAG_LINESTATE 0x0080 #define SCI_SETFOLDFLAGS 2233 #define SCI_ENSUREVISIBLEENFORCEPOLICY 2234 #define SCI_SETTABINDENTS 2260 @@ -432,14 +683,23 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_GETMOUSEDWELLTIME 2265 #define SCI_WORDSTARTPOSITION 2266 #define SCI_WORDENDPOSITION 2267 +#define SCI_ISRANGEWORD 2691 +#define SC_IDLESTYLING_NONE 0 +#define SC_IDLESTYLING_TOVISIBLE 1 +#define SC_IDLESTYLING_AFTERVISIBLE 2 +#define SC_IDLESTYLING_ALL 3 +#define SCI_SETIDLESTYLING 2692 +#define SCI_GETIDLESTYLING 2693 #define SC_WRAP_NONE 0 #define SC_WRAP_WORD 1 #define SC_WRAP_CHAR 2 +#define SC_WRAP_WHITESPACE 3 #define SCI_SETWRAPMODE 2268 #define SCI_GETWRAPMODE 2269 #define SC_WRAPVISUALFLAG_NONE 0x0000 #define SC_WRAPVISUALFLAG_END 0x0001 #define SC_WRAPVISUALFLAG_START 0x0002 +#define SC_WRAPVISUALFLAG_MARGIN 0x0004 #define SCI_SETWRAPVISUALFLAGS 2460 #define SCI_GETWRAPVISUALFLAGS 2461 #define SC_WRAPVISUALFLAGLOC_DEFAULT 0x0000 @@ -452,6 +712,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SC_WRAPINDENT_FIXED 0 #define SC_WRAPINDENT_SAME 1 #define SC_WRAPINDENT_INDENT 2 +#define SC_WRAPINDENT_DEEPINDENT 3 #define SCI_SETWRAPINDENTMODE 2472 #define SCI_GETWRAPINDENTMODE 2473 #define SC_CACHE_NONE 0 @@ -471,8 +732,11 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_SETVSCROLLBAR 2280 #define SCI_GETVSCROLLBAR 2281 #define SCI_APPENDTEXT 2282 -#define SCI_GETTWOPHASEDRAW 2283 -#define SCI_SETTWOPHASEDRAW 2284 +#define SC_PHASES_ONE 0 +#define SC_PHASES_TWO 1 +#define SC_PHASES_MULTIPLE 2 +#define SCI_GETPHASESDRAW 2673 +#define SCI_SETPHASESDRAW 2674 #define SC_EFF_QUALITY_MASK 0xF #define SC_EFF_QUALITY_DEFAULT 0 #define SC_EFF_QUALITY_NON_ANTIALIASED 1 @@ -486,11 +750,14 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_SETMULTIPASTE 2614 #define SCI_GETMULTIPASTE 2615 #define SCI_GETTAG 2616 -#define SCI_TARGETFROMSELECTION 2287 #define SCI_LINESJOIN 2288 #define SCI_LINESSPLIT 2289 #define SCI_SETFOLDMARGINCOLOUR 2290 #define SCI_SETFOLDMARGINHICOLOUR 2291 +#define SC_ACCESSIBILITY_DISABLED 0 +#define SC_ACCESSIBILITY_ENABLED 1 +#define SCI_SETACCESSIBILITY 2702 +#define SCI_GETACCESSIBILITY 2703 #define SCI_LINEDOWN 2300 #define SCI_LINEDOWNEXTEND 2301 #define SCI_LINEUP 2302 @@ -519,7 +786,9 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_CANCEL 2325 #define SCI_DELETEBACK 2326 #define SCI_TAB 2327 +#define SCI_LINEINDENT 2813 #define SCI_BACKTAB 2328 +#define SCI_LINEDEDENT 2814 #define SCI_NEWLINE 2329 #define SCI_FORMFEED 2330 #define SCI_VCHOME 2331 @@ -532,6 +801,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_LINECUT 2337 #define SCI_LINEDELETE 2338 #define SCI_LINETRANSPOSE 2339 +#define SCI_LINEREVERSE 2354 #define SCI_LINEDUPLICATE 2404 #define SCI_LOWERCASE 2340 #define SCI_UPPERCASE 2341 @@ -552,8 +822,11 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_MOVECARETINSIDEVIEW 2401 #define SCI_LINELENGTH 2350 #define SCI_BRACEHIGHLIGHT 2351 +#define SCI_BRACEHIGHLIGHTINDICATOR 2498 #define SCI_BRACEBADLIGHT 2352 +#define SCI_BRACEBADLIGHTINDICATOR 2499 #define SCI_BRACEMATCH 2353 +#define SCI_BRACEMATCHNEXT 2369 #define SCI_GETVIEWEOL 2355 #define SCI_SETVIEWEOL 2356 #define SCI_GETDOCPOINTER 2357 @@ -562,35 +835,50 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define EDGE_NONE 0 #define EDGE_LINE 1 #define EDGE_BACKGROUND 2 +#define EDGE_MULTILINE 3 #define SCI_GETEDGECOLUMN 2360 #define SCI_SETEDGECOLUMN 2361 #define SCI_GETEDGEMODE 2362 #define SCI_SETEDGEMODE 2363 #define SCI_GETEDGECOLOUR 2364 #define SCI_SETEDGECOLOUR 2365 +#define SCI_MULTIEDGEADDLINE 2694 +#define SCI_MULTIEDGECLEARALL 2695 +#define SCI_GETMULTIEDGECOLUMN 2749 #define SCI_SEARCHANCHOR 2366 #define SCI_SEARCHNEXT 2367 #define SCI_SEARCHPREV 2368 #define SCI_LINESONSCREEN 2370 +#define SC_POPUP_NEVER 0 +#define SC_POPUP_ALL 1 +#define SC_POPUP_TEXT 2 #define SCI_USEPOPUP 2371 #define SCI_SELECTIONISRECTANGLE 2372 #define SCI_SETZOOM 2373 #define SCI_GETZOOM 2374 +#define SC_DOCUMENTOPTION_DEFAULT 0 +#define SC_DOCUMENTOPTION_STYLES_NONE 0x1 +#define SC_DOCUMENTOPTION_TEXT_LARGE 0x100 #define SCI_CREATEDOCUMENT 2375 #define SCI_ADDREFDOCUMENT 2376 #define SCI_RELEASEDOCUMENT 2377 +#define SCI_GETDOCUMENTOPTIONS 2379 #define SCI_GETMODEVENTMASK 2378 +#define SCI_SETCOMMANDEVENTS 2717 +#define SCI_GETCOMMANDEVENTS 2718 #define SCI_SETFOCUS 2380 #define SCI_GETFOCUS 2381 #define SC_STATUS_OK 0 #define SC_STATUS_FAILURE 1 #define SC_STATUS_BADALLOC 2 +#define SC_STATUS_WARN_START 1000 +#define SC_STATUS_WARN_REGEX 1001 #define SCI_SETSTATUS 2382 #define SCI_GETSTATUS 2383 #define SCI_SETMOUSEDOWNCAPTURES 2384 #define SCI_GETMOUSEDOWNCAPTURES 2385 -#define SC_CURSORNORMAL -1 -#define SC_CURSORWAIT 4 +#define SCI_SETMOUSEWHEELCAPTURES 2696 +#define SCI_GETMOUSEWHEELCAPTURES 2697 #define SCI_SETCURSOR 2386 #define SCI_GETCURSOR 2387 #define SCI_SETCONTROLCHARSYMBOL 2388 @@ -630,6 +918,8 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_PARAUPEXTEND 2416 #define SCI_POSITIONBEFORE 2417 #define SCI_POSITIONAFTER 2418 +#define SCI_POSITIONRELATIVE 2670 +#define SCI_POSITIONRELATIVECODEUNITS 2716 #define SCI_COPYRANGE 2419 #define SCI_COPYTEXT 2420 #define SC_SEL_STREAM 0 @@ -637,7 +927,10 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SC_SEL_LINES 2 #define SC_SEL_THIN 3 #define SCI_SETSELECTIONMODE 2422 +#define SCI_CHANGESELECTIONMODE 2659 #define SCI_GETSELECTIONMODE 2423 +#define SCI_SETMOVEEXTENDSSELECTION 2719 +#define SCI_GETMOVEEXTENDSSELECTION 2706 #define SCI_GETLINESELSTARTPOSITION 2424 #define SCI_GETLINESELENDPOSITION 2425 #define SCI_LINEDOWNRECTEXTEND 2426 @@ -658,31 +951,50 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_WORDRIGHTEND 2441 #define SCI_WORDRIGHTENDEXTEND 2442 #define SCI_SETWHITESPACECHARS 2443 +#define SCI_GETWHITESPACECHARS 2647 +#define SCI_SETPUNCTUATIONCHARS 2648 +#define SCI_GETPUNCTUATIONCHARS 2649 #define SCI_SETCHARSDEFAULT 2444 #define SCI_AUTOCGETCURRENT 2445 #define SCI_AUTOCGETCURRENTTEXT 2610 +#define SC_CASEINSENSITIVEBEHAVIOUR_RESPECTCASE 0 +#define SC_CASEINSENSITIVEBEHAVIOUR_IGNORECASE 1 +#define SCI_AUTOCSETCASEINSENSITIVEBEHAVIOUR 2634 +#define SCI_AUTOCGETCASEINSENSITIVEBEHAVIOUR 2635 +#define SC_MULTIAUTOC_ONCE 0 +#define SC_MULTIAUTOC_EACH 1 +#define SCI_AUTOCSETMULTI 2636 +#define SCI_AUTOCGETMULTI 2637 +#define SC_ORDER_PRESORTED 0 +#define SC_ORDER_PERFORMSORT 1 +#define SC_ORDER_CUSTOM 2 +#define SCI_AUTOCSETORDER 2660 +#define SCI_AUTOCGETORDER 2661 #define SCI_ALLOCATE 2446 #define SCI_TARGETASUTF8 2447 #define SCI_SETLENGTHFORENCODE 2448 #define SCI_ENCODEDFROMUTF8 2449 #define SCI_FINDCOLUMN 2456 -#define SCI_GETCARETSTICKY 2457 -#define SCI_SETCARETSTICKY 2458 #define SC_CARETSTICKY_OFF 0 #define SC_CARETSTICKY_ON 1 #define SC_CARETSTICKY_WHITESPACE 2 +#define SCI_GETCARETSTICKY 2457 +#define SCI_SETCARETSTICKY 2458 #define SCI_TOGGLECARETSTICKY 2459 #define SCI_SETPASTECONVERTENDINGS 2467 #define SCI_GETPASTECONVERTENDINGS 2468 +#define SCI_REPLACERECTANGULAR 2771 #define SCI_SELECTIONDUPLICATE 2469 -#define SC_ALPHA_TRANSPARENT 0 -#define SC_ALPHA_OPAQUE 255 -#define SC_ALPHA_NOALPHA 256 #define SCI_SETCARETLINEBACKALPHA 2470 #define SCI_GETCARETLINEBACKALPHA 2471 #define CARETSTYLE_INVISIBLE 0 #define CARETSTYLE_LINE 1 #define CARETSTYLE_BLOCK 2 +#define CARETSTYLE_OVERSTRIKE_BAR 0 +#define CARETSTYLE_OVERSTRIKE_BLOCK 0x10 +#define CARETSTYLE_CURSES 0x20 +#define CARETSTYLE_INS_MASK 0xF +#define CARETSTYLE_BLOCK_AFTER 0x100 #define SCI_SETCARETSTYLE 2512 #define SCI_GETCARETSTYLE 2513 #define SCI_SETINDICATORCURRENT 2500 @@ -697,12 +1009,19 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_INDICATOREND 2509 #define SCI_SETPOSITIONCACHE 2514 #define SCI_GETPOSITIONCACHE 2515 +#define SCI_SETLAYOUTTHREADS 2775 +#define SCI_GETLAYOUTTHREADS 2776 #define SCI_COPYALLOWLINE 2519 +#define SCI_CUTALLOWLINE 2810 +#define SCI_SETCOPYSEPARATOR 2811 +#define SCI_GETCOPYSEPARATOR 2812 #define SCI_GETCHARACTERPOINTER 2520 -#define SCI_SETKEYSUNICODE 2521 -#define SCI_GETKEYSUNICODE 2522 +#define SCI_GETRANGEPOINTER 2643 +#define SCI_GETGAPPOSITION 2644 #define SCI_INDICSETALPHA 2523 #define SCI_INDICGETALPHA 2524 +#define SCI_INDICSETOUTLINEALPHA 2558 +#define SCI_INDICGETOUTLINEALPHA 2559 #define SCI_SETEXTRAASCENT 2525 #define SCI_GETEXTRAASCENT 2526 #define SCI_SETEXTRADESCENT 2527 @@ -717,6 +1036,10 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_MARGINTEXTCLEARALL 2536 #define SCI_MARGINSETSTYLEOFFSET 2537 #define SCI_MARGINGETSTYLEOFFSET 2538 +#define SC_MARGINOPTION_NONE 0 +#define SC_MARGINOPTION_SUBLINESELECT 1 +#define SCI_SETMARGINOPTIONS 2539 +#define SCI_GETMARGINOPTIONS 2557 #define SCI_ANNOTATIONSETTEXT 2540 #define SCI_ANNOTATIONGETTEXT 2541 #define SCI_ANNOTATIONSETSTYLE 2542 @@ -728,14 +1051,20 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define ANNOTATION_HIDDEN 0 #define ANNOTATION_STANDARD 1 #define ANNOTATION_BOXED 2 +#define ANNOTATION_INDENTED 3 #define SCI_ANNOTATIONSETVISIBLE 2548 #define SCI_ANNOTATIONGETVISIBLE 2549 #define SCI_ANNOTATIONSETSTYLEOFFSET 2550 #define SCI_ANNOTATIONGETSTYLEOFFSET 2551 +#define SCI_RELEASEALLEXTENDEDSTYLES 2552 +#define SCI_ALLOCATEEXTENDEDSTYLES 2553 +#define UNDO_NONE 0 #define UNDO_MAY_COALESCE 1 #define SCI_ADDUNDOACTION 2560 #define SCI_CHARPOSITIONFROMPOINT 2561 #define SCI_CHARPOSITIONFROMPOINTCLOSE 2562 +#define SCI_SETMOUSESELECTIONRECTANGULARSWITCH 2668 +#define SCI_GETMOUSESELECTIONRECTANGULARSWITCH 2669 #define SCI_SETMULTIPLESELECTION 2563 #define SCI_GETMULTIPLESELECTION 2564 #define SCI_SETADDITIONALSELECTIONTYPING 2565 @@ -745,9 +1074,12 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_SETADDITIONALCARETSVISIBLE 2608 #define SCI_GETADDITIONALCARETSVISIBLE 2609 #define SCI_GETSELECTIONS 2570 +#define SCI_GETSELECTIONEMPTY 2650 #define SCI_CLEARSELECTIONS 2571 #define SCI_SETSELECTION 2572 #define SCI_ADDSELECTION 2573 +#define SCI_SELECTIONFROMPOINT 2474 +#define SCI_DROPSELECTIONN 2671 #define SCI_SETMAINSELECTION 2574 #define SCI_GETMAINSELECTION 2575 #define SCI_SETSELECTIONNCARET 2576 @@ -760,7 +1092,9 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_GETSELECTIONNANCHORVIRTUALSPACE 2583 #define SCI_SETSELECTIONNSTART 2584 #define SCI_GETSELECTIONNSTART 2585 +#define SCI_GETSELECTIONNSTARTVIRTUALSPACE 2726 #define SCI_SETSELECTIONNEND 2586 +#define SCI_GETSELECTIONNENDVIRTUALSPACE 2727 #define SCI_GETSELECTIONNEND 2587 #define SCI_SETRECTANGULARSELECTIONCARET 2588 #define SCI_GETRECTANGULARSELECTIONCARET 2589 @@ -773,6 +1107,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCVS_NONE 0 #define SCVS_RECTANGULARSELECTION 1 #define SCVS_USERACCESSIBLE 2 +#define SCVS_NOWRAPLINESTART 4 #define SCI_SETVIRTUALSPACEOPTIONS 2596 #define SCI_GETVIRTUALSPACEOPTIONS 2597 #define SCI_SETRECTANGULARSELECTIONMODIFIER 2598 @@ -785,21 +1120,99 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_GETADDITIONALCARETFORE 2605 #define SCI_ROTATESELECTION 2606 #define SCI_SWAPMAINANCHORCARET 2607 +#define SCI_MULTIPLESELECTADDNEXT 2688 +#define SCI_MULTIPLESELECTADDEACH 2689 #define SCI_CHANGELEXERSTATE 2617 +#define SCI_CONTRACTEDFOLDNEXT 2618 +#define SCI_VERTICALCENTRECARET 2619 +#define SCI_MOVESELECTEDLINESUP 2620 +#define SCI_MOVESELECTEDLINESDOWN 2621 +#define SCI_SETIDENTIFIER 2622 +#define SCI_GETIDENTIFIER 2623 +#define SCI_RGBAIMAGESETWIDTH 2624 +#define SCI_RGBAIMAGESETHEIGHT 2625 +#define SCI_RGBAIMAGESETSCALE 2651 +#define SCI_MARKERDEFINERGBAIMAGE 2626 +#define SCI_REGISTERRGBAIMAGE 2627 +#define SCI_SCROLLTOSTART 2628 +#define SCI_SCROLLTOEND 2629 +#define SC_TECHNOLOGY_DEFAULT 0 +#define SC_TECHNOLOGY_DIRECTWRITE 1 +#define SC_TECHNOLOGY_DIRECTWRITERETAIN 2 +#define SC_TECHNOLOGY_DIRECTWRITEDC 3 +#define SC_TECHNOLOGY_DIRECT_WRITE_1 4 +#define SCI_SETTECHNOLOGY 2630 +#define SCI_GETTECHNOLOGY 2631 +#define SCI_CREATELOADER 2632 +#define SCI_FINDINDICATORSHOW 2640 +#define SCI_FINDINDICATORFLASH 2641 +#define SCI_FINDINDICATORHIDE 2642 +#define SCI_VCHOMEDISPLAY 2652 +#define SCI_VCHOMEDISPLAYEXTEND 2653 +#define SCI_GETCARETLINEVISIBLEALWAYS 2654 +#define SCI_SETCARETLINEVISIBLEALWAYS 2655 +#define SC_LINE_END_TYPE_DEFAULT 0 +#define SC_LINE_END_TYPE_UNICODE 1 +#define SCI_SETLINEENDTYPESALLOWED 2656 +#define SCI_GETLINEENDTYPESALLOWED 2657 +#define SCI_GETLINEENDTYPESACTIVE 2658 +#define SCI_SETREPRESENTATION 2665 +#define SCI_GETREPRESENTATION 2666 +#define SCI_CLEARREPRESENTATION 2667 +#define SCI_CLEARALLREPRESENTATIONS 2770 +#define SC_REPRESENTATION_PLAIN 0 +#define SC_REPRESENTATION_BLOB 1 +#define SC_REPRESENTATION_COLOUR 0x10 +#define SCI_SETREPRESENTATIONAPPEARANCE 2766 +#define SCI_GETREPRESENTATIONAPPEARANCE 2767 +#define SCI_SETREPRESENTATIONCOLOUR 2768 +#define SCI_GETREPRESENTATIONCOLOUR 2769 +#define SCI_EOLANNOTATIONSETTEXT 2740 +#define SCI_EOLANNOTATIONGETTEXT 2741 +#define SCI_EOLANNOTATIONSETSTYLE 2742 +#define SCI_EOLANNOTATIONGETSTYLE 2743 +#define SCI_EOLANNOTATIONCLEARALL 2744 +#define EOLANNOTATION_HIDDEN 0x0 +#define EOLANNOTATION_STANDARD 0x1 +#define EOLANNOTATION_BOXED 0x2 +#define EOLANNOTATION_STADIUM 0x100 +#define EOLANNOTATION_FLAT_CIRCLE 0x101 +#define EOLANNOTATION_ANGLE_CIRCLE 0x102 +#define EOLANNOTATION_CIRCLE_FLAT 0x110 +#define EOLANNOTATION_FLATS 0x111 +#define EOLANNOTATION_ANGLE_FLAT 0x112 +#define EOLANNOTATION_CIRCLE_ANGLE 0x120 +#define EOLANNOTATION_FLAT_ANGLE 0x121 +#define EOLANNOTATION_ANGLES 0x122 +#define SCI_EOLANNOTATIONSETVISIBLE 2745 +#define SCI_EOLANNOTATIONGETVISIBLE 2746 +#define SCI_EOLANNOTATIONSETSTYLEOFFSET 2747 +#define SCI_EOLANNOTATIONGETSTYLEOFFSET 2748 +#define SC_SUPPORTS_LINE_DRAWS_FINAL 0 +#define SC_SUPPORTS_PIXEL_DIVISIONS 1 +#define SC_SUPPORTS_FRACTIONAL_STROKE_WIDTH 2 +#define SC_SUPPORTS_TRANSLUCENT_STROKE 3 +#define SC_SUPPORTS_PIXEL_MODIFICATION 4 +#define SC_SUPPORTS_THREAD_SAFE_MEASURE_WIDTHS 5 +#define SCI_SUPPORTSFEATURE 2750 +#define SC_LINECHARACTERINDEX_NONE 0 +#define SC_LINECHARACTERINDEX_UTF32 1 +#define SC_LINECHARACTERINDEX_UTF16 2 +#define SCI_GETLINECHARACTERINDEX 2710 +#define SCI_ALLOCATELINECHARACTERINDEX 2711 +#define SCI_RELEASELINECHARACTERINDEX 2712 +#define SCI_LINEFROMINDEXPOSITION 2713 +#define SCI_INDEXPOSITIONFROMLINE 2714 #define SCI_STARTRECORD 3001 #define SCI_STOPRECORD 3002 -#define SCI_SETLEXER 4001 #define SCI_GETLEXER 4002 #define SCI_COLOURISE 4003 #define SCI_SETPROPERTY 4004 -#define KEYWORDSET_MAX 8 +#define KEYWORDSET_MAX 30 #define SCI_SETKEYWORDS 4005 -#define SCI_SETLEXERLANGUAGE 4006 -#define SCI_LOADLEXERLIBRARY 4007 #define SCI_GETPROPERTY 4008 #define SCI_GETPROPERTYEXPANDED 4009 #define SCI_GETPROPERTYINT 4010 -#define SCI_GETSTYLEBITSNEEDED 4011 #define SCI_GETLEXERLANGUAGE 4012 #define SCI_PRIVATELEXERCALL 4013 #define SCI_PROPERTYNAMES 4014 @@ -809,6 +1222,22 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_PROPERTYTYPE 4015 #define SCI_DESCRIBEPROPERTY 4016 #define SCI_DESCRIBEKEYWORDSETS 4017 +#define SCI_GETLINEENDTYPESSUPPORTED 4018 +#define SCI_ALLOCATESUBSTYLES 4020 +#define SCI_GETSUBSTYLESSTART 4021 +#define SCI_GETSUBSTYLESLENGTH 4022 +#define SCI_GETSTYLEFROMSUBSTYLE 4027 +#define SCI_GETPRIMARYSTYLEFROMSTYLE 4028 +#define SCI_FREESUBSTYLES 4023 +#define SCI_SETIDENTIFIERS 4024 +#define SCI_DISTANCETOSECONDARYSTYLES 4025 +#define SCI_GETSUBSTYLEBASES 4026 +#define SCI_GETNAMEDSTYLES 4029 +#define SCI_NAMEOFSTYLE 4030 +#define SCI_TAGSOFSTYLE 4031 +#define SCI_DESCRIPTIONOFSTYLE 4032 +#define SCI_SETILEXER 4033 +#define SC_MOD_NONE 0x0 #define SC_MOD_INSERTTEXT 0x1 #define SC_MOD_DELETETEXT 0x2 #define SC_MOD_CHANGESTYLE 0x4 @@ -829,7 +1258,15 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SC_MOD_CHANGEANNOTATION 0x20000 #define SC_MOD_CONTAINER 0x40000 #define SC_MOD_LEXERSTATE 0x80000 -#define SC_MODEVENTMASKALL 0xFFFFF +#define SC_MOD_INSERTCHECK 0x100000 +#define SC_MOD_CHANGETABSTOPS 0x200000 +#define SC_MOD_CHANGEEOLANNOTATION 0x400000 +#define SC_MODEVENTMASKALL 0x7FFFFF +#define SC_UPDATE_NONE 0x0 +#define SC_UPDATE_CONTENT 0x1 +#define SC_UPDATE_SELECTION 0x2 +#define SC_UPDATE_V_SCROLL 0x4 +#define SC_UPDATE_H_SCROLL 0x8 #define SCEN_CHANGE 768 #define SCEN_SETFOCUS 512 #define SCEN_KILLFOCUS 256 @@ -858,6 +1295,16 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCMOD_CTRL 2 #define SCMOD_ALT 4 #define SCMOD_SUPER 8 +#define SCMOD_META 16 +#define SC_AC_FILLUP 1 +#define SC_AC_DOUBLECLICK 2 +#define SC_AC_TAB 3 +#define SC_AC_NEWLINE 4 +#define SC_AC_COMMAND 5 +#define SC_AC_SINGLE_CHOICE 6 +#define SC_CHARACTERSOURCE_DIRECT_INPUT 0 +#define SC_CHARACTERSOURCE_TENTATIVE_INPUT 1 +#define SC_CHARACTERSOURCE_IME_RESULT 2 #define SCN_STYLENEEDED 2000 #define SCN_CHARADDED 2001 #define SCN_SAVEPOINTREACHED 2002 @@ -884,35 +1331,68 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCN_INDICATORRELEASE 2024 #define SCN_AUTOCCANCELLED 2025 #define SCN_AUTOCCHARDELETED 2026 +#define SCN_HOTSPOTRELEASECLICK 2027 +#define SCN_FOCUSIN 2028 +#define SCN_FOCUSOUT 2029 +#define SCN_AUTOCCOMPLETED 2030 +#define SCN_MARGINRIGHTCLICK 2031 +#define SCN_AUTOCSELECTIONCHANGE 2032 +#ifndef SCI_DISABLE_PROVISIONAL +#define SC_BIDIRECTIONAL_DISABLED 0 +#define SC_BIDIRECTIONAL_L2R 1 +#define SC_BIDIRECTIONAL_R2L 2 +#define SCI_GETBIDIRECTIONAL 2708 +#define SCI_SETBIDIRECTIONAL 2709 +#endif + +#define SC_SEARCHRESULT_LINEBUFFERMAXLENGTH 2048 +#define SCI_GETBOOSTREGEXERRMSG 5000 +#define SCN_FOLDINGSTATECHANGED 2081 /* --Autogenerated -- end of section automatically generated from Scintilla.iface */ +#endif + /* These structures are defined to be exactly the same shape as the Win32 * CHARRANGE, TEXTRANGE, FINDTEXTEX, FORMATRANGE, and NMHDR structs. * So older code that treats Scintilla as a RichEdit will work. */ -#ifdef SCI_NAMESPACE -namespace Scintilla { -#endif +//deprecated by N++ 2GB+ support via new scintilla interfaces from 5.2.3 (see https://www.scintilla.org/ScintillaHistory.html), +//please use SCI_GETTEXTRANGEFULL, SCI_FINDTEXTFULL, and SCI_FORMATRANGEFULL and corresponding defines/structs +//struct Sci_CharacterRange { +// Sci_PositionCR cpMin; +// Sci_PositionCR cpMax; +//}; -struct Sci_CharacterRange { - long cpMin; - long cpMax; +struct Sci_CharacterRangeFull { + Sci_Position cpMin; + Sci_Position cpMax; }; -struct Sci_TextRange { - struct Sci_CharacterRange chrg; - char *lpstrText; -}; +//deprecated by N++ 2GB+ support via new scintilla interfaces from 5.2.3 (see https://www.scintilla.org/ScintillaHistory.html), +//please use SCI_GETTEXTRANGEFULL, SCI_FINDTEXTFULL, and SCI_FORMATRANGEFULL and corresponding defines/structs +//struct Sci_TextRange { +// struct Sci_CharacterRange chrg; +// char *lpstrText; +//}; -struct Sci_TextToFind { - struct Sci_CharacterRange chrg; +struct Sci_TextRangeFull { + struct Sci_CharacterRangeFull chrg; char *lpstrText; - struct Sci_CharacterRange chrgText; }; -#define CharacterRange Sci_CharacterRange -#define TextRange Sci_TextRange -#define TextToFind Sci_TextToFind +//deprecated by N++ 2GB+ support via new scintilla interfaces from 5.2.3 (see https://www.scintilla.org/ScintillaHistory.html), +//please use SCI_GETTEXTRANGEFULL, SCI_FINDTEXTFULL, and SCI_FORMATRANGEFULL and corresponding defines/structs +//struct Sci_TextToFind { +// struct Sci_CharacterRange chrg; +// const char *lpstrText; +// struct Sci_CharacterRange chrgText; +//}; + +struct Sci_TextToFindFull { + struct Sci_CharacterRangeFull chrg; + const char *lpstrText; + struct Sci_CharacterRangeFull chrgText; +}; typedef void *Sci_SurfaceID; @@ -926,15 +1406,30 @@ struct Sci_Rectangle { /* This structure is used in printing and requires some of the graphics types * from Platform.h. Not needed by most client code. */ -struct Sci_RangeToFormat { +//deprecated by N++ 2GB+ support via new scintilla interfaces from 5.2.3 (see https://www.scintilla.org/ScintillaHistory.html), +//please use SCI_GETTEXTRANGEFULL, SCI_FINDTEXTFULL, and SCI_FORMATRANGEFULL and corresponding defines/structs +//struct Sci_RangeToFormat { +// Sci_SurfaceID hdc; +// Sci_SurfaceID hdcTarget; +// struct Sci_Rectangle rc; +// struct Sci_Rectangle rcPage; +// struct Sci_CharacterRange chrg; +//}; + +struct Sci_RangeToFormatFull { Sci_SurfaceID hdc; Sci_SurfaceID hdcTarget; struct Sci_Rectangle rc; struct Sci_Rectangle rcPage; - struct Sci_CharacterRange chrg; + struct Sci_CharacterRangeFull chrg; }; -#define RangeToFormat Sci_RangeToFormat +#ifndef __cplusplus +/* For the GTK+ platform, g-ir-scanner needs to have these typedefs. This + * is not required in C++ code and has caused problems in the past. */ +typedef struct Sci_NotifyHeader Sci_NotifyHeader; +typedef struct SCNotification SCNotification; +#endif struct Sci_NotifyHeader { /* Compatible with Windows NMHDR. @@ -945,38 +1440,81 @@ struct Sci_NotifyHeader { unsigned int code; }; -#define NotifyHeader Sci_NotifyHeader - struct SCNotification { - struct Sci_NotifyHeader nmhdr; - int position; /* SCN_STYLENEEDED, SCN_MODIFIED, SCN_DWELLSTART, SCN_DWELLEND */ - int ch; /* SCN_CHARADDED, SCN_KEY */ - int modifiers; /* SCN_KEY */ + Sci_NotifyHeader nmhdr; + Sci_Position position; + /* SCN_STYLENEEDED, SCN_DOUBLECLICK, SCN_MODIFIED, SCN_MARGINCLICK, */ + /* SCN_MARGINRIGHTCLICK, SCN_NEEDSHOWN, SCN_DWELLSTART, SCN_DWELLEND, */ + /* SCN_CALLTIPCLICK, */ + /* SCN_HOTSPOTCLICK, SCN_HOTSPOTDOUBLECLICK, SCN_HOTSPOTRELEASECLICK, */ + /* SCN_INDICATORCLICK, SCN_INDICATORRELEASE, */ + /* SCN_USERLISTSELECTION, SCN_AUTOCCOMPLETED, SCN_AUTOCSELECTION, */ + /* SCN_AUTOCSELECTIONCHANGE */ + + int ch; + /* SCN_CHARADDED, SCN_KEY, SCN_AUTOCCOMPLETED, SCN_AUTOCSELECTION, */ + /* SCN_USERLISTSELECTION */ + int modifiers; + /* SCN_KEY, SCN_DOUBLECLICK, SCN_HOTSPOTCLICK, SCN_HOTSPOTDOUBLECLICK, */ + /* SCN_HOTSPOTRELEASECLICK, SCN_INDICATORCLICK, SCN_INDICATORRELEASE, */ + /* SCN_MARGINCLICK, SCN_MARGINRIGHTCLICK */ + int modificationType; /* SCN_MODIFIED */ - const char *text; /* SCN_MODIFIED, SCN_USERLISTSELECTION, SCN_AUTOCSELECTION */ - int length; /* SCN_MODIFIED */ - int linesAdded; /* SCN_MODIFIED */ + const char *text; + /* SCN_MODIFIED, SCN_USERLISTSELECTION, SCN_URIDROPPED, */ + /* SCN_AUTOCCOMPLETED, SCN_AUTOCSELECTION, SCN_AUTOCSELECTIONCHANGE */ + + Sci_Position length; /* SCN_MODIFIED */ + Sci_Position linesAdded; /* SCN_MODIFIED */ int message; /* SCN_MACRORECORD */ uptr_t wParam; /* SCN_MACRORECORD */ sptr_t lParam; /* SCN_MACRORECORD */ - int line; /* SCN_MODIFIED */ + Sci_Position line; /* SCN_MODIFIED */ int foldLevelNow; /* SCN_MODIFIED */ int foldLevelPrev; /* SCN_MODIFIED */ - int margin; /* SCN_MARGINCLICK */ - int listType; /* SCN_USERLISTSELECTION */ + int margin; /* SCN_MARGINCLICK, SCN_MARGINRIGHTCLICK */ + int listType; /* SCN_USERLISTSELECTION, SCN_AUTOCSELECTIONCHANGE */ int x; /* SCN_DWELLSTART, SCN_DWELLEND */ int y; /* SCN_DWELLSTART, SCN_DWELLEND */ int token; /* SCN_MODIFIED with SC_MOD_CONTAINER */ - int annotationLinesAdded; /* SC_MOD_CHANGEANNOTATION */ + Sci_Position annotationLinesAdded; /* SCN_MODIFIED with SC_MOD_CHANGEANNOTATION */ + int updated; /* SCN_UPDATEUI */ + int listCompletionMethod; + /* SCN_AUTOCSELECTION, SCN_AUTOCCOMPLETED, SCN_USERLISTSELECTION */ + int characterSource; /* SCN_CHARADDED */ }; -#ifdef SCI_NAMESPACE -} -#endif +#include +struct SearchResultMarkingLine { // each line could have several segments if user want to see only 1 found line which contains several results + std::vector> _segmentPostions; // a vector of pair of start & end of occurrence for colourizing +}; +struct SearchResultMarkings { + intptr_t _length; + SearchResultMarkingLine *_markings; +}; #ifdef INCLUDE_DEPRECATED_FEATURES -#define SC_CP_DBCS 1 +#define SCI_SETKEYSUNICODE 2521 +#define SCI_GETKEYSUNICODE 2522 + +#define SCI_GETTWOPHASEDRAW 2283 +#define SCI_SETTWOPHASEDRAW 2284 + +#define CharacterRange Sci_CharacterRange +#define TextRange Sci_TextRange +#define TextToFind Sci_TextToFind +#define RangeToFormat Sci_RangeToFormat +#define NotifyHeader Sci_NotifyHeader + +#define SCI_SETSTYLEBITS 2090 +#define SCI_GETSTYLEBITS 2091 +#define SCI_GETSTYLEBITSNEEDED 4011 + +#define INDIC0_MASK 0x20 +#define INDIC1_MASK 0x40 +#define INDIC2_MASK 0x80 +#define INDICS_MASK 0xE0 #endif diff --git a/NppPlugin/include/StaticDialog.h b/NppPlugin/include/StaticDialog.h index cc7dd600..b475bdbb 100644 --- a/NppPlugin/include/StaticDialog.h +++ b/NppPlugin/include/StaticDialog.h @@ -1,63 +1,95 @@ -//this file is part of notepad++ -//Copyright (C)2003 Don HO ( donho@altern.org ) -// -//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 file is part of Notepad++ project +// Copyright (C)2024 Don HO + +// 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 3 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. +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. - -#ifndef STATIC_DIALOG_H -#define STATIC_DIALOG_H +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +#pragma once +#include "dpiManagerV2.h" +#include "Notepad_plus_msgs.h" #include "Window.h" -enum PosAlign{ALIGNPOS_LEFT, ALIGNPOS_RIGHT, ALIGNPOS_TOP, ALIGNPOS_BOTTOM}; - -struct DLGTEMPLATEEX { - WORD dlgVer; - WORD signature; - DWORD helpID; - DWORD exStyle; - DWORD style; - WORD cDlgItems; - short x; - short y; - short cx; - short cy; +typedef HRESULT (WINAPI * ETDTProc) (HWND, DWORD); + +enum class PosAlign { left, right, top, bottom }; + +struct DLGTEMPLATEEX +{ + WORD dlgVer = 0; + WORD signature = 0; + DWORD helpID = 0; + DWORD exStyle = 0; + DWORD style = 0; + WORD cDlgItems = 0; + short x = 0; + short y = 0; + short cx = 0; + short cy = 0; // The structure has more fields but are variable length -} ; +}; class StaticDialog : public Window { public : - StaticDialog(){} - ~StaticDialog(); + virtual ~StaticDialog(); - virtual void create(int dialogID, bool isRTL = false); + virtual void create(int dialogID, bool isRTL = false, bool msgDestParent = true); - virtual bool isCreated() const { - return (_hSelf != NULL); + virtual bool isCreated() const { + return (_hSelf != nullptr); } - void goToCenter(); - void destroy(); + void getMappedChildRect(HWND hChild, RECT& rcChild) const; + void getMappedChildRect(int idChild, RECT& rcChild) const; + void redrawDlgItem(const int nIDDlgItem, bool forceUpdate = false) const; + + void goToCenter(UINT swpFlags = SWP_SHOWWINDOW); + bool moveForDpiChange(); + + void display(bool toShow = true, bool enhancedPositioningCheckWhenShowing = false) const; -protected : - RECT _rc; - static BOOL CALLBACK dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); - virtual BOOL CALLBACK run_dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) = 0; + RECT getViewablePositionRect(RECT testRc) const; + + POINT getTopPoint(HWND hwnd, bool isLeft = true) const; + + bool isCheckedOrNot(int checkControlID) const + { + return (BST_CHECKED == ::SendMessage(::GetDlgItem(_hSelf, checkControlID), BM_GETCHECK, 0, 0)); + } + + void setChecked(int checkControlID, bool checkOrNot = true) const + { + ::SendDlgItemMessage(_hSelf, checkControlID, BM_SETCHECK, checkOrNot ? BST_CHECKED : BST_UNCHECKED, 0); + } + + void setDpi() { + _dpiManager.setDpi(_hSelf); + } + + void setPositionDpi(LPARAM lParam, UINT flags = SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE) { + DPIManagerV2::setPositionDpi(lParam, _hSelf, flags); + } + + void destroy() override; + + DPIManagerV2& dpiManager() { return _dpiManager; } + +protected: + RECT _rc{}; + DPIManagerV2 _dpiManager; + + static intptr_t CALLBACK dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); + virtual intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) = 0; - void alignWith(HWND handle, HWND handle2Align, PosAlign pos, POINT & point); HGLOBAL makeRTLResource(int dialogID, DLGTEMPLATE **ppMyDlgTemplate); }; - -#endif //STATIC_DIALOG_H diff --git a/NppPlugin/include/SysMsg.h b/NppPlugin/include/SysMsg.h deleted file mode 100644 index d217c45b..00000000 --- a/NppPlugin/include/SysMsg.h +++ /dev/null @@ -1,27 +0,0 @@ -//this file is part of notepad++ -//Copyright (C)2003 Don HO ( donho@altern.org ) -// -//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., 675 Mass Ave, Cambridge, MA 02139, USA. - -#ifndef M30_IDE_COMMUN_H -#define M30_IDE_COMMUN_H - -#include - - -void systemMessage(const char *title); -DWORD ShortToLongPathName(LPCTSTR lpszShortPath, LPTSTR lpszLongPath, DWORD cchBuffer); - -#endif //M30_IDE_COMMUN_H diff --git a/NppPlugin/include/Window.h b/NppPlugin/include/Window.h index 16a0462e..79a7fa34 100644 --- a/NppPlugin/include/Window.h +++ b/NppPlugin/include/Window.h @@ -1,31 +1,35 @@ -//this file is part of notepad++ -//Copyright (C)2003 Don HO -// -//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 file is part of Notepad++ project +// Copyright (C)2024 Don HO + +// 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 3 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. +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . -#ifndef WINDOW_CONTROL_H -#define WINDOW_CONTROL_H + +#pragma once +#include class Window { public: - Window(): _hInst(NULL), _hParent(NULL), _hSelf(NULL){}; - virtual ~Window() {}; + //! \name Constructors & Destructor + //@{ + Window() = default; + Window(const Window&) = delete; + virtual ~Window() = default; + //@} - virtual void init(HINSTANCE hInst, HWND parent) - { + + virtual void init(HINSTANCE hInst, HWND parent) { _hInst = hInst; _hParent = parent; } @@ -33,39 +37,42 @@ class Window virtual void destroy() = 0; virtual void display(bool toShow = true) const { - ::ShowWindow(_hSelf, toShow?SW_SHOW:SW_HIDE); - }; - - virtual void reSizeTo(RECT & rc) // should NEVER be const !!! - { + ::ShowWindow(_hSelf, toShow ? SW_SHOW : SW_HIDE); + } + + + virtual void reSizeTo(RECT & rc) { // should NEVER be const !!! ::MoveWindow(_hSelf, rc.left, rc.top, rc.right, rc.bottom, TRUE); redraw(); - }; + } - virtual void reSizeToWH(RECT & rc) // should NEVER be const !!! - { + + virtual void reSizeToWH(RECT& rc) { // should NEVER be const !!! ::MoveWindow(_hSelf, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, TRUE); redraw(); - }; + } + + + virtual void redraw(bool forceUpdate = false) const { + ::InvalidateRect(_hSelf, nullptr, TRUE); + if (forceUpdate) + ::UpdateWindow(_hSelf); + } + - virtual void redraw() const { - ::InvalidateRect(_hSelf, NULL, TRUE); - ::UpdateWindow(_hSelf); - }; - virtual void getClientRect(RECT & rc) const { ::GetClientRect(_hSelf, &rc); - }; + } virtual void getWindowRect(RECT & rc) const { ::GetWindowRect(_hSelf, &rc); - }; + } virtual int getWidth() const { RECT rc; ::GetClientRect(_hSelf, &rc); return (rc.right - rc.left); - }; + } virtual int getHeight() const { RECT rc; @@ -73,45 +80,35 @@ class Window if (::IsWindowVisible(_hSelf) == TRUE) return (rc.bottom - rc.top); return 0; - }; + } - virtual bool isVisible() const { + virtual bool isVisible() const + { return (::IsWindowVisible(_hSelf)?true:false); - }; + } HWND getHSelf() const { - /* - if (!_hSelf) - { - ::MessageBox(NULL, TEXT("_hSelf == NULL"), TEXT("class Window"), MB_OK); - throw int(999); - } - */ return _hSelf; - }; + } HWND getHParent() const { return _hParent; - }; + } - void getFocus() const { + void grabFocus() const { ::SetFocus(_hSelf); - }; + } HINSTANCE getHinst() const { - if (!_hInst) - { - ::MessageBox(NULL, TEXT("_hInst == NULL"), TEXT("class Window"), MB_OK); - throw int(1999); - } return _hInst; - }; -protected: - HINSTANCE _hInst; - HWND _hParent; - HWND _hSelf; -}; + } + -#endif //WINDOW_CONTROL_H + Window& operator = (const Window&) = delete; +protected: + HINSTANCE _hInst = NULL; + HWND _hParent = NULL; + HWND _hSelf = NULL; +}; \ No newline at end of file diff --git a/NppPlugin/include/dockingResource.h b/NppPlugin/include/dockingResource.h index 0d80683c..5a303fe9 100644 --- a/NppPlugin/include/dockingResource.h +++ b/NppPlugin/include/dockingResource.h @@ -1,22 +1,26 @@ -//this file is part of docking functionality for Notepad++ -//Copyright (C)2006 Jens Lorenz -// -//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 file is part of Notepad++ project +// Copyright (C)2006 Jens Lorenz + +// 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 3 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. +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// Contribution by Don HO +// Date of Contribution: 2025-05-14 +// Description of Contribution: Minor change + +#pragma once -#ifndef DOCKING_RESOURCE_H -#define DOCKING_RESOURCE_H +#define DM_NOFOCUSWHILECLICKINGCAPTION L"NOFOCUSWHILECLICKINGCAPTION" #define IDD_PLUGIN_DLG 103 #define IDC_EDIT1 1000 @@ -31,33 +35,25 @@ #define IDC_BTN_CAPTION 1050 #define DMM_MSG 0x5000 - #define DMM_CLOSE (DMM_MSG + 1) - #define DMM_DOCK (DMM_MSG + 2) - #define DMM_FLOAT (DMM_MSG + 3) - #define DMM_DOCKALL (DMM_MSG + 4) - #define DMM_FLOATALL (DMM_MSG + 5) - #define DMM_MOVE (DMM_MSG + 6) - #define DMM_UPDATEDISPINFO (DMM_MSG + 7) - #define DMM_GETIMAGELIST (DMM_MSG + 8) - #define DMM_GETICONPOS (DMM_MSG + 9) - #define DMM_DROPDATA (DMM_MSG + 10) - #define DMM_MOVE_SPLITTER (DMM_MSG + 11) - #define DMM_CANCEL_MOVE (DMM_MSG + 12) - #define DMM_LBUTTONUP (DMM_MSG + 13) + #define DMM_CLOSE (DMM_MSG + 1) + #define DMM_DOCK (DMM_MSG + 2) + #define DMM_FLOAT (DMM_MSG + 3) + #define DMM_DOCKALL (DMM_MSG + 4) + #define DMM_FLOATALL (DMM_MSG + 5) + #define DMM_MOVE (DMM_MSG + 6) + #define DMM_UPDATEDISPINFO (DMM_MSG + 7) + //#define DMM_GETIMAGELIST (DMM_MSG + 8) + //#define DMM_GETICONPOS (DMM_MSG + 9) + #define DMM_DROPDATA (DMM_MSG + 10) + #define DMM_MOVE_SPLITTER (DMM_MSG + 11) + #define DMM_CANCEL_MOVE (DMM_MSG + 12) + #define DMM_LBUTTONUP (DMM_MSG + 13) #define DMN_FIRST 1050 - #define DMN_CLOSE (DMN_FIRST + 1) - //nmhdr.code = DWORD(DMN_CLOSE, 0)); - //nmhdr.hwndFrom = hwndNpp; - //nmhdr.idFrom = ctrlIdNpp; - - #define DMN_DOCK (DMN_FIRST + 2) - #define DMN_FLOAT (DMN_FIRST + 3) - //nmhdr.code = DWORD(DMN_XXX, int newContainer); - //nmhdr.hwndFrom = hwndNpp; - //nmhdr.idFrom = ctrlIdNpp; - - - -#endif //DOCKING_RESOURCE_H + #define DMN_CLOSE (DMN_FIRST + 1) + #define DMN_DOCK (DMN_FIRST + 2) + #define DMN_FLOAT (DMN_FIRST + 3) + #define DMN_SWITCHIN (DMN_FIRST + 4) + #define DMN_SWITCHOFF (DMN_FIRST + 5) + #define DMN_FLOATDROPPED (DMN_FIRST + 6) diff --git a/NppPlugin/include/dpiManagerV2.h b/NppPlugin/include/dpiManagerV2.h new file mode 100644 index 00000000..86efbe44 --- /dev/null +++ b/NppPlugin/include/dpiManagerV2.h @@ -0,0 +1,146 @@ +// This file is part of Notepad++ project +// Copyright (c) 2024 ozone10 and Notepad++ team + +// 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 3 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, see . + + +#pragma once +#include "NppDarkMode.h" + +#ifndef WM_DPICHANGED +#define WM_DPICHANGED 0x02E0 +#endif + +#ifndef WM_DPICHANGED_BEFOREPARENT +#define WM_DPICHANGED_BEFOREPARENT 0x02E2 +#endif + +#ifndef WM_DPICHANGED_AFTERPARENT +#define WM_DPICHANGED_AFTERPARENT 0x02E3 +#endif + +#ifndef WM_GETDPISCALEDSIZE +#define WM_GETDPISCALEDSIZE 0x02E4 +#endif + +#ifndef USER_DEFAULT_SCREEN_DPI +#define USER_DEFAULT_SCREEN_DPI 96 +#endif + +class DPIManagerV2 +{ +public: + DPIManagerV2() { + setDpiWithSystem(); + } + virtual ~DPIManagerV2() = default; + + enum class FontType { menu, status, message, caption, smcaption }; + + static void initDpiAPI(); + + static int getSystemMetricsForDpi(int nIndex, UINT dpi); + int getSystemMetricsForDpi(int nIndex) const { + return getSystemMetricsForDpi(nIndex, _dpi); + } + static DPI_AWARENESS_CONTEXT setThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT dpiContext); + static BOOL adjustWindowRectExForDpi(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle, UINT dpi); + + + static UINT getDpiForSystem(); + static UINT getDpiForWindow(HWND hWnd); + static UINT getDpiForParent(HWND hWnd) { + return getDpiForWindow(::GetParent(hWnd)); + } + + void setDpiWithSystem() { + _dpi = getDpiForSystem(); + } + + // parameter is WPARAM + void setDpiWP(WPARAM wParam) { + _dpi = LOWORD(wParam); + } + + void setDpi(UINT newDpi) { + _dpi = newDpi; + } + + void setDpi(HWND hWnd) { + setDpi(getDpiForWindow(hWnd)); + } + + void setDpiWithParent(HWND hWnd) { + setDpi(::GetParent(hWnd)); + } + + UINT getDpi() const { + return _dpi; + } + + static void setPositionDpi(LPARAM lParam, HWND hWnd, UINT flags = SWP_NOZORDER | SWP_NOACTIVATE); + + static int scale(int x, UINT toDpi, UINT fromDpi) { + return MulDiv(x, toDpi, fromDpi); + } + + static int scale(int x, UINT dpi) { + return scale(x, dpi, USER_DEFAULT_SCREEN_DPI); + } + + static int unscale(int x, UINT dpi) { + return scale(x, USER_DEFAULT_SCREEN_DPI, dpi); + } + + static int scale(int x, HWND hWnd) { + return scale(x, getDpiForWindow(hWnd), USER_DEFAULT_SCREEN_DPI); + } + + static int unscale(int x, HWND hWnd) { + return scale(x, USER_DEFAULT_SCREEN_DPI, getDpiForWindow(hWnd)); + } + + int scale(int x) const { + return scale(x, _dpi); + } + + int unscale(int x) const { + return unscale(x, _dpi); + } + + static int scaleFont(int pt, UINT dpi) { + return -(scale(pt, dpi, 72)); + } + + static int scaleFont(int pt, HWND hWnd) { + return -(scale(pt, getDpiForWindow(hWnd), 72)); + } + + int scaleFont(int pt) const { + return scaleFont(pt, _dpi); + } + + static LOGFONT getDefaultGUIFontForDpi(UINT dpi, FontType type = FontType::message); + static LOGFONT getDefaultGUIFontForDpi(HWND hWnd, FontType type = FontType::message) { + return getDefaultGUIFontForDpi(getDpiForWindow(hWnd), type); + } + LOGFONT getDefaultGUIFontForDpi(FontType type = FontType::message) const { + return getDefaultGUIFontForDpi(_dpi, type); + } + + static void loadIcon(HINSTANCE hinst, const wchar_t* pszName, int cx, int cy, HICON* phico, UINT fuLoad = LR_DEFAULTCOLOR); + +private: + UINT _dpi = USER_DEFAULT_SCREEN_DPI; +}; diff --git a/NppPlugin/include/keys.h b/NppPlugin/include/keys.h index 17fd3ef4..10f5517a 100644 --- a/NppPlugin/include/keys.h +++ b/NppPlugin/include/keys.h @@ -1,54 +1,28 @@ +// This file is part of Notepad++ project +// Copyright (C)2023 Don HO + +// 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 3 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, see . + +#include + /* See winuser.h -Altered list to support VK_0-9 and VK_A-Z +Altered list to support VK_0-9 and VK_A-Z, plus VK_NULL */ #define VK_NULL 0x00 -#define VK_CANCEL 0x03 - -#define VK_BACK 0x08 -#define VK_TAB 0x09 - -#define VK_CLEAR 0x0C -#define VK_RETURN 0x0D - -#define VK_SHIFT 0x10 -#define VK_CONTROL 0x11 -#define VK_MENU 0x12 -#define VK_PAUSE 0x13 -#define VK_CAPITAL 0x14 - -#define VK_KANA 0x15 -#define VK_HANGUL 0x15 -#define VK_JUNJA 0x17 -#define VK_FINAL 0x18 -#define VK_HANJA 0x19 -#define VK_KANJI 0x19 - -#define VK_ESCAPE 0x1B - -#define VK_CONVERT 0x1C -#define VK_NONCONVERT 0x1D -#define VK_ACCEPT 0x1E -#define VK_MODECHANGE 0x1F - -#define VK_SPACE 0x20 -#define VK_PRIOR 0x21 -#define VK_NEXT 0x22 -#define VK_END 0x23 -#define VK_HOME 0x24 -#define VK_LEFT 0x25 -#define VK_UP 0x26 -#define VK_RIGHT 0x27 -#define VK_DOWN 0x28 -#define VK_SELECT 0x29 -#define VK_PRINT 0x2A -#define VK_EXECUTE 0x2B -#define VK_SNAPSHOT 0x2C -#define VK_INSERT 0x2D -#define VK_DELETE 0x2E -#define VK_HELP 0x2F #define VK_0 0x30 #define VK_1 0x31 @@ -86,93 +60,3 @@ Altered list to support VK_0-9 and VK_A-Z #define VK_X 0x58 #define VK_Y 0x59 #define VK_Z 0x5A - -#define VK_LWIN 0x5B -#define VK_RWIN 0x5C -#define VK_APPS 0x5D - - -#define VK_SLEEP 0x5F - -#define VK_NUMPAD0 0x60 -#define VK_NUMPAD1 0x61 -#define VK_NUMPAD2 0x62 -#define VK_NUMPAD3 0x63 -#define VK_NUMPAD4 0x64 -#define VK_NUMPAD5 0x65 -#define VK_NUMPAD6 0x66 -#define VK_NUMPAD7 0x67 -#define VK_NUMPAD8 0x68 -#define VK_NUMPAD9 0x69 -#define VK_MULTIPLY 0x6A -#define VK_ADD 0x6B -#define VK_SEPARATOR 0x6C -#define VK_SUBTRACT 0x6D -#define VK_DECIMAL 0x6E -#define VK_DIVIDE 0x6F -#define VK_F1 0x70 -#define VK_F2 0x71 -#define VK_F3 0x72 -#define VK_F4 0x73 -#define VK_F5 0x74 -#define VK_F6 0x75 -#define VK_F7 0x76 -#define VK_F8 0x77 -#define VK_F9 0x78 -#define VK_F10 0x79 -#define VK_F11 0x7A -#define VK_F12 0x7B -#define VK_F13 0x7C -#define VK_F14 0x7D -#define VK_F15 0x7E -#define VK_F16 0x7F -#define VK_F17 0x80 -#define VK_F18 0x81 -#define VK_F19 0x82 -#define VK_F20 0x83 -#define VK_F21 0x84 -#define VK_F22 0x85 -#define VK_F23 0x86 -#define VK_F24 0x87 - -#define VK_NUMLOCK 0x90 -#define VK_SCROLL 0x91 - -#define VK_OEM_1 0xBA // ';:' for US -#define VK_OEM_PLUS 0xBB // '+' any country -#define VK_OEM_COMMA 0xBC // ',' any country -#define VK_OEM_MINUS 0xBD // '-' any country -#define VK_OEM_PERIOD 0xBE // '.' any country -#define VK_OEM_2 0xBF // '/?' for US -#define VK_OEM_3 0xC0 // '`~' for US - -#define VK_OEM_4 0xDB // '[{' for US -#define VK_OEM_5 0xDC // '\|' for US -#define VK_OEM_6 0xDD // ']}' for US -#define VK_OEM_7 0xDE // ''"' for US -#define VK_OEM_8 0xDF - -#define VK_OEM_102 0xE2 // "<>" or "\|" on RT 102-key kbd. - -#define VK_OEM_RESET 0xE9 -#define VK_OEM_JUMP 0xEA -#define VK_OEM_PA1 0xEB -#define VK_OEM_PA2 0xEC -#define VK_OEM_PA3 0xED -#define VK_OEM_WSCTRL 0xEE -#define VK_OEM_CUSEL 0xEF -#define VK_OEM_ATTN 0xF0 -#define VK_OEM_FINISH 0xF1 -#define VK_OEM_COPY 0xF2 -#define VK_OEM_AUTO 0xF3 -#define VK_OEM_ENLW 0xF4 -#define VK_OEM_BACKTAB 0xF5 -#define VK_ATTN 0xF6 -#define VK_CRSEL 0xF7 -#define VK_EXSEL 0xF8 -#define VK_EREOF 0xF9 -#define VK_PLAY 0xFA -#define VK_ZOOM 0xFB -#define VK_NONAME 0xFC -#define VK_PA1 0xFD -#define VK_OEM_CLEAR 0xFE diff --git a/NppPlugin/include/menuCmdID.h b/NppPlugin/include/menuCmdID.h index 5304c77c..137329dd 100644 --- a/NppPlugin/include/menuCmdID.h +++ b/NppPlugin/include/menuCmdID.h @@ -1,108 +1,199 @@ -//this file is part of notepad++ -//Copyright (C)2003 Don HO -// -//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 file is part of Notepad++ project +// Copyright (C)2025 Don HO + +// 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 3 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. +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + -#ifndef MENUCMDID_H -#define MENUCMDID_H +#pragma once #define IDM 40000 #define IDM_FILE (IDM + 1000) - #define IDM_FILE_NEW (IDM_FILE + 1) - #define IDM_FILE_OPEN (IDM_FILE + 2) - #define IDM_FILE_CLOSE (IDM_FILE + 3) - #define IDM_FILE_CLOSEALL (IDM_FILE + 4) - #define IDM_FILE_CLOSEALL_BUT_CURRENT (IDM_FILE + 5) - #define IDM_FILE_SAVE (IDM_FILE + 6) - #define IDM_FILE_SAVEALL (IDM_FILE + 7) - #define IDM_FILE_SAVEAS (IDM_FILE + 8) - //#define IDM_FILE_ASIAN_LANG (IDM_FILE + 9) - #define IDM_FILE_PRINT (IDM_FILE + 10) - #define IDM_FILE_PRINTNOW 1001 - #define IDM_FILE_EXIT (IDM_FILE + 11) - #define IDM_FILE_LOADSESSION (IDM_FILE + 12) - #define IDM_FILE_SAVESESSION (IDM_FILE + 13) - #define IDM_FILE_RELOAD (IDM_FILE + 14) - #define IDM_FILE_SAVECOPYAS (IDM_FILE + 15) - #define IDM_FILE_DELETE (IDM_FILE + 16) - #define IDM_FILE_RENAME (IDM_FILE + 17) - - // A mettre jour si on ajoute nouveau menu item dans le menu "File" - #define IDM_FILEMENU_LASTONE IDM_FILE_RENAME +// IMPORTANT: If list below is modified, you have to change the value of IDM_FILEMENU_LASTONE and IDM_FILEMENU_EXISTCMDPOSITION + #define IDM_FILE_NEW (IDM_FILE + 1) + #define IDM_FILE_OPEN (IDM_FILE + 2) + #define IDM_FILE_CLOSE (IDM_FILE + 3) + #define IDM_FILE_CLOSEALL (IDM_FILE + 4) + #define IDM_FILE_CLOSEALL_BUT_CURRENT (IDM_FILE + 5) + #define IDM_FILE_SAVE (IDM_FILE + 6) + #define IDM_FILE_SAVEALL (IDM_FILE + 7) + #define IDM_FILE_SAVEAS (IDM_FILE + 8) + #define IDM_FILE_CLOSEALL_TOLEFT (IDM_FILE + 9) + #define IDM_FILE_PRINT (IDM_FILE + 10) + #define IDM_FILE_PRINTNOW 1001 + #define IDM_FILE_EXIT (IDM_FILE + 11) + #define IDM_FILE_LOADSESSION (IDM_FILE + 12) + #define IDM_FILE_SAVESESSION (IDM_FILE + 13) + #define IDM_FILE_RELOAD (IDM_FILE + 14) + #define IDM_FILE_SAVECOPYAS (IDM_FILE + 15) + #define IDM_FILE_DELETE (IDM_FILE + 16) + #define IDM_FILE_RENAME (IDM_FILE + 17) + #define IDM_FILE_CLOSEALL_TORIGHT (IDM_FILE + 18) + #define IDM_FILE_OPEN_FOLDER (IDM_FILE + 19) + #define IDM_FILE_OPEN_CMD (IDM_FILE + 20) + #define IDM_FILE_RESTORELASTCLOSEDFILE (IDM_FILE + 21) + #define IDM_FILE_OPENFOLDERASWORKSPACE (IDM_FILE + 22) + #define IDM_FILE_OPEN_DEFAULT_VIEWER (IDM_FILE + 23) + #define IDM_FILE_CLOSEALL_UNCHANGED (IDM_FILE + 24) + #define IDM_FILE_CONTAININGFOLDERASWORKSPACE (IDM_FILE + 25) + #define IDM_FILE_CLOSEALL_BUT_PINNED (IDM_FILE + 26) +// IMPORTANT: If list above is modified, you have to change the following values: +// To be updated if new menu item(s) is (are) added in menu "File" + #define IDM_FILEMENU_LASTONE IDM_FILE_CLOSEALL_BUT_PINNED + +// 0 based position of command "Exit" including the bars in the file menu +// and without counting "Recent files history" items + +// 0 New +// 1 Open... +// 2 Open Containing Folder +// 3 Open Folder as Workspace +// 4 Open in Default Viewer +// 5 Reload from Disk +// 6 Save +// 7 Save As... +// 8 Save a Copy As... +// 9 Save All +//10 Rename... +//11 Close +//12 Close All +//13 Close Multiple Documents +//14 Move to Recycle Bin +//15 -------- +//16 Load Session... +//17 Save Session... +//18 -------- +//19 Print... +//20 Print Now +//21 -------- +//22 Exit + #define IDM_FILEMENU_EXISTCMDPOSITION 22 + + #define IDM_EDIT (IDM + 2000) - #define IDM_EDIT_CUT (IDM_EDIT + 1) - #define IDM_EDIT_COPY (IDM_EDIT + 2) - #define IDM_EDIT_UNDO (IDM_EDIT + 3) - #define IDM_EDIT_REDO (IDM_EDIT + 4) - #define IDM_EDIT_PASTE (IDM_EDIT + 5) - #define IDM_EDIT_DELETE (IDM_EDIT + 6) - #define IDM_EDIT_SELECTALL (IDM_EDIT + 7) - - #define IDM_EDIT_INS_TAB (IDM_EDIT + 8) - #define IDM_EDIT_RMV_TAB (IDM_EDIT + 9) - #define IDM_EDIT_DUP_LINE (IDM_EDIT + 10) - #define IDM_EDIT_TRANSPOSE_LINE (IDM_EDIT + 11) - #define IDM_EDIT_SPLIT_LINES (IDM_EDIT + 12) - #define IDM_EDIT_JOIN_LINES (IDM_EDIT + 13) - #define IDM_EDIT_LINE_UP (IDM_EDIT + 14) - #define IDM_EDIT_LINE_DOWN (IDM_EDIT + 15) - #define IDM_EDIT_UPPERCASE (IDM_EDIT + 16) - #define IDM_EDIT_LOWERCASE (IDM_EDIT + 17) - -// Menu macro - #define IDM_MACRO_STARTRECORDINGMACRO (IDM_EDIT + 18) - #define IDM_MACRO_STOPRECORDINGMACRO (IDM_EDIT + 19) - #define IDM_MACRO_PLAYBACKRECORDEDMACRO (IDM_EDIT + 21) -//----------- - - #define IDM_EDIT_BLOCK_COMMENT (IDM_EDIT + 22) - #define IDM_EDIT_STREAM_COMMENT (IDM_EDIT + 23) - #define IDM_EDIT_TRIMTRAILING (IDM_EDIT + 24) - -// Menu macro - #define IDM_MACRO_SAVECURRENTMACRO (IDM_EDIT + 25) -//----------- - - #define IDM_EDIT_RTL (IDM_EDIT + 26) - #define IDM_EDIT_LTR (IDM_EDIT + 27) - #define IDM_EDIT_SETREADONLY (IDM_EDIT + 28) - #define IDM_EDIT_FULLPATHTOCLIP (IDM_EDIT + 29) - #define IDM_EDIT_FILENAMETOCLIP (IDM_EDIT + 30) - #define IDM_EDIT_CURRENTDIRTOCLIP (IDM_EDIT + 31) - -// Menu macro - #define IDM_MACRO_RUNMULTIMACRODLG (IDM_EDIT + 32) -//----------- - - #define IDM_EDIT_CLEARREADONLY (IDM_EDIT + 33) - #define IDM_EDIT_COLUMNMODE (IDM_EDIT + 34) - #define IDM_EDIT_BLOCK_COMMENT_SET (IDM_EDIT + 35) - #define IDM_EDIT_BLOCK_UNCOMMENT (IDM_EDIT + 36) - - #define IDM_EDIT_AUTOCOMPLETE (50000 + 0) - #define IDM_EDIT_AUTOCOMPLETE_CURRENTFILE (50000 + 1) - #define IDM_EDIT_FUNCCALLTIP (50000 + 2) - - //Belong to MENU FILE - #define IDM_OPEN_ALL_RECENT_FILE (IDM_EDIT + 40) - #define IDM_CLEAN_RECENT_FILE_LIST (IDM_EDIT + 41) + #define IDM_EDIT_CUT (IDM_EDIT + 1) + #define IDM_EDIT_COPY (IDM_EDIT + 2) + #define IDM_EDIT_UNDO (IDM_EDIT + 3) + #define IDM_EDIT_REDO (IDM_EDIT + 4) + #define IDM_EDIT_PASTE (IDM_EDIT + 5) + #define IDM_EDIT_DELETE (IDM_EDIT + 6) + #define IDM_EDIT_SELECTALL (IDM_EDIT + 7) + #define IDM_EDIT_INS_TAB (IDM_EDIT + 8) + #define IDM_EDIT_RMV_TAB (IDM_EDIT + 9) + #define IDM_EDIT_DUP_LINE (IDM_EDIT + 10) + #define IDM_EDIT_TRANSPOSE_LINE (IDM_EDIT + 11) + #define IDM_EDIT_SPLIT_LINES (IDM_EDIT + 12) + #define IDM_EDIT_JOIN_LINES (IDM_EDIT + 13) + #define IDM_EDIT_LINE_UP (IDM_EDIT + 14) + #define IDM_EDIT_LINE_DOWN (IDM_EDIT + 15) + #define IDM_EDIT_UPPERCASE (IDM_EDIT + 16) + #define IDM_EDIT_LOWERCASE (IDM_EDIT + 17) + #define IDM_MACRO_STARTRECORDINGMACRO (IDM_EDIT + 18) + #define IDM_MACRO_STOPRECORDINGMACRO (IDM_EDIT + 19) + #define IDM_EDIT_BEGINENDSELECT (IDM_EDIT + 20) + #define IDM_MACRO_PLAYBACKRECORDEDMACRO (IDM_EDIT + 21) + #define IDM_EDIT_BLOCK_COMMENT (IDM_EDIT + 22) + #define IDM_EDIT_STREAM_COMMENT (IDM_EDIT + 23) + #define IDM_EDIT_TRIMTRAILING (IDM_EDIT + 24) + #define IDM_MACRO_SAVECURRENTMACRO (IDM_EDIT + 25) + #define IDM_EDIT_RTL (IDM_EDIT + 26) + #define IDM_EDIT_LTR (IDM_EDIT + 27) + #define IDM_EDIT_TOGGLEREADONLY (IDM_EDIT + 28) + #define IDM_EDIT_FULLPATHTOCLIP (IDM_EDIT + 29) + #define IDM_EDIT_FILENAMETOCLIP (IDM_EDIT + 30) + #define IDM_EDIT_CURRENTDIRTOCLIP (IDM_EDIT + 31) + #define IDM_MACRO_RUNMULTIMACRODLG (IDM_EDIT + 32) + #define IDM_EDIT_TOGGLESYSTEMREADONLY (IDM_EDIT + 33) + #define IDM_EDIT_COLUMNMODE (IDM_EDIT + 34) + #define IDM_EDIT_BLOCK_COMMENT_SET (IDM_EDIT + 35) + #define IDM_EDIT_BLOCK_UNCOMMENT (IDM_EDIT + 36) + #define IDM_EDIT_COLUMNMODETIP (IDM_EDIT + 37) + #define IDM_EDIT_PASTE_AS_HTML (IDM_EDIT + 38) + #define IDM_EDIT_PASTE_AS_RTF (IDM_EDIT + 39) + #define IDM_OPEN_ALL_RECENT_FILE (IDM_EDIT + 40) + #define IDM_CLEAN_RECENT_FILE_LIST (IDM_EDIT + 41) + #define IDM_EDIT_TRIMLINEHEAD (IDM_EDIT + 42) + #define IDM_EDIT_TRIM_BOTH (IDM_EDIT + 43) + #define IDM_EDIT_EOL2WS (IDM_EDIT + 44) + #define IDM_EDIT_TRIMALL (IDM_EDIT + 45) + #define IDM_EDIT_TAB2SW (IDM_EDIT + 46) + #define IDM_EDIT_STREAM_UNCOMMENT (IDM_EDIT + 47) + #define IDM_EDIT_COPY_BINARY (IDM_EDIT + 48) + #define IDM_EDIT_CUT_BINARY (IDM_EDIT + 49) + #define IDM_EDIT_PASTE_BINARY (IDM_EDIT + 50) + #define IDM_EDIT_CHAR_PANEL (IDM_EDIT + 51) + #define IDM_EDIT_CLIPBOARDHISTORY_PANEL (IDM_EDIT + 52) + #define IDM_EDIT_SW2TAB_LEADING (IDM_EDIT + 53) + #define IDM_EDIT_SW2TAB_ALL (IDM_EDIT + 54) + #define IDM_EDIT_REMOVEEMPTYLINES (IDM_EDIT + 55) + #define IDM_EDIT_REMOVEEMPTYLINESWITHBLANK (IDM_EDIT + 56) + #define IDM_EDIT_BLANKLINEABOVECURRENT (IDM_EDIT + 57) + #define IDM_EDIT_BLANKLINEBELOWCURRENT (IDM_EDIT + 58) + #define IDM_EDIT_SORTLINES_LEXICOGRAPHIC_ASCENDING (IDM_EDIT + 59) + #define IDM_EDIT_SORTLINES_LEXICOGRAPHIC_DESCENDING (IDM_EDIT + 60) + #define IDM_EDIT_SORTLINES_INTEGER_ASCENDING (IDM_EDIT + 61) + #define IDM_EDIT_SORTLINES_INTEGER_DESCENDING (IDM_EDIT + 62) + #define IDM_EDIT_SORTLINES_DECIMALCOMMA_ASCENDING (IDM_EDIT + 63) + #define IDM_EDIT_SORTLINES_DECIMALCOMMA_DESCENDING (IDM_EDIT + 64) + #define IDM_EDIT_SORTLINES_DECIMALDOT_ASCENDING (IDM_EDIT + 65) + #define IDM_EDIT_SORTLINES_DECIMALDOT_DESCENDING (IDM_EDIT + 66) + #define IDM_EDIT_PROPERCASE_FORCE (IDM_EDIT + 67) + #define IDM_EDIT_PROPERCASE_BLEND (IDM_EDIT + 68) + #define IDM_EDIT_SENTENCECASE_FORCE (IDM_EDIT + 69) + #define IDM_EDIT_SENTENCECASE_BLEND (IDM_EDIT + 70) + #define IDM_EDIT_INVERTCASE (IDM_EDIT + 71) + #define IDM_EDIT_RANDOMCASE (IDM_EDIT + 72) + #define IDM_EDIT_OPENASFILE (IDM_EDIT + 73) + #define IDM_EDIT_OPENINFOLDER (IDM_EDIT + 74) + #define IDM_EDIT_SEARCHONINTERNET (IDM_EDIT + 75) + #define IDM_EDIT_CHANGESEARCHENGINE (IDM_EDIT + 76) + #define IDM_EDIT_REMOVE_CONSECUTIVE_DUP_LINES (IDM_EDIT + 77) + #define IDM_EDIT_SORTLINES_RANDOMLY (IDM_EDIT + 78) + #define IDM_EDIT_REMOVE_ANY_DUP_LINES (IDM_EDIT + 79) + #define IDM_EDIT_SORTLINES_LEXICO_CASE_INSENS_ASCENDING (IDM_EDIT + 80) + #define IDM_EDIT_SORTLINES_LEXICO_CASE_INSENS_DESCENDING (IDM_EDIT + 81) + #define IDM_EDIT_COPY_LINK (IDM_EDIT + 82) + #define IDM_EDIT_SORTLINES_REVERSE_ORDER (IDM_EDIT + 83) + #define IDM_EDIT_INSERT_DATETIME_SHORT (IDM_EDIT + 84) + #define IDM_EDIT_INSERT_DATETIME_LONG (IDM_EDIT + 85) + #define IDM_EDIT_INSERT_DATETIME_CUSTOMIZED (IDM_EDIT + 86) + #define IDM_EDIT_COPY_ALL_NAMES (IDM_EDIT + 87) + #define IDM_EDIT_COPY_ALL_PATHS (IDM_EDIT + 88) + #define IDM_EDIT_BEGINENDSELECT_COLUMNMODE (IDM_EDIT + 89) + #define IDM_EDIT_MULTISELECTALL (IDM_EDIT + 90) + #define IDM_EDIT_MULTISELECTALLMATCHCASE (IDM_EDIT + 91) + #define IDM_EDIT_MULTISELECTALLWHOLEWORD (IDM_EDIT + 92) + #define IDM_EDIT_MULTISELECTALLMATCHCASEWHOLEWORD (IDM_EDIT + 93) + #define IDM_EDIT_MULTISELECTNEXT (IDM_EDIT + 94) + #define IDM_EDIT_MULTISELECTNEXTMATCHCASE (IDM_EDIT + 95) + #define IDM_EDIT_MULTISELECTNEXTWHOLEWORD (IDM_EDIT + 96) + #define IDM_EDIT_MULTISELECTNEXTMATCHCASEWHOLEWORD (IDM_EDIT + 97) + #define IDM_EDIT_MULTISELECTUNDO (IDM_EDIT + 98) + #define IDM_EDIT_MULTISELECTSSKIP (IDM_EDIT + 99) + #define IDM_EDIT_SORTLINES_LOCALE_ASCENDING (IDM_EDIT + 100) + #define IDM_EDIT_SORTLINES_LOCALE_DESCENDING (IDM_EDIT + 101) + + #define IDM_EDIT_AUTOCOMPLETE (50000 + 0) + #define IDM_EDIT_AUTOCOMPLETE_CURRENTFILE (50000 + 1) + #define IDM_EDIT_FUNCCALLTIP (50000 + 2) + #define IDM_EDIT_AUTOCOMPLETE_PATH (50000 + 6) + #define IDM_EDIT_FUNCCALLTIP_PREVIOUS (50000 + 10) + #define IDM_EDIT_FUNCCALLTIP_NEXT (50000 + 11) + #define IDM_SEARCH (IDM + 3000) - #define IDM_SEARCH_FIND (IDM_SEARCH + 1) #define IDM_SEARCH_FINDNEXT (IDM_SEARCH + 2) #define IDM_SEARCH_REPLACE (IDM_SEARCH + 3) @@ -148,43 +239,72 @@ #define IDM_SEARCH_GONEXTMARKER_DEF (IDM_SEARCH + 44) #define IDM_FOCUS_ON_FOUND_RESULTS (IDM_SEARCH + 45) - #define IDM_SEARCH_GOTONEXTFOUND (IDM_SEARCH + 46) - #define IDM_SEARCH_GOTOPREVFOUND (IDM_SEARCH + 47) + #define IDM_SEARCH_GOTONEXTFOUND (IDM_SEARCH + 46) + #define IDM_SEARCH_GOTOPREVFOUND (IDM_SEARCH + 47) #define IDM_SEARCH_SETANDFINDNEXT (IDM_SEARCH + 48) #define IDM_SEARCH_SETANDFINDPREV (IDM_SEARCH + 49) - + #define IDM_SEARCH_INVERSEMARKS (IDM_SEARCH + 50) + #define IDM_SEARCH_DELETEUNMARKEDLINES (IDM_SEARCH + 51) + #define IDM_SEARCH_FINDCHARINRANGE (IDM_SEARCH + 52) + #define IDM_SEARCH_SELECTMATCHINGBRACES (IDM_SEARCH + 53) + #define IDM_SEARCH_MARK (IDM_SEARCH + 54) + + #define IDM_SEARCH_STYLE1TOCLIP (IDM_SEARCH + 55) + #define IDM_SEARCH_STYLE2TOCLIP (IDM_SEARCH + 56) + #define IDM_SEARCH_STYLE3TOCLIP (IDM_SEARCH + 57) + #define IDM_SEARCH_STYLE4TOCLIP (IDM_SEARCH + 58) + #define IDM_SEARCH_STYLE5TOCLIP (IDM_SEARCH + 59) + #define IDM_SEARCH_ALLSTYLESTOCLIP (IDM_SEARCH + 60) + #define IDM_SEARCH_MARKEDTOCLIP (IDM_SEARCH + 61) + + #define IDM_SEARCH_MARKONEEXT1 (IDM_SEARCH + 62) + #define IDM_SEARCH_MARKONEEXT2 (IDM_SEARCH + 63) + #define IDM_SEARCH_MARKONEEXT3 (IDM_SEARCH + 64) + #define IDM_SEARCH_MARKONEEXT4 (IDM_SEARCH + 65) + #define IDM_SEARCH_MARKONEEXT5 (IDM_SEARCH + 66) + + #define IDM_SEARCH_CHANGED_NEXT (IDM_SEARCH + 67) + #define IDM_SEARCH_CHANGED_PREV (IDM_SEARCH + 68) + #define IDM_SEARCH_CLEAR_CHANGE_HISTORY (IDM_SEARCH + 69) + +#define IDM_MISC (IDM + 3500) + #define IDM_DOCLIST_FILESCLOSE (IDM_MISC + 1) + #define IDM_DOCLIST_FILESCLOSEOTHERS (IDM_MISC + 2) + #define IDM_DOCLIST_COPYNAMES (IDM_MISC + 3) + #define IDM_DOCLIST_COPYPATHS (IDM_MISC + 4) + #define IDM_VIEW (IDM + 4000) //#define IDM_VIEW_TOOLBAR_HIDE (IDM_VIEW + 1) - #define IDM_VIEW_TOOLBAR_REDUCE (IDM_VIEW + 2) - #define IDM_VIEW_TOOLBAR_ENLARGE (IDM_VIEW + 3) - #define IDM_VIEW_TOOLBAR_STANDARD (IDM_VIEW + 4) - #define IDM_VIEW_REDUCETABBAR (IDM_VIEW + 5) - #define IDM_VIEW_LOCKTABBAR (IDM_VIEW + 6) - #define IDM_VIEW_DRAWTABBAR_TOPBAR (IDM_VIEW + 7) - #define IDM_VIEW_DRAWTABBAR_INACIVETAB (IDM_VIEW + 8) + //#define IDM_VIEW_TOOLBAR_REDUCE (IDM_VIEW + 2) + //#define IDM_VIEW_TOOLBAR_ENLARGE (IDM_VIEW + 3) + //#define IDM_VIEW_TOOLBAR_STANDARD (IDM_VIEW + 4) + //#define IDM_VIEW_REDUCETABBAR (IDM_VIEW + 5) + //#define IDM_VIEW_LOCKTABBAR (IDM_VIEW + 6) + //#define IDM_VIEW_DRAWTABBAR_TOPBAR (IDM_VIEW + 7) + //#define IDM_VIEW_DRAWTABBAR_INACTIVETAB (IDM_VIEW + 8) #define IDM_VIEW_POSTIT (IDM_VIEW + 9) - #define IDM_VIEW_TOGGLE_FOLDALL (IDM_VIEW + 10) - #define IDM_VIEW_USER_DLG (IDM_VIEW + 11) - #define IDM_VIEW_LINENUMBER (IDM_VIEW + 12) - #define IDM_VIEW_SYMBOLMARGIN (IDM_VIEW + 13) - #define IDM_VIEW_FOLDERMAGIN (IDM_VIEW + 14) - #define IDM_VIEW_FOLDERMAGIN_SIMPLE (IDM_VIEW + 15) - #define IDM_VIEW_FOLDERMAGIN_ARROW (IDM_VIEW + 16) - #define IDM_VIEW_FOLDERMAGIN_CIRCLE (IDM_VIEW + 17) - #define IDM_VIEW_FOLDERMAGIN_BOX (IDM_VIEW + 18) + #define IDM_VIEW_FOLDALL (IDM_VIEW + 10) + #define IDM_VIEW_DISTRACTIONFREE (IDM_VIEW + 11) + //#define IDM_VIEW_LINENUMBER (IDM_VIEW + 12) + //#define IDM_VIEW_SYMBOLMARGIN (IDM_VIEW + 13) + //#define IDM_VIEW_FOLDERMARGIN (IDM_VIEW + 14) + //#define IDM_VIEW_FOLDERMARGIN_SIMPLE (IDM_VIEW + 15) + //#define IDM_VIEW_FOLDERMARGIN_ARROW (IDM_VIEW + 16) + //#define IDM_VIEW_FOLDERMARGIN_CIRCLE (IDM_VIEW + 17) + //#define IDM_VIEW_FOLDERMARGIN_BOX (IDM_VIEW + 18) #define IDM_VIEW_ALL_CHARACTERS (IDM_VIEW + 19) #define IDM_VIEW_INDENT_GUIDE (IDM_VIEW + 20) - #define IDM_VIEW_CURLINE_HILITING (IDM_VIEW + 21) + //#define IDM_VIEW_CURLINE_HILITING (IDM_VIEW + 21) #define IDM_VIEW_WRAP (IDM_VIEW + 22) #define IDM_VIEW_ZOOMIN (IDM_VIEW + 23) #define IDM_VIEW_ZOOMOUT (IDM_VIEW + 24) #define IDM_VIEW_TAB_SPACE (IDM_VIEW + 25) #define IDM_VIEW_EOL (IDM_VIEW + 26) - #define IDM_VIEW_EDGELINE (IDM_VIEW + 27) - #define IDM_VIEW_EDGEBACKGROUND (IDM_VIEW + 28) - #define IDM_VIEW_TOGGLE_UNFOLDALL (IDM_VIEW + 29) + //#define IDM_VIEW_TOOLBAR_REDUCE_SET2 (IDM_VIEW + 27) + //#define IDM_VIEW_TOOLBAR_ENLARGE_SET2 (IDM_VIEW + 28) + #define IDM_VIEW_UNFOLDALL (IDM_VIEW + 29) #define IDM_VIEW_FOLD_CURRENT (IDM_VIEW + 30) #define IDM_VIEW_UNFOLD_CURRENT (IDM_VIEW + 31) #define IDM_VIEW_FULLSCREENTOGGLE (IDM_VIEW + 32) @@ -192,15 +312,19 @@ #define IDM_VIEW_ALWAYSONTOP (IDM_VIEW + 34) #define IDM_VIEW_SYNSCROLLV (IDM_VIEW + 35) #define IDM_VIEW_SYNSCROLLH (IDM_VIEW + 36) - #define IDM_VIEW_EDGENONE (IDM_VIEW + 37) - #define IDM_VIEW_DRAWTABBAR_CLOSEBOTTUN (IDM_VIEW + 38) - #define IDM_VIEW_DRAWTABBAR_DBCLK2CLOSE (IDM_VIEW + 39) - #define IDM_VIEW_REFRESHTABAR (IDM_VIEW + 40) + //#define IDM_VIEW_EDGENONE (IDM_VIEW + 37) + //#define IDM_VIEW_DRAWTABBAR_CLOSEBOTTUN (IDM_VIEW + 38) + //#define IDM_VIEW_DRAWTABBAR_DBCLK2CLOSE (IDM_VIEW + 39) + //#define IDM_VIEW_REFRESHTABAR (IDM_VIEW + 40) #define IDM_VIEW_WRAP_SYMBOL (IDM_VIEW + 41) #define IDM_VIEW_HIDELINES (IDM_VIEW + 42) - #define IDM_VIEW_DRAWTABBAR_VERTICAL (IDM_VIEW + 43) - #define IDM_VIEW_DRAWTABBAR_MULTILINE (IDM_VIEW + 44) - #define IDM_VIEW_DOCCHANGEMARGIN (IDM_VIEW + 45) + //#define IDM_VIEW_DRAWTABBAR_VERTICAL (IDM_VIEW + 43) + //#define IDM_VIEW_DRAWTABBAR_MULTILINE (IDM_VIEW + 44) + //#define IDM_VIEW_DOCCHANGEMARGIN (IDM_VIEW + 45) + //#define IDM_VIEW_LWDEF (IDM_VIEW + 46) + //#define IDM_VIEW_LWALIGN (IDM_VIEW + 47) + #define IDM_PINTAB (IDM_VIEW + 48) + #define IDM_VIEW_SUMMARY (IDM_VIEW + 49) #define IDM_VIEW_FOLD (IDM_VIEW + 50) #define IDM_VIEW_FOLD_1 (IDM_VIEW_FOLD + 1) @@ -212,7 +336,7 @@ #define IDM_VIEW_FOLD_7 (IDM_VIEW_FOLD + 7) #define IDM_VIEW_FOLD_8 (IDM_VIEW_FOLD + 8) - #define IDM_VIEW_UNFOLD (IDM_VIEW + 60) + #define IDM_VIEW_UNFOLD (IDM_VIEW + 60) #define IDM_VIEW_UNFOLD_1 (IDM_VIEW_UNFOLD + 1) #define IDM_VIEW_UNFOLD_2 (IDM_VIEW_UNFOLD + 2) #define IDM_VIEW_UNFOLD_3 (IDM_VIEW_UNFOLD + 3) @@ -221,28 +345,79 @@ #define IDM_VIEW_UNFOLD_6 (IDM_VIEW_UNFOLD + 6) #define IDM_VIEW_UNFOLD_7 (IDM_VIEW_UNFOLD + 7) #define IDM_VIEW_UNFOLD_8 (IDM_VIEW_UNFOLD + 8) - + + #define IDM_VIEW_DOCLIST (IDM_VIEW + 70) + #define IDM_VIEW_SWITCHTO_OTHER_VIEW (IDM_VIEW + 72) + #define IDM_EXPORT_FUNC_LIST_AND_QUIT (IDM_VIEW + 73) + + #define IDM_VIEW_DOC_MAP (IDM_VIEW + 80) + + #define IDM_VIEW_PROJECT_PANEL_1 (IDM_VIEW + 81) + #define IDM_VIEW_PROJECT_PANEL_2 (IDM_VIEW + 82) + #define IDM_VIEW_PROJECT_PANEL_3 (IDM_VIEW + 83) + + #define IDM_VIEW_FUNC_LIST (IDM_VIEW + 84) + #define IDM_VIEW_FILEBROWSER (IDM_VIEW + 85) + + #define IDM_VIEW_TAB1 (IDM_VIEW + 86) + #define IDM_VIEW_TAB2 (IDM_VIEW + 87) + #define IDM_VIEW_TAB3 (IDM_VIEW + 88) + #define IDM_VIEW_TAB4 (IDM_VIEW + 89) + #define IDM_VIEW_TAB5 (IDM_VIEW + 90) + #define IDM_VIEW_TAB6 (IDM_VIEW + 91) + #define IDM_VIEW_TAB7 (IDM_VIEW + 92) + #define IDM_VIEW_TAB8 (IDM_VIEW + 93) + #define IDM_VIEW_TAB9 (IDM_VIEW + 94) + #define IDM_VIEW_TAB_NEXT (IDM_VIEW + 95) + #define IDM_VIEW_TAB_PREV (IDM_VIEW + 96) + #define IDM_VIEW_MONITORING (IDM_VIEW + 97) + #define IDM_VIEW_TAB_MOVEFORWARD (IDM_VIEW + 98) + #define IDM_VIEW_TAB_MOVEBACKWARD (IDM_VIEW + 99) + #define IDM_VIEW_IN_FIREFOX (IDM_VIEW + 100) + #define IDM_VIEW_IN_CHROME (IDM_VIEW + 101) + #define IDM_VIEW_IN_EDGE (IDM_VIEW + 102) + #define IDM_VIEW_IN_IE (IDM_VIEW + 103) + + #define IDM_VIEW_SWITCHTO_PROJECT_PANEL_1 (IDM_VIEW + 104) + #define IDM_VIEW_SWITCHTO_PROJECT_PANEL_2 (IDM_VIEW + 105) + #define IDM_VIEW_SWITCHTO_PROJECT_PANEL_3 (IDM_VIEW + 106) + #define IDM_VIEW_SWITCHTO_FILEBROWSER (IDM_VIEW + 107) + #define IDM_VIEW_SWITCHTO_FUNC_LIST (IDM_VIEW + 108) + #define IDM_VIEW_SWITCHTO_DOCLIST (IDM_VIEW + 109) + + #define IDM_VIEW_TAB_COLOUR_NONE (IDM_VIEW + 110) + #define IDM_VIEW_TAB_COLOUR_1 (IDM_VIEW + 111) + #define IDM_VIEW_TAB_COLOUR_2 (IDM_VIEW + 112) + #define IDM_VIEW_TAB_COLOUR_3 (IDM_VIEW + 113) + #define IDM_VIEW_TAB_COLOUR_4 (IDM_VIEW + 114) + #define IDM_VIEW_TAB_COLOUR_5 (IDM_VIEW + 115) + #define IDM_VIEW_TAB_START (IDM_VIEW + 116) + #define IDM_VIEW_TAB_END (IDM_VIEW + 117) + + #define IDM_VIEW_NPC (IDM_VIEW + 130) + #define IDM_VIEW_NPC_CCUNIEOL (IDM_VIEW + 131) + #define IDM_VIEW_GOTO_ANOTHER_VIEW 10001 #define IDM_VIEW_CLONE_TO_ANOTHER_VIEW 10002 #define IDM_VIEW_GOTO_NEW_INSTANCE 10003 #define IDM_VIEW_LOAD_IN_NEW_INSTANCE 10004 + #define IDM_VIEW_GOTO_START 10005 + #define IDM_VIEW_GOTO_END 10006 - #define IDM_VIEW_SWITCHTO_OTHER_VIEW (IDM_VIEW + 72) - #define IDM_FORMAT (IDM + 5000) #define IDM_FORMAT_TODOS (IDM_FORMAT + 1) #define IDM_FORMAT_TOUNIX (IDM_FORMAT + 2) #define IDM_FORMAT_TOMAC (IDM_FORMAT + 3) #define IDM_FORMAT_ANSI (IDM_FORMAT + 4) #define IDM_FORMAT_UTF_8 (IDM_FORMAT + 5) - #define IDM_FORMAT_UCS_2BE (IDM_FORMAT + 6) - #define IDM_FORMAT_UCS_2LE (IDM_FORMAT + 7) + #define IDM_FORMAT_UTF_16BE (IDM_FORMAT + 6) + #define IDM_FORMAT_UTF_16LE (IDM_FORMAT + 7) #define IDM_FORMAT_AS_UTF_8 (IDM_FORMAT + 8) #define IDM_FORMAT_CONV2_ANSI (IDM_FORMAT + 9) #define IDM_FORMAT_CONV2_AS_UTF_8 (IDM_FORMAT + 10) #define IDM_FORMAT_CONV2_UTF_8 (IDM_FORMAT + 11) - #define IDM_FORMAT_CONV2_UCS_2BE (IDM_FORMAT + 12) - #define IDM_FORMAT_CONV2_UCS_2LE (IDM_FORMAT + 13) + #define IDM_FORMAT_CONV2_UTF_16BE (IDM_FORMAT + 12) + #define IDM_FORMAT_CONV2_UTF_16LE (IDM_FORMAT + 13) #define IDM_FORMAT_ENCODE (IDM_FORMAT + 20) #define IDM_FORMAT_WIN_1250 (IDM_FORMAT_ENCODE + 0) @@ -263,14 +438,14 @@ #define IDM_FORMAT_ISO_8859_7 (IDM_FORMAT_ENCODE + 15) #define IDM_FORMAT_ISO_8859_8 (IDM_FORMAT_ENCODE + 16) #define IDM_FORMAT_ISO_8859_9 (IDM_FORMAT_ENCODE + 17) - #define IDM_FORMAT_ISO_8859_10 (IDM_FORMAT_ENCODE + 18) - #define IDM_FORMAT_ISO_8859_11 (IDM_FORMAT_ENCODE + 19) + //#define IDM_FORMAT_ISO_8859_10 (IDM_FORMAT_ENCODE + 18) + //#define IDM_FORMAT_ISO_8859_11 (IDM_FORMAT_ENCODE + 19) #define IDM_FORMAT_ISO_8859_13 (IDM_FORMAT_ENCODE + 20) #define IDM_FORMAT_ISO_8859_14 (IDM_FORMAT_ENCODE + 21) #define IDM_FORMAT_ISO_8859_15 (IDM_FORMAT_ENCODE + 22) - #define IDM_FORMAT_ISO_8859_16 (IDM_FORMAT_ENCODE + 23) - #define IDM_FORMAT_DOS_437 (IDM_FORMAT_ENCODE + 24) - #define IDM_FORMAT_DOS_720 (IDM_FORMAT_ENCODE + 25) + //#define IDM_FORMAT_ISO_8859_16 (IDM_FORMAT_ENCODE + 23) + #define IDM_FORMAT_DOS_437 (IDM_FORMAT_ENCODE + 24) + #define IDM_FORMAT_DOS_720 (IDM_FORMAT_ENCODE + 25) #define IDM_FORMAT_DOS_737 (IDM_FORMAT_ENCODE + 26) #define IDM_FORMAT_DOS_775 (IDM_FORMAT_ENCODE + 27) #define IDM_FORMAT_DOS_850 (IDM_FORMAT_ENCODE + 28) @@ -296,17 +471,16 @@ #define IDM_FORMAT_KOI8R_CYRILLIC (IDM_FORMAT_ENCODE + 48) #define IDM_FORMAT_ENCODE_END IDM_FORMAT_KOI8R_CYRILLIC - //#define IDM_FORMAT_CONVERT 200 #define IDM_LANG (IDM + 6000) #define IDM_LANGSTYLE_CONFIG_DLG (IDM_LANG + 1) #define IDM_LANG_C (IDM_LANG + 2) #define IDM_LANG_CPP (IDM_LANG + 3) #define IDM_LANG_JAVA (IDM_LANG + 4) - #define IDM_LANG_HTML (IDM_LANG + 5) + #define IDM_LANG_HTML (IDM_LANG + 5) #define IDM_LANG_XML (IDM_LANG + 6) #define IDM_LANG_JS (IDM_LANG + 7) - #define IDM_LANG_PHP (IDM_LANG + 8) + #define IDM_LANG_PHP (IDM_LANG + 8) #define IDM_LANG_ASP (IDM_LANG + 9) #define IDM_LANG_CSS (IDM_LANG + 10) #define IDM_LANG_PASCAL (IDM_LANG + 11) @@ -354,37 +528,101 @@ #define IDM_LANG_POWERSHELL (IDM_LANG + 53) #define IDM_LANG_R (IDM_LANG + 54) #define IDM_LANG_JSP (IDM_LANG + 55) + #define IDM_LANG_COFFEESCRIPT (IDM_LANG + 56) + #define IDM_LANG_JSON (IDM_LANG + 57) + #define IDM_LANG_FORTRAN_77 (IDM_LANG + 58) + #define IDM_LANG_BAANC (IDM_LANG + 59) + #define IDM_LANG_SREC (IDM_LANG + 60) + #define IDM_LANG_IHEX (IDM_LANG + 61) + #define IDM_LANG_TEHEX (IDM_LANG + 62) + #define IDM_LANG_SWIFT (IDM_LANG + 63) + #define IDM_LANG_ASN1 (IDM_LANG + 64) + #define IDM_LANG_AVS (IDM_LANG + 65) + #define IDM_LANG_BLITZBASIC (IDM_LANG + 66) + #define IDM_LANG_PUREBASIC (IDM_LANG + 67) + #define IDM_LANG_FREEBASIC (IDM_LANG + 68) + #define IDM_LANG_CSOUND (IDM_LANG + 69) + #define IDM_LANG_ERLANG (IDM_LANG + 70) + #define IDM_LANG_ESCRIPT (IDM_LANG + 71) + #define IDM_LANG_FORTH (IDM_LANG + 72) + #define IDM_LANG_LATEX (IDM_LANG + 73) + #define IDM_LANG_MMIXAL (IDM_LANG + 74) + #define IDM_LANG_NIM (IDM_LANG + 75) + #define IDM_LANG_NNCRONTAB (IDM_LANG + 76) + #define IDM_LANG_OSCRIPT (IDM_LANG + 77) + #define IDM_LANG_REBOL (IDM_LANG + 78) + #define IDM_LANG_REGISTRY (IDM_LANG + 79) + #define IDM_LANG_RUST (IDM_LANG + 80) + #define IDM_LANG_SPICE (IDM_LANG + 81) + #define IDM_LANG_TXT2TAGS (IDM_LANG + 82) + #define IDM_LANG_VISUALPROLOG (IDM_LANG + 83) + #define IDM_LANG_TYPESCRIPT (IDM_LANG + 84) + #define IDM_LANG_JSON5 (IDM_LANG + 85) + #define IDM_LANG_MSSQL (IDM_LANG + 86) + #define IDM_LANG_GDSCRIPT (IDM_LANG + 87) + #define IDM_LANG_HOLLYWOOD (IDM_LANG + 88) + #define IDM_LANG_GOLANG (IDM_LANG + 89) + #define IDM_LANG_RAKU (IDM_LANG + 90) + #define IDM_LANG_TOML (IDM_LANG + 91) + #define IDM_LANG_SAS (IDM_LANG + 92) + #define IDM_LANG_ERRORLIST (IDM_LANG + 93) + + #define IDM_LANG_EXTERNAL (IDM_LANG + 165) + #define IDM_LANG_EXTERNAL_LIMIT (IDM_LANG + 179) + + #define IDM_LANG_USER (IDM_LANG + 180) //46180: Used for translation + #define IDM_LANG_USER_LIMIT (IDM_LANG + 210) //46210: Adjust with IDM_LANG_USER + #define IDM_LANG_USER_DLG (IDM_LANG + 250) //46250: Used for translation + #define IDM_LANG_OPENUDLDIR (IDM_LANG + 300) + #define IDM_LANG_UDLCOLLECTION_PROJECT_SITE (IDM_LANG + 301) + - #define IDM_LANG_EXTERNAL (IDM_LANG + 65) - #define IDM_LANG_EXTERNAL_LIMIT (IDM_LANG + 79) - #define IDM_LANG_USER (IDM_LANG + 80) //46080 - #define IDM_LANG_USER_LIMIT (IDM_LANG + 110) //46110 - - #define IDM_ABOUT (IDM + 7000) #define IDM_HOMESWEETHOME (IDM_ABOUT + 1) #define IDM_PROJECTPAGE (IDM_ABOUT + 2) - #define IDM_ONLINEHELP (IDM_ABOUT + 3) + #define IDM_ONLINEDOCUMENT (IDM_ABOUT + 3) #define IDM_FORUM (IDM_ABOUT + 4) - #define IDM_PLUGINSHOME (IDM_ABOUT + 5) + //#define IDM_PLUGINSHOME (IDM_ABOUT + 5) #define IDM_UPDATE_NPP (IDM_ABOUT + 6) - #define IDM_WIKIFAQ (IDM_ABOUT + 7) - #define IDM_HELP (IDM_ABOUT + 8) + //#define IDM_WIKIFAQ (IDM_ABOUT + 7) + //#define IDM_HELP (IDM_ABOUT + 8) + #define IDM_CONFUPDATERPROXY (IDM_ABOUT + 9) + #define IDM_CMDLINEARGUMENTS (IDM_ABOUT + 10) + //#define IDM_ONLINESUPPORT (IDM_ABOUT + 11) + #define IDM_DEBUGINFO (IDM_ABOUT + 12) #define IDM_SETTING (IDM + 8000) - #define IDM_SETTING_TAB_SIZE (IDM_SETTING + 1) - #define IDM_SETTING_TAB_REPLCESPACE (IDM_SETTING + 2) - #define IDM_SETTING_HISTORY_SIZE (IDM_SETTING + 3) - #define IDM_SETTING_EDGE_SIZE (IDM_SETTING + 4) +// #define IDM_SETTING_TAB_SIZE (IDM_SETTING + 1) +// #define IDM_SETTING_TAB_REPLACESPACE (IDM_SETTING + 2) +// #define IDM_SETTING_HISTORY_SIZE (IDM_SETTING + 3) +// #define IDM_SETTING_EDGE_SIZE (IDM_SETTING + 4) #define IDM_SETTING_IMPORTPLUGIN (IDM_SETTING + 5) - #define IDM_SETTING_IMPORTSTYLETHEMS (IDM_SETTING + 6) + #define IDM_SETTING_IMPORTSTYLETHEMES (IDM_SETTING + 6) #define IDM_SETTING_TRAYICON (IDM_SETTING + 8) #define IDM_SETTING_SHORTCUT_MAPPER (IDM_SETTING + 9) #define IDM_SETTING_REMEMBER_LAST_SESSION (IDM_SETTING + 10) - #define IDM_SETTING_PREFERECE (IDM_SETTING + 11) - #define IDM_SETTING_AUTOCNBCHAR (IDM_SETTING + 15) + #define IDM_SETTING_PREFERENCE (IDM_SETTING + 11) + #define IDM_SETTING_OPENPLUGINSDIR (IDM_SETTING + 14) + #define IDM_SETTING_PLUGINADM (IDM_SETTING + 15) + #define IDM_SETTING_SHORTCUT_MAPPER_MACRO (IDM_SETTING + 16) + #define IDM_SETTING_SHORTCUT_MAPPER_RUN (IDM_SETTING + 17) + #define IDM_SETTING_EDITCONTEXTMENU (IDM_SETTING + 18) + +#define IDM_TOOL (IDM + 8500) + #define IDM_TOOL_MD5_GENERATE (IDM_TOOL + 1) + #define IDM_TOOL_MD5_GENERATEFROMFILE (IDM_TOOL + 2) + #define IDM_TOOL_MD5_GENERATEINTOCLIPBOARD (IDM_TOOL + 3) + #define IDM_TOOL_SHA256_GENERATE (IDM_TOOL + 4) + #define IDM_TOOL_SHA256_GENERATEFROMFILE (IDM_TOOL + 5) + #define IDM_TOOL_SHA256_GENERATEINTOCLIPBOARD (IDM_TOOL + 6) + #define IDM_TOOL_SHA1_GENERATE (IDM_TOOL + 7) + #define IDM_TOOL_SHA1_GENERATEFROMFILE (IDM_TOOL + 8) + #define IDM_TOOL_SHA1_GENERATEINTOCLIPBOARD (IDM_TOOL + 9) + #define IDM_TOOL_SHA512_GENERATE (IDM_TOOL + 10) + #define IDM_TOOL_SHA512_GENERATEFROMFILE (IDM_TOOL + 11) + #define IDM_TOOL_SHA512_GENERATEINTOCLIPBOARD (IDM_TOOL + 12) #define IDM_EXECUTE (IDM + 9000) @@ -395,4 +633,23 @@ #define IDM_SYSTRAYPOPUP_OPENFILE (IDM_SYSTRAYPOPUP + 4) #define IDM_SYSTRAYPOPUP_CLOSE (IDM_SYSTRAYPOPUP + 5) -#endif //MENUCMDID_H +#define IDR_WINDOWS_MENU 11000 + #define IDM_WINDOW_WINDOWS (IDR_WINDOWS_MENU + 1) + #define IDM_WINDOW_SORT_FN_ASC (IDR_WINDOWS_MENU + 2) + #define IDM_WINDOW_SORT_FN_DSC (IDR_WINDOWS_MENU + 3) + #define IDM_WINDOW_SORT_FP_ASC (IDR_WINDOWS_MENU + 4) + #define IDM_WINDOW_SORT_FP_DSC (IDR_WINDOWS_MENU + 5) + #define IDM_WINDOW_SORT_FT_ASC (IDR_WINDOWS_MENU + 6) + #define IDM_WINDOW_SORT_FT_DSC (IDR_WINDOWS_MENU + 7) + #define IDM_WINDOW_SORT_FS_ASC (IDR_WINDOWS_MENU + 8) + #define IDM_WINDOW_SORT_FS_DSC (IDR_WINDOWS_MENU + 9) + #define IDM_WINDOW_SORT_FD_ASC (IDR_WINDOWS_MENU + 10) + #define IDM_WINDOW_SORT_FD_DSC (IDR_WINDOWS_MENU + 11) + #define IDM_WINDOW_MRU_FIRST (IDR_WINDOWS_MENU + 20) + #define IDM_WINDOW_MRU_LIMIT (IDR_WINDOWS_MENU + 59) + #define IDM_WINDOW_COPY_NAME (IDM_WINDOW_MRU_LIMIT + 1) + #define IDM_WINDOW_COPY_PATH (IDM_WINDOW_MRU_LIMIT + 2) + +#define IDR_DROPLIST_MENU 14000 + #define IDM_DROPLIST_LIST (IDR_DROPLIST_MENU + 1) + #define IDM_DROPLIST_MRU_FIRST (IDR_DROPLIST_MENU + 20) diff --git a/NppPlugin/project/NppPlugin.vcxproj b/NppPlugin/project/NppPlugin.vcxproj index 5b29430e..96952389 100644 --- a/NppPlugin/project/NppPlugin.vcxproj +++ b/NppPlugin/project/NppPlugin.vcxproj @@ -1,37 +1,69 @@  - + Debug Win32 + + Debug + x64 + PythonDebug Win32 + + PythonDebug + x64 + Release Win32 + + Release + x64 + {69CC76EB-0183-4622-929C-02E860A66A23} NppPlugin Win32Proj + 10.0 StaticLibrary Unicode true + v143 + + + StaticLibrary + Unicode + true + v143 StaticLibrary Unicode + v143 + + + StaticLibrary + Unicode + v143 StaticLibrary Unicode + v143 + + + StaticLibrary + Unicode + v143 @@ -39,77 +71,137 @@ + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 $(ProjectDir)\..\bin\$(Configuration)\ $(ProjectDir)\..\bin\$(Configuration)\ + $(ProjectDir)\..\bin\$(Configuration)\ $(Configuration)\ $(Configuration)\ - $(ProjectDir)\..\bin\$(Configuration)\ $(Configuration)\ - AllRules.ruleset - AllRules.ruleset - - - - - AllRules.ruleset - - + $(ProjectDir)\..\bin64\$(Configuration)\ + $(ProjectDir)\..\bin64\$(Configuration)\ + $(ProjectDir)\..\bin64\$(Configuration)\ $(IncludePath) + $(IncludePath) $(IncludePath) + $(IncludePath) $(IncludePath) + $(IncludePath) Disabled ..\include;..;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) - true + WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;_LIB;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebug - Use + NotUsing Level4 EditAndContinue + true + stdcpp17 + stdc17 + + + + + Disabled + ..\include;..;%(AdditionalIncludeDirectories) + WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;_LIB;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebug + NotUsing + Level4 + ProgramDatabase + true + stdcpp17 + stdc17 Disabled ..\include;..;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) - true + WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;_LIB;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebug - Use + NotUsing Level4 EditAndContinue + true + stdcpp17 + stdc17 + + + + + Disabled + ..\include;..;%(AdditionalIncludeDirectories) + WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;_LIB;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebug + NotUsing + Level4 + ProgramDatabase + true + stdcpp17 + stdc17 ..\include;..;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;_LIB;%(PreprocessorDefinitions) + MultiThreaded + NotUsing + Level3 + ProgramDatabase + true + stdcpp17 + stdc17 + + + + + ..\include;..;%(AdditionalIncludeDirectories) + WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;_LIB;%(PreprocessorDefinitions) MultiThreaded - Use + NotUsing Level3 ProgramDatabase + true + stdcpp17 + stdc17 - + + Create + Create Create + Create Create + Create @@ -117,12 +209,16 @@ + + + - + + + - diff --git a/NppPlugin/project/NppPlugin.vcxproj.filters b/NppPlugin/project/NppPlugin.vcxproj.filters index a6a99ed7..50d4a305 100644 --- a/NppPlugin/project/NppPlugin.vcxproj.filters +++ b/NppPlugin/project/NppPlugin.vcxproj.filters @@ -21,7 +21,10 @@ Source Files - + + Source Files + + Source Files @@ -35,18 +38,12 @@ Header Files - - Header Files - Header Files Header Files - - Header Files - Header Files @@ -62,6 +59,24 @@ Header Files + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + diff --git a/NppPlugin/src/DockingDlgInterface.cpp b/NppPlugin/src/DockingDlgInterface.cpp deleted file mode 100644 index d81e8b34..00000000 --- a/NppPlugin/src/DockingDlgInterface.cpp +++ /dev/null @@ -1,124 +0,0 @@ -//this file is part of notepad++ -//Copyright (C)2003 Don HO ( donho@altern.org ) -// -//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., 675 Mass Ave, Cambridge, MA 02139, USA. - -#include "stdafx.h" -#include "Notepad_plus_msgs.h" -#include "Docking.h" -#include "dockingResource.h" -#include "DockingDlgInterface.h" - -DockingDlgInterface::DockingDlgInterface(): - _HSource(NULL), - _data(NULL), - _dlgID(-1), - _isFloating(TRUE), - _iDockedPos(0), - _pluginName(TEXT("")) -{} - -DockingDlgInterface::DockingDlgInterface(int dlgID): - _HSource(NULL), - _data(NULL), - _dlgID(dlgID), - _isFloating(TRUE), - _iDockedPos(0), - _pluginName(TEXT("")) -{} - -void DockingDlgInterface::init(HINSTANCE hInst, HWND parent) -{ - StaticDialog::init(hInst, parent); - TCHAR temp[MAX_PATH]; - ::GetModuleFileName((HMODULE)hInst, temp, MAX_PATH); - _moduleName = PathFindFileName(temp); -} - -void DockingDlgInterface::create(tTbData * data, bool isRTL/* = false*/) -{ - StaticDialog::create(_dlgID, isRTL); - TCHAR temp[MAX_PATH]; - ::GetWindowText(_hSelf, temp, MAX_PATH); - _pluginName = temp; - // user information - data->hClient = _hSelf; - data->pszName = (TCHAR *)_pluginName.c_str(); - - // supported features by plugin - data->uMask = 0; - - // additional info - data->pszAddInfo = NULL; - - _data = data; - -} - -void DockingDlgInterface::updateDockingDlg() -{ - ::SendMessage(_hParent, NPPM_DMMUPDATEDISPINFO, 0, (LPARAM)_hSelf); -} - -void DockingDlgInterface::display(bool toShow /*= true*/) const -{ - ::SendMessage(_hParent, toShow?NPPM_DMMSHOW:NPPM_DMMHIDE, 0, (LPARAM)_hSelf); -} - -const TCHAR * DockingDlgInterface::getPluginFileName() const -{ - return _moduleName.c_str(); -} - -BOOL CALLBACK DockingDlgInterface::run_dlgProc(UINT message, WPARAM, LPARAM lParam) -{ - switch (message) - { - - case WM_NOTIFY: - { - LPNMHDR pnmh = (LPNMHDR)lParam; - - if (pnmh->hwndFrom == _hParent) - { - switch (LOWORD(pnmh->code)) - { - case DMN_CLOSE: - { - break; - } - case DMN_FLOAT: - { - _isFloating = true; - break; - } - case DMN_DOCK: - { - _iDockedPos = HIWORD(pnmh->code); - _isFloating = false; - break; - } - default: - break; - } - } - break; - } - default: - break; - } - return FALSE; -} - diff --git a/NppPlugin/src/NppDarkModeDummy.cpp b/NppPlugin/src/NppDarkModeDummy.cpp new file mode 100644 index 00000000..63470b70 --- /dev/null +++ b/NppPlugin/src/NppDarkModeDummy.cpp @@ -0,0 +1,75 @@ +#include "stdafx.h" //ADDED BY PYTHONSCRIPT +#include "NppDarkMode.h" +#include "PluginInterface.h" + +//extern NppData nppData; + +static constexpr COLORREF HEXRGB(DWORD rrggbb) { + // from 0xRRGGBB like natural #RRGGBB + // to the little-endian 0xBBGGRR + return + ((rrggbb & 0xFF0000) >> 16) | + ((rrggbb & 0x00FF00)) | + ((rrggbb & 0x0000FF) << 16); +} + + +namespace NppDarkMode +{ + bool isEnabled() + { + return false; // ::SendMessage(nppData._nppHandle, NPPM_ISDARKMODEENABLED, 0, 0); + } + + HBRUSH getDlgBackgroundBrush() + { + return ::CreateSolidBrush(HEXRGB(0x202020)); + } + + HBRUSH getDarkerBackgroundBrush() + { + return ::CreateSolidBrush(HEXRGB(0x202020)); + } + + COLORREF getTextColor() + { + return HEXRGB(0xE0E0E0); + } + + COLORREF getDarkerTextColor() + { + return HEXRGB(0xC0C0C0); + } + + COLORREF getLinkTextColor() + { + return HEXRGB(0xFFFF00); + } + + COLORREF getDarkerBackgroundColor() + { + return HEXRGB(0x202020); + } + + void setDarkTitleBar(HWND /*hwnd*/) + { + } + + bool isWindows10() + { + return false; + } + + LRESULT onCtlColorDarker(HDC hdc) + { + if (!NppDarkMode::isEnabled()) + { + return FALSE; + } + + ::SetTextColor(hdc, NppDarkMode::getTextColor()); + ::SetBkColor(hdc, NppDarkMode::getDarkerBackgroundColor()); + return reinterpret_cast(NppDarkMode::getDarkerBackgroundBrush()); + } + +} diff --git a/NppPlugin/src/StaticDialog.cpp b/NppPlugin/src/StaticDialog.cpp index 2a8e867f..5c2efb68 100644 --- a/NppPlugin/src/StaticDialog.cpp +++ b/NppPlugin/src/StaticDialog.cpp @@ -1,67 +1,246 @@ -//this file is part of notepad++ -//Copyright (C)2003 Don HO ( donho@altern.org ) -// -//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 file is part of Notepad++ project +// Copyright (C)2024 Don HO + +// 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 3 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. +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . -#include "stdafx.h" +#include +#include #include "StaticDialog.h" -#include "SysMsg.h" -#include "Notepad_plus_msgs.h" - -#define WS_EX_LAYOUTRTL 0x00400000L +#include "Common.h" +//#include "NppDarkMode.h" StaticDialog::~StaticDialog() { if (isCreated()) { - ::SetWindowLongPtr(_hSelf, GWLP_USERDATA, NULL); - StaticDialog::destroy(); + // Prevent run_dlgProc from doing anything, since its virtual + ::SetWindowLongPtr(_hSelf, GWLP_USERDATA, 0); + destroy(); } } +void StaticDialog::destroy() +{ + ::SendMessage(_hParent, NPPM_MODELESSDIALOG, MODELESSDIALOGREMOVE, reinterpret_cast(_hSelf)); + ::DestroyWindow(_hSelf); +} + +void StaticDialog::getMappedChildRect(HWND hChild, RECT& rcChild) const +{ + ::GetClientRect(hChild, &rcChild); + ::MapWindowPoints(hChild, _hSelf, reinterpret_cast(&rcChild), 2); +} + +void StaticDialog::getMappedChildRect(int idChild, RECT& rcChild) const +{ + const HWND hChild = ::GetDlgItem(_hSelf, idChild); + getMappedChildRect(hChild, rcChild); +} + +void StaticDialog::redrawDlgItem(const int nIDDlgItem, bool forceUpdate) const +{ + RECT rcDlgItem{}; + const HWND hDlgItem = ::GetDlgItem(_hSelf, nIDDlgItem); + getMappedChildRect(hDlgItem, rcDlgItem); + ::InvalidateRect(_hSelf, &rcDlgItem, TRUE); + + if (forceUpdate) + ::UpdateWindow(hDlgItem); +} + +POINT StaticDialog::getTopPoint(HWND hwnd, bool isLeft) const +{ + RECT rc{}; + ::GetWindowRect(hwnd, &rc); + + POINT p{}; + if (isLeft) + p.x = rc.left; + else + p.x = rc.right; + + p.y = rc.top; + ::ScreenToClient(_hSelf, &p); + return p; +} -void StaticDialog::goToCenter() +void StaticDialog::goToCenter(UINT swpFlags) { - RECT rc; - ::GetClientRect(_hParent, &rc); - POINT center; - center.x = rc.left + (rc.right - rc.left)/2; - center.y = rc.top + (rc.bottom - rc.top)/2; - ::ClientToScreen(_hParent, ¢er); + RECT rc{}; + ::GetClientRect(_hParent, &rc); + if ((rc.left == rc.right) || (rc.top == rc.bottom)) + swpFlags |= SWP_NOSIZE; // sizing has no sense here + + POINT center{}; + center.x = rc.left + (rc.right - rc.left)/2; + center.y = rc.top + (rc.bottom - rc.top)/2; + ::ClientToScreen(_hParent, ¢er); + if ((center.x == -32000) && (center.y == -32000)) // https://devblogs.microsoft.com/oldnewthing/20041028-00/?p=37453 + swpFlags |= SWP_NOMOVE; // moving has no sense here (owner wnd is minimized) int x = center.x - (_rc.right - _rc.left)/2; int y = center.y - (_rc.bottom - _rc.top)/2; - ::SetWindowPos(_hSelf, HWND_TOP, x, y, _rc.right - _rc.left, _rc.bottom - _rc.top, SWP_SHOWWINDOW); + ::SetWindowPos(_hSelf, HWND_TOP, x, y, _rc.right - _rc.left, _rc.bottom - _rc.top, swpFlags); + if (((swpFlags & SWP_NOMOVE) != SWP_NOMOVE) && ((swpFlags & SWP_SHOWWINDOW) == SWP_SHOWWINDOW)) + ::SendMessageW(_hSelf, DM_REPOSITION, 0, 0); +} + +bool StaticDialog::moveForDpiChange() +{ + if (_dpiManager.getDpi() != _dpiManager.getDpiForWindow(_hParent)) + { + goToCenter(SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOACTIVATE); + return true; + } + return false; +} + +void StaticDialog::display(bool toShow, bool enhancedPositioningCheckWhenShowing) const +{ + if (toShow) + { + if (enhancedPositioningCheckWhenShowing) + { + RECT testPositionRc{}, candidateRc{}; + + getWindowRect(testPositionRc); + + candidateRc = getViewablePositionRect(testPositionRc); + + if ((testPositionRc.left != candidateRc.left) || (testPositionRc.top != candidateRc.top)) + { + ::MoveWindow(_hSelf, candidateRc.left, candidateRc.top, + candidateRc.right - candidateRc.left, candidateRc.bottom - candidateRc.top, TRUE); + } + } + else + { + // If the user has switched from a dual monitor to a single monitor since we last + // displayed the dialog, then ensure that it's still visible on the single monitor. + RECT workAreaRect{}; + RECT rc{}; + ::SystemParametersInfo(SPI_GETWORKAREA, 0, &workAreaRect, 0); + ::GetWindowRect(_hSelf, &rc); + int newLeft = rc.left; + int newTop = rc.top; + int margin = ::GetSystemMetrics(SM_CYSMCAPTION); + + if (newLeft > ::GetSystemMetrics(SM_CXVIRTUALSCREEN) - margin) + newLeft -= rc.right - workAreaRect.right; + if (newLeft + (rc.right - rc.left) < ::GetSystemMetrics(SM_XVIRTUALSCREEN) + margin) + newLeft = workAreaRect.left; + if (newTop > ::GetSystemMetrics(SM_CYVIRTUALSCREEN) - margin) + newTop -= rc.bottom - workAreaRect.bottom; + if (newTop + (rc.bottom - rc.top) < ::GetSystemMetrics(SM_YVIRTUALSCREEN) + margin) + newTop = workAreaRect.top; + + if ((newLeft != rc.left) || (newTop != rc.top)) // then the virtual screen size has shrunk + ::SetWindowPos(_hSelf, nullptr, newLeft, newTop, 0, 0, SWP_NOSIZE | SWP_NOZORDER); + else + ::SendMessageW(_hSelf, DM_REPOSITION, 0, 0); + } + } + + Window::display(toShow); +} + +RECT StaticDialog::getViewablePositionRect(RECT testPositionRc) const +{ + HMONITOR hMon = ::MonitorFromRect(&testPositionRc, MONITOR_DEFAULTTONULL); + + MONITORINFO mi{}; + mi.cbSize = sizeof(MONITORINFO); + + bool rectPosViewableWithoutChange = false; + + if (hMon != NULL) + { + // rect would be at least partially visible on a monitor + + ::GetMonitorInfo(hMon, &mi); + + int margin = ::GetSystemMetrics(SM_CYBORDER) + ::GetSystemMetrics(SM_CYSIZEFRAME) + ::GetSystemMetrics(SM_CYCAPTION); + + // require that the title bar of the window be in a viewable place so the user can see it to grab it with the mouse + if ((testPositionRc.top >= mi.rcWork.top) && (testPositionRc.top + margin <= mi.rcWork.bottom) && + // require that some reasonable amount of width of the title bar be in the viewable area: + (testPositionRc.right - (margin * 2) > mi.rcWork.left) && (testPositionRc.left + (margin * 2) < mi.rcWork.right)) + { + rectPosViewableWithoutChange = true; + } + } + else + { + // rect would not have been visible on a monitor; get info about the nearest monitor to it + + hMon = ::MonitorFromRect(&testPositionRc, MONITOR_DEFAULTTONEAREST); + + ::GetMonitorInfo(hMon, &mi); + } + + RECT returnRc = testPositionRc; + + if (!rectPosViewableWithoutChange) + { + // reposition rect so that it would be viewable on current/nearest monitor, centering if reasonable + + LONG testRectWidth = testPositionRc.right - testPositionRc.left; + LONG testRectHeight = testPositionRc.bottom - testPositionRc.top; + LONG monWidth = mi.rcWork.right - mi.rcWork.left; + LONG monHeight = mi.rcWork.bottom - mi.rcWork.top; + + returnRc.left = mi.rcWork.left; + if (testRectWidth < monWidth) returnRc.left += (monWidth - testRectWidth) / 2; + returnRc.right = returnRc.left + testRectWidth; + + returnRc.top = mi.rcWork.top; + if (testRectHeight < monHeight) returnRc.top += (monHeight - testRectHeight) / 2; + returnRc.bottom = returnRc.top + testRectHeight; + } + + return returnRc; } HGLOBAL StaticDialog::makeRTLResource(int dialogID, DLGTEMPLATE **ppMyDlgTemplate) { // Get Dlg Template resource HRSRC hDialogRC = ::FindResource(_hInst, MAKEINTRESOURCE(dialogID), RT_DIALOG); + if (!hDialogRC) + return NULL; + HGLOBAL hDlgTemplate = ::LoadResource(_hInst, hDialogRC); - DLGTEMPLATE *pDlgTemplate = (DLGTEMPLATE *)::LockResource(hDlgTemplate); - + if (!hDlgTemplate) + return NULL; + + const DLGTEMPLATE *pDlgTemplate = static_cast(::LockResource(hDlgTemplate)); + if (!pDlgTemplate) + return NULL; + // Duplicate Dlg Template resource unsigned long sizeDlg = ::SizeofResource(_hInst, hDialogRC); HGLOBAL hMyDlgTemplate = ::GlobalAlloc(GPTR, sizeDlg); - *ppMyDlgTemplate = (DLGTEMPLATE *)::GlobalLock(hMyDlgTemplate); + if (!hMyDlgTemplate) return nullptr; + + *ppMyDlgTemplate = static_cast(::GlobalLock(hMyDlgTemplate)); + if (!*ppMyDlgTemplate) return nullptr; ::memcpy(*ppMyDlgTemplate, pDlgTemplate, sizeDlg); - - DLGTEMPLATEEX *pMyDlgTemplateEx = (DLGTEMPLATEEX *)*ppMyDlgTemplate; + + DLGTEMPLATEEX* pMyDlgTemplateEx = reinterpret_cast(*ppMyDlgTemplate); + if (!pMyDlgTemplateEx) return nullptr; + if (pMyDlgTemplateEx->signature == 0xFFFF) pMyDlgTemplateEx->exStyle |= WS_EX_LAYOUTRTL; else @@ -70,89 +249,59 @@ HGLOBAL StaticDialog::makeRTLResource(int dialogID, DLGTEMPLATE **ppMyDlgTemplat return hMyDlgTemplate; } -void StaticDialog::create(int dialogID, bool isRTL) +void StaticDialog::create(int dialogID, bool isRTL, bool msgDestParent) { if (isRTL) { DLGTEMPLATE *pMyDlgTemplate = NULL; HGLOBAL hMyDlgTemplate = makeRTLResource(dialogID, &pMyDlgTemplate); - _hSelf = ::CreateDialogIndirectParam(_hInst, pMyDlgTemplate, _hParent, (DLGPROC)dlgProc, (LPARAM)this); + _hSelf = ::CreateDialogIndirectParam(_hInst, pMyDlgTemplate, _hParent, dlgProc, reinterpret_cast(this)); ::GlobalFree(hMyDlgTemplate); } else - _hSelf = ::CreateDialogParam(_hInst, MAKEINTRESOURCE(dialogID), _hParent, (DLGPROC)dlgProc, (LPARAM)this); + _hSelf = ::CreateDialogParam(_hInst, MAKEINTRESOURCE(dialogID), _hParent, dlgProc, reinterpret_cast(this)); if (!_hSelf) { - //systemMessage("StaticDialog"); - throw int(666); + std::wstring errMsg = L"CreateDialogParam() return NULL.\rGetLastError(): "; + errMsg += GetLastErrorAsString(); + ::MessageBox(NULL, errMsg.c_str(), L"In StaticDialog::create()", MB_OK); + return; } - ::SendMessage(_hParent, NPPM_MODELESSDIALOG, MODELESSDIALOGADD, (WPARAM)_hSelf); + NppDarkMode::setDarkTitleBar(_hSelf); + setDpi(); + + // if the destination of message NPPM_MODELESSDIALOG is not its parent, then it's the grand-parent + ::SendMessage(msgDestParent ? _hParent : (::GetParent(_hParent)), NPPM_MODELESSDIALOG, MODELESSDIALOGADD, reinterpret_cast(_hSelf)); + //Modified for darkmode support + ::SendMessage(msgDestParent ? _hParent : (::GetParent(_hParent)), NPPM_DARKMODESUBCLASSANDTHEME, static_cast(NppDarkMode::dmfInit), reinterpret_cast(_hSelf)); } -BOOL CALLBACK StaticDialog::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +intptr_t CALLBACK StaticDialog::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { - switch (message) + switch (message) { - case WM_INITDIALOG : + case WM_INITDIALOG: { - StaticDialog *pStaticDlg = (StaticDialog *)(lParam); + NppDarkMode::setDarkTitleBar(hwnd); + + StaticDialog *pStaticDlg = reinterpret_cast(lParam); pStaticDlg->_hSelf = hwnd; - ::SetWindowLong(hwnd, GWL_USERDATA, (long)lParam); + ::SetWindowLongPtr(hwnd, GWLP_USERDATA, static_cast(lParam)); ::GetWindowRect(hwnd, &(pStaticDlg->_rc)); - pStaticDlg->run_dlgProc(hwnd, message, wParam, lParam); - + pStaticDlg->run_dlgProc(message, wParam, lParam); + return TRUE; } - default : + default: { StaticDialog *pStaticDlg = reinterpret_cast(::GetWindowLongPtr(hwnd, GWLP_USERDATA)); if (!pStaticDlg) return FALSE; - return pStaticDlg->run_dlgProc(hwnd, message, wParam, lParam); - + return pStaticDlg->run_dlgProc(message, wParam, lParam); } } } -void StaticDialog::alignWith(HWND handle, HWND handle2Align, PosAlign pos, POINT & point) -{ - RECT rc, rc2; - ::GetWindowRect(handle, &rc); - - point.x = rc.left; - point.y = rc.top; - - switch (pos) - { - case ALIGNPOS_LEFT : - ::GetWindowRect(handle2Align, &rc2); - point.x -= rc2.right - rc2.left; - break; - - case ALIGNPOS_RIGHT : - ::GetWindowRect(handle, &rc2); - point.x += rc2.right - rc2.left; - break; - - case ALIGNPOS_TOP : - ::GetWindowRect(handle2Align, &rc2); - point.y -= rc2.bottom - rc2.top; - break; - - default : //ALIGNPOS_BOTTOM - ::GetWindowRect(handle, &rc2); - point.y += rc2.bottom - rc2.top; - break; - } - - ::ScreenToClient(_hSelf, &point); -} - -void StaticDialog::destroy() -{ - ::SendMessage(_hParent, NPPM_MODELESSDIALOG, MODELESSDIALOGREMOVE, (WPARAM)_hSelf); - ::DestroyWindow(_hSelf); -} \ No newline at end of file diff --git a/NppPlugin/src/dpiManagerV2.cpp b/NppPlugin/src/dpiManagerV2.cpp new file mode 100644 index 00000000..0379b752 --- /dev/null +++ b/NppPlugin/src/dpiManagerV2.cpp @@ -0,0 +1,209 @@ +// This file is part of Notepad++ project +// Copyright (c) 2024 ozone10 and Notepad++ team + +// 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 3 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, see . + + +#include "dpiManagerV2.h" + +#include + +template +bool ptrFn(HMODULE handle, P& pointer, const char* name) +{ + auto p = reinterpret_cast

(::GetProcAddress(handle, name)); + if (p != nullptr) + { + pointer = p; + return true; + } + return false; +} + +using fnGetDpiForSystem = UINT (WINAPI*)(VOID); +using fnGetDpiForWindow = UINT (WINAPI*)(HWND hwnd); +using fnGetSystemMetricsForDpi = int (WINAPI*)(int nIndex, UINT dpi); +using fnSystemParametersInfoForDpi = BOOL (WINAPI*)(UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWinIni, UINT dpi); +using fnSetThreadDpiAwarenessContext = DPI_AWARENESS_CONTEXT (WINAPI*)(DPI_AWARENESS_CONTEXT dpiContext); +using fnAdjustWindowRectExForDpi = BOOL (WINAPI*)(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle, UINT dpi); + + +fnGetDpiForSystem _fnGetDpiForSystem = nullptr; +fnGetDpiForWindow _fnGetDpiForWindow = nullptr; +fnGetSystemMetricsForDpi _fnGetSystemMetricsForDpi = nullptr; +fnSystemParametersInfoForDpi _fnSystemParametersInfoForDpi = nullptr; +fnSetThreadDpiAwarenessContext _fnSetThreadDpiAwarenessContext = nullptr; +fnAdjustWindowRectExForDpi _fnAdjustWindowRectExForDpi = nullptr; + + +void DPIManagerV2::initDpiAPI() +{ + if (NppDarkMode::isWindows10()) + { + HMODULE hUser32 = ::GetModuleHandleW(L"user32.dll"); + if (hUser32 != nullptr) + { + ptrFn(hUser32, _fnGetDpiForSystem, "GetDpiForSystem"); + ptrFn(hUser32, _fnGetDpiForWindow, "GetDpiForWindow"); + ptrFn(hUser32, _fnGetSystemMetricsForDpi, "GetSystemMetricsForDpi"); + ptrFn(hUser32, _fnSystemParametersInfoForDpi, "SystemParametersInfoForDpi"); + ptrFn(hUser32, _fnSetThreadDpiAwarenessContext, "SetThreadDpiAwarenessContext"); + ptrFn(hUser32, _fnAdjustWindowRectExForDpi, "AdjustWindowRectExForDpi"); + + } + } +} + +int DPIManagerV2::getSystemMetricsForDpi(int nIndex, UINT dpi) +{ + if (_fnGetSystemMetricsForDpi != nullptr) + { + return _fnGetSystemMetricsForDpi(nIndex, dpi); + } + return DPIManagerV2::scale(::GetSystemMetrics(nIndex), dpi); +} + +DPI_AWARENESS_CONTEXT DPIManagerV2::setThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT dpiContext) +{ + if (_fnSetThreadDpiAwarenessContext != nullptr) + { + return _fnSetThreadDpiAwarenessContext(dpiContext); + } + return NULL; +} + +BOOL DPIManagerV2::adjustWindowRectExForDpi(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle, UINT dpi) +{ + if (_fnAdjustWindowRectExForDpi != nullptr) + { + return _fnAdjustWindowRectExForDpi(lpRect, dwStyle, bMenu, dwExStyle, dpi); + } + return FALSE; +} + +UINT DPIManagerV2::getDpiForSystem() +{ + if (_fnGetDpiForSystem != nullptr) + { + return _fnGetDpiForSystem(); + } + + UINT dpi = USER_DEFAULT_SCREEN_DPI; + HDC hdc = ::GetDC(nullptr); + if (hdc != nullptr) + { + dpi = ::GetDeviceCaps(hdc, LOGPIXELSX); + ::ReleaseDC(nullptr, hdc); + } + return dpi; +} + +UINT DPIManagerV2::getDpiForWindow(HWND hWnd) +{ + if (_fnGetDpiForWindow != nullptr) + { + const auto dpi = _fnGetDpiForWindow(hWnd); + if (dpi > 0) + { + return dpi; + } + } + return getDpiForSystem(); +} + +void DPIManagerV2::setPositionDpi(LPARAM lParam, HWND hWnd, UINT flags) +{ + const auto prcNewWindow = reinterpret_cast(lParam); + + ::SetWindowPos(hWnd, + nullptr, + prcNewWindow->left, + prcNewWindow->top, + prcNewWindow->right - prcNewWindow->left, + prcNewWindow->bottom - prcNewWindow->top, + flags); +} + +LOGFONT DPIManagerV2::getDefaultGUIFontForDpi(UINT dpi, FontType type) +{ + int result = 0; + LOGFONT lf{}; + NONCLIENTMETRICS ncm{}; + ncm.cbSize = sizeof(NONCLIENTMETRICS); + if (_fnSystemParametersInfoForDpi != nullptr + && (_fnSystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0, dpi) != FALSE)) + { + result = 2; + } + else if (::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0) != FALSE) + { + result = 1; + } + + if (result > 0) + { + switch (type) + { + case FontType::menu: + { + lf = ncm.lfMenuFont; + break; + } + + case FontType::status: + { + lf = ncm.lfStatusFont; + break; + } + + case FontType::caption: + { + lf = ncm.lfCaptionFont; + break; + } + + case FontType::smcaption: + { + lf = ncm.lfSmCaptionFont; + break; + } + //case FontType::message: + default: + { + lf = ncm.lfMessageFont; + break; + } + } + } + else // should not happen, fallback + { + auto hf = static_cast(::GetStockObject(DEFAULT_GUI_FONT)); + ::GetObject(hf, sizeof(LOGFONT), &lf); + } + + if (result < 2) + { + lf.lfHeight = scaleFont(lf.lfHeight, dpi); + } + + return lf; +} + +void DPIManagerV2::loadIcon(HINSTANCE hinst, const wchar_t* pszName, int cx, int cy, HICON* phico, UINT fuLoad) +{ + if (::LoadIconWithScaleDown(hinst, pszName, cx, cy, phico) != S_OK) + { + *phico = static_cast(::LoadImage(hinst, pszName, IMAGE_ICON, cx, cy, fuLoad)); + } +} diff --git a/NppPlugin/stdafx.cpp b/NppPlugin/stdafx.cpp index 1577c4e3..acb27776 100644 --- a/NppPlugin/stdafx.cpp +++ b/NppPlugin/stdafx.cpp @@ -1 +1,27 @@ -#include "stdafx.h" \ No newline at end of file +#include "stdafx.h" + +//Added single function from N++ Common.cpp +#include "Common.h" +#include "tchar.h" + +std::wstring GetLastErrorAsString(DWORD errorCode) +{ + std::wstring errorMsg(_T("")); + // Get the error message, if any. + // If both error codes (passed error n GetLastError) are 0, then return empty + if (errorCode == 0) + errorCode = GetLastError(); + if (errorCode == 0) + return errorMsg; //No error message has been recorded + + LPWSTR messageBuffer = nullptr; + FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + nullptr, errorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&messageBuffer, 0, nullptr); + + errorMsg += messageBuffer; + + //Free the buffer. + LocalFree(messageBuffer); + + return errorMsg; +} \ No newline at end of file diff --git a/NppPlugin/stdafx.h b/NppPlugin/stdafx.h index d82a230c..fd87e9d6 100644 --- a/NppPlugin/stdafx.h +++ b/NppPlugin/stdafx.h @@ -3,11 +3,11 @@ // Modify the following defines if you have to target a platform prior to the ones specified below. // Refer to MSDN for the latest info on corresponding values for different platforms. #ifndef WINVER // Allow use of features specific to Windows XP or later. -#define WINVER 0x0501 // Change this to the appropriate value to target other versions of Windows. +#define WINVER 0x0A00 // Change this to the appropriate value to target other versions of Windows. #endif #ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later. -#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows. +#define _WIN32_WINNT 0x0A00 // Change this to the appropriate value to target other versions of Windows. #endif #ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later. @@ -22,6 +22,8 @@ // Windows Header Files: #include #include +#include +#include #include typedef std::basic_string tstring; diff --git a/NppPluginIface_DocTabMap.cpp b/NppPluginIface_DocTabMap.cpp deleted file mode 100644 index 77ac08af..00000000 --- a/NppPluginIface_DocTabMap.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/* NppPluginIface_DocTabMap.h - * - * This file is part of the Notepad++ Plugin Interface Lib. - * Copyright 2008 - 2009 Thell Fowler (thell@almostautomated.com) - * - * 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., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -/* - * Notepad++ Plugin Interface Lib extension providing mapping of Notepad++ tab bufferID and - * visibility to Scintilla Document pointers, as well as tracking the currently open files - * by docID and a docId to bufferID map. - * - * For an example of using this see NppPluginIface_ActionIndex. - * - */ - - -#include "NppPluginIface_DocTabMap.h" - -#include -#include - -// <--- Notepad++ Scintilla Components for BufferID to pDoc ---> -#define TIXMLA_USE_STL -#include "Buffer.h" - -// <--- Boost ---> -#include -#include -#include -#include - - -namespace npp_plugin { - - -namespace doctabmap { - -// The main class for storing the document to buffer state information. -struct DocTab { - HWND _view; - int _tab; - BufferID _bufferID; - Document _pDoc; - bool _isVisible; - - DocTab( HWND view, int tab, BufferID bufferID, Document pDoc, bool isVisible) - :_view(view), _tab(tab), _bufferID(bufferID), _pDoc(pDoc), _isVisible(isVisible){}; -}; - - -// Boost mulit_index_container setup for tracking tab visibility states. -using boost::multi_index::multi_index_container; -using namespace boost::multi_index; - -// Namespace for the DocTab multi_index_container. -namespace doctabmap_mic { - -// DocTab_set index key for comp_visible_key. -struct dt_visible_key{}; - -// DocTab_set composite index key for unique view/visible combination. -struct comp_visible_key:composite_key< - DocTab, - BOOST_MULTI_INDEX_MEMBER(DocTab, HWND, _view), - BOOST_MULTI_INDEX_MEMBER(DocTab, bool, _isVisible) ->{}; - -// Multi Index Container for indexing N++ Doc Tab state data. -typedef multi_index_container< - DocTab, - indexed_by< - ordered_unique< tag, comp_visible_key > - > -> DocTab_set; - -// Index definition type for the DocTab_set container. -typedef DocTab_set::index::type dts_by_visibleTab; - -// The one and only DocTab_set container. -DocTab_set dts; - -// A set for storing active and ready open documents -std::set open_docs; - -// A map for storing buffer id to doc id. Usefull for doc open/close operations. -std::map< int, int > buff2doc_map; - -} // End namespace doctabmap_mic - -using namespace doctabmap_mic; - -// Public index to the DocTab_set. -dts_by_visibleTab& visibleTab_index = dts.get(); - -// Update the tab mapping between bufferIDs and pDocs for message filtering. -void update_DocTabMap() -{ - // Since there isn't a buffer-deactivate message to remove an entry we empty the set and - // rebuild on buffer activated messages. - if ( dts.size() > 0 ) { - dts.clear(); - open_docs.clear(); - } - - // Populate the DocTab_set - // The tab and buffer ID aren't really needed, yet I believe there may be some other - // uses for that information so they've been left in there. - bool isVisible = false; - for ( int view = MAIN_VIEW; view <= SUB_VIEW; view++ ) { - HWND targetView = hViewByInt(view); - Document viewDocID = (Document)::SendMessage( targetView, SCI_GETDOCPOINTER, 0, 0); - int nb_openfiles_view = ( view == MAIN_VIEW ) ? ( PRIMARY_VIEW ) : ( SECOND_VIEW ); - int nb_Tabs = ::SendMessage( hNpp(), NPPM_GETNBOPENFILES, 0, nb_openfiles_view ); - for ( int tab = 0; tab < nb_Tabs; tab++ ) { - int tabBuffID = ::SendMessage( hNpp(), NPPM_GETBUFFERIDFROMPOS, tab, view); - if ( tabBuffID > 0 ) { - BufferID pBuff = (BufferID)tabBuffID;; - Document pDoc = pBuff->getDocument(); - isVisible = ( pDoc == viewDocID ) ? ( true ) : ( false ); - dts.insert( - DocTab( targetView, tab, pBuff, pDoc, isVisible) - ); - open_docs.insert( (int)pDoc ); - if ( buff2doc_map.find( (int)pBuff ) == buff2doc_map.end() ) { - buff2doc_map[ (int)pBuff ] = (int)pDoc; - } - } - } - } -} - -// Returns the Scintilla Document ID for the visible document in the specified view. -// ( MAIN_VIEW = 0, SUB_VIEW = 1 ) -int getVisibleDocId_by_View( int view ) -{ - // The tuple is composed of the HWND for the view and a bool for 'is visible' to lookup - // the Doc ID based on the composite key from the index. - DocTab _DocTab = *(visibleTab_index.find( boost::make_tuple( hViewByInt( view ), true ) ) ); - - return ( _DocTab._pDoc ); -} - -// Returns the Scintilla Document ID matching a buffer ID. -int getDocIdFromBufferId( int bufferID ) { return ( buff2doc_map[bufferID] ); } - -// Returns true if a document is currently open and ready. -bool fileIsOpen( int pDoc ) -{ - if ( open_docs.find( pDoc ) != open_docs.end() ) return ( true ); - else return ( false ); -} - -} // End namespace: doctabmap - -} // End namespace: npp_plugin diff --git a/NppPluginIface_DocTabMap.h b/NppPluginIface_DocTabMap.h deleted file mode 100644 index 106d9ea8..00000000 --- a/NppPluginIface_DocTabMap.h +++ /dev/null @@ -1,48 +0,0 @@ -/* NppPluginIface_DocTabMap.h - * - * This file is part of the Notepad++ Plugin Interface Lib. - * Copyright 2008 - 2009 Thell Fowler (thell@almostautomated.com) - * - * 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., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -/* - * Notepad++ Plugin Interface Lib extension providing mapping of Notepad++ tab bufferID and - * visibility to Scintilla Document pointers, as well as tracking the currently open files - * by docID and a docId to bufferID map. - * - * For an example of using this see NppPluginIface_ActionIndex. - * - */ - - -#ifndef NPP_PLUGININTERFACE_DOCTABMAP_EXTENSION_H -#define NPP_PLUGININTERFACE_DOCTABMAP_EXTENSION_H - -#include "NppPluginIface.h" - -namespace npp_plugin { - -namespace doctabmap { - - -void update_DocTabMap(); -int getVisibleDocId_by_View( int view ); -int getDocIdFromBufferId( int bufferID ); -bool fileIsOpen( int pDoc ); - - -} // End namespace: doctabmap - -} // End namespace: npp_plugin - -#endif // End include guard: NPP_PLUGININTERFACE_ACTIONINDEX_EXTENSION_H diff --git a/PythonLib/extra/_bsddb.pyd b/PythonLib/extra/_bsddb.pyd deleted file mode 100644 index 1da2bcc3..00000000 Binary files a/PythonLib/extra/_bsddb.pyd and /dev/null differ diff --git a/PythonLib/extra/bsddb/__init__.py b/PythonLib/extra/bsddb/__init__.py deleted file mode 100644 index 13c9c27a..00000000 --- a/PythonLib/extra/bsddb/__init__.py +++ /dev/null @@ -1,455 +0,0 @@ -#---------------------------------------------------------------------- -# Copyright (c) 1999-2001, Digital Creations, Fredericksburg, VA, USA -# and Andrew Kuchling. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# o Redistributions of source code must retain the above copyright -# notice, this list of conditions, and the disclaimer that follows. -# -# o Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions, and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# -# o Neither the name of Digital Creations nor the names of its -# contributors may be used to endorse or promote products derived -# from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS AND CONTRIBUTORS *AS -# IS* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL -# CREATIONS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR -# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH -# DAMAGE. -#---------------------------------------------------------------------- - - -"""Support for Berkeley DB 4.3 through 5.3 with a simple interface. - -For the full featured object oriented interface use the bsddb.db module -instead. It mirrors the Oracle Berkeley DB C API. -""" - -import sys -absolute_import = (sys.version_info[0] >= 3) - -if (sys.version_info >= (2, 6)) and (sys.version_info < (3, 0)) : - import warnings - if sys.py3kwarning and (__name__ != 'bsddb3') : - warnings.warnpy3k("in 3.x, the bsddb module has been removed; " - "please use the pybsddb project instead", - DeprecationWarning, 2) - warnings.filterwarnings("ignore", ".*CObject.*", DeprecationWarning, - "bsddb.__init__") - -try: - if __name__ == 'bsddb3': - # import _pybsddb binary as it should be the more recent version from - # a standalone pybsddb addon package than the version included with - # python as bsddb._bsddb. - if absolute_import : - # Because this syntaxis is not valid before Python 2.5 - exec("from . import _pybsddb") - else : - import _pybsddb - _bsddb = _pybsddb - from bsddb3.dbutils import DeadlockWrap as _DeadlockWrap - else: - import _bsddb - from bsddb.dbutils import DeadlockWrap as _DeadlockWrap -except ImportError: - # Remove ourselves from sys.modules - import sys - del sys.modules[__name__] - raise - -# bsddb3 calls it db, but provide _db for backwards compatibility -db = _db = _bsddb -__version__ = db.__version__ - -error = db.DBError # So bsddb.error will mean something... - -#---------------------------------------------------------------------- - -import sys, os - -from weakref import ref - -if sys.version_info < (2, 6) : - import UserDict - MutableMapping = UserDict.DictMixin -else : - import collections - MutableMapping = collections.MutableMapping - -class _iter_mixin(MutableMapping): - def _make_iter_cursor(self): - cur = _DeadlockWrap(self.db.cursor) - key = id(cur) - self._cursor_refs[key] = ref(cur, self._gen_cref_cleaner(key)) - return cur - - def _gen_cref_cleaner(self, key): - # use generate the function for the weakref callback here - # to ensure that we do not hold a strict reference to cur - # in the callback. - return lambda ref: self._cursor_refs.pop(key, None) - - def __iter__(self): - self._kill_iteration = False - self._in_iter += 1 - try: - try: - cur = self._make_iter_cursor() - - # FIXME-20031102-greg: race condition. cursor could - # be closed by another thread before this call. - - # since we're only returning keys, we call the cursor - # methods with flags=0, dlen=0, dofs=0 - key = _DeadlockWrap(cur.first, 0,0,0)[0] - yield key - - next = getattr(cur, "next") - while 1: - try: - key = _DeadlockWrap(next, 0,0,0)[0] - yield key - except _bsddb.DBCursorClosedError: - if self._kill_iteration: - raise RuntimeError('Database changed size ' - 'during iteration.') - cur = self._make_iter_cursor() - # FIXME-20031101-greg: race condition. cursor could - # be closed by another thread before this call. - _DeadlockWrap(cur.set, key,0,0,0) - next = getattr(cur, "next") - except _bsddb.DBNotFoundError: - pass - except _bsddb.DBCursorClosedError: - # the database was modified during iteration. abort. - pass -# When Python 2.4 not supported in bsddb3, we can change this to "finally" - except : - self._in_iter -= 1 - raise - - self._in_iter -= 1 - - def iteritems(self): - if not self.db: - return - self._kill_iteration = False - self._in_iter += 1 - try: - try: - cur = self._make_iter_cursor() - - # FIXME-20031102-greg: race condition. cursor could - # be closed by another thread before this call. - - kv = _DeadlockWrap(cur.first) - key = kv[0] - yield kv - - next = getattr(cur, "next") - while 1: - try: - kv = _DeadlockWrap(next) - key = kv[0] - yield kv - except _bsddb.DBCursorClosedError: - if self._kill_iteration: - raise RuntimeError('Database changed size ' - 'during iteration.') - cur = self._make_iter_cursor() - # FIXME-20031101-greg: race condition. cursor could - # be closed by another thread before this call. - _DeadlockWrap(cur.set, key,0,0,0) - next = getattr(cur, "next") - except _bsddb.DBNotFoundError: - pass - except _bsddb.DBCursorClosedError: - # the database was modified during iteration. abort. - pass -# When Python 2.4 not supported in bsddb3, we can change this to "finally" - except : - self._in_iter -= 1 - raise - - self._in_iter -= 1 - - -class _DBWithCursor(_iter_mixin): - """ - A simple wrapper around DB that makes it look like the bsddbobject in - the old module. It uses a cursor as needed to provide DB traversal. - """ - def __init__(self, db): - self.db = db - self.db.set_get_returns_none(0) - - # FIXME-20031101-greg: I believe there is still the potential - # for deadlocks in a multithreaded environment if someone - # attempts to use the any of the cursor interfaces in one - # thread while doing a put or delete in another thread. The - # reason is that _checkCursor and _closeCursors are not atomic - # operations. Doing our own locking around self.dbc, - # self.saved_dbc_key and self._cursor_refs could prevent this. - # TODO: A test case demonstrating the problem needs to be written. - - # self.dbc is a DBCursor object used to implement the - # first/next/previous/last/set_location methods. - self.dbc = None - self.saved_dbc_key = None - - # a collection of all DBCursor objects currently allocated - # by the _iter_mixin interface. - self._cursor_refs = {} - self._in_iter = 0 - self._kill_iteration = False - - def __del__(self): - self.close() - - def _checkCursor(self): - if self.dbc is None: - self.dbc = _DeadlockWrap(self.db.cursor) - if self.saved_dbc_key is not None: - _DeadlockWrap(self.dbc.set, self.saved_dbc_key) - self.saved_dbc_key = None - - # This method is needed for all non-cursor DB calls to avoid - # Berkeley DB deadlocks (due to being opened with DB_INIT_LOCK - # and DB_THREAD to be thread safe) when intermixing database - # operations that use the cursor internally with those that don't. - def _closeCursors(self, save=1): - if self.dbc: - c = self.dbc - self.dbc = None - if save: - try: - self.saved_dbc_key = _DeadlockWrap(c.current, 0,0,0)[0] - except db.DBError: - pass - _DeadlockWrap(c.close) - del c - for cref in self._cursor_refs.values(): - c = cref() - if c is not None: - _DeadlockWrap(c.close) - - def _checkOpen(self): - if self.db is None: - raise error, "BSDDB object has already been closed" - - def isOpen(self): - return self.db is not None - - def __len__(self): - self._checkOpen() - return _DeadlockWrap(lambda: len(self.db)) # len(self.db) - - if sys.version_info >= (2, 6) : - def __repr__(self) : - if self.isOpen() : - return repr(dict(_DeadlockWrap(self.db.items))) - return repr(dict()) - - def __getitem__(self, key): - self._checkOpen() - return _DeadlockWrap(lambda: self.db[key]) # self.db[key] - - def __setitem__(self, key, value): - self._checkOpen() - self._closeCursors() - if self._in_iter and key not in self: - self._kill_iteration = True - def wrapF(): - self.db[key] = value - _DeadlockWrap(wrapF) # self.db[key] = value - - def __delitem__(self, key): - self._checkOpen() - self._closeCursors() - if self._in_iter and key in self: - self._kill_iteration = True - def wrapF(): - del self.db[key] - _DeadlockWrap(wrapF) # del self.db[key] - - def close(self): - self._closeCursors(save=0) - if self.dbc is not None: - _DeadlockWrap(self.dbc.close) - v = 0 - if self.db is not None: - v = _DeadlockWrap(self.db.close) - self.dbc = None - self.db = None - return v - - def keys(self): - self._checkOpen() - return _DeadlockWrap(self.db.keys) - - def has_key(self, key): - self._checkOpen() - return _DeadlockWrap(self.db.has_key, key) - - def set_location(self, key): - self._checkOpen() - self._checkCursor() - return _DeadlockWrap(self.dbc.set_range, key) - - def next(self): # Renamed by "2to3" - self._checkOpen() - self._checkCursor() - rv = _DeadlockWrap(getattr(self.dbc, "next")) - return rv - - if sys.version_info[0] >= 3 : # For "2to3" conversion - next = __next__ - - def previous(self): - self._checkOpen() - self._checkCursor() - rv = _DeadlockWrap(self.dbc.prev) - return rv - - def first(self): - self._checkOpen() - # fix 1725856: don't needlessly try to restore our cursor position - self.saved_dbc_key = None - self._checkCursor() - rv = _DeadlockWrap(self.dbc.first) - return rv - - def last(self): - self._checkOpen() - # fix 1725856: don't needlessly try to restore our cursor position - self.saved_dbc_key = None - self._checkCursor() - rv = _DeadlockWrap(self.dbc.last) - return rv - - def sync(self): - self._checkOpen() - return _DeadlockWrap(self.db.sync) - - -#---------------------------------------------------------------------- -# Compatibility object factory functions - -def hashopen(file, flag='c', mode=0666, pgsize=None, ffactor=None, nelem=None, - cachesize=None, lorder=None, hflags=0): - - flags = _checkflag(flag, file) - e = _openDBEnv(cachesize) - d = db.DB(e) - d.set_flags(hflags) - if pgsize is not None: d.set_pagesize(pgsize) - if lorder is not None: d.set_lorder(lorder) - if ffactor is not None: d.set_h_ffactor(ffactor) - if nelem is not None: d.set_h_nelem(nelem) - d.open(file, db.DB_HASH, flags, mode) - return _DBWithCursor(d) - -#---------------------------------------------------------------------- - -def btopen(file, flag='c', mode=0666, - btflags=0, cachesize=None, maxkeypage=None, minkeypage=None, - pgsize=None, lorder=None): - - flags = _checkflag(flag, file) - e = _openDBEnv(cachesize) - d = db.DB(e) - if pgsize is not None: d.set_pagesize(pgsize) - if lorder is not None: d.set_lorder(lorder) - d.set_flags(btflags) - if minkeypage is not None: d.set_bt_minkey(minkeypage) - if maxkeypage is not None: d.set_bt_maxkey(maxkeypage) - d.open(file, db.DB_BTREE, flags, mode) - return _DBWithCursor(d) - -#---------------------------------------------------------------------- - - -def rnopen(file, flag='c', mode=0666, - rnflags=0, cachesize=None, pgsize=None, lorder=None, - rlen=None, delim=None, source=None, pad=None): - - flags = _checkflag(flag, file) - e = _openDBEnv(cachesize) - d = db.DB(e) - if pgsize is not None: d.set_pagesize(pgsize) - if lorder is not None: d.set_lorder(lorder) - d.set_flags(rnflags) - if delim is not None: d.set_re_delim(delim) - if rlen is not None: d.set_re_len(rlen) - if source is not None: d.set_re_source(source) - if pad is not None: d.set_re_pad(pad) - d.open(file, db.DB_RECNO, flags, mode) - return _DBWithCursor(d) - -#---------------------------------------------------------------------- - -def _openDBEnv(cachesize): - e = db.DBEnv() - if cachesize is not None: - if cachesize >= 20480: - e.set_cachesize(0, cachesize) - else: - raise error, "cachesize must be >= 20480" - e.set_lk_detect(db.DB_LOCK_DEFAULT) - e.open('.', db.DB_PRIVATE | db.DB_CREATE | db.DB_THREAD | db.DB_INIT_LOCK | db.DB_INIT_MPOOL) - return e - -def _checkflag(flag, file): - if flag == 'r': - flags = db.DB_RDONLY - elif flag == 'rw': - flags = 0 - elif flag == 'w': - flags = db.DB_CREATE - elif flag == 'c': - flags = db.DB_CREATE - elif flag == 'n': - flags = db.DB_CREATE - #flags = db.DB_CREATE | db.DB_TRUNCATE - # we used db.DB_TRUNCATE flag for this before but Berkeley DB - # 4.2.52 changed to disallowed truncate with txn environments. - if file is not None and os.path.isfile(file): - os.unlink(file) - else: - raise error, "flags should be one of 'r', 'w', 'c' or 'n'" - return flags | db.DB_THREAD - -#---------------------------------------------------------------------- - - -# This is a silly little hack that allows apps to continue to use the -# DB_THREAD flag even on systems without threads without freaking out -# Berkeley DB. -# -# This assumes that if Python was built with thread support then -# Berkeley DB was too. - -try: - # 2to3 automatically changes "import thread" to "import _thread" - import thread as T - del T - -except ImportError: - db.DB_THREAD = 0 - -#---------------------------------------------------------------------- diff --git a/PythonLib/extra/bsddb/db.py b/PythonLib/extra/bsddb/db.py deleted file mode 100644 index c3aee307..00000000 --- a/PythonLib/extra/bsddb/db.py +++ /dev/null @@ -1,60 +0,0 @@ -#---------------------------------------------------------------------- -# Copyright (c) 1999-2001, Digital Creations, Fredericksburg, VA, USA -# and Andrew Kuchling. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# o Redistributions of source code must retain the above copyright -# notice, this list of conditions, and the disclaimer that follows. -# -# o Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions, and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# -# o Neither the name of Digital Creations nor the names of its -# contributors may be used to endorse or promote products derived -# from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS AND CONTRIBUTORS *AS -# IS* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL -# CREATIONS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR -# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH -# DAMAGE. -#---------------------------------------------------------------------- - - -# This module is just a placeholder for possible future expansion, in -# case we ever want to augment the stuff in _db in any way. For now -# it just simply imports everything from _db. - -import sys -absolute_import = (sys.version_info[0] >= 3) - -if not absolute_import : - if __name__.startswith('bsddb3.') : - # import _pybsddb binary as it should be the more recent version from - # a standalone pybsddb addon package than the version included with - # python as bsddb._bsddb. - from _pybsddb import * - from _pybsddb import __version__ - else: - from _bsddb import * - from _bsddb import __version__ -else : - # Because this syntaxis is not valid before Python 2.5 - if __name__.startswith('bsddb3.') : - exec("from ._pybsddb import *") - exec("from ._pybsddb import __version__") - else : - exec("from ._bsddb import *") - exec("from ._bsddb import __version__") diff --git a/PythonLib/extra/bsddb/dbobj.py b/PythonLib/extra/bsddb/dbobj.py deleted file mode 100644 index 1400fe15..00000000 --- a/PythonLib/extra/bsddb/dbobj.py +++ /dev/null @@ -1,266 +0,0 @@ -#------------------------------------------------------------------------- -# This file contains real Python object wrappers for DB and DBEnv -# C "objects" that can be usefully subclassed. The previous SWIG -# based interface allowed this thanks to SWIG's shadow classes. -# -- Gregory P. Smith -#------------------------------------------------------------------------- -# -# (C) Copyright 2001 Autonomous Zone Industries -# -# License: This is free software. You may use this software for any -# purpose including modification/redistribution, so long as -# this header remains intact and that you do not claim any -# rights of ownership or authorship of this software. This -# software has been tested, but no warranty is expressed or -# implied. -# - -# -# TODO it would be *really nice* to have an automatic shadow class populator -# so that new methods don't need to be added here manually after being -# added to _bsddb.c. -# - -import sys -absolute_import = (sys.version_info[0] >= 3) -if absolute_import : - # Because this syntaxis is not valid before Python 2.5 - exec("from . import db") -else : - import db - -if sys.version_info < (2, 6) : - from UserDict import DictMixin as MutableMapping -else : - import collections - MutableMapping = collections.MutableMapping - -class DBEnv: - def __init__(self, *args, **kwargs): - self._cobj = db.DBEnv(*args, **kwargs) - - def close(self, *args, **kwargs): - return self._cobj.close(*args, **kwargs) - def open(self, *args, **kwargs): - return self._cobj.open(*args, **kwargs) - def remove(self, *args, **kwargs): - return self._cobj.remove(*args, **kwargs) - def set_shm_key(self, *args, **kwargs): - return self._cobj.set_shm_key(*args, **kwargs) - def set_cachesize(self, *args, **kwargs): - return self._cobj.set_cachesize(*args, **kwargs) - def set_data_dir(self, *args, **kwargs): - return self._cobj.set_data_dir(*args, **kwargs) - def set_flags(self, *args, **kwargs): - return self._cobj.set_flags(*args, **kwargs) - def set_lg_bsize(self, *args, **kwargs): - return self._cobj.set_lg_bsize(*args, **kwargs) - def set_lg_dir(self, *args, **kwargs): - return self._cobj.set_lg_dir(*args, **kwargs) - def set_lg_max(self, *args, **kwargs): - return self._cobj.set_lg_max(*args, **kwargs) - def set_lk_detect(self, *args, **kwargs): - return self._cobj.set_lk_detect(*args, **kwargs) - if db.version() < (4,5): - def set_lk_max(self, *args, **kwargs): - return self._cobj.set_lk_max(*args, **kwargs) - def set_lk_max_locks(self, *args, **kwargs): - return self._cobj.set_lk_max_locks(*args, **kwargs) - def set_lk_max_lockers(self, *args, **kwargs): - return self._cobj.set_lk_max_lockers(*args, **kwargs) - def set_lk_max_objects(self, *args, **kwargs): - return self._cobj.set_lk_max_objects(*args, **kwargs) - def set_mp_mmapsize(self, *args, **kwargs): - return self._cobj.set_mp_mmapsize(*args, **kwargs) - def set_timeout(self, *args, **kwargs): - return self._cobj.set_timeout(*args, **kwargs) - def set_tmp_dir(self, *args, **kwargs): - return self._cobj.set_tmp_dir(*args, **kwargs) - def txn_begin(self, *args, **kwargs): - return self._cobj.txn_begin(*args, **kwargs) - def txn_checkpoint(self, *args, **kwargs): - return self._cobj.txn_checkpoint(*args, **kwargs) - def txn_stat(self, *args, **kwargs): - return self._cobj.txn_stat(*args, **kwargs) - def set_tx_max(self, *args, **kwargs): - return self._cobj.set_tx_max(*args, **kwargs) - def set_tx_timestamp(self, *args, **kwargs): - return self._cobj.set_tx_timestamp(*args, **kwargs) - def lock_detect(self, *args, **kwargs): - return self._cobj.lock_detect(*args, **kwargs) - def lock_get(self, *args, **kwargs): - return self._cobj.lock_get(*args, **kwargs) - def lock_id(self, *args, **kwargs): - return self._cobj.lock_id(*args, **kwargs) - def lock_put(self, *args, **kwargs): - return self._cobj.lock_put(*args, **kwargs) - def lock_stat(self, *args, **kwargs): - return self._cobj.lock_stat(*args, **kwargs) - def log_archive(self, *args, **kwargs): - return self._cobj.log_archive(*args, **kwargs) - - def set_get_returns_none(self, *args, **kwargs): - return self._cobj.set_get_returns_none(*args, **kwargs) - - def log_stat(self, *args, **kwargs): - return self._cobj.log_stat(*args, **kwargs) - - def dbremove(self, *args, **kwargs): - return self._cobj.dbremove(*args, **kwargs) - def dbrename(self, *args, **kwargs): - return self._cobj.dbrename(*args, **kwargs) - def set_encrypt(self, *args, **kwargs): - return self._cobj.set_encrypt(*args, **kwargs) - - if db.version() >= (4,4): - def fileid_reset(self, *args, **kwargs): - return self._cobj.fileid_reset(*args, **kwargs) - - def lsn_reset(self, *args, **kwargs): - return self._cobj.lsn_reset(*args, **kwargs) - - -class DB(MutableMapping): - def __init__(self, dbenv, *args, **kwargs): - # give it the proper DBEnv C object that its expecting - self._cobj = db.DB(*((dbenv._cobj,) + args), **kwargs) - - # TODO are there other dict methods that need to be overridden? - def __len__(self): - return len(self._cobj) - def __getitem__(self, arg): - return self._cobj[arg] - def __setitem__(self, key, value): - self._cobj[key] = value - def __delitem__(self, arg): - del self._cobj[arg] - - if sys.version_info >= (2, 6) : - def __iter__(self) : - return self._cobj.__iter__() - - def append(self, *args, **kwargs): - return self._cobj.append(*args, **kwargs) - def associate(self, *args, **kwargs): - return self._cobj.associate(*args, **kwargs) - def close(self, *args, **kwargs): - return self._cobj.close(*args, **kwargs) - def consume(self, *args, **kwargs): - return self._cobj.consume(*args, **kwargs) - def consume_wait(self, *args, **kwargs): - return self._cobj.consume_wait(*args, **kwargs) - def cursor(self, *args, **kwargs): - return self._cobj.cursor(*args, **kwargs) - def delete(self, *args, **kwargs): - return self._cobj.delete(*args, **kwargs) - def fd(self, *args, **kwargs): - return self._cobj.fd(*args, **kwargs) - def get(self, *args, **kwargs): - return self._cobj.get(*args, **kwargs) - def pget(self, *args, **kwargs): - return self._cobj.pget(*args, **kwargs) - def get_both(self, *args, **kwargs): - return self._cobj.get_both(*args, **kwargs) - def get_byteswapped(self, *args, **kwargs): - return self._cobj.get_byteswapped(*args, **kwargs) - def get_size(self, *args, **kwargs): - return self._cobj.get_size(*args, **kwargs) - def get_type(self, *args, **kwargs): - return self._cobj.get_type(*args, **kwargs) - def join(self, *args, **kwargs): - return self._cobj.join(*args, **kwargs) - def key_range(self, *args, **kwargs): - return self._cobj.key_range(*args, **kwargs) - def has_key(self, *args, **kwargs): - return self._cobj.has_key(*args, **kwargs) - def items(self, *args, **kwargs): - return self._cobj.items(*args, **kwargs) - def keys(self, *args, **kwargs): - return self._cobj.keys(*args, **kwargs) - def open(self, *args, **kwargs): - return self._cobj.open(*args, **kwargs) - def put(self, *args, **kwargs): - return self._cobj.put(*args, **kwargs) - def remove(self, *args, **kwargs): - return self._cobj.remove(*args, **kwargs) - def rename(self, *args, **kwargs): - return self._cobj.rename(*args, **kwargs) - def set_bt_minkey(self, *args, **kwargs): - return self._cobj.set_bt_minkey(*args, **kwargs) - def set_bt_compare(self, *args, **kwargs): - return self._cobj.set_bt_compare(*args, **kwargs) - def set_cachesize(self, *args, **kwargs): - return self._cobj.set_cachesize(*args, **kwargs) - def set_dup_compare(self, *args, **kwargs) : - return self._cobj.set_dup_compare(*args, **kwargs) - def set_flags(self, *args, **kwargs): - return self._cobj.set_flags(*args, **kwargs) - def set_h_ffactor(self, *args, **kwargs): - return self._cobj.set_h_ffactor(*args, **kwargs) - def set_h_nelem(self, *args, **kwargs): - return self._cobj.set_h_nelem(*args, **kwargs) - def set_lorder(self, *args, **kwargs): - return self._cobj.set_lorder(*args, **kwargs) - def set_pagesize(self, *args, **kwargs): - return self._cobj.set_pagesize(*args, **kwargs) - def set_re_delim(self, *args, **kwargs): - return self._cobj.set_re_delim(*args, **kwargs) - def set_re_len(self, *args, **kwargs): - return self._cobj.set_re_len(*args, **kwargs) - def set_re_pad(self, *args, **kwargs): - return self._cobj.set_re_pad(*args, **kwargs) - def set_re_source(self, *args, **kwargs): - return self._cobj.set_re_source(*args, **kwargs) - def set_q_extentsize(self, *args, **kwargs): - return self._cobj.set_q_extentsize(*args, **kwargs) - def stat(self, *args, **kwargs): - return self._cobj.stat(*args, **kwargs) - def sync(self, *args, **kwargs): - return self._cobj.sync(*args, **kwargs) - def type(self, *args, **kwargs): - return self._cobj.type(*args, **kwargs) - def upgrade(self, *args, **kwargs): - return self._cobj.upgrade(*args, **kwargs) - def values(self, *args, **kwargs): - return self._cobj.values(*args, **kwargs) - def verify(self, *args, **kwargs): - return self._cobj.verify(*args, **kwargs) - def set_get_returns_none(self, *args, **kwargs): - return self._cobj.set_get_returns_none(*args, **kwargs) - - def set_encrypt(self, *args, **kwargs): - return self._cobj.set_encrypt(*args, **kwargs) - - -class DBSequence: - def __init__(self, *args, **kwargs): - self._cobj = db.DBSequence(*args, **kwargs) - - def close(self, *args, **kwargs): - return self._cobj.close(*args, **kwargs) - def get(self, *args, **kwargs): - return self._cobj.get(*args, **kwargs) - def get_dbp(self, *args, **kwargs): - return self._cobj.get_dbp(*args, **kwargs) - def get_key(self, *args, **kwargs): - return self._cobj.get_key(*args, **kwargs) - def init_value(self, *args, **kwargs): - return self._cobj.init_value(*args, **kwargs) - def open(self, *args, **kwargs): - return self._cobj.open(*args, **kwargs) - def remove(self, *args, **kwargs): - return self._cobj.remove(*args, **kwargs) - def stat(self, *args, **kwargs): - return self._cobj.stat(*args, **kwargs) - def set_cachesize(self, *args, **kwargs): - return self._cobj.set_cachesize(*args, **kwargs) - def set_flags(self, *args, **kwargs): - return self._cobj.set_flags(*args, **kwargs) - def set_range(self, *args, **kwargs): - return self._cobj.set_range(*args, **kwargs) - def get_cachesize(self, *args, **kwargs): - return self._cobj.get_cachesize(*args, **kwargs) - def get_flags(self, *args, **kwargs): - return self._cobj.get_flags(*args, **kwargs) - def get_range(self, *args, **kwargs): - return self._cobj.get_range(*args, **kwargs) diff --git a/PythonLib/extra/bsddb/dbrecio.py b/PythonLib/extra/bsddb/dbrecio.py deleted file mode 100644 index d439f325..00000000 --- a/PythonLib/extra/bsddb/dbrecio.py +++ /dev/null @@ -1,190 +0,0 @@ - -""" -File-like objects that read from or write to a bsddb record. - -This implements (nearly) all stdio methods. - -f = DBRecIO(db, key, txn=None) -f.close() # explicitly release resources held -flag = f.isatty() # always false -pos = f.tell() # get current position -f.seek(pos) # set current position -f.seek(pos, mode) # mode 0: absolute; 1: relative; 2: relative to EOF -buf = f.read() # read until EOF -buf = f.read(n) # read up to n bytes -f.truncate([size]) # truncate file at to at most size (default: current pos) -f.write(buf) # write at current position -f.writelines(list) # for line in list: f.write(line) - -Notes: -- fileno() is left unimplemented so that code which uses it triggers - an exception early. -- There's a simple test set (see end of this file) - not yet updated - for DBRecIO. -- readline() is not implemented yet. - - -From: - Itamar Shtull-Trauring -""" - -import errno -import string - -class DBRecIO: - def __init__(self, db, key, txn=None): - self.db = db - self.key = key - self.txn = txn - self.len = None - self.pos = 0 - self.closed = 0 - self.softspace = 0 - - def close(self): - if not self.closed: - self.closed = 1 - del self.db, self.txn - - def isatty(self): - if self.closed: - raise ValueError, "I/O operation on closed file" - return 0 - - def seek(self, pos, mode = 0): - if self.closed: - raise ValueError, "I/O operation on closed file" - if mode == 1: - pos = pos + self.pos - elif mode == 2: - pos = pos + self.len - self.pos = max(0, pos) - - def tell(self): - if self.closed: - raise ValueError, "I/O operation on closed file" - return self.pos - - def read(self, n = -1): - if self.closed: - raise ValueError, "I/O operation on closed file" - if n < 0: - newpos = self.len - else: - newpos = min(self.pos+n, self.len) - - dlen = newpos - self.pos - - r = self.db.get(self.key, txn=self.txn, dlen=dlen, doff=self.pos) - self.pos = newpos - return r - - __fixme = """ - def readline(self, length=None): - if self.closed: - raise ValueError, "I/O operation on closed file" - if self.buflist: - self.buf = self.buf + string.joinfields(self.buflist, '') - self.buflist = [] - i = string.find(self.buf, '\n', self.pos) - if i < 0: - newpos = self.len - else: - newpos = i+1 - if length is not None: - if self.pos + length < newpos: - newpos = self.pos + length - r = self.buf[self.pos:newpos] - self.pos = newpos - return r - - def readlines(self, sizehint = 0): - total = 0 - lines = [] - line = self.readline() - while line: - lines.append(line) - total += len(line) - if 0 < sizehint <= total: - break - line = self.readline() - return lines - """ - - def truncate(self, size=None): - if self.closed: - raise ValueError, "I/O operation on closed file" - if size is None: - size = self.pos - elif size < 0: - raise IOError(errno.EINVAL, - "Negative size not allowed") - elif size < self.pos: - self.pos = size - self.db.put(self.key, "", txn=self.txn, dlen=self.len-size, doff=size) - - def write(self, s): - if self.closed: - raise ValueError, "I/O operation on closed file" - if not s: return - if self.pos > self.len: - self.buflist.append('\0'*(self.pos - self.len)) - self.len = self.pos - newpos = self.pos + len(s) - self.db.put(self.key, s, txn=self.txn, dlen=len(s), doff=self.pos) - self.pos = newpos - - def writelines(self, list): - self.write(string.joinfields(list, '')) - - def flush(self): - if self.closed: - raise ValueError, "I/O operation on closed file" - - -""" -# A little test suite - -def _test(): - import sys - if sys.argv[1:]: - file = sys.argv[1] - else: - file = '/etc/passwd' - lines = open(file, 'r').readlines() - text = open(file, 'r').read() - f = StringIO() - for line in lines[:-2]: - f.write(line) - f.writelines(lines[-2:]) - if f.getvalue() != text: - raise RuntimeError, 'write failed' - length = f.tell() - print 'File length =', length - f.seek(len(lines[0])) - f.write(lines[1]) - f.seek(0) - print 'First line =', repr(f.readline()) - here = f.tell() - line = f.readline() - print 'Second line =', repr(line) - f.seek(-len(line), 1) - line2 = f.read(len(line)) - if line != line2: - raise RuntimeError, 'bad result after seek back' - f.seek(len(line2), 1) - list = f.readlines() - line = list[-1] - f.seek(f.tell() - len(line)) - line2 = f.read() - if line != line2: - raise RuntimeError, 'bad result after seek back from EOF' - print 'Read', len(list), 'more lines' - print 'File length =', f.tell() - if f.tell() != length: - raise RuntimeError, 'bad length' - f.close() - -if __name__ == '__main__': - _test() -""" diff --git a/PythonLib/extra/bsddb/dbshelve.py b/PythonLib/extra/bsddb/dbshelve.py deleted file mode 100644 index 85deb13a..00000000 --- a/PythonLib/extra/bsddb/dbshelve.py +++ /dev/null @@ -1,382 +0,0 @@ -#!/usr/bin/env python -#------------------------------------------------------------------------ -# Copyright (c) 1997-2001 by Total Control Software -# All Rights Reserved -#------------------------------------------------------------------------ -# -# Module Name: dbShelve.py -# -# Description: A reimplementation of the standard shelve.py that -# forces the use of cPickle, and DB. -# -# Creation Date: 11/3/97 3:39:04PM -# -# License: This is free software. You may use this software for any -# purpose including modification/redistribution, so long as -# this header remains intact and that you do not claim any -# rights of ownership or authorship of this software. This -# software has been tested, but no warranty is expressed or -# implied. -# -# 13-Dec-2000: Updated to be used with the new bsddb3 package. -# Added DBShelfCursor class. -# -#------------------------------------------------------------------------ - -"""Manage shelves of pickled objects using bsddb database files for the -storage. -""" - -#------------------------------------------------------------------------ - -import sys -absolute_import = (sys.version_info[0] >= 3) -if absolute_import : - # Because this syntaxis is not valid before Python 2.5 - exec("from . import db") -else : - import db - -if sys.version_info[0] >= 3 : - import cPickle # Will be converted to "pickle" by "2to3" -else : - if sys.version_info < (2, 6) : - import cPickle - else : - # When we drop support for python 2.4 - # we could use: (in 2.5 we need a __future__ statement) - # - # with warnings.catch_warnings(): - # warnings.filterwarnings(...) - # ... - # - # We can not use "with" as is, because it would be invalid syntax - # in python 2.4 and (with no __future__) 2.5. - # Here we simulate "with" following PEP 343 : - import warnings - w = warnings.catch_warnings() - w.__enter__() - try : - warnings.filterwarnings('ignore', - message='the cPickle module has been removed in Python 3.0', - category=DeprecationWarning) - import cPickle - finally : - w.__exit__() - del w - -HIGHEST_PROTOCOL = cPickle.HIGHEST_PROTOCOL -def _dumps(object, protocol): - return cPickle.dumps(object, protocol=protocol) - -if sys.version_info < (2, 6) : - from UserDict import DictMixin as MutableMapping -else : - import collections - MutableMapping = collections.MutableMapping - -#------------------------------------------------------------------------ - - -def open(filename, flags=db.DB_CREATE, mode=0660, filetype=db.DB_HASH, - dbenv=None, dbname=None): - """ - A simple factory function for compatibility with the standard - shleve.py module. It can be used like this, where key is a string - and data is a pickleable object: - - from bsddb import dbshelve - db = dbshelve.open(filename) - - db[key] = data - - db.close() - """ - if type(flags) == type(''): - sflag = flags - if sflag == 'r': - flags = db.DB_RDONLY - elif sflag == 'rw': - flags = 0 - elif sflag == 'w': - flags = db.DB_CREATE - elif sflag == 'c': - flags = db.DB_CREATE - elif sflag == 'n': - flags = db.DB_TRUNCATE | db.DB_CREATE - else: - raise db.DBError, "flags should be one of 'r', 'w', 'c' or 'n' or use the bsddb.db.DB_* flags" - - d = DBShelf(dbenv) - d.open(filename, dbname, filetype, flags, mode) - return d - -#--------------------------------------------------------------------------- - -class DBShelveError(db.DBError): pass - - -class DBShelf(MutableMapping): - """A shelf to hold pickled objects, built upon a bsddb DB object. It - automatically pickles/unpickles data objects going to/from the DB. - """ - def __init__(self, dbenv=None): - self.db = db.DB(dbenv) - self._closed = True - if HIGHEST_PROTOCOL: - self.protocol = HIGHEST_PROTOCOL - else: - self.protocol = 1 - - - def __del__(self): - self.close() - - - def __getattr__(self, name): - """Many methods we can just pass through to the DB object. - (See below) - """ - return getattr(self.db, name) - - - #----------------------------------- - # Dictionary access methods - - def __len__(self): - return len(self.db) - - - def __getitem__(self, key): - data = self.db[key] - return cPickle.loads(data) - - - def __setitem__(self, key, value): - data = _dumps(value, self.protocol) - self.db[key] = data - - - def __delitem__(self, key): - del self.db[key] - - - def keys(self, txn=None): - if txn is not None: - return self.db.keys(txn) - else: - return self.db.keys() - - if sys.version_info >= (2, 6) : - def __iter__(self) : # XXX: Load all keys in memory :-( - for k in self.db.keys() : - yield k - - # Do this when "DB" support iteration - # Or is it enough to pass thru "getattr"? - # - # def __iter__(self) : - # return self.db.__iter__() - - - def open(self, *args, **kwargs): - self.db.open(*args, **kwargs) - self._closed = False - - - def close(self, *args, **kwargs): - self.db.close(*args, **kwargs) - self._closed = True - - - def __repr__(self): - if self._closed: - return '' % (id(self)) - else: - return repr(dict(self.iteritems())) - - - def items(self, txn=None): - if txn is not None: - items = self.db.items(txn) - else: - items = self.db.items() - newitems = [] - - for k, v in items: - newitems.append( (k, cPickle.loads(v)) ) - return newitems - - def values(self, txn=None): - if txn is not None: - values = self.db.values(txn) - else: - values = self.db.values() - - return map(cPickle.loads, values) - - #----------------------------------- - # Other methods - - def __append(self, value, txn=None): - data = _dumps(value, self.protocol) - return self.db.append(data, txn) - - def append(self, value, txn=None): - if self.get_type() == db.DB_RECNO: - return self.__append(value, txn=txn) - raise DBShelveError, "append() only supported when dbshelve opened with filetype=dbshelve.db.DB_RECNO" - - - def associate(self, secondaryDB, callback, flags=0): - def _shelf_callback(priKey, priData, realCallback=callback): - # Safe in Python 2.x because expresion short circuit - if sys.version_info[0] < 3 or isinstance(priData, bytes) : - data = cPickle.loads(priData) - else : - data = cPickle.loads(bytes(priData, "iso8859-1")) # 8 bits - return realCallback(priKey, data) - - return self.db.associate(secondaryDB, _shelf_callback, flags) - - - #def get(self, key, default=None, txn=None, flags=0): - def get(self, *args, **kw): - # We do it with *args and **kw so if the default value wasn't - # given nothing is passed to the extension module. That way - # an exception can be raised if set_get_returns_none is turned - # off. - data = self.db.get(*args, **kw) - try: - return cPickle.loads(data) - except (EOFError, TypeError, cPickle.UnpicklingError): - return data # we may be getting the default value, or None, - # so it doesn't need unpickled. - - def get_both(self, key, value, txn=None, flags=0): - data = _dumps(value, self.protocol) - data = self.db.get(key, data, txn, flags) - return cPickle.loads(data) - - - def cursor(self, txn=None, flags=0): - c = DBShelfCursor(self.db.cursor(txn, flags)) - c.protocol = self.protocol - return c - - - def put(self, key, value, txn=None, flags=0): - data = _dumps(value, self.protocol) - return self.db.put(key, data, txn, flags) - - - def join(self, cursorList, flags=0): - raise NotImplementedError - - - #---------------------------------------------- - # Methods allowed to pass-through to self.db - # - # close, delete, fd, get_byteswapped, get_type, has_key, - # key_range, open, remove, rename, stat, sync, - # upgrade, verify, and all set_* methods. - - -#--------------------------------------------------------------------------- - -class DBShelfCursor: - """ - """ - def __init__(self, cursor): - self.dbc = cursor - - def __del__(self): - self.close() - - - def __getattr__(self, name): - """Some methods we can just pass through to the cursor object. (See below)""" - return getattr(self.dbc, name) - - - #---------------------------------------------- - - def dup(self, flags=0): - c = DBShelfCursor(self.dbc.dup(flags)) - c.protocol = self.protocol - return c - - - def put(self, key, value, flags=0): - data = _dumps(value, self.protocol) - return self.dbc.put(key, data, flags) - - - def get(self, *args): - count = len(args) # a method overloading hack - method = getattr(self, 'get_%d' % count) - method(*args) - - def get_1(self, flags): - rec = self.dbc.get(flags) - return self._extract(rec) - - def get_2(self, key, flags): - rec = self.dbc.get(key, flags) - return self._extract(rec) - - def get_3(self, key, value, flags): - data = _dumps(value, self.protocol) - rec = self.dbc.get(key, flags) - return self._extract(rec) - - - def current(self, flags=0): return self.get_1(flags|db.DB_CURRENT) - def first(self, flags=0): return self.get_1(flags|db.DB_FIRST) - def last(self, flags=0): return self.get_1(flags|db.DB_LAST) - def next(self, flags=0): return self.get_1(flags|db.DB_NEXT) - def prev(self, flags=0): return self.get_1(flags|db.DB_PREV) - def consume(self, flags=0): return self.get_1(flags|db.DB_CONSUME) - def next_dup(self, flags=0): return self.get_1(flags|db.DB_NEXT_DUP) - def next_nodup(self, flags=0): return self.get_1(flags|db.DB_NEXT_NODUP) - def prev_nodup(self, flags=0): return self.get_1(flags|db.DB_PREV_NODUP) - - - def get_both(self, key, value, flags=0): - data = _dumps(value, self.protocol) - rec = self.dbc.get_both(key, flags) - return self._extract(rec) - - - def set(self, key, flags=0): - rec = self.dbc.set(key, flags) - return self._extract(rec) - - def set_range(self, key, flags=0): - rec = self.dbc.set_range(key, flags) - return self._extract(rec) - - def set_recno(self, recno, flags=0): - rec = self.dbc.set_recno(recno, flags) - return self._extract(rec) - - set_both = get_both - - def _extract(self, rec): - if rec is None: - return None - else: - key, data = rec - # Safe in Python 2.x because expresion short circuit - if sys.version_info[0] < 3 or isinstance(data, bytes) : - return key, cPickle.loads(data) - else : - return key, cPickle.loads(bytes(data, "iso8859-1")) # 8 bits - - #---------------------------------------------- - # Methods allowed to pass-through to self.dbc - # - # close, count, delete, get_recno, join_item - - -#--------------------------------------------------------------------------- diff --git a/PythonLib/extra/bsddb/dbtables.py b/PythonLib/extra/bsddb/dbtables.py deleted file mode 100644 index e8acdd00..00000000 --- a/PythonLib/extra/bsddb/dbtables.py +++ /dev/null @@ -1,843 +0,0 @@ -#----------------------------------------------------------------------- -# -# Copyright (C) 2000, 2001 by Autonomous Zone Industries -# Copyright (C) 2002 Gregory P. Smith -# -# License: This is free software. You may use this software for any -# purpose including modification/redistribution, so long as -# this header remains intact and that you do not claim any -# rights of ownership or authorship of this software. This -# software has been tested, but no warranty is expressed or -# implied. -# -# -- Gregory P. Smith - -# This provides a simple database table interface built on top of -# the Python Berkeley DB 3 interface. -# -_cvsid = '$Id$' - -import re -import sys -import copy -import random -import struct - - -if sys.version_info[0] >= 3 : - import pickle -else : - if sys.version_info < (2, 6) : - import cPickle as pickle - else : - # When we drop support for python 2.4 - # we could use: (in 2.5 we need a __future__ statement) - # - # with warnings.catch_warnings(): - # warnings.filterwarnings(...) - # ... - # - # We can not use "with" as is, because it would be invalid syntax - # in python 2.4 and (with no __future__) 2.5. - # Here we simulate "with" following PEP 343 : - import warnings - w = warnings.catch_warnings() - w.__enter__() - try : - warnings.filterwarnings('ignore', - message='the cPickle module has been removed in Python 3.0', - category=DeprecationWarning) - import cPickle as pickle - finally : - w.__exit__() - del w - -try: - # For Pythons w/distutils pybsddb - from bsddb3 import db -except ImportError: - # For Python 2.3 - from bsddb import db - -class TableDBError(StandardError): - pass -class TableAlreadyExists(TableDBError): - pass - - -class Cond: - """This condition matches everything""" - def __call__(self, s): - return 1 - -class ExactCond(Cond): - """Acts as an exact match condition function""" - def __init__(self, strtomatch): - self.strtomatch = strtomatch - def __call__(self, s): - return s == self.strtomatch - -class PrefixCond(Cond): - """Acts as a condition function for matching a string prefix""" - def __init__(self, prefix): - self.prefix = prefix - def __call__(self, s): - return s[:len(self.prefix)] == self.prefix - -class PostfixCond(Cond): - """Acts as a condition function for matching a string postfix""" - def __init__(self, postfix): - self.postfix = postfix - def __call__(self, s): - return s[-len(self.postfix):] == self.postfix - -class LikeCond(Cond): - """ - Acts as a function that will match using an SQL 'LIKE' style - string. Case insensitive and % signs are wild cards. - This isn't perfect but it should work for the simple common cases. - """ - def __init__(self, likestr, re_flags=re.IGNORECASE): - # escape python re characters - chars_to_escape = '.*+()[]?' - for char in chars_to_escape : - likestr = likestr.replace(char, '\\'+char) - # convert %s to wildcards - self.likestr = likestr.replace('%', '.*') - self.re = re.compile('^'+self.likestr+'$', re_flags) - def __call__(self, s): - return self.re.match(s) - -# -# keys used to store database metadata -# -_table_names_key = '__TABLE_NAMES__' # list of the tables in this db -_columns = '._COLUMNS__' # table_name+this key contains a list of columns - -def _columns_key(table): - return table + _columns - -# -# these keys are found within table sub databases -# -_data = '._DATA_.' # this+column+this+rowid key contains table data -_rowid = '._ROWID_.' # this+rowid+this key contains a unique entry for each - # row in the table. (no data is stored) -_rowid_str_len = 8 # length in bytes of the unique rowid strings - - -def _data_key(table, col, rowid): - return table + _data + col + _data + rowid - -def _search_col_data_key(table, col): - return table + _data + col + _data - -def _search_all_data_key(table): - return table + _data - -def _rowid_key(table, rowid): - return table + _rowid + rowid + _rowid - -def _search_rowid_key(table): - return table + _rowid - -def contains_metastrings(s) : - """Verify that the given string does not contain any - metadata strings that might interfere with dbtables database operation. - """ - if (s.find(_table_names_key) >= 0 or - s.find(_columns) >= 0 or - s.find(_data) >= 0 or - s.find(_rowid) >= 0): - # Then - return 1 - else: - return 0 - - -class bsdTableDB : - def __init__(self, filename, dbhome, create=0, truncate=0, mode=0600, - recover=0, dbflags=0): - """bsdTableDB(filename, dbhome, create=0, truncate=0, mode=0600) - - Open database name in the dbhome Berkeley DB directory. - Use keyword arguments when calling this constructor. - """ - self.db = None - myflags = db.DB_THREAD - if create: - myflags |= db.DB_CREATE - flagsforenv = (db.DB_INIT_MPOOL | db.DB_INIT_LOCK | db.DB_INIT_LOG | - db.DB_INIT_TXN | dbflags) - # DB_AUTO_COMMIT isn't a valid flag for env.open() - try: - dbflags |= db.DB_AUTO_COMMIT - except AttributeError: - pass - if recover: - flagsforenv = flagsforenv | db.DB_RECOVER - self.env = db.DBEnv() - # enable auto deadlock avoidance - self.env.set_lk_detect(db.DB_LOCK_DEFAULT) - self.env.open(dbhome, myflags | flagsforenv) - if truncate: - myflags |= db.DB_TRUNCATE - self.db = db.DB(self.env) - # this code relies on DBCursor.set* methods to raise exceptions - # rather than returning None - self.db.set_get_returns_none(1) - # allow duplicate entries [warning: be careful w/ metadata] - self.db.set_flags(db.DB_DUP) - self.db.open(filename, db.DB_BTREE, dbflags | myflags, mode) - self.dbfilename = filename - - if sys.version_info[0] >= 3 : - class cursor_py3k(object) : - def __init__(self, dbcursor) : - self._dbcursor = dbcursor - - def close(self) : - return self._dbcursor.close() - - def set_range(self, search) : - v = self._dbcursor.set_range(bytes(search, "iso8859-1")) - if v is not None : - v = (v[0].decode("iso8859-1"), - v[1].decode("iso8859-1")) - return v - - def __next__(self) : - v = getattr(self._dbcursor, "next")() - if v is not None : - v = (v[0].decode("iso8859-1"), - v[1].decode("iso8859-1")) - return v - - class db_py3k(object) : - def __init__(self, db) : - self._db = db - - def cursor(self, txn=None) : - return cursor_py3k(self._db.cursor(txn=txn)) - - def has_key(self, key, txn=None) : - return getattr(self._db,"has_key")(bytes(key, "iso8859-1"), - txn=txn) - - def put(self, key, value, flags=0, txn=None) : - key = bytes(key, "iso8859-1") - if value is not None : - value = bytes(value, "iso8859-1") - return self._db.put(key, value, flags=flags, txn=txn) - - def put_bytes(self, key, value, txn=None) : - key = bytes(key, "iso8859-1") - return self._db.put(key, value, txn=txn) - - def get(self, key, txn=None, flags=0) : - key = bytes(key, "iso8859-1") - v = self._db.get(key, txn=txn, flags=flags) - if v is not None : - v = v.decode("iso8859-1") - return v - - def get_bytes(self, key, txn=None, flags=0) : - key = bytes(key, "iso8859-1") - return self._db.get(key, txn=txn, flags=flags) - - def delete(self, key, txn=None) : - key = bytes(key, "iso8859-1") - return self._db.delete(key, txn=txn) - - def close (self) : - return self._db.close() - - self.db = db_py3k(self.db) - else : # Python 2.x - pass - - # Initialize the table names list if this is a new database - txn = self.env.txn_begin() - try: - if not getattr(self.db, "has_key")(_table_names_key, txn): - getattr(self.db, "put_bytes", self.db.put) \ - (_table_names_key, pickle.dumps([], 1), txn=txn) - # Yes, bare except - except: - txn.abort() - raise - else: - txn.commit() - # TODO verify more of the database's metadata? - self.__tablecolumns = {} - - def __del__(self): - self.close() - - def close(self): - if self.db is not None: - self.db.close() - self.db = None - if self.env is not None: - self.env.close() - self.env = None - - def checkpoint(self, mins=0): - self.env.txn_checkpoint(mins) - - def sync(self): - self.db.sync() - - def _db_print(self) : - """Print the database to stdout for debugging""" - print "******** Printing raw database for debugging ********" - cur = self.db.cursor() - try: - key, data = cur.first() - while 1: - print repr({key: data}) - next = cur.next() - if next: - key, data = next - else: - cur.close() - return - except db.DBNotFoundError: - cur.close() - - - def CreateTable(self, table, columns): - """CreateTable(table, columns) - Create a new table in the database. - - raises TableDBError if it already exists or for other DB errors. - """ - assert isinstance(columns, list) - - txn = None - try: - # checking sanity of the table and column names here on - # table creation will prevent problems elsewhere. - if contains_metastrings(table): - raise ValueError( - "bad table name: contains reserved metastrings") - for column in columns : - if contains_metastrings(column): - raise ValueError( - "bad column name: contains reserved metastrings") - - columnlist_key = _columns_key(table) - if getattr(self.db, "has_key")(columnlist_key): - raise TableAlreadyExists, "table already exists" - - txn = self.env.txn_begin() - # store the table's column info - getattr(self.db, "put_bytes", self.db.put)(columnlist_key, - pickle.dumps(columns, 1), txn=txn) - - # add the table name to the tablelist - tablelist = pickle.loads(getattr(self.db, "get_bytes", - self.db.get) (_table_names_key, txn=txn, flags=db.DB_RMW)) - tablelist.append(table) - # delete 1st, in case we opened with DB_DUP - self.db.delete(_table_names_key, txn=txn) - getattr(self.db, "put_bytes", self.db.put)(_table_names_key, - pickle.dumps(tablelist, 1), txn=txn) - - txn.commit() - txn = None - except db.DBError, dberror: - if txn: - txn.abort() - if sys.version_info < (2, 6) : - raise TableDBError, dberror[1] - else : - raise TableDBError, dberror.args[1] - - - def ListTableColumns(self, table): - """Return a list of columns in the given table. - [] if the table doesn't exist. - """ - assert isinstance(table, str) - if contains_metastrings(table): - raise ValueError, "bad table name: contains reserved metastrings" - - columnlist_key = _columns_key(table) - if not getattr(self.db, "has_key")(columnlist_key): - return [] - pickledcolumnlist = getattr(self.db, "get_bytes", - self.db.get)(columnlist_key) - if pickledcolumnlist: - return pickle.loads(pickledcolumnlist) - else: - return [] - - def ListTables(self): - """Return a list of tables in this database.""" - pickledtablelist = self.db.get_get(_table_names_key) - if pickledtablelist: - return pickle.loads(pickledtablelist) - else: - return [] - - def CreateOrExtendTable(self, table, columns): - """CreateOrExtendTable(table, columns) - - Create a new table in the database. - - If a table of this name already exists, extend it to have any - additional columns present in the given list as well as - all of its current columns. - """ - assert isinstance(columns, list) - - try: - self.CreateTable(table, columns) - except TableAlreadyExists: - # the table already existed, add any new columns - txn = None - try: - columnlist_key = _columns_key(table) - txn = self.env.txn_begin() - - # load the current column list - oldcolumnlist = pickle.loads( - getattr(self.db, "get_bytes", - self.db.get)(columnlist_key, txn=txn, flags=db.DB_RMW)) - # create a hash table for fast lookups of column names in the - # loop below - oldcolumnhash = {} - for c in oldcolumnlist: - oldcolumnhash[c] = c - - # create a new column list containing both the old and new - # column names - newcolumnlist = copy.copy(oldcolumnlist) - for c in columns: - if not c in oldcolumnhash: - newcolumnlist.append(c) - - # store the table's new extended column list - if newcolumnlist != oldcolumnlist : - # delete the old one first since we opened with DB_DUP - self.db.delete(columnlist_key, txn=txn) - getattr(self.db, "put_bytes", self.db.put)(columnlist_key, - pickle.dumps(newcolumnlist, 1), - txn=txn) - - txn.commit() - txn = None - - self.__load_column_info(table) - except db.DBError, dberror: - if txn: - txn.abort() - if sys.version_info < (2, 6) : - raise TableDBError, dberror[1] - else : - raise TableDBError, dberror.args[1] - - - def __load_column_info(self, table) : - """initialize the self.__tablecolumns dict""" - # check the column names - try: - tcolpickles = getattr(self.db, "get_bytes", - self.db.get)(_columns_key(table)) - except db.DBNotFoundError: - raise TableDBError, "unknown table: %r" % (table,) - if not tcolpickles: - raise TableDBError, "unknown table: %r" % (table,) - self.__tablecolumns[table] = pickle.loads(tcolpickles) - - def __new_rowid(self, table, txn) : - """Create a new unique row identifier""" - unique = 0 - while not unique: - # Generate a random 64-bit row ID string - # (note: might have <64 bits of true randomness - # but it's plenty for our database id needs!) - blist = [] - for x in xrange(_rowid_str_len): - blist.append(random.randint(0,255)) - newid = struct.pack('B'*_rowid_str_len, *blist) - - if sys.version_info[0] >= 3 : - newid = newid.decode("iso8859-1") # 8 bits - - # Guarantee uniqueness by adding this key to the database - try: - self.db.put(_rowid_key(table, newid), None, txn=txn, - flags=db.DB_NOOVERWRITE) - except db.DBKeyExistError: - pass - else: - unique = 1 - - return newid - - - def Insert(self, table, rowdict) : - """Insert(table, datadict) - Insert a new row into the table - using the keys+values from rowdict as the column values. - """ - - txn = None - try: - if not getattr(self.db, "has_key")(_columns_key(table)): - raise TableDBError, "unknown table" - - # check the validity of each column name - if not table in self.__tablecolumns: - self.__load_column_info(table) - for column in rowdict.keys() : - if not self.__tablecolumns[table].count(column): - raise TableDBError, "unknown column: %r" % (column,) - - # get a unique row identifier for this row - txn = self.env.txn_begin() - rowid = self.__new_rowid(table, txn=txn) - - # insert the row values into the table database - for column, dataitem in rowdict.items(): - # store the value - self.db.put(_data_key(table, column, rowid), dataitem, txn=txn) - - txn.commit() - txn = None - - except db.DBError, dberror: - # WIBNI we could just abort the txn and re-raise the exception? - # But no, because TableDBError is not related to DBError via - # inheritance, so it would be backwards incompatible. Do the next - # best thing. - info = sys.exc_info() - if txn: - txn.abort() - self.db.delete(_rowid_key(table, rowid)) - if sys.version_info < (2, 6) : - raise TableDBError, dberror[1], info[2] - else : - raise TableDBError, dberror.args[1], info[2] - - - def Modify(self, table, conditions={}, mappings={}): - """Modify(table, conditions={}, mappings={}) - Modify items in rows matching 'conditions' using mapping functions in 'mappings' - - * table - the table name - * conditions - a dictionary keyed on column names containing - a condition callable expecting the data string as an - argument and returning a boolean. - * mappings - a dictionary keyed on column names containing a - condition callable expecting the data string as an argument and - returning the new string for that column. - """ - - try: - matching_rowids = self.__Select(table, [], conditions) - - # modify only requested columns - columns = mappings.keys() - for rowid in matching_rowids.keys(): - txn = None - try: - for column in columns: - txn = self.env.txn_begin() - # modify the requested column - try: - dataitem = self.db.get( - _data_key(table, column, rowid), - txn=txn) - self.db.delete( - _data_key(table, column, rowid), - txn=txn) - except db.DBNotFoundError: - # XXXXXXX row key somehow didn't exist, assume no - # error - dataitem = None - dataitem = mappings[column](dataitem) - if dataitem is not None: - self.db.put( - _data_key(table, column, rowid), - dataitem, txn=txn) - txn.commit() - txn = None - - # catch all exceptions here since we call unknown callables - except: - if txn: - txn.abort() - raise - - except db.DBError, dberror: - if sys.version_info < (2, 6) : - raise TableDBError, dberror[1] - else : - raise TableDBError, dberror.args[1] - - def Delete(self, table, conditions={}): - """Delete(table, conditions) - Delete items matching the given - conditions from the table. - - * conditions - a dictionary keyed on column names containing - condition functions expecting the data string as an - argument and returning a boolean. - """ - - try: - matching_rowids = self.__Select(table, [], conditions) - - # delete row data from all columns - columns = self.__tablecolumns[table] - for rowid in matching_rowids.keys(): - txn = None - try: - txn = self.env.txn_begin() - for column in columns: - # delete the data key - try: - self.db.delete(_data_key(table, column, rowid), - txn=txn) - except db.DBNotFoundError: - # XXXXXXX column may not exist, assume no error - pass - - try: - self.db.delete(_rowid_key(table, rowid), txn=txn) - except db.DBNotFoundError: - # XXXXXXX row key somehow didn't exist, assume no error - pass - txn.commit() - txn = None - except db.DBError, dberror: - if txn: - txn.abort() - raise - except db.DBError, dberror: - if sys.version_info < (2, 6) : - raise TableDBError, dberror[1] - else : - raise TableDBError, dberror.args[1] - - - def Select(self, table, columns, conditions={}): - """Select(table, columns, conditions) - retrieve specific row data - Returns a list of row column->value mapping dictionaries. - - * columns - a list of which column data to return. If - columns is None, all columns will be returned. - * conditions - a dictionary keyed on column names - containing callable conditions expecting the data string as an - argument and returning a boolean. - """ - try: - if not table in self.__tablecolumns: - self.__load_column_info(table) - if columns is None: - columns = self.__tablecolumns[table] - matching_rowids = self.__Select(table, columns, conditions) - except db.DBError, dberror: - if sys.version_info < (2, 6) : - raise TableDBError, dberror[1] - else : - raise TableDBError, dberror.args[1] - # return the matches as a list of dictionaries - return matching_rowids.values() - - - def __Select(self, table, columns, conditions): - """__Select() - Used to implement Select and Delete (above) - Returns a dictionary keyed on rowids containing dicts - holding the row data for columns listed in the columns param - that match the given conditions. - * conditions is a dictionary keyed on column names - containing callable conditions expecting the data string as an - argument and returning a boolean. - """ - # check the validity of each column name - if not table in self.__tablecolumns: - self.__load_column_info(table) - if columns is None: - columns = self.tablecolumns[table] - for column in (columns + conditions.keys()): - if not self.__tablecolumns[table].count(column): - raise TableDBError, "unknown column: %r" % (column,) - - # keyed on rows that match so far, containings dicts keyed on - # column names containing the data for that row and column. - matching_rowids = {} - # keys are rowids that do not match - rejected_rowids = {} - - # attempt to sort the conditions in such a way as to minimize full - # column lookups - def cmp_conditions(atuple, btuple): - a = atuple[1] - b = btuple[1] - if type(a) is type(b): - - # Needed for python 3. "cmp" vanished in 3.0.1 - def cmp(a, b) : - if a==b : return 0 - if a 0: - for rowid, rowdata in matching_rowids.items(): - for column in columns: - if column in rowdata: - continue - try: - rowdata[column] = self.db.get( - _data_key(table, column, rowid)) - except db.DBError, dberror: - if sys.version_info < (2, 6) : - if dberror[0] != db.DB_NOTFOUND: - raise - else : - if dberror.args[0] != db.DB_NOTFOUND: - raise - rowdata[column] = None - - # return the matches - return matching_rowids - - - def Drop(self, table): - """Remove an entire table from the database""" - txn = None - try: - txn = self.env.txn_begin() - - # delete the column list - self.db.delete(_columns_key(table), txn=txn) - - cur = self.db.cursor(txn) - - # delete all keys containing this tables column and row info - table_key = _search_all_data_key(table) - while 1: - try: - key, data = cur.set_range(table_key) - except db.DBNotFoundError: - break - # only delete items in this table - if key[:len(table_key)] != table_key: - break - cur.delete() - - # delete all rowids used by this table - table_key = _search_rowid_key(table) - while 1: - try: - key, data = cur.set_range(table_key) - except db.DBNotFoundError: - break - # only delete items in this table - if key[:len(table_key)] != table_key: - break - cur.delete() - - cur.close() - - # delete the tablename from the table name list - tablelist = pickle.loads( - getattr(self.db, "get_bytes", self.db.get)(_table_names_key, - txn=txn, flags=db.DB_RMW)) - try: - tablelist.remove(table) - except ValueError: - # hmm, it wasn't there, oh well, that's what we want. - pass - # delete 1st, incase we opened with DB_DUP - self.db.delete(_table_names_key, txn=txn) - getattr(self.db, "put_bytes", self.db.put)(_table_names_key, - pickle.dumps(tablelist, 1), txn=txn) - - txn.commit() - txn = None - - if table in self.__tablecolumns: - del self.__tablecolumns[table] - - except db.DBError, dberror: - if txn: - txn.abort() - raise TableDBError(dberror.args[1]) diff --git a/PythonLib/extra/bsddb/dbutils.py b/PythonLib/extra/bsddb/dbutils.py deleted file mode 100644 index 02a686f5..00000000 --- a/PythonLib/extra/bsddb/dbutils.py +++ /dev/null @@ -1,83 +0,0 @@ -#------------------------------------------------------------------------ -# -# Copyright (C) 2000 Autonomous Zone Industries -# -# License: This is free software. You may use this software for any -# purpose including modification/redistribution, so long as -# this header remains intact and that you do not claim any -# rights of ownership or authorship of this software. This -# software has been tested, but no warranty is expressed or -# implied. -# -# Author: Gregory P. Smith -# -# Note: I don't know how useful this is in reality since when a -# DBLockDeadlockError happens the current transaction is supposed to be -# aborted. If it doesn't then when the operation is attempted again -# the deadlock is still happening... -# --Robin -# -#------------------------------------------------------------------------ - - -# -# import the time.sleep function in a namespace safe way to allow -# "from bsddb.dbutils import *" -# -from time import sleep as _sleep - -import sys -absolute_import = (sys.version_info[0] >= 3) -if absolute_import : - # Because this syntaxis is not valid before Python 2.5 - exec("from . import db") -else : - import db - -# always sleep at least N seconds between retrys -_deadlock_MinSleepTime = 1.0/128 -# never sleep more than N seconds between retrys -_deadlock_MaxSleepTime = 3.14159 - -# Assign a file object to this for a "sleeping" message to be written to it -# each retry -_deadlock_VerboseFile = None - - -def DeadlockWrap(function, *_args, **_kwargs): - """DeadlockWrap(function, *_args, **_kwargs) - automatically retries - function in case of a database deadlock. - - This is a function intended to be used to wrap database calls such - that they perform retrys with exponentially backing off sleeps in - between when a DBLockDeadlockError exception is raised. - - A 'max_retries' parameter may optionally be passed to prevent it - from retrying forever (in which case the exception will be reraised). - - d = DB(...) - d.open(...) - DeadlockWrap(d.put, "foo", data="bar") # set key "foo" to "bar" - """ - sleeptime = _deadlock_MinSleepTime - max_retries = _kwargs.get('max_retries', -1) - if 'max_retries' in _kwargs: - del _kwargs['max_retries'] - while True: - try: - return function(*_args, **_kwargs) - except db.DBLockDeadlockError: - if _deadlock_VerboseFile: - _deadlock_VerboseFile.write( - 'dbutils.DeadlockWrap: sleeping %1.3f\n' % sleeptime) - _sleep(sleeptime) - # exponential backoff in the sleep time - sleeptime *= 2 - if sleeptime > _deadlock_MaxSleepTime: - sleeptime = _deadlock_MaxSleepTime - max_retries -= 1 - if max_retries == -1: - raise - - -#------------------------------------------------------------------------ diff --git a/PythonLib/extra/bsddb/test/test_all.py b/PythonLib/extra/bsddb/test/test_all.py deleted file mode 100644 index caef1ac2..00000000 --- a/PythonLib/extra/bsddb/test/test_all.py +++ /dev/null @@ -1,623 +0,0 @@ -"""Run all test cases. -""" - -import sys -import os -import unittest -try: - # For Pythons w/distutils pybsddb - import bsddb3 as bsddb -except ImportError: - # For Python 2.3 - import bsddb - - -if sys.version_info[0] >= 3 : - charset = "iso8859-1" # Full 8 bit - - class logcursor_py3k(object) : - def __init__(self, env) : - self._logcursor = env.log_cursor() - - def __getattr__(self, v) : - return getattr(self._logcursor, v) - - def __next__(self) : - v = getattr(self._logcursor, "next")() - if v is not None : - v = (v[0], v[1].decode(charset)) - return v - - next = __next__ - - def first(self) : - v = self._logcursor.first() - if v is not None : - v = (v[0], v[1].decode(charset)) - return v - - def last(self) : - v = self._logcursor.last() - if v is not None : - v = (v[0], v[1].decode(charset)) - return v - - def prev(self) : - v = self._logcursor.prev() - if v is not None : - v = (v[0], v[1].decode(charset)) - return v - - def current(self) : - v = self._logcursor.current() - if v is not None : - v = (v[0], v[1].decode(charset)) - return v - - def set(self, lsn) : - v = self._logcursor.set(lsn) - if v is not None : - v = (v[0], v[1].decode(charset)) - return v - - class cursor_py3k(object) : - def __init__(self, db, *args, **kwargs) : - self._dbcursor = db.cursor(*args, **kwargs) - - def __getattr__(self, v) : - return getattr(self._dbcursor, v) - - def _fix(self, v) : - if v is None : return None - key, value = v - if isinstance(key, bytes) : - key = key.decode(charset) - return (key, value.decode(charset)) - - def __next__(self) : - v = getattr(self._dbcursor, "next")() - return self._fix(v) - - next = __next__ - - def previous(self) : - v = self._dbcursor.previous() - return self._fix(v) - - def last(self) : - v = self._dbcursor.last() - return self._fix(v) - - def set(self, k) : - if isinstance(k, str) : - k = bytes(k, charset) - v = self._dbcursor.set(k) - return self._fix(v) - - def set_recno(self, num) : - v = self._dbcursor.set_recno(num) - return self._fix(v) - - def set_range(self, k, dlen=-1, doff=-1) : - if isinstance(k, str) : - k = bytes(k, charset) - v = self._dbcursor.set_range(k, dlen=dlen, doff=doff) - return self._fix(v) - - def dup(self, flags=0) : - cursor = self._dbcursor.dup(flags) - return dup_cursor_py3k(cursor) - - def next_dup(self) : - v = self._dbcursor.next_dup() - return self._fix(v) - - def next_nodup(self) : - v = self._dbcursor.next_nodup() - return self._fix(v) - - def put(self, key, data, flags=0, dlen=-1, doff=-1) : - if isinstance(key, str) : - key = bytes(key, charset) - if isinstance(data, str) : - value = bytes(data, charset) - return self._dbcursor.put(key, data, flags=flags, dlen=dlen, - doff=doff) - - def current(self, flags=0, dlen=-1, doff=-1) : - v = self._dbcursor.current(flags=flags, dlen=dlen, doff=doff) - return self._fix(v) - - def first(self) : - v = self._dbcursor.first() - return self._fix(v) - - def pget(self, key=None, data=None, flags=0) : - # Incorrect because key can be a bare number, - # but enough to pass testsuite - if isinstance(key, int) and (data is None) and (flags == 0) : - flags = key - key = None - if isinstance(key, str) : - key = bytes(key, charset) - if isinstance(data, int) and (flags==0) : - flags = data - data = None - if isinstance(data, str) : - data = bytes(data, charset) - v=self._dbcursor.pget(key=key, data=data, flags=flags) - if v is not None : - v1, v2, v3 = v - if isinstance(v1, bytes) : - v1 = v1.decode(charset) - if isinstance(v2, bytes) : - v2 = v2.decode(charset) - - v = (v1, v2, v3.decode(charset)) - - return v - - def join_item(self) : - v = self._dbcursor.join_item() - if v is not None : - v = v.decode(charset) - return v - - def get(self, *args, **kwargs) : - l = len(args) - if l == 2 : - k, f = args - if isinstance(k, str) : - k = bytes(k, "iso8859-1") - args = (k, f) - elif l == 3 : - k, d, f = args - if isinstance(k, str) : - k = bytes(k, charset) - if isinstance(d, str) : - d = bytes(d, charset) - args =(k, d, f) - - v = self._dbcursor.get(*args, **kwargs) - if v is not None : - k, v = v - if isinstance(k, bytes) : - k = k.decode(charset) - v = (k, v.decode(charset)) - return v - - def get_both(self, key, value) : - if isinstance(key, str) : - key = bytes(key, charset) - if isinstance(value, str) : - value = bytes(value, charset) - v=self._dbcursor.get_both(key, value) - return self._fix(v) - - class dup_cursor_py3k(cursor_py3k) : - def __init__(self, dbcursor) : - self._dbcursor = dbcursor - - class DB_py3k(object) : - def __init__(self, *args, **kwargs) : - args2=[] - for i in args : - if isinstance(i, DBEnv_py3k) : - i = i._dbenv - args2.append(i) - args = tuple(args2) - for k, v in kwargs.items() : - if isinstance(v, DBEnv_py3k) : - kwargs[k] = v._dbenv - - self._db = bsddb._db.DB_orig(*args, **kwargs) - - def __contains__(self, k) : - if isinstance(k, str) : - k = bytes(k, charset) - return getattr(self._db, "has_key")(k) - - def __getitem__(self, k) : - if isinstance(k, str) : - k = bytes(k, charset) - v = self._db[k] - if v is not None : - v = v.decode(charset) - return v - - def __setitem__(self, k, v) : - if isinstance(k, str) : - k = bytes(k, charset) - if isinstance(v, str) : - v = bytes(v, charset) - self._db[k] = v - - def __delitem__(self, k) : - if isinstance(k, str) : - k = bytes(k, charset) - del self._db[k] - - def __getattr__(self, v) : - return getattr(self._db, v) - - def __len__(self) : - return len(self._db) - - def has_key(self, k, txn=None) : - if isinstance(k, str) : - k = bytes(k, charset) - return self._db.has_key(k, txn=txn) - - def set_re_delim(self, c) : - if isinstance(c, str) : # We can use a numeric value byte too - c = bytes(c, charset) - return self._db.set_re_delim(c) - - def set_re_pad(self, c) : - if isinstance(c, str) : # We can use a numeric value byte too - c = bytes(c, charset) - return self._db.set_re_pad(c) - - def get_re_source(self) : - source = self._db.get_re_source() - return source.decode(charset) - - def put(self, key, data, txn=None, flags=0, dlen=-1, doff=-1) : - if isinstance(key, str) : - key = bytes(key, charset) - if isinstance(data, str) : - value = bytes(data, charset) - return self._db.put(key, data, flags=flags, txn=txn, dlen=dlen, - doff=doff) - - def append(self, value, txn=None) : - if isinstance(value, str) : - value = bytes(value, charset) - return self._db.append(value, txn=txn) - - def get_size(self, key) : - if isinstance(key, str) : - key = bytes(key, charset) - return self._db.get_size(key) - - def exists(self, key, *args, **kwargs) : - if isinstance(key, str) : - key = bytes(key, charset) - return self._db.exists(key, *args, **kwargs) - - def get(self, key, default="MagicCookie", txn=None, flags=0, dlen=-1, doff=-1) : - if isinstance(key, str) : - key = bytes(key, charset) - if default != "MagicCookie" : # Magic for 'test_get_none.py' - v=self._db.get(key, default=default, txn=txn, flags=flags, - dlen=dlen, doff=doff) - else : - v=self._db.get(key, txn=txn, flags=flags, - dlen=dlen, doff=doff) - if (v is not None) and isinstance(v, bytes) : - v = v.decode(charset) - return v - - def pget(self, key, txn=None) : - if isinstance(key, str) : - key = bytes(key, charset) - v=self._db.pget(key, txn=txn) - if v is not None : - v1, v2 = v - if isinstance(v1, bytes) : - v1 = v1.decode(charset) - - v = (v1, v2.decode(charset)) - return v - - def get_both(self, key, value, txn=None, flags=0) : - if isinstance(key, str) : - key = bytes(key, charset) - if isinstance(value, str) : - value = bytes(value, charset) - v=self._db.get_both(key, value, txn=txn, flags=flags) - if v is not None : - v = v.decode(charset) - return v - - def delete(self, key, txn=None) : - if isinstance(key, str) : - key = bytes(key, charset) - return self._db.delete(key, txn=txn) - - def keys(self) : - k = self._db.keys() - if len(k) and isinstance(k[0], bytes) : - return [i.decode(charset) for i in self._db.keys()] - else : - return k - - def items(self) : - data = self._db.items() - if not len(data) : return data - data2 = [] - for k, v in data : - if isinstance(k, bytes) : - k = k.decode(charset) - data2.append((k, v.decode(charset))) - return data2 - - def associate(self, secondarydb, callback, flags=0, txn=None) : - class associate_callback(object) : - def __init__(self, callback) : - self._callback = callback - - def callback(self, key, data) : - if isinstance(key, str) : - key = key.decode(charset) - data = data.decode(charset) - key = self._callback(key, data) - if (key != bsddb._db.DB_DONOTINDEX) : - if isinstance(key, str) : - key = bytes(key, charset) - elif isinstance(key, list) : - key2 = [] - for i in key : - if isinstance(i, str) : - i = bytes(i, charset) - key2.append(i) - key = key2 - return key - - return self._db.associate(secondarydb._db, - associate_callback(callback).callback, flags=flags, - txn=txn) - - def cursor(self, txn=None, flags=0) : - return cursor_py3k(self._db, txn=txn, flags=flags) - - def join(self, cursor_list) : - cursor_list = [i._dbcursor for i in cursor_list] - return dup_cursor_py3k(self._db.join(cursor_list)) - - class DBEnv_py3k(object) : - def __init__(self, *args, **kwargs) : - self._dbenv = bsddb._db.DBEnv_orig(*args, **kwargs) - - def __getattr__(self, v) : - return getattr(self._dbenv, v) - - def log_cursor(self, flags=0) : - return logcursor_py3k(self._dbenv) - - def get_lg_dir(self) : - return self._dbenv.get_lg_dir().decode(charset) - - def get_tmp_dir(self) : - return self._dbenv.get_tmp_dir().decode(charset) - - def get_data_dirs(self) : - return tuple( - (i.decode(charset) for i in self._dbenv.get_data_dirs())) - - class DBSequence_py3k(object) : - def __init__(self, db, *args, **kwargs) : - self._db=db - self._dbsequence = bsddb._db.DBSequence_orig(db._db, *args, **kwargs) - - def __getattr__(self, v) : - return getattr(self._dbsequence, v) - - def open(self, key, *args, **kwargs) : - return self._dbsequence.open(bytes(key, charset), *args, **kwargs) - - def get_key(self) : - return self._dbsequence.get_key().decode(charset) - - def get_dbp(self) : - return self._db - - import string - string.letters=[chr(i) for i in xrange(65,91)] - - bsddb._db.DBEnv_orig = bsddb._db.DBEnv - bsddb._db.DB_orig = bsddb._db.DB - if bsddb.db.version() <= (4, 3) : - bsddb._db.DBSequence_orig = None - else : - bsddb._db.DBSequence_orig = bsddb._db.DBSequence - - def do_proxy_db_py3k(flag) : - flag2 = do_proxy_db_py3k.flag - do_proxy_db_py3k.flag = flag - if flag : - bsddb.DBEnv = bsddb.db.DBEnv = bsddb._db.DBEnv = DBEnv_py3k - bsddb.DB = bsddb.db.DB = bsddb._db.DB = DB_py3k - bsddb._db.DBSequence = DBSequence_py3k - else : - bsddb.DBEnv = bsddb.db.DBEnv = bsddb._db.DBEnv = bsddb._db.DBEnv_orig - bsddb.DB = bsddb.db.DB = bsddb._db.DB = bsddb._db.DB_orig - bsddb._db.DBSequence = bsddb._db.DBSequence_orig - return flag2 - - do_proxy_db_py3k.flag = False - do_proxy_db_py3k(True) - -try: - # For Pythons w/distutils pybsddb - from bsddb3 import db, dbtables, dbutils, dbshelve, \ - hashopen, btopen, rnopen, dbobj -except ImportError: - # For Python 2.3 - from bsddb import db, dbtables, dbutils, dbshelve, \ - hashopen, btopen, rnopen, dbobj - -try: - from bsddb3 import test_support -except ImportError: - if sys.version_info[0] < 3 : - from test import test_support - else : - from test import support as test_support - - -try: - if sys.version_info[0] < 3 : - from threading import Thread, currentThread - del Thread, currentThread - else : - from threading import Thread, current_thread - del Thread, current_thread - have_threads = True -except ImportError: - have_threads = False - -verbose = 0 -if 'verbose' in sys.argv: - verbose = 1 - sys.argv.remove('verbose') - -if 'silent' in sys.argv: # take care of old flag, just in case - verbose = 0 - sys.argv.remove('silent') - - -def print_versions(): - print - print '-=' * 38 - print db.DB_VERSION_STRING - print 'bsddb.db.version(): %s' % (db.version(), ) - if db.version() >= (5, 0) : - print 'bsddb.db.full_version(): %s' %repr(db.full_version()) - print 'bsddb.db.__version__: %s' % db.__version__ - print 'bsddb.db.cvsid: %s' % db.cvsid - - # Workaround for allowing generating an EGGs as a ZIP files. - suffix="__" - print 'py module: %s' % getattr(bsddb, "__file"+suffix) - print 'extension module: %s' % getattr(bsddb, "__file"+suffix) - - print 'python version: %s' % sys.version - print 'My pid: %s' % os.getpid() - print '-=' * 38 - - -def get_new_path(name) : - get_new_path.mutex.acquire() - try : - import os - path=os.path.join(get_new_path.prefix, - name+"_"+str(os.getpid())+"_"+str(get_new_path.num)) - get_new_path.num+=1 - finally : - get_new_path.mutex.release() - return path - -def get_new_environment_path() : - path=get_new_path("environment") - import os - try: - os.makedirs(path,mode=0700) - except os.error: - test_support.rmtree(path) - os.makedirs(path) - return path - -def get_new_database_path() : - path=get_new_path("database") - import os - if os.path.exists(path) : - os.remove(path) - return path - - -# This path can be overriden via "set_test_path_prefix()". -import os, os.path -get_new_path.prefix=os.path.join(os.environ.get("TMPDIR", - os.path.join(os.sep,"tmp")), "z-Berkeley_DB") -get_new_path.num=0 - -def get_test_path_prefix() : - return get_new_path.prefix - -def set_test_path_prefix(path) : - get_new_path.prefix=path - -def remove_test_path_directory() : - test_support.rmtree(get_new_path.prefix) - -if have_threads : - import threading - get_new_path.mutex=threading.Lock() - del threading -else : - class Lock(object) : - def acquire(self) : - pass - def release(self) : - pass - get_new_path.mutex=Lock() - del Lock - - - -class PrintInfoFakeTest(unittest.TestCase): - def testPrintVersions(self): - print_versions() - - -# This little hack is for when this module is run as main and all the -# other modules import it so they will still be able to get the right -# verbose setting. It's confusing but it works. -if sys.version_info[0] < 3 : - import test_all - test_all.verbose = verbose -else : - import sys - print >>sys.stderr, "Work to do!" - - -def suite(module_prefix='', timing_check=None): - test_modules = [ - 'test_associate', - 'test_basics', - 'test_dbenv', - 'test_db', - 'test_compare', - 'test_compat', - 'test_cursor_pget_bug', - 'test_dbobj', - 'test_dbshelve', - 'test_dbtables', - 'test_distributed_transactions', - 'test_early_close', - 'test_fileid', - 'test_get_none', - 'test_join', - 'test_lock', - 'test_misc', - 'test_pickle', - 'test_queue', - 'test_recno', - 'test_replication', - 'test_sequence', - 'test_thread', - ] - - alltests = unittest.TestSuite() - for name in test_modules: - #module = __import__(name) - # Do it this way so that suite may be called externally via - # python's Lib/test/test_bsddb3. - module = __import__(module_prefix+name, globals(), locals(), name) - - alltests.addTest(module.test_suite()) - if timing_check: - alltests.addTest(unittest.makeSuite(timing_check)) - return alltests - - -def test_suite(): - suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(PrintInfoFakeTest)) - return suite - - -if __name__ == '__main__': - print_versions() - unittest.main(defaultTest='suite') diff --git a/PythonLib/extra/bsddb/test/test_associate.py b/PythonLib/extra/bsddb/test/test_associate.py deleted file mode 100644 index 7a49e11e..00000000 --- a/PythonLib/extra/bsddb/test/test_associate.py +++ /dev/null @@ -1,465 +0,0 @@ -""" -TestCases for DB.associate. -""" - -import sys, os, string -import time -from pprint import pprint - -import unittest -from test_all import db, dbshelve, test_support, verbose, have_threads, \ - get_new_environment_path - - -#---------------------------------------------------------------------- - - -musicdata = { -1 : ("Bad English", "The Price Of Love", "Rock"), -2 : ("DNA featuring Suzanne Vega", "Tom's Diner", "Rock"), -3 : ("George Michael", "Praying For Time", "Rock"), -4 : ("Gloria Estefan", "Here We Are", "Rock"), -5 : ("Linda Ronstadt", "Don't Know Much", "Rock"), -6 : ("Michael Bolton", "How Am I Supposed To Live Without You", "Blues"), -7 : ("Paul Young", "Oh Girl", "Rock"), -8 : ("Paula Abdul", "Opposites Attract", "Rock"), -9 : ("Richard Marx", "Should've Known Better", "Rock"), -10: ("Rod Stewart", "Forever Young", "Rock"), -11: ("Roxette", "Dangerous", "Rock"), -12: ("Sheena Easton", "The Lover In Me", "Rock"), -13: ("Sinead O'Connor", "Nothing Compares 2 U", "Rock"), -14: ("Stevie B.", "Because I Love You", "Rock"), -15: ("Taylor Dayne", "Love Will Lead You Back", "Rock"), -16: ("The Bangles", "Eternal Flame", "Rock"), -17: ("Wilson Phillips", "Release Me", "Rock"), -18: ("Billy Joel", "Blonde Over Blue", "Rock"), -19: ("Billy Joel", "Famous Last Words", "Rock"), -20: ("Billy Joel", "Lullabye (Goodnight, My Angel)", "Rock"), -21: ("Billy Joel", "The River Of Dreams", "Rock"), -22: ("Billy Joel", "Two Thousand Years", "Rock"), -23: ("Janet Jackson", "Alright", "Rock"), -24: ("Janet Jackson", "Black Cat", "Rock"), -25: ("Janet Jackson", "Come Back To Me", "Rock"), -26: ("Janet Jackson", "Escapade", "Rock"), -27: ("Janet Jackson", "Love Will Never Do (Without You)", "Rock"), -28: ("Janet Jackson", "Miss You Much", "Rock"), -29: ("Janet Jackson", "Rhythm Nation", "Rock"), -30: ("Janet Jackson", "State Of The World", "Rock"), -31: ("Janet Jackson", "The Knowledge", "Rock"), -32: ("Spyro Gyra", "End of Romanticism", "Jazz"), -33: ("Spyro Gyra", "Heliopolis", "Jazz"), -34: ("Spyro Gyra", "Jubilee", "Jazz"), -35: ("Spyro Gyra", "Little Linda", "Jazz"), -36: ("Spyro Gyra", "Morning Dance", "Jazz"), -37: ("Spyro Gyra", "Song for Lorraine", "Jazz"), -38: ("Yes", "Owner Of A Lonely Heart", "Rock"), -39: ("Yes", "Rhythm Of Love", "Rock"), -40: ("Cusco", "Dream Catcher", "New Age"), -41: ("Cusco", "Geronimos Laughter", "New Age"), -42: ("Cusco", "Ghost Dance", "New Age"), -43: ("Blue Man Group", "Drumbone", "New Age"), -44: ("Blue Man Group", "Endless Column", "New Age"), -45: ("Blue Man Group", "Klein Mandelbrot", "New Age"), -46: ("Kenny G", "Silhouette", "Jazz"), -47: ("Sade", "Smooth Operator", "Jazz"), -48: ("David Arkenstone", "Papillon (On The Wings Of The Butterfly)", - "New Age"), -49: ("David Arkenstone", "Stepping Stars", "New Age"), -50: ("David Arkenstone", "Carnation Lily Lily Rose", "New Age"), -51: ("David Lanz", "Behind The Waterfall", "New Age"), -52: ("David Lanz", "Cristofori's Dream", "New Age"), -53: ("David Lanz", "Heartsounds", "New Age"), -54: ("David Lanz", "Leaves on the Seine", "New Age"), -99: ("unknown artist", "Unnamed song", "Unknown"), -} - -#---------------------------------------------------------------------- - -class AssociateErrorTestCase(unittest.TestCase): - def setUp(self): - self.filename = self.__class__.__name__ + '.db' - self.homeDir = get_new_environment_path() - self.env = db.DBEnv() - self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL) - - def tearDown(self): - self.env.close() - self.env = None - test_support.rmtree(self.homeDir) - - def test00_associateDBError(self): - if verbose: - print '\n', '-=' * 30 - print "Running %s.test00_associateDBError..." % \ - self.__class__.__name__ - - dupDB = db.DB(self.env) - dupDB.set_flags(db.DB_DUP) - dupDB.open(self.filename, "primary", db.DB_BTREE, db.DB_CREATE) - - secDB = db.DB(self.env) - secDB.open(self.filename, "secondary", db.DB_BTREE, db.DB_CREATE) - - # dupDB has been configured to allow duplicates, it can't - # associate with a secondary. Berkeley DB will return an error. - try: - def f(a,b): return a+b - dupDB.associate(secDB, f) - except db.DBError: - # good - secDB.close() - dupDB.close() - else: - secDB.close() - dupDB.close() - self.fail("DBError exception was expected") - - - -#---------------------------------------------------------------------- - - -class AssociateTestCase(unittest.TestCase): - keytype = '' - envFlags = 0 - dbFlags = 0 - - def setUp(self): - self.filename = self.__class__.__name__ + '.db' - self.homeDir = get_new_environment_path() - self.env = db.DBEnv() - self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL | - db.DB_INIT_LOCK | db.DB_THREAD | self.envFlags) - - def tearDown(self): - self.closeDB() - self.env.close() - self.env = None - test_support.rmtree(self.homeDir) - - def addDataToDB(self, d, txn=None): - for key, value in musicdata.items(): - if type(self.keytype) == type(''): - key = "%02d" % key - d.put(key, '|'.join(value), txn=txn) - - def createDB(self, txn=None): - self.cur = None - self.secDB = None - self.primary = db.DB(self.env) - self.primary.set_get_returns_none(2) - self.primary.open(self.filename, "primary", self.dbtype, - db.DB_CREATE | db.DB_THREAD | self.dbFlags, txn=txn) - - def closeDB(self): - if self.cur: - self.cur.close() - self.cur = None - if self.secDB: - self.secDB.close() - self.secDB = None - self.primary.close() - self.primary = None - - def getDB(self): - return self.primary - - - def _associateWithDB(self, getGenre): - self.createDB() - - self.secDB = db.DB(self.env) - self.secDB.set_flags(db.DB_DUP) - self.secDB.set_get_returns_none(2) - self.secDB.open(self.filename, "secondary", db.DB_BTREE, - db.DB_CREATE | db.DB_THREAD | self.dbFlags) - self.getDB().associate(self.secDB, getGenre) - - self.addDataToDB(self.getDB()) - - self.finish_test(self.secDB) - - def test01_associateWithDB(self): - if verbose: - print '\n', '-=' * 30 - print "Running %s.test01_associateWithDB..." % \ - self.__class__.__name__ - - return self._associateWithDB(self.getGenre) - - def _associateAfterDB(self, getGenre) : - self.createDB() - self.addDataToDB(self.getDB()) - - self.secDB = db.DB(self.env) - self.secDB.set_flags(db.DB_DUP) - self.secDB.open(self.filename, "secondary", db.DB_BTREE, - db.DB_CREATE | db.DB_THREAD | self.dbFlags) - - # adding the DB_CREATE flag will cause it to index existing records - self.getDB().associate(self.secDB, getGenre, db.DB_CREATE) - - self.finish_test(self.secDB) - - def test02_associateAfterDB(self): - if verbose: - print '\n', '-=' * 30 - print "Running %s.test02_associateAfterDB..." % \ - self.__class__.__name__ - - return self._associateAfterDB(self.getGenre) - - if db.version() >= (4, 6): - def test03_associateWithDB(self): - if verbose: - print '\n', '-=' * 30 - print "Running %s.test03_associateWithDB..." % \ - self.__class__.__name__ - - return self._associateWithDB(self.getGenreList) - - def test04_associateAfterDB(self): - if verbose: - print '\n', '-=' * 30 - print "Running %s.test04_associateAfterDB..." % \ - self.__class__.__name__ - - return self._associateAfterDB(self.getGenreList) - - - def finish_test(self, secDB, txn=None): - # 'Blues' should not be in the secondary database - vals = secDB.pget('Blues', txn=txn) - self.assertEqual(vals, None, vals) - - vals = secDB.pget('Unknown', txn=txn) - self.assertTrue(vals[0] == 99 or vals[0] == '99', vals) - vals[1].index('Unknown') - vals[1].index('Unnamed') - vals[1].index('unknown') - - if verbose: - print "Primary key traversal:" - self.cur = self.getDB().cursor(txn) - count = 0 - rec = self.cur.first() - while rec is not None: - if type(self.keytype) == type(''): - self.assertTrue(int(rec[0])) # for primary db, key is a number - else: - self.assertTrue(rec[0] and type(rec[0]) == type(0)) - count = count + 1 - if verbose: - print rec - rec = getattr(self.cur, "next")() - self.assertEqual(count, len(musicdata)) # all items accounted for - - - if verbose: - print "Secondary key traversal:" - self.cur = secDB.cursor(txn) - count = 0 - - # test cursor pget - vals = self.cur.pget('Unknown', flags=db.DB_LAST) - self.assertTrue(vals[1] == 99 or vals[1] == '99', vals) - self.assertEqual(vals[0], 'Unknown') - vals[2].index('Unknown') - vals[2].index('Unnamed') - vals[2].index('unknown') - - vals = self.cur.pget('Unknown', data='wrong value', flags=db.DB_GET_BOTH) - self.assertEqual(vals, None, vals) - - rec = self.cur.first() - self.assertEqual(rec[0], "Jazz") - while rec is not None: - count = count + 1 - if verbose: - print rec - rec = getattr(self.cur, "next")() - # all items accounted for EXCEPT for 1 with "Blues" genre - self.assertEqual(count, len(musicdata)-1) - - self.cur = None - - def getGenre(self, priKey, priData): - self.assertEqual(type(priData), type("")) - genre = priData.split('|')[2] - - if verbose: - print 'getGenre key: %r data: %r' % (priKey, priData) - - if genre == 'Blues': - return db.DB_DONOTINDEX - else: - return genre - - def getGenreList(self, priKey, PriData) : - v = self.getGenre(priKey, PriData) - if type(v) == type("") : - v = [v] - return v - - -#---------------------------------------------------------------------- - - -class AssociateHashTestCase(AssociateTestCase): - dbtype = db.DB_HASH - -class AssociateBTreeTestCase(AssociateTestCase): - dbtype = db.DB_BTREE - -class AssociateRecnoTestCase(AssociateTestCase): - dbtype = db.DB_RECNO - keytype = 0 - -#---------------------------------------------------------------------- - -class AssociateBTreeTxnTestCase(AssociateBTreeTestCase): - envFlags = db.DB_INIT_TXN - dbFlags = 0 - - def txn_finish_test(self, sDB, txn): - try: - self.finish_test(sDB, txn=txn) - finally: - if self.cur: - self.cur.close() - self.cur = None - if txn: - txn.commit() - - def test13_associate_in_transaction(self): - if verbose: - print '\n', '-=' * 30 - print "Running %s.test13_associateAutoCommit..." % \ - self.__class__.__name__ - - txn = self.env.txn_begin() - try: - self.createDB(txn=txn) - - self.secDB = db.DB(self.env) - self.secDB.set_flags(db.DB_DUP) - self.secDB.set_get_returns_none(2) - self.secDB.open(self.filename, "secondary", db.DB_BTREE, - db.DB_CREATE | db.DB_THREAD, txn=txn) - self.getDB().associate(self.secDB, self.getGenre, txn=txn) - - self.addDataToDB(self.getDB(), txn=txn) - except: - txn.abort() - raise - - self.txn_finish_test(self.secDB, txn=txn) - - -#---------------------------------------------------------------------- - -class ShelveAssociateTestCase(AssociateTestCase): - - def createDB(self): - self.primary = dbshelve.open(self.filename, - dbname="primary", - dbenv=self.env, - filetype=self.dbtype) - - def addDataToDB(self, d): - for key, value in musicdata.items(): - if type(self.keytype) == type(''): - key = "%02d" % key - d.put(key, value) # save the value as is this time - - - def getGenre(self, priKey, priData): - self.assertEqual(type(priData), type(())) - if verbose: - print 'getGenre key: %r data: %r' % (priKey, priData) - genre = priData[2] - if genre == 'Blues': - return db.DB_DONOTINDEX - else: - return genre - - -class ShelveAssociateHashTestCase(ShelveAssociateTestCase): - dbtype = db.DB_HASH - -class ShelveAssociateBTreeTestCase(ShelveAssociateTestCase): - dbtype = db.DB_BTREE - -class ShelveAssociateRecnoTestCase(ShelveAssociateTestCase): - dbtype = db.DB_RECNO - keytype = 0 - - -#---------------------------------------------------------------------- - -class ThreadedAssociateTestCase(AssociateTestCase): - - def addDataToDB(self, d): - t1 = Thread(target = self.writer1, - args = (d, )) - t2 = Thread(target = self.writer2, - args = (d, )) - - t1.setDaemon(True) - t2.setDaemon(True) - t1.start() - t2.start() - t1.join() - t2.join() - - def writer1(self, d): - for key, value in musicdata.items(): - if type(self.keytype) == type(''): - key = "%02d" % key - d.put(key, '|'.join(value)) - - def writer2(self, d): - for x in range(100, 600): - key = 'z%2d' % x - value = [key] * 4 - d.put(key, '|'.join(value)) - - -class ThreadedAssociateHashTestCase(ShelveAssociateTestCase): - dbtype = db.DB_HASH - -class ThreadedAssociateBTreeTestCase(ShelveAssociateTestCase): - dbtype = db.DB_BTREE - -class ThreadedAssociateRecnoTestCase(ShelveAssociateTestCase): - dbtype = db.DB_RECNO - keytype = 0 - - -#---------------------------------------------------------------------- - -def test_suite(): - suite = unittest.TestSuite() - - suite.addTest(unittest.makeSuite(AssociateErrorTestCase)) - - suite.addTest(unittest.makeSuite(AssociateHashTestCase)) - suite.addTest(unittest.makeSuite(AssociateBTreeTestCase)) - suite.addTest(unittest.makeSuite(AssociateRecnoTestCase)) - - suite.addTest(unittest.makeSuite(AssociateBTreeTxnTestCase)) - - suite.addTest(unittest.makeSuite(ShelveAssociateHashTestCase)) - suite.addTest(unittest.makeSuite(ShelveAssociateBTreeTestCase)) - suite.addTest(unittest.makeSuite(ShelveAssociateRecnoTestCase)) - - if have_threads: - suite.addTest(unittest.makeSuite(ThreadedAssociateHashTestCase)) - suite.addTest(unittest.makeSuite(ThreadedAssociateBTreeTestCase)) - suite.addTest(unittest.makeSuite(ThreadedAssociateRecnoTestCase)) - - return suite - - -if __name__ == '__main__': - unittest.main(defaultTest='test_suite') diff --git a/PythonLib/extra/bsddb/test/test_basics.py b/PythonLib/extra/bsddb/test/test_basics.py deleted file mode 100644 index 3c57be4f..00000000 --- a/PythonLib/extra/bsddb/test/test_basics.py +++ /dev/null @@ -1,1158 +0,0 @@ -""" -Basic TestCases for BTree and hash DBs, with and without a DBEnv, with -various DB flags, etc. -""" - -import os -import errno -import string -from pprint import pprint -import unittest -import time -import sys - -from test_all import db, test_support, verbose, get_new_environment_path, \ - get_new_database_path - -DASH = '-' - - -#---------------------------------------------------------------------- - -class VersionTestCase(unittest.TestCase): - def test00_version(self): - info = db.version() - if verbose: - print '\n', '-=' * 20 - print 'bsddb.db.version(): %s' % (info, ) - print db.DB_VERSION_STRING - print '-=' * 20 - self.assertEqual(info, (db.DB_VERSION_MAJOR, db.DB_VERSION_MINOR, - db.DB_VERSION_PATCH)) - -#---------------------------------------------------------------------- - -class BasicTestCase(unittest.TestCase): - dbtype = db.DB_UNKNOWN # must be set in derived class - cachesize = (0, 1024*1024, 1) - dbopenflags = 0 - dbsetflags = 0 - dbmode = 0660 - dbname = None - useEnv = 0 - envflags = 0 - envsetflags = 0 - - _numKeys = 1002 # PRIVATE. NOTE: must be an even value - - def setUp(self): - if self.useEnv: - self.homeDir=get_new_environment_path() - try: - self.env = db.DBEnv() - self.env.set_lg_max(1024*1024) - self.env.set_tx_max(30) - self._t = int(time.time()) - self.env.set_tx_timestamp(self._t) - self.env.set_flags(self.envsetflags, 1) - self.env.open(self.homeDir, self.envflags | db.DB_CREATE) - self.filename = "test" - # Yes, a bare except is intended, since we're re-raising the exc. - except: - test_support.rmtree(self.homeDir) - raise - else: - self.env = None - self.filename = get_new_database_path() - - # create and open the DB - self.d = db.DB(self.env) - if not self.useEnv : - self.d.set_cachesize(*self.cachesize) - cachesize = self.d.get_cachesize() - self.assertEqual(cachesize[0], self.cachesize[0]) - self.assertEqual(cachesize[2], self.cachesize[2]) - # Berkeley DB expands the cache 25% accounting overhead, - # if the cache is small. - self.assertEqual(125, int(100.0*cachesize[1]/self.cachesize[1])) - self.d.set_flags(self.dbsetflags) - if self.dbname: - self.d.open(self.filename, self.dbname, self.dbtype, - self.dbopenflags|db.DB_CREATE, self.dbmode) - else: - self.d.open(self.filename, # try out keyword args - mode = self.dbmode, - dbtype = self.dbtype, - flags = self.dbopenflags|db.DB_CREATE) - - if not self.useEnv: - self.assertRaises(db.DBInvalidArgError, - self.d.set_cachesize, *self.cachesize) - - self.populateDB() - - - def tearDown(self): - self.d.close() - if self.env is not None: - self.env.close() - test_support.rmtree(self.homeDir) - else: - os.remove(self.filename) - - - - def populateDB(self, _txn=None): - d = self.d - - for x in range(self._numKeys//2): - key = '%04d' % (self._numKeys - x) # insert keys in reverse order - data = self.makeData(key) - d.put(key, data, _txn) - - d.put('empty value', '', _txn) - - for x in range(self._numKeys//2-1): - key = '%04d' % x # and now some in forward order - data = self.makeData(key) - d.put(key, data, _txn) - - if _txn: - _txn.commit() - - num = len(d) - if verbose: - print "created %d records" % num - - - def makeData(self, key): - return DASH.join([key] * 5) - - - - #---------------------------------------- - - def test01_GetsAndPuts(self): - d = self.d - - if verbose: - print '\n', '-=' * 30 - print "Running %s.test01_GetsAndPuts..." % self.__class__.__name__ - - for key in ['0001', '0100', '0400', '0700', '0999']: - data = d.get(key) - if verbose: - print data - - self.assertEqual(d.get('0321'), '0321-0321-0321-0321-0321') - - # By default non-existent keys return None... - self.assertEqual(d.get('abcd'), None) - - # ...but they raise exceptions in other situations. Call - # set_get_returns_none() to change it. - try: - d.delete('abcd') - except db.DBNotFoundError, val: - if sys.version_info < (2, 6) : - self.assertEqual(val[0], db.DB_NOTFOUND) - else : - self.assertEqual(val.args[0], db.DB_NOTFOUND) - if verbose: print val - else: - self.fail("expected exception") - - - d.put('abcd', 'a new record') - self.assertEqual(d.get('abcd'), 'a new record') - - d.put('abcd', 'same key') - if self.dbsetflags & db.DB_DUP: - self.assertEqual(d.get('abcd'), 'a new record') - else: - self.assertEqual(d.get('abcd'), 'same key') - - - try: - d.put('abcd', 'this should fail', flags=db.DB_NOOVERWRITE) - except db.DBKeyExistError, val: - if sys.version_info < (2, 6) : - self.assertEqual(val[0], db.DB_KEYEXIST) - else : - self.assertEqual(val.args[0], db.DB_KEYEXIST) - if verbose: print val - else: - self.fail("expected exception") - - if self.dbsetflags & db.DB_DUP: - self.assertEqual(d.get('abcd'), 'a new record') - else: - self.assertEqual(d.get('abcd'), 'same key') - - - d.sync() - d.close() - del d - - self.d = db.DB(self.env) - if self.dbname: - self.d.open(self.filename, self.dbname) - else: - self.d.open(self.filename) - d = self.d - - self.assertEqual(d.get('0321'), '0321-0321-0321-0321-0321') - if self.dbsetflags & db.DB_DUP: - self.assertEqual(d.get('abcd'), 'a new record') - else: - self.assertEqual(d.get('abcd'), 'same key') - - rec = d.get_both('0555', '0555-0555-0555-0555-0555') - if verbose: - print rec - - self.assertEqual(d.get_both('0555', 'bad data'), None) - - # test default value - data = d.get('bad key', 'bad data') - self.assertEqual(data, 'bad data') - - # any object can pass through - data = d.get('bad key', self) - self.assertEqual(data, self) - - s = d.stat() - self.assertEqual(type(s), type({})) - if verbose: - print 'd.stat() returned this dictionary:' - pprint(s) - - - #---------------------------------------- - - def test02_DictionaryMethods(self): - d = self.d - - if verbose: - print '\n', '-=' * 30 - print "Running %s.test02_DictionaryMethods..." % \ - self.__class__.__name__ - - for key in ['0002', '0101', '0401', '0701', '0998']: - data = d[key] - self.assertEqual(data, self.makeData(key)) - if verbose: - print data - - self.assertEqual(len(d), self._numKeys) - keys = d.keys() - self.assertEqual(len(keys), self._numKeys) - self.assertEqual(type(keys), type([])) - - d['new record'] = 'a new record' - self.assertEqual(len(d), self._numKeys+1) - keys = d.keys() - self.assertEqual(len(keys), self._numKeys+1) - - d['new record'] = 'a replacement record' - self.assertEqual(len(d), self._numKeys+1) - keys = d.keys() - self.assertEqual(len(keys), self._numKeys+1) - - if verbose: - print "the first 10 keys are:" - pprint(keys[:10]) - - self.assertEqual(d['new record'], 'a replacement record') - -# We check also the positional parameter - self.assertEqual(d.has_key('0001', None), 1) -# We check also the keyword parameter - self.assertEqual(d.has_key('spam', txn=None), 0) - - items = d.items() - self.assertEqual(len(items), self._numKeys+1) - self.assertEqual(type(items), type([])) - self.assertEqual(type(items[0]), type(())) - self.assertEqual(len(items[0]), 2) - - if verbose: - print "the first 10 items are:" - pprint(items[:10]) - - values = d.values() - self.assertEqual(len(values), self._numKeys+1) - self.assertEqual(type(values), type([])) - - if verbose: - print "the first 10 values are:" - pprint(values[:10]) - - - #---------------------------------------- - - def test02b_SequenceMethods(self): - d = self.d - - for key in ['0002', '0101', '0401', '0701', '0998']: - data = d[key] - self.assertEqual(data, self.makeData(key)) - if verbose: - print data - - self.assertTrue(hasattr(d, "__contains__")) - self.assertTrue("0401" in d) - self.assertFalse("1234" in d) - - - #---------------------------------------- - - def test03_SimpleCursorStuff(self, get_raises_error=0, set_raises_error=0): - if verbose: - print '\n', '-=' * 30 - print "Running %s.test03_SimpleCursorStuff (get_error %s, set_error %s)..." % \ - (self.__class__.__name__, get_raises_error, set_raises_error) - - if self.env and self.dbopenflags & db.DB_AUTO_COMMIT: - txn = self.env.txn_begin() - else: - txn = None - c = self.d.cursor(txn=txn) - - rec = c.first() - count = 0 - while rec is not None: - count = count + 1 - if verbose and count % 100 == 0: - print rec - try: - rec = c.next() - except db.DBNotFoundError, val: - if get_raises_error: - if sys.version_info < (2, 6) : - self.assertEqual(val[0], db.DB_NOTFOUND) - else : - self.assertEqual(val.args[0], db.DB_NOTFOUND) - if verbose: print val - rec = None - else: - self.fail("unexpected DBNotFoundError") - self.assertEqual(c.get_current_size(), len(c.current()[1]), - "%s != len(%r)" % (c.get_current_size(), c.current()[1])) - - self.assertEqual(count, self._numKeys) - - - rec = c.last() - count = 0 - while rec is not None: - count = count + 1 - if verbose and count % 100 == 0: - print rec - try: - rec = c.prev() - except db.DBNotFoundError, val: - if get_raises_error: - if sys.version_info < (2, 6) : - self.assertEqual(val[0], db.DB_NOTFOUND) - else : - self.assertEqual(val.args[0], db.DB_NOTFOUND) - if verbose: print val - rec = None - else: - self.fail("unexpected DBNotFoundError") - - self.assertEqual(count, self._numKeys) - - rec = c.set('0505') - rec2 = c.current() - self.assertEqual(rec, rec2) - self.assertEqual(rec[0], '0505') - self.assertEqual(rec[1], self.makeData('0505')) - self.assertEqual(c.get_current_size(), len(rec[1])) - - # make sure we get empty values properly - rec = c.set('empty value') - self.assertEqual(rec[1], '') - self.assertEqual(c.get_current_size(), 0) - - try: - n = c.set('bad key') - except db.DBNotFoundError, val: - if sys.version_info < (2, 6) : - self.assertEqual(val[0], db.DB_NOTFOUND) - else : - self.assertEqual(val.args[0], db.DB_NOTFOUND) - if verbose: print val - else: - if set_raises_error: - self.fail("expected exception") - if n is not None: - self.fail("expected None: %r" % (n,)) - - rec = c.get_both('0404', self.makeData('0404')) - self.assertEqual(rec, ('0404', self.makeData('0404'))) - - try: - n = c.get_both('0404', 'bad data') - except db.DBNotFoundError, val: - if sys.version_info < (2, 6) : - self.assertEqual(val[0], db.DB_NOTFOUND) - else : - self.assertEqual(val.args[0], db.DB_NOTFOUND) - if verbose: print val - else: - if get_raises_error: - self.fail("expected exception") - if n is not None: - self.fail("expected None: %r" % (n,)) - - if self.d.get_type() == db.DB_BTREE: - rec = c.set_range('011') - if verbose: - print "searched for '011', found: ", rec - - rec = c.set_range('011',dlen=0,doff=0) - if verbose: - print "searched (partial) for '011', found: ", rec - if rec[1] != '': self.fail('expected empty data portion') - - ev = c.set_range('empty value') - if verbose: - print "search for 'empty value' returned", ev - if ev[1] != '': self.fail('empty value lookup failed') - - c.set('0499') - c.delete() - try: - rec = c.current() - except db.DBKeyEmptyError, val: - if get_raises_error: - if sys.version_info < (2, 6) : - self.assertEqual(val[0], db.DB_KEYEMPTY) - else : - self.assertEqual(val.args[0], db.DB_KEYEMPTY) - if verbose: print val - else: - self.fail("unexpected DBKeyEmptyError") - else: - if get_raises_error: - self.fail('DBKeyEmptyError exception expected') - - c.next() - c2 = c.dup(db.DB_POSITION) - self.assertEqual(c.current(), c2.current()) - - c2.put('', 'a new value', db.DB_CURRENT) - self.assertEqual(c.current(), c2.current()) - self.assertEqual(c.current()[1], 'a new value') - - c2.put('', 'er', db.DB_CURRENT, dlen=0, doff=5) - self.assertEqual(c2.current()[1], 'a newer value') - - c.close() - c2.close() - if txn: - txn.commit() - - # time to abuse the closed cursors and hope we don't crash - methods_to_test = { - 'current': (), - 'delete': (), - 'dup': (db.DB_POSITION,), - 'first': (), - 'get': (0,), - 'next': (), - 'prev': (), - 'last': (), - 'put':('', 'spam', db.DB_CURRENT), - 'set': ("0505",), - } - for method, args in methods_to_test.items(): - try: - if verbose: - print "attempting to use a closed cursor's %s method" % \ - method - # a bug may cause a NULL pointer dereference... - getattr(c, method)(*args) - except db.DBError, val: - if sys.version_info < (2, 6) : - self.assertEqual(val[0], 0) - else : - self.assertEqual(val.args[0], 0) - if verbose: print val - else: - self.fail("no exception raised when using a buggy cursor's" - "%s method" % method) - - # - # free cursor referencing a closed database, it should not barf: - # - oldcursor = self.d.cursor(txn=txn) - self.d.close() - - # this would originally cause a segfault when the cursor for a - # closed database was cleaned up. it should not anymore. - # SF pybsddb bug id 667343 - del oldcursor - - def test03b_SimpleCursorWithoutGetReturnsNone0(self): - # same test but raise exceptions instead of returning None - if verbose: - print '\n', '-=' * 30 - print "Running %s.test03b_SimpleCursorStuffWithoutGetReturnsNone..." % \ - self.__class__.__name__ - - old = self.d.set_get_returns_none(0) - self.assertEqual(old, 2) - self.test03_SimpleCursorStuff(get_raises_error=1, set_raises_error=1) - - def test03b_SimpleCursorWithGetReturnsNone1(self): - # same test but raise exceptions instead of returning None - if verbose: - print '\n', '-=' * 30 - print "Running %s.test03b_SimpleCursorStuffWithoutGetReturnsNone..." % \ - self.__class__.__name__ - - old = self.d.set_get_returns_none(1) - self.test03_SimpleCursorStuff(get_raises_error=0, set_raises_error=1) - - - def test03c_SimpleCursorGetReturnsNone2(self): - # same test but raise exceptions instead of returning None - if verbose: - print '\n', '-=' * 30 - print "Running %s.test03c_SimpleCursorStuffWithoutSetReturnsNone..." % \ - self.__class__.__name__ - - old = self.d.set_get_returns_none(1) - self.assertEqual(old, 2) - old = self.d.set_get_returns_none(2) - self.assertEqual(old, 1) - self.test03_SimpleCursorStuff(get_raises_error=0, set_raises_error=0) - - if db.version() >= (4, 6): - def test03d_SimpleCursorPriority(self) : - c = self.d.cursor() - c.set_priority(db.DB_PRIORITY_VERY_LOW) # Positional - self.assertEqual(db.DB_PRIORITY_VERY_LOW, c.get_priority()) - c.set_priority(priority=db.DB_PRIORITY_HIGH) # Keyword - self.assertEqual(db.DB_PRIORITY_HIGH, c.get_priority()) - c.close() - - #---------------------------------------- - - def test04_PartialGetAndPut(self): - d = self.d - if verbose: - print '\n', '-=' * 30 - print "Running %s.test04_PartialGetAndPut..." % \ - self.__class__.__name__ - - key = "partialTest" - data = "1" * 1000 + "2" * 1000 - d.put(key, data) - self.assertEqual(d.get(key), data) - self.assertEqual(d.get(key, dlen=20, doff=990), - ("1" * 10) + ("2" * 10)) - - d.put("partialtest2", ("1" * 30000) + "robin" ) - self.assertEqual(d.get("partialtest2", dlen=5, doff=30000), "robin") - - # There seems to be a bug in DB here... Commented out the test for - # now. - ##self.assertEqual(d.get("partialtest2", dlen=5, doff=30010), "") - - if self.dbsetflags != db.DB_DUP: - # Partial put with duplicate records requires a cursor - d.put(key, "0000", dlen=2000, doff=0) - self.assertEqual(d.get(key), "0000") - - d.put(key, "1111", dlen=1, doff=2) - self.assertEqual(d.get(key), "0011110") - - #---------------------------------------- - - def test05_GetSize(self): - d = self.d - if verbose: - print '\n', '-=' * 30 - print "Running %s.test05_GetSize..." % self.__class__.__name__ - - for i in range(1, 50000, 500): - key = "size%s" % i - #print "before ", i, - d.put(key, "1" * i) - #print "after", - self.assertEqual(d.get_size(key), i) - #print "done" - - #---------------------------------------- - - def test06_Truncate(self): - d = self.d - if verbose: - print '\n', '-=' * 30 - print "Running %s.test06_Truncate..." % self.__class__.__name__ - - d.put("abcde", "ABCDE"); - num = d.truncate() - self.assertTrue(num >= 1, "truncate returned <= 0 on non-empty database") - num = d.truncate() - self.assertEqual(num, 0, - "truncate on empty DB returned nonzero (%r)" % (num,)) - - #---------------------------------------- - - def test07_verify(self): - # Verify bug solved in 4.7.3pre8 - self.d.close() - d = db.DB(self.env) - d.verify(self.filename) - - - #---------------------------------------- - - if db.version() >= (4, 6): - def test08_exists(self) : - self.d.put("abcde", "ABCDE") - self.assertTrue(self.d.exists("abcde") == True, - "DB->exists() returns wrong value") - self.assertTrue(self.d.exists("x") == False, - "DB->exists() returns wrong value") - - #---------------------------------------- - - if db.version() >= (4, 7): - def test_compact(self) : - d = self.d - self.assertEqual(0, d.compact(flags=db.DB_FREELIST_ONLY)) - self.assertEqual(0, d.compact(flags=db.DB_FREELIST_ONLY)) - d.put("abcde", "ABCDE"); - d.put("bcde", "BCDE"); - d.put("abc", "ABC"); - d.put("monty", "python"); - d.delete("abc") - d.delete("bcde") - d.compact(start='abcde', stop='monty', txn=None, - compact_fillpercent=42, compact_pages=1, - compact_timeout=50000000, - flags=db.DB_FREELIST_ONLY|db.DB_FREE_SPACE) - - #---------------------------------------- - -#---------------------------------------------------------------------- - - -class BasicBTreeTestCase(BasicTestCase): - dbtype = db.DB_BTREE - - -class BasicHashTestCase(BasicTestCase): - dbtype = db.DB_HASH - - -class BasicBTreeWithThreadFlagTestCase(BasicTestCase): - dbtype = db.DB_BTREE - dbopenflags = db.DB_THREAD - - -class BasicHashWithThreadFlagTestCase(BasicTestCase): - dbtype = db.DB_HASH - dbopenflags = db.DB_THREAD - - -class BasicWithEnvTestCase(BasicTestCase): - dbopenflags = db.DB_THREAD - useEnv = 1 - envflags = db.DB_THREAD | db.DB_INIT_MPOOL | db.DB_INIT_LOCK - - #---------------------------------------- - - def test09_EnvRemoveAndRename(self): - if not self.env: - return - - if verbose: - print '\n', '-=' * 30 - print "Running %s.test09_EnvRemoveAndRename..." % self.__class__.__name__ - - # can't rename or remove an open DB - self.d.close() - - newname = self.filename + '.renamed' - self.env.dbrename(self.filename, None, newname) - self.env.dbremove(newname) - - #---------------------------------------- - -class BasicBTreeWithEnvTestCase(BasicWithEnvTestCase): - dbtype = db.DB_BTREE - - -class BasicHashWithEnvTestCase(BasicWithEnvTestCase): - dbtype = db.DB_HASH - - -#---------------------------------------------------------------------- - -class BasicTransactionTestCase(BasicTestCase): - if (sys.version_info < (2, 7)) or ((sys.version_info >= (3, 0)) and - (sys.version_info < (3, 2))) : - def assertIn(self, a, b, msg=None) : - return self.assertTrue(a in b, msg=msg) - - dbopenflags = db.DB_THREAD | db.DB_AUTO_COMMIT - useEnv = 1 - envflags = (db.DB_THREAD | db.DB_INIT_MPOOL | db.DB_INIT_LOCK | - db.DB_INIT_TXN) - envsetflags = db.DB_AUTO_COMMIT - - - def tearDown(self): - self.txn.commit() - BasicTestCase.tearDown(self) - - - def populateDB(self): - txn = self.env.txn_begin() - BasicTestCase.populateDB(self, _txn=txn) - - self.txn = self.env.txn_begin() - - - def test06_Transactions(self): - d = self.d - if verbose: - print '\n', '-=' * 30 - print "Running %s.test06_Transactions..." % self.__class__.__name__ - - self.assertEqual(d.get('new rec', txn=self.txn), None) - d.put('new rec', 'this is a new record', self.txn) - self.assertEqual(d.get('new rec', txn=self.txn), - 'this is a new record') - self.txn.abort() - self.assertEqual(d.get('new rec'), None) - - self.txn = self.env.txn_begin() - - self.assertEqual(d.get('new rec', txn=self.txn), None) - d.put('new rec', 'this is a new record', self.txn) - self.assertEqual(d.get('new rec', txn=self.txn), - 'this is a new record') - self.txn.commit() - self.assertEqual(d.get('new rec'), 'this is a new record') - - self.txn = self.env.txn_begin() - c = d.cursor(self.txn) - rec = c.first() - count = 0 - while rec is not None: - count = count + 1 - if verbose and count % 100 == 0: - print rec - rec = c.next() - self.assertEqual(count, self._numKeys+1) - - c.close() # Cursors *MUST* be closed before commit! - self.txn.commit() - - # flush pending updates - self.env.txn_checkpoint (0, 0, 0) - - statDict = self.env.log_stat(0); - self.assertIn('magic', statDict) - self.assertIn('version', statDict) - self.assertIn('cur_file', statDict) - self.assertIn('region_nowait', statDict) - - # must have at least one log file present: - logs = self.env.log_archive(db.DB_ARCH_ABS | db.DB_ARCH_LOG) - self.assertNotEqual(logs, None) - for log in logs: - if verbose: - print 'log file: ' + log - logs = self.env.log_archive(db.DB_ARCH_REMOVE) - self.assertTrue(not logs) - - self.txn = self.env.txn_begin() - - #---------------------------------------- - - if db.version() >= (4, 6): - def test08_exists(self) : - txn = self.env.txn_begin() - self.d.put("abcde", "ABCDE", txn=txn) - txn.commit() - txn = self.env.txn_begin() - self.assertTrue(self.d.exists("abcde", txn=txn) == True, - "DB->exists() returns wrong value") - self.assertTrue(self.d.exists("x", txn=txn) == False, - "DB->exists() returns wrong value") - txn.abort() - - #---------------------------------------- - - def test09_TxnTruncate(self): - d = self.d - if verbose: - print '\n', '-=' * 30 - print "Running %s.test09_TxnTruncate..." % self.__class__.__name__ - - d.put("abcde", "ABCDE"); - txn = self.env.txn_begin() - num = d.truncate(txn) - self.assertTrue(num >= 1, "truncate returned <= 0 on non-empty database") - num = d.truncate(txn) - self.assertEqual(num, 0, - "truncate on empty DB returned nonzero (%r)" % (num,)) - txn.commit() - - #---------------------------------------- - - def test10_TxnLateUse(self): - txn = self.env.txn_begin() - txn.abort() - try: - txn.abort() - except db.DBError, e: - pass - else: - raise RuntimeError, "DBTxn.abort() called after DB_TXN no longer valid w/o an exception" - - txn = self.env.txn_begin() - txn.commit() - try: - txn.commit() - except db.DBError, e: - pass - else: - raise RuntimeError, "DBTxn.commit() called after DB_TXN no longer valid w/o an exception" - - - #---------------------------------------- - - - if db.version() >= (4, 4): - def test_txn_name(self) : - txn=self.env.txn_begin() - self.assertEqual(txn.get_name(), "") - txn.set_name("XXYY") - self.assertEqual(txn.get_name(), "XXYY") - txn.set_name("") - self.assertEqual(txn.get_name(), "") - txn.abort() - - #---------------------------------------- - - - def test_txn_set_timeout(self) : - txn=self.env.txn_begin() - txn.set_timeout(1234567, db.DB_SET_LOCK_TIMEOUT) - txn.set_timeout(2345678, flags=db.DB_SET_TXN_TIMEOUT) - txn.abort() - - #---------------------------------------- - - def test_get_tx_max(self) : - self.assertEqual(self.env.get_tx_max(), 30) - - def test_get_tx_timestamp(self) : - self.assertEqual(self.env.get_tx_timestamp(), self._t) - - - -class BTreeTransactionTestCase(BasicTransactionTestCase): - dbtype = db.DB_BTREE - -class HashTransactionTestCase(BasicTransactionTestCase): - dbtype = db.DB_HASH - - - -#---------------------------------------------------------------------- - -class BTreeRecnoTestCase(BasicTestCase): - dbtype = db.DB_BTREE - dbsetflags = db.DB_RECNUM - - def test09_RecnoInBTree(self): - d = self.d - if verbose: - print '\n', '-=' * 30 - print "Running %s.test09_RecnoInBTree..." % self.__class__.__name__ - - rec = d.get(200) - self.assertEqual(type(rec), type(())) - self.assertEqual(len(rec), 2) - if verbose: - print "Record #200 is ", rec - - c = d.cursor() - c.set('0200') - num = c.get_recno() - self.assertEqual(type(num), type(1)) - if verbose: - print "recno of d['0200'] is ", num - - rec = c.current() - self.assertEqual(c.set_recno(num), rec) - - c.close() - - - -class BTreeRecnoWithThreadFlagTestCase(BTreeRecnoTestCase): - dbopenflags = db.DB_THREAD - -#---------------------------------------------------------------------- - -class BasicDUPTestCase(BasicTestCase): - dbsetflags = db.DB_DUP - - def test10_DuplicateKeys(self): - d = self.d - if verbose: - print '\n', '-=' * 30 - print "Running %s.test10_DuplicateKeys..." % \ - self.__class__.__name__ - - d.put("dup0", "before") - for x in "The quick brown fox jumped over the lazy dog.".split(): - d.put("dup1", x) - d.put("dup2", "after") - - data = d.get("dup1") - self.assertEqual(data, "The") - if verbose: - print data - - c = d.cursor() - rec = c.set("dup1") - self.assertEqual(rec, ('dup1', 'The')) - - next_reg = c.next() - self.assertEqual(next_reg, ('dup1', 'quick')) - - rec = c.set("dup1") - count = c.count() - self.assertEqual(count, 9) - - next_dup = c.next_dup() - self.assertEqual(next_dup, ('dup1', 'quick')) - - rec = c.set('dup1') - while rec is not None: - if verbose: - print rec - rec = c.next_dup() - - c.set('dup1') - rec = c.next_nodup() - self.assertNotEqual(rec[0], 'dup1') - if verbose: - print rec - - c.close() - - - -class BTreeDUPTestCase(BasicDUPTestCase): - dbtype = db.DB_BTREE - -class HashDUPTestCase(BasicDUPTestCase): - dbtype = db.DB_HASH - -class BTreeDUPWithThreadTestCase(BasicDUPTestCase): - dbtype = db.DB_BTREE - dbopenflags = db.DB_THREAD - -class HashDUPWithThreadTestCase(BasicDUPTestCase): - dbtype = db.DB_HASH - dbopenflags = db.DB_THREAD - - -#---------------------------------------------------------------------- - -class BasicMultiDBTestCase(BasicTestCase): - dbname = 'first' - - def otherType(self): - if self.dbtype == db.DB_BTREE: - return db.DB_HASH - else: - return db.DB_BTREE - - def test11_MultiDB(self): - d1 = self.d - if verbose: - print '\n', '-=' * 30 - print "Running %s.test11_MultiDB..." % self.__class__.__name__ - - d2 = db.DB(self.env) - d2.open(self.filename, "second", self.dbtype, - self.dbopenflags|db.DB_CREATE) - d3 = db.DB(self.env) - d3.open(self.filename, "third", self.otherType(), - self.dbopenflags|db.DB_CREATE) - - for x in "The quick brown fox jumped over the lazy dog".split(): - d2.put(x, self.makeData(x)) - - for x in string.letters: - d3.put(x, x*70) - - d1.sync() - d2.sync() - d3.sync() - d1.close() - d2.close() - d3.close() - - self.d = d1 = d2 = d3 = None - - self.d = d1 = db.DB(self.env) - d1.open(self.filename, self.dbname, flags = self.dbopenflags) - d2 = db.DB(self.env) - d2.open(self.filename, "second", flags = self.dbopenflags) - d3 = db.DB(self.env) - d3.open(self.filename, "third", flags = self.dbopenflags) - - c1 = d1.cursor() - c2 = d2.cursor() - c3 = d3.cursor() - - count = 0 - rec = c1.first() - while rec is not None: - count = count + 1 - if verbose and (count % 50) == 0: - print rec - rec = c1.next() - self.assertEqual(count, self._numKeys) - - count = 0 - rec = c2.first() - while rec is not None: - count = count + 1 - if verbose: - print rec - rec = c2.next() - self.assertEqual(count, 9) - - count = 0 - rec = c3.first() - while rec is not None: - count = count + 1 - if verbose: - print rec - rec = c3.next() - self.assertEqual(count, len(string.letters)) - - - c1.close() - c2.close() - c3.close() - - d2.close() - d3.close() - - - -# Strange things happen if you try to use Multiple DBs per file without a -# DBEnv with MPOOL and LOCKing... - -class BTreeMultiDBTestCase(BasicMultiDBTestCase): - dbtype = db.DB_BTREE - dbopenflags = db.DB_THREAD - useEnv = 1 - envflags = db.DB_THREAD | db.DB_INIT_MPOOL | db.DB_INIT_LOCK - -class HashMultiDBTestCase(BasicMultiDBTestCase): - dbtype = db.DB_HASH - dbopenflags = db.DB_THREAD - useEnv = 1 - envflags = db.DB_THREAD | db.DB_INIT_MPOOL | db.DB_INIT_LOCK - - -class PrivateObject(unittest.TestCase) : - def tearDown(self) : - del self.obj - - def test01_DefaultIsNone(self) : - self.assertEqual(self.obj.get_private(), None) - - def test02_assignment(self) : - a = "example of private object" - self.obj.set_private(a) - b = self.obj.get_private() - self.assertTrue(a is b) # Object identity - - def test03_leak_assignment(self) : - a = "example of private object" - refcount = sys.getrefcount(a) - self.obj.set_private(a) - self.assertEqual(refcount+1, sys.getrefcount(a)) - self.obj.set_private(None) - self.assertEqual(refcount, sys.getrefcount(a)) - - def test04_leak_GC(self) : - a = "example of private object" - refcount = sys.getrefcount(a) - self.obj.set_private(a) - self.obj = None - self.assertEqual(refcount, sys.getrefcount(a)) - -class DBEnvPrivateObject(PrivateObject) : - def setUp(self) : - self.obj = db.DBEnv() - -class DBPrivateObject(PrivateObject) : - def setUp(self) : - self.obj = db.DB() - -class CrashAndBurn(unittest.TestCase) : - #def test01_OpenCrash(self) : - # # See http://bugs.python.org/issue3307 - # self.assertRaises(db.DBInvalidArgError, db.DB, None, 65535) - - if db.version() < (4, 8) : - def test02_DBEnv_dealloc(self): - # http://bugs.python.org/issue3885 - import gc - self.assertRaises(db.DBInvalidArgError, db.DBEnv, ~db.DB_RPCCLIENT) - gc.collect() - - -#---------------------------------------------------------------------- -#---------------------------------------------------------------------- - -def test_suite(): - suite = unittest.TestSuite() - - suite.addTest(unittest.makeSuite(VersionTestCase)) - suite.addTest(unittest.makeSuite(BasicBTreeTestCase)) - suite.addTest(unittest.makeSuite(BasicHashTestCase)) - suite.addTest(unittest.makeSuite(BasicBTreeWithThreadFlagTestCase)) - suite.addTest(unittest.makeSuite(BasicHashWithThreadFlagTestCase)) - suite.addTest(unittest.makeSuite(BasicBTreeWithEnvTestCase)) - suite.addTest(unittest.makeSuite(BasicHashWithEnvTestCase)) - suite.addTest(unittest.makeSuite(BTreeTransactionTestCase)) - suite.addTest(unittest.makeSuite(HashTransactionTestCase)) - suite.addTest(unittest.makeSuite(BTreeRecnoTestCase)) - suite.addTest(unittest.makeSuite(BTreeRecnoWithThreadFlagTestCase)) - suite.addTest(unittest.makeSuite(BTreeDUPTestCase)) - suite.addTest(unittest.makeSuite(HashDUPTestCase)) - suite.addTest(unittest.makeSuite(BTreeDUPWithThreadTestCase)) - suite.addTest(unittest.makeSuite(HashDUPWithThreadTestCase)) - suite.addTest(unittest.makeSuite(BTreeMultiDBTestCase)) - suite.addTest(unittest.makeSuite(HashMultiDBTestCase)) - suite.addTest(unittest.makeSuite(DBEnvPrivateObject)) - suite.addTest(unittest.makeSuite(DBPrivateObject)) - suite.addTest(unittest.makeSuite(CrashAndBurn)) - - return suite - - -if __name__ == '__main__': - unittest.main(defaultTest='test_suite') diff --git a/PythonLib/extra/bsddb/test/test_compare.py b/PythonLib/extra/bsddb/test/test_compare.py deleted file mode 100644 index cb3b463e..00000000 --- a/PythonLib/extra/bsddb/test/test_compare.py +++ /dev/null @@ -1,447 +0,0 @@ -""" -TestCases for python DB duplicate and Btree key comparison function. -""" - -import sys, os, re -import test_all -from cStringIO import StringIO - -import unittest - -from test_all import db, dbshelve, test_support, \ - get_new_environment_path, get_new_database_path - - -# Needed for python 3. "cmp" vanished in 3.0.1 -def cmp(a, b) : - if a==b : return 0 - if a= (3,0)) and - (sys.version_info < (3, 2))) : - def assertLess(self, a, b, msg=None) : - return self.assertTrue(a= (3,0)) and - (sys.version_info < (3, 2))) : - def assertLess(self, a, b, msg=None) : - return self.assertTrue(a last!') - f.previous() - break - if verbose: - print rec - - self.assertTrue(f.has_key('f'), 'Error, missing key!') - - # test that set_location() returns the next nearest key, value - # on btree databases and raises KeyError on others. - if factory == btopen: - e = f.set_location('e') - if e != ('f', 'Python'): - self.fail('wrong key,value returned: '+repr(e)) - else: - try: - e = f.set_location('e') - except KeyError: - pass - else: - self.fail("set_location on non-existent key did not raise KeyError") - - f.sync() - f.close() - # truth test - try: - if f: - if verbose: print "truth test: true" - else: - if verbose: print "truth test: false" - except db.DBError: - pass - else: - self.fail("Exception expected") - - del f - - if verbose: - print 'modification...' - f = factory(self.filename, 'w') - f['d'] = 'discovered' - - if verbose: - print 'access...' - for key in f.keys(): - word = f[key] - if verbose: - print word - - def noRec(f): - rec = f['no such key'] - self.assertRaises(KeyError, noRec, f) - - def badKey(f): - rec = f[15] - self.assertRaises(TypeError, badKey, f) - - f.close() - - -#---------------------------------------------------------------------- - - -def test_suite(): - return unittest.makeSuite(CompatibilityTestCase) - - -if __name__ == '__main__': - unittest.main(defaultTest='test_suite') diff --git a/PythonLib/extra/bsddb/test/test_cursor_pget_bug.py b/PythonLib/extra/bsddb/test/test_cursor_pget_bug.py deleted file mode 100644 index 22d3dc1c..00000000 --- a/PythonLib/extra/bsddb/test/test_cursor_pget_bug.py +++ /dev/null @@ -1,54 +0,0 @@ -import unittest -import os, glob - -from test_all import db, test_support, get_new_environment_path, \ - get_new_database_path - -#---------------------------------------------------------------------- - -class pget_bugTestCase(unittest.TestCase): - """Verify that cursor.pget works properly""" - db_name = 'test-cursor_pget.db' - - def setUp(self): - self.homeDir = get_new_environment_path() - self.env = db.DBEnv() - self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL) - self.primary_db = db.DB(self.env) - self.primary_db.open(self.db_name, 'primary', db.DB_BTREE, db.DB_CREATE) - self.secondary_db = db.DB(self.env) - self.secondary_db.set_flags(db.DB_DUP) - self.secondary_db.open(self.db_name, 'secondary', db.DB_BTREE, db.DB_CREATE) - self.primary_db.associate(self.secondary_db, lambda key, data: data) - self.primary_db.put('salad', 'eggs') - self.primary_db.put('spam', 'ham') - self.primary_db.put('omelet', 'eggs') - - - def tearDown(self): - self.secondary_db.close() - self.primary_db.close() - self.env.close() - del self.secondary_db - del self.primary_db - del self.env - test_support.rmtree(self.homeDir) - - def test_pget(self): - cursor = self.secondary_db.cursor() - - self.assertEqual(('eggs', 'salad', 'eggs'), cursor.pget(key='eggs', flags=db.DB_SET)) - self.assertEqual(('eggs', 'omelet', 'eggs'), cursor.pget(db.DB_NEXT_DUP)) - self.assertEqual(None, cursor.pget(db.DB_NEXT_DUP)) - - self.assertEqual(('ham', 'spam', 'ham'), cursor.pget('ham', 'spam', flags=db.DB_SET)) - self.assertEqual(None, cursor.pget(db.DB_NEXT_DUP)) - - cursor.close() - - -def test_suite(): - return unittest.makeSuite(pget_bugTestCase) - -if __name__ == '__main__': - unittest.main(defaultTest='test_suite') diff --git a/PythonLib/extra/bsddb/test/test_db.py b/PythonLib/extra/bsddb/test/test_db.py deleted file mode 100644 index 2bc109f1..00000000 --- a/PythonLib/extra/bsddb/test/test_db.py +++ /dev/null @@ -1,163 +0,0 @@ -import unittest -import os, glob - -from test_all import db, test_support, get_new_environment_path, \ - get_new_database_path - -#---------------------------------------------------------------------- - -class DB(unittest.TestCase): - def setUp(self): - self.path = get_new_database_path() - self.db = db.DB() - - def tearDown(self): - self.db.close() - del self.db - test_support.unlink(self.path) - -class DB_general(DB) : - def test_get_open_flags(self) : - self.db.open(self.path, dbtype=db.DB_HASH, flags = db.DB_CREATE) - self.assertEqual(db.DB_CREATE, self.db.get_open_flags()) - - def test_get_open_flags2(self) : - self.db.open(self.path, dbtype=db.DB_HASH, flags = db.DB_CREATE | - db.DB_THREAD) - self.assertEqual(db.DB_CREATE | db.DB_THREAD, self.db.get_open_flags()) - - def test_get_dbname_filename(self) : - self.db.open(self.path, dbtype=db.DB_HASH, flags = db.DB_CREATE) - self.assertEqual((self.path, None), self.db.get_dbname()) - - def test_get_dbname_filename_database(self) : - name = "jcea-random-name" - self.db.open(self.path, dbname=name, dbtype=db.DB_HASH, - flags = db.DB_CREATE) - self.assertEqual((self.path, name), self.db.get_dbname()) - - def test_bt_minkey(self) : - for i in [17, 108, 1030] : - self.db.set_bt_minkey(i) - self.assertEqual(i, self.db.get_bt_minkey()) - - def test_lorder(self) : - self.db.set_lorder(1234) - self.assertEqual(1234, self.db.get_lorder()) - self.db.set_lorder(4321) - self.assertEqual(4321, self.db.get_lorder()) - self.assertRaises(db.DBInvalidArgError, self.db.set_lorder, 9182) - - if db.version() >= (4, 6) : - def test_priority(self) : - flags = [db.DB_PRIORITY_VERY_LOW, db.DB_PRIORITY_LOW, - db.DB_PRIORITY_DEFAULT, db.DB_PRIORITY_HIGH, - db.DB_PRIORITY_VERY_HIGH] - for flag in flags : - self.db.set_priority(flag) - self.assertEqual(flag, self.db.get_priority()) - - def test_get_transactional(self) : - self.assertFalse(self.db.get_transactional()) - self.db.open(self.path, dbtype=db.DB_HASH, flags = db.DB_CREATE) - self.assertFalse(self.db.get_transactional()) - -class DB_hash(DB) : - def test_h_ffactor(self) : - for ffactor in [4, 16, 256] : - self.db.set_h_ffactor(ffactor) - self.assertEqual(ffactor, self.db.get_h_ffactor()) - - def test_h_nelem(self) : - for nelem in [1, 2, 4] : - nelem = nelem*1024*1024 # Millions - self.db.set_h_nelem(nelem) - self.assertEqual(nelem, self.db.get_h_nelem()) - - def test_pagesize(self) : - for i in xrange(9, 17) : # From 512 to 65536 - i = 1<= (4, 7) : - def test_lk_partitions(self) : - for i in [10, 20, 40] : - self.env.set_lk_partitions(i) - self.assertEqual(i, self.env.get_lk_partitions()) - - def test_getset_intermediate_dir_mode(self) : - self.assertEqual(None, self.env.get_intermediate_dir_mode()) - for mode in ["rwx------", "rw-rw-rw-", "rw-r--r--"] : - self.env.set_intermediate_dir_mode(mode) - self.assertEqual(mode, self.env.get_intermediate_dir_mode()) - self.assertRaises(db.DBInvalidArgError, - self.env.set_intermediate_dir_mode, "abcde") - - if db.version() >= (4, 6) : - def test_thread(self) : - for i in [16, 100, 1000] : - self.env.set_thread_count(i) - self.assertEqual(i, self.env.get_thread_count()) - - def test_cache_max(self) : - for size in [64, 128] : - size = size*1024*1024 # Megabytes - self.env.set_cache_max(0, size) - size2 = self.env.get_cache_max() - self.assertEqual(0, size2[0]) - self.assertTrue(size <= size2[1]) - self.assertTrue(2*size > size2[1]) - - if db.version() >= (4, 4) : - def test_mutex_stat(self) : - self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL | - db.DB_INIT_LOCK) - stat = self.env.mutex_stat() - self.assertTrue("mutex_inuse_max" in stat) - - def test_lg_filemode(self) : - for i in [0600, 0660, 0666] : - self.env.set_lg_filemode(i) - self.assertEqual(i, self.env.get_lg_filemode()) - - def test_mp_max_openfd(self) : - for i in [17, 31, 42] : - self.env.set_mp_max_openfd(i) - self.assertEqual(i, self.env.get_mp_max_openfd()) - - def test_mp_max_write(self) : - for i in [100, 200, 300] : - for j in [1, 2, 3] : - j *= 1000000 - self.env.set_mp_max_write(i, j) - v=self.env.get_mp_max_write() - self.assertEqual((i, j), v) - - def test_invalid_txn(self) : - # This environment doesn't support transactions - self.assertRaises(db.DBInvalidArgError, self.env.txn_begin) - - def test_mp_mmapsize(self) : - for i in [16, 32, 64] : - i *= 1024*1024 - self.env.set_mp_mmapsize(i) - self.assertEqual(i, self.env.get_mp_mmapsize()) - - def test_tmp_dir(self) : - for i in ["a", "bb", "ccc"] : - self.env.set_tmp_dir(i) - self.assertEqual(i, self.env.get_tmp_dir()) - - def test_flags(self) : - self.env.set_flags(db.DB_AUTO_COMMIT, 1) - self.assertEqual(db.DB_AUTO_COMMIT, self.env.get_flags()) - self.env.set_flags(db.DB_TXN_NOSYNC, 1) - self.assertEqual(db.DB_AUTO_COMMIT | db.DB_TXN_NOSYNC, - self.env.get_flags()) - self.env.set_flags(db.DB_AUTO_COMMIT, 0) - self.assertEqual(db.DB_TXN_NOSYNC, self.env.get_flags()) - self.env.set_flags(db.DB_TXN_NOSYNC, 0) - self.assertEqual(0, self.env.get_flags()) - - def test_lk_max_objects(self) : - for i in [1000, 2000, 3000] : - self.env.set_lk_max_objects(i) - self.assertEqual(i, self.env.get_lk_max_objects()) - - def test_lk_max_locks(self) : - for i in [1000, 2000, 3000] : - self.env.set_lk_max_locks(i) - self.assertEqual(i, self.env.get_lk_max_locks()) - - def test_lk_max_lockers(self) : - for i in [1000, 2000, 3000] : - self.env.set_lk_max_lockers(i) - self.assertEqual(i, self.env.get_lk_max_lockers()) - - def test_lg_regionmax(self) : - for i in [128, 256, 1000] : - i = i*1024*1024 - self.env.set_lg_regionmax(i) - j = self.env.get_lg_regionmax() - self.assertTrue(i <= j) - self.assertTrue(2*i > j) - - def test_lk_detect(self) : - flags= [db.DB_LOCK_DEFAULT, db.DB_LOCK_EXPIRE, db.DB_LOCK_MAXLOCKS, - db.DB_LOCK_MINLOCKS, db.DB_LOCK_MINWRITE, - db.DB_LOCK_OLDEST, db.DB_LOCK_RANDOM, db.DB_LOCK_YOUNGEST] - - flags.append(db.DB_LOCK_MAXWRITE) - - for i in flags : - self.env.set_lk_detect(i) - self.assertEqual(i, self.env.get_lk_detect()) - - def test_lg_dir(self) : - for i in ["a", "bb", "ccc", "dddd"] : - self.env.set_lg_dir(i) - self.assertEqual(i, self.env.get_lg_dir()) - - def test_lg_bsize(self) : - log_size = 70*1024 - self.env.set_lg_bsize(log_size) - self.assertTrue(self.env.get_lg_bsize() >= log_size) - self.assertTrue(self.env.get_lg_bsize() < 4*log_size) - self.env.set_lg_bsize(4*log_size) - self.assertTrue(self.env.get_lg_bsize() >= 4*log_size) - - def test_setget_data_dirs(self) : - dirs = ("a", "b", "c", "d") - for i in dirs : - self.env.set_data_dir(i) - self.assertEqual(dirs, self.env.get_data_dirs()) - - def test_setget_cachesize(self) : - cachesize = (0, 512*1024*1024, 3) - self.env.set_cachesize(*cachesize) - self.assertEqual(cachesize, self.env.get_cachesize()) - - cachesize = (0, 1*1024*1024, 5) - self.env.set_cachesize(*cachesize) - cachesize2 = self.env.get_cachesize() - self.assertEqual(cachesize[0], cachesize2[0]) - self.assertEqual(cachesize[2], cachesize2[2]) - # Berkeley DB expands the cache 25% accounting overhead, - # if the cache is small. - self.assertEqual(125, int(100.0*cachesize2[1]/cachesize[1])) - - # You can not change configuration after opening - # the environment. - self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL) - cachesize = (0, 2*1024*1024, 1) - self.assertRaises(db.DBInvalidArgError, - self.env.set_cachesize, *cachesize) - cachesize3 = self.env.get_cachesize() - self.assertEqual(cachesize2[0], cachesize3[0]) - self.assertEqual(cachesize2[2], cachesize3[2]) - # In Berkeley DB 5.1, the cachesize can change when opening the Env - self.assertTrue(cachesize2[1] <= cachesize3[1]) - - def test_set_cachesize_dbenv_db(self) : - # You can not configure the cachesize using - # the database handle, if you are using an environment. - d = db.DB(self.env) - self.assertRaises(db.DBInvalidArgError, - d.set_cachesize, 0, 1024*1024, 1) - - def test_setget_shm_key(self) : - shm_key=137 - self.env.set_shm_key(shm_key) - self.assertEqual(shm_key, self.env.get_shm_key()) - self.env.set_shm_key(shm_key+1) - self.assertEqual(shm_key+1, self.env.get_shm_key()) - - # You can not change configuration after opening - # the environment. - self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL) - # If we try to reconfigure cache after opening the - # environment, core dump. - self.assertRaises(db.DBInvalidArgError, - self.env.set_shm_key, shm_key) - self.assertEqual(shm_key+1, self.env.get_shm_key()) - - if db.version() >= (4, 4) : - def test_mutex_setget_max(self) : - v = self.env.mutex_get_max() - v2 = v*2+1 - - self.env.mutex_set_max(v2) - self.assertEqual(v2, self.env.mutex_get_max()) - - self.env.mutex_set_max(v) - self.assertEqual(v, self.env.mutex_get_max()) - - # You can not change configuration after opening - # the environment. - self.env.open(self.homeDir, db.DB_CREATE) - self.assertRaises(db.DBInvalidArgError, - self.env.mutex_set_max, v2) - - def test_mutex_setget_increment(self) : - v = self.env.mutex_get_increment() - v2 = 127 - - self.env.mutex_set_increment(v2) - self.assertEqual(v2, self.env.mutex_get_increment()) - - self.env.mutex_set_increment(v) - self.assertEqual(v, self.env.mutex_get_increment()) - - # You can not change configuration after opening - # the environment. - self.env.open(self.homeDir, db.DB_CREATE) - self.assertRaises(db.DBInvalidArgError, - self.env.mutex_set_increment, v2) - - def test_mutex_setget_tas_spins(self) : - self.env.mutex_set_tas_spins(0) # Default = BDB decides - v = self.env.mutex_get_tas_spins() - v2 = v*2+1 - - self.env.mutex_set_tas_spins(v2) - self.assertEqual(v2, self.env.mutex_get_tas_spins()) - - self.env.mutex_set_tas_spins(v) - self.assertEqual(v, self.env.mutex_get_tas_spins()) - - # In this case, you can change configuration - # after opening the environment. - self.env.open(self.homeDir, db.DB_CREATE) - self.env.mutex_set_tas_spins(v2) - - def test_mutex_setget_align(self) : - v = self.env.mutex_get_align() - v2 = 64 - if v == 64 : - v2 = 128 - - self.env.mutex_set_align(v2) - self.assertEqual(v2, self.env.mutex_get_align()) - - # Requires a nonzero power of two - self.assertRaises(db.DBInvalidArgError, - self.env.mutex_set_align, 0) - self.assertRaises(db.DBInvalidArgError, - self.env.mutex_set_align, 17) - - self.env.mutex_set_align(2*v2) - self.assertEqual(2*v2, self.env.mutex_get_align()) - - # You can not change configuration after opening - # the environment. - self.env.open(self.homeDir, db.DB_CREATE) - self.assertRaises(db.DBInvalidArgError, - self.env.mutex_set_align, v2) - - -class DBEnv_log(DBEnv) : - def setUp(self): - DBEnv.setUp(self) - self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL | db.DB_INIT_LOG) - - def test_log_file(self) : - log_file = self.env.log_file((1, 1)) - self.assertEqual("log.0000000001", log_file[-14:]) - - if db.version() >= (4, 4) : - # The version with transactions is checked in other test object - def test_log_printf(self) : - msg = "This is a test..." - self.env.log_printf(msg) - logc = self.env.log_cursor() - self.assertTrue(msg in (logc.last()[1])) - - if db.version() >= (4, 7) : - def test_log_config(self) : - self.env.log_set_config(db.DB_LOG_DSYNC | db.DB_LOG_ZERO, 1) - self.assertTrue(self.env.log_get_config(db.DB_LOG_DSYNC)) - self.assertTrue(self.env.log_get_config(db.DB_LOG_ZERO)) - self.env.log_set_config(db.DB_LOG_ZERO, 0) - self.assertTrue(self.env.log_get_config(db.DB_LOG_DSYNC)) - self.assertFalse(self.env.log_get_config(db.DB_LOG_ZERO)) - - -class DBEnv_log_txn(DBEnv) : - def setUp(self): - DBEnv.setUp(self) - self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL | - db.DB_INIT_LOG | db.DB_INIT_TXN) - - if (db.version() >= (4, 5)) and (db.version() < (5, 2)) : - def test_tx_max(self) : - txns=[] - def tx() : - for i in xrange(self.env.get_tx_max()) : - txns.append(self.env.txn_begin()) - - tx() - self.assertRaises(MemoryError, tx) - - # Abort the transactions before garbage collection, - # to avoid "warnings". - for i in txns : - i.abort() - - if db.version() >= (4, 4) : - # The version without transactions is checked in other test object - def test_log_printf(self) : - msg = "This is a test..." - txn = self.env.txn_begin() - self.env.log_printf(msg, txn=txn) - txn.commit() - logc = self.env.log_cursor() - logc.last() # Skip the commit - self.assertTrue(msg in (logc.prev()[1])) - - msg = "This is another test..." - txn = self.env.txn_begin() - self.env.log_printf(msg, txn=txn) - txn.abort() # Do not store the new message - logc.last() # Skip the abort - self.assertTrue(msg not in (logc.prev()[1])) - - msg = "This is a third test..." - txn = self.env.txn_begin() - self.env.log_printf(msg, txn=txn) - txn.commit() # Do not store the new message - logc.last() # Skip the commit - self.assertTrue(msg in (logc.prev()[1])) - - -class DBEnv_memp(DBEnv): - def setUp(self): - DBEnv.setUp(self) - self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL | db.DB_INIT_LOG) - self.db = db.DB(self.env) - self.db.open("test", db.DB_HASH, db.DB_CREATE, 0660) - - def tearDown(self): - self.db.close() - del self.db - DBEnv.tearDown(self) - - def test_memp_1_trickle(self) : - self.db.put("hi", "bye") - self.assertTrue(self.env.memp_trickle(100) > 0) - -# Preserve the order, do "memp_trickle" test first - def test_memp_2_sync(self) : - self.db.put("hi", "bye") - self.env.memp_sync() # Full flush - # Nothing to do... - self.assertTrue(self.env.memp_trickle(100) == 0) - - self.db.put("hi", "bye2") - self.env.memp_sync((1, 0)) # NOP, probably - # Something to do... or not - self.assertTrue(self.env.memp_trickle(100) >= 0) - - self.db.put("hi", "bye3") - self.env.memp_sync((123, 99)) # Full flush - # Nothing to do... - self.assertTrue(self.env.memp_trickle(100) == 0) - - def test_memp_stat_1(self) : - stats = self.env.memp_stat() # No param - self.assertTrue(len(stats)==2) - self.assertTrue("cache_miss" in stats[0]) - stats = self.env.memp_stat(db.DB_STAT_CLEAR) # Positional param - self.assertTrue("cache_miss" in stats[0]) - stats = self.env.memp_stat(flags=0) # Keyword param - self.assertTrue("cache_miss" in stats[0]) - - def test_memp_stat_2(self) : - stats=self.env.memp_stat()[1] - self.assertTrue(len(stats))==1 - self.assertTrue("test" in stats) - self.assertTrue("page_in" in stats["test"]) - -class DBEnv_logcursor(DBEnv): - def setUp(self): - DBEnv.setUp(self) - self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL | - db.DB_INIT_LOG | db.DB_INIT_TXN) - txn = self.env.txn_begin() - self.db = db.DB(self.env) - self.db.open("test", db.DB_HASH, db.DB_CREATE, 0660, txn=txn) - txn.commit() - for i in ["2", "8", "20"] : - txn = self.env.txn_begin() - self.db.put(key = i, data = i*int(i), txn=txn) - txn.commit() - - def tearDown(self): - self.db.close() - del self.db - DBEnv.tearDown(self) - - def _check_return(self, value) : - self.assertTrue(isinstance(value, tuple)) - self.assertEqual(len(value), 2) - self.assertTrue(isinstance(value[0], tuple)) - self.assertEqual(len(value[0]), 2) - self.assertTrue(isinstance(value[0][0], int)) - self.assertTrue(isinstance(value[0][1], int)) - self.assertTrue(isinstance(value[1], str)) - - # Preserve test order - def test_1_first(self) : - logc = self.env.log_cursor() - v = logc.first() - self._check_return(v) - self.assertTrue((1, 1) < v[0]) - self.assertTrue(len(v[1])>0) - - def test_2_last(self) : - logc = self.env.log_cursor() - lsn_first = logc.first()[0] - v = logc.last() - self._check_return(v) - self.assertTrue(lsn_first < v[0]) - - def test_3_next(self) : - logc = self.env.log_cursor() - lsn_last = logc.last()[0] - self.assertEqual(logc.next(), None) - lsn_first = logc.first()[0] - v = logc.next() - self._check_return(v) - self.assertTrue(lsn_first < v[0]) - self.assertTrue(lsn_last > v[0]) - - v2 = logc.next() - self.assertTrue(v2[0] > v[0]) - self.assertTrue(lsn_last > v2[0]) - - v3 = logc.next() - self.assertTrue(v3[0] > v2[0]) - self.assertTrue(lsn_last > v3[0]) - - def test_4_prev(self) : - logc = self.env.log_cursor() - lsn_first = logc.first()[0] - self.assertEqual(logc.prev(), None) - lsn_last = logc.last()[0] - v = logc.prev() - self._check_return(v) - self.assertTrue(lsn_first < v[0]) - self.assertTrue(lsn_last > v[0]) - - v2 = logc.prev() - self.assertTrue(v2[0] < v[0]) - self.assertTrue(lsn_first < v2[0]) - - v3 = logc.prev() - self.assertTrue(v3[0] < v2[0]) - self.assertTrue(lsn_first < v3[0]) - - def test_5_current(self) : - logc = self.env.log_cursor() - logc.first() - v = logc.next() - self.assertEqual(v, logc.current()) - - def test_6_set(self) : - logc = self.env.log_cursor() - logc.first() - v = logc.next() - self.assertNotEqual(v, logc.next()) - self.assertNotEqual(v, logc.next()) - self.assertEqual(v, logc.set(v[0])) - - def test_explicit_close(self) : - logc = self.env.log_cursor() - logc.close() - self.assertRaises(db.DBCursorClosedError, logc.next) - - def test_implicit_close(self) : - logc = [self.env.log_cursor() for i in xrange(10)] - self.env.close() # This close should close too all its tree - for i in logc : - self.assertRaises(db.DBCursorClosedError, i.next) - -def test_suite(): - suite = unittest.TestSuite() - - suite.addTest(unittest.makeSuite(DBEnv_general)) - suite.addTest(unittest.makeSuite(DBEnv_memp)) - suite.addTest(unittest.makeSuite(DBEnv_logcursor)) - suite.addTest(unittest.makeSuite(DBEnv_log)) - suite.addTest(unittest.makeSuite(DBEnv_log_txn)) - - return suite - -if __name__ == '__main__': - unittest.main(defaultTest='test_suite') diff --git a/PythonLib/extra/bsddb/test/test_dbobj.py b/PythonLib/extra/bsddb/test/test_dbobj.py deleted file mode 100644 index e301a5ad..00000000 --- a/PythonLib/extra/bsddb/test/test_dbobj.py +++ /dev/null @@ -1,70 +0,0 @@ - -import os, string -import unittest - -from test_all import db, dbobj, test_support, get_new_environment_path, \ - get_new_database_path - -#---------------------------------------------------------------------- - -class dbobjTestCase(unittest.TestCase): - """Verify that dbobj.DB and dbobj.DBEnv work properly""" - db_name = 'test-dbobj.db' - - def setUp(self): - self.homeDir = get_new_environment_path() - - def tearDown(self): - if hasattr(self, 'db'): - del self.db - if hasattr(self, 'env'): - del self.env - test_support.rmtree(self.homeDir) - - def test01_both(self): - class TestDBEnv(dbobj.DBEnv): pass - class TestDB(dbobj.DB): - def put(self, key, *args, **kwargs): - key = key.upper() - # call our parent classes put method with an upper case key - return dbobj.DB.put(self, key, *args, **kwargs) - self.env = TestDBEnv() - self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL) - self.db = TestDB(self.env) - self.db.open(self.db_name, db.DB_HASH, db.DB_CREATE) - self.db.put('spam', 'eggs') - self.assertEqual(self.db.get('spam'), None, - "overridden dbobj.DB.put() method failed [1]") - self.assertEqual(self.db.get('SPAM'), 'eggs', - "overridden dbobj.DB.put() method failed [2]") - self.db.close() - self.env.close() - - def test02_dbobj_dict_interface(self): - self.env = dbobj.DBEnv() - self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL) - self.db = dbobj.DB(self.env) - self.db.open(self.db_name+'02', db.DB_HASH, db.DB_CREATE) - # __setitem__ - self.db['spam'] = 'eggs' - # __len__ - self.assertEqual(len(self.db), 1) - # __getitem__ - self.assertEqual(self.db['spam'], 'eggs') - # __del__ - del self.db['spam'] - self.assertEqual(self.db.get('spam'), None, "dbobj __del__ failed") - self.db.close() - self.env.close() - - def test03_dbobj_type_before_open(self): - # Ensure this doesn't cause a segfault. - self.assertRaises(db.DBInvalidArgError, db.DB().type) - -#---------------------------------------------------------------------- - -def test_suite(): - return unittest.makeSuite(dbobjTestCase) - -if __name__ == '__main__': - unittest.main(defaultTest='test_suite') diff --git a/PythonLib/extra/bsddb/test/test_dbshelve.py b/PythonLib/extra/bsddb/test/test_dbshelve.py deleted file mode 100644 index c3701e1d..00000000 --- a/PythonLib/extra/bsddb/test/test_dbshelve.py +++ /dev/null @@ -1,398 +0,0 @@ -""" -TestCases for checking dbShelve objects. -""" - -import os, string, sys -import random -import unittest - - -from test_all import db, dbshelve, test_support, verbose, \ - get_new_environment_path, get_new_database_path - - - - - -#---------------------------------------------------------------------- - -# We want the objects to be comparable so we can test dbshelve.values -# later on. -class DataClass: - def __init__(self): - self.value = random.random() - - def __repr__(self) : # For Python 3.0 comparison - return "DataClass %f" %self.value - - def __cmp__(self, other): # For Python 2.x comparison - return cmp(self.value, other) - - -class DBShelveTestCase(unittest.TestCase): - if (sys.version_info < (2, 7)) or ((sys.version_info >= (3, 0)) and - (sys.version_info < (3, 2))) : - def assertIn(self, a, b, msg=None) : - return self.assertTrue(a in b, msg=msg) - - - def setUp(self): - if sys.version_info[0] >= 3 : - from test_all import do_proxy_db_py3k - self._flag_proxy_db_py3k = do_proxy_db_py3k(False) - self.filename = get_new_database_path() - self.do_open() - - def tearDown(self): - if sys.version_info[0] >= 3 : - from test_all import do_proxy_db_py3k - do_proxy_db_py3k(self._flag_proxy_db_py3k) - self.do_close() - test_support.unlink(self.filename) - - def mk(self, key): - """Turn key into an appropriate key type for this db""" - # override in child class for RECNO - if sys.version_info[0] < 3 : - return key - else : - return bytes(key, "iso8859-1") # 8 bits - - def populateDB(self, d): - for x in string.letters: - d[self.mk('S' + x)] = 10 * x # add a string - d[self.mk('I' + x)] = ord(x) # add an integer - d[self.mk('L' + x)] = [x] * 10 # add a list - - inst = DataClass() # add an instance - inst.S = 10 * x - inst.I = ord(x) - inst.L = [x] * 10 - d[self.mk('O' + x)] = inst - - - # overridable in derived classes to affect how the shelf is created/opened - def do_open(self): - self.d = dbshelve.open(self.filename) - - # and closed... - def do_close(self): - self.d.close() - - - - def test01_basics(self): - if verbose: - print '\n', '-=' * 30 - print "Running %s.test01_basics..." % self.__class__.__name__ - - self.populateDB(self.d) - self.d.sync() - self.do_close() - self.do_open() - d = self.d - - l = len(d) - k = d.keys() - s = d.stat() - f = d.fd() - - if verbose: - print "length:", l - print "keys:", k - print "stats:", s - - self.assertEqual(0, d.has_key(self.mk('bad key'))) - self.assertEqual(1, d.has_key(self.mk('IA'))) - self.assertEqual(1, d.has_key(self.mk('OA'))) - - d.delete(self.mk('IA')) - del d[self.mk('OA')] - self.assertEqual(0, d.has_key(self.mk('IA'))) - self.assertEqual(0, d.has_key(self.mk('OA'))) - self.assertEqual(len(d), l-2) - - values = [] - for key in d.keys(): - value = d[key] - values.append(value) - if verbose: - print "%s: %s" % (key, value) - self.checkrec(key, value) - - dbvalues = d.values() - self.assertEqual(len(dbvalues), len(d.keys())) - if sys.version_info < (2, 6) : - values.sort() - dbvalues.sort() - self.assertEqual(values, dbvalues) - else : # XXX: Convert all to strings. Please, improve - values.sort(key=lambda x : str(x)) - dbvalues.sort(key=lambda x : str(x)) - self.assertEqual(repr(values), repr(dbvalues)) - - items = d.items() - self.assertEqual(len(items), len(values)) - - for key, value in items: - self.checkrec(key, value) - - self.assertEqual(d.get(self.mk('bad key')), None) - self.assertEqual(d.get(self.mk('bad key'), None), None) - self.assertEqual(d.get(self.mk('bad key'), 'a string'), 'a string') - self.assertEqual(d.get(self.mk('bad key'), [1, 2, 3]), [1, 2, 3]) - - d.set_get_returns_none(0) - self.assertRaises(db.DBNotFoundError, d.get, self.mk('bad key')) - d.set_get_returns_none(1) - - d.put(self.mk('new key'), 'new data') - self.assertEqual(d.get(self.mk('new key')), 'new data') - self.assertEqual(d[self.mk('new key')], 'new data') - - - - def test02_cursors(self): - if verbose: - print '\n', '-=' * 30 - print "Running %s.test02_cursors..." % self.__class__.__name__ - - self.populateDB(self.d) - d = self.d - - count = 0 - c = d.cursor() - rec = c.first() - while rec is not None: - count = count + 1 - if verbose: - print rec - key, value = rec - self.checkrec(key, value) - # Hack to avoid conversion by 2to3 tool - rec = getattr(c, "next")() - del c - - self.assertEqual(count, len(d)) - - count = 0 - c = d.cursor() - rec = c.last() - while rec is not None: - count = count + 1 - if verbose: - print rec - key, value = rec - self.checkrec(key, value) - rec = c.prev() - - self.assertEqual(count, len(d)) - - c.set(self.mk('SS')) - key, value = c.current() - self.checkrec(key, value) - del c - - - def test03_append(self): - # NOTE: this is overridden in RECNO subclass, don't change its name. - if verbose: - print '\n', '-=' * 30 - print "Running %s.test03_append..." % self.__class__.__name__ - - self.assertRaises(dbshelve.DBShelveError, - self.d.append, 'unit test was here') - - - def test04_iterable(self) : - self.populateDB(self.d) - d = self.d - keys = d.keys() - keyset = set(keys) - self.assertEqual(len(keyset), len(keys)) - - for key in d : - self.assertIn(key, keyset) - keyset.remove(key) - self.assertEqual(len(keyset), 0) - - def checkrec(self, key, value): - # override this in a subclass if the key type is different - - if sys.version_info[0] >= 3 : - if isinstance(key, bytes) : - key = key.decode("iso8859-1") # 8 bits - - x = key[1] - if key[0] == 'S': - self.assertEqual(type(value), str) - self.assertEqual(value, 10 * x) - - elif key[0] == 'I': - self.assertEqual(type(value), int) - self.assertEqual(value, ord(x)) - - elif key[0] == 'L': - self.assertEqual(type(value), list) - self.assertEqual(value, [x] * 10) - - elif key[0] == 'O': - if sys.version_info[0] < 3 : - from types import InstanceType - self.assertEqual(type(value), InstanceType) - else : - self.assertEqual(type(value), DataClass) - - self.assertEqual(value.S, 10 * x) - self.assertEqual(value.I, ord(x)) - self.assertEqual(value.L, [x] * 10) - - else: - self.assertTrue(0, 'Unknown key type, fix the test') - -#---------------------------------------------------------------------- - -class BasicShelveTestCase(DBShelveTestCase): - def do_open(self): - self.d = dbshelve.DBShelf() - self.d.open(self.filename, self.dbtype, self.dbflags) - - def do_close(self): - self.d.close() - - -class BTreeShelveTestCase(BasicShelveTestCase): - dbtype = db.DB_BTREE - dbflags = db.DB_CREATE - - -class HashShelveTestCase(BasicShelveTestCase): - dbtype = db.DB_HASH - dbflags = db.DB_CREATE - - -class ThreadBTreeShelveTestCase(BasicShelveTestCase): - dbtype = db.DB_BTREE - dbflags = db.DB_CREATE | db.DB_THREAD - - -class ThreadHashShelveTestCase(BasicShelveTestCase): - dbtype = db.DB_HASH - dbflags = db.DB_CREATE | db.DB_THREAD - - -#---------------------------------------------------------------------- - -class BasicEnvShelveTestCase(DBShelveTestCase): - def do_open(self): - self.env = db.DBEnv() - self.env.open(self.homeDir, - self.envflags | db.DB_INIT_MPOOL | db.DB_CREATE) - - self.filename = os.path.split(self.filename)[1] - self.d = dbshelve.DBShelf(self.env) - self.d.open(self.filename, self.dbtype, self.dbflags) - - - def do_close(self): - self.d.close() - self.env.close() - - - def setUp(self) : - self.homeDir = get_new_environment_path() - DBShelveTestCase.setUp(self) - - def tearDown(self): - if sys.version_info[0] >= 3 : - from test_all import do_proxy_db_py3k - do_proxy_db_py3k(self._flag_proxy_db_py3k) - self.do_close() - test_support.rmtree(self.homeDir) - - -class EnvBTreeShelveTestCase(BasicEnvShelveTestCase): - envflags = 0 - dbtype = db.DB_BTREE - dbflags = db.DB_CREATE - - -class EnvHashShelveTestCase(BasicEnvShelveTestCase): - envflags = 0 - dbtype = db.DB_HASH - dbflags = db.DB_CREATE - - -class EnvThreadBTreeShelveTestCase(BasicEnvShelveTestCase): - envflags = db.DB_THREAD - dbtype = db.DB_BTREE - dbflags = db.DB_CREATE | db.DB_THREAD - - -class EnvThreadHashShelveTestCase(BasicEnvShelveTestCase): - envflags = db.DB_THREAD - dbtype = db.DB_HASH - dbflags = db.DB_CREATE | db.DB_THREAD - - -#---------------------------------------------------------------------- -# test cases for a DBShelf in a RECNO DB. - -class RecNoShelveTestCase(BasicShelveTestCase): - dbtype = db.DB_RECNO - dbflags = db.DB_CREATE - - def setUp(self): - BasicShelveTestCase.setUp(self) - - # pool to assign integer key values out of - self.key_pool = list(range(1, 5000)) - self.key_map = {} # map string keys to the number we gave them - self.intkey_map = {} # reverse map of above - - def mk(self, key): - if key not in self.key_map: - self.key_map[key] = self.key_pool.pop(0) - self.intkey_map[self.key_map[key]] = key - return self.key_map[key] - - def checkrec(self, intkey, value): - key = self.intkey_map[intkey] - BasicShelveTestCase.checkrec(self, key, value) - - def test03_append(self): - if verbose: - print '\n', '-=' * 30 - print "Running %s.test03_append..." % self.__class__.__name__ - - self.d[1] = 'spam' - self.d[5] = 'eggs' - self.assertEqual(6, self.d.append('spam')) - self.assertEqual(7, self.d.append('baked beans')) - self.assertEqual('spam', self.d.get(6)) - self.assertEqual('spam', self.d.get(1)) - self.assertEqual('baked beans', self.d.get(7)) - self.assertEqual('eggs', self.d.get(5)) - - -#---------------------------------------------------------------------- - -def test_suite(): - suite = unittest.TestSuite() - - suite.addTest(unittest.makeSuite(DBShelveTestCase)) - suite.addTest(unittest.makeSuite(BTreeShelveTestCase)) - suite.addTest(unittest.makeSuite(HashShelveTestCase)) - suite.addTest(unittest.makeSuite(ThreadBTreeShelveTestCase)) - suite.addTest(unittest.makeSuite(ThreadHashShelveTestCase)) - suite.addTest(unittest.makeSuite(EnvBTreeShelveTestCase)) - suite.addTest(unittest.makeSuite(EnvHashShelveTestCase)) - suite.addTest(unittest.makeSuite(EnvThreadBTreeShelveTestCase)) - suite.addTest(unittest.makeSuite(EnvThreadHashShelveTestCase)) - suite.addTest(unittest.makeSuite(RecNoShelveTestCase)) - - return suite - - -if __name__ == '__main__': - unittest.main(defaultTest='test_suite') diff --git a/PythonLib/extra/bsddb/test/test_dbtables.py b/PythonLib/extra/bsddb/test/test_dbtables.py deleted file mode 100644 index bb31381e..00000000 --- a/PythonLib/extra/bsddb/test/test_dbtables.py +++ /dev/null @@ -1,409 +0,0 @@ -#!/usr/bin/env python -# -#----------------------------------------------------------------------- -# A test suite for the table interface built on bsddb.db -#----------------------------------------------------------------------- -# -# Copyright (C) 2000, 2001 by Autonomous Zone Industries -# Copyright (C) 2002 Gregory P. Smith -# -# March 20, 2000 -# -# License: This is free software. You may use this software for any -# purpose including modification/redistribution, so long as -# this header remains intact and that you do not claim any -# rights of ownership or authorship of this software. This -# software has been tested, but no warranty is expressed or -# implied. -# -# -- Gregory P. Smith -# -# $Id$ - -import os, re, sys - -if sys.version_info[0] < 3 : - try: - import cPickle - pickle = cPickle - except ImportError: - import pickle -else : - import pickle - -import unittest -from test_all import db, dbtables, test_support, verbose, \ - get_new_environment_path, get_new_database_path - -#---------------------------------------------------------------------- - -class TableDBTestCase(unittest.TestCase): - db_name = 'test-table.db' - - def setUp(self): - import sys - if sys.version_info[0] >= 3 : - from test_all import do_proxy_db_py3k - self._flag_proxy_db_py3k = do_proxy_db_py3k(False) - - self.testHomeDir = get_new_environment_path() - self.tdb = dbtables.bsdTableDB( - filename='tabletest.db', dbhome=self.testHomeDir, create=1) - - def tearDown(self): - self.tdb.close() - import sys - if sys.version_info[0] >= 3 : - from test_all import do_proxy_db_py3k - do_proxy_db_py3k(self._flag_proxy_db_py3k) - test_support.rmtree(self.testHomeDir) - - def test01(self): - tabname = "test01" - colname = 'cool numbers' - try: - self.tdb.Drop(tabname) - except dbtables.TableDBError: - pass - self.tdb.CreateTable(tabname, [colname]) - import sys - if sys.version_info[0] < 3 : - self.tdb.Insert(tabname, {colname: pickle.dumps(3.14159, 1)}) - else : - self.tdb.Insert(tabname, {colname: pickle.dumps(3.14159, - 1).decode("iso8859-1")}) # 8 bits - - if verbose: - self.tdb._db_print() - - values = self.tdb.Select( - tabname, [colname], conditions={colname: None}) - - import sys - if sys.version_info[0] < 3 : - colval = pickle.loads(values[0][colname]) - else : - colval = pickle.loads(bytes(values[0][colname], "iso8859-1")) - self.assertTrue(colval > 3.141) - self.assertTrue(colval < 3.142) - - - def test02(self): - tabname = "test02" - col0 = 'coolness factor' - col1 = 'but can it fly?' - col2 = 'Species' - - import sys - if sys.version_info[0] < 3 : - testinfo = [ - {col0: pickle.dumps(8, 1), col1: 'no', col2: 'Penguin'}, - {col0: pickle.dumps(-1, 1), col1: 'no', col2: 'Turkey'}, - {col0: pickle.dumps(9, 1), col1: 'yes', col2: 'SR-71A Blackbird'} - ] - else : - testinfo = [ - {col0: pickle.dumps(8, 1).decode("iso8859-1"), - col1: 'no', col2: 'Penguin'}, - {col0: pickle.dumps(-1, 1).decode("iso8859-1"), - col1: 'no', col2: 'Turkey'}, - {col0: pickle.dumps(9, 1).decode("iso8859-1"), - col1: 'yes', col2: 'SR-71A Blackbird'} - ] - - try: - self.tdb.Drop(tabname) - except dbtables.TableDBError: - pass - self.tdb.CreateTable(tabname, [col0, col1, col2]) - for row in testinfo : - self.tdb.Insert(tabname, row) - - import sys - if sys.version_info[0] < 3 : - values = self.tdb.Select(tabname, [col2], - conditions={col0: lambda x: pickle.loads(x) >= 8}) - else : - values = self.tdb.Select(tabname, [col2], - conditions={col0: lambda x: - pickle.loads(bytes(x, "iso8859-1")) >= 8}) - - self.assertEqual(len(values), 2) - if values[0]['Species'] == 'Penguin' : - self.assertEqual(values[1]['Species'], 'SR-71A Blackbird') - elif values[0]['Species'] == 'SR-71A Blackbird' : - self.assertEqual(values[1]['Species'], 'Penguin') - else : - if verbose: - print "values= %r" % (values,) - raise RuntimeError("Wrong values returned!") - - def test03(self): - tabname = "test03" - try: - self.tdb.Drop(tabname) - except dbtables.TableDBError: - pass - if verbose: - print '...before CreateTable...' - self.tdb._db_print() - self.tdb.CreateTable(tabname, ['a', 'b', 'c', 'd', 'e']) - if verbose: - print '...after CreateTable...' - self.tdb._db_print() - self.tdb.Drop(tabname) - if verbose: - print '...after Drop...' - self.tdb._db_print() - self.tdb.CreateTable(tabname, ['a', 'b', 'c', 'd', 'e']) - - try: - self.tdb.Insert(tabname, - {'a': "", - 'e': pickle.dumps([{4:5, 6:7}, 'foo'], 1), - 'f': "Zero"}) - self.fail('Expected an exception') - except dbtables.TableDBError: - pass - - try: - self.tdb.Select(tabname, [], conditions={'foo': '123'}) - self.fail('Expected an exception') - except dbtables.TableDBError: - pass - - self.tdb.Insert(tabname, - {'a': '42', - 'b': "bad", - 'c': "meep", - 'e': 'Fuzzy wuzzy was a bear'}) - self.tdb.Insert(tabname, - {'a': '581750', - 'b': "good", - 'd': "bla", - 'c': "black", - 'e': 'fuzzy was here'}) - self.tdb.Insert(tabname, - {'a': '800000', - 'b': "good", - 'd': "bla", - 'c': "black", - 'e': 'Fuzzy wuzzy is a bear'}) - - if verbose: - self.tdb._db_print() - - # this should return two rows - values = self.tdb.Select(tabname, ['b', 'a', 'd'], - conditions={'e': re.compile('wuzzy').search, - 'a': re.compile('^[0-9]+$').match}) - self.assertEqual(len(values), 2) - - # now lets delete one of them and try again - self.tdb.Delete(tabname, conditions={'b': dbtables.ExactCond('good')}) - values = self.tdb.Select( - tabname, ['a', 'd', 'b'], - conditions={'e': dbtables.PrefixCond('Fuzzy')}) - self.assertEqual(len(values), 1) - self.assertEqual(values[0]['d'], None) - - values = self.tdb.Select(tabname, ['b'], - conditions={'c': lambda c: c == 'meep'}) - self.assertEqual(len(values), 1) - self.assertEqual(values[0]['b'], "bad") - - - def test04_MultiCondSelect(self): - tabname = "test04_MultiCondSelect" - try: - self.tdb.Drop(tabname) - except dbtables.TableDBError: - pass - self.tdb.CreateTable(tabname, ['a', 'b', 'c', 'd', 'e']) - - try: - self.tdb.Insert(tabname, - {'a': "", - 'e': pickle.dumps([{4:5, 6:7}, 'foo'], 1), - 'f': "Zero"}) - self.fail('Expected an exception') - except dbtables.TableDBError: - pass - - self.tdb.Insert(tabname, {'a': "A", 'b': "B", 'c': "C", 'd': "D", - 'e': "E"}) - self.tdb.Insert(tabname, {'a': "-A", 'b': "-B", 'c': "-C", 'd': "-D", - 'e': "-E"}) - self.tdb.Insert(tabname, {'a': "A-", 'b': "B-", 'c': "C-", 'd': "D-", - 'e': "E-"}) - - if verbose: - self.tdb._db_print() - - # This select should return 0 rows. it is designed to test - # the bug identified and fixed in sourceforge bug # 590449 - # (Big Thanks to "Rob Tillotson (n9mtb)" for tracking this down - # and supplying a fix!! This one caused many headaches to say - # the least...) - values = self.tdb.Select(tabname, ['b', 'a', 'd'], - conditions={'e': dbtables.ExactCond('E'), - 'a': dbtables.ExactCond('A'), - 'd': dbtables.PrefixCond('-') - } ) - self.assertEqual(len(values), 0, values) - - - def test_CreateOrExtend(self): - tabname = "test_CreateOrExtend" - - self.tdb.CreateOrExtendTable( - tabname, ['name', 'taste', 'filling', 'alcohol content', 'price']) - try: - self.tdb.Insert(tabname, - {'taste': 'crap', - 'filling': 'no', - 'is it Guinness?': 'no'}) - self.fail("Insert should've failed due to bad column name") - except: - pass - self.tdb.CreateOrExtendTable(tabname, - ['name', 'taste', 'is it Guinness?']) - - # these should both succeed as the table should contain the union of both sets of columns. - self.tdb.Insert(tabname, {'taste': 'crap', 'filling': 'no', - 'is it Guinness?': 'no'}) - self.tdb.Insert(tabname, {'taste': 'great', 'filling': 'yes', - 'is it Guinness?': 'yes', - 'name': 'Guinness'}) - - - def test_CondObjs(self): - tabname = "test_CondObjs" - - self.tdb.CreateTable(tabname, ['a', 'b', 'c', 'd', 'e', 'p']) - - self.tdb.Insert(tabname, {'a': "the letter A", - 'b': "the letter B", - 'c': "is for cookie"}) - self.tdb.Insert(tabname, {'a': "is for aardvark", - 'e': "the letter E", - 'c': "is for cookie", - 'd': "is for dog"}) - self.tdb.Insert(tabname, {'a': "the letter A", - 'e': "the letter E", - 'c': "is for cookie", - 'p': "is for Python"}) - - values = self.tdb.Select( - tabname, ['p', 'e'], - conditions={'e': dbtables.PrefixCond('the l')}) - self.assertEqual(len(values), 2, values) - self.assertEqual(values[0]['e'], values[1]['e'], values) - self.assertNotEqual(values[0]['p'], values[1]['p'], values) - - values = self.tdb.Select( - tabname, ['d', 'a'], - conditions={'a': dbtables.LikeCond('%aardvark%')}) - self.assertEqual(len(values), 1, values) - self.assertEqual(values[0]['d'], "is for dog", values) - self.assertEqual(values[0]['a'], "is for aardvark", values) - - values = self.tdb.Select(tabname, None, - {'b': dbtables.Cond(), - 'e':dbtables.LikeCond('%letter%'), - 'a':dbtables.PrefixCond('is'), - 'd':dbtables.ExactCond('is for dog'), - 'c':dbtables.PrefixCond('is for'), - 'p':lambda s: not s}) - self.assertEqual(len(values), 1, values) - self.assertEqual(values[0]['d'], "is for dog", values) - self.assertEqual(values[0]['a'], "is for aardvark", values) - - def test_Delete(self): - tabname = "test_Delete" - self.tdb.CreateTable(tabname, ['x', 'y', 'z']) - - # prior to 2001-05-09 there was a bug where Delete() would - # fail if it encountered any rows that did not have values in - # every column. - # Hunted and Squashed by (Jukka Santala - donwulff@nic.fi) - self.tdb.Insert(tabname, {'x': 'X1', 'y':'Y1'}) - self.tdb.Insert(tabname, {'x': 'X2', 'y':'Y2', 'z': 'Z2'}) - - self.tdb.Delete(tabname, conditions={'x': dbtables.PrefixCond('X')}) - values = self.tdb.Select(tabname, ['y'], - conditions={'x': dbtables.PrefixCond('X')}) - self.assertEqual(len(values), 0) - - def test_Modify(self): - tabname = "test_Modify" - self.tdb.CreateTable(tabname, ['Name', 'Type', 'Access']) - - self.tdb.Insert(tabname, {'Name': 'Index to MP3 files.doc', - 'Type': 'Word', 'Access': '8'}) - self.tdb.Insert(tabname, {'Name': 'Nifty.MP3', 'Access': '1'}) - self.tdb.Insert(tabname, {'Type': 'Unknown', 'Access': '0'}) - - def set_type(type): - if type is None: - return 'MP3' - return type - - def increment_access(count): - return str(int(count)+1) - - def remove_value(value): - return None - - self.tdb.Modify(tabname, - conditions={'Access': dbtables.ExactCond('0')}, - mappings={'Access': remove_value}) - self.tdb.Modify(tabname, - conditions={'Name': dbtables.LikeCond('%MP3%')}, - mappings={'Type': set_type}) - self.tdb.Modify(tabname, - conditions={'Name': dbtables.LikeCond('%')}, - mappings={'Access': increment_access}) - - try: - self.tdb.Modify(tabname, - conditions={'Name': dbtables.LikeCond('%')}, - mappings={'Access': 'What is your quest?'}) - except TypeError: - # success, the string value in mappings isn't callable - pass - else: - raise RuntimeError, "why was TypeError not raised for bad callable?" - - # Delete key in select conditions - values = self.tdb.Select( - tabname, None, - conditions={'Type': dbtables.ExactCond('Unknown')}) - self.assertEqual(len(values), 1, values) - self.assertEqual(values[0]['Name'], None, values) - self.assertEqual(values[0]['Access'], None, values) - - # Modify value by select conditions - values = self.tdb.Select( - tabname, None, - conditions={'Name': dbtables.ExactCond('Nifty.MP3')}) - self.assertEqual(len(values), 1, values) - self.assertEqual(values[0]['Type'], "MP3", values) - self.assertEqual(values[0]['Access'], "2", values) - - # Make sure change applied only to select conditions - values = self.tdb.Select( - tabname, None, conditions={'Name': dbtables.LikeCond('%doc%')}) - self.assertEqual(len(values), 1, values) - self.assertEqual(values[0]['Type'], "Word", values) - self.assertEqual(values[0]['Access'], "9", values) - - -def test_suite(): - suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(TableDBTestCase)) - return suite - - -if __name__ == '__main__': - unittest.main(defaultTest='test_suite') diff --git a/PythonLib/extra/bsddb/test/test_distributed_transactions.py b/PythonLib/extra/bsddb/test/test_distributed_transactions.py deleted file mode 100644 index 90585755..00000000 --- a/PythonLib/extra/bsddb/test/test_distributed_transactions.py +++ /dev/null @@ -1,152 +0,0 @@ -"""TestCases for distributed transactions. -""" - -import os -import unittest - -from test_all import db, test_support, get_new_environment_path, \ - get_new_database_path - -from test_all import verbose - -#---------------------------------------------------------------------- - -class DBTxn_distributed(unittest.TestCase): - num_txns=1234 - nosync=True - must_open_db=False - def _create_env(self, must_open_db) : - self.dbenv = db.DBEnv() - self.dbenv.set_tx_max(self.num_txns) - self.dbenv.set_lk_max_lockers(self.num_txns*2) - self.dbenv.set_lk_max_locks(self.num_txns*2) - self.dbenv.set_lk_max_objects(self.num_txns*2) - if self.nosync : - self.dbenv.set_flags(db.DB_TXN_NOSYNC,True) - self.dbenv.open(self.homeDir, db.DB_CREATE | db.DB_THREAD | - db.DB_RECOVER | - db.DB_INIT_TXN | db.DB_INIT_LOG | db.DB_INIT_MPOOL | - db.DB_INIT_LOCK, 0666) - self.db = db.DB(self.dbenv) - self.db.set_re_len(db.DB_GID_SIZE) - if must_open_db : - txn=self.dbenv.txn_begin() - self.db.open(self.filename, - db.DB_QUEUE, db.DB_CREATE | db.DB_THREAD, 0666, - txn=txn) - txn.commit() - - def setUp(self) : - self.homeDir = get_new_environment_path() - self.filename = "test" - return self._create_env(must_open_db=True) - - def _destroy_env(self): - if self.nosync or (db.version()[:2] == (4,6)): # Known bug - self.dbenv.log_flush() - self.db.close() - self.dbenv.close() - - def tearDown(self): - self._destroy_env() - test_support.rmtree(self.homeDir) - - def _recreate_env(self,must_open_db) : - self._destroy_env() - self._create_env(must_open_db) - - def test01_distributed_transactions(self) : - txns=set() - adapt = lambda x : x - import sys - if sys.version_info[0] >= 3 : - adapt = lambda x : bytes(x, "ascii") - # Create transactions, "prepare" them, and - # let them be garbage collected. - for i in xrange(self.num_txns) : - txn = self.dbenv.txn_begin() - gid = "%%%dd" %db.DB_GID_SIZE - gid = adapt(gid %i) - self.db.put(i, gid, txn=txn, flags=db.DB_APPEND) - txns.add(gid) - txn.prepare(gid) - del txn - - self._recreate_env(self.must_open_db) - - # Get "to be recovered" transactions but - # let them be garbage collected. - recovered_txns=self.dbenv.txn_recover() - self.assertEqual(self.num_txns,len(recovered_txns)) - for gid,txn in recovered_txns : - self.assertTrue(gid in txns) - del txn - del recovered_txns - - self._recreate_env(self.must_open_db) - - # Get "to be recovered" transactions. Commit, abort and - # discard them. - recovered_txns=self.dbenv.txn_recover() - self.assertEqual(self.num_txns,len(recovered_txns)) - discard_txns=set() - committed_txns=set() - state=0 - for gid,txn in recovered_txns : - if state==0 or state==1: - committed_txns.add(gid) - txn.commit() - elif state==2 : - txn.abort() - elif state==3 : - txn.discard() - discard_txns.add(gid) - state=-1 - state+=1 - del txn - del recovered_txns - - self._recreate_env(self.must_open_db) - - # Verify the discarded transactions are still - # around, and dispose them. - recovered_txns=self.dbenv.txn_recover() - self.assertEqual(len(discard_txns),len(recovered_txns)) - for gid,txn in recovered_txns : - txn.abort() - del txn - del recovered_txns - - self._recreate_env(must_open_db=True) - - # Be sure there are not pending transactions. - # Check also database size. - recovered_txns=self.dbenv.txn_recover() - self.assertTrue(len(recovered_txns)==0) - self.assertEqual(len(committed_txns),self.db.stat()["nkeys"]) - -class DBTxn_distributedSYNC(DBTxn_distributed): - nosync=False - -class DBTxn_distributed_must_open_db(DBTxn_distributed): - must_open_db=True - -class DBTxn_distributedSYNC_must_open_db(DBTxn_distributed): - nosync=False - must_open_db=True - -#---------------------------------------------------------------------- - -def test_suite(): - suite = unittest.TestSuite() - if db.version() >= (4,5) : - suite.addTest(unittest.makeSuite(DBTxn_distributed)) - suite.addTest(unittest.makeSuite(DBTxn_distributedSYNC)) - if db.version() >= (4,6) : - suite.addTest(unittest.makeSuite(DBTxn_distributed_must_open_db)) - suite.addTest(unittest.makeSuite(DBTxn_distributedSYNC_must_open_db)) - return suite - - -if __name__ == '__main__': - unittest.main(defaultTest='test_suite') diff --git a/PythonLib/extra/bsddb/test/test_early_close.py b/PythonLib/extra/bsddb/test/test_early_close.py deleted file mode 100644 index e9252795..00000000 --- a/PythonLib/extra/bsddb/test/test_early_close.py +++ /dev/null @@ -1,215 +0,0 @@ -"""TestCases for checking that it does not segfault when a DBEnv object -is closed before its DB objects. -""" - -import os, sys -import unittest - -from test_all import db, test_support, verbose, get_new_environment_path, get_new_database_path - -# We're going to get warnings in this module about trying to close the db when -# its env is already closed. Let's just ignore those. -try: - import warnings -except ImportError: - pass -else: - warnings.filterwarnings('ignore', - message='DB could not be closed in', - category=RuntimeWarning) - - -#---------------------------------------------------------------------- - -class DBEnvClosedEarlyCrash(unittest.TestCase): - def setUp(self): - self.homeDir = get_new_environment_path() - self.filename = "test" - - def tearDown(self): - test_support.rmtree(self.homeDir) - - def test01_close_dbenv_before_db(self): - dbenv = db.DBEnv() - dbenv.open(self.homeDir, - db.DB_INIT_CDB| db.DB_CREATE |db.DB_THREAD|db.DB_INIT_MPOOL, - 0666) - - d = db.DB(dbenv) - d2 = db.DB(dbenv) - d.open(self.filename, db.DB_BTREE, db.DB_CREATE | db.DB_THREAD, 0666) - - self.assertRaises(db.DBNoSuchFileError, d2.open, - self.filename+"2", db.DB_BTREE, db.DB_THREAD, 0666) - - d.put("test","this is a test") - self.assertEqual(d.get("test"), "this is a test", "put!=get") - dbenv.close() # This "close" should close the child db handle also - self.assertRaises(db.DBError, d.get, "test") - - def test02_close_dbenv_before_dbcursor(self): - dbenv = db.DBEnv() - dbenv.open(self.homeDir, - db.DB_INIT_CDB| db.DB_CREATE |db.DB_THREAD|db.DB_INIT_MPOOL, - 0666) - - d = db.DB(dbenv) - d.open(self.filename, db.DB_BTREE, db.DB_CREATE | db.DB_THREAD, 0666) - - d.put("test","this is a test") - d.put("test2","another test") - d.put("test3","another one") - self.assertEqual(d.get("test"), "this is a test", "put!=get") - c=d.cursor() - c.first() - c.next() - d.close() # This "close" should close the child db handle also - # db.close should close the child cursor - self.assertRaises(db.DBError,c.next) - - d = db.DB(dbenv) - d.open(self.filename, db.DB_BTREE, db.DB_CREATE | db.DB_THREAD, 0666) - c=d.cursor() - c.first() - c.next() - dbenv.close() - # The "close" should close the child db handle also, with cursors - self.assertRaises(db.DBError, c.next) - - def test03_close_db_before_dbcursor_without_env(self): - import os.path - path=os.path.join(self.homeDir,self.filename) - d = db.DB() - d.open(path, db.DB_BTREE, db.DB_CREATE | db.DB_THREAD, 0666) - - d.put("test","this is a test") - d.put("test2","another test") - d.put("test3","another one") - self.assertEqual(d.get("test"), "this is a test", "put!=get") - c=d.cursor() - c.first() - c.next() - d.close() - # The "close" should close the child db handle also - self.assertRaises(db.DBError, c.next) - - def test04_close_massive(self): - dbenv = db.DBEnv() - dbenv.open(self.homeDir, - db.DB_INIT_CDB| db.DB_CREATE |db.DB_THREAD|db.DB_INIT_MPOOL, - 0666) - - dbs=[db.DB(dbenv) for i in xrange(16)] - cursors=[] - for i in dbs : - i.open(self.filename, db.DB_BTREE, db.DB_CREATE | db.DB_THREAD, 0666) - - dbs[10].put("test","this is a test") - dbs[10].put("test2","another test") - dbs[10].put("test3","another one") - self.assertEqual(dbs[4].get("test"), "this is a test", "put!=get") - - for i in dbs : - cursors.extend([i.cursor() for j in xrange(32)]) - - for i in dbs[::3] : - i.close() - for i in cursors[::3] : - i.close() - - # Check for missing exception in DB! (after DB close) - self.assertRaises(db.DBError, dbs[9].get, "test") - - # Check for missing exception in DBCursor! (after DB close) - self.assertRaises(db.DBError, cursors[101].first) - - cursors[80].first() - cursors[80].next() - dbenv.close() # This "close" should close the child db handle also - # Check for missing exception! (after DBEnv close) - self.assertRaises(db.DBError, cursors[80].next) - - def test05_close_dbenv_delete_db_success(self): - dbenv = db.DBEnv() - dbenv.open(self.homeDir, - db.DB_INIT_CDB| db.DB_CREATE |db.DB_THREAD|db.DB_INIT_MPOOL, - 0666) - - d = db.DB(dbenv) - d.open(self.filename, db.DB_BTREE, db.DB_CREATE | db.DB_THREAD, 0666) - - dbenv.close() # This "close" should close the child db handle also - - del d - try: - import gc - except ImportError: - gc = None - if gc: - # force d.__del__ [DB_dealloc] to be called - gc.collect() - - def test06_close_txn_before_dup_cursor(self) : - dbenv = db.DBEnv() - dbenv.open(self.homeDir,db.DB_INIT_TXN | db.DB_INIT_MPOOL | - db.DB_INIT_LOG | db.DB_CREATE) - d = db.DB(dbenv) - txn = dbenv.txn_begin() - d.open(self.filename, dbtype = db.DB_HASH, flags = db.DB_CREATE, - txn=txn) - d.put("XXX", "yyy", txn=txn) - txn.commit() - txn = dbenv.txn_begin() - c1 = d.cursor(txn) - c2 = c1.dup() - self.assertEqual(("XXX", "yyy"), c1.first()) - - # Not interested in warnings about implicit close. - import warnings - if sys.version_info < (2, 6) : - # Completely resetting the warning state is - # problematic with python >=2.6 with -3 (py3k warning), - # because some stdlib modules selectively ignores warnings. - warnings.simplefilter("ignore") - txn.commit() - warnings.resetwarnings() - else : - # When we drop support for python 2.4 - # we could use: (in 2.5 we need a __future__ statement) - # - # with warnings.catch_warnings(): - # warnings.simplefilter("ignore") - # txn.commit() - # - # We can not use "with" as is, because it would be invalid syntax - # in python 2.4 and (with no __future__) 2.5. - # Here we simulate "with" following PEP 343 : - w = warnings.catch_warnings() - w.__enter__() - try : - warnings.simplefilter("ignore") - txn.commit() - finally : - w.__exit__() - - self.assertRaises(db.DBCursorClosedError, c2.first) - - def test07_close_db_before_sequence(self): - import os.path - path=os.path.join(self.homeDir,self.filename) - d = db.DB() - d.open(path, db.DB_BTREE, db.DB_CREATE | db.DB_THREAD, 0666) - dbs=db.DBSequence(d) - d.close() # This "close" should close the child DBSequence also - dbs.close() # If not closed, core dump (in Berkeley DB 4.6.*) - -#---------------------------------------------------------------------- - -def test_suite(): - suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(DBEnvClosedEarlyCrash)) - return suite - - -if __name__ == '__main__': - unittest.main(defaultTest='test_suite') diff --git a/PythonLib/extra/bsddb/test/test_fileid.py b/PythonLib/extra/bsddb/test/test_fileid.py deleted file mode 100644 index 095ec83d..00000000 --- a/PythonLib/extra/bsddb/test/test_fileid.py +++ /dev/null @@ -1,61 +0,0 @@ -"""TestCase for reseting File ID. -""" - -import os -import shutil -import unittest - -from test_all import db, test_support, get_new_environment_path, get_new_database_path - -class FileidResetTestCase(unittest.TestCase): - def setUp(self): - self.db_path_1 = get_new_database_path() - self.db_path_2 = get_new_database_path() - self.db_env_path = get_new_environment_path() - - def test_fileid_reset(self): - # create DB 1 - self.db1 = db.DB() - self.db1.open(self.db_path_1, dbtype=db.DB_HASH, flags=(db.DB_CREATE|db.DB_EXCL)) - self.db1.put('spam', 'eggs') - self.db1.close() - - shutil.copy(self.db_path_1, self.db_path_2) - - self.db2 = db.DB() - self.db2.open(self.db_path_2, dbtype=db.DB_HASH) - self.db2.put('spam', 'spam') - self.db2.close() - - self.db_env = db.DBEnv() - self.db_env.open(self.db_env_path, db.DB_CREATE|db.DB_INIT_MPOOL) - - # use fileid_reset() here - self.db_env.fileid_reset(self.db_path_2) - - self.db1 = db.DB(self.db_env) - self.db1.open(self.db_path_1, dbtype=db.DB_HASH, flags=db.DB_RDONLY) - self.assertEqual(self.db1.get('spam'), 'eggs') - - self.db2 = db.DB(self.db_env) - self.db2.open(self.db_path_2, dbtype=db.DB_HASH, flags=db.DB_RDONLY) - self.assertEqual(self.db2.get('spam'), 'spam') - - self.db1.close() - self.db2.close() - - self.db_env.close() - - def tearDown(self): - test_support.unlink(self.db_path_1) - test_support.unlink(self.db_path_2) - test_support.rmtree(self.db_env_path) - -def test_suite(): - suite = unittest.TestSuite() - if db.version() >= (4, 4): - suite.addTest(unittest.makeSuite(FileidResetTestCase)) - return suite - -if __name__ == '__main__': - unittest.main(defaultTest='test_suite') diff --git a/PythonLib/extra/bsddb/test/test_get_none.py b/PythonLib/extra/bsddb/test/test_get_none.py deleted file mode 100644 index 8763b543..00000000 --- a/PythonLib/extra/bsddb/test/test_get_none.py +++ /dev/null @@ -1,92 +0,0 @@ -""" -TestCases for checking set_get_returns_none. -""" - -import os, string -import unittest - -from test_all import db, verbose, get_new_database_path - - -#---------------------------------------------------------------------- - -class GetReturnsNoneTestCase(unittest.TestCase): - def setUp(self): - self.filename = get_new_database_path() - - def tearDown(self): - try: - os.remove(self.filename) - except os.error: - pass - - - def test01_get_returns_none(self): - d = db.DB() - d.open(self.filename, db.DB_BTREE, db.DB_CREATE) - d.set_get_returns_none(1) - - for x in string.letters: - d.put(x, x * 40) - - data = d.get('bad key') - self.assertEqual(data, None) - - data = d.get(string.letters[0]) - self.assertEqual(data, string.letters[0]*40) - - count = 0 - c = d.cursor() - rec = c.first() - while rec: - count = count + 1 - rec = c.next() - - self.assertEqual(rec, None) - self.assertEqual(count, len(string.letters)) - - c.close() - d.close() - - - def test02_get_raises_exception(self): - d = db.DB() - d.open(self.filename, db.DB_BTREE, db.DB_CREATE) - d.set_get_returns_none(0) - - for x in string.letters: - d.put(x, x * 40) - - self.assertRaises(db.DBNotFoundError, d.get, 'bad key') - self.assertRaises(KeyError, d.get, 'bad key') - - data = d.get(string.letters[0]) - self.assertEqual(data, string.letters[0]*40) - - count = 0 - exceptionHappened = 0 - c = d.cursor() - rec = c.first() - while rec: - count = count + 1 - try: - rec = c.next() - except db.DBNotFoundError: # end of the records - exceptionHappened = 1 - break - - self.assertNotEqual(rec, None) - self.assertTrue(exceptionHappened) - self.assertEqual(count, len(string.letters)) - - c.close() - d.close() - -#---------------------------------------------------------------------- - -def test_suite(): - return unittest.makeSuite(GetReturnsNoneTestCase) - - -if __name__ == '__main__': - unittest.main(defaultTest='test_suite') diff --git a/PythonLib/extra/bsddb/test/test_join.py b/PythonLib/extra/bsddb/test/test_join.py deleted file mode 100644 index 1f0dfff8..00000000 --- a/PythonLib/extra/bsddb/test/test_join.py +++ /dev/null @@ -1,99 +0,0 @@ -"""TestCases for using the DB.join and DBCursor.join_item methods. -""" - -import os - -import unittest - -from test_all import db, dbshelve, test_support, verbose, \ - get_new_environment_path, get_new_database_path - -#---------------------------------------------------------------------- - -ProductIndex = [ - ('apple', "Convenience Store"), - ('blueberry', "Farmer's Market"), - ('shotgun', "S-Mart"), # Aisle 12 - ('pear', "Farmer's Market"), - ('chainsaw', "S-Mart"), # "Shop smart. Shop S-Mart!" - ('strawberry', "Farmer's Market"), -] - -ColorIndex = [ - ('blue', "blueberry"), - ('red', "apple"), - ('red', "chainsaw"), - ('red', "strawberry"), - ('yellow', "peach"), - ('yellow', "pear"), - ('black', "shotgun"), -] - -class JoinTestCase(unittest.TestCase): - keytype = '' - - def setUp(self): - self.filename = self.__class__.__name__ + '.db' - self.homeDir = get_new_environment_path() - self.env = db.DBEnv() - self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL | db.DB_INIT_LOCK ) - - def tearDown(self): - self.env.close() - test_support.rmtree(self.homeDir) - - def test01_join(self): - if verbose: - print '\n', '-=' * 30 - print "Running %s.test01_join..." % \ - self.__class__.__name__ - - # create and populate primary index - priDB = db.DB(self.env) - priDB.open(self.filename, "primary", db.DB_BTREE, db.DB_CREATE) - map(lambda t, priDB=priDB: priDB.put(*t), ProductIndex) - - # create and populate secondary index - secDB = db.DB(self.env) - secDB.set_flags(db.DB_DUP | db.DB_DUPSORT) - secDB.open(self.filename, "secondary", db.DB_BTREE, db.DB_CREATE) - map(lambda t, secDB=secDB: secDB.put(*t), ColorIndex) - - sCursor = None - jCursor = None - try: - # lets look up all of the red Products - sCursor = secDB.cursor() - # Don't do the .set() in an assert, or you can get a bogus failure - # when running python -O - tmp = sCursor.set('red') - self.assertTrue(tmp) - - # FIXME: jCursor doesn't properly hold a reference to its - # cursors, if they are closed before jcursor is used it - # can cause a crash. - jCursor = priDB.join([sCursor]) - - if jCursor.get(0) != ('apple', "Convenience Store"): - self.fail("join cursor positioned wrong") - if jCursor.join_item() != 'chainsaw': - self.fail("DBCursor.join_item returned wrong item") - if jCursor.get(0)[0] != 'strawberry': - self.fail("join cursor returned wrong thing") - if jCursor.get(0): # there were only three red items to return - self.fail("join cursor returned too many items") - finally: - if jCursor: - jCursor.close() - if sCursor: - sCursor.close() - priDB.close() - secDB.close() - - -def test_suite(): - suite = unittest.TestSuite() - - suite.addTest(unittest.makeSuite(JoinTestCase)) - - return suite diff --git a/PythonLib/extra/bsddb/test/test_lock.py b/PythonLib/extra/bsddb/test/test_lock.py deleted file mode 100644 index 10ca8d64..00000000 --- a/PythonLib/extra/bsddb/test/test_lock.py +++ /dev/null @@ -1,184 +0,0 @@ -""" -TestCases for testing the locking sub-system. -""" - -import time - -import unittest -from test_all import db, test_support, verbose, have_threads, \ - get_new_environment_path, get_new_database_path - -if have_threads : - from threading import Thread - import sys - if sys.version_info[0] < 3 : - from threading import currentThread - else : - from threading import current_thread as currentThread - -#---------------------------------------------------------------------- - -class LockingTestCase(unittest.TestCase): - def setUp(self): - self.homeDir = get_new_environment_path() - self.env = db.DBEnv() - self.env.open(self.homeDir, db.DB_THREAD | db.DB_INIT_MPOOL | - db.DB_INIT_LOCK | db.DB_CREATE) - - - def tearDown(self): - self.env.close() - test_support.rmtree(self.homeDir) - - - def test01_simple(self): - if verbose: - print '\n', '-=' * 30 - print "Running %s.test01_simple..." % self.__class__.__name__ - - anID = self.env.lock_id() - if verbose: - print "locker ID: %s" % anID - lock = self.env.lock_get(anID, "some locked thing", db.DB_LOCK_WRITE) - if verbose: - print "Aquired lock: %s" % lock - self.env.lock_put(lock) - if verbose: - print "Released lock: %s" % lock - self.env.lock_id_free(anID) - - - def test02_threaded(self): - if verbose: - print '\n', '-=' * 30 - print "Running %s.test02_threaded..." % self.__class__.__name__ - - threads = [] - threads.append(Thread(target = self.theThread, - args=(db.DB_LOCK_WRITE,))) - threads.append(Thread(target = self.theThread, - args=(db.DB_LOCK_READ,))) - threads.append(Thread(target = self.theThread, - args=(db.DB_LOCK_READ,))) - threads.append(Thread(target = self.theThread, - args=(db.DB_LOCK_WRITE,))) - threads.append(Thread(target = self.theThread, - args=(db.DB_LOCK_READ,))) - threads.append(Thread(target = self.theThread, - args=(db.DB_LOCK_READ,))) - threads.append(Thread(target = self.theThread, - args=(db.DB_LOCK_WRITE,))) - threads.append(Thread(target = self.theThread, - args=(db.DB_LOCK_WRITE,))) - threads.append(Thread(target = self.theThread, - args=(db.DB_LOCK_WRITE,))) - - for t in threads: - import sys - if sys.version_info[0] < 3 : - t.setDaemon(True) - else : - t.daemon = True - t.start() - for t in threads: - t.join() - - def test03_lock_timeout(self): - self.env.set_timeout(0, db.DB_SET_LOCK_TIMEOUT) - self.assertEqual(self.env.get_timeout(db.DB_SET_LOCK_TIMEOUT), 0) - self.env.set_timeout(0, db.DB_SET_TXN_TIMEOUT) - self.assertEqual(self.env.get_timeout(db.DB_SET_TXN_TIMEOUT), 0) - self.env.set_timeout(123456, db.DB_SET_LOCK_TIMEOUT) - self.assertEqual(self.env.get_timeout(db.DB_SET_LOCK_TIMEOUT), 123456) - self.env.set_timeout(7890123, db.DB_SET_TXN_TIMEOUT) - self.assertEqual(self.env.get_timeout(db.DB_SET_TXN_TIMEOUT), 7890123) - - def test04_lock_timeout2(self): - self.env.set_timeout(0, db.DB_SET_LOCK_TIMEOUT) - self.env.set_timeout(0, db.DB_SET_TXN_TIMEOUT) - self.env.set_timeout(123456, db.DB_SET_LOCK_TIMEOUT) - self.env.set_timeout(7890123, db.DB_SET_TXN_TIMEOUT) - - def deadlock_detection() : - while not deadlock_detection.end : - deadlock_detection.count = \ - self.env.lock_detect(db.DB_LOCK_EXPIRE) - if deadlock_detection.count : - while not deadlock_detection.end : - pass - break - time.sleep(0.01) - - deadlock_detection.end=False - deadlock_detection.count=0 - t=Thread(target=deadlock_detection) - import sys - if sys.version_info[0] < 3 : - t.setDaemon(True) - else : - t.daemon = True - t.start() - self.env.set_timeout(100000, db.DB_SET_LOCK_TIMEOUT) - anID = self.env.lock_id() - anID2 = self.env.lock_id() - self.assertNotEqual(anID, anID2) - lock = self.env.lock_get(anID, "shared lock", db.DB_LOCK_WRITE) - start_time=time.time() - self.assertRaises(db.DBLockNotGrantedError, - self.env.lock_get,anID2, "shared lock", db.DB_LOCK_READ) - end_time=time.time() - deadlock_detection.end=True - # Floating point rounding - self.assertTrue((end_time-start_time) >= 0.0999) - self.env.lock_put(lock) - t.join() - - self.env.lock_id_free(anID) - self.env.lock_id_free(anID2) - - if db.version() >= (4,6): - self.assertTrue(deadlock_detection.count>0) - - def theThread(self, lockType): - import sys - if sys.version_info[0] < 3 : - name = currentThread().getName() - else : - name = currentThread().name - - if lockType == db.DB_LOCK_WRITE: - lt = "write" - else: - lt = "read" - - anID = self.env.lock_id() - if verbose: - print "%s: locker ID: %s" % (name, anID) - - for i in xrange(1000) : - lock = self.env.lock_get(anID, "some locked thing", lockType) - if verbose: - print "%s: Aquired %s lock: %s" % (name, lt, lock) - - self.env.lock_put(lock) - if verbose: - print "%s: Released %s lock: %s" % (name, lt, lock) - - self.env.lock_id_free(anID) - - -#---------------------------------------------------------------------- - -def test_suite(): - suite = unittest.TestSuite() - - if have_threads: - suite.addTest(unittest.makeSuite(LockingTestCase)) - else: - suite.addTest(unittest.makeSuite(LockingTestCase, 'test01')) - - return suite - - -if __name__ == '__main__': - unittest.main(defaultTest='test_suite') diff --git a/PythonLib/extra/bsddb/test/test_misc.py b/PythonLib/extra/bsddb/test/test_misc.py deleted file mode 100644 index b1e928f5..00000000 --- a/PythonLib/extra/bsddb/test/test_misc.py +++ /dev/null @@ -1,138 +0,0 @@ -"""Miscellaneous bsddb module test cases -""" - -import os, sys -import unittest - -from test_all import db, dbshelve, hashopen, test_support, get_new_environment_path, get_new_database_path - -#---------------------------------------------------------------------- - -class MiscTestCase(unittest.TestCase): - def setUp(self): - self.filename = get_new_database_path() - self.homeDir = get_new_environment_path() - - def tearDown(self): - test_support.unlink(self.filename) - test_support.rmtree(self.homeDir) - - def test01_badpointer(self): - dbs = dbshelve.open(self.filename) - dbs.close() - self.assertRaises(db.DBError, dbs.get, "foo") - - def test02_db_home(self): - env = db.DBEnv() - # check for crash fixed when db_home is used before open() - self.assertTrue(env.db_home is None) - env.open(self.homeDir, db.DB_CREATE) - if sys.version_info[0] < 3 : - self.assertEqual(self.homeDir, env.db_home) - else : - self.assertEqual(bytes(self.homeDir, "ascii"), env.db_home) - - def test03_repr_closed_db(self): - db = hashopen(self.filename) - db.close() - rp = repr(db) - self.assertEqual(rp, "{}") - - def test04_repr_db(self) : - db = hashopen(self.filename) - d = {} - for i in xrange(100) : - db[repr(i)] = repr(100*i) - d[repr(i)] = repr(100*i) - db.close() - db = hashopen(self.filename) - rp = repr(db) - self.assertEqual(rp, repr(d)) - db.close() - - # http://sourceforge.net/tracker/index.php?func=detail&aid=1708868&group_id=13900&atid=313900 - # - # See the bug report for details. - # - # The problem was that make_key_dbt() was not allocating a copy of - # string keys but FREE_DBT() was always being told to free it when the - # database was opened with DB_THREAD. - def test05_double_free_make_key_dbt(self): - try: - db1 = db.DB() - db1.open(self.filename, None, db.DB_BTREE, - db.DB_CREATE | db.DB_THREAD) - - curs = db1.cursor() - t = curs.get("/foo", db.DB_SET) - # double free happened during exit from DBC_get - finally: - db1.close() - test_support.unlink(self.filename) - - def test06_key_with_null_bytes(self): - try: - db1 = db.DB() - db1.open(self.filename, None, db.DB_HASH, db.DB_CREATE) - db1['a'] = 'eh?' - db1['a\x00'] = 'eh zed.' - db1['a\x00a'] = 'eh zed eh?' - db1['aaa'] = 'eh eh eh!' - keys = db1.keys() - keys.sort() - self.assertEqual(['a', 'a\x00', 'a\x00a', 'aaa'], keys) - self.assertEqual(db1['a'], 'eh?') - self.assertEqual(db1['a\x00'], 'eh zed.') - self.assertEqual(db1['a\x00a'], 'eh zed eh?') - self.assertEqual(db1['aaa'], 'eh eh eh!') - finally: - db1.close() - test_support.unlink(self.filename) - - def test07_DB_set_flags_persists(self): - try: - db1 = db.DB() - db1.set_flags(db.DB_DUPSORT) - db1.open(self.filename, db.DB_HASH, db.DB_CREATE) - db1['a'] = 'eh' - db1['a'] = 'A' - self.assertEqual([('a', 'A')], db1.items()) - db1.put('a', 'Aa') - self.assertEqual([('a', 'A'), ('a', 'Aa')], db1.items()) - db1.close() - db1 = db.DB() - # no set_flags call, we're testing that it reads and obeys - # the flags on open. - db1.open(self.filename, db.DB_HASH) - self.assertEqual([('a', 'A'), ('a', 'Aa')], db1.items()) - # if it read the flags right this will replace all values - # for key 'a' instead of adding a new one. (as a dict should) - db1['a'] = 'new A' - self.assertEqual([('a', 'new A')], db1.items()) - finally: - db1.close() - test_support.unlink(self.filename) - - - def test08_ExceptionTypes(self) : - self.assertTrue(issubclass(db.DBError, Exception)) - for i, j in db.__dict__.items() : - if i.startswith("DB") and i.endswith("Error") : - self.assertTrue(issubclass(j, db.DBError), msg=i) - if i not in ("DBKeyEmptyError", "DBNotFoundError") : - self.assertFalse(issubclass(j, KeyError), msg=i) - - # This two exceptions have two bases - self.assertTrue(issubclass(db.DBKeyEmptyError, KeyError)) - self.assertTrue(issubclass(db.DBNotFoundError, KeyError)) - - -#---------------------------------------------------------------------- - - -def test_suite(): - return unittest.makeSuite(MiscTestCase) - - -if __name__ == '__main__': - unittest.main(defaultTest='test_suite') diff --git a/PythonLib/extra/bsddb/test/test_pickle.py b/PythonLib/extra/bsddb/test/test_pickle.py deleted file mode 100644 index 6a8478d5..00000000 --- a/PythonLib/extra/bsddb/test/test_pickle.py +++ /dev/null @@ -1,68 +0,0 @@ - -import os -import pickle -import sys - -if sys.version_info[0] < 3 : - try: - import cPickle - except ImportError: - cPickle = None -else : - cPickle = None - -import unittest - -from test_all import db, test_support, get_new_environment_path, get_new_database_path - -#---------------------------------------------------------------------- - -class pickleTestCase(unittest.TestCase): - """Verify that DBError can be pickled and unpickled""" - db_name = 'test-dbobj.db' - - def setUp(self): - self.homeDir = get_new_environment_path() - - def tearDown(self): - if hasattr(self, 'db'): - del self.db - if hasattr(self, 'env'): - del self.env - test_support.rmtree(self.homeDir) - - def _base_test_pickle_DBError(self, pickle): - self.env = db.DBEnv() - self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL) - self.db = db.DB(self.env) - self.db.open(self.db_name, db.DB_HASH, db.DB_CREATE) - self.db.put('spam', 'eggs') - self.assertEqual(self.db['spam'], 'eggs') - try: - self.db.put('spam', 'ham', flags=db.DB_NOOVERWRITE) - except db.DBError, egg: - pickledEgg = pickle.dumps(egg) - #print repr(pickledEgg) - rottenEgg = pickle.loads(pickledEgg) - if rottenEgg.args != egg.args or type(rottenEgg) != type(egg): - raise Exception, (rottenEgg, '!=', egg) - else: - raise Exception, "where's my DBError exception?!?" - - self.db.close() - self.env.close() - - def test01_pickle_DBError(self): - self._base_test_pickle_DBError(pickle=pickle) - - if cPickle: - def test02_cPickle_DBError(self): - self._base_test_pickle_DBError(pickle=cPickle) - -#---------------------------------------------------------------------- - -def test_suite(): - return unittest.makeSuite(pickleTestCase) - -if __name__ == '__main__': - unittest.main(defaultTest='test_suite') diff --git a/PythonLib/extra/bsddb/test/test_queue.py b/PythonLib/extra/bsddb/test/test_queue.py deleted file mode 100644 index c213ff41..00000000 --- a/PythonLib/extra/bsddb/test/test_queue.py +++ /dev/null @@ -1,163 +0,0 @@ -""" -TestCases for exercising a Queue DB. -""" - -import os, string -from pprint import pprint -import unittest - -from test_all import db, verbose, get_new_database_path - -#---------------------------------------------------------------------- - -class SimpleQueueTestCase(unittest.TestCase): - def setUp(self): - self.filename = get_new_database_path() - - def tearDown(self): - try: - os.remove(self.filename) - except os.error: - pass - - - def test01_basic(self): - # Basic Queue tests using the deprecated DBCursor.consume method. - - if verbose: - print '\n', '-=' * 30 - print "Running %s.test01_basic..." % self.__class__.__name__ - - d = db.DB() - d.set_re_len(40) # Queues must be fixed length - d.open(self.filename, db.DB_QUEUE, db.DB_CREATE) - - if verbose: - print "before appends" + '-' * 30 - pprint(d.stat()) - - for x in string.letters: - d.append(x * 40) - - self.assertEqual(len(d), len(string.letters)) - - d.put(100, "some more data") - d.put(101, "and some more ") - d.put(75, "out of order") - d.put(1, "replacement data") - - self.assertEqual(len(d), len(string.letters)+3) - - if verbose: - print "before close" + '-' * 30 - pprint(d.stat()) - - d.close() - del d - d = db.DB() - d.open(self.filename) - - if verbose: - print "after open" + '-' * 30 - pprint(d.stat()) - - # Test "txn" as a positional parameter - d.append("one more", None) - # Test "txn" as a keyword parameter - d.append("another one", txn=None) - - c = d.cursor() - - if verbose: - print "after append" + '-' * 30 - pprint(d.stat()) - - rec = c.consume() - while rec: - if verbose: - print rec - rec = c.consume() - c.close() - - if verbose: - print "after consume loop" + '-' * 30 - pprint(d.stat()) - - self.assertEqual(len(d), 0, \ - "if you see this message then you need to rebuild " \ - "Berkeley DB 3.1.17 with the patch in patches/qam_stat.diff") - - d.close() - - - - def test02_basicPost32(self): - # Basic Queue tests using the new DB.consume method in DB 3.2+ - # (No cursor needed) - - if verbose: - print '\n', '-=' * 30 - print "Running %s.test02_basicPost32..." % self.__class__.__name__ - - d = db.DB() - d.set_re_len(40) # Queues must be fixed length - d.open(self.filename, db.DB_QUEUE, db.DB_CREATE) - - if verbose: - print "before appends" + '-' * 30 - pprint(d.stat()) - - for x in string.letters: - d.append(x * 40) - - self.assertEqual(len(d), len(string.letters)) - - d.put(100, "some more data") - d.put(101, "and some more ") - d.put(75, "out of order") - d.put(1, "replacement data") - - self.assertEqual(len(d), len(string.letters)+3) - - if verbose: - print "before close" + '-' * 30 - pprint(d.stat()) - - d.close() - del d - d = db.DB() - d.open(self.filename) - #d.set_get_returns_none(true) - - if verbose: - print "after open" + '-' * 30 - pprint(d.stat()) - - d.append("one more") - - if verbose: - print "after append" + '-' * 30 - pprint(d.stat()) - - rec = d.consume() - while rec: - if verbose: - print rec - rec = d.consume() - - if verbose: - print "after consume loop" + '-' * 30 - pprint(d.stat()) - - d.close() - - - -#---------------------------------------------------------------------- - -def test_suite(): - return unittest.makeSuite(SimpleQueueTestCase) - - -if __name__ == '__main__': - unittest.main(defaultTest='test_suite') diff --git a/PythonLib/extra/bsddb/test/test_recno.py b/PythonLib/extra/bsddb/test/test_recno.py deleted file mode 100644 index fb6956ae..00000000 --- a/PythonLib/extra/bsddb/test/test_recno.py +++ /dev/null @@ -1,320 +0,0 @@ -"""TestCases for exercising a Recno DB. -""" - -import os, sys -import errno -from pprint import pprint -import unittest - -from test_all import db, test_support, verbose, get_new_environment_path, get_new_database_path - -letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' - - -#---------------------------------------------------------------------- - -class SimpleRecnoTestCase(unittest.TestCase): - if (sys.version_info < (2, 7)) or ((sys.version_info >= (3, 0)) and - (sys.version_info < (3, 2))) : - def assertIsInstance(self, obj, datatype, msg=None) : - return self.assertEqual(type(obj), datatype, msg=msg) - def assertGreaterEqual(self, a, b, msg=None) : - return self.assertTrue(a>=b, msg=msg) - - - def setUp(self): - self.filename = get_new_database_path() - self.homeDir = None - - def tearDown(self): - test_support.unlink(self.filename) - if self.homeDir: - test_support.rmtree(self.homeDir) - - def test01_basic(self): - d = db.DB() - - get_returns_none = d.set_get_returns_none(2) - d.set_get_returns_none(get_returns_none) - - d.open(self.filename, db.DB_RECNO, db.DB_CREATE) - - for x in letters: - recno = d.append(x * 60) - self.assertIsInstance(recno, int) - self.assertGreaterEqual(recno, 1) - if verbose: - print recno, - - if verbose: print - - stat = d.stat() - if verbose: - pprint(stat) - - for recno in range(1, len(d)+1): - data = d[recno] - if verbose: - print data - - self.assertIsInstance(data, str) - self.assertEqual(data, d.get(recno)) - - try: - data = d[0] # This should raise a KeyError!?!?! - except db.DBInvalidArgError, val: - if sys.version_info < (2, 6) : - self.assertEqual(val[0], db.EINVAL) - else : - self.assertEqual(val.args[0], db.EINVAL) - if verbose: print val - else: - self.fail("expected exception") - - # test that has_key raises DB exceptions (fixed in pybsddb 4.3.2) - try: - d.has_key(0) - except db.DBError, val: - pass - else: - self.fail("has_key did not raise a proper exception") - - try: - data = d[100] - except KeyError: - pass - else: - self.fail("expected exception") - - try: - data = d.get(100) - except db.DBNotFoundError, val: - if get_returns_none: - self.fail("unexpected exception") - else: - self.assertEqual(data, None) - - keys = d.keys() - if verbose: - print keys - self.assertIsInstance(keys, list) - self.assertIsInstance(keys[0], int) - self.assertEqual(len(keys), len(d)) - - items = d.items() - if verbose: - pprint(items) - self.assertIsInstance(items, list) - self.assertIsInstance(items[0], tuple) - self.assertEqual(len(items[0]), 2) - self.assertIsInstance(items[0][0], int) - self.assertIsInstance(items[0][1], str) - self.assertEqual(len(items), len(d)) - - self.assertTrue(d.has_key(25)) - - del d[25] - self.assertFalse(d.has_key(25)) - - d.delete(13) - self.assertFalse(d.has_key(13)) - - data = d.get_both(26, "z" * 60) - self.assertEqual(data, "z" * 60, 'was %r' % data) - if verbose: - print data - - fd = d.fd() - if verbose: - print fd - - c = d.cursor() - rec = c.first() - while rec: - if verbose: - print rec - rec = c.next() - - c.set(50) - rec = c.current() - if verbose: - print rec - - c.put(-1, "a replacement record", db.DB_CURRENT) - - c.set(50) - rec = c.current() - self.assertEqual(rec, (50, "a replacement record")) - if verbose: - print rec - - rec = c.set_range(30) - if verbose: - print rec - - # test that non-existent key lookups work (and that - # DBC_set_range doesn't have a memleak under valgrind) - rec = c.set_range(999999) - self.assertEqual(rec, None) - if verbose: - print rec - - c.close() - d.close() - - d = db.DB() - d.open(self.filename) - c = d.cursor() - - # put a record beyond the consecutive end of the recno's - d[100] = "way out there" - self.assertEqual(d[100], "way out there") - - try: - data = d[99] - except KeyError: - pass - else: - self.fail("expected exception") - - try: - d.get(99) - except db.DBKeyEmptyError, val: - if get_returns_none: - self.fail("unexpected DBKeyEmptyError exception") - else: - if sys.version_info < (2, 6) : - self.assertEqual(val[0], db.DB_KEYEMPTY) - else : - self.assertEqual(val.args[0], db.DB_KEYEMPTY) - if verbose: print val - else: - if not get_returns_none: - self.fail("expected exception") - - rec = c.set(40) - while rec: - if verbose: - print rec - rec = c.next() - - c.close() - d.close() - - def test02_WithSource(self): - """ - A Recno file that is given a "backing source file" is essentially a - simple ASCII file. Normally each record is delimited by \n and so is - just a line in the file, but you can set a different record delimiter - if needed. - """ - homeDir = get_new_environment_path() - self.homeDir = homeDir - source = os.path.join(homeDir, 'test_recno.txt') - if not os.path.isdir(homeDir): - os.mkdir(homeDir) - f = open(source, 'w') # create the file - f.close() - - d = db.DB() - # This is the default value, just checking if both int - d.set_re_delim(0x0A) - d.set_re_delim('\n') # and char can be used... - d.set_re_source(source) - d.open(self.filename, db.DB_RECNO, db.DB_CREATE) - - data = "The quick brown fox jumped over the lazy dog".split() - for datum in data: - d.append(datum) - d.sync() - d.close() - - # get the text from the backing source - f = open(source, 'r') - text = f.read() - f.close() - text = text.strip() - if verbose: - print text - print data - print text.split('\n') - - self.assertEqual(text.split('\n'), data) - - # open as a DB again - d = db.DB() - d.set_re_source(source) - d.open(self.filename, db.DB_RECNO) - - d[3] = 'reddish-brown' - d[8] = 'comatose' - - d.sync() - d.close() - - f = open(source, 'r') - text = f.read() - f.close() - text = text.strip() - if verbose: - print text - print text.split('\n') - - self.assertEqual(text.split('\n'), - "The quick reddish-brown fox jumped over the comatose dog".split()) - - def test03_FixedLength(self): - d = db.DB() - d.set_re_len(40) # fixed length records, 40 bytes long - d.set_re_pad('-') # sets the pad character... - d.set_re_pad(45) # ...test both int and char - d.open(self.filename, db.DB_RECNO, db.DB_CREATE) - - for x in letters: - d.append(x * 35) # These will be padded - - d.append('.' * 40) # this one will be exact - - try: # this one will fail - d.append('bad' * 20) - except db.DBInvalidArgError, val: - if sys.version_info < (2, 6) : - self.assertEqual(val[0], db.EINVAL) - else : - self.assertEqual(val.args[0], db.EINVAL) - if verbose: print val - else: - self.fail("expected exception") - - c = d.cursor() - rec = c.first() - while rec: - if verbose: - print rec - rec = c.next() - - c.close() - d.close() - - def test04_get_size_empty(self) : - d = db.DB() - d.open(self.filename, dbtype=db.DB_RECNO, flags=db.DB_CREATE) - - row_id = d.append(' ') - self.assertEqual(1, d.get_size(key=row_id)) - row_id = d.append('') - self.assertEqual(0, d.get_size(key=row_id)) - - - - - -#---------------------------------------------------------------------- - - -def test_suite(): - return unittest.makeSuite(SimpleRecnoTestCase) - - -if __name__ == '__main__': - unittest.main(defaultTest='test_suite') diff --git a/PythonLib/extra/bsddb/test/test_replication.py b/PythonLib/extra/bsddb/test/test_replication.py deleted file mode 100644 index 12ab2dd8..00000000 --- a/PythonLib/extra/bsddb/test/test_replication.py +++ /dev/null @@ -1,543 +0,0 @@ -"""TestCases for distributed transactions. -""" - -import os -import time -import unittest - -from test_all import db, test_support, have_threads, verbose, \ - get_new_environment_path, get_new_database_path - - -#---------------------------------------------------------------------- - -class DBReplication(unittest.TestCase) : - def setUp(self) : - self.homeDirMaster = get_new_environment_path() - self.homeDirClient = get_new_environment_path() - - self.dbenvMaster = db.DBEnv() - self.dbenvClient = db.DBEnv() - - # Must use "DB_THREAD" because the Replication Manager will - # be executed in other threads but will use the same environment. - # http://forums.oracle.com/forums/thread.jspa?threadID=645788&tstart=0 - self.dbenvMaster.open(self.homeDirMaster, db.DB_CREATE | db.DB_INIT_TXN - | db.DB_INIT_LOG | db.DB_INIT_MPOOL | db.DB_INIT_LOCK | - db.DB_INIT_REP | db.DB_RECOVER | db.DB_THREAD, 0666) - self.dbenvClient.open(self.homeDirClient, db.DB_CREATE | db.DB_INIT_TXN - | db.DB_INIT_LOG | db.DB_INIT_MPOOL | db.DB_INIT_LOCK | - db.DB_INIT_REP | db.DB_RECOVER | db.DB_THREAD, 0666) - - self.confirmed_master=self.client_startupdone=False - def confirmed_master(a,b,c) : - if b==db.DB_EVENT_REP_MASTER : - self.confirmed_master=True - - def client_startupdone(a,b,c) : - if b==db.DB_EVENT_REP_STARTUPDONE : - self.client_startupdone=True - - self.dbenvMaster.set_event_notify(confirmed_master) - self.dbenvClient.set_event_notify(client_startupdone) - - #self.dbenvMaster.set_verbose(db.DB_VERB_REPLICATION, True) - #self.dbenvMaster.set_verbose(db.DB_VERB_FILEOPS_ALL, True) - #self.dbenvClient.set_verbose(db.DB_VERB_REPLICATION, True) - #self.dbenvClient.set_verbose(db.DB_VERB_FILEOPS_ALL, True) - - self.dbMaster = self.dbClient = None - - - def tearDown(self): - if self.dbClient : - self.dbClient.close() - if self.dbMaster : - self.dbMaster.close() - - # Here we assign dummy event handlers to allow GC of the test object. - # Since the dummy handler doesn't use any outer scope variable, it - # doesn't keep any reference to the test object. - def dummy(*args) : - pass - self.dbenvMaster.set_event_notify(dummy) - self.dbenvClient.set_event_notify(dummy) - - self.dbenvClient.close() - self.dbenvMaster.close() - test_support.rmtree(self.homeDirClient) - test_support.rmtree(self.homeDirMaster) - -class DBReplicationManager(DBReplication) : - def test01_basic_replication(self) : - master_port = test_support.find_unused_port() - client_port = test_support.find_unused_port() - if db.version() >= (5, 2) : - self.site = self.dbenvMaster.repmgr_site("127.0.0.1", master_port) - self.site.set_config(db.DB_GROUP_CREATOR, True) - self.site.set_config(db.DB_LOCAL_SITE, True) - self.site2 = self.dbenvMaster.repmgr_site("127.0.0.1", client_port) - - self.site3 = self.dbenvClient.repmgr_site("127.0.0.1", master_port) - self.site3.set_config(db.DB_BOOTSTRAP_HELPER, True) - self.site4 = self.dbenvClient.repmgr_site("127.0.0.1", client_port) - self.site4.set_config(db.DB_LOCAL_SITE, True) - - d = { - db.DB_BOOTSTRAP_HELPER: [False, False, True, False], - db.DB_GROUP_CREATOR: [True, False, False, False], - db.DB_LEGACY: [False, False, False, False], - db.DB_LOCAL_SITE: [True, False, False, True], - db.DB_REPMGR_PEER: [False, False, False, False ], - } - - for i, j in d.items() : - for k, v in \ - zip([self.site, self.site2, self.site3, self.site4], j) : - if v : - self.assertTrue(k.get_config(i)) - else : - self.assertFalse(k.get_config(i)) - - self.assertNotEqual(self.site.get_eid(), self.site2.get_eid()) - self.assertNotEqual(self.site3.get_eid(), self.site4.get_eid()) - - for i, j in zip([self.site, self.site2, self.site3, self.site4], \ - [master_port, client_port, master_port, client_port]) : - addr = i.get_address() - self.assertEqual(addr, ("127.0.0.1", j)) - - for i in [self.site, self.site2] : - self.assertEqual(i.get_address(), - self.dbenvMaster.repmgr_site_by_eid(i.get_eid()).get_address()) - for i in [self.site3, self.site4] : - self.assertEqual(i.get_address(), - self.dbenvClient.repmgr_site_by_eid(i.get_eid()).get_address()) - else : - self.dbenvMaster.repmgr_set_local_site("127.0.0.1", master_port) - self.dbenvClient.repmgr_set_local_site("127.0.0.1", client_port) - self.dbenvMaster.repmgr_add_remote_site("127.0.0.1", client_port) - self.dbenvClient.repmgr_add_remote_site("127.0.0.1", master_port) - - self.dbenvMaster.rep_set_nsites(2) - self.dbenvClient.rep_set_nsites(2) - - self.dbenvMaster.rep_set_priority(10) - self.dbenvClient.rep_set_priority(0) - - self.dbenvMaster.rep_set_timeout(db.DB_REP_CONNECTION_RETRY,100123) - self.dbenvClient.rep_set_timeout(db.DB_REP_CONNECTION_RETRY,100321) - self.assertEqual(self.dbenvMaster.rep_get_timeout( - db.DB_REP_CONNECTION_RETRY), 100123) - self.assertEqual(self.dbenvClient.rep_get_timeout( - db.DB_REP_CONNECTION_RETRY), 100321) - - self.dbenvMaster.rep_set_timeout(db.DB_REP_ELECTION_TIMEOUT, 100234) - self.dbenvClient.rep_set_timeout(db.DB_REP_ELECTION_TIMEOUT, 100432) - self.assertEqual(self.dbenvMaster.rep_get_timeout( - db.DB_REP_ELECTION_TIMEOUT), 100234) - self.assertEqual(self.dbenvClient.rep_get_timeout( - db.DB_REP_ELECTION_TIMEOUT), 100432) - - self.dbenvMaster.rep_set_timeout(db.DB_REP_ELECTION_RETRY, 100345) - self.dbenvClient.rep_set_timeout(db.DB_REP_ELECTION_RETRY, 100543) - self.assertEqual(self.dbenvMaster.rep_get_timeout( - db.DB_REP_ELECTION_RETRY), 100345) - self.assertEqual(self.dbenvClient.rep_get_timeout( - db.DB_REP_ELECTION_RETRY), 100543) - - self.dbenvMaster.repmgr_set_ack_policy(db.DB_REPMGR_ACKS_ALL) - self.dbenvClient.repmgr_set_ack_policy(db.DB_REPMGR_ACKS_ALL) - - self.dbenvMaster.repmgr_start(1, db.DB_REP_MASTER); - self.dbenvClient.repmgr_start(1, db.DB_REP_CLIENT); - - self.assertEqual(self.dbenvMaster.rep_get_nsites(),2) - self.assertEqual(self.dbenvClient.rep_get_nsites(),2) - self.assertEqual(self.dbenvMaster.rep_get_priority(),10) - self.assertEqual(self.dbenvClient.rep_get_priority(),0) - self.assertEqual(self.dbenvMaster.repmgr_get_ack_policy(), - db.DB_REPMGR_ACKS_ALL) - self.assertEqual(self.dbenvClient.repmgr_get_ack_policy(), - db.DB_REPMGR_ACKS_ALL) - - # The timeout is necessary in BDB 4.5, since DB_EVENT_REP_STARTUPDONE - # is not generated if the master has no new transactions. - # This is solved in BDB 4.6 (#15542). - import time - timeout = time.time()+60 - while (time.time()timeout: - import sys - print >> sys.stderr, ("XXX: timeout happened before" - "startup was confirmed - see issue 3892") - startup_timeout = True - - d = self.dbenvMaster.repmgr_site_list() - self.assertEqual(len(d), 1) - d = d.values()[0] # There is only one - self.assertEqual(d[0], "127.0.0.1") - self.assertEqual(d[1], client_port) - self.assertTrue((d[2]==db.DB_REPMGR_CONNECTED) or \ - (d[2]==db.DB_REPMGR_DISCONNECTED)) - - d = self.dbenvClient.repmgr_site_list() - self.assertEqual(len(d), 1) - d = d.values()[0] # There is only one - self.assertEqual(d[0], "127.0.0.1") - self.assertEqual(d[1], master_port) - self.assertTrue((d[2]==db.DB_REPMGR_CONNECTED) or \ - (d[2]==db.DB_REPMGR_DISCONNECTED)) - - if db.version() >= (4,6) : - d = self.dbenvMaster.repmgr_stat(flags=db.DB_STAT_CLEAR); - self.assertTrue("msgs_queued" in d) - - self.dbMaster=db.DB(self.dbenvMaster) - txn=self.dbenvMaster.txn_begin() - self.dbMaster.open("test", db.DB_HASH, db.DB_CREATE, 0666, txn=txn) - txn.commit() - - import time,os.path - timeout=time.time()+10 - while (time.time()=timeout and startup_timeout: - self.skipTest("replication test skipped due to random failure, " - "see issue 3892") - self.assertTrue(time.time()= (4,7) : - def test02_test_request(self) : - self.basic_rep_threading() - (minimum, maximum) = self.dbenvClient.rep_get_request() - self.dbenvClient.rep_set_request(minimum-1, maximum+1) - self.assertEqual(self.dbenvClient.rep_get_request(), - (minimum-1, maximum+1)) - - if db.version() >= (4,6) : - def test03_master_election(self) : - # Get ready to hold an election - #self.dbenvMaster.rep_start(flags=db.DB_REP_MASTER) - self.dbenvMaster.rep_start(flags=db.DB_REP_CLIENT) - self.dbenvClient.rep_start(flags=db.DB_REP_CLIENT) - - def thread_do(env, q, envid, election_status, must_be_master) : - while True : - v=q.get() - if v is None : return - r = env.rep_process_message(v[0],v[1],envid) - if must_be_master and self.confirmed_master : - self.dbenvMaster.rep_start(flags = db.DB_REP_MASTER) - must_be_master = False - - if r[0] == db.DB_REP_HOLDELECTION : - def elect() : - while True : - try : - env.rep_elect(2, 1) - election_status[0] = False - break - except db.DBRepUnavailError : - pass - if not election_status[0] and not self.confirmed_master : - from threading import Thread - election_status[0] = True - t=Thread(target=elect) - import sys - if sys.version_info[0] < 3 : - t.setDaemon(True) - else : - t.daemon = True - t.start() - - self.thread_do = thread_do - - self.t_m.start() - self.t_c.start() - - self.dbenvMaster.rep_set_timeout(db.DB_REP_ELECTION_TIMEOUT, 50000) - self.dbenvClient.rep_set_timeout(db.DB_REP_ELECTION_TIMEOUT, 50000) - self.client_doing_election[0] = True - while True : - try : - self.dbenvClient.rep_elect(2, 1) - self.client_doing_election[0] = False - break - except db.DBRepUnavailError : - pass - - self.assertTrue(self.confirmed_master) - - # Race condition showed up after upgrading to Solaris 10 Update 10 - # https://forums.oracle.com/forums/thread.jspa?messageID=9902860 - # jcea@jcea.es: See private email from Paula Bingham (Oracle), - # in 20110929. - while not (self.dbenvClient.rep_stat()["startup_complete"]) : - pass - - if db.version() >= (4,7) : - def test04_test_clockskew(self) : - fast, slow = 1234, 1230 - self.dbenvMaster.rep_set_clockskew(fast, slow) - self.assertEqual((fast, slow), - self.dbenvMaster.rep_get_clockskew()) - self.basic_rep_threading() - -#---------------------------------------------------------------------- - -def test_suite(): - suite = unittest.TestSuite() - if db.version() >= (4, 6) : - dbenv = db.DBEnv() - try : - dbenv.repmgr_get_ack_policy() - ReplicationManager_available=True - except : - ReplicationManager_available=False - dbenv.close() - del dbenv - if ReplicationManager_available : - suite.addTest(unittest.makeSuite(DBReplicationManager)) - - if have_threads : - suite.addTest(unittest.makeSuite(DBBaseReplication)) - - return suite - - -if __name__ == '__main__': - unittest.main(defaultTest='test_suite') diff --git a/PythonLib/extra/bsddb/test/test_sequence.py b/PythonLib/extra/bsddb/test/test_sequence.py deleted file mode 100644 index f0aa12a8..00000000 --- a/PythonLib/extra/bsddb/test/test_sequence.py +++ /dev/null @@ -1,136 +0,0 @@ -import unittest -import os - -from test_all import db, test_support, get_new_environment_path, get_new_database_path - - -class DBSequenceTest(unittest.TestCase): - def setUp(self): - self.int_32_max = 0x100000000 - self.homeDir = get_new_environment_path() - self.filename = "test" - - self.dbenv = db.DBEnv() - self.dbenv.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL, 0666) - self.d = db.DB(self.dbenv) - self.d.open(self.filename, db.DB_BTREE, db.DB_CREATE, 0666) - - def tearDown(self): - if hasattr(self, 'seq'): - self.seq.close() - del self.seq - if hasattr(self, 'd'): - self.d.close() - del self.d - if hasattr(self, 'dbenv'): - self.dbenv.close() - del self.dbenv - - test_support.rmtree(self.homeDir) - - def test_get(self): - self.seq = db.DBSequence(self.d, flags=0) - start_value = 10 * self.int_32_max - self.assertEqual(0xA00000000, start_value) - self.assertEqual(None, self.seq.initial_value(start_value)) - self.assertEqual(None, self.seq.open(key='id', txn=None, flags=db.DB_CREATE)) - self.assertEqual(start_value, self.seq.get(5)) - self.assertEqual(start_value + 5, self.seq.get()) - - def test_remove(self): - self.seq = db.DBSequence(self.d, flags=0) - self.assertEqual(None, self.seq.open(key='foo', txn=None, flags=db.DB_CREATE)) - self.assertEqual(None, self.seq.remove(txn=None, flags=0)) - del self.seq - - def test_get_key(self): - self.seq = db.DBSequence(self.d, flags=0) - key = 'foo' - self.assertEqual(None, self.seq.open(key=key, txn=None, flags=db.DB_CREATE)) - self.assertEqual(key, self.seq.get_key()) - - def test_get_dbp(self): - self.seq = db.DBSequence(self.d, flags=0) - self.assertEqual(None, self.seq.open(key='foo', txn=None, flags=db.DB_CREATE)) - self.assertEqual(self.d, self.seq.get_dbp()) - - def test_cachesize(self): - self.seq = db.DBSequence(self.d, flags=0) - cashe_size = 10 - self.assertEqual(None, self.seq.set_cachesize(cashe_size)) - self.assertEqual(None, self.seq.open(key='foo', txn=None, flags=db.DB_CREATE)) - self.assertEqual(cashe_size, self.seq.get_cachesize()) - - def test_flags(self): - self.seq = db.DBSequence(self.d, flags=0) - flag = db.DB_SEQ_WRAP; - self.assertEqual(None, self.seq.set_flags(flag)) - self.assertEqual(None, self.seq.open(key='foo', txn=None, flags=db.DB_CREATE)) - self.assertEqual(flag, self.seq.get_flags() & flag) - - def test_range(self): - self.seq = db.DBSequence(self.d, flags=0) - seq_range = (10 * self.int_32_max, 11 * self.int_32_max - 1) - self.assertEqual(None, self.seq.set_range(seq_range)) - self.seq.initial_value(seq_range[0]) - self.assertEqual(None, self.seq.open(key='foo', txn=None, flags=db.DB_CREATE)) - self.assertEqual(seq_range, self.seq.get_range()) - - def test_stat(self): - self.seq = db.DBSequence(self.d, flags=0) - self.assertEqual(None, self.seq.open(key='foo', txn=None, flags=db.DB_CREATE)) - stat = self.seq.stat() - for param in ('nowait', 'min', 'max', 'value', 'current', - 'flags', 'cache_size', 'last_value', 'wait'): - self.assertTrue(param in stat, "parameter %s isn't in stat info" % param) - - if db.version() >= (4,7) : - # This code checks a crash solved in Berkeley DB 4.7 - def test_stat_crash(self) : - d=db.DB() - d.open(None,dbtype=db.DB_HASH,flags=db.DB_CREATE) # In RAM - seq = db.DBSequence(d, flags=0) - - self.assertRaises(db.DBNotFoundError, seq.open, - key='id', txn=None, flags=0) - - self.assertRaises(db.DBInvalidArgError, seq.stat) - - d.close() - - def test_64bits(self) : - # We don't use both extremes because they are problematic - value_plus=(1L<<63)-2 - self.assertEqual(9223372036854775806L,value_plus) - value_minus=(-1L<<63)+1 # Two complement - self.assertEqual(-9223372036854775807L,value_minus) - self.seq = db.DBSequence(self.d, flags=0) - self.assertEqual(None, self.seq.initial_value(value_plus-1)) - self.assertEqual(None, self.seq.open(key='id', txn=None, - flags=db.DB_CREATE)) - self.assertEqual(value_plus-1, self.seq.get(1)) - self.assertEqual(value_plus, self.seq.get(1)) - - self.seq.remove(txn=None, flags=0) - - self.seq = db.DBSequence(self.d, flags=0) - self.assertEqual(None, self.seq.initial_value(value_minus)) - self.assertEqual(None, self.seq.open(key='id', txn=None, - flags=db.DB_CREATE)) - self.assertEqual(value_minus, self.seq.get(1)) - self.assertEqual(value_minus+1, self.seq.get(1)) - - def test_multiple_close(self): - self.seq = db.DBSequence(self.d) - self.seq.close() # You can close a Sequence multiple times - self.seq.close() - self.seq.close() - -def test_suite(): - suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(DBSequenceTest)) - return suite - - -if __name__ == '__main__': - unittest.main(defaultTest='test_suite') diff --git a/PythonLib/extra/bsddb/test/test_thread.py b/PythonLib/extra/bsddb/test/test_thread.py deleted file mode 100644 index 42212e9d..00000000 --- a/PythonLib/extra/bsddb/test/test_thread.py +++ /dev/null @@ -1,517 +0,0 @@ -"""TestCases for multi-threaded access to a DB. -""" - -import os -import sys -import time -import errno -from random import random - -DASH = '-' - -try: - WindowsError -except NameError: - class WindowsError(Exception): - pass - -import unittest -from test_all import db, dbutils, test_support, verbose, have_threads, \ - get_new_environment_path, get_new_database_path - -if have_threads : - from threading import Thread - if sys.version_info[0] < 3 : - from threading import currentThread - else : - from threading import current_thread as currentThread - - -#---------------------------------------------------------------------- - -class BaseThreadedTestCase(unittest.TestCase): - dbtype = db.DB_UNKNOWN # must be set in derived class - dbopenflags = 0 - dbsetflags = 0 - envflags = 0 - - def setUp(self): - if verbose: - dbutils._deadlock_VerboseFile = sys.stdout - - self.homeDir = get_new_environment_path() - self.env = db.DBEnv() - self.setEnvOpts() - self.env.open(self.homeDir, self.envflags | db.DB_CREATE) - - self.filename = self.__class__.__name__ + '.db' - self.d = db.DB(self.env) - if self.dbsetflags: - self.d.set_flags(self.dbsetflags) - self.d.open(self.filename, self.dbtype, self.dbopenflags|db.DB_CREATE) - - def tearDown(self): - self.d.close() - self.env.close() - test_support.rmtree(self.homeDir) - - def setEnvOpts(self): - pass - - def makeData(self, key): - return DASH.join([key] * 5) - - -#---------------------------------------------------------------------- - - -class ConcurrentDataStoreBase(BaseThreadedTestCase): - dbopenflags = db.DB_THREAD - envflags = db.DB_THREAD | db.DB_INIT_CDB | db.DB_INIT_MPOOL - readers = 0 # derived class should set - writers = 0 - records = 1000 - - def test01_1WriterMultiReaders(self): - if verbose: - print '\n', '-=' * 30 - print "Running %s.test01_1WriterMultiReaders..." % \ - self.__class__.__name__ - - keys=range(self.records) - import random - random.shuffle(keys) - records_per_writer=self.records//self.writers - readers_per_writer=self.readers//self.writers - self.assertEqual(self.records,self.writers*records_per_writer) - self.assertEqual(self.readers,self.writers*readers_per_writer) - self.assertTrue((records_per_writer%readers_per_writer)==0) - readers = [] - - for x in xrange(self.readers): - rt = Thread(target = self.readerThread, - args = (self.d, x), - name = 'reader %d' % x, - )#verbose = verbose) - if sys.version_info[0] < 3 : - rt.setDaemon(True) - else : - rt.daemon = True - readers.append(rt) - - writers=[] - for x in xrange(self.writers): - a=keys[records_per_writer*x:records_per_writer*(x+1)] - a.sort() # Generate conflicts - b=readers[readers_per_writer*x:readers_per_writer*(x+1)] - wt = Thread(target = self.writerThread, - args = (self.d, a, b), - name = 'writer %d' % x, - )#verbose = verbose) - writers.append(wt) - - for t in writers: - if sys.version_info[0] < 3 : - t.setDaemon(True) - else : - t.daemon = True - t.start() - - for t in writers: - t.join() - for t in readers: - t.join() - - def writerThread(self, d, keys, readers): - if sys.version_info[0] < 3 : - name = currentThread().getName() - else : - name = currentThread().name - - if verbose: - print "%s: creating records %d - %d" % (name, start, stop) - - count=len(keys)//len(readers) - count2=count - for x in keys : - key = '%04d' % x - dbutils.DeadlockWrap(d.put, key, self.makeData(key), - max_retries=12) - if verbose and x % 100 == 0: - print "%s: records %d - %d finished" % (name, start, x) - - count2-=1 - if not count2 : - readers.pop().start() - count2=count - - if verbose: - print "%s: finished creating records" % name - - if verbose: - print "%s: thread finished" % name - - def readerThread(self, d, readerNum): - if sys.version_info[0] < 3 : - name = currentThread().getName() - else : - name = currentThread().name - - for i in xrange(5) : - c = d.cursor() - count = 0 - rec = c.first() - while rec: - count += 1 - key, data = rec - self.assertEqual(self.makeData(key), data) - rec = c.next() - if verbose: - print "%s: found %d records" % (name, count) - c.close() - - if verbose: - print "%s: thread finished" % name - - -class BTreeConcurrentDataStore(ConcurrentDataStoreBase): - dbtype = db.DB_BTREE - writers = 2 - readers = 10 - records = 1000 - - -class HashConcurrentDataStore(ConcurrentDataStoreBase): - dbtype = db.DB_HASH - writers = 2 - readers = 10 - records = 1000 - - -#---------------------------------------------------------------------- - -class SimpleThreadedBase(BaseThreadedTestCase): - dbopenflags = db.DB_THREAD - envflags = db.DB_THREAD | db.DB_INIT_MPOOL | db.DB_INIT_LOCK - readers = 10 - writers = 2 - records = 1000 - - def setEnvOpts(self): - self.env.set_lk_detect(db.DB_LOCK_DEFAULT) - - def test02_SimpleLocks(self): - if verbose: - print '\n', '-=' * 30 - print "Running %s.test02_SimpleLocks..." % self.__class__.__name__ - - - keys=range(self.records) - import random - random.shuffle(keys) - records_per_writer=self.records//self.writers - readers_per_writer=self.readers//self.writers - self.assertEqual(self.records,self.writers*records_per_writer) - self.assertEqual(self.readers,self.writers*readers_per_writer) - self.assertTrue((records_per_writer%readers_per_writer)==0) - - readers = [] - for x in xrange(self.readers): - rt = Thread(target = self.readerThread, - args = (self.d, x), - name = 'reader %d' % x, - )#verbose = verbose) - if sys.version_info[0] < 3 : - rt.setDaemon(True) - else : - rt.daemon = True - readers.append(rt) - - writers = [] - for x in xrange(self.writers): - a=keys[records_per_writer*x:records_per_writer*(x+1)] - a.sort() # Generate conflicts - b=readers[readers_per_writer*x:readers_per_writer*(x+1)] - wt = Thread(target = self.writerThread, - args = (self.d, a, b), - name = 'writer %d' % x, - )#verbose = verbose) - writers.append(wt) - - for t in writers: - if sys.version_info[0] < 3 : - t.setDaemon(True) - else : - t.daemon = True - t.start() - - for t in writers: - t.join() - for t in readers: - t.join() - - def writerThread(self, d, keys, readers): - if sys.version_info[0] < 3 : - name = currentThread().getName() - else : - name = currentThread().name - if verbose: - print "%s: creating records %d - %d" % (name, start, stop) - - count=len(keys)//len(readers) - count2=count - for x in keys : - key = '%04d' % x - dbutils.DeadlockWrap(d.put, key, self.makeData(key), - max_retries=12) - - if verbose and x % 100 == 0: - print "%s: records %d - %d finished" % (name, start, x) - - count2-=1 - if not count2 : - readers.pop().start() - count2=count - - if verbose: - print "%s: thread finished" % name - - def readerThread(self, d, readerNum): - if sys.version_info[0] < 3 : - name = currentThread().getName() - else : - name = currentThread().name - - c = d.cursor() - count = 0 - rec = dbutils.DeadlockWrap(c.first, max_retries=10) - while rec: - count += 1 - key, data = rec - self.assertEqual(self.makeData(key), data) - rec = dbutils.DeadlockWrap(c.next, max_retries=10) - if verbose: - print "%s: found %d records" % (name, count) - c.close() - - if verbose: - print "%s: thread finished" % name - - -class BTreeSimpleThreaded(SimpleThreadedBase): - dbtype = db.DB_BTREE - - -class HashSimpleThreaded(SimpleThreadedBase): - dbtype = db.DB_HASH - - -#---------------------------------------------------------------------- - - -class ThreadedTransactionsBase(BaseThreadedTestCase): - dbopenflags = db.DB_THREAD | db.DB_AUTO_COMMIT - envflags = (db.DB_THREAD | - db.DB_INIT_MPOOL | - db.DB_INIT_LOCK | - db.DB_INIT_LOG | - db.DB_INIT_TXN - ) - readers = 0 - writers = 0 - records = 2000 - txnFlag = 0 - - def setEnvOpts(self): - #self.env.set_lk_detect(db.DB_LOCK_DEFAULT) - pass - - def test03_ThreadedTransactions(self): - if verbose: - print '\n', '-=' * 30 - print "Running %s.test03_ThreadedTransactions..." % \ - self.__class__.__name__ - - keys=range(self.records) - import random - random.shuffle(keys) - records_per_writer=self.records//self.writers - readers_per_writer=self.readers//self.writers - self.assertEqual(self.records,self.writers*records_per_writer) - self.assertEqual(self.readers,self.writers*readers_per_writer) - self.assertTrue((records_per_writer%readers_per_writer)==0) - - readers=[] - for x in xrange(self.readers): - rt = Thread(target = self.readerThread, - args = (self.d, x), - name = 'reader %d' % x, - )#verbose = verbose) - if sys.version_info[0] < 3 : - rt.setDaemon(True) - else : - rt.daemon = True - readers.append(rt) - - writers = [] - for x in xrange(self.writers): - a=keys[records_per_writer*x:records_per_writer*(x+1)] - b=readers[readers_per_writer*x:readers_per_writer*(x+1)] - wt = Thread(target = self.writerThread, - args = (self.d, a, b), - name = 'writer %d' % x, - )#verbose = verbose) - writers.append(wt) - - dt = Thread(target = self.deadlockThread) - if sys.version_info[0] < 3 : - dt.setDaemon(True) - else : - dt.daemon = True - dt.start() - - for t in writers: - if sys.version_info[0] < 3 : - t.setDaemon(True) - else : - t.daemon = True - t.start() - - for t in writers: - t.join() - for t in readers: - t.join() - - self.doLockDetect = False - dt.join() - - def writerThread(self, d, keys, readers): - if sys.version_info[0] < 3 : - name = currentThread().getName() - else : - name = currentThread().name - - count=len(keys)//len(readers) - while len(keys): - try: - txn = self.env.txn_begin(None, self.txnFlag) - keys2=keys[:count] - for x in keys2 : - key = '%04d' % x - d.put(key, self.makeData(key), txn) - if verbose and x % 100 == 0: - print "%s: records %d - %d finished" % (name, start, x) - txn.commit() - keys=keys[count:] - readers.pop().start() - except (db.DBLockDeadlockError, db.DBLockNotGrantedError), val: - if verbose: - if sys.version_info < (2, 6) : - print "%s: Aborting transaction (%s)" % (name, val[1]) - else : - print "%s: Aborting transaction (%s)" % (name, - val.args[1]) - txn.abort() - - if verbose: - print "%s: thread finished" % name - - def readerThread(self, d, readerNum): - if sys.version_info[0] < 3 : - name = currentThread().getName() - else : - name = currentThread().name - - finished = False - while not finished: - try: - txn = self.env.txn_begin(None, self.txnFlag) - c = d.cursor(txn) - count = 0 - rec = c.first() - while rec: - count += 1 - key, data = rec - self.assertEqual(self.makeData(key), data) - rec = c.next() - if verbose: print "%s: found %d records" % (name, count) - c.close() - txn.commit() - finished = True - except (db.DBLockDeadlockError, db.DBLockNotGrantedError), val: - if verbose: - if sys.version_info < (2, 6) : - print "%s: Aborting transaction (%s)" % (name, val[1]) - else : - print "%s: Aborting transaction (%s)" % (name, - val.args[1]) - c.close() - txn.abort() - - if verbose: - print "%s: thread finished" % name - - def deadlockThread(self): - self.doLockDetect = True - while self.doLockDetect: - time.sleep(0.05) - try: - aborted = self.env.lock_detect( - db.DB_LOCK_RANDOM, db.DB_LOCK_CONFLICT) - if verbose and aborted: - print "deadlock: Aborted %d deadlocked transaction(s)" \ - % aborted - except db.DBError: - pass - - -class BTreeThreadedTransactions(ThreadedTransactionsBase): - dbtype = db.DB_BTREE - writers = 2 - readers = 10 - records = 1000 - -class HashThreadedTransactions(ThreadedTransactionsBase): - dbtype = db.DB_HASH - writers = 2 - readers = 10 - records = 1000 - -class BTreeThreadedNoWaitTransactions(ThreadedTransactionsBase): - dbtype = db.DB_BTREE - writers = 2 - readers = 10 - records = 1000 - txnFlag = db.DB_TXN_NOWAIT - -class HashThreadedNoWaitTransactions(ThreadedTransactionsBase): - dbtype = db.DB_HASH - writers = 2 - readers = 10 - records = 1000 - txnFlag = db.DB_TXN_NOWAIT - - -#---------------------------------------------------------------------- - -def test_suite(): - suite = unittest.TestSuite() - - if have_threads: - suite.addTest(unittest.makeSuite(BTreeConcurrentDataStore)) - suite.addTest(unittest.makeSuite(HashConcurrentDataStore)) - suite.addTest(unittest.makeSuite(BTreeSimpleThreaded)) - suite.addTest(unittest.makeSuite(HashSimpleThreaded)) - suite.addTest(unittest.makeSuite(BTreeThreadedTransactions)) - suite.addTest(unittest.makeSuite(HashThreadedTransactions)) - suite.addTest(unittest.makeSuite(BTreeThreadedNoWaitTransactions)) - suite.addTest(unittest.makeSuite(HashThreadedNoWaitTransactions)) - - else: - print "Threads not available, skipping thread tests." - - return suite - - -if __name__ == '__main__': - unittest.main(defaultTest='test_suite') diff --git a/PythonLib/extra/distutils/README b/PythonLib/extra/distutils/README deleted file mode 100644 index 408a203b..00000000 --- a/PythonLib/extra/distutils/README +++ /dev/null @@ -1,13 +0,0 @@ -This directory contains the Distutils package. - -There's a full documentation available at: - - http://docs.python.org/distutils/ - -The Distutils-SIG web page is also a good starting point: - - http://www.python.org/sigs/distutils-sig/ - -WARNING : Distutils must remain compatible with 2.3 - -$Id$ diff --git a/PythonLib/extra/distutils/__init__.py b/PythonLib/extra/distutils/__init__.py deleted file mode 100644 index 6e508855..00000000 --- a/PythonLib/extra/distutils/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ -"""distutils - -The main package for the Python Module Distribution Utilities. Normally -used from a setup script as - - from distutils.core import setup - - setup (...) -""" - -__revision__ = "$Id$" - -# Distutils version -# -# Updated automatically by the Python release process. -# -#--start constants-- -__version__ = "2.7.6" -#--end constants-- diff --git a/PythonLib/extra/distutils/archive_util.py b/PythonLib/extra/distutils/archive_util.py deleted file mode 100644 index 834b722e..00000000 --- a/PythonLib/extra/distutils/archive_util.py +++ /dev/null @@ -1,243 +0,0 @@ -"""distutils.archive_util - -Utility functions for creating archive files (tarballs, zip files, -that sort of thing).""" - -__revision__ = "$Id$" - -import os -from warnings import warn -import sys - -from distutils.errors import DistutilsExecError -from distutils.spawn import spawn -from distutils.dir_util import mkpath -from distutils import log - -try: - from pwd import getpwnam -except ImportError: - getpwnam = None - -try: - from grp import getgrnam -except ImportError: - getgrnam = None - -def _get_gid(name): - """Returns a gid, given a group name.""" - if getgrnam is None or name is None: - return None - try: - result = getgrnam(name) - except KeyError: - result = None - if result is not None: - return result[2] - return None - -def _get_uid(name): - """Returns an uid, given a user name.""" - if getpwnam is None or name is None: - return None - try: - result = getpwnam(name) - except KeyError: - result = None - if result is not None: - return result[2] - return None - -def make_tarball(base_name, base_dir, compress="gzip", verbose=0, dry_run=0, - owner=None, group=None): - """Create a (possibly compressed) tar file from all the files under - 'base_dir'. - - 'compress' must be "gzip" (the default), "compress", "bzip2", or None. - (compress will be deprecated in Python 3.2) - - 'owner' and 'group' can be used to define an owner and a group for the - archive that is being built. If not provided, the current owner and group - will be used. - - The output tar file will be named 'base_dir' + ".tar", possibly plus - the appropriate compression extension (".gz", ".bz2" or ".Z"). - - Returns the output filename. - """ - tar_compression = {'gzip': 'gz', 'bzip2': 'bz2', None: '', 'compress': ''} - compress_ext = {'gzip': '.gz', 'bzip2': '.bz2', 'compress': '.Z'} - - # flags for compression program, each element of list will be an argument - if compress is not None and compress not in compress_ext.keys(): - raise ValueError, \ - ("bad value for 'compress': must be None, 'gzip', 'bzip2' " - "or 'compress'") - - archive_name = base_name + '.tar' - if compress != 'compress': - archive_name += compress_ext.get(compress, '') - - mkpath(os.path.dirname(archive_name), dry_run=dry_run) - - # creating the tarball - import tarfile # late import so Python build itself doesn't break - - log.info('Creating tar archive') - - uid = _get_uid(owner) - gid = _get_gid(group) - - def _set_uid_gid(tarinfo): - if gid is not None: - tarinfo.gid = gid - tarinfo.gname = group - if uid is not None: - tarinfo.uid = uid - tarinfo.uname = owner - return tarinfo - - if not dry_run: - tar = tarfile.open(archive_name, 'w|%s' % tar_compression[compress]) - try: - tar.add(base_dir, filter=_set_uid_gid) - finally: - tar.close() - - # compression using `compress` - if compress == 'compress': - warn("'compress' will be deprecated.", PendingDeprecationWarning) - # the option varies depending on the platform - compressed_name = archive_name + compress_ext[compress] - if sys.platform == 'win32': - cmd = [compress, archive_name, compressed_name] - else: - cmd = [compress, '-f', archive_name] - spawn(cmd, dry_run=dry_run) - return compressed_name - - return archive_name - -def make_zipfile(base_name, base_dir, verbose=0, dry_run=0): - """Create a zip file from all the files under 'base_dir'. - - The output zip file will be named 'base_name' + ".zip". Uses either the - "zipfile" Python module (if available) or the InfoZIP "zip" utility - (if installed and found on the default search path). If neither tool is - available, raises DistutilsExecError. Returns the name of the output zip - file. - """ - try: - import zipfile - except ImportError: - zipfile = None - - zip_filename = base_name + ".zip" - mkpath(os.path.dirname(zip_filename), dry_run=dry_run) - - # If zipfile module is not available, try spawning an external - # 'zip' command. - if zipfile is None: - if verbose: - zipoptions = "-r" - else: - zipoptions = "-rq" - - try: - spawn(["zip", zipoptions, zip_filename, base_dir], - dry_run=dry_run) - except DistutilsExecError: - # XXX really should distinguish between "couldn't find - # external 'zip' command" and "zip failed". - raise DistutilsExecError, \ - ("unable to create zip file '%s': " - "could neither import the 'zipfile' module nor " - "find a standalone zip utility") % zip_filename - - else: - log.info("creating '%s' and adding '%s' to it", - zip_filename, base_dir) - - if not dry_run: - zip = zipfile.ZipFile(zip_filename, "w", - compression=zipfile.ZIP_DEFLATED) - - for dirpath, dirnames, filenames in os.walk(base_dir): - for name in filenames: - path = os.path.normpath(os.path.join(dirpath, name)) - if os.path.isfile(path): - zip.write(path, path) - log.info("adding '%s'" % path) - zip.close() - - return zip_filename - -ARCHIVE_FORMATS = { - 'gztar': (make_tarball, [('compress', 'gzip')], "gzip'ed tar-file"), - 'bztar': (make_tarball, [('compress', 'bzip2')], "bzip2'ed tar-file"), - 'ztar': (make_tarball, [('compress', 'compress')], "compressed tar file"), - 'tar': (make_tarball, [('compress', None)], "uncompressed tar file"), - 'zip': (make_zipfile, [],"ZIP file") - } - -def check_archive_formats(formats): - """Returns the first format from the 'format' list that is unknown. - - If all formats are known, returns None - """ - for format in formats: - if format not in ARCHIVE_FORMATS: - return format - return None - -def make_archive(base_name, format, root_dir=None, base_dir=None, verbose=0, - dry_run=0, owner=None, group=None): - """Create an archive file (eg. zip or tar). - - 'base_name' is the name of the file to create, minus any format-specific - extension; 'format' is the archive format: one of "zip", "tar", "ztar", - or "gztar". - - 'root_dir' is a directory that will be the root directory of the - archive; ie. we typically chdir into 'root_dir' before creating the - archive. 'base_dir' is the directory where we start archiving from; - ie. 'base_dir' will be the common prefix of all files and - directories in the archive. 'root_dir' and 'base_dir' both default - to the current directory. Returns the name of the archive file. - - 'owner' and 'group' are used when creating a tar archive. By default, - uses the current owner and group. - """ - save_cwd = os.getcwd() - if root_dir is not None: - log.debug("changing into '%s'", root_dir) - base_name = os.path.abspath(base_name) - if not dry_run: - os.chdir(root_dir) - - if base_dir is None: - base_dir = os.curdir - - kwargs = {'dry_run': dry_run} - - try: - format_info = ARCHIVE_FORMATS[format] - except KeyError: - raise ValueError, "unknown archive format '%s'" % format - - func = format_info[0] - for arg, val in format_info[1]: - kwargs[arg] = val - - if format != 'zip': - kwargs['owner'] = owner - kwargs['group'] = group - - try: - filename = func(base_name, base_dir, **kwargs) - finally: - if root_dir is not None: - log.debug("changing back to '%s'", save_cwd) - os.chdir(save_cwd) - - return filename diff --git a/PythonLib/extra/distutils/bcppcompiler.py b/PythonLib/extra/distutils/bcppcompiler.py deleted file mode 100644 index f26e7ae4..00000000 --- a/PythonLib/extra/distutils/bcppcompiler.py +++ /dev/null @@ -1,394 +0,0 @@ -"""distutils.bcppcompiler - -Contains BorlandCCompiler, an implementation of the abstract CCompiler class -for the Borland C++ compiler. -""" - -# This implementation by Lyle Johnson, based on the original msvccompiler.py -# module and using the directions originally published by Gordon Williams. - -# XXX looks like there's a LOT of overlap between these two classes: -# someone should sit down and factor out the common code as -# WindowsCCompiler! --GPW - -__revision__ = "$Id$" - -import os - -from distutils.errors import (DistutilsExecError, CompileError, LibError, - LinkError, UnknownFileError) -from distutils.ccompiler import CCompiler, gen_preprocess_options -from distutils.file_util import write_file -from distutils.dep_util import newer -from distutils import log - -class BCPPCompiler(CCompiler) : - """Concrete class that implements an interface to the Borland C/C++ - compiler, as defined by the CCompiler abstract class. - """ - - compiler_type = 'bcpp' - - # Just set this so CCompiler's constructor doesn't barf. We currently - # don't use the 'set_executables()' bureaucracy provided by CCompiler, - # as it really isn't necessary for this sort of single-compiler class. - # Would be nice to have a consistent interface with UnixCCompiler, - # though, so it's worth thinking about. - executables = {} - - # Private class data (need to distinguish C from C++ source for compiler) - _c_extensions = ['.c'] - _cpp_extensions = ['.cc', '.cpp', '.cxx'] - - # Needed for the filename generation methods provided by the - # base class, CCompiler. - src_extensions = _c_extensions + _cpp_extensions - obj_extension = '.obj' - static_lib_extension = '.lib' - shared_lib_extension = '.dll' - static_lib_format = shared_lib_format = '%s%s' - exe_extension = '.exe' - - - def __init__ (self, - verbose=0, - dry_run=0, - force=0): - - CCompiler.__init__ (self, verbose, dry_run, force) - - # These executables are assumed to all be in the path. - # Borland doesn't seem to use any special registry settings to - # indicate their installation locations. - - self.cc = "bcc32.exe" - self.linker = "ilink32.exe" - self.lib = "tlib.exe" - - self.preprocess_options = None - self.compile_options = ['/tWM', '/O2', '/q', '/g0'] - self.compile_options_debug = ['/tWM', '/Od', '/q', '/g0'] - - self.ldflags_shared = ['/Tpd', '/Gn', '/q', '/x'] - self.ldflags_shared_debug = ['/Tpd', '/Gn', '/q', '/x'] - self.ldflags_static = [] - self.ldflags_exe = ['/Gn', '/q', '/x'] - self.ldflags_exe_debug = ['/Gn', '/q', '/x','/r'] - - - # -- Worker methods ------------------------------------------------ - - def compile(self, sources, - output_dir=None, macros=None, include_dirs=None, debug=0, - extra_preargs=None, extra_postargs=None, depends=None): - - macros, objects, extra_postargs, pp_opts, build = \ - self._setup_compile(output_dir, macros, include_dirs, sources, - depends, extra_postargs) - compile_opts = extra_preargs or [] - compile_opts.append ('-c') - if debug: - compile_opts.extend (self.compile_options_debug) - else: - compile_opts.extend (self.compile_options) - - for obj in objects: - try: - src, ext = build[obj] - except KeyError: - continue - # XXX why do the normpath here? - src = os.path.normpath(src) - obj = os.path.normpath(obj) - # XXX _setup_compile() did a mkpath() too but before the normpath. - # Is it possible to skip the normpath? - self.mkpath(os.path.dirname(obj)) - - if ext == '.res': - # This is already a binary file -- skip it. - continue # the 'for' loop - if ext == '.rc': - # This needs to be compiled to a .res file -- do it now. - try: - self.spawn (["brcc32", "-fo", obj, src]) - except DistutilsExecError, msg: - raise CompileError, msg - continue # the 'for' loop - - # The next two are both for the real compiler. - if ext in self._c_extensions: - input_opt = "" - elif ext in self._cpp_extensions: - input_opt = "-P" - else: - # Unknown file type -- no extra options. The compiler - # will probably fail, but let it just in case this is a - # file the compiler recognizes even if we don't. - input_opt = "" - - output_opt = "-o" + obj - - # Compiler command line syntax is: "bcc32 [options] file(s)". - # Note that the source file names must appear at the end of - # the command line. - try: - self.spawn ([self.cc] + compile_opts + pp_opts + - [input_opt, output_opt] + - extra_postargs + [src]) - except DistutilsExecError, msg: - raise CompileError, msg - - return objects - - # compile () - - - def create_static_lib (self, - objects, - output_libname, - output_dir=None, - debug=0, - target_lang=None): - - (objects, output_dir) = self._fix_object_args (objects, output_dir) - output_filename = \ - self.library_filename (output_libname, output_dir=output_dir) - - if self._need_link (objects, output_filename): - lib_args = [output_filename, '/u'] + objects - if debug: - pass # XXX what goes here? - try: - self.spawn ([self.lib] + lib_args) - except DistutilsExecError, msg: - raise LibError, msg - else: - log.debug("skipping %s (up-to-date)", output_filename) - - # create_static_lib () - - - def link (self, - target_desc, - objects, - output_filename, - output_dir=None, - libraries=None, - library_dirs=None, - runtime_library_dirs=None, - export_symbols=None, - debug=0, - extra_preargs=None, - extra_postargs=None, - build_temp=None, - target_lang=None): - - # XXX this ignores 'build_temp'! should follow the lead of - # msvccompiler.py - - (objects, output_dir) = self._fix_object_args (objects, output_dir) - (libraries, library_dirs, runtime_library_dirs) = \ - self._fix_lib_args (libraries, library_dirs, runtime_library_dirs) - - if runtime_library_dirs: - log.warn("I don't know what to do with 'runtime_library_dirs': %s", - str(runtime_library_dirs)) - - if output_dir is not None: - output_filename = os.path.join (output_dir, output_filename) - - if self._need_link (objects, output_filename): - - # Figure out linker args based on type of target. - if target_desc == CCompiler.EXECUTABLE: - startup_obj = 'c0w32' - if debug: - ld_args = self.ldflags_exe_debug[:] - else: - ld_args = self.ldflags_exe[:] - else: - startup_obj = 'c0d32' - if debug: - ld_args = self.ldflags_shared_debug[:] - else: - ld_args = self.ldflags_shared[:] - - - # Create a temporary exports file for use by the linker - if export_symbols is None: - def_file = '' - else: - head, tail = os.path.split (output_filename) - modname, ext = os.path.splitext (tail) - temp_dir = os.path.dirname(objects[0]) # preserve tree structure - def_file = os.path.join (temp_dir, '%s.def' % modname) - contents = ['EXPORTS'] - for sym in (export_symbols or []): - contents.append(' %s=_%s' % (sym, sym)) - self.execute(write_file, (def_file, contents), - "writing %s" % def_file) - - # Borland C++ has problems with '/' in paths - objects2 = map(os.path.normpath, objects) - # split objects in .obj and .res files - # Borland C++ needs them at different positions in the command line - objects = [startup_obj] - resources = [] - for file in objects2: - (base, ext) = os.path.splitext(os.path.normcase(file)) - if ext == '.res': - resources.append(file) - else: - objects.append(file) - - - for l in library_dirs: - ld_args.append("/L%s" % os.path.normpath(l)) - ld_args.append("/L.") # we sometimes use relative paths - - # list of object files - ld_args.extend(objects) - - # XXX the command-line syntax for Borland C++ is a bit wonky; - # certain filenames are jammed together in one big string, but - # comma-delimited. This doesn't mesh too well with the - # Unix-centric attitude (with a DOS/Windows quoting hack) of - # 'spawn()', so constructing the argument list is a bit - # awkward. Note that doing the obvious thing and jamming all - # the filenames and commas into one argument would be wrong, - # because 'spawn()' would quote any filenames with spaces in - # them. Arghghh!. Apparently it works fine as coded... - - # name of dll/exe file - ld_args.extend([',',output_filename]) - # no map file and start libraries - ld_args.append(',,') - - for lib in libraries: - # see if we find it and if there is a bcpp specific lib - # (xxx_bcpp.lib) - libfile = self.find_library_file(library_dirs, lib, debug) - if libfile is None: - ld_args.append(lib) - # probably a BCPP internal library -- don't warn - else: - # full name which prefers bcpp_xxx.lib over xxx.lib - ld_args.append(libfile) - - # some default libraries - ld_args.append ('import32') - ld_args.append ('cw32mt') - - # def file for export symbols - ld_args.extend([',',def_file]) - # add resource files - ld_args.append(',') - ld_args.extend(resources) - - - if extra_preargs: - ld_args[:0] = extra_preargs - if extra_postargs: - ld_args.extend(extra_postargs) - - self.mkpath (os.path.dirname (output_filename)) - try: - self.spawn ([self.linker] + ld_args) - except DistutilsExecError, msg: - raise LinkError, msg - - else: - log.debug("skipping %s (up-to-date)", output_filename) - - # link () - - # -- Miscellaneous methods ----------------------------------------- - - - def find_library_file (self, dirs, lib, debug=0): - # List of effective library names to try, in order of preference: - # xxx_bcpp.lib is better than xxx.lib - # and xxx_d.lib is better than xxx.lib if debug is set - # - # The "_bcpp" suffix is to handle a Python installation for people - # with multiple compilers (primarily Distutils hackers, I suspect - # ;-). The idea is they'd have one static library for each - # compiler they care about, since (almost?) every Windows compiler - # seems to have a different format for static libraries. - if debug: - dlib = (lib + "_d") - try_names = (dlib + "_bcpp", lib + "_bcpp", dlib, lib) - else: - try_names = (lib + "_bcpp", lib) - - for dir in dirs: - for name in try_names: - libfile = os.path.join(dir, self.library_filename(name)) - if os.path.exists(libfile): - return libfile - else: - # Oops, didn't find it in *any* of 'dirs' - return None - - # overwrite the one from CCompiler to support rc and res-files - def object_filenames (self, - source_filenames, - strip_dir=0, - output_dir=''): - if output_dir is None: output_dir = '' - obj_names = [] - for src_name in source_filenames: - # use normcase to make sure '.rc' is really '.rc' and not '.RC' - (base, ext) = os.path.splitext (os.path.normcase(src_name)) - if ext not in (self.src_extensions + ['.rc','.res']): - raise UnknownFileError, \ - "unknown file type '%s' (from '%s')" % \ - (ext, src_name) - if strip_dir: - base = os.path.basename (base) - if ext == '.res': - # these can go unchanged - obj_names.append (os.path.join (output_dir, base + ext)) - elif ext == '.rc': - # these need to be compiled to .res-files - obj_names.append (os.path.join (output_dir, base + '.res')) - else: - obj_names.append (os.path.join (output_dir, - base + self.obj_extension)) - return obj_names - - # object_filenames () - - def preprocess (self, - source, - output_file=None, - macros=None, - include_dirs=None, - extra_preargs=None, - extra_postargs=None): - - (_, macros, include_dirs) = \ - self._fix_compile_args(None, macros, include_dirs) - pp_opts = gen_preprocess_options(macros, include_dirs) - pp_args = ['cpp32.exe'] + pp_opts - if output_file is not None: - pp_args.append('-o' + output_file) - if extra_preargs: - pp_args[:0] = extra_preargs - if extra_postargs: - pp_args.extend(extra_postargs) - pp_args.append(source) - - # We need to preprocess: either we're being forced to, or the - # source file is newer than the target (or the target doesn't - # exist). - if self.force or output_file is None or newer(source, output_file): - if output_file: - self.mkpath(os.path.dirname(output_file)) - try: - self.spawn(pp_args) - except DistutilsExecError, msg: - print msg - raise CompileError, msg - - # preprocess() diff --git a/PythonLib/extra/distutils/ccompiler.py b/PythonLib/extra/distutils/ccompiler.py deleted file mode 100644 index 4907a0aa..00000000 --- a/PythonLib/extra/distutils/ccompiler.py +++ /dev/null @@ -1,1095 +0,0 @@ -"""distutils.ccompiler - -Contains CCompiler, an abstract base class that defines the interface -for the Distutils compiler abstraction model.""" - -__revision__ = "$Id$" - -import sys -import os -import re - -from distutils.errors import (CompileError, LinkError, UnknownFileError, - DistutilsPlatformError, DistutilsModuleError) -from distutils.spawn import spawn -from distutils.file_util import move_file -from distutils.dir_util import mkpath -from distutils.dep_util import newer_group -from distutils.util import split_quoted, execute -from distutils import log -# following import is for backward compatibility -from distutils.sysconfig import customize_compiler - -class CCompiler: - """Abstract base class to define the interface that must be implemented - by real compiler classes. Also has some utility methods used by - several compiler classes. - - The basic idea behind a compiler abstraction class is that each - instance can be used for all the compile/link steps in building a - single project. Thus, attributes common to all of those compile and - link steps -- include directories, macros to define, libraries to link - against, etc. -- are attributes of the compiler instance. To allow for - variability in how individual files are treated, most of those - attributes may be varied on a per-compilation or per-link basis. - """ - - # 'compiler_type' is a class attribute that identifies this class. It - # keeps code that wants to know what kind of compiler it's dealing with - # from having to import all possible compiler classes just to do an - # 'isinstance'. In concrete CCompiler subclasses, 'compiler_type' - # should really, really be one of the keys of the 'compiler_class' - # dictionary (see below -- used by the 'new_compiler()' factory - # function) -- authors of new compiler interface classes are - # responsible for updating 'compiler_class'! - compiler_type = None - - # XXX things not handled by this compiler abstraction model: - # * client can't provide additional options for a compiler, - # e.g. warning, optimization, debugging flags. Perhaps this - # should be the domain of concrete compiler abstraction classes - # (UnixCCompiler, MSVCCompiler, etc.) -- or perhaps the base - # class should have methods for the common ones. - # * can't completely override the include or library searchg - # path, ie. no "cc -I -Idir1 -Idir2" or "cc -L -Ldir1 -Ldir2". - # I'm not sure how widely supported this is even by Unix - # compilers, much less on other platforms. And I'm even less - # sure how useful it is; maybe for cross-compiling, but - # support for that is a ways off. (And anyways, cross - # compilers probably have a dedicated binary with the - # right paths compiled in. I hope.) - # * can't do really freaky things with the library list/library - # dirs, e.g. "-Ldir1 -lfoo -Ldir2 -lfoo" to link against - # different versions of libfoo.a in different locations. I - # think this is useless without the ability to null out the - # library search path anyways. - - - # Subclasses that rely on the standard filename generation methods - # implemented below should override these; see the comment near - # those methods ('object_filenames()' et. al.) for details: - src_extensions = None # list of strings - obj_extension = None # string - static_lib_extension = None - shared_lib_extension = None # string - static_lib_format = None # format string - shared_lib_format = None # prob. same as static_lib_format - exe_extension = None # string - - # Default language settings. language_map is used to detect a source - # file or Extension target language, checking source filenames. - # language_order is used to detect the language precedence, when deciding - # what language to use when mixing source types. For example, if some - # extension has two files with ".c" extension, and one with ".cpp", it - # is still linked as c++. - language_map = {".c" : "c", - ".cc" : "c++", - ".cpp" : "c++", - ".cxx" : "c++", - ".m" : "objc", - } - language_order = ["c++", "objc", "c"] - - def __init__ (self, verbose=0, dry_run=0, force=0): - self.dry_run = dry_run - self.force = force - self.verbose = verbose - - # 'output_dir': a common output directory for object, library, - # shared object, and shared library files - self.output_dir = None - - # 'macros': a list of macro definitions (or undefinitions). A - # macro definition is a 2-tuple (name, value), where the value is - # either a string or None (no explicit value). A macro - # undefinition is a 1-tuple (name,). - self.macros = [] - - # 'include_dirs': a list of directories to search for include files - self.include_dirs = [] - - # 'libraries': a list of libraries to include in any link - # (library names, not filenames: eg. "foo" not "libfoo.a") - self.libraries = [] - - # 'library_dirs': a list of directories to search for libraries - self.library_dirs = [] - - # 'runtime_library_dirs': a list of directories to search for - # shared libraries/objects at runtime - self.runtime_library_dirs = [] - - # 'objects': a list of object files (or similar, such as explicitly - # named library files) to include on any link - self.objects = [] - - for key in self.executables.keys(): - self.set_executable(key, self.executables[key]) - - def set_executables(self, **args): - """Define the executables (and options for them) that will be run - to perform the various stages of compilation. The exact set of - executables that may be specified here depends on the compiler - class (via the 'executables' class attribute), but most will have: - compiler the C/C++ compiler - linker_so linker used to create shared objects and libraries - linker_exe linker used to create binary executables - archiver static library creator - - On platforms with a command-line (Unix, DOS/Windows), each of these - is a string that will be split into executable name and (optional) - list of arguments. (Splitting the string is done similarly to how - Unix shells operate: words are delimited by spaces, but quotes and - backslashes can override this. See - 'distutils.util.split_quoted()'.) - """ - - # Note that some CCompiler implementation classes will define class - # attributes 'cpp', 'cc', etc. with hard-coded executable names; - # this is appropriate when a compiler class is for exactly one - # compiler/OS combination (eg. MSVCCompiler). Other compiler - # classes (UnixCCompiler, in particular) are driven by information - # discovered at run-time, since there are many different ways to do - # basically the same things with Unix C compilers. - - for key in args.keys(): - if key not in self.executables: - raise ValueError, \ - "unknown executable '%s' for class %s" % \ - (key, self.__class__.__name__) - self.set_executable(key, args[key]) - - def set_executable(self, key, value): - if isinstance(value, str): - setattr(self, key, split_quoted(value)) - else: - setattr(self, key, value) - - def _find_macro(self, name): - i = 0 - for defn in self.macros: - if defn[0] == name: - return i - i = i + 1 - return None - - def _check_macro_definitions(self, definitions): - """Ensures that every element of 'definitions' is a valid macro - definition, ie. either (name,value) 2-tuple or a (name,) tuple. Do - nothing if all definitions are OK, raise TypeError otherwise. - """ - for defn in definitions: - if not (isinstance(defn, tuple) and - (len (defn) == 1 or - (len (defn) == 2 and - (isinstance(defn[1], str) or defn[1] is None))) and - isinstance(defn[0], str)): - raise TypeError, \ - ("invalid macro definition '%s': " % defn) + \ - "must be tuple (string,), (string, string), or " + \ - "(string, None)" - - - # -- Bookkeeping methods ------------------------------------------- - - def define_macro(self, name, value=None): - """Define a preprocessor macro for all compilations driven by this - compiler object. The optional parameter 'value' should be a - string; if it is not supplied, then the macro will be defined - without an explicit value and the exact outcome depends on the - compiler used (XXX true? does ANSI say anything about this?) - """ - # Delete from the list of macro definitions/undefinitions if - # already there (so that this one will take precedence). - i = self._find_macro (name) - if i is not None: - del self.macros[i] - - defn = (name, value) - self.macros.append (defn) - - def undefine_macro(self, name): - """Undefine a preprocessor macro for all compilations driven by - this compiler object. If the same macro is defined by - 'define_macro()' and undefined by 'undefine_macro()' the last call - takes precedence (including multiple redefinitions or - undefinitions). If the macro is redefined/undefined on a - per-compilation basis (ie. in the call to 'compile()'), then that - takes precedence. - """ - # Delete from the list of macro definitions/undefinitions if - # already there (so that this one will take precedence). - i = self._find_macro (name) - if i is not None: - del self.macros[i] - - undefn = (name,) - self.macros.append (undefn) - - def add_include_dir(self, dir): - """Add 'dir' to the list of directories that will be searched for - header files. The compiler is instructed to search directories in - the order in which they are supplied by successive calls to - 'add_include_dir()'. - """ - self.include_dirs.append (dir) - - def set_include_dirs(self, dirs): - """Set the list of directories that will be searched to 'dirs' (a - list of strings). Overrides any preceding calls to - 'add_include_dir()'; subsequence calls to 'add_include_dir()' add - to the list passed to 'set_include_dirs()'. This does not affect - any list of standard include directories that the compiler may - search by default. - """ - self.include_dirs = dirs[:] - - def add_library(self, libname): - """Add 'libname' to the list of libraries that will be included in - all links driven by this compiler object. Note that 'libname' - should *not* be the name of a file containing a library, but the - name of the library itself: the actual filename will be inferred by - the linker, the compiler, or the compiler class (depending on the - platform). - - The linker will be instructed to link against libraries in the - order they were supplied to 'add_library()' and/or - 'set_libraries()'. It is perfectly valid to duplicate library - names; the linker will be instructed to link against libraries as - many times as they are mentioned. - """ - self.libraries.append (libname) - - def set_libraries(self, libnames): - """Set the list of libraries to be included in all links driven by - this compiler object to 'libnames' (a list of strings). This does - not affect any standard system libraries that the linker may - include by default. - """ - self.libraries = libnames[:] - - - def add_library_dir(self, dir): - """Add 'dir' to the list of directories that will be searched for - libraries specified to 'add_library()' and 'set_libraries()'. The - linker will be instructed to search for libraries in the order they - are supplied to 'add_library_dir()' and/or 'set_library_dirs()'. - """ - self.library_dirs.append(dir) - - def set_library_dirs(self, dirs): - """Set the list of library search directories to 'dirs' (a list of - strings). This does not affect any standard library search path - that the linker may search by default. - """ - self.library_dirs = dirs[:] - - def add_runtime_library_dir(self, dir): - """Add 'dir' to the list of directories that will be searched for - shared libraries at runtime. - """ - self.runtime_library_dirs.append(dir) - - def set_runtime_library_dirs(self, dirs): - """Set the list of directories to search for shared libraries at - runtime to 'dirs' (a list of strings). This does not affect any - standard search path that the runtime linker may search by - default. - """ - self.runtime_library_dirs = dirs[:] - - def add_link_object(self, object): - """Add 'object' to the list of object files (or analogues, such as - explicitly named library files or the output of "resource - compilers") to be included in every link driven by this compiler - object. - """ - self.objects.append(object) - - def set_link_objects(self, objects): - """Set the list of object files (or analogues) to be included in - every link to 'objects'. This does not affect any standard object - files that the linker may include by default (such as system - libraries). - """ - self.objects = objects[:] - - - # -- Private utility methods -------------------------------------- - # (here for the convenience of subclasses) - - # Helper method to prep compiler in subclass compile() methods - - def _setup_compile(self, outdir, macros, incdirs, sources, depends, - extra): - """Process arguments and decide which source files to compile.""" - if outdir is None: - outdir = self.output_dir - elif not isinstance(outdir, str): - raise TypeError, "'output_dir' must be a string or None" - - if macros is None: - macros = self.macros - elif isinstance(macros, list): - macros = macros + (self.macros or []) - else: - raise TypeError, "'macros' (if supplied) must be a list of tuples" - - if incdirs is None: - incdirs = self.include_dirs - elif isinstance(incdirs, (list, tuple)): - incdirs = list(incdirs) + (self.include_dirs or []) - else: - raise TypeError, \ - "'include_dirs' (if supplied) must be a list of strings" - - if extra is None: - extra = [] - - # Get the list of expected output (object) files - objects = self.object_filenames(sources, - strip_dir=0, - output_dir=outdir) - assert len(objects) == len(sources) - - pp_opts = gen_preprocess_options(macros, incdirs) - - build = {} - for i in range(len(sources)): - src = sources[i] - obj = objects[i] - ext = os.path.splitext(src)[1] - self.mkpath(os.path.dirname(obj)) - build[obj] = (src, ext) - - return macros, objects, extra, pp_opts, build - - def _get_cc_args(self, pp_opts, debug, before): - # works for unixccompiler, emxccompiler, cygwinccompiler - cc_args = pp_opts + ['-c'] - if debug: - cc_args[:0] = ['-g'] - if before: - cc_args[:0] = before - return cc_args - - def _fix_compile_args(self, output_dir, macros, include_dirs): - """Typecheck and fix-up some of the arguments to the 'compile()' - method, and return fixed-up values. Specifically: if 'output_dir' - is None, replaces it with 'self.output_dir'; ensures that 'macros' - is a list, and augments it with 'self.macros'; ensures that - 'include_dirs' is a list, and augments it with 'self.include_dirs'. - Guarantees that the returned values are of the correct type, - i.e. for 'output_dir' either string or None, and for 'macros' and - 'include_dirs' either list or None. - """ - if output_dir is None: - output_dir = self.output_dir - elif not isinstance(output_dir, str): - raise TypeError, "'output_dir' must be a string or None" - - if macros is None: - macros = self.macros - elif isinstance(macros, list): - macros = macros + (self.macros or []) - else: - raise TypeError, "'macros' (if supplied) must be a list of tuples" - - if include_dirs is None: - include_dirs = self.include_dirs - elif isinstance(include_dirs, (list, tuple)): - include_dirs = list (include_dirs) + (self.include_dirs or []) - else: - raise TypeError, \ - "'include_dirs' (if supplied) must be a list of strings" - - return output_dir, macros, include_dirs - - def _fix_object_args(self, objects, output_dir): - """Typecheck and fix up some arguments supplied to various methods. - Specifically: ensure that 'objects' is a list; if output_dir is - None, replace with self.output_dir. Return fixed versions of - 'objects' and 'output_dir'. - """ - if not isinstance(objects, (list, tuple)): - raise TypeError, \ - "'objects' must be a list or tuple of strings" - objects = list (objects) - - if output_dir is None: - output_dir = self.output_dir - elif not isinstance(output_dir, str): - raise TypeError, "'output_dir' must be a string or None" - - return (objects, output_dir) - - def _fix_lib_args(self, libraries, library_dirs, runtime_library_dirs): - """Typecheck and fix up some of the arguments supplied to the - 'link_*' methods. Specifically: ensure that all arguments are - lists, and augment them with their permanent versions - (eg. 'self.libraries' augments 'libraries'). Return a tuple with - fixed versions of all arguments. - """ - if libraries is None: - libraries = self.libraries - elif isinstance(libraries, (list, tuple)): - libraries = list (libraries) + (self.libraries or []) - else: - raise TypeError, \ - "'libraries' (if supplied) must be a list of strings" - - if library_dirs is None: - library_dirs = self.library_dirs - elif isinstance(library_dirs, (list, tuple)): - library_dirs = list (library_dirs) + (self.library_dirs or []) - else: - raise TypeError, \ - "'library_dirs' (if supplied) must be a list of strings" - - if runtime_library_dirs is None: - runtime_library_dirs = self.runtime_library_dirs - elif isinstance(runtime_library_dirs, (list, tuple)): - runtime_library_dirs = (list (runtime_library_dirs) + - (self.runtime_library_dirs or [])) - else: - raise TypeError, \ - "'runtime_library_dirs' (if supplied) " + \ - "must be a list of strings" - - return (libraries, library_dirs, runtime_library_dirs) - - def _need_link(self, objects, output_file): - """Return true if we need to relink the files listed in 'objects' - to recreate 'output_file'. - """ - if self.force: - return 1 - else: - if self.dry_run: - newer = newer_group (objects, output_file, missing='newer') - else: - newer = newer_group (objects, output_file) - return newer - - def detect_language(self, sources): - """Detect the language of a given file, or list of files. Uses - language_map, and language_order to do the job. - """ - if not isinstance(sources, list): - sources = [sources] - lang = None - index = len(self.language_order) - for source in sources: - base, ext = os.path.splitext(source) - extlang = self.language_map.get(ext) - try: - extindex = self.language_order.index(extlang) - if extindex < index: - lang = extlang - index = extindex - except ValueError: - pass - return lang - - # -- Worker methods ------------------------------------------------ - # (must be implemented by subclasses) - - def preprocess(self, source, output_file=None, macros=None, - include_dirs=None, extra_preargs=None, extra_postargs=None): - """Preprocess a single C/C++ source file, named in 'source'. - Output will be written to file named 'output_file', or stdout if - 'output_file' not supplied. 'macros' is a list of macro - definitions as for 'compile()', which will augment the macros set - with 'define_macro()' and 'undefine_macro()'. 'include_dirs' is a - list of directory names that will be added to the default list. - - Raises PreprocessError on failure. - """ - pass - - def compile(self, sources, output_dir=None, macros=None, - include_dirs=None, debug=0, extra_preargs=None, - extra_postargs=None, depends=None): - """Compile one or more source files. - - 'sources' must be a list of filenames, most likely C/C++ - files, but in reality anything that can be handled by a - particular compiler and compiler class (eg. MSVCCompiler can - handle resource files in 'sources'). Return a list of object - filenames, one per source filename in 'sources'. Depending on - the implementation, not all source files will necessarily be - compiled, but all corresponding object filenames will be - returned. - - If 'output_dir' is given, object files will be put under it, while - retaining their original path component. That is, "foo/bar.c" - normally compiles to "foo/bar.o" (for a Unix implementation); if - 'output_dir' is "build", then it would compile to - "build/foo/bar.o". - - 'macros', if given, must be a list of macro definitions. A macro - definition is either a (name, value) 2-tuple or a (name,) 1-tuple. - The former defines a macro; if the value is None, the macro is - defined without an explicit value. The 1-tuple case undefines a - macro. Later definitions/redefinitions/ undefinitions take - precedence. - - 'include_dirs', if given, must be a list of strings, the - directories to add to the default include file search path for this - compilation only. - - 'debug' is a boolean; if true, the compiler will be instructed to - output debug symbols in (or alongside) the object file(s). - - 'extra_preargs' and 'extra_postargs' are implementation- dependent. - On platforms that have the notion of a command-line (e.g. Unix, - DOS/Windows), they are most likely lists of strings: extra - command-line arguments to prepand/append to the compiler command - line. On other platforms, consult the implementation class - documentation. In any event, they are intended as an escape hatch - for those occasions when the abstract compiler framework doesn't - cut the mustard. - - 'depends', if given, is a list of filenames that all targets - depend on. If a source file is older than any file in - depends, then the source file will be recompiled. This - supports dependency tracking, but only at a coarse - granularity. - - Raises CompileError on failure. - """ - # A concrete compiler class can either override this method - # entirely or implement _compile(). - - macros, objects, extra_postargs, pp_opts, build = \ - self._setup_compile(output_dir, macros, include_dirs, sources, - depends, extra_postargs) - cc_args = self._get_cc_args(pp_opts, debug, extra_preargs) - - for obj in objects: - try: - src, ext = build[obj] - except KeyError: - continue - self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) - - # Return *all* object filenames, not just the ones we just built. - return objects - - def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts): - """Compile 'src' to product 'obj'.""" - - # A concrete compiler class that does not override compile() - # should implement _compile(). - pass - - def create_static_lib(self, objects, output_libname, output_dir=None, - debug=0, target_lang=None): - """Link a bunch of stuff together to create a static library file. - The "bunch of stuff" consists of the list of object files supplied - as 'objects', the extra object files supplied to - 'add_link_object()' and/or 'set_link_objects()', the libraries - supplied to 'add_library()' and/or 'set_libraries()', and the - libraries supplied as 'libraries' (if any). - - 'output_libname' should be a library name, not a filename; the - filename will be inferred from the library name. 'output_dir' is - the directory where the library file will be put. - - 'debug' is a boolean; if true, debugging information will be - included in the library (note that on most platforms, it is the - compile step where this matters: the 'debug' flag is included here - just for consistency). - - 'target_lang' is the target language for which the given objects - are being compiled. This allows specific linkage time treatment of - certain languages. - - Raises LibError on failure. - """ - pass - - # values for target_desc parameter in link() - SHARED_OBJECT = "shared_object" - SHARED_LIBRARY = "shared_library" - EXECUTABLE = "executable" - - def link(self, target_desc, objects, output_filename, output_dir=None, - libraries=None, library_dirs=None, runtime_library_dirs=None, - export_symbols=None, debug=0, extra_preargs=None, - extra_postargs=None, build_temp=None, target_lang=None): - """Link a bunch of stuff together to create an executable or - shared library file. - - The "bunch of stuff" consists of the list of object files supplied - as 'objects'. 'output_filename' should be a filename. If - 'output_dir' is supplied, 'output_filename' is relative to it - (i.e. 'output_filename' can provide directory components if - needed). - - 'libraries' is a list of libraries to link against. These are - library names, not filenames, since they're translated into - filenames in a platform-specific way (eg. "foo" becomes "libfoo.a" - on Unix and "foo.lib" on DOS/Windows). However, they can include a - directory component, which means the linker will look in that - specific directory rather than searching all the normal locations. - - 'library_dirs', if supplied, should be a list of directories to - search for libraries that were specified as bare library names - (ie. no directory component). These are on top of the system - default and those supplied to 'add_library_dir()' and/or - 'set_library_dirs()'. 'runtime_library_dirs' is a list of - directories that will be embedded into the shared library and used - to search for other shared libraries that *it* depends on at - run-time. (This may only be relevant on Unix.) - - 'export_symbols' is a list of symbols that the shared library will - export. (This appears to be relevant only on Windows.) - - 'debug' is as for 'compile()' and 'create_static_lib()', with the - slight distinction that it actually matters on most platforms (as - opposed to 'create_static_lib()', which includes a 'debug' flag - mostly for form's sake). - - 'extra_preargs' and 'extra_postargs' are as for 'compile()' (except - of course that they supply command-line arguments for the - particular linker being used). - - 'target_lang' is the target language for which the given objects - are being compiled. This allows specific linkage time treatment of - certain languages. - - Raises LinkError on failure. - """ - raise NotImplementedError - - - # Old 'link_*()' methods, rewritten to use the new 'link()' method. - - def link_shared_lib(self, objects, output_libname, output_dir=None, - libraries=None, library_dirs=None, - runtime_library_dirs=None, export_symbols=None, - debug=0, extra_preargs=None, extra_postargs=None, - build_temp=None, target_lang=None): - self.link(CCompiler.SHARED_LIBRARY, objects, - self.library_filename(output_libname, lib_type='shared'), - output_dir, - libraries, library_dirs, runtime_library_dirs, - export_symbols, debug, - extra_preargs, extra_postargs, build_temp, target_lang) - - - def link_shared_object(self, objects, output_filename, output_dir=None, - libraries=None, library_dirs=None, - runtime_library_dirs=None, export_symbols=None, - debug=0, extra_preargs=None, extra_postargs=None, - build_temp=None, target_lang=None): - self.link(CCompiler.SHARED_OBJECT, objects, - output_filename, output_dir, - libraries, library_dirs, runtime_library_dirs, - export_symbols, debug, - extra_preargs, extra_postargs, build_temp, target_lang) - - def link_executable(self, objects, output_progname, output_dir=None, - libraries=None, library_dirs=None, - runtime_library_dirs=None, debug=0, extra_preargs=None, - extra_postargs=None, target_lang=None): - self.link(CCompiler.EXECUTABLE, objects, - self.executable_filename(output_progname), output_dir, - libraries, library_dirs, runtime_library_dirs, None, - debug, extra_preargs, extra_postargs, None, target_lang) - - - # -- Miscellaneous methods ----------------------------------------- - # These are all used by the 'gen_lib_options() function; there is - # no appropriate default implementation so subclasses should - # implement all of these. - - def library_dir_option(self, dir): - """Return the compiler option to add 'dir' to the list of - directories searched for libraries. - """ - raise NotImplementedError - - def runtime_library_dir_option(self, dir): - """Return the compiler option to add 'dir' to the list of - directories searched for runtime libraries. - """ - raise NotImplementedError - - def library_option(self, lib): - """Return the compiler option to add 'dir' to the list of libraries - linked into the shared library or executable. - """ - raise NotImplementedError - - def has_function(self, funcname, includes=None, include_dirs=None, - libraries=None, library_dirs=None): - """Return a boolean indicating whether funcname is supported on - the current platform. The optional arguments can be used to - augment the compilation environment. - """ - - # this can't be included at module scope because it tries to - # import math which might not be available at that point - maybe - # the necessary logic should just be inlined? - import tempfile - if includes is None: - includes = [] - if include_dirs is None: - include_dirs = [] - if libraries is None: - libraries = [] - if library_dirs is None: - library_dirs = [] - fd, fname = tempfile.mkstemp(".c", funcname, text=True) - f = os.fdopen(fd, "w") - try: - for incl in includes: - f.write("""#include "%s"\n""" % incl) - f.write("""\ -main (int argc, char **argv) { - %s(); -} -""" % funcname) - finally: - f.close() - try: - objects = self.compile([fname], include_dirs=include_dirs) - except CompileError: - return False - - try: - self.link_executable(objects, "a.out", - libraries=libraries, - library_dirs=library_dirs) - except (LinkError, TypeError): - return False - return True - - def find_library_file (self, dirs, lib, debug=0): - """Search the specified list of directories for a static or shared - library file 'lib' and return the full path to that file. If - 'debug' true, look for a debugging version (if that makes sense on - the current platform). Return None if 'lib' wasn't found in any of - the specified directories. - """ - raise NotImplementedError - - # -- Filename generation methods ----------------------------------- - - # The default implementation of the filename generating methods are - # prejudiced towards the Unix/DOS/Windows view of the world: - # * object files are named by replacing the source file extension - # (eg. .c/.cpp -> .o/.obj) - # * library files (shared or static) are named by plugging the - # library name and extension into a format string, eg. - # "lib%s.%s" % (lib_name, ".a") for Unix static libraries - # * executables are named by appending an extension (possibly - # empty) to the program name: eg. progname + ".exe" for - # Windows - # - # To reduce redundant code, these methods expect to find - # several attributes in the current object (presumably defined - # as class attributes): - # * src_extensions - - # list of C/C++ source file extensions, eg. ['.c', '.cpp'] - # * obj_extension - - # object file extension, eg. '.o' or '.obj' - # * static_lib_extension - - # extension for static library files, eg. '.a' or '.lib' - # * shared_lib_extension - - # extension for shared library/object files, eg. '.so', '.dll' - # * static_lib_format - - # format string for generating static library filenames, - # eg. 'lib%s.%s' or '%s.%s' - # * shared_lib_format - # format string for generating shared library filenames - # (probably same as static_lib_format, since the extension - # is one of the intended parameters to the format string) - # * exe_extension - - # extension for executable files, eg. '' or '.exe' - - def object_filenames(self, source_filenames, strip_dir=0, output_dir=''): - if output_dir is None: - output_dir = '' - obj_names = [] - for src_name in source_filenames: - base, ext = os.path.splitext(src_name) - base = os.path.splitdrive(base)[1] # Chop off the drive - base = base[os.path.isabs(base):] # If abs, chop off leading / - if ext not in self.src_extensions: - raise UnknownFileError, \ - "unknown file type '%s' (from '%s')" % (ext, src_name) - if strip_dir: - base = os.path.basename(base) - obj_names.append(os.path.join(output_dir, - base + self.obj_extension)) - return obj_names - - def shared_object_filename(self, basename, strip_dir=0, output_dir=''): - assert output_dir is not None - if strip_dir: - basename = os.path.basename (basename) - return os.path.join(output_dir, basename + self.shared_lib_extension) - - def executable_filename(self, basename, strip_dir=0, output_dir=''): - assert output_dir is not None - if strip_dir: - basename = os.path.basename (basename) - return os.path.join(output_dir, basename + (self.exe_extension or '')) - - def library_filename(self, libname, lib_type='static', # or 'shared' - strip_dir=0, output_dir=''): - assert output_dir is not None - if lib_type not in ("static", "shared", "dylib"): - raise ValueError, "'lib_type' must be \"static\", \"shared\" or \"dylib\"" - fmt = getattr(self, lib_type + "_lib_format") - ext = getattr(self, lib_type + "_lib_extension") - - dir, base = os.path.split (libname) - filename = fmt % (base, ext) - if strip_dir: - dir = '' - - return os.path.join(output_dir, dir, filename) - - - # -- Utility methods ----------------------------------------------- - - def announce(self, msg, level=1): - log.debug(msg) - - def debug_print(self, msg): - from distutils.debug import DEBUG - if DEBUG: - print msg - - def warn(self, msg): - sys.stderr.write("warning: %s\n" % msg) - - def execute(self, func, args, msg=None, level=1): - execute(func, args, msg, self.dry_run) - - def spawn(self, cmd): - spawn(cmd, dry_run=self.dry_run) - - def move_file(self, src, dst): - return move_file(src, dst, dry_run=self.dry_run) - - def mkpath(self, name, mode=0777): - mkpath(name, mode, dry_run=self.dry_run) - - -# class CCompiler - - -# Map a sys.platform/os.name ('posix', 'nt') to the default compiler -# type for that platform. Keys are interpreted as re match -# patterns. Order is important; platform mappings are preferred over -# OS names. -_default_compilers = ( - - # Platform string mappings - - # on a cygwin built python we can use gcc like an ordinary UNIXish - # compiler - ('cygwin.*', 'unix'), - ('os2emx', 'emx'), - - # OS name mappings - ('posix', 'unix'), - ('nt', 'msvc'), - - ) - -def get_default_compiler(osname=None, platform=None): - """ Determine the default compiler to use for the given platform. - - osname should be one of the standard Python OS names (i.e. the - ones returned by os.name) and platform the common value - returned by sys.platform for the platform in question. - - The default values are os.name and sys.platform in case the - parameters are not given. - - """ - if osname is None: - osname = os.name - if platform is None: - platform = sys.platform - for pattern, compiler in _default_compilers: - if re.match(pattern, platform) is not None or \ - re.match(pattern, osname) is not None: - return compiler - # Default to Unix compiler - return 'unix' - -# Map compiler types to (module_name, class_name) pairs -- ie. where to -# find the code that implements an interface to this compiler. (The module -# is assumed to be in the 'distutils' package.) -compiler_class = { 'unix': ('unixccompiler', 'UnixCCompiler', - "standard UNIX-style compiler"), - 'msvc': ('msvccompiler', 'MSVCCompiler', - "Microsoft Visual C++"), - 'cygwin': ('cygwinccompiler', 'CygwinCCompiler', - "Cygwin port of GNU C Compiler for Win32"), - 'mingw32': ('cygwinccompiler', 'Mingw32CCompiler', - "Mingw32 port of GNU C Compiler for Win32"), - 'bcpp': ('bcppcompiler', 'BCPPCompiler', - "Borland C++ Compiler"), - 'emx': ('emxccompiler', 'EMXCCompiler', - "EMX port of GNU C Compiler for OS/2"), - } - -def show_compilers(): - """Print list of available compilers (used by the "--help-compiler" - options to "build", "build_ext", "build_clib"). - """ - # XXX this "knows" that the compiler option it's describing is - # "--compiler", which just happens to be the case for the three - # commands that use it. - from distutils.fancy_getopt import FancyGetopt - compilers = [] - for compiler in compiler_class.keys(): - compilers.append(("compiler="+compiler, None, - compiler_class[compiler][2])) - compilers.sort() - pretty_printer = FancyGetopt(compilers) - pretty_printer.print_help("List of available compilers:") - - -def new_compiler(plat=None, compiler=None, verbose=0, dry_run=0, force=0): - """Generate an instance of some CCompiler subclass for the supplied - platform/compiler combination. 'plat' defaults to 'os.name' - (eg. 'posix', 'nt'), and 'compiler' defaults to the default compiler - for that platform. Currently only 'posix' and 'nt' are supported, and - the default compilers are "traditional Unix interface" (UnixCCompiler - class) and Visual C++ (MSVCCompiler class). Note that it's perfectly - possible to ask for a Unix compiler object under Windows, and a - Microsoft compiler object under Unix -- if you supply a value for - 'compiler', 'plat' is ignored. - """ - if plat is None: - plat = os.name - - try: - if compiler is None: - compiler = get_default_compiler(plat) - - (module_name, class_name, long_description) = compiler_class[compiler] - except KeyError: - msg = "don't know how to compile C/C++ code on platform '%s'" % plat - if compiler is not None: - msg = msg + " with '%s' compiler" % compiler - raise DistutilsPlatformError, msg - - try: - module_name = "distutils." + module_name - __import__ (module_name) - module = sys.modules[module_name] - klass = vars(module)[class_name] - except ImportError: - raise DistutilsModuleError, \ - "can't compile C/C++ code: unable to load module '%s'" % \ - module_name - except KeyError: - raise DistutilsModuleError, \ - ("can't compile C/C++ code: unable to find class '%s' " + - "in module '%s'") % (class_name, module_name) - - # XXX The None is necessary to preserve backwards compatibility - # with classes that expect verbose to be the first positional - # argument. - return klass(None, dry_run, force) - - -def gen_preprocess_options(macros, include_dirs): - """Generate C pre-processor options (-D, -U, -I) as used by at least - two types of compilers: the typical Unix compiler and Visual C++. - 'macros' is the usual thing, a list of 1- or 2-tuples, where (name,) - means undefine (-U) macro 'name', and (name,value) means define (-D) - macro 'name' to 'value'. 'include_dirs' is just a list of directory - names to be added to the header file search path (-I). Returns a list - of command-line options suitable for either Unix compilers or Visual - C++. - """ - # XXX it would be nice (mainly aesthetic, and so we don't generate - # stupid-looking command lines) to go over 'macros' and eliminate - # redundant definitions/undefinitions (ie. ensure that only the - # latest mention of a particular macro winds up on the command - # line). I don't think it's essential, though, since most (all?) - # Unix C compilers only pay attention to the latest -D or -U - # mention of a macro on their command line. Similar situation for - # 'include_dirs'. I'm punting on both for now. Anyways, weeding out - # redundancies like this should probably be the province of - # CCompiler, since the data structures used are inherited from it - # and therefore common to all CCompiler classes. - - pp_opts = [] - for macro in macros: - - if not (isinstance(macro, tuple) and - 1 <= len (macro) <= 2): - raise TypeError, \ - ("bad macro definition '%s': " + - "each element of 'macros' list must be a 1- or 2-tuple") % \ - macro - - if len (macro) == 1: # undefine this macro - pp_opts.append ("-U%s" % macro[0]) - elif len (macro) == 2: - if macro[1] is None: # define with no explicit value - pp_opts.append ("-D%s" % macro[0]) - else: - # XXX *don't* need to be clever about quoting the - # macro value here, because we're going to avoid the - # shell at all costs when we spawn the command! - pp_opts.append ("-D%s=%s" % macro) - - for dir in include_dirs: - pp_opts.append ("-I%s" % dir) - - return pp_opts - - -def gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries): - """Generate linker options for searching library directories and - linking with specific libraries. - - 'libraries' and 'library_dirs' are, respectively, lists of library names - (not filenames!) and search directories. Returns a list of command-line - options suitable for use with some compiler (depending on the two format - strings passed in). - """ - lib_opts = [] - - for dir in library_dirs: - lib_opts.append(compiler.library_dir_option(dir)) - - for dir in runtime_library_dirs: - opt = compiler.runtime_library_dir_option(dir) - if isinstance(opt, list): - lib_opts.extend(opt) - else: - lib_opts.append(opt) - - # XXX it's important that we *not* remove redundant library mentions! - # sometimes you really do have to say "-lfoo -lbar -lfoo" in order to - # resolve all symbols. I just hope we never have to say "-lfoo obj.o - # -lbar" to get things to work -- that's certainly a possibility, but a - # pretty nasty way to arrange your C code. - - for lib in libraries: - lib_dir, lib_name = os.path.split(lib) - if lib_dir != '': - lib_file = compiler.find_library_file([lib_dir], lib_name) - if lib_file is not None: - lib_opts.append(lib_file) - else: - compiler.warn("no library file corresponding to " - "'%s' found (skipping)" % lib) - else: - lib_opts.append(compiler.library_option(lib)) - - return lib_opts diff --git a/PythonLib/extra/distutils/cmd.py b/PythonLib/extra/distutils/cmd.py deleted file mode 100644 index 9ad5657e..00000000 --- a/PythonLib/extra/distutils/cmd.py +++ /dev/null @@ -1,457 +0,0 @@ -"""distutils.cmd - -Provides the Command class, the base class for the command classes -in the distutils.command package. -""" - -__revision__ = "$Id$" - -import sys, os, re -from distutils.errors import DistutilsOptionError -from distutils import util, dir_util, file_util, archive_util, dep_util -from distutils import log - -class Command: - """Abstract base class for defining command classes, the "worker bees" - of the Distutils. A useful analogy for command classes is to think of - them as subroutines with local variables called "options". The options - are "declared" in 'initialize_options()' and "defined" (given their - final values, aka "finalized") in 'finalize_options()', both of which - must be defined by every command class. The distinction between the - two is necessary because option values might come from the outside - world (command line, config file, ...), and any options dependent on - other options must be computed *after* these outside influences have - been processed -- hence 'finalize_options()'. The "body" of the - subroutine, where it does all its work based on the values of its - options, is the 'run()' method, which must also be implemented by every - command class. - """ - - # 'sub_commands' formalizes the notion of a "family" of commands, - # eg. "install" as the parent with sub-commands "install_lib", - # "install_headers", etc. The parent of a family of commands - # defines 'sub_commands' as a class attribute; it's a list of - # (command_name : string, predicate : unbound_method | string | None) - # tuples, where 'predicate' is a method of the parent command that - # determines whether the corresponding command is applicable in the - # current situation. (Eg. we "install_headers" is only applicable if - # we have any C header files to install.) If 'predicate' is None, - # that command is always applicable. - # - # 'sub_commands' is usually defined at the *end* of a class, because - # predicates can be unbound methods, so they must already have been - # defined. The canonical example is the "install" command. - sub_commands = [] - - - # -- Creation/initialization methods ------------------------------- - - def __init__(self, dist): - """Create and initialize a new Command object. Most importantly, - invokes the 'initialize_options()' method, which is the real - initializer and depends on the actual command being - instantiated. - """ - # late import because of mutual dependence between these classes - from distutils.dist import Distribution - - if not isinstance(dist, Distribution): - raise TypeError, "dist must be a Distribution instance" - if self.__class__ is Command: - raise RuntimeError, "Command is an abstract class" - - self.distribution = dist - self.initialize_options() - - # Per-command versions of the global flags, so that the user can - # customize Distutils' behaviour command-by-command and let some - # commands fall back on the Distribution's behaviour. None means - # "not defined, check self.distribution's copy", while 0 or 1 mean - # false and true (duh). Note that this means figuring out the real - # value of each flag is a touch complicated -- hence "self._dry_run" - # will be handled by __getattr__, below. - # XXX This needs to be fixed. - self._dry_run = None - - # verbose is largely ignored, but needs to be set for - # backwards compatibility (I think)? - self.verbose = dist.verbose - - # Some commands define a 'self.force' option to ignore file - # timestamps, but methods defined *here* assume that - # 'self.force' exists for all commands. So define it here - # just to be safe. - self.force = None - - # The 'help' flag is just used for command-line parsing, so - # none of that complicated bureaucracy is needed. - self.help = 0 - - # 'finalized' records whether or not 'finalize_options()' has been - # called. 'finalize_options()' itself should not pay attention to - # this flag: it is the business of 'ensure_finalized()', which - # always calls 'finalize_options()', to respect/update it. - self.finalized = 0 - - # XXX A more explicit way to customize dry_run would be better. - def __getattr__(self, attr): - if attr == 'dry_run': - myval = getattr(self, "_" + attr) - if myval is None: - return getattr(self.distribution, attr) - else: - return myval - else: - raise AttributeError, attr - - def ensure_finalized(self): - if not self.finalized: - self.finalize_options() - self.finalized = 1 - - # Subclasses must define: - # initialize_options() - # provide default values for all options; may be customized by - # setup script, by options from config file(s), or by command-line - # options - # finalize_options() - # decide on the final values for all options; this is called - # after all possible intervention from the outside world - # (command-line, option file, etc.) has been processed - # run() - # run the command: do whatever it is we're here to do, - # controlled by the command's various option values - - def initialize_options(self): - """Set default values for all the options that this command - supports. Note that these defaults may be overridden by other - commands, by the setup script, by config files, or by the - command-line. Thus, this is not the place to code dependencies - between options; generally, 'initialize_options()' implementations - are just a bunch of "self.foo = None" assignments. - - This method must be implemented by all command classes. - """ - raise RuntimeError, \ - "abstract method -- subclass %s must override" % self.__class__ - - def finalize_options(self): - """Set final values for all the options that this command supports. - This is always called as late as possible, ie. after any option - assignments from the command-line or from other commands have been - done. Thus, this is the place to code option dependencies: if - 'foo' depends on 'bar', then it is safe to set 'foo' from 'bar' as - long as 'foo' still has the same value it was assigned in - 'initialize_options()'. - - This method must be implemented by all command classes. - """ - raise RuntimeError, \ - "abstract method -- subclass %s must override" % self.__class__ - - - def dump_options(self, header=None, indent=""): - from distutils.fancy_getopt import longopt_xlate - if header is None: - header = "command options for '%s':" % self.get_command_name() - self.announce(indent + header, level=log.INFO) - indent = indent + " " - for (option, _, _) in self.user_options: - option = option.translate(longopt_xlate) - if option[-1] == "=": - option = option[:-1] - value = getattr(self, option) - self.announce(indent + "%s = %s" % (option, value), - level=log.INFO) - - def run(self): - """A command's raison d'etre: carry out the action it exists to - perform, controlled by the options initialized in - 'initialize_options()', customized by other commands, the setup - script, the command-line, and config files, and finalized in - 'finalize_options()'. All terminal output and filesystem - interaction should be done by 'run()'. - - This method must be implemented by all command classes. - """ - raise RuntimeError, \ - "abstract method -- subclass %s must override" % self.__class__ - - def announce(self, msg, level=1): - """If the current verbosity level is of greater than or equal to - 'level' print 'msg' to stdout. - """ - log.log(level, msg) - - def debug_print(self, msg): - """Print 'msg' to stdout if the global DEBUG (taken from the - DISTUTILS_DEBUG environment variable) flag is true. - """ - from distutils.debug import DEBUG - if DEBUG: - print msg - sys.stdout.flush() - - - # -- Option validation methods ------------------------------------- - # (these are very handy in writing the 'finalize_options()' method) - # - # NB. the general philosophy here is to ensure that a particular option - # value meets certain type and value constraints. If not, we try to - # force it into conformance (eg. if we expect a list but have a string, - # split the string on comma and/or whitespace). If we can't force the - # option into conformance, raise DistutilsOptionError. Thus, command - # classes need do nothing more than (eg.) - # self.ensure_string_list('foo') - # and they can be guaranteed that thereafter, self.foo will be - # a list of strings. - - def _ensure_stringlike(self, option, what, default=None): - val = getattr(self, option) - if val is None: - setattr(self, option, default) - return default - elif not isinstance(val, str): - raise DistutilsOptionError, \ - "'%s' must be a %s (got `%s`)" % (option, what, val) - return val - - def ensure_string(self, option, default=None): - """Ensure that 'option' is a string; if not defined, set it to - 'default'. - """ - self._ensure_stringlike(option, "string", default) - - def ensure_string_list(self, option): - """Ensure that 'option' is a list of strings. If 'option' is - currently a string, we split it either on /,\s*/ or /\s+/, so - "foo bar baz", "foo,bar,baz", and "foo, bar baz" all become - ["foo", "bar", "baz"]. - """ - val = getattr(self, option) - if val is None: - return - elif isinstance(val, str): - setattr(self, option, re.split(r',\s*|\s+', val)) - else: - if isinstance(val, list): - # checks if all elements are str - ok = 1 - for element in val: - if not isinstance(element, str): - ok = 0 - break - else: - ok = 0 - - if not ok: - raise DistutilsOptionError, \ - "'%s' must be a list of strings (got %r)" % \ - (option, val) - - - def _ensure_tested_string(self, option, tester, - what, error_fmt, default=None): - val = self._ensure_stringlike(option, what, default) - if val is not None and not tester(val): - raise DistutilsOptionError, \ - ("error in '%s' option: " + error_fmt) % (option, val) - - def ensure_filename(self, option): - """Ensure that 'option' is the name of an existing file.""" - self._ensure_tested_string(option, os.path.isfile, - "filename", - "'%s' does not exist or is not a file") - - def ensure_dirname(self, option): - self._ensure_tested_string(option, os.path.isdir, - "directory name", - "'%s' does not exist or is not a directory") - - - # -- Convenience methods for commands ------------------------------ - - def get_command_name(self): - if hasattr(self, 'command_name'): - return self.command_name - else: - return self.__class__.__name__ - - def set_undefined_options(self, src_cmd, *option_pairs): - """Set the values of any "undefined" options from corresponding - option values in some other command object. "Undefined" here means - "is None", which is the convention used to indicate that an option - has not been changed between 'initialize_options()' and - 'finalize_options()'. Usually called from 'finalize_options()' for - options that depend on some other command rather than another - option of the same command. 'src_cmd' is the other command from - which option values will be taken (a command object will be created - for it if necessary); the remaining arguments are - '(src_option,dst_option)' tuples which mean "take the value of - 'src_option' in the 'src_cmd' command object, and copy it to - 'dst_option' in the current command object". - """ - - # Option_pairs: list of (src_option, dst_option) tuples - - src_cmd_obj = self.distribution.get_command_obj(src_cmd) - src_cmd_obj.ensure_finalized() - for (src_option, dst_option) in option_pairs: - if getattr(self, dst_option) is None: - setattr(self, dst_option, - getattr(src_cmd_obj, src_option)) - - - def get_finalized_command(self, command, create=1): - """Wrapper around Distribution's 'get_command_obj()' method: find - (create if necessary and 'create' is true) the command object for - 'command', call its 'ensure_finalized()' method, and return the - finalized command object. - """ - cmd_obj = self.distribution.get_command_obj(command, create) - cmd_obj.ensure_finalized() - return cmd_obj - - # XXX rename to 'get_reinitialized_command()'? (should do the - # same in dist.py, if so) - def reinitialize_command(self, command, reinit_subcommands=0): - return self.distribution.reinitialize_command( - command, reinit_subcommands) - - def run_command(self, command): - """Run some other command: uses the 'run_command()' method of - Distribution, which creates and finalizes the command object if - necessary and then invokes its 'run()' method. - """ - self.distribution.run_command(command) - - def get_sub_commands(self): - """Determine the sub-commands that are relevant in the current - distribution (ie., that need to be run). This is based on the - 'sub_commands' class attribute: each tuple in that list may include - a method that we call to determine if the subcommand needs to be - run for the current distribution. Return a list of command names. - """ - commands = [] - for (cmd_name, method) in self.sub_commands: - if method is None or method(self): - commands.append(cmd_name) - return commands - - - # -- External world manipulation ----------------------------------- - - def warn(self, msg): - log.warn("warning: %s: %s\n" % - (self.get_command_name(), msg)) - - def execute(self, func, args, msg=None, level=1): - util.execute(func, args, msg, dry_run=self.dry_run) - - def mkpath(self, name, mode=0777): - dir_util.mkpath(name, mode, dry_run=self.dry_run) - - def copy_file(self, infile, outfile, - preserve_mode=1, preserve_times=1, link=None, level=1): - """Copy a file respecting verbose, dry-run and force flags. (The - former two default to whatever is in the Distribution object, and - the latter defaults to false for commands that don't define it.)""" - - return file_util.copy_file( - infile, outfile, - preserve_mode, preserve_times, - not self.force, - link, - dry_run=self.dry_run) - - def copy_tree(self, infile, outfile, - preserve_mode=1, preserve_times=1, preserve_symlinks=0, - level=1): - """Copy an entire directory tree respecting verbose, dry-run, - and force flags. - """ - return dir_util.copy_tree( - infile, outfile, - preserve_mode,preserve_times,preserve_symlinks, - not self.force, - dry_run=self.dry_run) - - def move_file (self, src, dst, level=1): - """Move a file respecting dry-run flag.""" - return file_util.move_file(src, dst, dry_run = self.dry_run) - - def spawn (self, cmd, search_path=1, level=1): - """Spawn an external command respecting dry-run flag.""" - from distutils.spawn import spawn - spawn(cmd, search_path, dry_run= self.dry_run) - - def make_archive(self, base_name, format, root_dir=None, base_dir=None, - owner=None, group=None): - return archive_util.make_archive(base_name, format, root_dir, - base_dir, dry_run=self.dry_run, - owner=owner, group=group) - - def make_file(self, infiles, outfile, func, args, - exec_msg=None, skip_msg=None, level=1): - """Special case of 'execute()' for operations that process one or - more input files and generate one output file. Works just like - 'execute()', except the operation is skipped and a different - message printed if 'outfile' already exists and is newer than all - files listed in 'infiles'. If the command defined 'self.force', - and it is true, then the command is unconditionally run -- does no - timestamp checks. - """ - if skip_msg is None: - skip_msg = "skipping %s (inputs unchanged)" % outfile - - # Allow 'infiles' to be a single string - if isinstance(infiles, str): - infiles = (infiles,) - elif not isinstance(infiles, (list, tuple)): - raise TypeError, \ - "'infiles' must be a string, or a list or tuple of strings" - - if exec_msg is None: - exec_msg = "generating %s from %s" % \ - (outfile, ', '.join(infiles)) - - # If 'outfile' must be regenerated (either because it doesn't - # exist, is out-of-date, or the 'force' flag is true) then - # perform the action that presumably regenerates it - if self.force or dep_util.newer_group(infiles, outfile): - self.execute(func, args, exec_msg, level) - - # Otherwise, print the "skip" message - else: - log.debug(skip_msg) - -# XXX 'install_misc' class not currently used -- it was the base class for -# both 'install_scripts' and 'install_data', but they outgrew it. It might -# still be useful for 'install_headers', though, so I'm keeping it around -# for the time being. - -class install_misc(Command): - """Common base class for installing some files in a subdirectory. - Currently used by install_data and install_scripts. - """ - - user_options = [('install-dir=', 'd', "directory to install the files to")] - - def initialize_options (self): - self.install_dir = None - self.outfiles = [] - - def _install_dir_from(self, dirname): - self.set_undefined_options('install', (dirname, 'install_dir')) - - def _copy_files(self, filelist): - self.outfiles = [] - if not filelist: - return - self.mkpath(self.install_dir) - for f in filelist: - self.copy_file(f, self.install_dir) - self.outfiles.append(os.path.join(self.install_dir, f)) - - def get_outputs(self): - return self.outfiles diff --git a/PythonLib/extra/distutils/command/__init__.py b/PythonLib/extra/distutils/command/__init__.py deleted file mode 100644 index 20b159f7..00000000 --- a/PythonLib/extra/distutils/command/__init__.py +++ /dev/null @@ -1,33 +0,0 @@ -"""distutils.command - -Package containing implementation of all the standard Distutils -commands.""" - -__revision__ = "$Id$" - -__all__ = ['build', - 'build_py', - 'build_ext', - 'build_clib', - 'build_scripts', - 'clean', - 'install', - 'install_lib', - 'install_headers', - 'install_scripts', - 'install_data', - 'sdist', - 'register', - 'bdist', - 'bdist_dumb', - 'bdist_rpm', - 'bdist_wininst', - 'upload', - 'check', - # These two are reserved for future use: - #'bdist_sdux', - #'bdist_pkgtool', - # Note: - # bdist_packager is not included because it only provides - # an abstract base class - ] diff --git a/PythonLib/extra/distutils/command/bdist.py b/PythonLib/extra/distutils/command/bdist.py deleted file mode 100644 index d7910b14..00000000 --- a/PythonLib/extra/distutils/command/bdist.py +++ /dev/null @@ -1,146 +0,0 @@ -"""distutils.command.bdist - -Implements the Distutils 'bdist' command (create a built [binary] -distribution).""" - -__revision__ = "$Id$" - -import os - -from distutils.util import get_platform -from distutils.core import Command -from distutils.errors import DistutilsPlatformError, DistutilsOptionError - - -def show_formats(): - """Print list of available formats (arguments to "--format" option). - """ - from distutils.fancy_getopt import FancyGetopt - formats = [] - for format in bdist.format_commands: - formats.append(("formats=" + format, None, - bdist.format_command[format][1])) - pretty_printer = FancyGetopt(formats) - pretty_printer.print_help("List of available distribution formats:") - - -class bdist(Command): - - description = "create a built (binary) distribution" - - user_options = [('bdist-base=', 'b', - "temporary directory for creating built distributions"), - ('plat-name=', 'p', - "platform name to embed in generated filenames " - "(default: %s)" % get_platform()), - ('formats=', None, - "formats for distribution (comma-separated list)"), - ('dist-dir=', 'd', - "directory to put final built distributions in " - "[default: dist]"), - ('skip-build', None, - "skip rebuilding everything (for testing/debugging)"), - ('owner=', 'u', - "Owner name used when creating a tar file" - " [default: current user]"), - ('group=', 'g', - "Group name used when creating a tar file" - " [default: current group]"), - ] - - boolean_options = ['skip-build'] - - help_options = [ - ('help-formats', None, - "lists available distribution formats", show_formats), - ] - - # The following commands do not take a format option from bdist - no_format_option = ('bdist_rpm',) - - # This won't do in reality: will need to distinguish RPM-ish Linux, - # Debian-ish Linux, Solaris, FreeBSD, ..., Windows, Mac OS. - default_format = {'posix': 'gztar', - 'nt': 'zip', - 'os2': 'zip'} - - # Establish the preferred order (for the --help-formats option). - format_commands = ['rpm', 'gztar', 'bztar', 'ztar', 'tar', - 'wininst', 'zip', 'msi'] - - # And the real information. - format_command = {'rpm': ('bdist_rpm', "RPM distribution"), - 'gztar': ('bdist_dumb', "gzip'ed tar file"), - 'bztar': ('bdist_dumb', "bzip2'ed tar file"), - 'ztar': ('bdist_dumb', "compressed tar file"), - 'tar': ('bdist_dumb', "tar file"), - 'wininst': ('bdist_wininst', - "Windows executable installer"), - 'zip': ('bdist_dumb', "ZIP file"), - 'msi': ('bdist_msi', "Microsoft Installer") - } - - - def initialize_options(self): - self.bdist_base = None - self.plat_name = None - self.formats = None - self.dist_dir = None - self.skip_build = 0 - self.group = None - self.owner = None - - def finalize_options(self): - # have to finalize 'plat_name' before 'bdist_base' - if self.plat_name is None: - if self.skip_build: - self.plat_name = get_platform() - else: - self.plat_name = self.get_finalized_command('build').plat_name - - # 'bdist_base' -- parent of per-built-distribution-format - # temporary directories (eg. we'll probably have - # "build/bdist./dumb", "build/bdist./rpm", etc.) - if self.bdist_base is None: - build_base = self.get_finalized_command('build').build_base - self.bdist_base = os.path.join(build_base, - 'bdist.' + self.plat_name) - - self.ensure_string_list('formats') - if self.formats is None: - try: - self.formats = [self.default_format[os.name]] - except KeyError: - raise DistutilsPlatformError, \ - "don't know how to create built distributions " + \ - "on platform %s" % os.name - - if self.dist_dir is None: - self.dist_dir = "dist" - - def run(self): - # Figure out which sub-commands we need to run. - commands = [] - for format in self.formats: - try: - commands.append(self.format_command[format][0]) - except KeyError: - raise DistutilsOptionError, "invalid format '%s'" % format - - # Reinitialize and run each command. - for i in range(len(self.formats)): - cmd_name = commands[i] - sub_cmd = self.reinitialize_command(cmd_name) - if cmd_name not in self.no_format_option: - sub_cmd.format = self.formats[i] - - # passing the owner and group names for tar archiving - if cmd_name == 'bdist_dumb': - sub_cmd.owner = self.owner - sub_cmd.group = self.group - - # If we're going to need to run this command again, tell it to - # keep its temporary files around so subsequent runs go faster. - if cmd_name in commands[i+1:]: - sub_cmd.keep_temp = 1 - self.run_command(cmd_name) diff --git a/PythonLib/extra/distutils/command/bdist_dumb.py b/PythonLib/extra/distutils/command/bdist_dumb.py deleted file mode 100644 index 2f3c6682..00000000 --- a/PythonLib/extra/distutils/command/bdist_dumb.py +++ /dev/null @@ -1,133 +0,0 @@ -"""distutils.command.bdist_dumb - -Implements the Distutils 'bdist_dumb' command (create a "dumb" built -distribution -- i.e., just an archive to be unpacked under $prefix or -$exec_prefix).""" - -__revision__ = "$Id$" - -import os - -from sysconfig import get_python_version - -from distutils.util import get_platform -from distutils.core import Command -from distutils.dir_util import remove_tree, ensure_relative -from distutils.errors import DistutilsPlatformError -from distutils import log - -class bdist_dumb (Command): - - description = 'create a "dumb" built distribution' - - user_options = [('bdist-dir=', 'd', - "temporary directory for creating the distribution"), - ('plat-name=', 'p', - "platform name to embed in generated filenames " - "(default: %s)" % get_platform()), - ('format=', 'f', - "archive format to create (tar, ztar, gztar, zip)"), - ('keep-temp', 'k', - "keep the pseudo-installation tree around after " + - "creating the distribution archive"), - ('dist-dir=', 'd', - "directory to put final built distributions in"), - ('skip-build', None, - "skip rebuilding everything (for testing/debugging)"), - ('relative', None, - "build the archive using relative paths" - "(default: false)"), - ('owner=', 'u', - "Owner name used when creating a tar file" - " [default: current user]"), - ('group=', 'g', - "Group name used when creating a tar file" - " [default: current group]"), - ] - - boolean_options = ['keep-temp', 'skip-build', 'relative'] - - default_format = { 'posix': 'gztar', - 'nt': 'zip', - 'os2': 'zip' } - - - def initialize_options (self): - self.bdist_dir = None - self.plat_name = None - self.format = None - self.keep_temp = 0 - self.dist_dir = None - self.skip_build = None - self.relative = 0 - self.owner = None - self.group = None - - def finalize_options(self): - if self.bdist_dir is None: - bdist_base = self.get_finalized_command('bdist').bdist_base - self.bdist_dir = os.path.join(bdist_base, 'dumb') - - if self.format is None: - try: - self.format = self.default_format[os.name] - except KeyError: - raise DistutilsPlatformError, \ - ("don't know how to create dumb built distributions " + - "on platform %s") % os.name - - self.set_undefined_options('bdist', - ('dist_dir', 'dist_dir'), - ('plat_name', 'plat_name'), - ('skip_build', 'skip_build')) - - def run(self): - if not self.skip_build: - self.run_command('build') - - install = self.reinitialize_command('install', reinit_subcommands=1) - install.root = self.bdist_dir - install.skip_build = self.skip_build - install.warn_dir = 0 - - log.info("installing to %s" % self.bdist_dir) - self.run_command('install') - - # And make an archive relative to the root of the - # pseudo-installation tree. - archive_basename = "%s.%s" % (self.distribution.get_fullname(), - self.plat_name) - - # OS/2 objects to any ":" characters in a filename (such as when - # a timestamp is used in a version) so change them to hyphens. - if os.name == "os2": - archive_basename = archive_basename.replace(":", "-") - - pseudoinstall_root = os.path.join(self.dist_dir, archive_basename) - if not self.relative: - archive_root = self.bdist_dir - else: - if (self.distribution.has_ext_modules() and - (install.install_base != install.install_platbase)): - raise DistutilsPlatformError, \ - ("can't make a dumb built distribution where " - "base and platbase are different (%s, %s)" - % (repr(install.install_base), - repr(install.install_platbase))) - else: - archive_root = os.path.join(self.bdist_dir, - ensure_relative(install.install_base)) - - # Make the archive - filename = self.make_archive(pseudoinstall_root, - self.format, root_dir=archive_root, - owner=self.owner, group=self.group) - if self.distribution.has_ext_modules(): - pyversion = get_python_version() - else: - pyversion = 'any' - self.distribution.dist_files.append(('bdist_dumb', pyversion, - filename)) - - if not self.keep_temp: - remove_tree(self.bdist_dir, dry_run=self.dry_run) diff --git a/PythonLib/extra/distutils/command/bdist_msi.py b/PythonLib/extra/distutils/command/bdist_msi.py deleted file mode 100644 index 703f873b..00000000 --- a/PythonLib/extra/distutils/command/bdist_msi.py +++ /dev/null @@ -1,742 +0,0 @@ -# -*- coding: iso-8859-1 -*- -# Copyright (C) 2005, 2006 Martin von Lwis -# Licensed to PSF under a Contributor Agreement. -# The bdist_wininst command proper -# based on bdist_wininst -""" -Implements the bdist_msi command. -""" -import sys, os -from sysconfig import get_python_version - -from distutils.core import Command -from distutils.dir_util import remove_tree -from distutils.version import StrictVersion -from distutils.errors import DistutilsOptionError -from distutils import log -from distutils.util import get_platform - -import msilib -from msilib import schema, sequence, text -from msilib import Directory, Feature, Dialog, add_data - -class PyDialog(Dialog): - """Dialog class with a fixed layout: controls at the top, then a ruler, - then a list of buttons: back, next, cancel. Optionally a bitmap at the - left.""" - def __init__(self, *args, **kw): - """Dialog(database, name, x, y, w, h, attributes, title, first, - default, cancel, bitmap=true)""" - Dialog.__init__(self, *args) - ruler = self.h - 36 - #if kw.get("bitmap", True): - # self.bitmap("Bitmap", 0, 0, bmwidth, ruler, "PythonWin") - self.line("BottomLine", 0, ruler, self.w, 0) - - def title(self, title): - "Set the title text of the dialog at the top." - # name, x, y, w, h, flags=Visible|Enabled|Transparent|NoPrefix, - # text, in VerdanaBold10 - self.text("Title", 15, 10, 320, 60, 0x30003, - r"{\VerdanaBold10}%s" % title) - - def back(self, title, next, name = "Back", active = 1): - """Add a back button with a given title, the tab-next button, - its name in the Control table, possibly initially disabled. - - Return the button, so that events can be associated""" - if active: - flags = 3 # Visible|Enabled - else: - flags = 1 # Visible - return self.pushbutton(name, 180, self.h-27 , 56, 17, flags, title, next) - - def cancel(self, title, next, name = "Cancel", active = 1): - """Add a cancel button with a given title, the tab-next button, - its name in the Control table, possibly initially disabled. - - Return the button, so that events can be associated""" - if active: - flags = 3 # Visible|Enabled - else: - flags = 1 # Visible - return self.pushbutton(name, 304, self.h-27, 56, 17, flags, title, next) - - def next(self, title, next, name = "Next", active = 1): - """Add a Next button with a given title, the tab-next button, - its name in the Control table, possibly initially disabled. - - Return the button, so that events can be associated""" - if active: - flags = 3 # Visible|Enabled - else: - flags = 1 # Visible - return self.pushbutton(name, 236, self.h-27, 56, 17, flags, title, next) - - def xbutton(self, name, title, next, xpos): - """Add a button with a given title, the tab-next button, - its name in the Control table, giving its x position; the - y-position is aligned with the other buttons. - - Return the button, so that events can be associated""" - return self.pushbutton(name, int(self.w*xpos - 28), self.h-27, 56, 17, 3, title, next) - -class bdist_msi (Command): - - description = "create a Microsoft Installer (.msi) binary distribution" - - user_options = [('bdist-dir=', None, - "temporary directory for creating the distribution"), - ('plat-name=', 'p', - "platform name to embed in generated filenames " - "(default: %s)" % get_platform()), - ('keep-temp', 'k', - "keep the pseudo-installation tree around after " + - "creating the distribution archive"), - ('target-version=', None, - "require a specific python version" + - " on the target system"), - ('no-target-compile', 'c', - "do not compile .py to .pyc on the target system"), - ('no-target-optimize', 'o', - "do not compile .py to .pyo (optimized)" - "on the target system"), - ('dist-dir=', 'd', - "directory to put final built distributions in"), - ('skip-build', None, - "skip rebuilding everything (for testing/debugging)"), - ('install-script=', None, - "basename of installation script to be run after" - "installation or before deinstallation"), - ('pre-install-script=', None, - "Fully qualified filename of a script to be run before " - "any files are installed. This script need not be in the " - "distribution"), - ] - - boolean_options = ['keep-temp', 'no-target-compile', 'no-target-optimize', - 'skip-build'] - - all_versions = ['2.0', '2.1', '2.2', '2.3', '2.4', - '2.5', '2.6', '2.7', '2.8', '2.9', - '3.0', '3.1', '3.2', '3.3', '3.4', - '3.5', '3.6', '3.7', '3.8', '3.9'] - other_version = 'X' - - def initialize_options (self): - self.bdist_dir = None - self.plat_name = None - self.keep_temp = 0 - self.no_target_compile = 0 - self.no_target_optimize = 0 - self.target_version = None - self.dist_dir = None - self.skip_build = None - self.install_script = None - self.pre_install_script = None - self.versions = None - - def finalize_options (self): - self.set_undefined_options('bdist', ('skip_build', 'skip_build')) - - if self.bdist_dir is None: - bdist_base = self.get_finalized_command('bdist').bdist_base - self.bdist_dir = os.path.join(bdist_base, 'msi') - - short_version = get_python_version() - if (not self.target_version) and self.distribution.has_ext_modules(): - self.target_version = short_version - - if self.target_version: - self.versions = [self.target_version] - if not self.skip_build and self.distribution.has_ext_modules()\ - and self.target_version != short_version: - raise DistutilsOptionError, \ - "target version can only be %s, or the '--skip-build'" \ - " option must be specified" % (short_version,) - else: - self.versions = list(self.all_versions) - - self.set_undefined_options('bdist', - ('dist_dir', 'dist_dir'), - ('plat_name', 'plat_name'), - ) - - if self.pre_install_script: - raise DistutilsOptionError, "the pre-install-script feature is not yet implemented" - - if self.install_script: - for script in self.distribution.scripts: - if self.install_script == os.path.basename(script): - break - else: - raise DistutilsOptionError, \ - "install_script '%s' not found in scripts" % \ - self.install_script - self.install_script_key = None - # finalize_options() - - - def run (self): - if not self.skip_build: - self.run_command('build') - - install = self.reinitialize_command('install', reinit_subcommands=1) - install.prefix = self.bdist_dir - install.skip_build = self.skip_build - install.warn_dir = 0 - - install_lib = self.reinitialize_command('install_lib') - # we do not want to include pyc or pyo files - install_lib.compile = 0 - install_lib.optimize = 0 - - if self.distribution.has_ext_modules(): - # If we are building an installer for a Python version other - # than the one we are currently running, then we need to ensure - # our build_lib reflects the other Python version rather than ours. - # Note that for target_version!=sys.version, we must have skipped the - # build step, so there is no issue with enforcing the build of this - # version. - target_version = self.target_version - if not target_version: - assert self.skip_build, "Should have already checked this" - target_version = sys.version[0:3] - plat_specifier = ".%s-%s" % (self.plat_name, target_version) - build = self.get_finalized_command('build') - build.build_lib = os.path.join(build.build_base, - 'lib' + plat_specifier) - - log.info("installing to %s", self.bdist_dir) - install.ensure_finalized() - - # avoid warning of 'install_lib' about installing - # into a directory not in sys.path - sys.path.insert(0, os.path.join(self.bdist_dir, 'PURELIB')) - - install.run() - - del sys.path[0] - - self.mkpath(self.dist_dir) - fullname = self.distribution.get_fullname() - installer_name = self.get_installer_filename(fullname) - installer_name = os.path.abspath(installer_name) - if os.path.exists(installer_name): os.unlink(installer_name) - - metadata = self.distribution.metadata - author = metadata.author - if not author: - author = metadata.maintainer - if not author: - author = "UNKNOWN" - version = metadata.get_version() - # ProductVersion must be strictly numeric - # XXX need to deal with prerelease versions - sversion = "%d.%d.%d" % StrictVersion(version).version - # Prefix ProductName with Python x.y, so that - # it sorts together with the other Python packages - # in Add-Remove-Programs (APR) - fullname = self.distribution.get_fullname() - if self.target_version: - product_name = "Python %s %s" % (self.target_version, fullname) - else: - product_name = "Python %s" % (fullname) - self.db = msilib.init_database(installer_name, schema, - product_name, msilib.gen_uuid(), - sversion, author) - msilib.add_tables(self.db, sequence) - props = [('DistVersion', version)] - email = metadata.author_email or metadata.maintainer_email - if email: - props.append(("ARPCONTACT", email)) - if metadata.url: - props.append(("ARPURLINFOABOUT", metadata.url)) - if props: - add_data(self.db, 'Property', props) - - self.add_find_python() - self.add_files() - self.add_scripts() - self.add_ui() - self.db.Commit() - - if hasattr(self.distribution, 'dist_files'): - tup = 'bdist_msi', self.target_version or 'any', fullname - self.distribution.dist_files.append(tup) - - if not self.keep_temp: - remove_tree(self.bdist_dir, dry_run=self.dry_run) - - def add_files(self): - db = self.db - cab = msilib.CAB("distfiles") - rootdir = os.path.abspath(self.bdist_dir) - - root = Directory(db, cab, None, rootdir, "TARGETDIR", "SourceDir") - f = Feature(db, "Python", "Python", "Everything", - 0, 1, directory="TARGETDIR") - - items = [(f, root, '')] - for version in self.versions + [self.other_version]: - target = "TARGETDIR" + version - name = default = "Python" + version - desc = "Everything" - if version is self.other_version: - title = "Python from another location" - level = 2 - else: - title = "Python %s from registry" % version - level = 1 - f = Feature(db, name, title, desc, 1, level, directory=target) - dir = Directory(db, cab, root, rootdir, target, default) - items.append((f, dir, version)) - db.Commit() - - seen = {} - for feature, dir, version in items: - todo = [dir] - while todo: - dir = todo.pop() - for file in os.listdir(dir.absolute): - afile = os.path.join(dir.absolute, file) - if os.path.isdir(afile): - short = "%s|%s" % (dir.make_short(file), file) - default = file + version - newdir = Directory(db, cab, dir, file, default, short) - todo.append(newdir) - else: - if not dir.component: - dir.start_component(dir.logical, feature, 0) - if afile not in seen: - key = seen[afile] = dir.add_file(file) - if file==self.install_script: - if self.install_script_key: - raise DistutilsOptionError( - "Multiple files with name %s" % file) - self.install_script_key = '[#%s]' % key - else: - key = seen[afile] - add_data(self.db, "DuplicateFile", - [(key + version, dir.component, key, None, dir.logical)]) - db.Commit() - cab.commit(db) - - def add_find_python(self): - """Adds code to the installer to compute the location of Python. - - Properties PYTHON.MACHINE.X.Y and PYTHON.USER.X.Y will be set from the - registry for each version of Python. - - Properties TARGETDIRX.Y will be set from PYTHON.USER.X.Y if defined, - else from PYTHON.MACHINE.X.Y. - - Properties PYTHONX.Y will be set to TARGETDIRX.Y\\python.exe""" - - start = 402 - for ver in self.versions: - install_path = r"SOFTWARE\Python\PythonCore\%s\InstallPath" % ver - machine_reg = "python.machine." + ver - user_reg = "python.user." + ver - machine_prop = "PYTHON.MACHINE." + ver - user_prop = "PYTHON.USER." + ver - machine_action = "PythonFromMachine" + ver - user_action = "PythonFromUser" + ver - exe_action = "PythonExe" + ver - target_dir_prop = "TARGETDIR" + ver - exe_prop = "PYTHON" + ver - if msilib.Win64: - # type: msidbLocatorTypeRawValue + msidbLocatorType64bit - Type = 2+16 - else: - Type = 2 - add_data(self.db, "RegLocator", - [(machine_reg, 2, install_path, None, Type), - (user_reg, 1, install_path, None, Type)]) - add_data(self.db, "AppSearch", - [(machine_prop, machine_reg), - (user_prop, user_reg)]) - add_data(self.db, "CustomAction", - [(machine_action, 51+256, target_dir_prop, "[" + machine_prop + "]"), - (user_action, 51+256, target_dir_prop, "[" + user_prop + "]"), - (exe_action, 51+256, exe_prop, "[" + target_dir_prop + "]\\python.exe"), - ]) - add_data(self.db, "InstallExecuteSequence", - [(machine_action, machine_prop, start), - (user_action, user_prop, start + 1), - (exe_action, None, start + 2), - ]) - add_data(self.db, "InstallUISequence", - [(machine_action, machine_prop, start), - (user_action, user_prop, start + 1), - (exe_action, None, start + 2), - ]) - add_data(self.db, "Condition", - [("Python" + ver, 0, "NOT TARGETDIR" + ver)]) - start += 4 - assert start < 500 - - def add_scripts(self): - if self.install_script: - start = 6800 - for ver in self.versions + [self.other_version]: - install_action = "install_script." + ver - exe_prop = "PYTHON" + ver - add_data(self.db, "CustomAction", - [(install_action, 50, exe_prop, self.install_script_key)]) - add_data(self.db, "InstallExecuteSequence", - [(install_action, "&Python%s=3" % ver, start)]) - start += 1 - # XXX pre-install scripts are currently refused in finalize_options() - # but if this feature is completed, it will also need to add - # entries for each version as the above code does - if self.pre_install_script: - scriptfn = os.path.join(self.bdist_dir, "preinstall.bat") - f = open(scriptfn, "w") - # The batch file will be executed with [PYTHON], so that %1 - # is the path to the Python interpreter; %0 will be the path - # of the batch file. - # rem =""" - # %1 %0 - # exit - # """ - # - f.write('rem ="""\n%1 %0\nexit\n"""\n') - f.write(open(self.pre_install_script).read()) - f.close() - add_data(self.db, "Binary", - [("PreInstall", msilib.Binary(scriptfn)) - ]) - add_data(self.db, "CustomAction", - [("PreInstall", 2, "PreInstall", None) - ]) - add_data(self.db, "InstallExecuteSequence", - [("PreInstall", "NOT Installed", 450)]) - - - def add_ui(self): - db = self.db - x = y = 50 - w = 370 - h = 300 - title = "[ProductName] Setup" - - # see "Dialog Style Bits" - modal = 3 # visible | modal - modeless = 1 # visible - - # UI customization properties - add_data(db, "Property", - # See "DefaultUIFont Property" - [("DefaultUIFont", "DlgFont8"), - # See "ErrorDialog Style Bit" - ("ErrorDialog", "ErrorDlg"), - ("Progress1", "Install"), # modified in maintenance type dlg - ("Progress2", "installs"), - ("MaintenanceForm_Action", "Repair"), - # possible values: ALL, JUSTME - ("WhichUsers", "ALL") - ]) - - # Fonts, see "TextStyle Table" - add_data(db, "TextStyle", - [("DlgFont8", "Tahoma", 9, None, 0), - ("DlgFontBold8", "Tahoma", 8, None, 1), #bold - ("VerdanaBold10", "Verdana", 10, None, 1), - ("VerdanaRed9", "Verdana", 9, 255, 0), - ]) - - # UI Sequences, see "InstallUISequence Table", "Using a Sequence Table" - # Numbers indicate sequence; see sequence.py for how these action integrate - add_data(db, "InstallUISequence", - [("PrepareDlg", "Not Privileged or Windows9x or Installed", 140), - ("WhichUsersDlg", "Privileged and not Windows9x and not Installed", 141), - # In the user interface, assume all-users installation if privileged. - ("SelectFeaturesDlg", "Not Installed", 1230), - # XXX no support for resume installations yet - #("ResumeDlg", "Installed AND (RESUME OR Preselected)", 1240), - ("MaintenanceTypeDlg", "Installed AND NOT RESUME AND NOT Preselected", 1250), - ("ProgressDlg", None, 1280)]) - - add_data(db, 'ActionText', text.ActionText) - add_data(db, 'UIText', text.UIText) - ##################################################################### - # Standard dialogs: FatalError, UserExit, ExitDialog - fatal=PyDialog(db, "FatalError", x, y, w, h, modal, title, - "Finish", "Finish", "Finish") - fatal.title("[ProductName] Installer ended prematurely") - fatal.back("< Back", "Finish", active = 0) - fatal.cancel("Cancel", "Back", active = 0) - fatal.text("Description1", 15, 70, 320, 80, 0x30003, - "[ProductName] setup ended prematurely because of an error. Your system has not been modified. To install this program at a later time, please run the installation again.") - fatal.text("Description2", 15, 155, 320, 20, 0x30003, - "Click the Finish button to exit the Installer.") - c=fatal.next("Finish", "Cancel", name="Finish") - c.event("EndDialog", "Exit") - - user_exit=PyDialog(db, "UserExit", x, y, w, h, modal, title, - "Finish", "Finish", "Finish") - user_exit.title("[ProductName] Installer was interrupted") - user_exit.back("< Back", "Finish", active = 0) - user_exit.cancel("Cancel", "Back", active = 0) - user_exit.text("Description1", 15, 70, 320, 80, 0x30003, - "[ProductName] setup was interrupted. Your system has not been modified. " - "To install this program at a later time, please run the installation again.") - user_exit.text("Description2", 15, 155, 320, 20, 0x30003, - "Click the Finish button to exit the Installer.") - c = user_exit.next("Finish", "Cancel", name="Finish") - c.event("EndDialog", "Exit") - - exit_dialog = PyDialog(db, "ExitDialog", x, y, w, h, modal, title, - "Finish", "Finish", "Finish") - exit_dialog.title("Completing the [ProductName] Installer") - exit_dialog.back("< Back", "Finish", active = 0) - exit_dialog.cancel("Cancel", "Back", active = 0) - exit_dialog.text("Description", 15, 235, 320, 20, 0x30003, - "Click the Finish button to exit the Installer.") - c = exit_dialog.next("Finish", "Cancel", name="Finish") - c.event("EndDialog", "Return") - - ##################################################################### - # Required dialog: FilesInUse, ErrorDlg - inuse = PyDialog(db, "FilesInUse", - x, y, w, h, - 19, # KeepModeless|Modal|Visible - title, - "Retry", "Retry", "Retry", bitmap=False) - inuse.text("Title", 15, 6, 200, 15, 0x30003, - r"{\DlgFontBold8}Files in Use") - inuse.text("Description", 20, 23, 280, 20, 0x30003, - "Some files that need to be updated are currently in use.") - inuse.text("Text", 20, 55, 330, 50, 3, - "The following applications are using files that need to be updated by this setup. Close these applications and then click Retry to continue the installation or Cancel to exit it.") - inuse.control("List", "ListBox", 20, 107, 330, 130, 7, "FileInUseProcess", - None, None, None) - c=inuse.back("Exit", "Ignore", name="Exit") - c.event("EndDialog", "Exit") - c=inuse.next("Ignore", "Retry", name="Ignore") - c.event("EndDialog", "Ignore") - c=inuse.cancel("Retry", "Exit", name="Retry") - c.event("EndDialog","Retry") - - # See "Error Dialog". See "ICE20" for the required names of the controls. - error = Dialog(db, "ErrorDlg", - 50, 10, 330, 101, - 65543, # Error|Minimize|Modal|Visible - title, - "ErrorText", None, None) - error.text("ErrorText", 50,9,280,48,3, "") - #error.control("ErrorIcon", "Icon", 15, 9, 24, 24, 5242881, None, "py.ico", None, None) - error.pushbutton("N",120,72,81,21,3,"No",None).event("EndDialog","ErrorNo") - error.pushbutton("Y",240,72,81,21,3,"Yes",None).event("EndDialog","ErrorYes") - error.pushbutton("A",0,72,81,21,3,"Abort",None).event("EndDialog","ErrorAbort") - error.pushbutton("C",42,72,81,21,3,"Cancel",None).event("EndDialog","ErrorCancel") - error.pushbutton("I",81,72,81,21,3,"Ignore",None).event("EndDialog","ErrorIgnore") - error.pushbutton("O",159,72,81,21,3,"Ok",None).event("EndDialog","ErrorOk") - error.pushbutton("R",198,72,81,21,3,"Retry",None).event("EndDialog","ErrorRetry") - - ##################################################################### - # Global "Query Cancel" dialog - cancel = Dialog(db, "CancelDlg", 50, 10, 260, 85, 3, title, - "No", "No", "No") - cancel.text("Text", 48, 15, 194, 30, 3, - "Are you sure you want to cancel [ProductName] installation?") - #cancel.control("Icon", "Icon", 15, 15, 24, 24, 5242881, None, - # "py.ico", None, None) - c=cancel.pushbutton("Yes", 72, 57, 56, 17, 3, "Yes", "No") - c.event("EndDialog", "Exit") - - c=cancel.pushbutton("No", 132, 57, 56, 17, 3, "No", "Yes") - c.event("EndDialog", "Return") - - ##################################################################### - # Global "Wait for costing" dialog - costing = Dialog(db, "WaitForCostingDlg", 50, 10, 260, 85, modal, title, - "Return", "Return", "Return") - costing.text("Text", 48, 15, 194, 30, 3, - "Please wait while the installer finishes determining your disk space requirements.") - c = costing.pushbutton("Return", 102, 57, 56, 17, 3, "Return", None) - c.event("EndDialog", "Exit") - - ##################################################################### - # Preparation dialog: no user input except cancellation - prep = PyDialog(db, "PrepareDlg", x, y, w, h, modeless, title, - "Cancel", "Cancel", "Cancel") - prep.text("Description", 15, 70, 320, 40, 0x30003, - "Please wait while the Installer prepares to guide you through the installation.") - prep.title("Welcome to the [ProductName] Installer") - c=prep.text("ActionText", 15, 110, 320, 20, 0x30003, "Pondering...") - c.mapping("ActionText", "Text") - c=prep.text("ActionData", 15, 135, 320, 30, 0x30003, None) - c.mapping("ActionData", "Text") - prep.back("Back", None, active=0) - prep.next("Next", None, active=0) - c=prep.cancel("Cancel", None) - c.event("SpawnDialog", "CancelDlg") - - ##################################################################### - # Feature (Python directory) selection - seldlg = PyDialog(db, "SelectFeaturesDlg", x, y, w, h, modal, title, - "Next", "Next", "Cancel") - seldlg.title("Select Python Installations") - - seldlg.text("Hint", 15, 30, 300, 20, 3, - "Select the Python locations where %s should be installed." - % self.distribution.get_fullname()) - - seldlg.back("< Back", None, active=0) - c = seldlg.next("Next >", "Cancel") - order = 1 - c.event("[TARGETDIR]", "[SourceDir]", ordering=order) - for version in self.versions + [self.other_version]: - order += 1 - c.event("[TARGETDIR]", "[TARGETDIR%s]" % version, - "FEATURE_SELECTED AND &Python%s=3" % version, - ordering=order) - c.event("SpawnWaitDialog", "WaitForCostingDlg", ordering=order + 1) - c.event("EndDialog", "Return", ordering=order + 2) - c = seldlg.cancel("Cancel", "Features") - c.event("SpawnDialog", "CancelDlg") - - c = seldlg.control("Features", "SelectionTree", 15, 60, 300, 120, 3, - "FEATURE", None, "PathEdit", None) - c.event("[FEATURE_SELECTED]", "1") - ver = self.other_version - install_other_cond = "FEATURE_SELECTED AND &Python%s=3" % ver - dont_install_other_cond = "FEATURE_SELECTED AND &Python%s<>3" % ver - - c = seldlg.text("Other", 15, 200, 300, 15, 3, - "Provide an alternate Python location") - c.condition("Enable", install_other_cond) - c.condition("Show", install_other_cond) - c.condition("Disable", dont_install_other_cond) - c.condition("Hide", dont_install_other_cond) - - c = seldlg.control("PathEdit", "PathEdit", 15, 215, 300, 16, 1, - "TARGETDIR" + ver, None, "Next", None) - c.condition("Enable", install_other_cond) - c.condition("Show", install_other_cond) - c.condition("Disable", dont_install_other_cond) - c.condition("Hide", dont_install_other_cond) - - ##################################################################### - # Disk cost - cost = PyDialog(db, "DiskCostDlg", x, y, w, h, modal, title, - "OK", "OK", "OK", bitmap=False) - cost.text("Title", 15, 6, 200, 15, 0x30003, - "{\DlgFontBold8}Disk Space Requirements") - cost.text("Description", 20, 20, 280, 20, 0x30003, - "The disk space required for the installation of the selected features.") - cost.text("Text", 20, 53, 330, 60, 3, - "The highlighted volumes (if any) do not have enough disk space " - "available for the currently selected features. You can either " - "remove some files from the highlighted volumes, or choose to " - "install less features onto local drive(s), or select different " - "destination drive(s).") - cost.control("VolumeList", "VolumeCostList", 20, 100, 330, 150, 393223, - None, "{120}{70}{70}{70}{70}", None, None) - cost.xbutton("OK", "Ok", None, 0.5).event("EndDialog", "Return") - - ##################################################################### - # WhichUsers Dialog. Only available on NT, and for privileged users. - # This must be run before FindRelatedProducts, because that will - # take into account whether the previous installation was per-user - # or per-machine. We currently don't support going back to this - # dialog after "Next" was selected; to support this, we would need to - # find how to reset the ALLUSERS property, and how to re-run - # FindRelatedProducts. - # On Windows9x, the ALLUSERS property is ignored on the command line - # and in the Property table, but installer fails according to the documentation - # if a dialog attempts to set ALLUSERS. - whichusers = PyDialog(db, "WhichUsersDlg", x, y, w, h, modal, title, - "AdminInstall", "Next", "Cancel") - whichusers.title("Select whether to install [ProductName] for all users of this computer.") - # A radio group with two options: allusers, justme - g = whichusers.radiogroup("AdminInstall", 15, 60, 260, 50, 3, - "WhichUsers", "", "Next") - g.add("ALL", 0, 5, 150, 20, "Install for all users") - g.add("JUSTME", 0, 25, 150, 20, "Install just for me") - - whichusers.back("Back", None, active=0) - - c = whichusers.next("Next >", "Cancel") - c.event("[ALLUSERS]", "1", 'WhichUsers="ALL"', 1) - c.event("EndDialog", "Return", ordering = 2) - - c = whichusers.cancel("Cancel", "AdminInstall") - c.event("SpawnDialog", "CancelDlg") - - ##################################################################### - # Installation Progress dialog (modeless) - progress = PyDialog(db, "ProgressDlg", x, y, w, h, modeless, title, - "Cancel", "Cancel", "Cancel", bitmap=False) - progress.text("Title", 20, 15, 200, 15, 0x30003, - "{\DlgFontBold8}[Progress1] [ProductName]") - progress.text("Text", 35, 65, 300, 30, 3, - "Please wait while the Installer [Progress2] [ProductName]. " - "This may take several minutes.") - progress.text("StatusLabel", 35, 100, 35, 20, 3, "Status:") - - c=progress.text("ActionText", 70, 100, w-70, 20, 3, "Pondering...") - c.mapping("ActionText", "Text") - - #c=progress.text("ActionData", 35, 140, 300, 20, 3, None) - #c.mapping("ActionData", "Text") - - c=progress.control("ProgressBar", "ProgressBar", 35, 120, 300, 10, 65537, - None, "Progress done", None, None) - c.mapping("SetProgress", "Progress") - - progress.back("< Back", "Next", active=False) - progress.next("Next >", "Cancel", active=False) - progress.cancel("Cancel", "Back").event("SpawnDialog", "CancelDlg") - - ################################################################### - # Maintenance type: repair/uninstall - maint = PyDialog(db, "MaintenanceTypeDlg", x, y, w, h, modal, title, - "Next", "Next", "Cancel") - maint.title("Welcome to the [ProductName] Setup Wizard") - maint.text("BodyText", 15, 63, 330, 42, 3, - "Select whether you want to repair or remove [ProductName].") - g=maint.radiogroup("RepairRadioGroup", 15, 108, 330, 60, 3, - "MaintenanceForm_Action", "", "Next") - #g.add("Change", 0, 0, 200, 17, "&Change [ProductName]") - g.add("Repair", 0, 18, 200, 17, "&Repair [ProductName]") - g.add("Remove", 0, 36, 200, 17, "Re&move [ProductName]") - - maint.back("< Back", None, active=False) - c=maint.next("Finish", "Cancel") - # Change installation: Change progress dialog to "Change", then ask - # for feature selection - #c.event("[Progress1]", "Change", 'MaintenanceForm_Action="Change"', 1) - #c.event("[Progress2]", "changes", 'MaintenanceForm_Action="Change"', 2) - - # Reinstall: Change progress dialog to "Repair", then invoke reinstall - # Also set list of reinstalled features to "ALL" - c.event("[REINSTALL]", "ALL", 'MaintenanceForm_Action="Repair"', 5) - c.event("[Progress1]", "Repairing", 'MaintenanceForm_Action="Repair"', 6) - c.event("[Progress2]", "repairs", 'MaintenanceForm_Action="Repair"', 7) - c.event("Reinstall", "ALL", 'MaintenanceForm_Action="Repair"', 8) - - # Uninstall: Change progress to "Remove", then invoke uninstall - # Also set list of removed features to "ALL" - c.event("[REMOVE]", "ALL", 'MaintenanceForm_Action="Remove"', 11) - c.event("[Progress1]", "Removing", 'MaintenanceForm_Action="Remove"', 12) - c.event("[Progress2]", "removes", 'MaintenanceForm_Action="Remove"', 13) - c.event("Remove", "ALL", 'MaintenanceForm_Action="Remove"', 14) - - # Close dialog when maintenance action scheduled - c.event("EndDialog", "Return", 'MaintenanceForm_Action<>"Change"', 20) - #c.event("NewDialog", "SelectFeaturesDlg", 'MaintenanceForm_Action="Change"', 21) - - maint.cancel("Cancel", "RepairRadioGroup").event("SpawnDialog", "CancelDlg") - - def get_installer_filename(self, fullname): - # Factored out to allow overriding in subclasses - if self.target_version: - base_name = "%s.%s-py%s.msi" % (fullname, self.plat_name, - self.target_version) - else: - base_name = "%s.%s.msi" % (fullname, self.plat_name) - installer_name = os.path.join(self.dist_dir, base_name) - return installer_name diff --git a/PythonLib/extra/distutils/command/bdist_rpm.py b/PythonLib/extra/distutils/command/bdist_rpm.py deleted file mode 100644 index 59582436..00000000 --- a/PythonLib/extra/distutils/command/bdist_rpm.py +++ /dev/null @@ -1,587 +0,0 @@ -"""distutils.command.bdist_rpm - -Implements the Distutils 'bdist_rpm' command (create RPM source and binary -distributions).""" - -__revision__ = "$Id$" - -import sys -import os -import string - -from distutils.core import Command -from distutils.debug import DEBUG -from distutils.file_util import write_file -from distutils.errors import (DistutilsOptionError, DistutilsPlatformError, - DistutilsFileError, DistutilsExecError) -from distutils import log - -class bdist_rpm (Command): - - description = "create an RPM distribution" - - user_options = [ - ('bdist-base=', None, - "base directory for creating built distributions"), - ('rpm-base=', None, - "base directory for creating RPMs (defaults to \"rpm\" under " - "--bdist-base; must be specified for RPM 2)"), - ('dist-dir=', 'd', - "directory to put final RPM files in " - "(and .spec files if --spec-only)"), - ('python=', None, - "path to Python interpreter to hard-code in the .spec file " - "(default: \"python\")"), - ('fix-python', None, - "hard-code the exact path to the current Python interpreter in " - "the .spec file"), - ('spec-only', None, - "only regenerate spec file"), - ('source-only', None, - "only generate source RPM"), - ('binary-only', None, - "only generate binary RPM"), - ('use-bzip2', None, - "use bzip2 instead of gzip to create source distribution"), - - # More meta-data: too RPM-specific to put in the setup script, - # but needs to go in the .spec file -- so we make these options - # to "bdist_rpm". The idea is that packagers would put this - # info in setup.cfg, although they are of course free to - # supply it on the command line. - ('distribution-name=', None, - "name of the (Linux) distribution to which this " - "RPM applies (*not* the name of the module distribution!)"), - ('group=', None, - "package classification [default: \"Development/Libraries\"]"), - ('release=', None, - "RPM release number"), - ('serial=', None, - "RPM serial number"), - ('vendor=', None, - "RPM \"vendor\" (eg. \"Joe Blow \") " - "[default: maintainer or author from setup script]"), - ('packager=', None, - "RPM packager (eg. \"Jane Doe \")" - "[default: vendor]"), - ('doc-files=', None, - "list of documentation files (space or comma-separated)"), - ('changelog=', None, - "RPM changelog"), - ('icon=', None, - "name of icon file"), - ('provides=', None, - "capabilities provided by this package"), - ('requires=', None, - "capabilities required by this package"), - ('conflicts=', None, - "capabilities which conflict with this package"), - ('build-requires=', None, - "capabilities required to build this package"), - ('obsoletes=', None, - "capabilities made obsolete by this package"), - ('no-autoreq', None, - "do not automatically calculate dependencies"), - - # Actions to take when building RPM - ('keep-temp', 'k', - "don't clean up RPM build directory"), - ('no-keep-temp', None, - "clean up RPM build directory [default]"), - ('use-rpm-opt-flags', None, - "compile with RPM_OPT_FLAGS when building from source RPM"), - ('no-rpm-opt-flags', None, - "do not pass any RPM CFLAGS to compiler"), - ('rpm3-mode', None, - "RPM 3 compatibility mode (default)"), - ('rpm2-mode', None, - "RPM 2 compatibility mode"), - - # Add the hooks necessary for specifying custom scripts - ('prep-script=', None, - "Specify a script for the PREP phase of RPM building"), - ('build-script=', None, - "Specify a script for the BUILD phase of RPM building"), - - ('pre-install=', None, - "Specify a script for the pre-INSTALL phase of RPM building"), - ('install-script=', None, - "Specify a script for the INSTALL phase of RPM building"), - ('post-install=', None, - "Specify a script for the post-INSTALL phase of RPM building"), - - ('pre-uninstall=', None, - "Specify a script for the pre-UNINSTALL phase of RPM building"), - ('post-uninstall=', None, - "Specify a script for the post-UNINSTALL phase of RPM building"), - - ('clean-script=', None, - "Specify a script for the CLEAN phase of RPM building"), - - ('verify-script=', None, - "Specify a script for the VERIFY phase of the RPM build"), - - # Allow a packager to explicitly force an architecture - ('force-arch=', None, - "Force an architecture onto the RPM build process"), - - ('quiet', 'q', - "Run the INSTALL phase of RPM building in quiet mode"), - ] - - boolean_options = ['keep-temp', 'use-rpm-opt-flags', 'rpm3-mode', - 'no-autoreq', 'quiet'] - - negative_opt = {'no-keep-temp': 'keep-temp', - 'no-rpm-opt-flags': 'use-rpm-opt-flags', - 'rpm2-mode': 'rpm3-mode'} - - - def initialize_options (self): - self.bdist_base = None - self.rpm_base = None - self.dist_dir = None - self.python = None - self.fix_python = None - self.spec_only = None - self.binary_only = None - self.source_only = None - self.use_bzip2 = None - - self.distribution_name = None - self.group = None - self.release = None - self.serial = None - self.vendor = None - self.packager = None - self.doc_files = None - self.changelog = None - self.icon = None - - self.prep_script = None - self.build_script = None - self.install_script = None - self.clean_script = None - self.verify_script = None - self.pre_install = None - self.post_install = None - self.pre_uninstall = None - self.post_uninstall = None - self.prep = None - self.provides = None - self.requires = None - self.conflicts = None - self.build_requires = None - self.obsoletes = None - - self.keep_temp = 0 - self.use_rpm_opt_flags = 1 - self.rpm3_mode = 1 - self.no_autoreq = 0 - - self.force_arch = None - self.quiet = 0 - - # initialize_options() - - - def finalize_options (self): - self.set_undefined_options('bdist', ('bdist_base', 'bdist_base')) - if self.rpm_base is None: - if not self.rpm3_mode: - raise DistutilsOptionError, \ - "you must specify --rpm-base in RPM 2 mode" - self.rpm_base = os.path.join(self.bdist_base, "rpm") - - if self.python is None: - if self.fix_python: - self.python = sys.executable - else: - self.python = "python" - elif self.fix_python: - raise DistutilsOptionError, \ - "--python and --fix-python are mutually exclusive options" - - if os.name != 'posix': - raise DistutilsPlatformError, \ - ("don't know how to create RPM " - "distributions on platform %s" % os.name) - if self.binary_only and self.source_only: - raise DistutilsOptionError, \ - "cannot supply both '--source-only' and '--binary-only'" - - # don't pass CFLAGS to pure python distributions - if not self.distribution.has_ext_modules(): - self.use_rpm_opt_flags = 0 - - self.set_undefined_options('bdist', ('dist_dir', 'dist_dir')) - self.finalize_package_data() - - # finalize_options() - - def finalize_package_data (self): - self.ensure_string('group', "Development/Libraries") - self.ensure_string('vendor', - "%s <%s>" % (self.distribution.get_contact(), - self.distribution.get_contact_email())) - self.ensure_string('packager') - self.ensure_string_list('doc_files') - if isinstance(self.doc_files, list): - for readme in ('README', 'README.txt'): - if os.path.exists(readme) and readme not in self.doc_files: - self.doc_files.append(readme) - - self.ensure_string('release', "1") - self.ensure_string('serial') # should it be an int? - - self.ensure_string('distribution_name') - - self.ensure_string('changelog') - # Format changelog correctly - self.changelog = self._format_changelog(self.changelog) - - self.ensure_filename('icon') - - self.ensure_filename('prep_script') - self.ensure_filename('build_script') - self.ensure_filename('install_script') - self.ensure_filename('clean_script') - self.ensure_filename('verify_script') - self.ensure_filename('pre_install') - self.ensure_filename('post_install') - self.ensure_filename('pre_uninstall') - self.ensure_filename('post_uninstall') - - # XXX don't forget we punted on summaries and descriptions -- they - # should be handled here eventually! - - # Now *this* is some meta-data that belongs in the setup script... - self.ensure_string_list('provides') - self.ensure_string_list('requires') - self.ensure_string_list('conflicts') - self.ensure_string_list('build_requires') - self.ensure_string_list('obsoletes') - - self.ensure_string('force_arch') - # finalize_package_data () - - - def run (self): - - if DEBUG: - print "before _get_package_data():" - print "vendor =", self.vendor - print "packager =", self.packager - print "doc_files =", self.doc_files - print "changelog =", self.changelog - - # make directories - if self.spec_only: - spec_dir = self.dist_dir - self.mkpath(spec_dir) - else: - rpm_dir = {} - for d in ('SOURCES', 'SPECS', 'BUILD', 'RPMS', 'SRPMS'): - rpm_dir[d] = os.path.join(self.rpm_base, d) - self.mkpath(rpm_dir[d]) - spec_dir = rpm_dir['SPECS'] - - # Spec file goes into 'dist_dir' if '--spec-only specified', - # build/rpm. otherwise. - spec_path = os.path.join(spec_dir, - "%s.spec" % self.distribution.get_name()) - self.execute(write_file, - (spec_path, - self._make_spec_file()), - "writing '%s'" % spec_path) - - if self.spec_only: # stop if requested - return - - # Make a source distribution and copy to SOURCES directory with - # optional icon. - saved_dist_files = self.distribution.dist_files[:] - sdist = self.reinitialize_command('sdist') - if self.use_bzip2: - sdist.formats = ['bztar'] - else: - sdist.formats = ['gztar'] - self.run_command('sdist') - self.distribution.dist_files = saved_dist_files - - source = sdist.get_archive_files()[0] - source_dir = rpm_dir['SOURCES'] - self.copy_file(source, source_dir) - - if self.icon: - if os.path.exists(self.icon): - self.copy_file(self.icon, source_dir) - else: - raise DistutilsFileError, \ - "icon file '%s' does not exist" % self.icon - - - # build package - log.info("building RPMs") - rpm_cmd = ['rpm'] - if os.path.exists('/usr/bin/rpmbuild') or \ - os.path.exists('/bin/rpmbuild'): - rpm_cmd = ['rpmbuild'] - - if self.source_only: # what kind of RPMs? - rpm_cmd.append('-bs') - elif self.binary_only: - rpm_cmd.append('-bb') - else: - rpm_cmd.append('-ba') - if self.rpm3_mode: - rpm_cmd.extend(['--define', - '_topdir %s' % os.path.abspath(self.rpm_base)]) - if not self.keep_temp: - rpm_cmd.append('--clean') - - if self.quiet: - rpm_cmd.append('--quiet') - - rpm_cmd.append(spec_path) - # Determine the binary rpm names that should be built out of this spec - # file - # Note that some of these may not be really built (if the file - # list is empty) - nvr_string = "%{name}-%{version}-%{release}" - src_rpm = nvr_string + ".src.rpm" - non_src_rpm = "%{arch}/" + nvr_string + ".%{arch}.rpm" - q_cmd = r"rpm -q --qf '%s %s\n' --specfile '%s'" % ( - src_rpm, non_src_rpm, spec_path) - - out = os.popen(q_cmd) - try: - binary_rpms = [] - source_rpm = None - while 1: - line = out.readline() - if not line: - break - l = string.split(string.strip(line)) - assert(len(l) == 2) - binary_rpms.append(l[1]) - # The source rpm is named after the first entry in the spec file - if source_rpm is None: - source_rpm = l[0] - - status = out.close() - if status: - raise DistutilsExecError("Failed to execute: %s" % repr(q_cmd)) - - finally: - out.close() - - self.spawn(rpm_cmd) - - if not self.dry_run: - if self.distribution.has_ext_modules(): - pyversion = get_python_version() - else: - pyversion = 'any' - - if not self.binary_only: - srpm = os.path.join(rpm_dir['SRPMS'], source_rpm) - assert(os.path.exists(srpm)) - self.move_file(srpm, self.dist_dir) - filename = os.path.join(self.dist_dir, source_rpm) - self.distribution.dist_files.append( - ('bdist_rpm', pyversion, filename)) - - if not self.source_only: - for rpm in binary_rpms: - rpm = os.path.join(rpm_dir['RPMS'], rpm) - if os.path.exists(rpm): - self.move_file(rpm, self.dist_dir) - filename = os.path.join(self.dist_dir, - os.path.basename(rpm)) - self.distribution.dist_files.append( - ('bdist_rpm', pyversion, filename)) - # run() - - def _dist_path(self, path): - return os.path.join(self.dist_dir, os.path.basename(path)) - - def _make_spec_file(self): - """Generate the text of an RPM spec file and return it as a - list of strings (one per line). - """ - # definitions and headers - spec_file = [ - '%define name ' + self.distribution.get_name(), - '%define version ' + self.distribution.get_version().replace('-','_'), - '%define unmangled_version ' + self.distribution.get_version(), - '%define release ' + self.release.replace('-','_'), - '', - 'Summary: ' + self.distribution.get_description(), - ] - - # put locale summaries into spec file - # XXX not supported for now (hard to put a dictionary - # in a config file -- arg!) - #for locale in self.summaries.keys(): - # spec_file.append('Summary(%s): %s' % (locale, - # self.summaries[locale])) - - spec_file.extend([ - 'Name: %{name}', - 'Version: %{version}', - 'Release: %{release}',]) - - # XXX yuck! this filename is available from the "sdist" command, - # but only after it has run: and we create the spec file before - # running "sdist", in case of --spec-only. - if self.use_bzip2: - spec_file.append('Source0: %{name}-%{unmangled_version}.tar.bz2') - else: - spec_file.append('Source0: %{name}-%{unmangled_version}.tar.gz') - - spec_file.extend([ - 'License: ' + self.distribution.get_license(), - 'Group: ' + self.group, - 'BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot', - 'Prefix: %{_prefix}', ]) - - if not self.force_arch: - # noarch if no extension modules - if not self.distribution.has_ext_modules(): - spec_file.append('BuildArch: noarch') - else: - spec_file.append( 'BuildArch: %s' % self.force_arch ) - - for field in ('Vendor', - 'Packager', - 'Provides', - 'Requires', - 'Conflicts', - 'Obsoletes', - ): - val = getattr(self, string.lower(field)) - if isinstance(val, list): - spec_file.append('%s: %s' % (field, string.join(val))) - elif val is not None: - spec_file.append('%s: %s' % (field, val)) - - - if self.distribution.get_url() != 'UNKNOWN': - spec_file.append('Url: ' + self.distribution.get_url()) - - if self.distribution_name: - spec_file.append('Distribution: ' + self.distribution_name) - - if self.build_requires: - spec_file.append('BuildRequires: ' + - string.join(self.build_requires)) - - if self.icon: - spec_file.append('Icon: ' + os.path.basename(self.icon)) - - if self.no_autoreq: - spec_file.append('AutoReq: 0') - - spec_file.extend([ - '', - '%description', - self.distribution.get_long_description() - ]) - - # put locale descriptions into spec file - # XXX again, suppressed because config file syntax doesn't - # easily support this ;-( - #for locale in self.descriptions.keys(): - # spec_file.extend([ - # '', - # '%description -l ' + locale, - # self.descriptions[locale], - # ]) - - # rpm scripts - # figure out default build script - def_setup_call = "%s %s" % (self.python,os.path.basename(sys.argv[0])) - def_build = "%s build" % def_setup_call - if self.use_rpm_opt_flags: - def_build = 'env CFLAGS="$RPM_OPT_FLAGS" ' + def_build - - # insert contents of files - - # XXX this is kind of misleading: user-supplied options are files - # that we open and interpolate into the spec file, but the defaults - # are just text that we drop in as-is. Hmmm. - - install_cmd = ('%s install -O1 --root=$RPM_BUILD_ROOT ' - '--record=INSTALLED_FILES') % def_setup_call - - script_options = [ - ('prep', 'prep_script', "%setup -n %{name}-%{unmangled_version}"), - ('build', 'build_script', def_build), - ('install', 'install_script', install_cmd), - ('clean', 'clean_script', "rm -rf $RPM_BUILD_ROOT"), - ('verifyscript', 'verify_script', None), - ('pre', 'pre_install', None), - ('post', 'post_install', None), - ('preun', 'pre_uninstall', None), - ('postun', 'post_uninstall', None), - ] - - for (rpm_opt, attr, default) in script_options: - # Insert contents of file referred to, if no file is referred to - # use 'default' as contents of script - val = getattr(self, attr) - if val or default: - spec_file.extend([ - '', - '%' + rpm_opt,]) - if val: - spec_file.extend(string.split(open(val, 'r').read(), '\n')) - else: - spec_file.append(default) - - - # files section - spec_file.extend([ - '', - '%files -f INSTALLED_FILES', - '%defattr(-,root,root)', - ]) - - if self.doc_files: - spec_file.append('%doc ' + string.join(self.doc_files)) - - if self.changelog: - spec_file.extend([ - '', - '%changelog',]) - spec_file.extend(self.changelog) - - return spec_file - - # _make_spec_file () - - def _format_changelog(self, changelog): - """Format the changelog correctly and convert it to a list of strings - """ - if not changelog: - return changelog - new_changelog = [] - for line in string.split(string.strip(changelog), '\n'): - line = string.strip(line) - if line[0] == '*': - new_changelog.extend(['', line]) - elif line[0] == '-': - new_changelog.append(line) - else: - new_changelog.append(' ' + line) - - # strip trailing newline inserted by first changelog entry - if not new_changelog[0]: - del new_changelog[0] - - return new_changelog - - # _format_changelog() - -# class bdist_rpm diff --git a/PythonLib/extra/distutils/command/bdist_wininst.py b/PythonLib/extra/distutils/command/bdist_wininst.py deleted file mode 100644 index aa9383af..00000000 --- a/PythonLib/extra/distutils/command/bdist_wininst.py +++ /dev/null @@ -1,368 +0,0 @@ -"""distutils.command.bdist_wininst - -Implements the Distutils 'bdist_wininst' command: create a windows installer -exe-program.""" - -__revision__ = "$Id$" - -import sys -import os -import string - -from sysconfig import get_python_version - -from distutils.core import Command -from distutils.dir_util import remove_tree -from distutils.errors import DistutilsOptionError, DistutilsPlatformError -from distutils import log -from distutils.util import get_platform - -class bdist_wininst (Command): - - description = "create an executable installer for MS Windows" - - user_options = [('bdist-dir=', None, - "temporary directory for creating the distribution"), - ('plat-name=', 'p', - "platform name to embed in generated filenames " - "(default: %s)" % get_platform()), - ('keep-temp', 'k', - "keep the pseudo-installation tree around after " + - "creating the distribution archive"), - ('target-version=', None, - "require a specific python version" + - " on the target system"), - ('no-target-compile', 'c', - "do not compile .py to .pyc on the target system"), - ('no-target-optimize', 'o', - "do not compile .py to .pyo (optimized)" - "on the target system"), - ('dist-dir=', 'd', - "directory to put final built distributions in"), - ('bitmap=', 'b', - "bitmap to use for the installer instead of python-powered logo"), - ('title=', 't', - "title to display on the installer background instead of default"), - ('skip-build', None, - "skip rebuilding everything (for testing/debugging)"), - ('install-script=', None, - "basename of installation script to be run after" - "installation or before deinstallation"), - ('pre-install-script=', None, - "Fully qualified filename of a script to be run before " - "any files are installed. This script need not be in the " - "distribution"), - ('user-access-control=', None, - "specify Vista's UAC handling - 'none'/default=no " - "handling, 'auto'=use UAC if target Python installed for " - "all users, 'force'=always use UAC"), - ] - - boolean_options = ['keep-temp', 'no-target-compile', 'no-target-optimize', - 'skip-build'] - - def initialize_options (self): - self.bdist_dir = None - self.plat_name = None - self.keep_temp = 0 - self.no_target_compile = 0 - self.no_target_optimize = 0 - self.target_version = None - self.dist_dir = None - self.bitmap = None - self.title = None - self.skip_build = None - self.install_script = None - self.pre_install_script = None - self.user_access_control = None - - # initialize_options() - - - def finalize_options (self): - self.set_undefined_options('bdist', ('skip_build', 'skip_build')) - - if self.bdist_dir is None: - if self.skip_build and self.plat_name: - # If build is skipped and plat_name is overridden, bdist will - # not see the correct 'plat_name' - so set that up manually. - bdist = self.distribution.get_command_obj('bdist') - bdist.plat_name = self.plat_name - # next the command will be initialized using that name - bdist_base = self.get_finalized_command('bdist').bdist_base - self.bdist_dir = os.path.join(bdist_base, 'wininst') - - if not self.target_version: - self.target_version = "" - - if not self.skip_build and self.distribution.has_ext_modules(): - short_version = get_python_version() - if self.target_version and self.target_version != short_version: - raise DistutilsOptionError, \ - "target version can only be %s, or the '--skip-build'" \ - " option must be specified" % (short_version,) - self.target_version = short_version - - self.set_undefined_options('bdist', - ('dist_dir', 'dist_dir'), - ('plat_name', 'plat_name'), - ) - - if self.install_script: - for script in self.distribution.scripts: - if self.install_script == os.path.basename(script): - break - else: - raise DistutilsOptionError, \ - "install_script '%s' not found in scripts" % \ - self.install_script - # finalize_options() - - - def run (self): - if (sys.platform != "win32" and - (self.distribution.has_ext_modules() or - self.distribution.has_c_libraries())): - raise DistutilsPlatformError \ - ("distribution contains extensions and/or C libraries; " - "must be compiled on a Windows 32 platform") - - if not self.skip_build: - self.run_command('build') - - install = self.reinitialize_command('install', reinit_subcommands=1) - install.root = self.bdist_dir - install.skip_build = self.skip_build - install.warn_dir = 0 - install.plat_name = self.plat_name - - install_lib = self.reinitialize_command('install_lib') - # we do not want to include pyc or pyo files - install_lib.compile = 0 - install_lib.optimize = 0 - - if self.distribution.has_ext_modules(): - # If we are building an installer for a Python version other - # than the one we are currently running, then we need to ensure - # our build_lib reflects the other Python version rather than ours. - # Note that for target_version!=sys.version, we must have skipped the - # build step, so there is no issue with enforcing the build of this - # version. - target_version = self.target_version - if not target_version: - assert self.skip_build, "Should have already checked this" - target_version = sys.version[0:3] - plat_specifier = ".%s-%s" % (self.plat_name, target_version) - build = self.get_finalized_command('build') - build.build_lib = os.path.join(build.build_base, - 'lib' + plat_specifier) - - # Use a custom scheme for the zip-file, because we have to decide - # at installation time which scheme to use. - for key in ('purelib', 'platlib', 'headers', 'scripts', 'data'): - value = string.upper(key) - if key == 'headers': - value = value + '/Include/$dist_name' - setattr(install, - 'install_' + key, - value) - - log.info("installing to %s", self.bdist_dir) - install.ensure_finalized() - - # avoid warning of 'install_lib' about installing - # into a directory not in sys.path - sys.path.insert(0, os.path.join(self.bdist_dir, 'PURELIB')) - - install.run() - - del sys.path[0] - - # And make an archive relative to the root of the - # pseudo-installation tree. - from tempfile import mktemp - archive_basename = mktemp() - fullname = self.distribution.get_fullname() - arcname = self.make_archive(archive_basename, "zip", - root_dir=self.bdist_dir) - # create an exe containing the zip-file - self.create_exe(arcname, fullname, self.bitmap) - if self.distribution.has_ext_modules(): - pyversion = get_python_version() - else: - pyversion = 'any' - self.distribution.dist_files.append(('bdist_wininst', pyversion, - self.get_installer_filename(fullname))) - # remove the zip-file again - log.debug("removing temporary file '%s'", arcname) - os.remove(arcname) - - if not self.keep_temp: - remove_tree(self.bdist_dir, dry_run=self.dry_run) - - # run() - - def get_inidata (self): - # Return data describing the installation. - - lines = [] - metadata = self.distribution.metadata - - # Write the [metadata] section. - lines.append("[metadata]") - - # 'info' will be displayed in the installer's dialog box, - # describing the items to be installed. - info = (metadata.long_description or '') + '\n' - - # Escape newline characters - def escape(s): - return string.replace(s, "\n", "\\n") - - for name in ["author", "author_email", "description", "maintainer", - "maintainer_email", "name", "url", "version"]: - data = getattr(metadata, name, "") - if data: - info = info + ("\n %s: %s" % \ - (string.capitalize(name), escape(data))) - lines.append("%s=%s" % (name, escape(data))) - - # The [setup] section contains entries controlling - # the installer runtime. - lines.append("\n[Setup]") - if self.install_script: - lines.append("install_script=%s" % self.install_script) - lines.append("info=%s" % escape(info)) - lines.append("target_compile=%d" % (not self.no_target_compile)) - lines.append("target_optimize=%d" % (not self.no_target_optimize)) - if self.target_version: - lines.append("target_version=%s" % self.target_version) - if self.user_access_control: - lines.append("user_access_control=%s" % self.user_access_control) - - title = self.title or self.distribution.get_fullname() - lines.append("title=%s" % escape(title)) - import time - import distutils - build_info = "Built %s with distutils-%s" % \ - (time.ctime(time.time()), distutils.__version__) - lines.append("build_info=%s" % build_info) - return string.join(lines, "\n") - - # get_inidata() - - def create_exe (self, arcname, fullname, bitmap=None): - import struct - - self.mkpath(self.dist_dir) - - cfgdata = self.get_inidata() - - installer_name = self.get_installer_filename(fullname) - self.announce("creating %s" % installer_name) - - if bitmap: - bitmapdata = open(bitmap, "rb").read() - bitmaplen = len(bitmapdata) - else: - bitmaplen = 0 - - file = open(installer_name, "wb") - file.write(self.get_exe_bytes()) - if bitmap: - file.write(bitmapdata) - - # Convert cfgdata from unicode to ascii, mbcs encoded - try: - unicode - except NameError: - pass - else: - if isinstance(cfgdata, unicode): - cfgdata = cfgdata.encode("mbcs") - - # Append the pre-install script - cfgdata = cfgdata + "\0" - if self.pre_install_script: - script_data = open(self.pre_install_script, "r").read() - cfgdata = cfgdata + script_data + "\n\0" - else: - # empty pre-install script - cfgdata = cfgdata + "\0" - file.write(cfgdata) - - # The 'magic number' 0x1234567B is used to make sure that the - # binary layout of 'cfgdata' is what the wininst.exe binary - # expects. If the layout changes, increment that number, make - # the corresponding changes to the wininst.exe sources, and - # recompile them. - header = struct.pack(" cur_version: - bv = get_build_version() - else: - if self.target_version < "2.4": - bv = 6.0 - else: - bv = 7.1 - else: - # for current version - use authoritative check. - bv = get_build_version() - - # wininst-x.y.exe is in the same directory as this file - directory = os.path.dirname(__file__) - # we must use a wininst-x.y.exe built with the same C compiler - # used for python. XXX What about mingw, borland, and so on? - - # if plat_name starts with "win" but is not "win32" - # we want to strip "win" and leave the rest (e.g. -amd64) - # for all other cases, we don't want any suffix - if self.plat_name != 'win32' and self.plat_name[:3] == 'win': - sfix = self.plat_name[3:] - else: - sfix = '' - - filename = os.path.join(directory, "wininst-%.1f%s.exe" % (bv, sfix)) - f = open(filename, "rb") - try: - return f.read() - finally: - f.close() -# class bdist_wininst diff --git a/PythonLib/extra/distutils/command/build.py b/PythonLib/extra/distutils/command/build.py deleted file mode 100644 index f84bf359..00000000 --- a/PythonLib/extra/distutils/command/build.py +++ /dev/null @@ -1,147 +0,0 @@ -"""distutils.command.build - -Implements the Distutils 'build' command.""" - -__revision__ = "$Id$" - -import sys, os - -from distutils.util import get_platform -from distutils.core import Command -from distutils.errors import DistutilsOptionError - -def show_compilers(): - from distutils.ccompiler import show_compilers - show_compilers() - -class build(Command): - - description = "build everything needed to install" - - user_options = [ - ('build-base=', 'b', - "base directory for build library"), - ('build-purelib=', None, - "build directory for platform-neutral distributions"), - ('build-platlib=', None, - "build directory for platform-specific distributions"), - ('build-lib=', None, - "build directory for all distribution (defaults to either " + - "build-purelib or build-platlib"), - ('build-scripts=', None, - "build directory for scripts"), - ('build-temp=', 't', - "temporary build directory"), - ('plat-name=', 'p', - "platform name to build for, if supported " - "(default: %s)" % get_platform()), - ('compiler=', 'c', - "specify the compiler type"), - ('debug', 'g', - "compile extensions and libraries with debugging information"), - ('force', 'f', - "forcibly build everything (ignore file timestamps)"), - ('executable=', 'e', - "specify final destination interpreter path (build.py)"), - ] - - boolean_options = ['debug', 'force'] - - help_options = [ - ('help-compiler', None, - "list available compilers", show_compilers), - ] - - def initialize_options(self): - self.build_base = 'build' - # these are decided only after 'build_base' has its final value - # (unless overridden by the user or client) - self.build_purelib = None - self.build_platlib = None - self.build_lib = None - self.build_temp = None - self.build_scripts = None - self.compiler = None - self.plat_name = None - self.debug = None - self.force = 0 - self.executable = None - - def finalize_options(self): - if self.plat_name is None: - self.plat_name = get_platform() - else: - # plat-name only supported for windows (other platforms are - # supported via ./configure flags, if at all). Avoid misleading - # other platforms. - if os.name != 'nt': - raise DistutilsOptionError( - "--plat-name only supported on Windows (try " - "using './configure --help' on your platform)") - - plat_specifier = ".%s-%s" % (self.plat_name, sys.version[0:3]) - - # Make it so Python 2.x and Python 2.x with --with-pydebug don't - # share the same build directories. Doing so confuses the build - # process for C modules - if hasattr(sys, 'gettotalrefcount'): - plat_specifier += '-pydebug' - - # 'build_purelib' and 'build_platlib' just default to 'lib' and - # 'lib.' under the base build directory. We only use one of - # them for a given distribution, though -- - if self.build_purelib is None: - self.build_purelib = os.path.join(self.build_base, 'lib') - if self.build_platlib is None: - self.build_platlib = os.path.join(self.build_base, - 'lib' + plat_specifier) - - # 'build_lib' is the actual directory that we will use for this - # particular module distribution -- if user didn't supply it, pick - # one of 'build_purelib' or 'build_platlib'. - if self.build_lib is None: - if self.distribution.ext_modules: - self.build_lib = self.build_platlib - else: - self.build_lib = self.build_purelib - - # 'build_temp' -- temporary directory for compiler turds, - # "build/temp." - if self.build_temp is None: - self.build_temp = os.path.join(self.build_base, - 'temp' + plat_specifier) - if self.build_scripts is None: - self.build_scripts = os.path.join(self.build_base, - 'scripts-' + sys.version[0:3]) - - if self.executable is None: - self.executable = os.path.normpath(sys.executable) - - def run(self): - # Run all relevant sub-commands. This will be some subset of: - # - build_py - pure Python modules - # - build_clib - standalone C libraries - # - build_ext - Python extensions - # - build_scripts - (Python) scripts - for cmd_name in self.get_sub_commands(): - self.run_command(cmd_name) - - # -- Predicates for the sub-command list --------------------------- - - def has_pure_modules (self): - return self.distribution.has_pure_modules() - - def has_c_libraries (self): - return self.distribution.has_c_libraries() - - def has_ext_modules (self): - return self.distribution.has_ext_modules() - - def has_scripts (self): - return self.distribution.has_scripts() - - sub_commands = [('build_py', has_pure_modules), - ('build_clib', has_c_libraries), - ('build_ext', has_ext_modules), - ('build_scripts', has_scripts), - ] diff --git a/PythonLib/extra/distutils/command/build_clib.py b/PythonLib/extra/distutils/command/build_clib.py deleted file mode 100644 index 205587e7..00000000 --- a/PythonLib/extra/distutils/command/build_clib.py +++ /dev/null @@ -1,209 +0,0 @@ -"""distutils.command.build_clib - -Implements the Distutils 'build_clib' command, to build a C/C++ library -that is included in the module distribution and needed by an extension -module.""" - -__revision__ = "$Id$" - - -# XXX this module has *lots* of code ripped-off quite transparently from -# build_ext.py -- not surprisingly really, as the work required to build -# a static library from a collection of C source files is not really all -# that different from what's required to build a shared object file from -# a collection of C source files. Nevertheless, I haven't done the -# necessary refactoring to account for the overlap in code between the -# two modules, mainly because a number of subtle details changed in the -# cut 'n paste. Sigh. - -import os -from distutils.core import Command -from distutils.errors import DistutilsSetupError -from distutils.sysconfig import customize_compiler -from distutils import log - -def show_compilers(): - from distutils.ccompiler import show_compilers - show_compilers() - - -class build_clib(Command): - - description = "build C/C++ libraries used by Python extensions" - - user_options = [ - ('build-clib=', 'b', - "directory to build C/C++ libraries to"), - ('build-temp=', 't', - "directory to put temporary build by-products"), - ('debug', 'g', - "compile with debugging information"), - ('force', 'f', - "forcibly build everything (ignore file timestamps)"), - ('compiler=', 'c', - "specify the compiler type"), - ] - - boolean_options = ['debug', 'force'] - - help_options = [ - ('help-compiler', None, - "list available compilers", show_compilers), - ] - - def initialize_options(self): - self.build_clib = None - self.build_temp = None - - # List of libraries to build - self.libraries = None - - # Compilation options for all libraries - self.include_dirs = None - self.define = None - self.undef = None - self.debug = None - self.force = 0 - self.compiler = None - - - def finalize_options(self): - # This might be confusing: both build-clib and build-temp default - # to build-temp as defined by the "build" command. This is because - # I think that C libraries are really just temporary build - # by-products, at least from the point of view of building Python - # extensions -- but I want to keep my options open. - self.set_undefined_options('build', - ('build_temp', 'build_clib'), - ('build_temp', 'build_temp'), - ('compiler', 'compiler'), - ('debug', 'debug'), - ('force', 'force')) - - self.libraries = self.distribution.libraries - if self.libraries: - self.check_library_list(self.libraries) - - if self.include_dirs is None: - self.include_dirs = self.distribution.include_dirs or [] - if isinstance(self.include_dirs, str): - self.include_dirs = self.include_dirs.split(os.pathsep) - - # XXX same as for build_ext -- what about 'self.define' and - # 'self.undef' ? - - def run(self): - if not self.libraries: - return - - # Yech -- this is cut 'n pasted from build_ext.py! - from distutils.ccompiler import new_compiler - self.compiler = new_compiler(compiler=self.compiler, - dry_run=self.dry_run, - force=self.force) - customize_compiler(self.compiler) - - if self.include_dirs is not None: - self.compiler.set_include_dirs(self.include_dirs) - if self.define is not None: - # 'define' option is a list of (name,value) tuples - for (name,value) in self.define: - self.compiler.define_macro(name, value) - if self.undef is not None: - for macro in self.undef: - self.compiler.undefine_macro(macro) - - self.build_libraries(self.libraries) - - - def check_library_list(self, libraries): - """Ensure that the list of libraries is valid. - - `library` is presumably provided as a command option 'libraries'. - This method checks that it is a list of 2-tuples, where the tuples - are (library_name, build_info_dict). - - Raise DistutilsSetupError if the structure is invalid anywhere; - just returns otherwise. - """ - if not isinstance(libraries, list): - raise DistutilsSetupError, \ - "'libraries' option must be a list of tuples" - - for lib in libraries: - if not isinstance(lib, tuple) and len(lib) != 2: - raise DistutilsSetupError, \ - "each element of 'libraries' must a 2-tuple" - - name, build_info = lib - - if not isinstance(name, str): - raise DistutilsSetupError, \ - "first element of each tuple in 'libraries' " + \ - "must be a string (the library name)" - if '/' in name or (os.sep != '/' and os.sep in name): - raise DistutilsSetupError, \ - ("bad library name '%s': " + - "may not contain directory separators") % \ - lib[0] - - if not isinstance(build_info, dict): - raise DistutilsSetupError, \ - "second element of each tuple in 'libraries' " + \ - "must be a dictionary (build info)" - - def get_library_names(self): - # Assume the library list is valid -- 'check_library_list()' is - # called from 'finalize_options()', so it should be! - if not self.libraries: - return None - - lib_names = [] - for (lib_name, build_info) in self.libraries: - lib_names.append(lib_name) - return lib_names - - - def get_source_files(self): - self.check_library_list(self.libraries) - filenames = [] - for (lib_name, build_info) in self.libraries: - sources = build_info.get('sources') - if sources is None or not isinstance(sources, (list, tuple)): - raise DistutilsSetupError, \ - ("in 'libraries' option (library '%s'), " - "'sources' must be present and must be " - "a list of source filenames") % lib_name - - filenames.extend(sources) - return filenames - - def build_libraries(self, libraries): - for (lib_name, build_info) in libraries: - sources = build_info.get('sources') - if sources is None or not isinstance(sources, (list, tuple)): - raise DistutilsSetupError, \ - ("in 'libraries' option (library '%s'), " + - "'sources' must be present and must be " + - "a list of source filenames") % lib_name - sources = list(sources) - - log.info("building '%s' library", lib_name) - - # First, compile the source code to object files in the library - # directory. (This should probably change to putting object - # files in a temporary build directory.) - macros = build_info.get('macros') - include_dirs = build_info.get('include_dirs') - objects = self.compiler.compile(sources, - output_dir=self.build_temp, - macros=macros, - include_dirs=include_dirs, - debug=self.debug) - - # Now "link" the object files together into a static library. - # (On Unix at least, this isn't really linking -- it just - # builds an archive. Whatever.) - self.compiler.create_static_lib(objects, lib_name, - output_dir=self.build_clib, - debug=self.debug) diff --git a/PythonLib/extra/distutils/command/build_ext.py b/PythonLib/extra/distutils/command/build_ext.py deleted file mode 100644 index f0a7d4ca..00000000 --- a/PythonLib/extra/distutils/command/build_ext.py +++ /dev/null @@ -1,766 +0,0 @@ -"""distutils.command.build_ext - -Implements the Distutils 'build_ext' command, for building extension -modules (currently limited to C extensions, should accommodate C++ -extensions ASAP).""" - -# This module should be kept compatible with Python 2.1. - -__revision__ = "$Id$" - -import sys, os, string, re -from types import * -from site import USER_BASE, USER_SITE -from distutils.core import Command -from distutils.errors import * -from distutils.sysconfig import customize_compiler, get_python_version -from distutils.dep_util import newer_group -from distutils.extension import Extension -from distutils.util import get_platform -from distutils import log - -if os.name == 'nt': - from distutils.msvccompiler import get_build_version - MSVC_VERSION = int(get_build_version()) - -# An extension name is just a dot-separated list of Python NAMEs (ie. -# the same as a fully-qualified module name). -extension_name_re = re.compile \ - (r'^[a-zA-Z_][a-zA-Z_0-9]*(\.[a-zA-Z_][a-zA-Z_0-9]*)*$') - - -def show_compilers (): - from distutils.ccompiler import show_compilers - show_compilers() - - -class build_ext (Command): - - description = "build C/C++ extensions (compile/link to build directory)" - - # XXX thoughts on how to deal with complex command-line options like - # these, i.e. how to make it so fancy_getopt can suck them off the - # command line and make it look like setup.py defined the appropriate - # lists of tuples of what-have-you. - # - each command needs a callback to process its command-line options - # - Command.__init__() needs access to its share of the whole - # command line (must ultimately come from - # Distribution.parse_command_line()) - # - it then calls the current command class' option-parsing - # callback to deal with weird options like -D, which have to - # parse the option text and churn out some custom data - # structure - # - that data structure (in this case, a list of 2-tuples) - # will then be present in the command object by the time - # we get to finalize_options() (i.e. the constructor - # takes care of both command-line and client options - # in between initialize_options() and finalize_options()) - - sep_by = " (separated by '%s')" % os.pathsep - user_options = [ - ('build-lib=', 'b', - "directory for compiled extension modules"), - ('build-temp=', 't', - "directory for temporary files (build by-products)"), - ('plat-name=', 'p', - "platform name to cross-compile for, if supported " - "(default: %s)" % get_platform()), - ('inplace', 'i', - "ignore build-lib and put compiled extensions into the source " + - "directory alongside your pure Python modules"), - ('include-dirs=', 'I', - "list of directories to search for header files" + sep_by), - ('define=', 'D', - "C preprocessor macros to define"), - ('undef=', 'U', - "C preprocessor macros to undefine"), - ('libraries=', 'l', - "external C libraries to link with"), - ('library-dirs=', 'L', - "directories to search for external C libraries" + sep_by), - ('rpath=', 'R', - "directories to search for shared C libraries at runtime"), - ('link-objects=', 'O', - "extra explicit link objects to include in the link"), - ('debug', 'g', - "compile/link with debugging information"), - ('force', 'f', - "forcibly build everything (ignore file timestamps)"), - ('compiler=', 'c', - "specify the compiler type"), - ('swig-cpp', None, - "make SWIG create C++ files (default is C)"), - ('swig-opts=', None, - "list of SWIG command line options"), - ('swig=', None, - "path to the SWIG executable"), - ('user', None, - "add user include, library and rpath"), - ] - - boolean_options = ['inplace', 'debug', 'force', 'swig-cpp', 'user'] - - help_options = [ - ('help-compiler', None, - "list available compilers", show_compilers), - ] - - def initialize_options (self): - self.extensions = None - self.build_lib = None - self.plat_name = None - self.build_temp = None - self.inplace = 0 - self.package = None - - self.include_dirs = None - self.define = None - self.undef = None - self.libraries = None - self.library_dirs = None - self.rpath = None - self.link_objects = None - self.debug = None - self.force = None - self.compiler = None - self.swig = None - self.swig_cpp = None - self.swig_opts = None - self.user = None - - def finalize_options(self): - from distutils import sysconfig - - self.set_undefined_options('build', - ('build_lib', 'build_lib'), - ('build_temp', 'build_temp'), - ('compiler', 'compiler'), - ('debug', 'debug'), - ('force', 'force'), - ('plat_name', 'plat_name'), - ) - - if self.package is None: - self.package = self.distribution.ext_package - - self.extensions = self.distribution.ext_modules - - # Make sure Python's include directories (for Python.h, pyconfig.h, - # etc.) are in the include search path. - py_include = sysconfig.get_python_inc() - plat_py_include = sysconfig.get_python_inc(plat_specific=1) - if self.include_dirs is None: - self.include_dirs = self.distribution.include_dirs or [] - if isinstance(self.include_dirs, str): - self.include_dirs = self.include_dirs.split(os.pathsep) - - # Put the Python "system" include dir at the end, so that - # any local include dirs take precedence. - self.include_dirs.append(py_include) - if plat_py_include != py_include: - self.include_dirs.append(plat_py_include) - - self.ensure_string_list('libraries') - - # Life is easier if we're not forever checking for None, so - # simplify these options to empty lists if unset - if self.libraries is None: - self.libraries = [] - if self.library_dirs is None: - self.library_dirs = [] - elif type(self.library_dirs) is StringType: - self.library_dirs = string.split(self.library_dirs, os.pathsep) - - if self.rpath is None: - self.rpath = [] - elif type(self.rpath) is StringType: - self.rpath = string.split(self.rpath, os.pathsep) - - # for extensions under windows use different directories - # for Release and Debug builds. - # also Python's library directory must be appended to library_dirs - if os.name == 'nt': - # the 'libs' directory is for binary installs - we assume that - # must be the *native* platform. But we don't really support - # cross-compiling via a binary install anyway, so we let it go. - self.library_dirs.append(os.path.join(sys.exec_prefix, 'libs')) - if self.debug: - self.build_temp = os.path.join(self.build_temp, "Debug") - else: - self.build_temp = os.path.join(self.build_temp, "Release") - - # Append the source distribution include and library directories, - # this allows distutils on windows to work in the source tree - self.include_dirs.append(os.path.join(sys.exec_prefix, 'PC')) - if MSVC_VERSION == 9: - # Use the .lib files for the correct architecture - if self.plat_name == 'win32': - suffix = '' - else: - # win-amd64 or win-ia64 - suffix = self.plat_name[4:] - new_lib = os.path.join(sys.exec_prefix, 'PCbuild') - if suffix: - new_lib = os.path.join(new_lib, suffix) - self.library_dirs.append(new_lib) - - elif MSVC_VERSION == 8: - self.library_dirs.append(os.path.join(sys.exec_prefix, - 'PC', 'VS8.0')) - elif MSVC_VERSION == 7: - self.library_dirs.append(os.path.join(sys.exec_prefix, - 'PC', 'VS7.1')) - else: - self.library_dirs.append(os.path.join(sys.exec_prefix, - 'PC', 'VC6')) - - # OS/2 (EMX) doesn't support Debug vs Release builds, but has the - # import libraries in its "Config" subdirectory - if os.name == 'os2': - self.library_dirs.append(os.path.join(sys.exec_prefix, 'Config')) - - # for extensions under Cygwin and AtheOS Python's library directory must be - # appended to library_dirs - if sys.platform[:6] == 'cygwin' or sys.platform[:6] == 'atheos': - if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")): - # building third party extensions - self.library_dirs.append(os.path.join(sys.prefix, "lib", - "python" + get_python_version(), - "config")) - else: - # building python standard extensions - self.library_dirs.append('.') - - # For building extensions with a shared Python library, - # Python's library directory must be appended to library_dirs - # See Issues: #1600860, #4366 - if (sysconfig.get_config_var('Py_ENABLE_SHARED')): - if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")): - # building third party extensions - self.library_dirs.append(sysconfig.get_config_var('LIBDIR')) - else: - # building python standard extensions - self.library_dirs.append('.') - - # The argument parsing will result in self.define being a string, but - # it has to be a list of 2-tuples. All the preprocessor symbols - # specified by the 'define' option will be set to '1'. Multiple - # symbols can be separated with commas. - - if self.define: - defines = self.define.split(',') - self.define = map(lambda symbol: (symbol, '1'), defines) - - # The option for macros to undefine is also a string from the - # option parsing, but has to be a list. Multiple symbols can also - # be separated with commas here. - if self.undef: - self.undef = self.undef.split(',') - - if self.swig_opts is None: - self.swig_opts = [] - else: - self.swig_opts = self.swig_opts.split(' ') - - # Finally add the user include and library directories if requested - if self.user: - user_include = os.path.join(USER_BASE, "include") - user_lib = os.path.join(USER_BASE, "lib") - if os.path.isdir(user_include): - self.include_dirs.append(user_include) - if os.path.isdir(user_lib): - self.library_dirs.append(user_lib) - self.rpath.append(user_lib) - - def run(self): - from distutils.ccompiler import new_compiler - - # 'self.extensions', as supplied by setup.py, is a list of - # Extension instances. See the documentation for Extension (in - # distutils.extension) for details. - # - # For backwards compatibility with Distutils 0.8.2 and earlier, we - # also allow the 'extensions' list to be a list of tuples: - # (ext_name, build_info) - # where build_info is a dictionary containing everything that - # Extension instances do except the name, with a few things being - # differently named. We convert these 2-tuples to Extension - # instances as needed. - - if not self.extensions: - return - - # If we were asked to build any C/C++ libraries, make sure that the - # directory where we put them is in the library search path for - # linking extensions. - if self.distribution.has_c_libraries(): - build_clib = self.get_finalized_command('build_clib') - self.libraries.extend(build_clib.get_library_names() or []) - self.library_dirs.append(build_clib.build_clib) - - # Setup the CCompiler object that we'll use to do all the - # compiling and linking - self.compiler = new_compiler(compiler=self.compiler, - verbose=self.verbose, - dry_run=self.dry_run, - force=self.force) - customize_compiler(self.compiler) - # If we are cross-compiling, init the compiler now (if we are not - # cross-compiling, init would not hurt, but people may rely on - # late initialization of compiler even if they shouldn't...) - if os.name == 'nt' and self.plat_name != get_platform(): - self.compiler.initialize(self.plat_name) - - # And make sure that any compile/link-related options (which might - # come from the command-line or from the setup script) are set in - # that CCompiler object -- that way, they automatically apply to - # all compiling and linking done here. - if self.include_dirs is not None: - self.compiler.set_include_dirs(self.include_dirs) - if self.define is not None: - # 'define' option is a list of (name,value) tuples - for (name, value) in self.define: - self.compiler.define_macro(name, value) - if self.undef is not None: - for macro in self.undef: - self.compiler.undefine_macro(macro) - if self.libraries is not None: - self.compiler.set_libraries(self.libraries) - if self.library_dirs is not None: - self.compiler.set_library_dirs(self.library_dirs) - if self.rpath is not None: - self.compiler.set_runtime_library_dirs(self.rpath) - if self.link_objects is not None: - self.compiler.set_link_objects(self.link_objects) - - # Now actually compile and link everything. - self.build_extensions() - - def check_extensions_list(self, extensions): - """Ensure that the list of extensions (presumably provided as a - command option 'extensions') is valid, i.e. it is a list of - Extension objects. We also support the old-style list of 2-tuples, - where the tuples are (ext_name, build_info), which are converted to - Extension instances here. - - Raise DistutilsSetupError if the structure is invalid anywhere; - just returns otherwise. - """ - if not isinstance(extensions, list): - raise DistutilsSetupError, \ - "'ext_modules' option must be a list of Extension instances" - - for i, ext in enumerate(extensions): - if isinstance(ext, Extension): - continue # OK! (assume type-checking done - # by Extension constructor) - - if not isinstance(ext, tuple) or len(ext) != 2: - raise DistutilsSetupError, \ - ("each element of 'ext_modules' option must be an " - "Extension instance or 2-tuple") - - ext_name, build_info = ext - - log.warn(("old-style (ext_name, build_info) tuple found in " - "ext_modules for extension '%s'" - "-- please convert to Extension instance" % ext_name)) - - if not (isinstance(ext_name, str) and - extension_name_re.match(ext_name)): - raise DistutilsSetupError, \ - ("first element of each tuple in 'ext_modules' " - "must be the extension name (a string)") - - if not isinstance(build_info, dict): - raise DistutilsSetupError, \ - ("second element of each tuple in 'ext_modules' " - "must be a dictionary (build info)") - - # OK, the (ext_name, build_info) dict is type-safe: convert it - # to an Extension instance. - ext = Extension(ext_name, build_info['sources']) - - # Easy stuff: one-to-one mapping from dict elements to - # instance attributes. - for key in ('include_dirs', 'library_dirs', 'libraries', - 'extra_objects', 'extra_compile_args', - 'extra_link_args'): - val = build_info.get(key) - if val is not None: - setattr(ext, key, val) - - # Medium-easy stuff: same syntax/semantics, different names. - ext.runtime_library_dirs = build_info.get('rpath') - if 'def_file' in build_info: - log.warn("'def_file' element of build info dict " - "no longer supported") - - # Non-trivial stuff: 'macros' split into 'define_macros' - # and 'undef_macros'. - macros = build_info.get('macros') - if macros: - ext.define_macros = [] - ext.undef_macros = [] - for macro in macros: - if not (isinstance(macro, tuple) and len(macro) in (1, 2)): - raise DistutilsSetupError, \ - ("'macros' element of build info dict " - "must be 1- or 2-tuple") - if len(macro) == 1: - ext.undef_macros.append(macro[0]) - elif len(macro) == 2: - ext.define_macros.append(macro) - - extensions[i] = ext - - def get_source_files(self): - self.check_extensions_list(self.extensions) - filenames = [] - - # Wouldn't it be neat if we knew the names of header files too... - for ext in self.extensions: - filenames.extend(ext.sources) - - return filenames - - def get_outputs(self): - # Sanity check the 'extensions' list -- can't assume this is being - # done in the same run as a 'build_extensions()' call (in fact, we - # can probably assume that it *isn't*!). - self.check_extensions_list(self.extensions) - - # And build the list of output (built) filenames. Note that this - # ignores the 'inplace' flag, and assumes everything goes in the - # "build" tree. - outputs = [] - for ext in self.extensions: - outputs.append(self.get_ext_fullpath(ext.name)) - return outputs - - def build_extensions(self): - # First, sanity-check the 'extensions' list - self.check_extensions_list(self.extensions) - - for ext in self.extensions: - self.build_extension(ext) - - def build_extension(self, ext): - sources = ext.sources - if sources is None or type(sources) not in (ListType, TupleType): - raise DistutilsSetupError, \ - ("in 'ext_modules' option (extension '%s'), " + - "'sources' must be present and must be " + - "a list of source filenames") % ext.name - sources = list(sources) - - ext_path = self.get_ext_fullpath(ext.name) - depends = sources + ext.depends - if not (self.force or newer_group(depends, ext_path, 'newer')): - log.debug("skipping '%s' extension (up-to-date)", ext.name) - return - else: - log.info("building '%s' extension", ext.name) - - # First, scan the sources for SWIG definition files (.i), run - # SWIG on 'em to create .c files, and modify the sources list - # accordingly. - sources = self.swig_sources(sources, ext) - - # Next, compile the source code to object files. - - # XXX not honouring 'define_macros' or 'undef_macros' -- the - # CCompiler API needs to change to accommodate this, and I - # want to do one thing at a time! - - # Two possible sources for extra compiler arguments: - # - 'extra_compile_args' in Extension object - # - CFLAGS environment variable (not particularly - # elegant, but people seem to expect it and I - # guess it's useful) - # The environment variable should take precedence, and - # any sensible compiler will give precedence to later - # command line args. Hence we combine them in order: - extra_args = ext.extra_compile_args or [] - - macros = ext.define_macros[:] - for undef in ext.undef_macros: - macros.append((undef,)) - - objects = self.compiler.compile(sources, - output_dir=self.build_temp, - macros=macros, - include_dirs=ext.include_dirs, - debug=self.debug, - extra_postargs=extra_args, - depends=ext.depends) - - # XXX -- this is a Vile HACK! - # - # The setup.py script for Python on Unix needs to be able to - # get this list so it can perform all the clean up needed to - # avoid keeping object files around when cleaning out a failed - # build of an extension module. Since Distutils does not - # track dependencies, we have to get rid of intermediates to - # ensure all the intermediates will be properly re-built. - # - self._built_objects = objects[:] - - # Now link the object files together into a "shared object" -- - # of course, first we have to figure out all the other things - # that go into the mix. - if ext.extra_objects: - objects.extend(ext.extra_objects) - extra_args = ext.extra_link_args or [] - - # Detect target language, if not provided - language = ext.language or self.compiler.detect_language(sources) - - self.compiler.link_shared_object( - objects, ext_path, - libraries=self.get_libraries(ext), - library_dirs=ext.library_dirs, - runtime_library_dirs=ext.runtime_library_dirs, - extra_postargs=extra_args, - export_symbols=self.get_export_symbols(ext), - debug=self.debug, - build_temp=self.build_temp, - target_lang=language) - - - def swig_sources (self, sources, extension): - - """Walk the list of source files in 'sources', looking for SWIG - interface (.i) files. Run SWIG on all that are found, and - return a modified 'sources' list with SWIG source files replaced - by the generated C (or C++) files. - """ - - new_sources = [] - swig_sources = [] - swig_targets = {} - - # XXX this drops generated C/C++ files into the source tree, which - # is fine for developers who want to distribute the generated - # source -- but there should be an option to put SWIG output in - # the temp dir. - - if self.swig_cpp: - log.warn("--swig-cpp is deprecated - use --swig-opts=-c++") - - if self.swig_cpp or ('-c++' in self.swig_opts) or \ - ('-c++' in extension.swig_opts): - target_ext = '.cpp' - else: - target_ext = '.c' - - for source in sources: - (base, ext) = os.path.splitext(source) - if ext == ".i": # SWIG interface file - new_sources.append(base + '_wrap' + target_ext) - swig_sources.append(source) - swig_targets[source] = new_sources[-1] - else: - new_sources.append(source) - - if not swig_sources: - return new_sources - - swig = self.swig or self.find_swig() - swig_cmd = [swig, "-python"] - swig_cmd.extend(self.swig_opts) - if self.swig_cpp: - swig_cmd.append("-c++") - - # Do not override commandline arguments - if not self.swig_opts: - for o in extension.swig_opts: - swig_cmd.append(o) - - for source in swig_sources: - target = swig_targets[source] - log.info("swigging %s to %s", source, target) - self.spawn(swig_cmd + ["-o", target, source]) - - return new_sources - - # swig_sources () - - def find_swig (self): - """Return the name of the SWIG executable. On Unix, this is - just "swig" -- it should be in the PATH. Tries a bit harder on - Windows. - """ - - if os.name == "posix": - return "swig" - elif os.name == "nt": - - # Look for SWIG in its standard installation directory on - # Windows (or so I presume!). If we find it there, great; - # if not, act like Unix and assume it's in the PATH. - for vers in ("1.3", "1.2", "1.1"): - fn = os.path.join("c:\\swig%s" % vers, "swig.exe") - if os.path.isfile(fn): - return fn - else: - return "swig.exe" - - elif os.name == "os2": - # assume swig available in the PATH. - return "swig.exe" - - else: - raise DistutilsPlatformError, \ - ("I don't know how to find (much less run) SWIG " - "on platform '%s'") % os.name - - # find_swig () - - # -- Name generators ----------------------------------------------- - # (extension names, filenames, whatever) - def get_ext_fullpath(self, ext_name): - """Returns the path of the filename for a given extension. - - The file is located in `build_lib` or directly in the package - (inplace option). - """ - # makes sure the extension name is only using dots - all_dots = string.maketrans('/'+os.sep, '..') - ext_name = ext_name.translate(all_dots) - - fullname = self.get_ext_fullname(ext_name) - modpath = fullname.split('.') - filename = self.get_ext_filename(ext_name) - filename = os.path.split(filename)[-1] - - if not self.inplace: - # no further work needed - # returning : - # build_dir/package/path/filename - filename = os.path.join(*modpath[:-1]+[filename]) - return os.path.join(self.build_lib, filename) - - # the inplace option requires to find the package directory - # using the build_py command for that - package = '.'.join(modpath[0:-1]) - build_py = self.get_finalized_command('build_py') - package_dir = os.path.abspath(build_py.get_package_dir(package)) - - # returning - # package_dir/filename - return os.path.join(package_dir, filename) - - def get_ext_fullname(self, ext_name): - """Returns the fullname of a given extension name. - - Adds the `package.` prefix""" - if self.package is None: - return ext_name - else: - return self.package + '.' + ext_name - - def get_ext_filename(self, ext_name): - r"""Convert the name of an extension (eg. "foo.bar") into the name - of the file from which it will be loaded (eg. "foo/bar.so", or - "foo\bar.pyd"). - """ - from distutils.sysconfig import get_config_var - ext_path = string.split(ext_name, '.') - # OS/2 has an 8 character module (extension) limit :-( - if os.name == "os2": - ext_path[len(ext_path) - 1] = ext_path[len(ext_path) - 1][:8] - # extensions in debug_mode are named 'module_d.pyd' under windows - so_ext = get_config_var('SO') - if os.name == 'nt' and self.debug: - return os.path.join(*ext_path) + '_d' + so_ext - return os.path.join(*ext_path) + so_ext - - def get_export_symbols (self, ext): - """Return the list of symbols that a shared extension has to - export. This either uses 'ext.export_symbols' or, if it's not - provided, "init" + module_name. Only relevant on Windows, where - the .pyd file (DLL) must export the module "init" function. - """ - initfunc_name = "init" + ext.name.split('.')[-1] - if initfunc_name not in ext.export_symbols: - ext.export_symbols.append(initfunc_name) - return ext.export_symbols - - def get_libraries (self, ext): - """Return the list of libraries to link against when building a - shared extension. On most platforms, this is just 'ext.libraries'; - on Windows and OS/2, we add the Python library (eg. python20.dll). - """ - # The python library is always needed on Windows. For MSVC, this - # is redundant, since the library is mentioned in a pragma in - # pyconfig.h that MSVC groks. The other Windows compilers all seem - # to need it mentioned explicitly, though, so that's what we do. - # Append '_d' to the python import library on debug builds. - if sys.platform == "win32": - from distutils.msvccompiler import MSVCCompiler - if not isinstance(self.compiler, MSVCCompiler): - template = "python%d%d" - if self.debug: - template = template + '_d' - pythonlib = (template % - (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) - # don't extend ext.libraries, it may be shared with other - # extensions, it is a reference to the original list - return ext.libraries + [pythonlib] - else: - return ext.libraries - elif sys.platform == "os2emx": - # EMX/GCC requires the python library explicitly, and I - # believe VACPP does as well (though not confirmed) - AIM Apr01 - template = "python%d%d" - # debug versions of the main DLL aren't supported, at least - # not at this time - AIM Apr01 - #if self.debug: - # template = template + '_d' - pythonlib = (template % - (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) - # don't extend ext.libraries, it may be shared with other - # extensions, it is a reference to the original list - return ext.libraries + [pythonlib] - elif sys.platform[:6] == "cygwin": - template = "python%d.%d" - pythonlib = (template % - (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) - # don't extend ext.libraries, it may be shared with other - # extensions, it is a reference to the original list - return ext.libraries + [pythonlib] - elif sys.platform[:6] == "atheos": - from distutils import sysconfig - - template = "python%d.%d" - pythonlib = (template % - (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) - # Get SHLIBS from Makefile - extra = [] - for lib in sysconfig.get_config_var('SHLIBS').split(): - if lib.startswith('-l'): - extra.append(lib[2:]) - else: - extra.append(lib) - # don't extend ext.libraries, it may be shared with other - # extensions, it is a reference to the original list - return ext.libraries + [pythonlib, "m"] + extra - - elif sys.platform == 'darwin': - # Don't use the default code below - return ext.libraries - elif sys.platform[:3] == 'aix': - # Don't use the default code below - return ext.libraries - else: - from distutils import sysconfig - if sysconfig.get_config_var('Py_ENABLE_SHARED'): - template = "python%d.%d" - pythonlib = (template % - (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) - return ext.libraries + [pythonlib] - else: - return ext.libraries - -# class build_ext diff --git a/PythonLib/extra/distutils/command/build_py.py b/PythonLib/extra/distutils/command/build_py.py deleted file mode 100644 index c123c622..00000000 --- a/PythonLib/extra/distutils/command/build_py.py +++ /dev/null @@ -1,394 +0,0 @@ -"""distutils.command.build_py - -Implements the Distutils 'build_py' command.""" - -__revision__ = "$Id$" - -import os -import sys -from glob import glob - -from distutils.core import Command -from distutils.errors import DistutilsOptionError, DistutilsFileError -from distutils.util import convert_path -from distutils import log - -class build_py(Command): - - description = "\"build\" pure Python modules (copy to build directory)" - - user_options = [ - ('build-lib=', 'd', "directory to \"build\" (copy) to"), - ('compile', 'c', "compile .py to .pyc"), - ('no-compile', None, "don't compile .py files [default]"), - ('optimize=', 'O', - "also compile with optimization: -O1 for \"python -O\", " - "-O2 for \"python -OO\", and -O0 to disable [default: -O0]"), - ('force', 'f', "forcibly build everything (ignore file timestamps)"), - ] - - boolean_options = ['compile', 'force'] - negative_opt = {'no-compile' : 'compile'} - - def initialize_options(self): - self.build_lib = None - self.py_modules = None - self.package = None - self.package_data = None - self.package_dir = None - self.compile = 0 - self.optimize = 0 - self.force = None - - def finalize_options(self): - self.set_undefined_options('build', - ('build_lib', 'build_lib'), - ('force', 'force')) - - # Get the distribution options that are aliases for build_py - # options -- list of packages and list of modules. - self.packages = self.distribution.packages - self.py_modules = self.distribution.py_modules - self.package_data = self.distribution.package_data - self.package_dir = {} - if self.distribution.package_dir: - for name, path in self.distribution.package_dir.items(): - self.package_dir[name] = convert_path(path) - self.data_files = self.get_data_files() - - # Ick, copied straight from install_lib.py (fancy_getopt needs a - # type system! Hell, *everything* needs a type system!!!) - if not isinstance(self.optimize, int): - try: - self.optimize = int(self.optimize) - assert 0 <= self.optimize <= 2 - except (ValueError, AssertionError): - raise DistutilsOptionError("optimize must be 0, 1, or 2") - - def run(self): - # XXX copy_file by default preserves atime and mtime. IMHO this is - # the right thing to do, but perhaps it should be an option -- in - # particular, a site administrator might want installed files to - # reflect the time of installation rather than the last - # modification time before the installed release. - - # XXX copy_file by default preserves mode, which appears to be the - # wrong thing to do: if a file is read-only in the working - # directory, we want it to be installed read/write so that the next - # installation of the same module distribution can overwrite it - # without problems. (This might be a Unix-specific issue.) Thus - # we turn off 'preserve_mode' when copying to the build directory, - # since the build directory is supposed to be exactly what the - # installation will look like (ie. we preserve mode when - # installing). - - # Two options control which modules will be installed: 'packages' - # and 'py_modules'. The former lets us work with whole packages, not - # specifying individual modules at all; the latter is for - # specifying modules one-at-a-time. - - if self.py_modules: - self.build_modules() - if self.packages: - self.build_packages() - self.build_package_data() - - self.byte_compile(self.get_outputs(include_bytecode=0)) - - def get_data_files(self): - """Generate list of '(package,src_dir,build_dir,filenames)' tuples""" - data = [] - if not self.packages: - return data - for package in self.packages: - # Locate package source directory - src_dir = self.get_package_dir(package) - - # Compute package build directory - build_dir = os.path.join(*([self.build_lib] + package.split('.'))) - - # Length of path to strip from found files - plen = 0 - if src_dir: - plen = len(src_dir)+1 - - # Strip directory from globbed filenames - filenames = [ - file[plen:] for file in self.find_data_files(package, src_dir) - ] - data.append((package, src_dir, build_dir, filenames)) - return data - - def find_data_files(self, package, src_dir): - """Return filenames for package's data files in 'src_dir'""" - globs = (self.package_data.get('', []) - + self.package_data.get(package, [])) - files = [] - for pattern in globs: - # Each pattern has to be converted to a platform-specific path - filelist = glob(os.path.join(src_dir, convert_path(pattern))) - # Files that match more than one pattern are only added once - files.extend([fn for fn in filelist if fn not in files - and os.path.isfile(fn)]) - return files - - def build_package_data(self): - """Copy data files into build directory""" - for package, src_dir, build_dir, filenames in self.data_files: - for filename in filenames: - target = os.path.join(build_dir, filename) - self.mkpath(os.path.dirname(target)) - self.copy_file(os.path.join(src_dir, filename), target, - preserve_mode=False) - - def get_package_dir(self, package): - """Return the directory, relative to the top of the source - distribution, where package 'package' should be found - (at least according to the 'package_dir' option, if any).""" - - path = package.split('.') - - if not self.package_dir: - if path: - return os.path.join(*path) - else: - return '' - else: - tail = [] - while path: - try: - pdir = self.package_dir['.'.join(path)] - except KeyError: - tail.insert(0, path[-1]) - del path[-1] - else: - tail.insert(0, pdir) - return os.path.join(*tail) - else: - # Oops, got all the way through 'path' without finding a - # match in package_dir. If package_dir defines a directory - # for the root (nameless) package, then fallback on it; - # otherwise, we might as well have not consulted - # package_dir at all, as we just use the directory implied - # by 'tail' (which should be the same as the original value - # of 'path' at this point). - pdir = self.package_dir.get('') - if pdir is not None: - tail.insert(0, pdir) - - if tail: - return os.path.join(*tail) - else: - return '' - - def check_package(self, package, package_dir): - # Empty dir name means current directory, which we can probably - # assume exists. Also, os.path.exists and isdir don't know about - # my "empty string means current dir" convention, so we have to - # circumvent them. - if package_dir != "": - if not os.path.exists(package_dir): - raise DistutilsFileError( - "package directory '%s' does not exist" % package_dir) - if not os.path.isdir(package_dir): - raise DistutilsFileError( - "supposed package directory '%s' exists, " - "but is not a directory" % package_dir) - - # Require __init__.py for all but the "root package" - if package: - init_py = os.path.join(package_dir, "__init__.py") - if os.path.isfile(init_py): - return init_py - else: - log.warn(("package init file '%s' not found " + - "(or not a regular file)"), init_py) - - # Either not in a package at all (__init__.py not expected), or - # __init__.py doesn't exist -- so don't return the filename. - return None - - def check_module(self, module, module_file): - if not os.path.isfile(module_file): - log.warn("file %s (for module %s) not found", module_file, module) - return False - else: - return True - - def find_package_modules(self, package, package_dir): - self.check_package(package, package_dir) - module_files = glob(os.path.join(package_dir, "*.py")) - modules = [] - setup_script = os.path.abspath(self.distribution.script_name) - - for f in module_files: - abs_f = os.path.abspath(f) - if abs_f != setup_script: - module = os.path.splitext(os.path.basename(f))[0] - modules.append((package, module, f)) - else: - self.debug_print("excluding %s" % setup_script) - return modules - - def find_modules(self): - """Finds individually-specified Python modules, ie. those listed by - module name in 'self.py_modules'. Returns a list of tuples (package, - module_base, filename): 'package' is a tuple of the path through - package-space to the module; 'module_base' is the bare (no - packages, no dots) module name, and 'filename' is the path to the - ".py" file (relative to the distribution root) that implements the - module. - """ - # Map package names to tuples of useful info about the package: - # (package_dir, checked) - # package_dir - the directory where we'll find source files for - # this package - # checked - true if we have checked that the package directory - # is valid (exists, contains __init__.py, ... ?) - packages = {} - - # List of (package, module, filename) tuples to return - modules = [] - - # We treat modules-in-packages almost the same as toplevel modules, - # just the "package" for a toplevel is empty (either an empty - # string or empty list, depending on context). Differences: - # - don't check for __init__.py in directory for empty package - for module in self.py_modules: - path = module.split('.') - package = '.'.join(path[0:-1]) - module_base = path[-1] - - try: - (package_dir, checked) = packages[package] - except KeyError: - package_dir = self.get_package_dir(package) - checked = 0 - - if not checked: - init_py = self.check_package(package, package_dir) - packages[package] = (package_dir, 1) - if init_py: - modules.append((package, "__init__", init_py)) - - # XXX perhaps we should also check for just .pyc files - # (so greedy closed-source bastards can distribute Python - # modules too) - module_file = os.path.join(package_dir, module_base + ".py") - if not self.check_module(module, module_file): - continue - - modules.append((package, module_base, module_file)) - - return modules - - def find_all_modules(self): - """Compute the list of all modules that will be built, whether - they are specified one-module-at-a-time ('self.py_modules') or - by whole packages ('self.packages'). Return a list of tuples - (package, module, module_file), just like 'find_modules()' and - 'find_package_modules()' do.""" - modules = [] - if self.py_modules: - modules.extend(self.find_modules()) - if self.packages: - for package in self.packages: - package_dir = self.get_package_dir(package) - m = self.find_package_modules(package, package_dir) - modules.extend(m) - return modules - - def get_source_files(self): - return [module[-1] for module in self.find_all_modules()] - - def get_module_outfile(self, build_dir, package, module): - outfile_path = [build_dir] + list(package) + [module + ".py"] - return os.path.join(*outfile_path) - - def get_outputs(self, include_bytecode=1): - modules = self.find_all_modules() - outputs = [] - for (package, module, module_file) in modules: - package = package.split('.') - filename = self.get_module_outfile(self.build_lib, package, module) - outputs.append(filename) - if include_bytecode: - if self.compile: - outputs.append(filename + "c") - if self.optimize > 0: - outputs.append(filename + "o") - - outputs += [ - os.path.join(build_dir, filename) - for package, src_dir, build_dir, filenames in self.data_files - for filename in filenames - ] - - return outputs - - def build_module(self, module, module_file, package): - if isinstance(package, str): - package = package.split('.') - elif not isinstance(package, (list, tuple)): - raise TypeError( - "'package' must be a string (dot-separated), list, or tuple") - - # Now put the module source file into the "build" area -- this is - # easy, we just copy it somewhere under self.build_lib (the build - # directory for Python source). - outfile = self.get_module_outfile(self.build_lib, package, module) - dir = os.path.dirname(outfile) - self.mkpath(dir) - return self.copy_file(module_file, outfile, preserve_mode=0) - - def build_modules(self): - modules = self.find_modules() - for (package, module, module_file) in modules: - - # Now "build" the module -- ie. copy the source file to - # self.build_lib (the build directory for Python source). - # (Actually, it gets copied to the directory for this package - # under self.build_lib.) - self.build_module(module, module_file, package) - - def build_packages(self): - for package in self.packages: - - # Get list of (package, module, module_file) tuples based on - # scanning the package directory. 'package' is only included - # in the tuple so that 'find_modules()' and - # 'find_package_tuples()' have a consistent interface; it's - # ignored here (apart from a sanity check). Also, 'module' is - # the *unqualified* module name (ie. no dots, no package -- we - # already know its package!), and 'module_file' is the path to - # the .py file, relative to the current directory - # (ie. including 'package_dir'). - package_dir = self.get_package_dir(package) - modules = self.find_package_modules(package, package_dir) - - # Now loop over the modules we found, "building" each one (just - # copy it to self.build_lib). - for (package_, module, module_file) in modules: - assert package == package_ - self.build_module(module, module_file, package) - - def byte_compile(self, files): - if sys.dont_write_bytecode: - self.warn('byte-compiling is disabled, skipping.') - return - - from distutils.util import byte_compile - prefix = self.build_lib - if prefix[-1] != os.sep: - prefix = prefix + os.sep - - # XXX this code is essentially the same as the 'byte_compile() - # method of the "install_lib" command, except for the determination - # of the 'prefix' string. Hmmm. - - if self.compile: - byte_compile(files, optimize=0, - force=self.force, prefix=prefix, dry_run=self.dry_run) - if self.optimize > 0: - byte_compile(files, optimize=self.optimize, - force=self.force, prefix=prefix, dry_run=self.dry_run) diff --git a/PythonLib/extra/distutils/command/build_scripts.py b/PythonLib/extra/distutils/command/build_scripts.py deleted file mode 100644 index 567df658..00000000 --- a/PythonLib/extra/distutils/command/build_scripts.py +++ /dev/null @@ -1,131 +0,0 @@ -"""distutils.command.build_scripts - -Implements the Distutils 'build_scripts' command.""" - -__revision__ = "$Id$" - -import os, re -from stat import ST_MODE -from distutils.core import Command -from distutils.dep_util import newer -from distutils.util import convert_path -from distutils import log - -# check if Python is called on the first line with this expression -first_line_re = re.compile('^#!.*python[0-9.]*([ \t].*)?$') - -class build_scripts (Command): - - description = "\"build\" scripts (copy and fixup #! line)" - - user_options = [ - ('build-dir=', 'd', "directory to \"build\" (copy) to"), - ('force', 'f', "forcibly build everything (ignore file timestamps"), - ('executable=', 'e', "specify final destination interpreter path"), - ] - - boolean_options = ['force'] - - - def initialize_options (self): - self.build_dir = None - self.scripts = None - self.force = None - self.executable = None - self.outfiles = None - - def finalize_options (self): - self.set_undefined_options('build', - ('build_scripts', 'build_dir'), - ('force', 'force'), - ('executable', 'executable')) - self.scripts = self.distribution.scripts - - def get_source_files(self): - return self.scripts - - def run (self): - if not self.scripts: - return - self.copy_scripts() - - - def copy_scripts (self): - """Copy each script listed in 'self.scripts'; if it's marked as a - Python script in the Unix way (first line matches 'first_line_re', - ie. starts with "\#!" and contains "python"), then adjust the first - line to refer to the current Python interpreter as we copy. - """ - _sysconfig = __import__('sysconfig') - self.mkpath(self.build_dir) - outfiles = [] - for script in self.scripts: - adjust = 0 - script = convert_path(script) - outfile = os.path.join(self.build_dir, os.path.basename(script)) - outfiles.append(outfile) - - if not self.force and not newer(script, outfile): - log.debug("not copying %s (up-to-date)", script) - continue - - # Always open the file, but ignore failures in dry-run mode -- - # that way, we'll get accurate feedback if we can read the - # script. - try: - f = open(script, "r") - except IOError: - if not self.dry_run: - raise - f = None - else: - first_line = f.readline() - if not first_line: - self.warn("%s is an empty file (skipping)" % script) - continue - - match = first_line_re.match(first_line) - if match: - adjust = 1 - post_interp = match.group(1) or '' - - if adjust: - log.info("copying and adjusting %s -> %s", script, - self.build_dir) - if not self.dry_run: - outf = open(outfile, "w") - if not _sysconfig.is_python_build(): - outf.write("#!%s%s\n" % - (self.executable, - post_interp)) - else: - outf.write("#!%s%s\n" % - (os.path.join( - _sysconfig.get_config_var("BINDIR"), - "python%s%s" % (_sysconfig.get_config_var("VERSION"), - _sysconfig.get_config_var("EXE"))), - post_interp)) - outf.writelines(f.readlines()) - outf.close() - if f: - f.close() - else: - if f: - f.close() - self.copy_file(script, outfile) - - if os.name == 'posix': - for file in outfiles: - if self.dry_run: - log.info("changing mode of %s", file) - else: - oldmode = os.stat(file)[ST_MODE] & 07777 - newmode = (oldmode | 0555) & 07777 - if newmode != oldmode: - log.info("changing mode of %s from %o to %o", - file, oldmode, newmode) - os.chmod(file, newmode) - - # copy_scripts () - -# class build_scripts diff --git a/PythonLib/extra/distutils/command/check.py b/PythonLib/extra/distutils/command/check.py deleted file mode 100644 index 152bf0de..00000000 --- a/PythonLib/extra/distutils/command/check.py +++ /dev/null @@ -1,149 +0,0 @@ -"""distutils.command.check - -Implements the Distutils 'check' command. -""" -__revision__ = "$Id$" - -from distutils.core import Command -from distutils.dist import PKG_INFO_ENCODING -from distutils.errors import DistutilsSetupError - -try: - # docutils is installed - from docutils.utils import Reporter - from docutils.parsers.rst import Parser - from docutils import frontend - from docutils import nodes - from StringIO import StringIO - - class SilentReporter(Reporter): - - def __init__(self, source, report_level, halt_level, stream=None, - debug=0, encoding='ascii', error_handler='replace'): - self.messages = [] - Reporter.__init__(self, source, report_level, halt_level, stream, - debug, encoding, error_handler) - - def system_message(self, level, message, *children, **kwargs): - self.messages.append((level, message, children, kwargs)) - return nodes.system_message(message, level=level, - type=self.levels[level], - *children, **kwargs) - - HAS_DOCUTILS = True -except ImportError: - # docutils is not installed - HAS_DOCUTILS = False - -class check(Command): - """This command checks the meta-data of the package. - """ - description = ("perform some checks on the package") - user_options = [('metadata', 'm', 'Verify meta-data'), - ('restructuredtext', 'r', - ('Checks if long string meta-data syntax ' - 'are reStructuredText-compliant')), - ('strict', 's', - 'Will exit with an error if a check fails')] - - boolean_options = ['metadata', 'restructuredtext', 'strict'] - - def initialize_options(self): - """Sets default values for options.""" - self.restructuredtext = 0 - self.metadata = 1 - self.strict = 0 - self._warnings = 0 - - def finalize_options(self): - pass - - def warn(self, msg): - """Counts the number of warnings that occurs.""" - self._warnings += 1 - return Command.warn(self, msg) - - def run(self): - """Runs the command.""" - # perform the various tests - if self.metadata: - self.check_metadata() - if self.restructuredtext: - if HAS_DOCUTILS: - self.check_restructuredtext() - elif self.strict: - raise DistutilsSetupError('The docutils package is needed.') - - # let's raise an error in strict mode, if we have at least - # one warning - if self.strict and self._warnings > 0: - raise DistutilsSetupError('Please correct your package.') - - def check_metadata(self): - """Ensures that all required elements of meta-data are supplied. - - name, version, URL, (author and author_email) or - (maintainer and maintainer_email)). - - Warns if any are missing. - """ - metadata = self.distribution.metadata - - missing = [] - for attr in ('name', 'version', 'url'): - if not (hasattr(metadata, attr) and getattr(metadata, attr)): - missing.append(attr) - - if missing: - self.warn("missing required meta-data: %s" % ', '.join(missing)) - if metadata.author: - if not metadata.author_email: - self.warn("missing meta-data: if 'author' supplied, " + - "'author_email' must be supplied too") - elif metadata.maintainer: - if not metadata.maintainer_email: - self.warn("missing meta-data: if 'maintainer' supplied, " + - "'maintainer_email' must be supplied too") - else: - self.warn("missing meta-data: either (author and author_email) " + - "or (maintainer and maintainer_email) " + - "must be supplied") - - def check_restructuredtext(self): - """Checks if the long string fields are reST-compliant.""" - data = self.distribution.get_long_description() - if not isinstance(data, unicode): - data = data.decode(PKG_INFO_ENCODING) - for warning in self._check_rst_data(data): - line = warning[-1].get('line') - if line is None: - warning = warning[1] - else: - warning = '%s (line %s)' % (warning[1], line) - self.warn(warning) - - def _check_rst_data(self, data): - """Returns warnings when the provided data doesn't compile.""" - source_path = StringIO() - parser = Parser() - settings = frontend.OptionParser().get_default_values() - settings.tab_width = 4 - settings.pep_references = None - settings.rfc_references = None - reporter = SilentReporter(source_path, - settings.report_level, - settings.halt_level, - stream=settings.warning_stream, - debug=settings.debug, - encoding=settings.error_encoding, - error_handler=settings.error_encoding_error_handler) - - document = nodes.document(settings, reporter, source=source_path) - document.note_source(source_path, -1) - try: - parser.parse(data, document) - except AttributeError: - reporter.messages.append((-1, 'Could not finish the parsing.', - '', {})) - - return reporter.messages diff --git a/PythonLib/extra/distutils/command/clean.py b/PythonLib/extra/distutils/command/clean.py deleted file mode 100644 index 90ef35f1..00000000 --- a/PythonLib/extra/distutils/command/clean.py +++ /dev/null @@ -1,80 +0,0 @@ -"""distutils.command.clean - -Implements the Distutils 'clean' command.""" - -# contributed by Bastian Kleineidam , added 2000-03-18 - -__revision__ = "$Id$" - -import os -from distutils.core import Command -from distutils.dir_util import remove_tree -from distutils import log - -class clean(Command): - - description = "clean up temporary files from 'build' command" - user_options = [ - ('build-base=', 'b', - "base build directory (default: 'build.build-base')"), - ('build-lib=', None, - "build directory for all modules (default: 'build.build-lib')"), - ('build-temp=', 't', - "temporary build directory (default: 'build.build-temp')"), - ('build-scripts=', None, - "build directory for scripts (default: 'build.build-scripts')"), - ('bdist-base=', None, - "temporary directory for built distributions"), - ('all', 'a', - "remove all build output, not just temporary by-products") - ] - - boolean_options = ['all'] - - def initialize_options(self): - self.build_base = None - self.build_lib = None - self.build_temp = None - self.build_scripts = None - self.bdist_base = None - self.all = None - - def finalize_options(self): - self.set_undefined_options('build', - ('build_base', 'build_base'), - ('build_lib', 'build_lib'), - ('build_scripts', 'build_scripts'), - ('build_temp', 'build_temp')) - self.set_undefined_options('bdist', - ('bdist_base', 'bdist_base')) - - def run(self): - # remove the build/temp. directory (unless it's already - # gone) - if os.path.exists(self.build_temp): - remove_tree(self.build_temp, dry_run=self.dry_run) - else: - log.debug("'%s' does not exist -- can't clean it", - self.build_temp) - - if self.all: - # remove build directories - for directory in (self.build_lib, - self.bdist_base, - self.build_scripts): - if os.path.exists(directory): - remove_tree(directory, dry_run=self.dry_run) - else: - log.warn("'%s' does not exist -- can't clean it", - directory) - - # just for the heck of it, try to remove the base build directory: - # we might have emptied it right now, but if not we don't care - if not self.dry_run: - try: - os.rmdir(self.build_base) - log.info("removing '%s'", self.build_base) - except OSError: - pass - -# class clean diff --git a/PythonLib/extra/distutils/command/command_template b/PythonLib/extra/distutils/command/command_template deleted file mode 100644 index 50bbab7b..00000000 --- a/PythonLib/extra/distutils/command/command_template +++ /dev/null @@ -1,45 +0,0 @@ -"""distutils.command.x - -Implements the Distutils 'x' command. -""" - -# created 2000/mm/dd, John Doe - -__revision__ = "$Id$" - -from distutils.core import Command - - -class x (Command): - - # Brief (40-50 characters) description of the command - description = "" - - # List of option tuples: long name, short name (None if no short - # name), and help string. - user_options = [('', '', - ""), - ] - - - def initialize_options (self): - self. = None - self. = None - self. = None - - # initialize_options() - - - def finalize_options (self): - if self.x is None: - self.x = - - # finalize_options() - - - def run (self): - - - # run() - -# class x diff --git a/PythonLib/extra/distutils/command/config.py b/PythonLib/extra/distutils/command/config.py deleted file mode 100644 index b0849135..00000000 --- a/PythonLib/extra/distutils/command/config.py +++ /dev/null @@ -1,357 +0,0 @@ -"""distutils.command.config - -Implements the Distutils 'config' command, a (mostly) empty command class -that exists mainly to be sub-classed by specific module distributions and -applications. The idea is that while every "config" command is different, -at least they're all named the same, and users always see "config" in the -list of standard commands. Also, this is a good place to put common -configure-like tasks: "try to compile this C code", or "figure out where -this header file lives". -""" - -__revision__ = "$Id$" - -import os -import re - -from distutils.core import Command -from distutils.errors import DistutilsExecError -from distutils.sysconfig import customize_compiler -from distutils import log - -LANG_EXT = {'c': '.c', 'c++': '.cxx'} - -class config(Command): - - description = "prepare to build" - - user_options = [ - ('compiler=', None, - "specify the compiler type"), - ('cc=', None, - "specify the compiler executable"), - ('include-dirs=', 'I', - "list of directories to search for header files"), - ('define=', 'D', - "C preprocessor macros to define"), - ('undef=', 'U', - "C preprocessor macros to undefine"), - ('libraries=', 'l', - "external C libraries to link with"), - ('library-dirs=', 'L', - "directories to search for external C libraries"), - - ('noisy', None, - "show every action (compile, link, run, ...) taken"), - ('dump-source', None, - "dump generated source files before attempting to compile them"), - ] - - - # The three standard command methods: since the "config" command - # does nothing by default, these are empty. - - def initialize_options(self): - self.compiler = None - self.cc = None - self.include_dirs = None - self.libraries = None - self.library_dirs = None - - # maximal output for now - self.noisy = 1 - self.dump_source = 1 - - # list of temporary files generated along-the-way that we have - # to clean at some point - self.temp_files = [] - - def finalize_options(self): - if self.include_dirs is None: - self.include_dirs = self.distribution.include_dirs or [] - elif isinstance(self.include_dirs, str): - self.include_dirs = self.include_dirs.split(os.pathsep) - - if self.libraries is None: - self.libraries = [] - elif isinstance(self.libraries, str): - self.libraries = [self.libraries] - - if self.library_dirs is None: - self.library_dirs = [] - elif isinstance(self.library_dirs, str): - self.library_dirs = self.library_dirs.split(os.pathsep) - - def run(self): - pass - - - # Utility methods for actual "config" commands. The interfaces are - # loosely based on Autoconf macros of similar names. Sub-classes - # may use these freely. - - def _check_compiler(self): - """Check that 'self.compiler' really is a CCompiler object; - if not, make it one. - """ - # We do this late, and only on-demand, because this is an expensive - # import. - from distutils.ccompiler import CCompiler, new_compiler - if not isinstance(self.compiler, CCompiler): - self.compiler = new_compiler(compiler=self.compiler, - dry_run=self.dry_run, force=1) - customize_compiler(self.compiler) - if self.include_dirs: - self.compiler.set_include_dirs(self.include_dirs) - if self.libraries: - self.compiler.set_libraries(self.libraries) - if self.library_dirs: - self.compiler.set_library_dirs(self.library_dirs) - - - def _gen_temp_sourcefile(self, body, headers, lang): - filename = "_configtest" + LANG_EXT[lang] - file = open(filename, "w") - if headers: - for header in headers: - file.write("#include <%s>\n" % header) - file.write("\n") - file.write(body) - if body[-1] != "\n": - file.write("\n") - file.close() - return filename - - def _preprocess(self, body, headers, include_dirs, lang): - src = self._gen_temp_sourcefile(body, headers, lang) - out = "_configtest.i" - self.temp_files.extend([src, out]) - self.compiler.preprocess(src, out, include_dirs=include_dirs) - return (src, out) - - def _compile(self, body, headers, include_dirs, lang): - src = self._gen_temp_sourcefile(body, headers, lang) - if self.dump_source: - dump_file(src, "compiling '%s':" % src) - (obj,) = self.compiler.object_filenames([src]) - self.temp_files.extend([src, obj]) - self.compiler.compile([src], include_dirs=include_dirs) - return (src, obj) - - def _link(self, body, headers, include_dirs, libraries, library_dirs, - lang): - (src, obj) = self._compile(body, headers, include_dirs, lang) - prog = os.path.splitext(os.path.basename(src))[0] - self.compiler.link_executable([obj], prog, - libraries=libraries, - library_dirs=library_dirs, - target_lang=lang) - - if self.compiler.exe_extension is not None: - prog = prog + self.compiler.exe_extension - self.temp_files.append(prog) - - return (src, obj, prog) - - def _clean(self, *filenames): - if not filenames: - filenames = self.temp_files - self.temp_files = [] - log.info("removing: %s", ' '.join(filenames)) - for filename in filenames: - try: - os.remove(filename) - except OSError: - pass - - - # XXX these ignore the dry-run flag: what to do, what to do? even if - # you want a dry-run build, you still need some sort of configuration - # info. My inclination is to make it up to the real config command to - # consult 'dry_run', and assume a default (minimal) configuration if - # true. The problem with trying to do it here is that you'd have to - # return either true or false from all the 'try' methods, neither of - # which is correct. - - # XXX need access to the header search path and maybe default macros. - - def try_cpp(self, body=None, headers=None, include_dirs=None, lang="c"): - """Construct a source file from 'body' (a string containing lines - of C/C++ code) and 'headers' (a list of header files to include) - and run it through the preprocessor. Return true if the - preprocessor succeeded, false if there were any errors. - ('body' probably isn't of much use, but what the heck.) - """ - from distutils.ccompiler import CompileError - self._check_compiler() - ok = 1 - try: - self._preprocess(body, headers, include_dirs, lang) - except CompileError: - ok = 0 - - self._clean() - return ok - - def search_cpp(self, pattern, body=None, headers=None, include_dirs=None, - lang="c"): - """Construct a source file (just like 'try_cpp()'), run it through - the preprocessor, and return true if any line of the output matches - 'pattern'. 'pattern' should either be a compiled regex object or a - string containing a regex. If both 'body' and 'headers' are None, - preprocesses an empty file -- which can be useful to determine the - symbols the preprocessor and compiler set by default. - """ - self._check_compiler() - src, out = self._preprocess(body, headers, include_dirs, lang) - - if isinstance(pattern, str): - pattern = re.compile(pattern) - - file = open(out) - match = 0 - while 1: - line = file.readline() - if line == '': - break - if pattern.search(line): - match = 1 - break - - file.close() - self._clean() - return match - - def try_compile(self, body, headers=None, include_dirs=None, lang="c"): - """Try to compile a source file built from 'body' and 'headers'. - Return true on success, false otherwise. - """ - from distutils.ccompiler import CompileError - self._check_compiler() - try: - self._compile(body, headers, include_dirs, lang) - ok = 1 - except CompileError: - ok = 0 - - log.info(ok and "success!" or "failure.") - self._clean() - return ok - - def try_link(self, body, headers=None, include_dirs=None, libraries=None, - library_dirs=None, lang="c"): - """Try to compile and link a source file, built from 'body' and - 'headers', to executable form. Return true on success, false - otherwise. - """ - from distutils.ccompiler import CompileError, LinkError - self._check_compiler() - try: - self._link(body, headers, include_dirs, - libraries, library_dirs, lang) - ok = 1 - except (CompileError, LinkError): - ok = 0 - - log.info(ok and "success!" or "failure.") - self._clean() - return ok - - def try_run(self, body, headers=None, include_dirs=None, libraries=None, - library_dirs=None, lang="c"): - """Try to compile, link to an executable, and run a program - built from 'body' and 'headers'. Return true on success, false - otherwise. - """ - from distutils.ccompiler import CompileError, LinkError - self._check_compiler() - try: - src, obj, exe = self._link(body, headers, include_dirs, - libraries, library_dirs, lang) - self.spawn([exe]) - ok = 1 - except (CompileError, LinkError, DistutilsExecError): - ok = 0 - - log.info(ok and "success!" or "failure.") - self._clean() - return ok - - - # -- High-level methods -------------------------------------------- - # (these are the ones that are actually likely to be useful - # when implementing a real-world config command!) - - def check_func(self, func, headers=None, include_dirs=None, - libraries=None, library_dirs=None, decl=0, call=0): - - """Determine if function 'func' is available by constructing a - source file that refers to 'func', and compiles and links it. - If everything succeeds, returns true; otherwise returns false. - - The constructed source file starts out by including the header - files listed in 'headers'. If 'decl' is true, it then declares - 'func' (as "int func()"); you probably shouldn't supply 'headers' - and set 'decl' true in the same call, or you might get errors about - a conflicting declarations for 'func'. Finally, the constructed - 'main()' function either references 'func' or (if 'call' is true) - calls it. 'libraries' and 'library_dirs' are used when - linking. - """ - - self._check_compiler() - body = [] - if decl: - body.append("int %s ();" % func) - body.append("int main () {") - if call: - body.append(" %s();" % func) - else: - body.append(" %s;" % func) - body.append("}") - body = "\n".join(body) + "\n" - - return self.try_link(body, headers, include_dirs, - libraries, library_dirs) - - # check_func () - - def check_lib(self, library, library_dirs=None, headers=None, - include_dirs=None, other_libraries=[]): - """Determine if 'library' is available to be linked against, - without actually checking that any particular symbols are provided - by it. 'headers' will be used in constructing the source file to - be compiled, but the only effect of this is to check if all the - header files listed are available. Any libraries listed in - 'other_libraries' will be included in the link, in case 'library' - has symbols that depend on other libraries. - """ - self._check_compiler() - return self.try_link("int main (void) { }", - headers, include_dirs, - [library]+other_libraries, library_dirs) - - def check_header(self, header, include_dirs=None, library_dirs=None, - lang="c"): - """Determine if the system header file named by 'header_file' - exists and can be found by the preprocessor; return true if so, - false otherwise. - """ - return self.try_cpp(body="/* No body */", headers=[header], - include_dirs=include_dirs) - - -def dump_file(filename, head=None): - """Dumps a file content into log.info. - - If head is not None, will be dumped before the file content. - """ - if head is None: - log.info('%s' % filename) - else: - log.info(head) - file = open(filename) - try: - log.info(file.read()) - finally: - file.close() diff --git a/PythonLib/extra/distutils/command/install.py b/PythonLib/extra/distutils/command/install.py deleted file mode 100644 index b9f1c6c5..00000000 --- a/PythonLib/extra/distutils/command/install.py +++ /dev/null @@ -1,672 +0,0 @@ -"""distutils.command.install - -Implements the Distutils 'install' command.""" - -from distutils import log - -# This module should be kept compatible with Python 2.1. - -__revision__ = "$Id$" - -import sys, os, string -from types import * -from distutils.core import Command -from distutils.debug import DEBUG -from distutils.sysconfig import get_config_vars -from distutils.errors import DistutilsPlatformError -from distutils.file_util import write_file -from distutils.util import convert_path, subst_vars, change_root -from distutils.util import get_platform -from distutils.errors import DistutilsOptionError -from site import USER_BASE -from site import USER_SITE - - -if sys.version < "2.2": - WINDOWS_SCHEME = { - 'purelib': '$base', - 'platlib': '$base', - 'headers': '$base/Include/$dist_name', - 'scripts': '$base/Scripts', - 'data' : '$base', - } -else: - WINDOWS_SCHEME = { - 'purelib': '$base/Lib/site-packages', - 'platlib': '$base/Lib/site-packages', - 'headers': '$base/Include/$dist_name', - 'scripts': '$base/Scripts', - 'data' : '$base', - } - -INSTALL_SCHEMES = { - 'unix_prefix': { - 'purelib': '$base/lib/python$py_version_short/site-packages', - 'platlib': '$platbase/lib/python$py_version_short/site-packages', - 'headers': '$base/include/python$py_version_short/$dist_name', - 'scripts': '$base/bin', - 'data' : '$base', - }, - 'unix_home': { - 'purelib': '$base/lib/python', - 'platlib': '$base/lib/python', - 'headers': '$base/include/python/$dist_name', - 'scripts': '$base/bin', - 'data' : '$base', - }, - 'unix_user': { - 'purelib': '$usersite', - 'platlib': '$usersite', - 'headers': '$userbase/include/python$py_version_short/$dist_name', - 'scripts': '$userbase/bin', - 'data' : '$userbase', - }, - 'nt': WINDOWS_SCHEME, - 'nt_user': { - 'purelib': '$usersite', - 'platlib': '$usersite', - 'headers': '$userbase/Python$py_version_nodot/Include/$dist_name', - 'scripts': '$userbase/Scripts', - 'data' : '$userbase', - }, - 'os2': { - 'purelib': '$base/Lib/site-packages', - 'platlib': '$base/Lib/site-packages', - 'headers': '$base/Include/$dist_name', - 'scripts': '$base/Scripts', - 'data' : '$base', - }, - 'os2_home': { - 'purelib': '$usersite', - 'platlib': '$usersite', - 'headers': '$userbase/include/python$py_version_short/$dist_name', - 'scripts': '$userbase/bin', - 'data' : '$userbase', - }, - } - -# The keys to an installation scheme; if any new types of files are to be -# installed, be sure to add an entry to every installation scheme above, -# and to SCHEME_KEYS here. -SCHEME_KEYS = ('purelib', 'platlib', 'headers', 'scripts', 'data') - - -class install (Command): - - description = "install everything from build directory" - - user_options = [ - # Select installation scheme and set base director(y|ies) - ('prefix=', None, - "installation prefix"), - ('exec-prefix=', None, - "(Unix only) prefix for platform-specific files"), - ('home=', None, - "(Unix only) home directory to install under"), - ('user', None, - "install in user site-package '%s'" % USER_SITE), - - # Or, just set the base director(y|ies) - ('install-base=', None, - "base installation directory (instead of --prefix or --home)"), - ('install-platbase=', None, - "base installation directory for platform-specific files " + - "(instead of --exec-prefix or --home)"), - ('root=', None, - "install everything relative to this alternate root directory"), - - # Or, explicitly set the installation scheme - ('install-purelib=', None, - "installation directory for pure Python module distributions"), - ('install-platlib=', None, - "installation directory for non-pure module distributions"), - ('install-lib=', None, - "installation directory for all module distributions " + - "(overrides --install-purelib and --install-platlib)"), - - ('install-headers=', None, - "installation directory for C/C++ headers"), - ('install-scripts=', None, - "installation directory for Python scripts"), - ('install-data=', None, - "installation directory for data files"), - - # Byte-compilation options -- see install_lib.py for details, as - # these are duplicated from there (but only install_lib does - # anything with them). - ('compile', 'c', "compile .py to .pyc [default]"), - ('no-compile', None, "don't compile .py files"), - ('optimize=', 'O', - "also compile with optimization: -O1 for \"python -O\", " - "-O2 for \"python -OO\", and -O0 to disable [default: -O0]"), - - # Miscellaneous control options - ('force', 'f', - "force installation (overwrite any existing files)"), - ('skip-build', None, - "skip rebuilding everything (for testing/debugging)"), - - # Where to install documentation (eventually!) - #('doc-format=', None, "format of documentation to generate"), - #('install-man=', None, "directory for Unix man pages"), - #('install-html=', None, "directory for HTML documentation"), - #('install-info=', None, "directory for GNU info files"), - - ('record=', None, - "filename in which to record list of installed files"), - ] - - boolean_options = ['compile', 'force', 'skip-build', 'user'] - negative_opt = {'no-compile' : 'compile'} - - - def initialize_options (self): - - # High-level options: these select both an installation base - # and scheme. - self.prefix = None - self.exec_prefix = None - self.home = None - self.user = 0 - - # These select only the installation base; it's up to the user to - # specify the installation scheme (currently, that means supplying - # the --install-{platlib,purelib,scripts,data} options). - self.install_base = None - self.install_platbase = None - self.root = None - - # These options are the actual installation directories; if not - # supplied by the user, they are filled in using the installation - # scheme implied by prefix/exec-prefix/home and the contents of - # that installation scheme. - self.install_purelib = None # for pure module distributions - self.install_platlib = None # non-pure (dists w/ extensions) - self.install_headers = None # for C/C++ headers - self.install_lib = None # set to either purelib or platlib - self.install_scripts = None - self.install_data = None - self.install_userbase = USER_BASE - self.install_usersite = USER_SITE - - self.compile = None - self.optimize = None - - # These two are for putting non-packagized distributions into their - # own directory and creating a .pth file if it makes sense. - # 'extra_path' comes from the setup file; 'install_path_file' can - # be turned off if it makes no sense to install a .pth file. (But - # better to install it uselessly than to guess wrong and not - # install it when it's necessary and would be used!) Currently, - # 'install_path_file' is always true unless some outsider meddles - # with it. - self.extra_path = None - self.install_path_file = 1 - - # 'force' forces installation, even if target files are not - # out-of-date. 'skip_build' skips running the "build" command, - # handy if you know it's not necessary. 'warn_dir' (which is *not* - # a user option, it's just there so the bdist_* commands can turn - # it off) determines whether we warn about installing to a - # directory not in sys.path. - self.force = 0 - self.skip_build = 0 - self.warn_dir = 1 - - # These are only here as a conduit from the 'build' command to the - # 'install_*' commands that do the real work. ('build_base' isn't - # actually used anywhere, but it might be useful in future.) They - # are not user options, because if the user told the install - # command where the build directory is, that wouldn't affect the - # build command. - self.build_base = None - self.build_lib = None - - # Not defined yet because we don't know anything about - # documentation yet. - #self.install_man = None - #self.install_html = None - #self.install_info = None - - self.record = None - - - # -- Option finalizing methods ------------------------------------- - # (This is rather more involved than for most commands, - # because this is where the policy for installing third- - # party Python modules on various platforms given a wide - # array of user input is decided. Yes, it's quite complex!) - - def finalize_options (self): - - # This method (and its pliant slaves, like 'finalize_unix()', - # 'finalize_other()', and 'select_scheme()') is where the default - # installation directories for modules, extension modules, and - # anything else we care to install from a Python module - # distribution. Thus, this code makes a pretty important policy - # statement about how third-party stuff is added to a Python - # installation! Note that the actual work of installation is done - # by the relatively simple 'install_*' commands; they just take - # their orders from the installation directory options determined - # here. - - # Check for errors/inconsistencies in the options; first, stuff - # that's wrong on any platform. - - if ((self.prefix or self.exec_prefix or self.home) and - (self.install_base or self.install_platbase)): - raise DistutilsOptionError, \ - ("must supply either prefix/exec-prefix/home or " + - "install-base/install-platbase -- not both") - - if self.home and (self.prefix or self.exec_prefix): - raise DistutilsOptionError, \ - "must supply either home or prefix/exec-prefix -- not both" - - if self.user and (self.prefix or self.exec_prefix or self.home or - self.install_base or self.install_platbase): - raise DistutilsOptionError("can't combine user with prefix, " - "exec_prefix/home, or install_(plat)base") - - # Next, stuff that's wrong (or dubious) only on certain platforms. - if os.name != "posix": - if self.exec_prefix: - self.warn("exec-prefix option ignored on this platform") - self.exec_prefix = None - - # Now the interesting logic -- so interesting that we farm it out - # to other methods. The goal of these methods is to set the final - # values for the install_{lib,scripts,data,...} options, using as - # input a heady brew of prefix, exec_prefix, home, install_base, - # install_platbase, user-supplied versions of - # install_{purelib,platlib,lib,scripts,data,...}, and the - # INSTALL_SCHEME dictionary above. Phew! - - self.dump_dirs("pre-finalize_{unix,other}") - - if os.name == 'posix': - self.finalize_unix() - else: - self.finalize_other() - - self.dump_dirs("post-finalize_{unix,other}()") - - # Expand configuration variables, tilde, etc. in self.install_base - # and self.install_platbase -- that way, we can use $base or - # $platbase in the other installation directories and not worry - # about needing recursive variable expansion (shudder). - - py_version = (string.split(sys.version))[0] - (prefix, exec_prefix) = get_config_vars('prefix', 'exec_prefix') - self.config_vars = {'dist_name': self.distribution.get_name(), - 'dist_version': self.distribution.get_version(), - 'dist_fullname': self.distribution.get_fullname(), - 'py_version': py_version, - 'py_version_short': py_version[0:3], - 'py_version_nodot': py_version[0] + py_version[2], - 'sys_prefix': prefix, - 'prefix': prefix, - 'sys_exec_prefix': exec_prefix, - 'exec_prefix': exec_prefix, - 'userbase': self.install_userbase, - 'usersite': self.install_usersite, - } - self.expand_basedirs() - - self.dump_dirs("post-expand_basedirs()") - - # Now define config vars for the base directories so we can expand - # everything else. - self.config_vars['base'] = self.install_base - self.config_vars['platbase'] = self.install_platbase - - if DEBUG: - from pprint import pprint - print "config vars:" - pprint(self.config_vars) - - # Expand "~" and configuration variables in the installation - # directories. - self.expand_dirs() - - self.dump_dirs("post-expand_dirs()") - - # Create directories in the home dir: - if self.user: - self.create_home_path() - - # Pick the actual directory to install all modules to: either - # install_purelib or install_platlib, depending on whether this - # module distribution is pure or not. Of course, if the user - # already specified install_lib, use their selection. - if self.install_lib is None: - if self.distribution.ext_modules: # has extensions: non-pure - self.install_lib = self.install_platlib - else: - self.install_lib = self.install_purelib - - - # Convert directories from Unix /-separated syntax to the local - # convention. - self.convert_paths('lib', 'purelib', 'platlib', - 'scripts', 'data', 'headers', - 'userbase', 'usersite') - - # Well, we're not actually fully completely finalized yet: we still - # have to deal with 'extra_path', which is the hack for allowing - # non-packagized module distributions (hello, Numerical Python!) to - # get their own directories. - self.handle_extra_path() - self.install_libbase = self.install_lib # needed for .pth file - self.install_lib = os.path.join(self.install_lib, self.extra_dirs) - - # If a new root directory was supplied, make all the installation - # dirs relative to it. - if self.root is not None: - self.change_roots('libbase', 'lib', 'purelib', 'platlib', - 'scripts', 'data', 'headers') - - self.dump_dirs("after prepending root") - - # Find out the build directories, ie. where to install from. - self.set_undefined_options('build', - ('build_base', 'build_base'), - ('build_lib', 'build_lib')) - - # Punt on doc directories for now -- after all, we're punting on - # documentation completely! - - # finalize_options () - - - def dump_dirs (self, msg): - if DEBUG: - from distutils.fancy_getopt import longopt_xlate - print msg + ":" - for opt in self.user_options: - opt_name = opt[0] - if opt_name[-1] == "=": - opt_name = opt_name[0:-1] - if opt_name in self.negative_opt: - opt_name = string.translate(self.negative_opt[opt_name], - longopt_xlate) - val = not getattr(self, opt_name) - else: - opt_name = string.translate(opt_name, longopt_xlate) - val = getattr(self, opt_name) - print " %s: %s" % (opt_name, val) - - - def finalize_unix (self): - - if self.install_base is not None or self.install_platbase is not None: - if ((self.install_lib is None and - self.install_purelib is None and - self.install_platlib is None) or - self.install_headers is None or - self.install_scripts is None or - self.install_data is None): - raise DistutilsOptionError, \ - ("install-base or install-platbase supplied, but " - "installation scheme is incomplete") - return - - if self.user: - if self.install_userbase is None: - raise DistutilsPlatformError( - "User base directory is not specified") - self.install_base = self.install_platbase = self.install_userbase - self.select_scheme("unix_user") - elif self.home is not None: - self.install_base = self.install_platbase = self.home - self.select_scheme("unix_home") - else: - if self.prefix is None: - if self.exec_prefix is not None: - raise DistutilsOptionError, \ - "must not supply exec-prefix without prefix" - - self.prefix = os.path.normpath(sys.prefix) - self.exec_prefix = os.path.normpath(sys.exec_prefix) - - else: - if self.exec_prefix is None: - self.exec_prefix = self.prefix - - self.install_base = self.prefix - self.install_platbase = self.exec_prefix - self.select_scheme("unix_prefix") - - # finalize_unix () - - - def finalize_other (self): # Windows and Mac OS for now - - if self.user: - if self.install_userbase is None: - raise DistutilsPlatformError( - "User base directory is not specified") - self.install_base = self.install_platbase = self.install_userbase - self.select_scheme(os.name + "_user") - elif self.home is not None: - self.install_base = self.install_platbase = self.home - self.select_scheme("unix_home") - else: - if self.prefix is None: - self.prefix = os.path.normpath(sys.prefix) - - self.install_base = self.install_platbase = self.prefix - try: - self.select_scheme(os.name) - except KeyError: - raise DistutilsPlatformError, \ - "I don't know how to install stuff on '%s'" % os.name - - # finalize_other () - - - def select_scheme (self, name): - # it's the caller's problem if they supply a bad name! - scheme = INSTALL_SCHEMES[name] - for key in SCHEME_KEYS: - attrname = 'install_' + key - if getattr(self, attrname) is None: - setattr(self, attrname, scheme[key]) - - - def _expand_attrs (self, attrs): - for attr in attrs: - val = getattr(self, attr) - if val is not None: - if os.name == 'posix' or os.name == 'nt': - val = os.path.expanduser(val) - val = subst_vars(val, self.config_vars) - setattr(self, attr, val) - - - def expand_basedirs (self): - self._expand_attrs(['install_base', - 'install_platbase', - 'root']) - - def expand_dirs (self): - self._expand_attrs(['install_purelib', - 'install_platlib', - 'install_lib', - 'install_headers', - 'install_scripts', - 'install_data',]) - - - def convert_paths (self, *names): - for name in names: - attr = "install_" + name - setattr(self, attr, convert_path(getattr(self, attr))) - - - def handle_extra_path (self): - - if self.extra_path is None: - self.extra_path = self.distribution.extra_path - - if self.extra_path is not None: - if type(self.extra_path) is StringType: - self.extra_path = string.split(self.extra_path, ',') - - if len(self.extra_path) == 1: - path_file = extra_dirs = self.extra_path[0] - elif len(self.extra_path) == 2: - (path_file, extra_dirs) = self.extra_path - else: - raise DistutilsOptionError, \ - ("'extra_path' option must be a list, tuple, or " - "comma-separated string with 1 or 2 elements") - - # convert to local form in case Unix notation used (as it - # should be in setup scripts) - extra_dirs = convert_path(extra_dirs) - - else: - path_file = None - extra_dirs = '' - - # XXX should we warn if path_file and not extra_dirs? (in which - # case the path file would be harmless but pointless) - self.path_file = path_file - self.extra_dirs = extra_dirs - - # handle_extra_path () - - - def change_roots (self, *names): - for name in names: - attr = "install_" + name - setattr(self, attr, change_root(self.root, getattr(self, attr))) - - def create_home_path(self): - """Create directories under ~ - """ - if not self.user: - return - home = convert_path(os.path.expanduser("~")) - for name, path in self.config_vars.iteritems(): - if path.startswith(home) and not os.path.isdir(path): - self.debug_print("os.makedirs('%s', 0700)" % path) - os.makedirs(path, 0700) - - # -- Command execution methods ------------------------------------- - - def run (self): - - # Obviously have to build before we can install - if not self.skip_build: - self.run_command('build') - # If we built for any other platform, we can't install. - build_plat = self.distribution.get_command_obj('build').plat_name - # check warn_dir - it is a clue that the 'install' is happening - # internally, and not to sys.path, so we don't check the platform - # matches what we are running. - if self.warn_dir and build_plat != get_platform(): - raise DistutilsPlatformError("Can't install when " - "cross-compiling") - - # Run all sub-commands (at least those that need to be run) - for cmd_name in self.get_sub_commands(): - self.run_command(cmd_name) - - if self.path_file: - self.create_path_file() - - # write list of installed files, if requested. - if self.record: - outputs = self.get_outputs() - if self.root: # strip any package prefix - root_len = len(self.root) - for counter in xrange(len(outputs)): - outputs[counter] = outputs[counter][root_len:] - self.execute(write_file, - (self.record, outputs), - "writing list of installed files to '%s'" % - self.record) - - sys_path = map(os.path.normpath, sys.path) - sys_path = map(os.path.normcase, sys_path) - install_lib = os.path.normcase(os.path.normpath(self.install_lib)) - if (self.warn_dir and - not (self.path_file and self.install_path_file) and - install_lib not in sys_path): - log.debug(("modules installed to '%s', which is not in " - "Python's module search path (sys.path) -- " - "you'll have to change the search path yourself"), - self.install_lib) - - # run () - - def create_path_file (self): - filename = os.path.join(self.install_libbase, - self.path_file + ".pth") - if self.install_path_file: - self.execute(write_file, - (filename, [self.extra_dirs]), - "creating %s" % filename) - else: - self.warn("path file '%s' not created" % filename) - - - # -- Reporting methods --------------------------------------------- - - def get_outputs (self): - # Assemble the outputs of all the sub-commands. - outputs = [] - for cmd_name in self.get_sub_commands(): - cmd = self.get_finalized_command(cmd_name) - # Add the contents of cmd.get_outputs(), ensuring - # that outputs doesn't contain duplicate entries - for filename in cmd.get_outputs(): - if filename not in outputs: - outputs.append(filename) - - if self.path_file and self.install_path_file: - outputs.append(os.path.join(self.install_libbase, - self.path_file + ".pth")) - - return outputs - - def get_inputs (self): - # XXX gee, this looks familiar ;-( - inputs = [] - for cmd_name in self.get_sub_commands(): - cmd = self.get_finalized_command(cmd_name) - inputs.extend(cmd.get_inputs()) - - return inputs - - - # -- Predicates for sub-command list ------------------------------- - - def has_lib (self): - """Return true if the current distribution has any Python - modules to install.""" - return (self.distribution.has_pure_modules() or - self.distribution.has_ext_modules()) - - def has_headers (self): - return self.distribution.has_headers() - - def has_scripts (self): - return self.distribution.has_scripts() - - def has_data (self): - return self.distribution.has_data_files() - - - # 'sub_commands': a list of commands this command might have to run to - # get its work done. See cmd.py for more info. - sub_commands = [('install_lib', has_lib), - ('install_headers', has_headers), - ('install_scripts', has_scripts), - ('install_data', has_data), - ('install_egg_info', lambda self:True), - ] - -# class install diff --git a/PythonLib/extra/distutils/command/install_data.py b/PythonLib/extra/distutils/command/install_data.py deleted file mode 100644 index ab40797b..00000000 --- a/PythonLib/extra/distutils/command/install_data.py +++ /dev/null @@ -1,81 +0,0 @@ -"""distutils.command.install_data - -Implements the Distutils 'install_data' command, for installing -platform-independent data files.""" - -# contributed by Bastian Kleineidam - -__revision__ = "$Id$" - -import os -from distutils.core import Command -from distutils.util import change_root, convert_path - -class install_data(Command): - - description = "install data files" - - user_options = [ - ('install-dir=', 'd', - "base directory for installing data files " - "(default: installation base dir)"), - ('root=', None, - "install everything relative to this alternate root directory"), - ('force', 'f', "force installation (overwrite existing files)"), - ] - - boolean_options = ['force'] - - def initialize_options(self): - self.install_dir = None - self.outfiles = [] - self.root = None - self.force = 0 - self.data_files = self.distribution.data_files - self.warn_dir = 1 - - def finalize_options(self): - self.set_undefined_options('install', - ('install_data', 'install_dir'), - ('root', 'root'), - ('force', 'force'), - ) - - def run(self): - self.mkpath(self.install_dir) - for f in self.data_files: - if isinstance(f, str): - # it's a simple file, so copy it - f = convert_path(f) - if self.warn_dir: - self.warn("setup script did not provide a directory for " - "'%s' -- installing right in '%s'" % - (f, self.install_dir)) - (out, _) = self.copy_file(f, self.install_dir) - self.outfiles.append(out) - else: - # it's a tuple with path to install to and a list of files - dir = convert_path(f[0]) - if not os.path.isabs(dir): - dir = os.path.join(self.install_dir, dir) - elif self.root: - dir = change_root(self.root, dir) - self.mkpath(dir) - - if f[1] == []: - # If there are no files listed, the user must be - # trying to create an empty directory, so add the - # directory to the list of output files. - self.outfiles.append(dir) - else: - # Copy files, adding them to the list of output files. - for data in f[1]: - data = convert_path(data) - (out, _) = self.copy_file(data, dir) - self.outfiles.append(out) - - def get_inputs(self): - return self.data_files or [] - - def get_outputs(self): - return self.outfiles diff --git a/PythonLib/extra/distutils/command/install_egg_info.py b/PythonLib/extra/distutils/command/install_egg_info.py deleted file mode 100644 index c8880310..00000000 --- a/PythonLib/extra/distutils/command/install_egg_info.py +++ /dev/null @@ -1,78 +0,0 @@ -"""distutils.command.install_egg_info - -Implements the Distutils 'install_egg_info' command, for installing -a package's PKG-INFO metadata.""" - - -from distutils.cmd import Command -from distutils import log, dir_util -import os, sys, re - -class install_egg_info(Command): - """Install an .egg-info file for the package""" - - description = "Install package's PKG-INFO metadata as an .egg-info file" - user_options = [ - ('install-dir=', 'd', "directory to install to"), - ] - - def initialize_options(self): - self.install_dir = None - - def finalize_options(self): - self.set_undefined_options('install_lib',('install_dir','install_dir')) - basename = "%s-%s-py%s.egg-info" % ( - to_filename(safe_name(self.distribution.get_name())), - to_filename(safe_version(self.distribution.get_version())), - sys.version[:3] - ) - self.target = os.path.join(self.install_dir, basename) - self.outputs = [self.target] - - def run(self): - target = self.target - if os.path.isdir(target) and not os.path.islink(target): - dir_util.remove_tree(target, dry_run=self.dry_run) - elif os.path.exists(target): - self.execute(os.unlink,(self.target,),"Removing "+target) - elif not os.path.isdir(self.install_dir): - self.execute(os.makedirs, (self.install_dir,), - "Creating "+self.install_dir) - log.info("Writing %s", target) - if not self.dry_run: - f = open(target, 'w') - self.distribution.metadata.write_pkg_file(f) - f.close() - - def get_outputs(self): - return self.outputs - - -# The following routines are taken from setuptools' pkg_resources module and -# can be replaced by importing them from pkg_resources once it is included -# in the stdlib. - -def safe_name(name): - """Convert an arbitrary string to a standard distribution name - - Any runs of non-alphanumeric/. characters are replaced with a single '-'. - """ - return re.sub('[^A-Za-z0-9.]+', '-', name) - - -def safe_version(version): - """Convert an arbitrary string to a standard version string - - Spaces become dots, and all other non-alphanumeric characters become - dashes, with runs of multiple dashes condensed to a single dash. - """ - version = version.replace(' ','.') - return re.sub('[^A-Za-z0-9.]+', '-', version) - - -def to_filename(name): - """Convert a project or version name to its filename-escaped form - - Any '-' characters are currently replaced with '_'. - """ - return name.replace('-','_') diff --git a/PythonLib/extra/distutils/command/install_headers.py b/PythonLib/extra/distutils/command/install_headers.py deleted file mode 100644 index d892416a..00000000 --- a/PythonLib/extra/distutils/command/install_headers.py +++ /dev/null @@ -1,51 +0,0 @@ -"""distutils.command.install_headers - -Implements the Distutils 'install_headers' command, to install C/C++ header -files to the Python include directory.""" - -__revision__ = "$Id$" - -from distutils.core import Command - - -# XXX force is never used -class install_headers(Command): - - description = "install C/C++ header files" - - user_options = [('install-dir=', 'd', - "directory to install header files to"), - ('force', 'f', - "force installation (overwrite existing files)"), - ] - - boolean_options = ['force'] - - def initialize_options(self): - self.install_dir = None - self.force = 0 - self.outfiles = [] - - def finalize_options(self): - self.set_undefined_options('install', - ('install_headers', 'install_dir'), - ('force', 'force')) - - - def run(self): - headers = self.distribution.headers - if not headers: - return - - self.mkpath(self.install_dir) - for header in headers: - (out, _) = self.copy_file(header, self.install_dir) - self.outfiles.append(out) - - def get_inputs(self): - return self.distribution.headers or [] - - def get_outputs(self): - return self.outfiles - -# class install_headers diff --git a/PythonLib/extra/distutils/command/install_lib.py b/PythonLib/extra/distutils/command/install_lib.py deleted file mode 100644 index 043e8b6e..00000000 --- a/PythonLib/extra/distutils/command/install_lib.py +++ /dev/null @@ -1,219 +0,0 @@ -"""distutils.command.install_lib - -Implements the Distutils 'install_lib' command -(install all Python modules).""" - -__revision__ = "$Id$" - -import os -import sys - -from distutils.core import Command -from distutils.errors import DistutilsOptionError - - -# Extension for Python source files. -if hasattr(os, 'extsep'): - PYTHON_SOURCE_EXTENSION = os.extsep + "py" -else: - PYTHON_SOURCE_EXTENSION = ".py" - -class install_lib(Command): - - description = "install all Python modules (extensions and pure Python)" - - # The byte-compilation options are a tad confusing. Here are the - # possible scenarios: - # 1) no compilation at all (--no-compile --no-optimize) - # 2) compile .pyc only (--compile --no-optimize; default) - # 3) compile .pyc and "level 1" .pyo (--compile --optimize) - # 4) compile "level 1" .pyo only (--no-compile --optimize) - # 5) compile .pyc and "level 2" .pyo (--compile --optimize-more) - # 6) compile "level 2" .pyo only (--no-compile --optimize-more) - # - # The UI for this is two option, 'compile' and 'optimize'. - # 'compile' is strictly boolean, and only decides whether to - # generate .pyc files. 'optimize' is three-way (0, 1, or 2), and - # decides both whether to generate .pyo files and what level of - # optimization to use. - - user_options = [ - ('install-dir=', 'd', "directory to install to"), - ('build-dir=','b', "build directory (where to install from)"), - ('force', 'f', "force installation (overwrite existing files)"), - ('compile', 'c', "compile .py to .pyc [default]"), - ('no-compile', None, "don't compile .py files"), - ('optimize=', 'O', - "also compile with optimization: -O1 for \"python -O\", " - "-O2 for \"python -OO\", and -O0 to disable [default: -O0]"), - ('skip-build', None, "skip the build steps"), - ] - - boolean_options = ['force', 'compile', 'skip-build'] - negative_opt = {'no-compile' : 'compile'} - - def initialize_options(self): - # let the 'install' command dictate our installation directory - self.install_dir = None - self.build_dir = None - self.force = 0 - self.compile = None - self.optimize = None - self.skip_build = None - - def finalize_options(self): - # Get all the information we need to install pure Python modules - # from the umbrella 'install' command -- build (source) directory, - # install (target) directory, and whether to compile .py files. - self.set_undefined_options('install', - ('build_lib', 'build_dir'), - ('install_lib', 'install_dir'), - ('force', 'force'), - ('compile', 'compile'), - ('optimize', 'optimize'), - ('skip_build', 'skip_build'), - ) - - if self.compile is None: - self.compile = 1 - if self.optimize is None: - self.optimize = 0 - - if not isinstance(self.optimize, int): - try: - self.optimize = int(self.optimize) - if self.optimize not in (0, 1, 2): - raise AssertionError - except (ValueError, AssertionError): - raise DistutilsOptionError, "optimize must be 0, 1, or 2" - - def run(self): - # Make sure we have built everything we need first - self.build() - - # Install everything: simply dump the entire contents of the build - # directory to the installation directory (that's the beauty of - # having a build directory!) - outfiles = self.install() - - # (Optionally) compile .py to .pyc - if outfiles is not None and self.distribution.has_pure_modules(): - self.byte_compile(outfiles) - - # -- Top-level worker functions ------------------------------------ - # (called from 'run()') - - def build(self): - if not self.skip_build: - if self.distribution.has_pure_modules(): - self.run_command('build_py') - if self.distribution.has_ext_modules(): - self.run_command('build_ext') - - def install(self): - if os.path.isdir(self.build_dir): - outfiles = self.copy_tree(self.build_dir, self.install_dir) - else: - self.warn("'%s' does not exist -- no Python modules to install" % - self.build_dir) - return - return outfiles - - def byte_compile(self, files): - if sys.dont_write_bytecode: - self.warn('byte-compiling is disabled, skipping.') - return - - from distutils.util import byte_compile - - # Get the "--root" directory supplied to the "install" command, - # and use it as a prefix to strip off the purported filename - # encoded in bytecode files. This is far from complete, but it - # should at least generate usable bytecode in RPM distributions. - install_root = self.get_finalized_command('install').root - - if self.compile: - byte_compile(files, optimize=0, - force=self.force, prefix=install_root, - dry_run=self.dry_run) - if self.optimize > 0: - byte_compile(files, optimize=self.optimize, - force=self.force, prefix=install_root, - verbose=self.verbose, dry_run=self.dry_run) - - - # -- Utility methods ----------------------------------------------- - - def _mutate_outputs(self, has_any, build_cmd, cmd_option, output_dir): - if not has_any: - return [] - - build_cmd = self.get_finalized_command(build_cmd) - build_files = build_cmd.get_outputs() - build_dir = getattr(build_cmd, cmd_option) - - prefix_len = len(build_dir) + len(os.sep) - outputs = [] - for file in build_files: - outputs.append(os.path.join(output_dir, file[prefix_len:])) - - return outputs - - def _bytecode_filenames(self, py_filenames): - bytecode_files = [] - for py_file in py_filenames: - # Since build_py handles package data installation, the - # list of outputs can contain more than just .py files. - # Make sure we only report bytecode for the .py files. - ext = os.path.splitext(os.path.normcase(py_file))[1] - if ext != PYTHON_SOURCE_EXTENSION: - continue - if self.compile: - bytecode_files.append(py_file + "c") - if self.optimize > 0: - bytecode_files.append(py_file + "o") - - return bytecode_files - - - # -- External interface -------------------------------------------- - # (called by outsiders) - - def get_outputs(self): - """Return the list of files that would be installed if this command - were actually run. Not affected by the "dry-run" flag or whether - modules have actually been built yet. - """ - pure_outputs = \ - self._mutate_outputs(self.distribution.has_pure_modules(), - 'build_py', 'build_lib', - self.install_dir) - if self.compile: - bytecode_outputs = self._bytecode_filenames(pure_outputs) - else: - bytecode_outputs = [] - - ext_outputs = \ - self._mutate_outputs(self.distribution.has_ext_modules(), - 'build_ext', 'build_lib', - self.install_dir) - - return pure_outputs + bytecode_outputs + ext_outputs - - def get_inputs(self): - """Get the list of files that are input to this command, ie. the - files that get installed as they are named in the build tree. - The files in this list correspond one-to-one to the output - filenames returned by 'get_outputs()'. - """ - inputs = [] - - if self.distribution.has_pure_modules(): - build_py = self.get_finalized_command('build_py') - inputs.extend(build_py.get_outputs()) - - if self.distribution.has_ext_modules(): - build_ext = self.get_finalized_command('build_ext') - inputs.extend(build_ext.get_outputs()) - - return inputs diff --git a/PythonLib/extra/distutils/command/install_scripts.py b/PythonLib/extra/distutils/command/install_scripts.py deleted file mode 100644 index 29cd9e7a..00000000 --- a/PythonLib/extra/distutils/command/install_scripts.py +++ /dev/null @@ -1,64 +0,0 @@ -"""distutils.command.install_scripts - -Implements the Distutils 'install_scripts' command, for installing -Python scripts.""" - -# contributed by Bastian Kleineidam - -__revision__ = "$Id$" - -import os -from distutils.core import Command -from distutils import log -from stat import ST_MODE - -class install_scripts (Command): - - description = "install scripts (Python or otherwise)" - - user_options = [ - ('install-dir=', 'd', "directory to install scripts to"), - ('build-dir=','b', "build directory (where to install from)"), - ('force', 'f', "force installation (overwrite existing files)"), - ('skip-build', None, "skip the build steps"), - ] - - boolean_options = ['force', 'skip-build'] - - - def initialize_options (self): - self.install_dir = None - self.force = 0 - self.build_dir = None - self.skip_build = None - - def finalize_options (self): - self.set_undefined_options('build', ('build_scripts', 'build_dir')) - self.set_undefined_options('install', - ('install_scripts', 'install_dir'), - ('force', 'force'), - ('skip_build', 'skip_build'), - ) - - def run (self): - if not self.skip_build: - self.run_command('build_scripts') - self.outfiles = self.copy_tree(self.build_dir, self.install_dir) - if os.name == 'posix': - # Set the executable bits (owner, group, and world) on - # all the scripts we just installed. - for file in self.get_outputs(): - if self.dry_run: - log.info("changing mode of %s", file) - else: - mode = ((os.stat(file)[ST_MODE]) | 0555) & 07777 - log.info("changing mode of %s to %o", file, mode) - os.chmod(file, mode) - - def get_inputs (self): - return self.distribution.scripts or [] - - def get_outputs(self): - return self.outfiles or [] - -# class install_scripts diff --git a/PythonLib/extra/distutils/command/register.py b/PythonLib/extra/distutils/command/register.py deleted file mode 100644 index edb42b95..00000000 --- a/PythonLib/extra/distutils/command/register.py +++ /dev/null @@ -1,315 +0,0 @@ -"""distutils.command.register - -Implements the Distutils 'register' command (register with the repository). -""" - -# created 2002/10/21, Richard Jones - -__revision__ = "$Id$" - -import urllib2 -import getpass -import urlparse -from warnings import warn - -from distutils.core import PyPIRCCommand -from distutils import log - -class register(PyPIRCCommand): - - description = ("register the distribution with the Python package index") - user_options = PyPIRCCommand.user_options + [ - ('list-classifiers', None, - 'list the valid Trove classifiers'), - ('strict', None , - 'Will stop the registering if the meta-data are not fully compliant') - ] - boolean_options = PyPIRCCommand.boolean_options + [ - 'verify', 'list-classifiers', 'strict'] - - sub_commands = [('check', lambda self: True)] - - def initialize_options(self): - PyPIRCCommand.initialize_options(self) - self.list_classifiers = 0 - self.strict = 0 - - def finalize_options(self): - PyPIRCCommand.finalize_options(self) - # setting options for the `check` subcommand - check_options = {'strict': ('register', self.strict), - 'restructuredtext': ('register', 1)} - self.distribution.command_options['check'] = check_options - - def run(self): - self.finalize_options() - self._set_config() - - # Run sub commands - for cmd_name in self.get_sub_commands(): - self.run_command(cmd_name) - - if self.dry_run: - self.verify_metadata() - elif self.list_classifiers: - self.classifiers() - else: - self.send_metadata() - - def check_metadata(self): - """Deprecated API.""" - warn("distutils.command.register.check_metadata is deprecated, \ - use the check command instead", PendingDeprecationWarning) - check = self.distribution.get_command_obj('check') - check.ensure_finalized() - check.strict = self.strict - check.restructuredtext = 1 - check.run() - - def _set_config(self): - ''' Reads the configuration file and set attributes. - ''' - config = self._read_pypirc() - if config != {}: - self.username = config['username'] - self.password = config['password'] - self.repository = config['repository'] - self.realm = config['realm'] - self.has_config = True - else: - if self.repository not in ('pypi', self.DEFAULT_REPOSITORY): - raise ValueError('%s not found in .pypirc' % self.repository) - if self.repository == 'pypi': - self.repository = self.DEFAULT_REPOSITORY - self.has_config = False - - def classifiers(self): - ''' Fetch the list of classifiers from the server. - ''' - response = urllib2.urlopen(self.repository+'?:action=list_classifiers') - log.info(response.read()) - - def verify_metadata(self): - ''' Send the metadata to the package index server to be checked. - ''' - # send the info to the server and report the result - (code, result) = self.post_to_server(self.build_post_data('verify')) - log.info('Server response (%s): %s' % (code, result)) - - - def send_metadata(self): - ''' Send the metadata to the package index server. - - Well, do the following: - 1. figure who the user is, and then - 2. send the data as a Basic auth'ed POST. - - First we try to read the username/password from $HOME/.pypirc, - which is a ConfigParser-formatted file with a section - [distutils] containing username and password entries (both - in clear text). Eg: - - [distutils] - index-servers = - pypi - - [pypi] - username: fred - password: sekrit - - Otherwise, to figure who the user is, we offer the user three - choices: - - 1. use existing login, - 2. register as a new user, or - 3. set the password to a random string and email the user. - - ''' - # see if we can short-cut and get the username/password from the - # config - if self.has_config: - choice = '1' - username = self.username - password = self.password - else: - choice = 'x' - username = password = '' - - # get the user's login info - choices = '1 2 3 4'.split() - while choice not in choices: - self.announce('''\ -We need to know who you are, so please choose either: - 1. use your existing login, - 2. register as a new user, - 3. have the server generate a new password for you (and email it to you), or - 4. quit -Your selection [default 1]: ''', log.INFO) - - choice = raw_input() - if not choice: - choice = '1' - elif choice not in choices: - print 'Please choose one of the four options!' - - if choice == '1': - # get the username and password - while not username: - username = raw_input('Username: ') - while not password: - password = getpass.getpass('Password: ') - - # set up the authentication - auth = urllib2.HTTPPasswordMgr() - host = urlparse.urlparse(self.repository)[1] - auth.add_password(self.realm, host, username, password) - # send the info to the server and report the result - code, result = self.post_to_server(self.build_post_data('submit'), - auth) - self.announce('Server response (%s): %s' % (code, result), - log.INFO) - - # possibly save the login - if code == 200: - if self.has_config: - # sharing the password in the distribution instance - # so the upload command can reuse it - self.distribution.password = password - else: - self.announce(('I can store your PyPI login so future ' - 'submissions will be faster.'), log.INFO) - self.announce('(the login will be stored in %s)' % \ - self._get_rc_file(), log.INFO) - choice = 'X' - while choice.lower() not in 'yn': - choice = raw_input('Save your login (y/N)?') - if not choice: - choice = 'n' - if choice.lower() == 'y': - self._store_pypirc(username, password) - - elif choice == '2': - data = {':action': 'user'} - data['name'] = data['password'] = data['email'] = '' - data['confirm'] = None - while not data['name']: - data['name'] = raw_input('Username: ') - while data['password'] != data['confirm']: - while not data['password']: - data['password'] = getpass.getpass('Password: ') - while not data['confirm']: - data['confirm'] = getpass.getpass(' Confirm: ') - if data['password'] != data['confirm']: - data['password'] = '' - data['confirm'] = None - print "Password and confirm don't match!" - while not data['email']: - data['email'] = raw_input(' EMail: ') - code, result = self.post_to_server(data) - if code != 200: - log.info('Server response (%s): %s' % (code, result)) - else: - log.info('You will receive an email shortly.') - log.info(('Follow the instructions in it to ' - 'complete registration.')) - elif choice == '3': - data = {':action': 'password_reset'} - data['email'] = '' - while not data['email']: - data['email'] = raw_input('Your email address: ') - code, result = self.post_to_server(data) - log.info('Server response (%s): %s' % (code, result)) - - def build_post_data(self, action): - # figure the data to send - the metadata plus some additional - # information used by the package server - meta = self.distribution.metadata - data = { - ':action': action, - 'metadata_version' : '1.0', - 'name': meta.get_name(), - 'version': meta.get_version(), - 'summary': meta.get_description(), - 'home_page': meta.get_url(), - 'author': meta.get_contact(), - 'author_email': meta.get_contact_email(), - 'license': meta.get_licence(), - 'description': meta.get_long_description(), - 'keywords': meta.get_keywords(), - 'platform': meta.get_platforms(), - 'classifiers': meta.get_classifiers(), - 'download_url': meta.get_download_url(), - # PEP 314 - 'provides': meta.get_provides(), - 'requires': meta.get_requires(), - 'obsoletes': meta.get_obsoletes(), - } - if data['provides'] or data['requires'] or data['obsoletes']: - data['metadata_version'] = '1.1' - return data - - def post_to_server(self, data, auth=None): - ''' Post a query to the server, and return a string response. - ''' - if 'name' in data: - self.announce('Registering %s to %s' % (data['name'], - self.repository), - log.INFO) - # Build up the MIME payload for the urllib2 POST data - boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254' - sep_boundary = '\n--' + boundary - end_boundary = sep_boundary + '--' - chunks = [] - for key, value in data.items(): - # handle multiple entries for the same name - if type(value) not in (type([]), type( () )): - value = [value] - for value in value: - chunks.append(sep_boundary) - chunks.append('\nContent-Disposition: form-data; name="%s"'%key) - chunks.append("\n\n") - chunks.append(value) - if value and value[-1] == '\r': - chunks.append('\n') # write an extra newline (lurve Macs) - chunks.append(end_boundary) - chunks.append("\n") - - # chunks may be bytes (str) or unicode objects that we need to encode - body = [] - for chunk in chunks: - if isinstance(chunk, unicode): - body.append(chunk.encode('utf-8')) - else: - body.append(chunk) - - body = ''.join(body) - - # build the Request - headers = { - 'Content-type': 'multipart/form-data; boundary=%s; charset=utf-8'%boundary, - 'Content-length': str(len(body)) - } - req = urllib2.Request(self.repository, body, headers) - - # handle HTTP and include the Basic Auth handler - opener = urllib2.build_opener( - urllib2.HTTPBasicAuthHandler(password_mgr=auth) - ) - data = '' - try: - result = opener.open(req) - except urllib2.HTTPError, e: - if self.show_response: - data = e.fp.read() - result = e.code, e.msg - except urllib2.URLError, e: - result = 500, str(e) - else: - if self.show_response: - data = result.read() - result = 200, 'OK' - if self.show_response: - dashes = '-' * 75 - self.announce('%s%s%s' % (dashes, data, dashes)) - - return result diff --git a/PythonLib/extra/distutils/command/sdist.py b/PythonLib/extra/distutils/command/sdist.py deleted file mode 100644 index 821420d6..00000000 --- a/PythonLib/extra/distutils/command/sdist.py +++ /dev/null @@ -1,477 +0,0 @@ -"""distutils.command.sdist - -Implements the Distutils 'sdist' command (create a source distribution).""" - -__revision__ = "$Id$" - -import os -import string -import sys -from glob import glob -from warnings import warn - -from distutils.core import Command -from distutils import dir_util, dep_util, file_util, archive_util -from distutils.text_file import TextFile -from distutils.errors import (DistutilsPlatformError, DistutilsOptionError, - DistutilsTemplateError) -from distutils.filelist import FileList -from distutils import log -from distutils.util import convert_path - -def show_formats(): - """Print all possible values for the 'formats' option (used by - the "--help-formats" command-line option). - """ - from distutils.fancy_getopt import FancyGetopt - from distutils.archive_util import ARCHIVE_FORMATS - formats = [] - for format in ARCHIVE_FORMATS.keys(): - formats.append(("formats=" + format, None, - ARCHIVE_FORMATS[format][2])) - formats.sort() - FancyGetopt(formats).print_help( - "List of available source distribution formats:") - -class sdist(Command): - - description = "create a source distribution (tarball, zip file, etc.)" - - def checking_metadata(self): - """Callable used for the check sub-command. - - Placed here so user_options can view it""" - return self.metadata_check - - user_options = [ - ('template=', 't', - "name of manifest template file [default: MANIFEST.in]"), - ('manifest=', 'm', - "name of manifest file [default: MANIFEST]"), - ('use-defaults', None, - "include the default file set in the manifest " - "[default; disable with --no-defaults]"), - ('no-defaults', None, - "don't include the default file set"), - ('prune', None, - "specifically exclude files/directories that should not be " - "distributed (build tree, RCS/CVS dirs, etc.) " - "[default; disable with --no-prune]"), - ('no-prune', None, - "don't automatically exclude anything"), - ('manifest-only', 'o', - "just regenerate the manifest and then stop " - "(implies --force-manifest)"), - ('force-manifest', 'f', - "forcibly regenerate the manifest and carry on as usual. " - "Deprecated: now the manifest is always regenerated."), - ('formats=', None, - "formats for source distribution (comma-separated list)"), - ('keep-temp', 'k', - "keep the distribution tree around after creating " + - "archive file(s)"), - ('dist-dir=', 'd', - "directory to put the source distribution archive(s) in " - "[default: dist]"), - ('metadata-check', None, - "Ensure that all required elements of meta-data " - "are supplied. Warn if any missing. [default]"), - ('owner=', 'u', - "Owner name used when creating a tar file [default: current user]"), - ('group=', 'g', - "Group name used when creating a tar file [default: current group]"), - ] - - boolean_options = ['use-defaults', 'prune', - 'manifest-only', 'force-manifest', - 'keep-temp', 'metadata-check'] - - help_options = [ - ('help-formats', None, - "list available distribution formats", show_formats), - ] - - negative_opt = {'no-defaults': 'use-defaults', - 'no-prune': 'prune' } - - default_format = {'posix': 'gztar', - 'nt': 'zip' } - - sub_commands = [('check', checking_metadata)] - - def initialize_options(self): - # 'template' and 'manifest' are, respectively, the names of - # the manifest template and manifest file. - self.template = None - self.manifest = None - - # 'use_defaults': if true, we will include the default file set - # in the manifest - self.use_defaults = 1 - self.prune = 1 - - self.manifest_only = 0 - self.force_manifest = 0 - - self.formats = None - self.keep_temp = 0 - self.dist_dir = None - - self.archive_files = None - self.metadata_check = 1 - self.owner = None - self.group = None - - def finalize_options(self): - if self.manifest is None: - self.manifest = "MANIFEST" - if self.template is None: - self.template = "MANIFEST.in" - - self.ensure_string_list('formats') - if self.formats is None: - try: - self.formats = [self.default_format[os.name]] - except KeyError: - raise DistutilsPlatformError, \ - "don't know how to create source distributions " + \ - "on platform %s" % os.name - - bad_format = archive_util.check_archive_formats(self.formats) - if bad_format: - raise DistutilsOptionError, \ - "unknown archive format '%s'" % bad_format - - if self.dist_dir is None: - self.dist_dir = "dist" - - def run(self): - # 'filelist' contains the list of files that will make up the - # manifest - self.filelist = FileList() - - # Run sub commands - for cmd_name in self.get_sub_commands(): - self.run_command(cmd_name) - - # Do whatever it takes to get the list of files to process - # (process the manifest template, read an existing manifest, - # whatever). File list is accumulated in 'self.filelist'. - self.get_file_list() - - # If user just wanted us to regenerate the manifest, stop now. - if self.manifest_only: - return - - # Otherwise, go ahead and create the source distribution tarball, - # or zipfile, or whatever. - self.make_distribution() - - def check_metadata(self): - """Deprecated API.""" - warn("distutils.command.sdist.check_metadata is deprecated, \ - use the check command instead", PendingDeprecationWarning) - check = self.distribution.get_command_obj('check') - check.ensure_finalized() - check.run() - - def get_file_list(self): - """Figure out the list of files to include in the source - distribution, and put it in 'self.filelist'. This might involve - reading the manifest template (and writing the manifest), or just - reading the manifest, or just using the default file set -- it all - depends on the user's options. - """ - # new behavior when using a template: - # the file list is recalculated every time because - # even if MANIFEST.in or setup.py are not changed - # the user might have added some files in the tree that - # need to be included. - # - # This makes --force the default and only behavior with templates. - template_exists = os.path.isfile(self.template) - if not template_exists and self._manifest_is_not_generated(): - self.read_manifest() - self.filelist.sort() - self.filelist.remove_duplicates() - return - - if not template_exists: - self.warn(("manifest template '%s' does not exist " + - "(using default file list)") % - self.template) - self.filelist.findall() - - if self.use_defaults: - self.add_defaults() - - if template_exists: - self.read_template() - - if self.prune: - self.prune_file_list() - - self.filelist.sort() - self.filelist.remove_duplicates() - self.write_manifest() - - def add_defaults(self): - """Add all the default files to self.filelist: - - README or README.txt - - setup.py - - test/test*.py - - all pure Python modules mentioned in setup script - - all files pointed by package_data (build_py) - - all files defined in data_files. - - all files defined as scripts. - - all C sources listed as part of extensions or C libraries - in the setup script (doesn't catch C headers!) - Warns if (README or README.txt) or setup.py are missing; everything - else is optional. - """ - - standards = [('README', 'README.txt'), self.distribution.script_name] - for fn in standards: - if isinstance(fn, tuple): - alts = fn - got_it = 0 - for fn in alts: - if os.path.exists(fn): - got_it = 1 - self.filelist.append(fn) - break - - if not got_it: - self.warn("standard file not found: should have one of " + - string.join(alts, ', ')) - else: - if os.path.exists(fn): - self.filelist.append(fn) - else: - self.warn("standard file '%s' not found" % fn) - - optional = ['test/test*.py', 'setup.cfg'] - for pattern in optional: - files = filter(os.path.isfile, glob(pattern)) - if files: - self.filelist.extend(files) - - # build_py is used to get: - # - python modules - # - files defined in package_data - build_py = self.get_finalized_command('build_py') - - # getting python files - if self.distribution.has_pure_modules(): - self.filelist.extend(build_py.get_source_files()) - - # getting package_data files - # (computed in build_py.data_files by build_py.finalize_options) - for pkg, src_dir, build_dir, filenames in build_py.data_files: - for filename in filenames: - self.filelist.append(os.path.join(src_dir, filename)) - - # getting distribution.data_files - if self.distribution.has_data_files(): - for item in self.distribution.data_files: - if isinstance(item, str): # plain file - item = convert_path(item) - if os.path.isfile(item): - self.filelist.append(item) - else: # a (dirname, filenames) tuple - dirname, filenames = item - for f in filenames: - f = convert_path(f) - if os.path.isfile(f): - self.filelist.append(f) - - if self.distribution.has_ext_modules(): - build_ext = self.get_finalized_command('build_ext') - self.filelist.extend(build_ext.get_source_files()) - - if self.distribution.has_c_libraries(): - build_clib = self.get_finalized_command('build_clib') - self.filelist.extend(build_clib.get_source_files()) - - if self.distribution.has_scripts(): - build_scripts = self.get_finalized_command('build_scripts') - self.filelist.extend(build_scripts.get_source_files()) - - def read_template(self): - """Read and parse manifest template file named by self.template. - - (usually "MANIFEST.in") The parsing and processing is done by - 'self.filelist', which updates itself accordingly. - """ - log.info("reading manifest template '%s'", self.template) - template = TextFile(self.template, - strip_comments=1, - skip_blanks=1, - join_lines=1, - lstrip_ws=1, - rstrip_ws=1, - collapse_join=1) - - try: - while 1: - line = template.readline() - if line is None: # end of file - break - - try: - self.filelist.process_template_line(line) - # the call above can raise a DistutilsTemplateError for - # malformed lines, or a ValueError from the lower-level - # convert_path function - except (DistutilsTemplateError, ValueError) as msg: - self.warn("%s, line %d: %s" % (template.filename, - template.current_line, - msg)) - finally: - template.close() - - def prune_file_list(self): - """Prune off branches that might slip into the file list as created - by 'read_template()', but really don't belong there: - * the build tree (typically "build") - * the release tree itself (only an issue if we ran "sdist" - previously with --keep-temp, or it aborted) - * any RCS, CVS, .svn, .hg, .git, .bzr, _darcs directories - """ - build = self.get_finalized_command('build') - base_dir = self.distribution.get_fullname() - - self.filelist.exclude_pattern(None, prefix=build.build_base) - self.filelist.exclude_pattern(None, prefix=base_dir) - - # pruning out vcs directories - # both separators are used under win32 - if sys.platform == 'win32': - seps = r'/|\\' - else: - seps = '/' - - vcs_dirs = ['RCS', 'CVS', r'\.svn', r'\.hg', r'\.git', r'\.bzr', - '_darcs'] - vcs_ptrn = r'(^|%s)(%s)(%s).*' % (seps, '|'.join(vcs_dirs), seps) - self.filelist.exclude_pattern(vcs_ptrn, is_regex=1) - - def write_manifest(self): - """Write the file list in 'self.filelist' (presumably as filled in - by 'add_defaults()' and 'read_template()') to the manifest file - named by 'self.manifest'. - """ - if self._manifest_is_not_generated(): - log.info("not writing to manually maintained " - "manifest file '%s'" % self.manifest) - return - - content = self.filelist.files[:] - content.insert(0, '# file GENERATED by distutils, do NOT edit') - self.execute(file_util.write_file, (self.manifest, content), - "writing manifest file '%s'" % self.manifest) - - def _manifest_is_not_generated(self): - # check for special comment used in 2.7.1 and higher - if not os.path.isfile(self.manifest): - return False - - fp = open(self.manifest, 'rU') - try: - first_line = fp.readline() - finally: - fp.close() - return first_line != '# file GENERATED by distutils, do NOT edit\n' - - def read_manifest(self): - """Read the manifest file (named by 'self.manifest') and use it to - fill in 'self.filelist', the list of files to include in the source - distribution. - """ - log.info("reading manifest file '%s'", self.manifest) - manifest = open(self.manifest) - for line in manifest: - # ignore comments and blank lines - line = line.strip() - if line.startswith('#') or not line: - continue - self.filelist.append(line) - manifest.close() - - def make_release_tree(self, base_dir, files): - """Create the directory tree that will become the source - distribution archive. All directories implied by the filenames in - 'files' are created under 'base_dir', and then we hard link or copy - (if hard linking is unavailable) those files into place. - Essentially, this duplicates the developer's source tree, but in a - directory named after the distribution, containing only the files - to be distributed. - """ - # Create all the directories under 'base_dir' necessary to - # put 'files' there; the 'mkpath()' is just so we don't die - # if the manifest happens to be empty. - self.mkpath(base_dir) - dir_util.create_tree(base_dir, files, dry_run=self.dry_run) - - # And walk over the list of files, either making a hard link (if - # os.link exists) to each one that doesn't already exist in its - # corresponding location under 'base_dir', or copying each file - # that's out-of-date in 'base_dir'. (Usually, all files will be - # out-of-date, because by default we blow away 'base_dir' when - # we're done making the distribution archives.) - - if hasattr(os, 'link'): # can make hard links on this system - link = 'hard' - msg = "making hard links in %s..." % base_dir - else: # nope, have to copy - link = None - msg = "copying files to %s..." % base_dir - - if not files: - log.warn("no files to distribute -- empty manifest?") - else: - log.info(msg) - for file in files: - if not os.path.isfile(file): - log.warn("'%s' not a regular file -- skipping" % file) - else: - dest = os.path.join(base_dir, file) - self.copy_file(file, dest, link=link) - - self.distribution.metadata.write_pkg_info(base_dir) - - def make_distribution(self): - """Create the source distribution(s). First, we create the release - tree with 'make_release_tree()'; then, we create all required - archive files (according to 'self.formats') from the release tree. - Finally, we clean up by blowing away the release tree (unless - 'self.keep_temp' is true). The list of archive files created is - stored so it can be retrieved later by 'get_archive_files()'. - """ - # Don't warn about missing meta-data here -- should be (and is!) - # done elsewhere. - base_dir = self.distribution.get_fullname() - base_name = os.path.join(self.dist_dir, base_dir) - - self.make_release_tree(base_dir, self.filelist.files) - archive_files = [] # remember names of files we create - # tar archive must be created last to avoid overwrite and remove - if 'tar' in self.formats: - self.formats.append(self.formats.pop(self.formats.index('tar'))) - - for fmt in self.formats: - file = self.make_archive(base_name, fmt, base_dir=base_dir, - owner=self.owner, group=self.group) - archive_files.append(file) - self.distribution.dist_files.append(('sdist', '', file)) - - self.archive_files = archive_files - - if not self.keep_temp: - dir_util.remove_tree(base_dir, dry_run=self.dry_run) - - def get_archive_files(self): - """Return the list of archive files created when the command - was run, or None if the command hasn't run yet. - """ - return self.archive_files diff --git a/PythonLib/extra/distutils/command/upload.py b/PythonLib/extra/distutils/command/upload.py deleted file mode 100644 index d0133353..00000000 --- a/PythonLib/extra/distutils/command/upload.py +++ /dev/null @@ -1,194 +0,0 @@ -"""distutils.command.upload - -Implements the Distutils 'upload' subcommand (upload package to PyPI).""" -import os -import socket -import platform -from urllib2 import urlopen, Request, HTTPError -from base64 import standard_b64encode -import urlparse -import cStringIO as StringIO -from hashlib import md5 - -from distutils.errors import DistutilsOptionError -from distutils.core import PyPIRCCommand -from distutils.spawn import spawn -from distutils import log - -class upload(PyPIRCCommand): - - description = "upload binary package to PyPI" - - user_options = PyPIRCCommand.user_options + [ - ('sign', 's', - 'sign files to upload using gpg'), - ('identity=', 'i', 'GPG identity used to sign files'), - ] - - boolean_options = PyPIRCCommand.boolean_options + ['sign'] - - def initialize_options(self): - PyPIRCCommand.initialize_options(self) - self.username = '' - self.password = '' - self.show_response = 0 - self.sign = False - self.identity = None - - def finalize_options(self): - PyPIRCCommand.finalize_options(self) - if self.identity and not self.sign: - raise DistutilsOptionError( - "Must use --sign for --identity to have meaning" - ) - config = self._read_pypirc() - if config != {}: - self.username = config['username'] - self.password = config['password'] - self.repository = config['repository'] - self.realm = config['realm'] - - # getting the password from the distribution - # if previously set by the register command - if not self.password and self.distribution.password: - self.password = self.distribution.password - - def run(self): - if not self.distribution.dist_files: - raise DistutilsOptionError("No dist file created in earlier command") - for command, pyversion, filename in self.distribution.dist_files: - self.upload_file(command, pyversion, filename) - - def upload_file(self, command, pyversion, filename): - # Makes sure the repository URL is compliant - schema, netloc, url, params, query, fragments = \ - urlparse.urlparse(self.repository) - if params or query or fragments: - raise AssertionError("Incompatible url %s" % self.repository) - - if schema not in ('http', 'https'): - raise AssertionError("unsupported schema " + schema) - - # Sign if requested - if self.sign: - gpg_args = ["gpg", "--detach-sign", "-a", filename] - if self.identity: - gpg_args[2:2] = ["--local-user", self.identity] - spawn(gpg_args, - dry_run=self.dry_run) - - # Fill in the data - send all the meta-data in case we need to - # register a new release - f = open(filename,'rb') - try: - content = f.read() - finally: - f.close() - meta = self.distribution.metadata - data = { - # action - ':action': 'file_upload', - 'protcol_version': '1', - - # identify release - 'name': meta.get_name(), - 'version': meta.get_version(), - - # file content - 'content': (os.path.basename(filename),content), - 'filetype': command, - 'pyversion': pyversion, - 'md5_digest': md5(content).hexdigest(), - - # additional meta-data - 'metadata_version' : '1.0', - 'summary': meta.get_description(), - 'home_page': meta.get_url(), - 'author': meta.get_contact(), - 'author_email': meta.get_contact_email(), - 'license': meta.get_licence(), - 'description': meta.get_long_description(), - 'keywords': meta.get_keywords(), - 'platform': meta.get_platforms(), - 'classifiers': meta.get_classifiers(), - 'download_url': meta.get_download_url(), - # PEP 314 - 'provides': meta.get_provides(), - 'requires': meta.get_requires(), - 'obsoletes': meta.get_obsoletes(), - } - comment = '' - if command == 'bdist_rpm': - dist, version, id = platform.dist() - if dist: - comment = 'built for %s %s' % (dist, version) - elif command == 'bdist_dumb': - comment = 'built for %s' % platform.platform(terse=1) - data['comment'] = comment - - if self.sign: - data['gpg_signature'] = (os.path.basename(filename) + ".asc", - open(filename+".asc").read()) - - # set up the authentication - auth = "Basic " + standard_b64encode(self.username + ":" + - self.password) - - # Build up the MIME payload for the POST data - boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254' - sep_boundary = '\n--' + boundary - end_boundary = sep_boundary + '--' - body = StringIO.StringIO() - for key, value in data.items(): - # handle multiple entries for the same name - if not isinstance(value, list): - value = [value] - for value in value: - if isinstance(value, tuple): - fn = ';filename="%s"' % value[0] - value = value[1] - else: - fn = "" - - body.write(sep_boundary) - body.write('\nContent-Disposition: form-data; name="%s"'%key) - body.write(fn) - body.write("\n\n") - body.write(value) - if value and value[-1] == '\r': - body.write('\n') # write an extra newline (lurve Macs) - body.write(end_boundary) - body.write("\n") - body = body.getvalue() - - self.announce("Submitting %s to %s" % (filename, self.repository), log.INFO) - - # build the Request - headers = {'Content-type': - 'multipart/form-data; boundary=%s' % boundary, - 'Content-length': str(len(body)), - 'Authorization': auth} - - request = Request(self.repository, data=body, - headers=headers) - # send the data - try: - result = urlopen(request) - status = result.getcode() - reason = result.msg - if self.show_response: - msg = '\n'.join(('-' * 75, r.read(), '-' * 75)) - self.announce(msg, log.INFO) - except socket.error, e: - self.announce(str(e), log.ERROR) - return - except HTTPError, e: - status = e.code - reason = e.msg - - if status == 200: - self.announce('Server response (%s): %s' % (status, reason), - log.INFO) - else: - self.announce('Upload failed (%s): %s' % (status, reason), - log.ERROR) diff --git a/PythonLib/extra/distutils/config.py b/PythonLib/extra/distutils/config.py deleted file mode 100644 index 1d327143..00000000 --- a/PythonLib/extra/distutils/config.py +++ /dev/null @@ -1,116 +0,0 @@ -"""distutils.pypirc - -Provides the PyPIRCCommand class, the base class for the command classes -that uses .pypirc in the distutils.command package. -""" -import os -from ConfigParser import ConfigParser - -from distutils.cmd import Command - -DEFAULT_PYPIRC = """\ -[distutils] -index-servers = - pypi - -[pypi] -username:%s -password:%s -""" - -class PyPIRCCommand(Command): - """Base command that knows how to handle the .pypirc file - """ - DEFAULT_REPOSITORY = 'http://pypi.python.org/pypi' - DEFAULT_REALM = 'pypi' - repository = None - realm = None - - user_options = [ - ('repository=', 'r', - "url of repository [default: %s]" % \ - DEFAULT_REPOSITORY), - ('show-response', None, - 'display full response text from server')] - - boolean_options = ['show-response'] - - def _get_rc_file(self): - """Returns rc file path.""" - return os.path.join(os.path.expanduser('~'), '.pypirc') - - def _store_pypirc(self, username, password): - """Creates a default .pypirc file.""" - rc = self._get_rc_file() - f = os.fdopen(os.open(rc, os.O_CREAT | os.O_WRONLY, 0600), 'w') - try: - f.write(DEFAULT_PYPIRC % (username, password)) - finally: - f.close() - - def _read_pypirc(self): - """Reads the .pypirc file.""" - rc = self._get_rc_file() - if os.path.exists(rc): - self.announce('Using PyPI login from %s' % rc) - repository = self.repository or self.DEFAULT_REPOSITORY - config = ConfigParser() - config.read(rc) - sections = config.sections() - if 'distutils' in sections: - # let's get the list of servers - index_servers = config.get('distutils', 'index-servers') - _servers = [server.strip() for server in - index_servers.split('\n') - if server.strip() != ''] - if _servers == []: - # nothing set, let's try to get the default pypi - if 'pypi' in sections: - _servers = ['pypi'] - else: - # the file is not properly defined, returning - # an empty dict - return {} - for server in _servers: - current = {'server': server} - current['username'] = config.get(server, 'username') - - # optional params - for key, default in (('repository', - self.DEFAULT_REPOSITORY), - ('realm', self.DEFAULT_REALM), - ('password', None)): - if config.has_option(server, key): - current[key] = config.get(server, key) - else: - current[key] = default - if (current['server'] == repository or - current['repository'] == repository): - return current - elif 'server-login' in sections: - # old format - server = 'server-login' - if config.has_option(server, 'repository'): - repository = config.get(server, 'repository') - else: - repository = self.DEFAULT_REPOSITORY - return {'username': config.get(server, 'username'), - 'password': config.get(server, 'password'), - 'repository': repository, - 'server': server, - 'realm': self.DEFAULT_REALM} - - return {} - - def initialize_options(self): - """Initialize options.""" - self.repository = None - self.realm = None - self.show_response = 0 - - def finalize_options(self): - """Finalizes options.""" - if self.repository is None: - self.repository = self.DEFAULT_REPOSITORY - if self.realm is None: - self.realm = self.DEFAULT_REALM diff --git a/PythonLib/extra/distutils/core.py b/PythonLib/extra/distutils/core.py deleted file mode 100644 index b89557d7..00000000 --- a/PythonLib/extra/distutils/core.py +++ /dev/null @@ -1,242 +0,0 @@ -"""distutils.core - -The only module that needs to be imported to use the Distutils; provides -the 'setup' function (which is to be called from the setup script). Also -indirectly provides the Distribution and Command classes, although they are -really defined in distutils.dist and distutils.cmd. -""" - -__revision__ = "$Id$" - -import sys -import os - -from distutils.debug import DEBUG -from distutils.errors import (DistutilsSetupError, DistutilsArgError, - DistutilsError, CCompilerError) -from distutils.util import grok_environment_error - -# Mainly import these so setup scripts can "from distutils.core import" them. -from distutils.dist import Distribution -from distutils.cmd import Command -from distutils.config import PyPIRCCommand -from distutils.extension import Extension - -# This is a barebones help message generated displayed when the user -# runs the setup script with no arguments at all. More useful help -# is generated with various --help options: global help, list commands, -# and per-command help. -USAGE = """\ -usage: %(script)s [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] - or: %(script)s --help [cmd1 cmd2 ...] - or: %(script)s --help-commands - or: %(script)s cmd --help -""" - -def gen_usage(script_name): - script = os.path.basename(script_name) - return USAGE % {'script': script} - - -# Some mild magic to control the behaviour of 'setup()' from 'run_setup()'. -_setup_stop_after = None -_setup_distribution = None - -# Legal keyword arguments for the setup() function -setup_keywords = ('distclass', 'script_name', 'script_args', 'options', - 'name', 'version', 'author', 'author_email', - 'maintainer', 'maintainer_email', 'url', 'license', - 'description', 'long_description', 'keywords', - 'platforms', 'classifiers', 'download_url', - 'requires', 'provides', 'obsoletes', - ) - -# Legal keyword arguments for the Extension constructor -extension_keywords = ('name', 'sources', 'include_dirs', - 'define_macros', 'undef_macros', - 'library_dirs', 'libraries', 'runtime_library_dirs', - 'extra_objects', 'extra_compile_args', 'extra_link_args', - 'swig_opts', 'export_symbols', 'depends', 'language') - -def setup(**attrs): - """The gateway to the Distutils: do everything your setup script needs - to do, in a highly flexible and user-driven way. Briefly: create a - Distribution instance; find and parse config files; parse the command - line; run each Distutils command found there, customized by the options - supplied to 'setup()' (as keyword arguments), in config files, and on - the command line. - - The Distribution instance might be an instance of a class supplied via - the 'distclass' keyword argument to 'setup'; if no such class is - supplied, then the Distribution class (in dist.py) is instantiated. - All other arguments to 'setup' (except for 'cmdclass') are used to set - attributes of the Distribution instance. - - The 'cmdclass' argument, if supplied, is a dictionary mapping command - names to command classes. Each command encountered on the command line - will be turned into a command class, which is in turn instantiated; any - class found in 'cmdclass' is used in place of the default, which is - (for command 'foo_bar') class 'foo_bar' in module - 'distutils.command.foo_bar'. The command class must provide a - 'user_options' attribute which is a list of option specifiers for - 'distutils.fancy_getopt'. Any command-line options between the current - and the next command are used to set attributes of the current command - object. - - When the entire command-line has been successfully parsed, calls the - 'run()' method on each command object in turn. This method will be - driven entirely by the Distribution object (which each command object - has a reference to, thanks to its constructor), and the - command-specific options that became attributes of each command - object. - """ - - global _setup_stop_after, _setup_distribution - - # Determine the distribution class -- either caller-supplied or - # our Distribution (see below). - klass = attrs.get('distclass') - if klass: - del attrs['distclass'] - else: - klass = Distribution - - if 'script_name' not in attrs: - attrs['script_name'] = os.path.basename(sys.argv[0]) - if 'script_args' not in attrs: - attrs['script_args'] = sys.argv[1:] - - # Create the Distribution instance, using the remaining arguments - # (ie. everything except distclass) to initialize it - try: - _setup_distribution = dist = klass(attrs) - except DistutilsSetupError, msg: - if 'name' in attrs: - raise SystemExit, "error in %s setup command: %s" % \ - (attrs['name'], msg) - else: - raise SystemExit, "error in setup command: %s" % msg - - if _setup_stop_after == "init": - return dist - - # Find and parse the config file(s): they will override options from - # the setup script, but be overridden by the command line. - dist.parse_config_files() - - if DEBUG: - print "options (after parsing config files):" - dist.dump_option_dicts() - - if _setup_stop_after == "config": - return dist - - # Parse the command line and override config files; any - # command-line errors are the end user's fault, so turn them into - # SystemExit to suppress tracebacks. - try: - ok = dist.parse_command_line() - except DistutilsArgError, msg: - raise SystemExit, gen_usage(dist.script_name) + "\nerror: %s" % msg - - if DEBUG: - print "options (after parsing command line):" - dist.dump_option_dicts() - - if _setup_stop_after == "commandline": - return dist - - # And finally, run all the commands found on the command line. - if ok: - try: - dist.run_commands() - except KeyboardInterrupt: - raise SystemExit, "interrupted" - except (IOError, os.error), exc: - error = grok_environment_error(exc) - - if DEBUG: - sys.stderr.write(error + "\n") - raise - else: - raise SystemExit, error - - except (DistutilsError, - CCompilerError), msg: - if DEBUG: - raise - else: - raise SystemExit, "error: " + str(msg) - - return dist - - -def run_setup(script_name, script_args=None, stop_after="run"): - """Run a setup script in a somewhat controlled environment, and - return the Distribution instance that drives things. This is useful - if you need to find out the distribution meta-data (passed as - keyword args from 'script' to 'setup()', or the contents of the - config files or command-line. - - 'script_name' is a file that will be run with 'execfile()'; - 'sys.argv[0]' will be replaced with 'script' for the duration of the - call. 'script_args' is a list of strings; if supplied, - 'sys.argv[1:]' will be replaced by 'script_args' for the duration of - the call. - - 'stop_after' tells 'setup()' when to stop processing; possible - values: - init - stop after the Distribution instance has been created and - populated with the keyword arguments to 'setup()' - config - stop after config files have been parsed (and their data - stored in the Distribution instance) - commandline - stop after the command-line ('sys.argv[1:]' or 'script_args') - have been parsed (and the data stored in the Distribution) - run [default] - stop after all commands have been run (the same as if 'setup()' - had been called in the usual way - - Returns the Distribution instance, which provides all information - used to drive the Distutils. - """ - if stop_after not in ('init', 'config', 'commandline', 'run'): - raise ValueError, "invalid value for 'stop_after': %r" % (stop_after,) - - global _setup_stop_after, _setup_distribution - _setup_stop_after = stop_after - - save_argv = sys.argv - g = {'__file__': script_name} - l = {} - try: - try: - sys.argv[0] = script_name - if script_args is not None: - sys.argv[1:] = script_args - f = open(script_name) - try: - exec f.read() in g, l - finally: - f.close() - finally: - sys.argv = save_argv - _setup_stop_after = None - except SystemExit: - # Hmm, should we do something if exiting with a non-zero code - # (ie. error)? - pass - except: - raise - - if _setup_distribution is None: - raise RuntimeError, \ - ("'distutils.core.setup()' was never called -- " - "perhaps '%s' is not a Distutils setup script?") % \ - script_name - - # I wonder if the setup script's namespace -- g and l -- would be of - # any interest to callers? - return _setup_distribution diff --git a/PythonLib/extra/distutils/cygwinccompiler.py b/PythonLib/extra/distutils/cygwinccompiler.py deleted file mode 100644 index 5d116876..00000000 --- a/PythonLib/extra/distutils/cygwinccompiler.py +++ /dev/null @@ -1,463 +0,0 @@ -"""distutils.cygwinccompiler - -Provides the CygwinCCompiler class, a subclass of UnixCCompiler that -handles the Cygwin port of the GNU C compiler to Windows. It also contains -the Mingw32CCompiler class which handles the mingw32 port of GCC (same as -cygwin in no-cygwin mode). -""" - -# problems: -# -# * if you use a msvc compiled python version (1.5.2) -# 1. you have to insert a __GNUC__ section in its config.h -# 2. you have to generate a import library for its dll -# - create a def-file for python??.dll -# - create a import library using -# dlltool --dllname python15.dll --def python15.def \ -# --output-lib libpython15.a -# -# see also http://starship.python.net/crew/kernr/mingw32/Notes.html -# -# * We put export_symbols in a def-file, and don't use -# --export-all-symbols because it doesn't worked reliable in some -# tested configurations. And because other windows compilers also -# need their symbols specified this no serious problem. -# -# tested configurations: -# -# * cygwin gcc 2.91.57/ld 2.9.4/dllwrap 0.2.4 works -# (after patching python's config.h and for C++ some other include files) -# see also http://starship.python.net/crew/kernr/mingw32/Notes.html -# * mingw32 gcc 2.95.2/ld 2.9.4/dllwrap 0.2.4 works -# (ld doesn't support -shared, so we use dllwrap) -# * cygwin gcc 2.95.2/ld 2.10.90/dllwrap 2.10.90 works now -# - its dllwrap doesn't work, there is a bug in binutils 2.10.90 -# see also http://sources.redhat.com/ml/cygwin/2000-06/msg01274.html -# - using gcc -mdll instead dllwrap doesn't work without -static because -# it tries to link against dlls instead their import libraries. (If -# it finds the dll first.) -# By specifying -static we force ld to link against the import libraries, -# this is windows standard and there are normally not the necessary symbols -# in the dlls. -# *** only the version of June 2000 shows these problems -# * cygwin gcc 3.2/ld 2.13.90 works -# (ld supports -shared) -# * mingw gcc 3.2/ld 2.13 works -# (ld supports -shared) - -# This module should be kept compatible with Python 2.1. - -__revision__ = "$Id$" - -import os,sys,copy -from distutils.ccompiler import gen_preprocess_options, gen_lib_options -from distutils.unixccompiler import UnixCCompiler -from distutils.file_util import write_file -from distutils.errors import DistutilsExecError, CompileError, UnknownFileError -from distutils import log - -def get_msvcr(): - """Include the appropriate MSVC runtime library if Python was built - with MSVC 7.0 or later. - """ - msc_pos = sys.version.find('MSC v.') - if msc_pos != -1: - msc_ver = sys.version[msc_pos+6:msc_pos+10] - if msc_ver == '1300': - # MSVC 7.0 - return ['msvcr70'] - elif msc_ver == '1310': - # MSVC 7.1 - return ['msvcr71'] - elif msc_ver == '1400': - # VS2005 / MSVC 8.0 - return ['msvcr80'] - elif msc_ver == '1500': - # VS2008 / MSVC 9.0 - return ['msvcr90'] - else: - raise ValueError("Unknown MS Compiler version %s " % msc_ver) - - -class CygwinCCompiler (UnixCCompiler): - - compiler_type = 'cygwin' - obj_extension = ".o" - static_lib_extension = ".a" - shared_lib_extension = ".dll" - static_lib_format = "lib%s%s" - shared_lib_format = "%s%s" - exe_extension = ".exe" - - def __init__ (self, verbose=0, dry_run=0, force=0): - - UnixCCompiler.__init__ (self, verbose, dry_run, force) - - (status, details) = check_config_h() - self.debug_print("Python's GCC status: %s (details: %s)" % - (status, details)) - if status is not CONFIG_H_OK: - self.warn( - "Python's pyconfig.h doesn't seem to support your compiler. " - "Reason: %s. " - "Compiling may fail because of undefined preprocessor macros." - % details) - - self.gcc_version, self.ld_version, self.dllwrap_version = \ - get_versions() - self.debug_print(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" % - (self.gcc_version, - self.ld_version, - self.dllwrap_version) ) - - # ld_version >= "2.10.90" and < "2.13" should also be able to use - # gcc -mdll instead of dllwrap - # Older dllwraps had own version numbers, newer ones use the - # same as the rest of binutils ( also ld ) - # dllwrap 2.10.90 is buggy - if self.ld_version >= "2.10.90": - self.linker_dll = "gcc" - else: - self.linker_dll = "dllwrap" - - # ld_version >= "2.13" support -shared so use it instead of - # -mdll -static - if self.ld_version >= "2.13": - shared_option = "-shared" - else: - shared_option = "-mdll -static" - - # Hard-code GCC because that's what this is all about. - # XXX optimization, warnings etc. should be customizable. - self.set_executables(compiler='gcc -mcygwin -O -Wall', - compiler_so='gcc -mcygwin -mdll -O -Wall', - compiler_cxx='g++ -mcygwin -O -Wall', - linker_exe='gcc -mcygwin', - linker_so=('%s -mcygwin %s' % - (self.linker_dll, shared_option))) - - # cygwin and mingw32 need different sets of libraries - if self.gcc_version == "2.91.57": - # cygwin shouldn't need msvcrt, but without the dlls will crash - # (gcc version 2.91.57) -- perhaps something about initialization - self.dll_libraries=["msvcrt"] - self.warn( - "Consider upgrading to a newer version of gcc") - else: - # Include the appropriate MSVC runtime library if Python was built - # with MSVC 7.0 or later. - self.dll_libraries = get_msvcr() - - # __init__ () - - - def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts): - if ext == '.rc' or ext == '.res': - # gcc needs '.res' and '.rc' compiled to object files !!! - try: - self.spawn(["windres", "-i", src, "-o", obj]) - except DistutilsExecError, msg: - raise CompileError, msg - else: # for other files use the C-compiler - try: - self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + - extra_postargs) - except DistutilsExecError, msg: - raise CompileError, msg - - def link (self, - target_desc, - objects, - output_filename, - output_dir=None, - libraries=None, - library_dirs=None, - runtime_library_dirs=None, - export_symbols=None, - debug=0, - extra_preargs=None, - extra_postargs=None, - build_temp=None, - target_lang=None): - - # use separate copies, so we can modify the lists - extra_preargs = copy.copy(extra_preargs or []) - libraries = copy.copy(libraries or []) - objects = copy.copy(objects or []) - - # Additional libraries - libraries.extend(self.dll_libraries) - - # handle export symbols by creating a def-file - # with executables this only works with gcc/ld as linker - if ((export_symbols is not None) and - (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")): - # (The linker doesn't do anything if output is up-to-date. - # So it would probably better to check if we really need this, - # but for this we had to insert some unchanged parts of - # UnixCCompiler, and this is not what we want.) - - # we want to put some files in the same directory as the - # object files are, build_temp doesn't help much - # where are the object files - temp_dir = os.path.dirname(objects[0]) - # name of dll to give the helper files the same base name - (dll_name, dll_extension) = os.path.splitext( - os.path.basename(output_filename)) - - # generate the filenames for these files - def_file = os.path.join(temp_dir, dll_name + ".def") - lib_file = os.path.join(temp_dir, 'lib' + dll_name + ".a") - - # Generate .def file - contents = [ - "LIBRARY %s" % os.path.basename(output_filename), - "EXPORTS"] - for sym in export_symbols: - contents.append(sym) - self.execute(write_file, (def_file, contents), - "writing %s" % def_file) - - # next add options for def-file and to creating import libraries - - # dllwrap uses different options than gcc/ld - if self.linker_dll == "dllwrap": - extra_preargs.extend(["--output-lib", lib_file]) - # for dllwrap we have to use a special option - extra_preargs.extend(["--def", def_file]) - # we use gcc/ld here and can be sure ld is >= 2.9.10 - else: - # doesn't work: bfd_close build\...\libfoo.a: Invalid operation - #extra_preargs.extend(["-Wl,--out-implib,%s" % lib_file]) - # for gcc/ld the def-file is specified as any object files - objects.append(def_file) - - #end: if ((export_symbols is not None) and - # (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")): - - # who wants symbols and a many times larger output file - # should explicitly switch the debug mode on - # otherwise we let dllwrap/ld strip the output file - # (On my machine: 10KB < stripped_file < ??100KB - # unstripped_file = stripped_file + XXX KB - # ( XXX=254 for a typical python extension)) - if not debug: - extra_preargs.append("-s") - - UnixCCompiler.link(self, - target_desc, - objects, - output_filename, - output_dir, - libraries, - library_dirs, - runtime_library_dirs, - None, # export_symbols, we do this in our def-file - debug, - extra_preargs, - extra_postargs, - build_temp, - target_lang) - - # link () - - # -- Miscellaneous methods ----------------------------------------- - - # overwrite the one from CCompiler to support rc and res-files - def object_filenames (self, - source_filenames, - strip_dir=0, - output_dir=''): - if output_dir is None: output_dir = '' - obj_names = [] - for src_name in source_filenames: - # use normcase to make sure '.rc' is really '.rc' and not '.RC' - (base, ext) = os.path.splitext (os.path.normcase(src_name)) - if ext not in (self.src_extensions + ['.rc','.res']): - raise UnknownFileError, \ - "unknown file type '%s' (from '%s')" % \ - (ext, src_name) - if strip_dir: - base = os.path.basename (base) - if ext == '.res' or ext == '.rc': - # these need to be compiled to object files - obj_names.append (os.path.join (output_dir, - base + ext + self.obj_extension)) - else: - obj_names.append (os.path.join (output_dir, - base + self.obj_extension)) - return obj_names - - # object_filenames () - -# class CygwinCCompiler - - -# the same as cygwin plus some additional parameters -class Mingw32CCompiler (CygwinCCompiler): - - compiler_type = 'mingw32' - - def __init__ (self, - verbose=0, - dry_run=0, - force=0): - - CygwinCCompiler.__init__ (self, verbose, dry_run, force) - - # ld_version >= "2.13" support -shared so use it instead of - # -mdll -static - if self.ld_version >= "2.13": - shared_option = "-shared" - else: - shared_option = "-mdll -static" - - # A real mingw32 doesn't need to specify a different entry point, - # but cygwin 2.91.57 in no-cygwin-mode needs it. - if self.gcc_version <= "2.91.57": - entry_point = '--entry _DllMain@12' - else: - entry_point = '' - - if self.gcc_version < '4' or is_cygwingcc(): - no_cygwin = ' -mno-cygwin' - else: - no_cygwin = '' - - self.set_executables(compiler='gcc%s -O -Wall' % no_cygwin, - compiler_so='gcc%s -mdll -O -Wall' % no_cygwin, - compiler_cxx='g++%s -O -Wall' % no_cygwin, - linker_exe='gcc%s' % no_cygwin, - linker_so='%s%s %s %s' - % (self.linker_dll, no_cygwin, - shared_option, entry_point)) - # Maybe we should also append -mthreads, but then the finished - # dlls need another dll (mingwm10.dll see Mingw32 docs) - # (-mthreads: Support thread-safe exception handling on `Mingw32') - - # no additional libraries needed - self.dll_libraries=[] - - # Include the appropriate MSVC runtime library if Python was built - # with MSVC 7.0 or later. - self.dll_libraries = get_msvcr() - - # __init__ () - -# class Mingw32CCompiler - -# Because these compilers aren't configured in Python's pyconfig.h file by -# default, we should at least warn the user if he is using a unmodified -# version. - -CONFIG_H_OK = "ok" -CONFIG_H_NOTOK = "not ok" -CONFIG_H_UNCERTAIN = "uncertain" - -def check_config_h(): - - """Check if the current Python installation (specifically, pyconfig.h) - appears amenable to building extensions with GCC. Returns a tuple - (status, details), where 'status' is one of the following constants: - CONFIG_H_OK - all is well, go ahead and compile - CONFIG_H_NOTOK - doesn't look good - CONFIG_H_UNCERTAIN - not sure -- unable to read pyconfig.h - 'details' is a human-readable string explaining the situation. - - Note there are two ways to conclude "OK": either 'sys.version' contains - the string "GCC" (implying that this Python was built with GCC), or the - installed "pyconfig.h" contains the string "__GNUC__". - """ - - # XXX since this function also checks sys.version, it's not strictly a - # "pyconfig.h" check -- should probably be renamed... - - from distutils import sysconfig - import string - # if sys.version contains GCC then python was compiled with - # GCC, and the pyconfig.h file should be OK - if string.find(sys.version,"GCC") >= 0: - return (CONFIG_H_OK, "sys.version mentions 'GCC'") - - fn = sysconfig.get_config_h_filename() - try: - # It would probably better to read single lines to search. - # But we do this only once, and it is fast enough - f = open(fn) - try: - s = f.read() - finally: - f.close() - - except IOError, exc: - # if we can't read this file, we cannot say it is wrong - # the compiler will complain later about this file as missing - return (CONFIG_H_UNCERTAIN, - "couldn't read '%s': %s" % (fn, exc.strerror)) - - else: - # "pyconfig.h" contains an "#ifdef __GNUC__" or something similar - if string.find(s,"__GNUC__") >= 0: - return (CONFIG_H_OK, "'%s' mentions '__GNUC__'" % fn) - else: - return (CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn) - - - -def get_versions(): - """ Try to find out the versions of gcc, ld and dllwrap. - If not possible it returns None for it. - """ - from distutils.version import LooseVersion - from distutils.spawn import find_executable - import re - - gcc_exe = find_executable('gcc') - if gcc_exe: - out = os.popen(gcc_exe + ' -dumpversion','r') - out_string = out.read() - out.close() - result = re.search('(\d+\.\d+(\.\d+)*)',out_string) - if result: - gcc_version = LooseVersion(result.group(1)) - else: - gcc_version = None - else: - gcc_version = None - ld_exe = find_executable('ld') - if ld_exe: - out = os.popen(ld_exe + ' -v','r') - out_string = out.read() - out.close() - result = re.search('(\d+\.\d+(\.\d+)*)',out_string) - if result: - ld_version = LooseVersion(result.group(1)) - else: - ld_version = None - else: - ld_version = None - dllwrap_exe = find_executable('dllwrap') - if dllwrap_exe: - out = os.popen(dllwrap_exe + ' --version','r') - out_string = out.read() - out.close() - result = re.search(' (\d+\.\d+(\.\d+)*)',out_string) - if result: - dllwrap_version = LooseVersion(result.group(1)) - else: - dllwrap_version = None - else: - dllwrap_version = None - return (gcc_version, ld_version, dllwrap_version) - -def is_cygwingcc(): - '''Try to determine if the gcc that would be used is from cygwin.''' - out = os.popen('gcc -dumpmachine', 'r') - out_string = out.read() - out.close() - # out_string is the target triplet cpu-vendor-os - # Cygwin's gcc sets the os to 'cygwin' - return out_string.strip().endswith('cygwin') diff --git a/PythonLib/extra/distutils/debug.py b/PythonLib/extra/distutils/debug.py deleted file mode 100644 index 28867444..00000000 --- a/PythonLib/extra/distutils/debug.py +++ /dev/null @@ -1,7 +0,0 @@ -import os - -__revision__ = "$Id$" - -# If DISTUTILS_DEBUG is anything other than the empty string, we run in -# debug mode. -DEBUG = os.environ.get('DISTUTILS_DEBUG') diff --git a/PythonLib/extra/distutils/dep_util.py b/PythonLib/extra/distutils/dep_util.py deleted file mode 100644 index 2b759056..00000000 --- a/PythonLib/extra/distutils/dep_util.py +++ /dev/null @@ -1,89 +0,0 @@ -"""distutils.dep_util - -Utility functions for simple, timestamp-based dependency of files -and groups of files; also, function based entirely on such -timestamp dependency analysis.""" - -__revision__ = "$Id$" - -import os -from stat import ST_MTIME -from distutils.errors import DistutilsFileError - -def newer(source, target): - """Tells if the target is newer than the source. - - Return true if 'source' exists and is more recently modified than - 'target', or if 'source' exists and 'target' doesn't. - - Return false if both exist and 'target' is the same age or younger - than 'source'. Raise DistutilsFileError if 'source' does not exist. - - Note that this test is not very accurate: files created in the same second - will have the same "age". - """ - if not os.path.exists(source): - raise DistutilsFileError("file '%s' does not exist" % - os.path.abspath(source)) - if not os.path.exists(target): - return True - - return os.stat(source)[ST_MTIME] > os.stat(target)[ST_MTIME] - -def newer_pairwise(sources, targets): - """Walk two filename lists in parallel, testing if each source is newer - than its corresponding target. Return a pair of lists (sources, - targets) where source is newer than target, according to the semantics - of 'newer()'. - """ - if len(sources) != len(targets): - raise ValueError, "'sources' and 'targets' must be same length" - - # build a pair of lists (sources, targets) where source is newer - n_sources = [] - n_targets = [] - for source, target in zip(sources, targets): - if newer(source, target): - n_sources.append(source) - n_targets.append(target) - - return n_sources, n_targets - -def newer_group(sources, target, missing='error'): - """Return true if 'target' is out-of-date with respect to any file - listed in 'sources'. - - In other words, if 'target' exists and is newer - than every file in 'sources', return false; otherwise return true. - 'missing' controls what we do when a source file is missing; the - default ("error") is to blow up with an OSError from inside 'stat()'; - if it is "ignore", we silently drop any missing source files; if it is - "newer", any missing source files make us assume that 'target' is - out-of-date (this is handy in "dry-run" mode: it'll make you pretend to - carry out commands that wouldn't work because inputs are missing, but - that doesn't matter because you're not actually going to run the - commands). - """ - # If the target doesn't even exist, then it's definitely out-of-date. - if not os.path.exists(target): - return True - - # Otherwise we have to find out the hard way: if *any* source file - # is more recent than 'target', then 'target' is out-of-date and - # we can immediately return true. If we fall through to the end - # of the loop, then 'target' is up-to-date and we return false. - target_mtime = os.stat(target)[ST_MTIME] - - for source in sources: - if not os.path.exists(source): - if missing == 'error': # blow up when we stat() the file - pass - elif missing == 'ignore': # missing source dropped from - continue # target's dependency list - elif missing == 'newer': # missing source means target is - return True # out-of-date - - if os.stat(source)[ST_MTIME] > target_mtime: - return True - - return False diff --git a/PythonLib/extra/distutils/dir_util.py b/PythonLib/extra/distutils/dir_util.py deleted file mode 100644 index 5026e246..00000000 --- a/PythonLib/extra/distutils/dir_util.py +++ /dev/null @@ -1,216 +0,0 @@ -"""distutils.dir_util - -Utility functions for manipulating directories and directory trees.""" - -__revision__ = "$Id$" - -import os -import errno -from distutils.errors import DistutilsFileError, DistutilsInternalError -from distutils import log - -# cache for by mkpath() -- in addition to cheapening redundant calls, -# eliminates redundant "creating /foo/bar/baz" messages in dry-run mode -_path_created = {} - -# I don't use os.makedirs because a) it's new to Python 1.5.2, and -# b) it blows up if the directory already exists (I want to silently -# succeed in that case). -def mkpath(name, mode=0777, verbose=1, dry_run=0): - """Create a directory and any missing ancestor directories. - - If the directory already exists (or if 'name' is the empty string, which - means the current directory, which of course exists), then do nothing. - Raise DistutilsFileError if unable to create some directory along the way - (eg. some sub-path exists, but is a file rather than a directory). - If 'verbose' is true, print a one-line summary of each mkdir to stdout. - Return the list of directories actually created. - """ - - global _path_created - - # Detect a common bug -- name is None - if not isinstance(name, basestring): - raise DistutilsInternalError, \ - "mkpath: 'name' must be a string (got %r)" % (name,) - - # XXX what's the better way to handle verbosity? print as we create - # each directory in the path (the current behaviour), or only announce - # the creation of the whole path? (quite easy to do the latter since - # we're not using a recursive algorithm) - - name = os.path.normpath(name) - created_dirs = [] - if os.path.isdir(name) or name == '': - return created_dirs - if _path_created.get(os.path.abspath(name)): - return created_dirs - - (head, tail) = os.path.split(name) - tails = [tail] # stack of lone dirs to create - - while head and tail and not os.path.isdir(head): - (head, tail) = os.path.split(head) - tails.insert(0, tail) # push next higher dir onto stack - - # now 'head' contains the deepest directory that already exists - # (that is, the child of 'head' in 'name' is the highest directory - # that does *not* exist) - for d in tails: - #print "head = %s, d = %s: " % (head, d), - head = os.path.join(head, d) - abs_head = os.path.abspath(head) - - if _path_created.get(abs_head): - continue - - if verbose >= 1: - log.info("creating %s", head) - - if not dry_run: - try: - os.mkdir(head, mode) - except OSError, exc: - if not (exc.errno == errno.EEXIST and os.path.isdir(head)): - raise DistutilsFileError( - "could not create '%s': %s" % (head, exc.args[-1])) - created_dirs.append(head) - - _path_created[abs_head] = 1 - return created_dirs - -def create_tree(base_dir, files, mode=0777, verbose=1, dry_run=0): - """Create all the empty directories under 'base_dir' needed to put 'files' - there. - - 'base_dir' is just the a name of a directory which doesn't necessarily - exist yet; 'files' is a list of filenames to be interpreted relative to - 'base_dir'. 'base_dir' + the directory portion of every file in 'files' - will be created if it doesn't already exist. 'mode', 'verbose' and - 'dry_run' flags are as for 'mkpath()'. - """ - # First get the list of directories to create - need_dir = {} - for file in files: - need_dir[os.path.join(base_dir, os.path.dirname(file))] = 1 - need_dirs = need_dir.keys() - need_dirs.sort() - - # Now create them - for dir in need_dirs: - mkpath(dir, mode, verbose=verbose, dry_run=dry_run) - -def copy_tree(src, dst, preserve_mode=1, preserve_times=1, - preserve_symlinks=0, update=0, verbose=1, dry_run=0): - """Copy an entire directory tree 'src' to a new location 'dst'. - - Both 'src' and 'dst' must be directory names. If 'src' is not a - directory, raise DistutilsFileError. If 'dst' does not exist, it is - created with 'mkpath()'. The end result of the copy is that every - file in 'src' is copied to 'dst', and directories under 'src' are - recursively copied to 'dst'. Return the list of files that were - copied or might have been copied, using their output name. The - return value is unaffected by 'update' or 'dry_run': it is simply - the list of all files under 'src', with the names changed to be - under 'dst'. - - 'preserve_mode' and 'preserve_times' are the same as for - 'copy_file'; note that they only apply to regular files, not to - directories. If 'preserve_symlinks' is true, symlinks will be - copied as symlinks (on platforms that support them!); otherwise - (the default), the destination of the symlink will be copied. - 'update' and 'verbose' are the same as for 'copy_file'. - """ - from distutils.file_util import copy_file - - if not dry_run and not os.path.isdir(src): - raise DistutilsFileError, \ - "cannot copy tree '%s': not a directory" % src - try: - names = os.listdir(src) - except os.error, (errno, errstr): - if dry_run: - names = [] - else: - raise DistutilsFileError, \ - "error listing files in '%s': %s" % (src, errstr) - - if not dry_run: - mkpath(dst, verbose=verbose) - - outputs = [] - - for n in names: - src_name = os.path.join(src, n) - dst_name = os.path.join(dst, n) - - if n.startswith('.nfs'): - # skip NFS rename files - continue - - if preserve_symlinks and os.path.islink(src_name): - link_dest = os.readlink(src_name) - if verbose >= 1: - log.info("linking %s -> %s", dst_name, link_dest) - if not dry_run: - os.symlink(link_dest, dst_name) - outputs.append(dst_name) - - elif os.path.isdir(src_name): - outputs.extend( - copy_tree(src_name, dst_name, preserve_mode, - preserve_times, preserve_symlinks, update, - verbose=verbose, dry_run=dry_run)) - else: - copy_file(src_name, dst_name, preserve_mode, - preserve_times, update, verbose=verbose, - dry_run=dry_run) - outputs.append(dst_name) - - return outputs - -def _build_cmdtuple(path, cmdtuples): - """Helper for remove_tree().""" - for f in os.listdir(path): - real_f = os.path.join(path,f) - if os.path.isdir(real_f) and not os.path.islink(real_f): - _build_cmdtuple(real_f, cmdtuples) - else: - cmdtuples.append((os.remove, real_f)) - cmdtuples.append((os.rmdir, path)) - -def remove_tree(directory, verbose=1, dry_run=0): - """Recursively remove an entire directory tree. - - Any errors are ignored (apart from being reported to stdout if 'verbose' - is true). - """ - from distutils.util import grok_environment_error - global _path_created - - if verbose >= 1: - log.info("removing '%s' (and everything under it)", directory) - if dry_run: - return - cmdtuples = [] - _build_cmdtuple(directory, cmdtuples) - for cmd in cmdtuples: - try: - cmd[0](cmd[1]) - # remove dir from cache if it's already there - abspath = os.path.abspath(cmd[1]) - if abspath in _path_created: - del _path_created[abspath] - except (IOError, OSError), exc: - log.warn(grok_environment_error( - exc, "error removing %s: " % directory)) - -def ensure_relative(path): - """Take the full path 'path', and make it a relative path. - - This is useful to make 'path' the second argument to os.path.join(). - """ - drive, path = os.path.splitdrive(path) - if path[0:1] == os.sep: - path = drive + path[1:] - return path diff --git a/PythonLib/extra/distutils/dist.py b/PythonLib/extra/distutils/dist.py deleted file mode 100644 index e025313d..00000000 --- a/PythonLib/extra/distutils/dist.py +++ /dev/null @@ -1,1249 +0,0 @@ -"""distutils.dist - -Provides the Distribution class, which represents the module distribution -being built/installed/distributed. -""" - -__revision__ = "$Id$" - -import sys, os, re -from email import message_from_file - -try: - import warnings -except ImportError: - warnings = None - -from distutils.errors import (DistutilsOptionError, DistutilsArgError, - DistutilsModuleError, DistutilsClassError) -from distutils.fancy_getopt import FancyGetopt, translate_longopt -from distutils.util import check_environ, strtobool, rfc822_escape -from distutils import log -from distutils.debug import DEBUG - -# Encoding used for the PKG-INFO files -PKG_INFO_ENCODING = 'utf-8' - -# Regex to define acceptable Distutils command names. This is not *quite* -# the same as a Python NAME -- I don't allow leading underscores. The fact -# that they're very similar is no coincidence; the default naming scheme is -# to look for a Python module named after the command. -command_re = re.compile (r'^[a-zA-Z]([a-zA-Z0-9_]*)$') - - -class Distribution: - """The core of the Distutils. Most of the work hiding behind 'setup' - is really done within a Distribution instance, which farms the work out - to the Distutils commands specified on the command line. - - Setup scripts will almost never instantiate Distribution directly, - unless the 'setup()' function is totally inadequate to their needs. - However, it is conceivable that a setup script might wish to subclass - Distribution for some specialized purpose, and then pass the subclass - to 'setup()' as the 'distclass' keyword argument. If so, it is - necessary to respect the expectations that 'setup' has of Distribution. - See the code for 'setup()', in core.py, for details. - """ - - - # 'global_options' describes the command-line options that may be - # supplied to the setup script prior to any actual commands. - # Eg. "./setup.py -n" or "./setup.py --quiet" both take advantage of - # these global options. This list should be kept to a bare minimum, - # since every global option is also valid as a command option -- and we - # don't want to pollute the commands with too many options that they - # have minimal control over. - # The fourth entry for verbose means that it can be repeated. - global_options = [('verbose', 'v', "run verbosely (default)", 1), - ('quiet', 'q', "run quietly (turns verbosity off)"), - ('dry-run', 'n', "don't actually do anything"), - ('help', 'h', "show detailed help message"), - ('no-user-cfg', None, - 'ignore pydistutils.cfg in your home directory'), - ] - - # 'common_usage' is a short (2-3 line) string describing the common - # usage of the setup script. - common_usage = """\ -Common commands: (see '--help-commands' for more) - - setup.py build will build the package underneath 'build/' - setup.py install will install the package -""" - - # options that are not propagated to the commands - display_options = [ - ('help-commands', None, - "list all available commands"), - ('name', None, - "print package name"), - ('version', 'V', - "print package version"), - ('fullname', None, - "print -"), - ('author', None, - "print the author's name"), - ('author-email', None, - "print the author's email address"), - ('maintainer', None, - "print the maintainer's name"), - ('maintainer-email', None, - "print the maintainer's email address"), - ('contact', None, - "print the maintainer's name if known, else the author's"), - ('contact-email', None, - "print the maintainer's email address if known, else the author's"), - ('url', None, - "print the URL for this package"), - ('license', None, - "print the license of the package"), - ('licence', None, - "alias for --license"), - ('description', None, - "print the package description"), - ('long-description', None, - "print the long package description"), - ('platforms', None, - "print the list of platforms"), - ('classifiers', None, - "print the list of classifiers"), - ('keywords', None, - "print the list of keywords"), - ('provides', None, - "print the list of packages/modules provided"), - ('requires', None, - "print the list of packages/modules required"), - ('obsoletes', None, - "print the list of packages/modules made obsolete") - ] - display_option_names = map(lambda x: translate_longopt(x[0]), - display_options) - - # negative options are options that exclude other options - negative_opt = {'quiet': 'verbose'} - - - # -- Creation/initialization methods ------------------------------- - - def __init__ (self, attrs=None): - """Construct a new Distribution instance: initialize all the - attributes of a Distribution, and then use 'attrs' (a dictionary - mapping attribute names to values) to assign some of those - attributes their "real" values. (Any attributes not mentioned in - 'attrs' will be assigned to some null value: 0, None, an empty list - or dictionary, etc.) Most importantly, initialize the - 'command_obj' attribute to the empty dictionary; this will be - filled in with real command objects by 'parse_command_line()'. - """ - - # Default values for our command-line options - self.verbose = 1 - self.dry_run = 0 - self.help = 0 - for attr in self.display_option_names: - setattr(self, attr, 0) - - # Store the distribution meta-data (name, version, author, and so - # forth) in a separate object -- we're getting to have enough - # information here (and enough command-line options) that it's - # worth it. Also delegate 'get_XXX()' methods to the 'metadata' - # object in a sneaky and underhanded (but efficient!) way. - self.metadata = DistributionMetadata() - for basename in self.metadata._METHOD_BASENAMES: - method_name = "get_" + basename - setattr(self, method_name, getattr(self.metadata, method_name)) - - # 'cmdclass' maps command names to class objects, so we - # can 1) quickly figure out which class to instantiate when - # we need to create a new command object, and 2) have a way - # for the setup script to override command classes - self.cmdclass = {} - - # 'command_packages' is a list of packages in which commands - # are searched for. The factory for command 'foo' is expected - # to be named 'foo' in the module 'foo' in one of the packages - # named here. This list is searched from the left; an error - # is raised if no named package provides the command being - # searched for. (Always access using get_command_packages().) - self.command_packages = None - - # 'script_name' and 'script_args' are usually set to sys.argv[0] - # and sys.argv[1:], but they can be overridden when the caller is - # not necessarily a setup script run from the command-line. - self.script_name = None - self.script_args = None - - # 'command_options' is where we store command options between - # parsing them (from config files, the command-line, etc.) and when - # they are actually needed -- ie. when the command in question is - # instantiated. It is a dictionary of dictionaries of 2-tuples: - # command_options = { command_name : { option : (source, value) } } - self.command_options = {} - - # 'dist_files' is the list of (command, pyversion, file) that - # have been created by any dist commands run so far. This is - # filled regardless of whether the run is dry or not. pyversion - # gives sysconfig.get_python_version() if the dist file is - # specific to a Python version, 'any' if it is good for all - # Python versions on the target platform, and '' for a source - # file. pyversion should not be used to specify minimum or - # maximum required Python versions; use the metainfo for that - # instead. - self.dist_files = [] - - # These options are really the business of various commands, rather - # than of the Distribution itself. We provide aliases for them in - # Distribution as a convenience to the developer. - self.packages = None - self.package_data = {} - self.package_dir = None - self.py_modules = None - self.libraries = None - self.headers = None - self.ext_modules = None - self.ext_package = None - self.include_dirs = None - self.extra_path = None - self.scripts = None - self.data_files = None - self.password = '' - - # And now initialize bookkeeping stuff that can't be supplied by - # the caller at all. 'command_obj' maps command names to - # Command instances -- that's how we enforce that every command - # class is a singleton. - self.command_obj = {} - - # 'have_run' maps command names to boolean values; it keeps track - # of whether we have actually run a particular command, to make it - # cheap to "run" a command whenever we think we might need to -- if - # it's already been done, no need for expensive filesystem - # operations, we just check the 'have_run' dictionary and carry on. - # It's only safe to query 'have_run' for a command class that has - # been instantiated -- a false value will be inserted when the - # command object is created, and replaced with a true value when - # the command is successfully run. Thus it's probably best to use - # '.get()' rather than a straight lookup. - self.have_run = {} - - # Now we'll use the attrs dictionary (ultimately, keyword args from - # the setup script) to possibly override any or all of these - # distribution options. - - if attrs: - # Pull out the set of command options and work on them - # specifically. Note that this order guarantees that aliased - # command options will override any supplied redundantly - # through the general options dictionary. - options = attrs.get('options') - if options is not None: - del attrs['options'] - for (command, cmd_options) in options.items(): - opt_dict = self.get_option_dict(command) - for (opt, val) in cmd_options.items(): - opt_dict[opt] = ("setup script", val) - - if 'licence' in attrs: - attrs['license'] = attrs['licence'] - del attrs['licence'] - msg = "'licence' distribution option is deprecated; use 'license'" - if warnings is not None: - warnings.warn(msg) - else: - sys.stderr.write(msg + "\n") - - # Now work on the rest of the attributes. Any attribute that's - # not already defined is invalid! - for (key, val) in attrs.items(): - if hasattr(self.metadata, "set_" + key): - getattr(self.metadata, "set_" + key)(val) - elif hasattr(self.metadata, key): - setattr(self.metadata, key, val) - elif hasattr(self, key): - setattr(self, key, val) - else: - msg = "Unknown distribution option: %s" % repr(key) - if warnings is not None: - warnings.warn(msg) - else: - sys.stderr.write(msg + "\n") - - # no-user-cfg is handled before other command line args - # because other args override the config files, and this - # one is needed before we can load the config files. - # If attrs['script_args'] wasn't passed, assume false. - # - # This also make sure we just look at the global options - self.want_user_cfg = True - - if self.script_args is not None: - for arg in self.script_args: - if not arg.startswith('-'): - break - if arg == '--no-user-cfg': - self.want_user_cfg = False - break - - self.finalize_options() - - def get_option_dict(self, command): - """Get the option dictionary for a given command. If that - command's option dictionary hasn't been created yet, then create it - and return the new dictionary; otherwise, return the existing - option dictionary. - """ - dict = self.command_options.get(command) - if dict is None: - dict = self.command_options[command] = {} - return dict - - def dump_option_dicts(self, header=None, commands=None, indent=""): - from pprint import pformat - - if commands is None: # dump all command option dicts - commands = self.command_options.keys() - commands.sort() - - if header is not None: - self.announce(indent + header) - indent = indent + " " - - if not commands: - self.announce(indent + "no commands known yet") - return - - for cmd_name in commands: - opt_dict = self.command_options.get(cmd_name) - if opt_dict is None: - self.announce(indent + - "no option dict for '%s' command" % cmd_name) - else: - self.announce(indent + - "option dict for '%s' command:" % cmd_name) - out = pformat(opt_dict) - for line in out.split('\n'): - self.announce(indent + " " + line) - - # -- Config file finding/parsing methods --------------------------- - - def find_config_files(self): - """Find as many configuration files as should be processed for this - platform, and return a list of filenames in the order in which they - should be parsed. The filenames returned are guaranteed to exist - (modulo nasty race conditions). - - There are three possible config files: distutils.cfg in the - Distutils installation directory (ie. where the top-level - Distutils __inst__.py file lives), a file in the user's home - directory named .pydistutils.cfg on Unix and pydistutils.cfg - on Windows/Mac; and setup.cfg in the current directory. - - The file in the user's home directory can be disabled with the - --no-user-cfg option. - """ - files = [] - check_environ() - - # Where to look for the system-wide Distutils config file - sys_dir = os.path.dirname(sys.modules['distutils'].__file__) - - # Look for the system config file - sys_file = os.path.join(sys_dir, "distutils.cfg") - if os.path.isfile(sys_file): - files.append(sys_file) - - # What to call the per-user config file - if os.name == 'posix': - user_filename = ".pydistutils.cfg" - else: - user_filename = "pydistutils.cfg" - - # And look for the user config file - if self.want_user_cfg: - user_file = os.path.join(os.path.expanduser('~'), user_filename) - if os.path.isfile(user_file): - files.append(user_file) - - # All platforms support local setup.cfg - local_file = "setup.cfg" - if os.path.isfile(local_file): - files.append(local_file) - - if DEBUG: - self.announce("using config files: %s" % ', '.join(files)) - - return files - - def parse_config_files(self, filenames=None): - from ConfigParser import ConfigParser - - if filenames is None: - filenames = self.find_config_files() - - if DEBUG: - self.announce("Distribution.parse_config_files():") - - parser = ConfigParser() - for filename in filenames: - if DEBUG: - self.announce(" reading %s" % filename) - parser.read(filename) - for section in parser.sections(): - options = parser.options(section) - opt_dict = self.get_option_dict(section) - - for opt in options: - if opt != '__name__': - val = parser.get(section,opt) - opt = opt.replace('-', '_') - opt_dict[opt] = (filename, val) - - # Make the ConfigParser forget everything (so we retain - # the original filenames that options come from) - parser.__init__() - - # If there was a "global" section in the config file, use it - # to set Distribution options. - - if 'global' in self.command_options: - for (opt, (src, val)) in self.command_options['global'].items(): - alias = self.negative_opt.get(opt) - try: - if alias: - setattr(self, alias, not strtobool(val)) - elif opt in ('verbose', 'dry_run'): # ugh! - setattr(self, opt, strtobool(val)) - else: - setattr(self, opt, val) - except ValueError, msg: - raise DistutilsOptionError, msg - - # -- Command-line parsing methods ---------------------------------- - - def parse_command_line(self): - """Parse the setup script's command line, taken from the - 'script_args' instance attribute (which defaults to 'sys.argv[1:]' - -- see 'setup()' in core.py). This list is first processed for - "global options" -- options that set attributes of the Distribution - instance. Then, it is alternately scanned for Distutils commands - and options for that command. Each new command terminates the - options for the previous command. The allowed options for a - command are determined by the 'user_options' attribute of the - command class -- thus, we have to be able to load command classes - in order to parse the command line. Any error in that 'options' - attribute raises DistutilsGetoptError; any error on the - command-line raises DistutilsArgError. If no Distutils commands - were found on the command line, raises DistutilsArgError. Return - true if command-line was successfully parsed and we should carry - on with executing commands; false if no errors but we shouldn't - execute commands (currently, this only happens if user asks for - help). - """ - # - # We now have enough information to show the Macintosh dialog - # that allows the user to interactively specify the "command line". - # - toplevel_options = self._get_toplevel_options() - - # We have to parse the command line a bit at a time -- global - # options, then the first command, then its options, and so on -- - # because each command will be handled by a different class, and - # the options that are valid for a particular class aren't known - # until we have loaded the command class, which doesn't happen - # until we know what the command is. - - self.commands = [] - parser = FancyGetopt(toplevel_options + self.display_options) - parser.set_negative_aliases(self.negative_opt) - parser.set_aliases({'licence': 'license'}) - args = parser.getopt(args=self.script_args, object=self) - option_order = parser.get_option_order() - log.set_verbosity(self.verbose) - - # for display options we return immediately - if self.handle_display_options(option_order): - return - while args: - args = self._parse_command_opts(parser, args) - if args is None: # user asked for help (and got it) - return - - # Handle the cases of --help as a "global" option, ie. - # "setup.py --help" and "setup.py --help command ...". For the - # former, we show global options (--verbose, --dry-run, etc.) - # and display-only options (--name, --version, etc.); for the - # latter, we omit the display-only options and show help for - # each command listed on the command line. - if self.help: - self._show_help(parser, - display_options=len(self.commands) == 0, - commands=self.commands) - return - - # Oops, no commands found -- an end-user error - if not self.commands: - raise DistutilsArgError, "no commands supplied" - - # All is well: return true - return 1 - - def _get_toplevel_options(self): - """Return the non-display options recognized at the top level. - - This includes options that are recognized *only* at the top - level as well as options recognized for commands. - """ - return self.global_options + [ - ("command-packages=", None, - "list of packages that provide distutils commands"), - ] - - def _parse_command_opts(self, parser, args): - """Parse the command-line options for a single command. - 'parser' must be a FancyGetopt instance; 'args' must be the list - of arguments, starting with the current command (whose options - we are about to parse). Returns a new version of 'args' with - the next command at the front of the list; will be the empty - list if there are no more commands on the command line. Returns - None if the user asked for help on this command. - """ - # late import because of mutual dependence between these modules - from distutils.cmd import Command - - # Pull the current command from the head of the command line - command = args[0] - if not command_re.match(command): - raise SystemExit, "invalid command name '%s'" % command - self.commands.append(command) - - # Dig up the command class that implements this command, so we - # 1) know that it's a valid command, and 2) know which options - # it takes. - try: - cmd_class = self.get_command_class(command) - except DistutilsModuleError, msg: - raise DistutilsArgError, msg - - # Require that the command class be derived from Command -- want - # to be sure that the basic "command" interface is implemented. - if not issubclass(cmd_class, Command): - raise DistutilsClassError, \ - "command class %s must subclass Command" % cmd_class - - # Also make sure that the command object provides a list of its - # known options. - if not (hasattr(cmd_class, 'user_options') and - isinstance(cmd_class.user_options, list)): - raise DistutilsClassError, \ - ("command class %s must provide " + - "'user_options' attribute (a list of tuples)") % \ - cmd_class - - # If the command class has a list of negative alias options, - # merge it in with the global negative aliases. - negative_opt = self.negative_opt - if hasattr(cmd_class, 'negative_opt'): - negative_opt = negative_opt.copy() - negative_opt.update(cmd_class.negative_opt) - - # Check for help_options in command class. They have a different - # format (tuple of four) so we need to preprocess them here. - if (hasattr(cmd_class, 'help_options') and - isinstance(cmd_class.help_options, list)): - help_options = fix_help_options(cmd_class.help_options) - else: - help_options = [] - - - # All commands support the global options too, just by adding - # in 'global_options'. - parser.set_option_table(self.global_options + - cmd_class.user_options + - help_options) - parser.set_negative_aliases(negative_opt) - (args, opts) = parser.getopt(args[1:]) - if hasattr(opts, 'help') and opts.help: - self._show_help(parser, display_options=0, commands=[cmd_class]) - return - - if (hasattr(cmd_class, 'help_options') and - isinstance(cmd_class.help_options, list)): - help_option_found=0 - for (help_option, short, desc, func) in cmd_class.help_options: - if hasattr(opts, parser.get_attr_name(help_option)): - help_option_found=1 - if hasattr(func, '__call__'): - func() - else: - raise DistutilsClassError( - "invalid help function %r for help option '%s': " - "must be a callable object (function, etc.)" - % (func, help_option)) - - if help_option_found: - return - - # Put the options from the command-line into their official - # holding pen, the 'command_options' dictionary. - opt_dict = self.get_option_dict(command) - for (name, value) in vars(opts).items(): - opt_dict[name] = ("command line", value) - - return args - - def finalize_options(self): - """Set final values for all the options on the Distribution - instance, analogous to the .finalize_options() method of Command - objects. - """ - for attr in ('keywords', 'platforms'): - value = getattr(self.metadata, attr) - if value is None: - continue - if isinstance(value, str): - value = [elm.strip() for elm in value.split(',')] - setattr(self.metadata, attr, value) - - def _show_help(self, parser, global_options=1, display_options=1, - commands=[]): - """Show help for the setup script command-line in the form of - several lists of command-line options. 'parser' should be a - FancyGetopt instance; do not expect it to be returned in the - same state, as its option table will be reset to make it - generate the correct help text. - - If 'global_options' is true, lists the global options: - --verbose, --dry-run, etc. If 'display_options' is true, lists - the "display-only" options: --name, --version, etc. Finally, - lists per-command help for every command name or command class - in 'commands'. - """ - # late import because of mutual dependence between these modules - from distutils.core import gen_usage - from distutils.cmd import Command - - if global_options: - if display_options: - options = self._get_toplevel_options() - else: - options = self.global_options - parser.set_option_table(options) - parser.print_help(self.common_usage + "\nGlobal options:") - print('') - - if display_options: - parser.set_option_table(self.display_options) - parser.print_help( - "Information display options (just display " + - "information, ignore any commands)") - print('') - - for command in self.commands: - if isinstance(command, type) and issubclass(command, Command): - klass = command - else: - klass = self.get_command_class(command) - if (hasattr(klass, 'help_options') and - isinstance(klass.help_options, list)): - parser.set_option_table(klass.user_options + - fix_help_options(klass.help_options)) - else: - parser.set_option_table(klass.user_options) - parser.print_help("Options for '%s' command:" % klass.__name__) - print('') - - print(gen_usage(self.script_name)) - - def handle_display_options(self, option_order): - """If there were any non-global "display-only" options - (--help-commands or the metadata display options) on the command - line, display the requested info and return true; else return - false. - """ - from distutils.core import gen_usage - - # User just wants a list of commands -- we'll print it out and stop - # processing now (ie. if they ran "setup --help-commands foo bar", - # we ignore "foo bar"). - if self.help_commands: - self.print_commands() - print('') - print(gen_usage(self.script_name)) - return 1 - - # If user supplied any of the "display metadata" options, then - # display that metadata in the order in which the user supplied the - # metadata options. - any_display_options = 0 - is_display_option = {} - for option in self.display_options: - is_display_option[option[0]] = 1 - - for (opt, val) in option_order: - if val and is_display_option.get(opt): - opt = translate_longopt(opt) - value = getattr(self.metadata, "get_"+opt)() - if opt in ['keywords', 'platforms']: - print(','.join(value)) - elif opt in ('classifiers', 'provides', 'requires', - 'obsoletes'): - print('\n'.join(value)) - else: - print(value) - any_display_options = 1 - - return any_display_options - - def print_command_list(self, commands, header, max_length): - """Print a subset of the list of all commands -- used by - 'print_commands()'. - """ - print(header + ":") - - for cmd in commands: - klass = self.cmdclass.get(cmd) - if not klass: - klass = self.get_command_class(cmd) - try: - description = klass.description - except AttributeError: - description = "(no description available)" - - print(" %-*s %s" % (max_length, cmd, description)) - - def print_commands(self): - """Print out a help message listing all available commands with a - description of each. The list is divided into "standard commands" - (listed in distutils.command.__all__) and "extra commands" - (mentioned in self.cmdclass, but not a standard command). The - descriptions come from the command class attribute - 'description'. - """ - import distutils.command - std_commands = distutils.command.__all__ - is_std = {} - for cmd in std_commands: - is_std[cmd] = 1 - - extra_commands = [] - for cmd in self.cmdclass.keys(): - if not is_std.get(cmd): - extra_commands.append(cmd) - - max_length = 0 - for cmd in (std_commands + extra_commands): - if len(cmd) > max_length: - max_length = len(cmd) - - self.print_command_list(std_commands, - "Standard commands", - max_length) - if extra_commands: - print - self.print_command_list(extra_commands, - "Extra commands", - max_length) - - def get_command_list(self): - """Get a list of (command, description) tuples. - The list is divided into "standard commands" (listed in - distutils.command.__all__) and "extra commands" (mentioned in - self.cmdclass, but not a standard command). The descriptions come - from the command class attribute 'description'. - """ - # Currently this is only used on Mac OS, for the Mac-only GUI - # Distutils interface (by Jack Jansen) - - import distutils.command - std_commands = distutils.command.__all__ - is_std = {} - for cmd in std_commands: - is_std[cmd] = 1 - - extra_commands = [] - for cmd in self.cmdclass.keys(): - if not is_std.get(cmd): - extra_commands.append(cmd) - - rv = [] - for cmd in (std_commands + extra_commands): - klass = self.cmdclass.get(cmd) - if not klass: - klass = self.get_command_class(cmd) - try: - description = klass.description - except AttributeError: - description = "(no description available)" - rv.append((cmd, description)) - return rv - - # -- Command class/object methods ---------------------------------- - - def get_command_packages(self): - """Return a list of packages from which commands are loaded.""" - pkgs = self.command_packages - if not isinstance(pkgs, list): - if pkgs is None: - pkgs = '' - pkgs = [pkg.strip() for pkg in pkgs.split(',') if pkg != ''] - if "distutils.command" not in pkgs: - pkgs.insert(0, "distutils.command") - self.command_packages = pkgs - return pkgs - - def get_command_class(self, command): - """Return the class that implements the Distutils command named by - 'command'. First we check the 'cmdclass' dictionary; if the - command is mentioned there, we fetch the class object from the - dictionary and return it. Otherwise we load the command module - ("distutils.command." + command) and fetch the command class from - the module. The loaded class is also stored in 'cmdclass' - to speed future calls to 'get_command_class()'. - - Raises DistutilsModuleError if the expected module could not be - found, or if that module does not define the expected class. - """ - klass = self.cmdclass.get(command) - if klass: - return klass - - for pkgname in self.get_command_packages(): - module_name = "%s.%s" % (pkgname, command) - klass_name = command - - try: - __import__ (module_name) - module = sys.modules[module_name] - except ImportError: - continue - - try: - klass = getattr(module, klass_name) - except AttributeError: - raise DistutilsModuleError, \ - "invalid command '%s' (no class '%s' in module '%s')" \ - % (command, klass_name, module_name) - - self.cmdclass[command] = klass - return klass - - raise DistutilsModuleError("invalid command '%s'" % command) - - - def get_command_obj(self, command, create=1): - """Return the command object for 'command'. Normally this object - is cached on a previous call to 'get_command_obj()'; if no command - object for 'command' is in the cache, then we either create and - return it (if 'create' is true) or return None. - """ - cmd_obj = self.command_obj.get(command) - if not cmd_obj and create: - if DEBUG: - self.announce("Distribution.get_command_obj(): " \ - "creating '%s' command object" % command) - - klass = self.get_command_class(command) - cmd_obj = self.command_obj[command] = klass(self) - self.have_run[command] = 0 - - # Set any options that were supplied in config files - # or on the command line. (NB. support for error - # reporting is lame here: any errors aren't reported - # until 'finalize_options()' is called, which means - # we won't report the source of the error.) - options = self.command_options.get(command) - if options: - self._set_command_options(cmd_obj, options) - - return cmd_obj - - def _set_command_options(self, command_obj, option_dict=None): - """Set the options for 'command_obj' from 'option_dict'. Basically - this means copying elements of a dictionary ('option_dict') to - attributes of an instance ('command'). - - 'command_obj' must be a Command instance. If 'option_dict' is not - supplied, uses the standard option dictionary for this command - (from 'self.command_options'). - """ - command_name = command_obj.get_command_name() - if option_dict is None: - option_dict = self.get_option_dict(command_name) - - if DEBUG: - self.announce(" setting options for '%s' command:" % command_name) - for (option, (source, value)) in option_dict.items(): - if DEBUG: - self.announce(" %s = %s (from %s)" % (option, value, - source)) - try: - bool_opts = map(translate_longopt, command_obj.boolean_options) - except AttributeError: - bool_opts = [] - try: - neg_opt = command_obj.negative_opt - except AttributeError: - neg_opt = {} - - try: - is_string = isinstance(value, str) - if option in neg_opt and is_string: - setattr(command_obj, neg_opt[option], not strtobool(value)) - elif option in bool_opts and is_string: - setattr(command_obj, option, strtobool(value)) - elif hasattr(command_obj, option): - setattr(command_obj, option, value) - else: - raise DistutilsOptionError, \ - ("error in %s: command '%s' has no such option '%s'" - % (source, command_name, option)) - except ValueError, msg: - raise DistutilsOptionError, msg - - def reinitialize_command(self, command, reinit_subcommands=0): - """Reinitializes a command to the state it was in when first - returned by 'get_command_obj()': ie., initialized but not yet - finalized. This provides the opportunity to sneak option - values in programmatically, overriding or supplementing - user-supplied values from the config files and command line. - You'll have to re-finalize the command object (by calling - 'finalize_options()' or 'ensure_finalized()') before using it for - real. - - 'command' should be a command name (string) or command object. If - 'reinit_subcommands' is true, also reinitializes the command's - sub-commands, as declared by the 'sub_commands' class attribute (if - it has one). See the "install" command for an example. Only - reinitializes the sub-commands that actually matter, ie. those - whose test predicates return true. - - Returns the reinitialized command object. - """ - from distutils.cmd import Command - if not isinstance(command, Command): - command_name = command - command = self.get_command_obj(command_name) - else: - command_name = command.get_command_name() - - if not command.finalized: - return command - command.initialize_options() - command.finalized = 0 - self.have_run[command_name] = 0 - self._set_command_options(command) - - if reinit_subcommands: - for sub in command.get_sub_commands(): - self.reinitialize_command(sub, reinit_subcommands) - - return command - - # -- Methods that operate on the Distribution ---------------------- - - def announce(self, msg, level=log.INFO): - log.log(level, msg) - - def run_commands(self): - """Run each command that was seen on the setup script command line. - Uses the list of commands found and cache of command objects - created by 'get_command_obj()'. - """ - for cmd in self.commands: - self.run_command(cmd) - - # -- Methods that operate on its Commands -------------------------- - - def run_command(self, command): - """Do whatever it takes to run a command (including nothing at all, - if the command has already been run). Specifically: if we have - already created and run the command named by 'command', return - silently without doing anything. If the command named by 'command' - doesn't even have a command object yet, create one. Then invoke - 'run()' on that command object (or an existing one). - """ - # Already been here, done that? then return silently. - if self.have_run.get(command): - return - - log.info("running %s", command) - cmd_obj = self.get_command_obj(command) - cmd_obj.ensure_finalized() - cmd_obj.run() - self.have_run[command] = 1 - - - # -- Distribution query methods ------------------------------------ - - def has_pure_modules(self): - return len(self.packages or self.py_modules or []) > 0 - - def has_ext_modules(self): - return self.ext_modules and len(self.ext_modules) > 0 - - def has_c_libraries(self): - return self.libraries and len(self.libraries) > 0 - - def has_modules(self): - return self.has_pure_modules() or self.has_ext_modules() - - def has_headers(self): - return self.headers and len(self.headers) > 0 - - def has_scripts(self): - return self.scripts and len(self.scripts) > 0 - - def has_data_files(self): - return self.data_files and len(self.data_files) > 0 - - def is_pure(self): - return (self.has_pure_modules() and - not self.has_ext_modules() and - not self.has_c_libraries()) - - # -- Metadata query methods ---------------------------------------- - - # If you're looking for 'get_name()', 'get_version()', and so forth, - # they are defined in a sneaky way: the constructor binds self.get_XXX - # to self.metadata.get_XXX. The actual code is in the - # DistributionMetadata class, below. - -class DistributionMetadata: - """Dummy class to hold the distribution meta-data: name, version, - author, and so forth. - """ - - _METHOD_BASENAMES = ("name", "version", "author", "author_email", - "maintainer", "maintainer_email", "url", - "license", "description", "long_description", - "keywords", "platforms", "fullname", "contact", - "contact_email", "license", "classifiers", - "download_url", - # PEP 314 - "provides", "requires", "obsoletes", - ) - - def __init__(self, path=None): - if path is not None: - self.read_pkg_file(open(path)) - else: - self.name = None - self.version = None - self.author = None - self.author_email = None - self.maintainer = None - self.maintainer_email = None - self.url = None - self.license = None - self.description = None - self.long_description = None - self.keywords = None - self.platforms = None - self.classifiers = None - self.download_url = None - # PEP 314 - self.provides = None - self.requires = None - self.obsoletes = None - - def read_pkg_file(self, file): - """Reads the metadata values from a file object.""" - msg = message_from_file(file) - - def _read_field(name): - value = msg[name] - if value == 'UNKNOWN': - return None - return value - - def _read_list(name): - values = msg.get_all(name, None) - if values == []: - return None - return values - - metadata_version = msg['metadata-version'] - self.name = _read_field('name') - self.version = _read_field('version') - self.description = _read_field('summary') - # we are filling author only. - self.author = _read_field('author') - self.maintainer = None - self.author_email = _read_field('author-email') - self.maintainer_email = None - self.url = _read_field('home-page') - self.license = _read_field('license') - - if 'download-url' in msg: - self.download_url = _read_field('download-url') - else: - self.download_url = None - - self.long_description = _read_field('description') - self.description = _read_field('summary') - - if 'keywords' in msg: - self.keywords = _read_field('keywords').split(',') - - self.platforms = _read_list('platform') - self.classifiers = _read_list('classifier') - - # PEP 314 - these fields only exist in 1.1 - if metadata_version == '1.1': - self.requires = _read_list('requires') - self.provides = _read_list('provides') - self.obsoletes = _read_list('obsoletes') - else: - self.requires = None - self.provides = None - self.obsoletes = None - - def write_pkg_info(self, base_dir): - """Write the PKG-INFO file into the release tree. - """ - pkg_info = open(os.path.join(base_dir, 'PKG-INFO'), 'w') - try: - self.write_pkg_file(pkg_info) - finally: - pkg_info.close() - - def write_pkg_file(self, file): - """Write the PKG-INFO format data to a file object. - """ - version = '1.0' - if (self.provides or self.requires or self.obsoletes or - self.classifiers or self.download_url): - version = '1.1' - - self._write_field(file, 'Metadata-Version', version) - self._write_field(file, 'Name', self.get_name()) - self._write_field(file, 'Version', self.get_version()) - self._write_field(file, 'Summary', self.get_description()) - self._write_field(file, 'Home-page', self.get_url()) - self._write_field(file, 'Author', self.get_contact()) - self._write_field(file, 'Author-email', self.get_contact_email()) - self._write_field(file, 'License', self.get_license()) - if self.download_url: - self._write_field(file, 'Download-URL', self.download_url) - - long_desc = rfc822_escape(self.get_long_description()) - self._write_field(file, 'Description', long_desc) - - keywords = ','.join(self.get_keywords()) - if keywords: - self._write_field(file, 'Keywords', keywords) - - self._write_list(file, 'Platform', self.get_platforms()) - self._write_list(file, 'Classifier', self.get_classifiers()) - - # PEP 314 - self._write_list(file, 'Requires', self.get_requires()) - self._write_list(file, 'Provides', self.get_provides()) - self._write_list(file, 'Obsoletes', self.get_obsoletes()) - - def _write_field(self, file, name, value): - file.write('%s: %s\n' % (name, self._encode_field(value))) - - def _write_list (self, file, name, values): - for value in values: - self._write_field(file, name, value) - - def _encode_field(self, value): - if value is None: - return None - if isinstance(value, unicode): - return value.encode(PKG_INFO_ENCODING) - return str(value) - - # -- Metadata query methods ---------------------------------------- - - def get_name(self): - return self.name or "UNKNOWN" - - def get_version(self): - return self.version or "0.0.0" - - def get_fullname(self): - return "%s-%s" % (self.get_name(), self.get_version()) - - def get_author(self): - return self._encode_field(self.author) or "UNKNOWN" - - def get_author_email(self): - return self.author_email or "UNKNOWN" - - def get_maintainer(self): - return self._encode_field(self.maintainer) or "UNKNOWN" - - def get_maintainer_email(self): - return self.maintainer_email or "UNKNOWN" - - def get_contact(self): - return (self._encode_field(self.maintainer) or - self._encode_field(self.author) or "UNKNOWN") - - def get_contact_email(self): - return self.maintainer_email or self.author_email or "UNKNOWN" - - def get_url(self): - return self.url or "UNKNOWN" - - def get_license(self): - return self.license or "UNKNOWN" - get_licence = get_license - - def get_description(self): - return self._encode_field(self.description) or "UNKNOWN" - - def get_long_description(self): - return self._encode_field(self.long_description) or "UNKNOWN" - - def get_keywords(self): - return self.keywords or [] - - def get_platforms(self): - return self.platforms or ["UNKNOWN"] - - def get_classifiers(self): - return self.classifiers or [] - - def get_download_url(self): - return self.download_url or "UNKNOWN" - - # PEP 314 - def get_requires(self): - return self.requires or [] - - def set_requires(self, value): - import distutils.versionpredicate - for v in value: - distutils.versionpredicate.VersionPredicate(v) - self.requires = value - - def get_provides(self): - return self.provides or [] - - def set_provides(self, value): - value = [v.strip() for v in value] - for v in value: - import distutils.versionpredicate - distutils.versionpredicate.split_provision(v) - self.provides = value - - def get_obsoletes(self): - return self.obsoletes or [] - - def set_obsoletes(self, value): - import distutils.versionpredicate - for v in value: - distutils.versionpredicate.VersionPredicate(v) - self.obsoletes = value - -def fix_help_options(options): - """Convert a 4-tuple 'help_options' list as found in various command - classes to the 3-tuple form required by FancyGetopt. - """ - new_options = [] - for help_tuple in options: - new_options.append(help_tuple[0:3]) - return new_options diff --git a/PythonLib/extra/distutils/emxccompiler.py b/PythonLib/extra/distutils/emxccompiler.py deleted file mode 100644 index a0172058..00000000 --- a/PythonLib/extra/distutils/emxccompiler.py +++ /dev/null @@ -1,319 +0,0 @@ -"""distutils.emxccompiler - -Provides the EMXCCompiler class, a subclass of UnixCCompiler that -handles the EMX port of the GNU C compiler to OS/2. -""" - -# issues: -# -# * OS/2 insists that DLLs can have names no longer than 8 characters -# We put export_symbols in a def-file, as though the DLL can have -# an arbitrary length name, but truncate the output filename. -# -# * only use OMF objects and use LINK386 as the linker (-Zomf) -# -# * always build for multithreading (-Zmt) as the accompanying OS/2 port -# of Python is only distributed with threads enabled. -# -# tested configurations: -# -# * EMX gcc 2.81/EMX 0.9d fix03 - -__revision__ = "$Id$" - -import os,sys,copy -from distutils.ccompiler import gen_preprocess_options, gen_lib_options -from distutils.unixccompiler import UnixCCompiler -from distutils.file_util import write_file -from distutils.errors import DistutilsExecError, CompileError, UnknownFileError -from distutils import log - -class EMXCCompiler (UnixCCompiler): - - compiler_type = 'emx' - obj_extension = ".obj" - static_lib_extension = ".lib" - shared_lib_extension = ".dll" - static_lib_format = "%s%s" - shared_lib_format = "%s%s" - res_extension = ".res" # compiled resource file - exe_extension = ".exe" - - def __init__ (self, - verbose=0, - dry_run=0, - force=0): - - UnixCCompiler.__init__ (self, verbose, dry_run, force) - - (status, details) = check_config_h() - self.debug_print("Python's GCC status: %s (details: %s)" % - (status, details)) - if status is not CONFIG_H_OK: - self.warn( - "Python's pyconfig.h doesn't seem to support your compiler. " + - ("Reason: %s." % details) + - "Compiling may fail because of undefined preprocessor macros.") - - (self.gcc_version, self.ld_version) = \ - get_versions() - self.debug_print(self.compiler_type + ": gcc %s, ld %s\n" % - (self.gcc_version, - self.ld_version) ) - - # Hard-code GCC because that's what this is all about. - # XXX optimization, warnings etc. should be customizable. - self.set_executables(compiler='gcc -Zomf -Zmt -O3 -fomit-frame-pointer -mprobe -Wall', - compiler_so='gcc -Zomf -Zmt -O3 -fomit-frame-pointer -mprobe -Wall', - linker_exe='gcc -Zomf -Zmt -Zcrtdll', - linker_so='gcc -Zomf -Zmt -Zcrtdll -Zdll') - - # want the gcc library statically linked (so that we don't have - # to distribute a version dependent on the compiler we have) - self.dll_libraries=["gcc"] - - # __init__ () - - def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts): - if ext == '.rc': - # gcc requires '.rc' compiled to binary ('.res') files !!! - try: - self.spawn(["rc", "-r", src]) - except DistutilsExecError, msg: - raise CompileError, msg - else: # for other files use the C-compiler - try: - self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + - extra_postargs) - except DistutilsExecError, msg: - raise CompileError, msg - - def link (self, - target_desc, - objects, - output_filename, - output_dir=None, - libraries=None, - library_dirs=None, - runtime_library_dirs=None, - export_symbols=None, - debug=0, - extra_preargs=None, - extra_postargs=None, - build_temp=None, - target_lang=None): - - # use separate copies, so we can modify the lists - extra_preargs = copy.copy(extra_preargs or []) - libraries = copy.copy(libraries or []) - objects = copy.copy(objects or []) - - # Additional libraries - libraries.extend(self.dll_libraries) - - # handle export symbols by creating a def-file - # with executables this only works with gcc/ld as linker - if ((export_symbols is not None) and - (target_desc != self.EXECUTABLE)): - # (The linker doesn't do anything if output is up-to-date. - # So it would probably better to check if we really need this, - # but for this we had to insert some unchanged parts of - # UnixCCompiler, and this is not what we want.) - - # we want to put some files in the same directory as the - # object files are, build_temp doesn't help much - # where are the object files - temp_dir = os.path.dirname(objects[0]) - # name of dll to give the helper files the same base name - (dll_name, dll_extension) = os.path.splitext( - os.path.basename(output_filename)) - - # generate the filenames for these files - def_file = os.path.join(temp_dir, dll_name + ".def") - - # Generate .def file - contents = [ - "LIBRARY %s INITINSTANCE TERMINSTANCE" % \ - os.path.splitext(os.path.basename(output_filename))[0], - "DATA MULTIPLE NONSHARED", - "EXPORTS"] - for sym in export_symbols: - contents.append(' "%s"' % sym) - self.execute(write_file, (def_file, contents), - "writing %s" % def_file) - - # next add options for def-file and to creating import libraries - # for gcc/ld the def-file is specified as any other object files - objects.append(def_file) - - #end: if ((export_symbols is not None) and - # (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")): - - # who wants symbols and a many times larger output file - # should explicitly switch the debug mode on - # otherwise we let dllwrap/ld strip the output file - # (On my machine: 10KB < stripped_file < ??100KB - # unstripped_file = stripped_file + XXX KB - # ( XXX=254 for a typical python extension)) - if not debug: - extra_preargs.append("-s") - - UnixCCompiler.link(self, - target_desc, - objects, - output_filename, - output_dir, - libraries, - library_dirs, - runtime_library_dirs, - None, # export_symbols, we do this in our def-file - debug, - extra_preargs, - extra_postargs, - build_temp, - target_lang) - - # link () - - # -- Miscellaneous methods ----------------------------------------- - - # override the object_filenames method from CCompiler to - # support rc and res-files - def object_filenames (self, - source_filenames, - strip_dir=0, - output_dir=''): - if output_dir is None: output_dir = '' - obj_names = [] - for src_name in source_filenames: - # use normcase to make sure '.rc' is really '.rc' and not '.RC' - (base, ext) = os.path.splitext (os.path.normcase(src_name)) - if ext not in (self.src_extensions + ['.rc']): - raise UnknownFileError, \ - "unknown file type '%s' (from '%s')" % \ - (ext, src_name) - if strip_dir: - base = os.path.basename (base) - if ext == '.rc': - # these need to be compiled to object files - obj_names.append (os.path.join (output_dir, - base + self.res_extension)) - else: - obj_names.append (os.path.join (output_dir, - base + self.obj_extension)) - return obj_names - - # object_filenames () - - # override the find_library_file method from UnixCCompiler - # to deal with file naming/searching differences - def find_library_file(self, dirs, lib, debug=0): - shortlib = '%s.lib' % lib - longlib = 'lib%s.lib' % lib # this form very rare - - # get EMX's default library directory search path - try: - emx_dirs = os.environ['LIBRARY_PATH'].split(';') - except KeyError: - emx_dirs = [] - - for dir in dirs + emx_dirs: - shortlibp = os.path.join(dir, shortlib) - longlibp = os.path.join(dir, longlib) - if os.path.exists(shortlibp): - return shortlibp - elif os.path.exists(longlibp): - return longlibp - - # Oops, didn't find it in *any* of 'dirs' - return None - -# class EMXCCompiler - - -# Because these compilers aren't configured in Python's pyconfig.h file by -# default, we should at least warn the user if he is using a unmodified -# version. - -CONFIG_H_OK = "ok" -CONFIG_H_NOTOK = "not ok" -CONFIG_H_UNCERTAIN = "uncertain" - -def check_config_h(): - - """Check if the current Python installation (specifically, pyconfig.h) - appears amenable to building extensions with GCC. Returns a tuple - (status, details), where 'status' is one of the following constants: - CONFIG_H_OK - all is well, go ahead and compile - CONFIG_H_NOTOK - doesn't look good - CONFIG_H_UNCERTAIN - not sure -- unable to read pyconfig.h - 'details' is a human-readable string explaining the situation. - - Note there are two ways to conclude "OK": either 'sys.version' contains - the string "GCC" (implying that this Python was built with GCC), or the - installed "pyconfig.h" contains the string "__GNUC__". - """ - - # XXX since this function also checks sys.version, it's not strictly a - # "pyconfig.h" check -- should probably be renamed... - - from distutils import sysconfig - import string - # if sys.version contains GCC then python was compiled with - # GCC, and the pyconfig.h file should be OK - if string.find(sys.version,"GCC") >= 0: - return (CONFIG_H_OK, "sys.version mentions 'GCC'") - - fn = sysconfig.get_config_h_filename() - try: - # It would probably better to read single lines to search. - # But we do this only once, and it is fast enough - f = open(fn) - try: - s = f.read() - finally: - f.close() - - except IOError, exc: - # if we can't read this file, we cannot say it is wrong - # the compiler will complain later about this file as missing - return (CONFIG_H_UNCERTAIN, - "couldn't read '%s': %s" % (fn, exc.strerror)) - - else: - # "pyconfig.h" contains an "#ifdef __GNUC__" or something similar - if string.find(s,"__GNUC__") >= 0: - return (CONFIG_H_OK, "'%s' mentions '__GNUC__'" % fn) - else: - return (CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn) - - -def get_versions(): - """ Try to find out the versions of gcc and ld. - If not possible it returns None for it. - """ - from distutils.version import StrictVersion - from distutils.spawn import find_executable - import re - - gcc_exe = find_executable('gcc') - if gcc_exe: - out = os.popen(gcc_exe + ' -dumpversion','r') - try: - out_string = out.read() - finally: - out.close() - result = re.search('(\d+\.\d+\.\d+)',out_string) - if result: - gcc_version = StrictVersion(result.group(1)) - else: - gcc_version = None - else: - gcc_version = None - # EMX ld has no way of reporting version number, and we use GCC - # anyway - so we can link OMF DLLs - ld_version = None - return (gcc_version, ld_version) diff --git a/PythonLib/extra/distutils/errors.py b/PythonLib/extra/distutils/errors.py deleted file mode 100644 index d9c47c76..00000000 --- a/PythonLib/extra/distutils/errors.py +++ /dev/null @@ -1,88 +0,0 @@ -"""distutils.errors - -Provides exceptions used by the Distutils modules. Note that Distutils -modules may raise standard exceptions; in particular, SystemExit is -usually raised for errors that are obviously the end-user's fault -(eg. bad command-line arguments). - -This module is safe to use in "from ... import *" mode; it only exports -symbols whose names start with "Distutils" and end with "Error".""" - -__revision__ = "$Id$" - -class DistutilsError(Exception): - """The root of all Distutils evil.""" - -class DistutilsModuleError(DistutilsError): - """Unable to load an expected module, or to find an expected class - within some module (in particular, command modules and classes).""" - -class DistutilsClassError(DistutilsError): - """Some command class (or possibly distribution class, if anyone - feels a need to subclass Distribution) is found not to be holding - up its end of the bargain, ie. implementing some part of the - "command "interface.""" - -class DistutilsGetoptError(DistutilsError): - """The option table provided to 'fancy_getopt()' is bogus.""" - -class DistutilsArgError(DistutilsError): - """Raised by fancy_getopt in response to getopt.error -- ie. an - error in the command line usage.""" - -class DistutilsFileError(DistutilsError): - """Any problems in the filesystem: expected file not found, etc. - Typically this is for problems that we detect before IOError or - OSError could be raised.""" - -class DistutilsOptionError(DistutilsError): - """Syntactic/semantic errors in command options, such as use of - mutually conflicting options, or inconsistent options, - badly-spelled values, etc. No distinction is made between option - values originating in the setup script, the command line, config - files, or what-have-you -- but if we *know* something originated in - the setup script, we'll raise DistutilsSetupError instead.""" - -class DistutilsSetupError(DistutilsError): - """For errors that can be definitely blamed on the setup script, - such as invalid keyword arguments to 'setup()'.""" - -class DistutilsPlatformError(DistutilsError): - """We don't know how to do something on the current platform (but - we do know how to do it on some platform) -- eg. trying to compile - C files on a platform not supported by a CCompiler subclass.""" - -class DistutilsExecError(DistutilsError): - """Any problems executing an external program (such as the C - compiler, when compiling C files).""" - -class DistutilsInternalError(DistutilsError): - """Internal inconsistencies or impossibilities (obviously, this - should never be seen if the code is working!).""" - -class DistutilsTemplateError(DistutilsError): - """Syntax error in a file list template.""" - -class DistutilsByteCompileError(DistutilsError): - """Byte compile error.""" - -# Exception classes used by the CCompiler implementation classes -class CCompilerError(Exception): - """Some compile/link operation failed.""" - -class PreprocessError(CCompilerError): - """Failure to preprocess one or more C/C++ files.""" - -class CompileError(CCompilerError): - """Failure to compile one or more C/C++ source files.""" - -class LibError(CCompilerError): - """Failure to create a static library from one or more C/C++ object - files.""" - -class LinkError(CCompilerError): - """Failure to link one or more C/C++ object files into an executable - or shared library file.""" - -class UnknownFileError(CCompilerError): - """Attempt to process an unknown file type.""" diff --git a/PythonLib/extra/distutils/extension.py b/PythonLib/extra/distutils/extension.py deleted file mode 100644 index 9a67ca8b..00000000 --- a/PythonLib/extra/distutils/extension.py +++ /dev/null @@ -1,255 +0,0 @@ -"""distutils.extension - -Provides the Extension class, used to describe C/C++ extension -modules in setup scripts.""" - -__revision__ = "$Id$" - -import os, string, sys -from types import * - -try: - import warnings -except ImportError: - warnings = None - -# This class is really only used by the "build_ext" command, so it might -# make sense to put it in distutils.command.build_ext. However, that -# module is already big enough, and I want to make this class a bit more -# complex to simplify some common cases ("foo" module in "foo.c") and do -# better error-checking ("foo.c" actually exists). -# -# Also, putting this in build_ext.py means every setup script would have to -# import that large-ish module (indirectly, through distutils.core) in -# order to do anything. - -class Extension: - """Just a collection of attributes that describes an extension - module and everything needed to build it (hopefully in a portable - way, but there are hooks that let you be as unportable as you need). - - Instance attributes: - name : string - the full name of the extension, including any packages -- ie. - *not* a filename or pathname, but Python dotted name - sources : [string] - list of source filenames, relative to the distribution root - (where the setup script lives), in Unix form (slash-separated) - for portability. Source files may be C, C++, SWIG (.i), - platform-specific resource files, or whatever else is recognized - by the "build_ext" command as source for a Python extension. - include_dirs : [string] - list of directories to search for C/C++ header files (in Unix - form for portability) - define_macros : [(name : string, value : string|None)] - list of macros to define; each macro is defined using a 2-tuple, - where 'value' is either the string to define it to or None to - define it without a particular value (equivalent of "#define - FOO" in source or -DFOO on Unix C compiler command line) - undef_macros : [string] - list of macros to undefine explicitly - library_dirs : [string] - list of directories to search for C/C++ libraries at link time - libraries : [string] - list of library names (not filenames or paths) to link against - runtime_library_dirs : [string] - list of directories to search for C/C++ libraries at run time - (for shared extensions, this is when the extension is loaded) - extra_objects : [string] - list of extra files to link with (eg. object files not implied - by 'sources', static library that must be explicitly specified, - binary resource files, etc.) - extra_compile_args : [string] - any extra platform- and compiler-specific information to use - when compiling the source files in 'sources'. For platforms and - compilers where "command line" makes sense, this is typically a - list of command-line arguments, but for other platforms it could - be anything. - extra_link_args : [string] - any extra platform- and compiler-specific information to use - when linking object files together to create the extension (or - to create a new static Python interpreter). Similar - interpretation as for 'extra_compile_args'. - export_symbols : [string] - list of symbols to be exported from a shared extension. Not - used on all platforms, and not generally necessary for Python - extensions, which typically export exactly one symbol: "init" + - extension_name. - swig_opts : [string] - any extra options to pass to SWIG if a source file has the .i - extension. - depends : [string] - list of files that the extension depends on - language : string - extension language (i.e. "c", "c++", "objc"). Will be detected - from the source extensions if not provided. - """ - - # When adding arguments to this constructor, be sure to update - # setup_keywords in core.py. - def __init__ (self, name, sources, - include_dirs=None, - define_macros=None, - undef_macros=None, - library_dirs=None, - libraries=None, - runtime_library_dirs=None, - extra_objects=None, - extra_compile_args=None, - extra_link_args=None, - export_symbols=None, - swig_opts = None, - depends=None, - language=None, - **kw # To catch unknown keywords - ): - assert type(name) is StringType, "'name' must be a string" - assert (type(sources) is ListType and - map(type, sources) == [StringType]*len(sources)), \ - "'sources' must be a list of strings" - - self.name = name - self.sources = sources - self.include_dirs = include_dirs or [] - self.define_macros = define_macros or [] - self.undef_macros = undef_macros or [] - self.library_dirs = library_dirs or [] - self.libraries = libraries or [] - self.runtime_library_dirs = runtime_library_dirs or [] - self.extra_objects = extra_objects or [] - self.extra_compile_args = extra_compile_args or [] - self.extra_link_args = extra_link_args or [] - self.export_symbols = export_symbols or [] - self.swig_opts = swig_opts or [] - self.depends = depends or [] - self.language = language - - # If there are unknown keyword options, warn about them - if len(kw): - L = kw.keys() ; L.sort() - L = map(repr, L) - msg = "Unknown Extension options: " + string.join(L, ', ') - if warnings is not None: - warnings.warn(msg) - else: - sys.stderr.write(msg + '\n') -# class Extension - - -def read_setup_file (filename): - from distutils.sysconfig import \ - parse_makefile, expand_makefile_vars, _variable_rx - from distutils.text_file import TextFile - from distutils.util import split_quoted - - # First pass over the file to gather "VAR = VALUE" assignments. - vars = parse_makefile(filename) - - # Second pass to gobble up the real content: lines of the form - # ... [ ...] [ ...] [ ...] - file = TextFile(filename, - strip_comments=1, skip_blanks=1, join_lines=1, - lstrip_ws=1, rstrip_ws=1) - try: - extensions = [] - - while 1: - line = file.readline() - if line is None: # eof - break - if _variable_rx.match(line): # VAR=VALUE, handled in first pass - continue - - if line[0] == line[-1] == "*": - file.warn("'%s' lines not handled yet" % line) - continue - - #print "original line: " + line - line = expand_makefile_vars(line, vars) - words = split_quoted(line) - #print "expanded line: " + line - - # NB. this parses a slightly different syntax than the old - # makesetup script: here, there must be exactly one extension per - # line, and it must be the first word of the line. I have no idea - # why the old syntax supported multiple extensions per line, as - # they all wind up being the same. - - module = words[0] - ext = Extension(module, []) - append_next_word = None - - for word in words[1:]: - if append_next_word is not None: - append_next_word.append(word) - append_next_word = None - continue - - suffix = os.path.splitext(word)[1] - switch = word[0:2] ; value = word[2:] - - if suffix in (".c", ".cc", ".cpp", ".cxx", ".c++", ".m", ".mm"): - # hmm, should we do something about C vs. C++ sources? - # or leave it up to the CCompiler implementation to - # worry about? - ext.sources.append(word) - elif switch == "-I": - ext.include_dirs.append(value) - elif switch == "-D": - equals = string.find(value, "=") - if equals == -1: # bare "-DFOO" -- no value - ext.define_macros.append((value, None)) - else: # "-DFOO=blah" - ext.define_macros.append((value[0:equals], - value[equals+2:])) - elif switch == "-U": - ext.undef_macros.append(value) - elif switch == "-C": # only here 'cause makesetup has it! - ext.extra_compile_args.append(word) - elif switch == "-l": - ext.libraries.append(value) - elif switch == "-L": - ext.library_dirs.append(value) - elif switch == "-R": - ext.runtime_library_dirs.append(value) - elif word == "-rpath": - append_next_word = ext.runtime_library_dirs - elif word == "-Xlinker": - append_next_word = ext.extra_link_args - elif word == "-Xcompiler": - append_next_word = ext.extra_compile_args - elif switch == "-u": - ext.extra_link_args.append(word) - if not value: - append_next_word = ext.extra_link_args - elif word == "-Xcompiler": - append_next_word = ext.extra_compile_args - elif switch == "-u": - ext.extra_link_args.append(word) - if not value: - append_next_word = ext.extra_link_args - elif suffix in (".a", ".so", ".sl", ".o", ".dylib"): - # NB. a really faithful emulation of makesetup would - # append a .o file to extra_objects only if it - # had a slash in it; otherwise, it would s/.o/.c/ - # and append it to sources. Hmmmm. - ext.extra_objects.append(word) - else: - file.warn("unrecognized argument '%s'" % word) - - extensions.append(ext) - finally: - file.close() - - #print "module:", module - #print "source files:", source_files - #print "cpp args:", cpp_args - #print "lib args:", library_args - - #extensions[module] = { 'sources': source_files, - # 'cpp_args': cpp_args, - # 'lib_args': library_args } - - return extensions - -# read_setup_file () diff --git a/PythonLib/extra/distutils/fancy_getopt.py b/PythonLib/extra/distutils/fancy_getopt.py deleted file mode 100644 index 2dea9480..00000000 --- a/PythonLib/extra/distutils/fancy_getopt.py +++ /dev/null @@ -1,484 +0,0 @@ -"""distutils.fancy_getopt - -Wrapper around the standard getopt module that provides the following -additional features: - * short and long options are tied together - * options have help strings, so fancy_getopt could potentially - create a complete usage summary - * options set attributes of a passed-in object -""" - -__revision__ = "$Id$" - -import sys -import string -import re -import getopt -from distutils.errors import DistutilsGetoptError, DistutilsArgError - -# Much like command_re in distutils.core, this is close to but not quite -# the same as a Python NAME -- except, in the spirit of most GNU -# utilities, we use '-' in place of '_'. (The spirit of LISP lives on!) -# The similarities to NAME are again not a coincidence... -longopt_pat = r'[a-zA-Z](?:[a-zA-Z0-9-]*)' -longopt_re = re.compile(r'^%s$' % longopt_pat) - -# For recognizing "negative alias" options, eg. "quiet=!verbose" -neg_alias_re = re.compile("^(%s)=!(%s)$" % (longopt_pat, longopt_pat)) - -# This is used to translate long options to legitimate Python identifiers -# (for use as attributes of some object). -longopt_xlate = string.maketrans('-', '_') - -class FancyGetopt: - """Wrapper around the standard 'getopt()' module that provides some - handy extra functionality: - * short and long options are tied together - * options have help strings, and help text can be assembled - from them - * options set attributes of a passed-in object - * boolean options can have "negative aliases" -- eg. if - --quiet is the "negative alias" of --verbose, then "--quiet" - on the command line sets 'verbose' to false - """ - - def __init__ (self, option_table=None): - - # The option table is (currently) a list of tuples. The - # tuples may have 3 or four values: - # (long_option, short_option, help_string [, repeatable]) - # if an option takes an argument, its long_option should have '=' - # appended; short_option should just be a single character, no ':' - # in any case. If a long_option doesn't have a corresponding - # short_option, short_option should be None. All option tuples - # must have long options. - self.option_table = option_table - - # 'option_index' maps long option names to entries in the option - # table (ie. those 3-tuples). - self.option_index = {} - if self.option_table: - self._build_index() - - # 'alias' records (duh) alias options; {'foo': 'bar'} means - # --foo is an alias for --bar - self.alias = {} - - # 'negative_alias' keeps track of options that are the boolean - # opposite of some other option - self.negative_alias = {} - - # These keep track of the information in the option table. We - # don't actually populate these structures until we're ready to - # parse the command-line, since the 'option_table' passed in here - # isn't necessarily the final word. - self.short_opts = [] - self.long_opts = [] - self.short2long = {} - self.attr_name = {} - self.takes_arg = {} - - # And 'option_order' is filled up in 'getopt()'; it records the - # original order of options (and their values) on the command-line, - # but expands short options, converts aliases, etc. - self.option_order = [] - - # __init__ () - - - def _build_index (self): - self.option_index.clear() - for option in self.option_table: - self.option_index[option[0]] = option - - def set_option_table (self, option_table): - self.option_table = option_table - self._build_index() - - def add_option (self, long_option, short_option=None, help_string=None): - if long_option in self.option_index: - raise DistutilsGetoptError, \ - "option conflict: already an option '%s'" % long_option - else: - option = (long_option, short_option, help_string) - self.option_table.append(option) - self.option_index[long_option] = option - - - def has_option (self, long_option): - """Return true if the option table for this parser has an - option with long name 'long_option'.""" - return long_option in self.option_index - - def get_attr_name (self, long_option): - """Translate long option name 'long_option' to the form it - has as an attribute of some object: ie., translate hyphens - to underscores.""" - return string.translate(long_option, longopt_xlate) - - - def _check_alias_dict (self, aliases, what): - assert isinstance(aliases, dict) - for (alias, opt) in aliases.items(): - if alias not in self.option_index: - raise DistutilsGetoptError, \ - ("invalid %s '%s': " - "option '%s' not defined") % (what, alias, alias) - if opt not in self.option_index: - raise DistutilsGetoptError, \ - ("invalid %s '%s': " - "aliased option '%s' not defined") % (what, alias, opt) - - def set_aliases (self, alias): - """Set the aliases for this option parser.""" - self._check_alias_dict(alias, "alias") - self.alias = alias - - def set_negative_aliases (self, negative_alias): - """Set the negative aliases for this option parser. - 'negative_alias' should be a dictionary mapping option names to - option names, both the key and value must already be defined - in the option table.""" - self._check_alias_dict(negative_alias, "negative alias") - self.negative_alias = negative_alias - - - def _grok_option_table (self): - """Populate the various data structures that keep tabs on the - option table. Called by 'getopt()' before it can do anything - worthwhile. - """ - self.long_opts = [] - self.short_opts = [] - self.short2long.clear() - self.repeat = {} - - for option in self.option_table: - if len(option) == 3: - long, short, help = option - repeat = 0 - elif len(option) == 4: - long, short, help, repeat = option - else: - # the option table is part of the code, so simply - # assert that it is correct - raise ValueError, "invalid option tuple: %r" % (option,) - - # Type- and value-check the option names - if not isinstance(long, str) or len(long) < 2: - raise DistutilsGetoptError, \ - ("invalid long option '%s': " - "must be a string of length >= 2") % long - - if (not ((short is None) or - (isinstance(short, str) and len(short) == 1))): - raise DistutilsGetoptError, \ - ("invalid short option '%s': " - "must a single character or None") % short - - self.repeat[long] = repeat - self.long_opts.append(long) - - if long[-1] == '=': # option takes an argument? - if short: short = short + ':' - long = long[0:-1] - self.takes_arg[long] = 1 - else: - - # Is option is a "negative alias" for some other option (eg. - # "quiet" == "!verbose")? - alias_to = self.negative_alias.get(long) - if alias_to is not None: - if self.takes_arg[alias_to]: - raise DistutilsGetoptError, \ - ("invalid negative alias '%s': " - "aliased option '%s' takes a value") % \ - (long, alias_to) - - self.long_opts[-1] = long # XXX redundant?! - self.takes_arg[long] = 0 - - else: - self.takes_arg[long] = 0 - - # If this is an alias option, make sure its "takes arg" flag is - # the same as the option it's aliased to. - alias_to = self.alias.get(long) - if alias_to is not None: - if self.takes_arg[long] != self.takes_arg[alias_to]: - raise DistutilsGetoptError, \ - ("invalid alias '%s': inconsistent with " - "aliased option '%s' (one of them takes a value, " - "the other doesn't") % (long, alias_to) - - - # Now enforce some bondage on the long option name, so we can - # later translate it to an attribute name on some object. Have - # to do this a bit late to make sure we've removed any trailing - # '='. - if not longopt_re.match(long): - raise DistutilsGetoptError, \ - ("invalid long option name '%s' " + - "(must be letters, numbers, hyphens only") % long - - self.attr_name[long] = self.get_attr_name(long) - if short: - self.short_opts.append(short) - self.short2long[short[0]] = long - - # for option_table - - # _grok_option_table() - - - def getopt (self, args=None, object=None): - """Parse command-line options in args. Store as attributes on object. - - If 'args' is None or not supplied, uses 'sys.argv[1:]'. If - 'object' is None or not supplied, creates a new OptionDummy - object, stores option values there, and returns a tuple (args, - object). If 'object' is supplied, it is modified in place and - 'getopt()' just returns 'args'; in both cases, the returned - 'args' is a modified copy of the passed-in 'args' list, which - is left untouched. - """ - if args is None: - args = sys.argv[1:] - if object is None: - object = OptionDummy() - created_object = 1 - else: - created_object = 0 - - self._grok_option_table() - - short_opts = string.join(self.short_opts) - try: - opts, args = getopt.getopt(args, short_opts, self.long_opts) - except getopt.error, msg: - raise DistutilsArgError, msg - - for opt, val in opts: - if len(opt) == 2 and opt[0] == '-': # it's a short option - opt = self.short2long[opt[1]] - else: - assert len(opt) > 2 and opt[:2] == '--' - opt = opt[2:] - - alias = self.alias.get(opt) - if alias: - opt = alias - - if not self.takes_arg[opt]: # boolean option? - assert val == '', "boolean option can't have value" - alias = self.negative_alias.get(opt) - if alias: - opt = alias - val = 0 - else: - val = 1 - - attr = self.attr_name[opt] - # The only repeating option at the moment is 'verbose'. - # It has a negative option -q quiet, which should set verbose = 0. - if val and self.repeat.get(attr) is not None: - val = getattr(object, attr, 0) + 1 - setattr(object, attr, val) - self.option_order.append((opt, val)) - - # for opts - if created_object: - return args, object - else: - return args - - # getopt() - - - def get_option_order (self): - """Returns the list of (option, value) tuples processed by the - previous run of 'getopt()'. Raises RuntimeError if - 'getopt()' hasn't been called yet. - """ - if self.option_order is None: - raise RuntimeError, "'getopt()' hasn't been called yet" - else: - return self.option_order - - - def generate_help (self, header=None): - """Generate help text (a list of strings, one per suggested line of - output) from the option table for this FancyGetopt object. - """ - # Blithely assume the option table is good: probably wouldn't call - # 'generate_help()' unless you've already called 'getopt()'. - - # First pass: determine maximum length of long option names - max_opt = 0 - for option in self.option_table: - long = option[0] - short = option[1] - l = len(long) - if long[-1] == '=': - l = l - 1 - if short is not None: - l = l + 5 # " (-x)" where short == 'x' - if l > max_opt: - max_opt = l - - opt_width = max_opt + 2 + 2 + 2 # room for indent + dashes + gutter - - # Typical help block looks like this: - # --foo controls foonabulation - # Help block for longest option looks like this: - # --flimflam set the flim-flam level - # and with wrapped text: - # --flimflam set the flim-flam level (must be between - # 0 and 100, except on Tuesdays) - # Options with short names will have the short name shown (but - # it doesn't contribute to max_opt): - # --foo (-f) controls foonabulation - # If adding the short option would make the left column too wide, - # we push the explanation off to the next line - # --flimflam (-l) - # set the flim-flam level - # Important parameters: - # - 2 spaces before option block start lines - # - 2 dashes for each long option name - # - min. 2 spaces between option and explanation (gutter) - # - 5 characters (incl. space) for short option name - - # Now generate lines of help text. (If 80 columns were good enough - # for Jesus, then 78 columns are good enough for me!) - line_width = 78 - text_width = line_width - opt_width - big_indent = ' ' * opt_width - if header: - lines = [header] - else: - lines = ['Option summary:'] - - for option in self.option_table: - long, short, help = option[:3] - text = wrap_text(help, text_width) - if long[-1] == '=': - long = long[0:-1] - - # Case 1: no short option at all (makes life easy) - if short is None: - if text: - lines.append(" --%-*s %s" % (max_opt, long, text[0])) - else: - lines.append(" --%-*s " % (max_opt, long)) - - # Case 2: we have a short option, so we have to include it - # just after the long option - else: - opt_names = "%s (-%s)" % (long, short) - if text: - lines.append(" --%-*s %s" % - (max_opt, opt_names, text[0])) - else: - lines.append(" --%-*s" % opt_names) - - for l in text[1:]: - lines.append(big_indent + l) - - # for self.option_table - - return lines - - # generate_help () - - def print_help (self, header=None, file=None): - if file is None: - file = sys.stdout - for line in self.generate_help(header): - file.write(line + "\n") - -# class FancyGetopt - - -def fancy_getopt (options, negative_opt, object, args): - parser = FancyGetopt(options) - parser.set_negative_aliases(negative_opt) - return parser.getopt(args, object) - - -WS_TRANS = string.maketrans(string.whitespace, ' ' * len(string.whitespace)) - -def wrap_text (text, width): - """wrap_text(text : string, width : int) -> [string] - - Split 'text' into multiple lines of no more than 'width' characters - each, and return the list of strings that results. - """ - - if text is None: - return [] - if len(text) <= width: - return [text] - - text = string.expandtabs(text) - text = string.translate(text, WS_TRANS) - chunks = re.split(r'( +|-+)', text) - chunks = filter(None, chunks) # ' - ' results in empty strings - lines = [] - - while chunks: - - cur_line = [] # list of chunks (to-be-joined) - cur_len = 0 # length of current line - - while chunks: - l = len(chunks[0]) - if cur_len + l <= width: # can squeeze (at least) this chunk in - cur_line.append(chunks[0]) - del chunks[0] - cur_len = cur_len + l - else: # this line is full - # drop last chunk if all space - if cur_line and cur_line[-1][0] == ' ': - del cur_line[-1] - break - - if chunks: # any chunks left to process? - - # if the current line is still empty, then we had a single - # chunk that's too big too fit on a line -- so we break - # down and break it up at the line width - if cur_len == 0: - cur_line.append(chunks[0][0:width]) - chunks[0] = chunks[0][width:] - - # all-whitespace chunks at the end of a line can be discarded - # (and we know from the re.split above that if a chunk has - # *any* whitespace, it is *all* whitespace) - if chunks[0][0] == ' ': - del chunks[0] - - # and store this line in the list-of-all-lines -- as a single - # string, of course! - lines.append(string.join(cur_line, '')) - - # while chunks - - return lines - - -def translate_longopt(opt): - """Convert a long option name to a valid Python identifier by - changing "-" to "_". - """ - return string.translate(opt, longopt_xlate) - - -class OptionDummy: - """Dummy class just used as a place to hold command-line option - values as instance attributes.""" - - def __init__ (self, options=[]): - """Create a new OptionDummy instance. The attributes listed in - 'options' will be initialized to None.""" - for opt in options: - setattr(self, opt, None) diff --git a/PythonLib/extra/distutils/file_util.py b/PythonLib/extra/distutils/file_util.py deleted file mode 100644 index b9f07861..00000000 --- a/PythonLib/extra/distutils/file_util.py +++ /dev/null @@ -1,231 +0,0 @@ -"""distutils.file_util - -Utility functions for operating on single files. -""" - -__revision__ = "$Id$" - -import os -from distutils.errors import DistutilsFileError -from distutils import log - -# for generating verbose output in 'copy_file()' -_copy_action = {None: 'copying', - 'hard': 'hard linking', - 'sym': 'symbolically linking'} - - -def _copy_file_contents(src, dst, buffer_size=16*1024): - """Copy the file 'src' to 'dst'. - - Both must be filenames. Any error opening either file, reading from - 'src', or writing to 'dst', raises DistutilsFileError. Data is - read/written in chunks of 'buffer_size' bytes (default 16k). No attempt - is made to handle anything apart from regular files. - """ - # Stolen from shutil module in the standard library, but with - # custom error-handling added. - fsrc = None - fdst = None - try: - try: - fsrc = open(src, 'rb') - except os.error, (errno, errstr): - raise DistutilsFileError("could not open '%s': %s" % (src, errstr)) - - if os.path.exists(dst): - try: - os.unlink(dst) - except os.error, (errno, errstr): - raise DistutilsFileError( - "could not delete '%s': %s" % (dst, errstr)) - - try: - fdst = open(dst, 'wb') - except os.error, (errno, errstr): - raise DistutilsFileError( - "could not create '%s': %s" % (dst, errstr)) - - while 1: - try: - buf = fsrc.read(buffer_size) - except os.error, (errno, errstr): - raise DistutilsFileError( - "could not read from '%s': %s" % (src, errstr)) - - if not buf: - break - - try: - fdst.write(buf) - except os.error, (errno, errstr): - raise DistutilsFileError( - "could not write to '%s': %s" % (dst, errstr)) - - finally: - if fdst: - fdst.close() - if fsrc: - fsrc.close() - -def copy_file(src, dst, preserve_mode=1, preserve_times=1, update=0, - link=None, verbose=1, dry_run=0): - """Copy a file 'src' to 'dst'. - - If 'dst' is a directory, then 'src' is copied there with the same name; - otherwise, it must be a filename. (If the file exists, it will be - ruthlessly clobbered.) If 'preserve_mode' is true (the default), - the file's mode (type and permission bits, or whatever is analogous on - the current platform) is copied. If 'preserve_times' is true (the - default), the last-modified and last-access times are copied as well. - If 'update' is true, 'src' will only be copied if 'dst' does not exist, - or if 'dst' does exist but is older than 'src'. - - 'link' allows you to make hard links (os.link) or symbolic links - (os.symlink) instead of copying: set it to "hard" or "sym"; if it is - None (the default), files are copied. Don't set 'link' on systems that - don't support it: 'copy_file()' doesn't check if hard or symbolic - linking is available. - - Under Mac OS, uses the native file copy function in macostools; on - other systems, uses '_copy_file_contents()' to copy file contents. - - Return a tuple (dest_name, copied): 'dest_name' is the actual name of - the output file, and 'copied' is true if the file was copied (or would - have been copied, if 'dry_run' true). - """ - # XXX if the destination file already exists, we clobber it if - # copying, but blow up if linking. Hmmm. And I don't know what - # macostools.copyfile() does. Should definitely be consistent, and - # should probably blow up if destination exists and we would be - # changing it (ie. it's not already a hard/soft link to src OR - # (not update) and (src newer than dst). - - from distutils.dep_util import newer - from stat import ST_ATIME, ST_MTIME, ST_MODE, S_IMODE - - if not os.path.isfile(src): - raise DistutilsFileError( - "can't copy '%s': doesn't exist or not a regular file" % src) - - if os.path.isdir(dst): - dir = dst - dst = os.path.join(dst, os.path.basename(src)) - else: - dir = os.path.dirname(dst) - - if update and not newer(src, dst): - if verbose >= 1: - log.debug("not copying %s (output up-to-date)", src) - return dst, 0 - - try: - action = _copy_action[link] - except KeyError: - raise ValueError("invalid value '%s' for 'link' argument" % link) - - if verbose >= 1: - if os.path.basename(dst) == os.path.basename(src): - log.info("%s %s -> %s", action, src, dir) - else: - log.info("%s %s -> %s", action, src, dst) - - if dry_run: - return (dst, 1) - - # If linking (hard or symbolic), use the appropriate system call - # (Unix only, of course, but that's the caller's responsibility) - if link == 'hard': - if not (os.path.exists(dst) and os.path.samefile(src, dst)): - os.link(src, dst) - elif link == 'sym': - if not (os.path.exists(dst) and os.path.samefile(src, dst)): - os.symlink(src, dst) - - # Otherwise (non-Mac, not linking), copy the file contents and - # (optionally) copy the times and mode. - else: - _copy_file_contents(src, dst) - if preserve_mode or preserve_times: - st = os.stat(src) - - # According to David Ascher , utime() should be done - # before chmod() (at least under NT). - if preserve_times: - os.utime(dst, (st[ST_ATIME], st[ST_MTIME])) - if preserve_mode: - os.chmod(dst, S_IMODE(st[ST_MODE])) - - return (dst, 1) - -# XXX I suspect this is Unix-specific -- need porting help! -def move_file (src, dst, verbose=1, dry_run=0): - """Move a file 'src' to 'dst'. - - If 'dst' is a directory, the file will be moved into it with the same - name; otherwise, 'src' is just renamed to 'dst'. Return the new - full name of the file. - - Handles cross-device moves on Unix using 'copy_file()'. What about - other systems??? - """ - from os.path import exists, isfile, isdir, basename, dirname - import errno - - if verbose >= 1: - log.info("moving %s -> %s", src, dst) - - if dry_run: - return dst - - if not isfile(src): - raise DistutilsFileError("can't move '%s': not a regular file" % src) - - if isdir(dst): - dst = os.path.join(dst, basename(src)) - elif exists(dst): - raise DistutilsFileError( - "can't move '%s': destination '%s' already exists" % - (src, dst)) - - if not isdir(dirname(dst)): - raise DistutilsFileError( - "can't move '%s': destination '%s' not a valid path" % \ - (src, dst)) - - copy_it = 0 - try: - os.rename(src, dst) - except os.error, (num, msg): - if num == errno.EXDEV: - copy_it = 1 - else: - raise DistutilsFileError( - "couldn't move '%s' to '%s': %s" % (src, dst, msg)) - - if copy_it: - copy_file(src, dst, verbose=verbose) - try: - os.unlink(src) - except os.error, (num, msg): - try: - os.unlink(dst) - except os.error: - pass - raise DistutilsFileError( - ("couldn't move '%s' to '%s' by copy/delete: " + - "delete '%s' failed: %s") % - (src, dst, src, msg)) - return dst - - -def write_file (filename, contents): - """Create a file with the specified name and write 'contents' (a - sequence of strings without line terminators) to it. - """ - f = open(filename, "w") - try: - for line in contents: - f.write(line + "\n") - finally: - f.close() diff --git a/PythonLib/extra/distutils/filelist.py b/PythonLib/extra/distutils/filelist.py deleted file mode 100644 index 2f1c457e..00000000 --- a/PythonLib/extra/distutils/filelist.py +++ /dev/null @@ -1,343 +0,0 @@ -"""distutils.filelist - -Provides the FileList class, used for poking about the filesystem -and building lists of files. -""" - -__revision__ = "$Id$" - -import os, re -import fnmatch -from distutils.util import convert_path -from distutils.errors import DistutilsTemplateError, DistutilsInternalError -from distutils import log - -class FileList: - """A list of files built by on exploring the filesystem and filtered by - applying various patterns to what we find there. - - Instance attributes: - dir - directory from which files will be taken -- only used if - 'allfiles' not supplied to constructor - files - list of filenames currently being built/filtered/manipulated - allfiles - complete list of files under consideration (ie. without any - filtering applied) - """ - - def __init__(self, warn=None, debug_print=None): - # ignore argument to FileList, but keep them for backwards - # compatibility - self.allfiles = None - self.files = [] - - def set_allfiles(self, allfiles): - self.allfiles = allfiles - - def findall(self, dir=os.curdir): - self.allfiles = findall(dir) - - def debug_print(self, msg): - """Print 'msg' to stdout if the global DEBUG (taken from the - DISTUTILS_DEBUG environment variable) flag is true. - """ - from distutils.debug import DEBUG - if DEBUG: - print msg - - # -- List-like methods --------------------------------------------- - - def append(self, item): - self.files.append(item) - - def extend(self, items): - self.files.extend(items) - - def sort(self): - # Not a strict lexical sort! - sortable_files = map(os.path.split, self.files) - sortable_files.sort() - self.files = [] - for sort_tuple in sortable_files: - self.files.append(os.path.join(*sort_tuple)) - - - # -- Other miscellaneous utility methods --------------------------- - - def remove_duplicates(self): - # Assumes list has been sorted! - for i in range(len(self.files) - 1, 0, -1): - if self.files[i] == self.files[i - 1]: - del self.files[i] - - - # -- "File template" methods --------------------------------------- - - def _parse_template_line(self, line): - words = line.split() - action = words[0] - - patterns = dir = dir_pattern = None - - if action in ('include', 'exclude', - 'global-include', 'global-exclude'): - if len(words) < 2: - raise DistutilsTemplateError, \ - "'%s' expects ..." % action - - patterns = map(convert_path, words[1:]) - - elif action in ('recursive-include', 'recursive-exclude'): - if len(words) < 3: - raise DistutilsTemplateError, \ - "'%s' expects

..." % action - - dir = convert_path(words[1]) - patterns = map(convert_path, words[2:]) - - elif action in ('graft', 'prune'): - if len(words) != 2: - raise DistutilsTemplateError, \ - "'%s' expects a single " % action - - dir_pattern = convert_path(words[1]) - - else: - raise DistutilsTemplateError, "unknown action '%s'" % action - - return (action, patterns, dir, dir_pattern) - - def process_template_line(self, line): - # Parse the line: split it up, make sure the right number of words - # is there, and return the relevant words. 'action' is always - # defined: it's the first word of the line. Which of the other - # three are defined depends on the action; it'll be either - # patterns, (dir and patterns), or (dir_pattern). - action, patterns, dir, dir_pattern = self._parse_template_line(line) - - # OK, now we know that the action is valid and we have the - # right number of words on the line for that action -- so we - # can proceed with minimal error-checking. - if action == 'include': - self.debug_print("include " + ' '.join(patterns)) - for pattern in patterns: - if not self.include_pattern(pattern, anchor=1): - log.warn("warning: no files found matching '%s'", - pattern) - - elif action == 'exclude': - self.debug_print("exclude " + ' '.join(patterns)) - for pattern in patterns: - if not self.exclude_pattern(pattern, anchor=1): - log.warn(("warning: no previously-included files " - "found matching '%s'"), pattern) - - elif action == 'global-include': - self.debug_print("global-include " + ' '.join(patterns)) - for pattern in patterns: - if not self.include_pattern(pattern, anchor=0): - log.warn(("warning: no files found matching '%s' " + - "anywhere in distribution"), pattern) - - elif action == 'global-exclude': - self.debug_print("global-exclude " + ' '.join(patterns)) - for pattern in patterns: - if not self.exclude_pattern(pattern, anchor=0): - log.warn(("warning: no previously-included files matching " - "'%s' found anywhere in distribution"), - pattern) - - elif action == 'recursive-include': - self.debug_print("recursive-include %s %s" % - (dir, ' '.join(patterns))) - for pattern in patterns: - if not self.include_pattern(pattern, prefix=dir): - log.warn(("warning: no files found matching '%s' " + - "under directory '%s'"), - pattern, dir) - - elif action == 'recursive-exclude': - self.debug_print("recursive-exclude %s %s" % - (dir, ' '.join(patterns))) - for pattern in patterns: - if not self.exclude_pattern(pattern, prefix=dir): - log.warn(("warning: no previously-included files matching " - "'%s' found under directory '%s'"), - pattern, dir) - - elif action == 'graft': - self.debug_print("graft " + dir_pattern) - if not self.include_pattern(None, prefix=dir_pattern): - log.warn("warning: no directories found matching '%s'", - dir_pattern) - - elif action == 'prune': - self.debug_print("prune " + dir_pattern) - if not self.exclude_pattern(None, prefix=dir_pattern): - log.warn(("no previously-included directories found " + - "matching '%s'"), dir_pattern) - else: - raise DistutilsInternalError, \ - "this cannot happen: invalid action '%s'" % action - - # -- Filtering/selection methods ----------------------------------- - - def include_pattern(self, pattern, anchor=1, prefix=None, is_regex=0): - """Select strings (presumably filenames) from 'self.files' that - match 'pattern', a Unix-style wildcard (glob) pattern. - - Patterns are not quite the same as implemented by the 'fnmatch' - module: '*' and '?' match non-special characters, where "special" - is platform-dependent: slash on Unix; colon, slash, and backslash on - DOS/Windows; and colon on Mac OS. - - If 'anchor' is true (the default), then the pattern match is more - stringent: "*.py" will match "foo.py" but not "foo/bar.py". If - 'anchor' is false, both of these will match. - - If 'prefix' is supplied, then only filenames starting with 'prefix' - (itself a pattern) and ending with 'pattern', with anything in between - them, will match. 'anchor' is ignored in this case. - - If 'is_regex' is true, 'anchor' and 'prefix' are ignored, and - 'pattern' is assumed to be either a string containing a regex or a - regex object -- no translation is done, the regex is just compiled - and used as-is. - - Selected strings will be added to self.files. - - Return 1 if files are found. - """ - # XXX docstring lying about what the special chars are? - files_found = 0 - pattern_re = translate_pattern(pattern, anchor, prefix, is_regex) - self.debug_print("include_pattern: applying regex r'%s'" % - pattern_re.pattern) - - # delayed loading of allfiles list - if self.allfiles is None: - self.findall() - - for name in self.allfiles: - if pattern_re.search(name): - self.debug_print(" adding " + name) - self.files.append(name) - files_found = 1 - - return files_found - - - def exclude_pattern(self, pattern, anchor=1, prefix=None, is_regex=0): - """Remove strings (presumably filenames) from 'files' that match - 'pattern'. - - Other parameters are the same as for 'include_pattern()', above. - The list 'self.files' is modified in place. Return 1 if files are - found. - """ - files_found = 0 - pattern_re = translate_pattern(pattern, anchor, prefix, is_regex) - self.debug_print("exclude_pattern: applying regex r'%s'" % - pattern_re.pattern) - for i in range(len(self.files)-1, -1, -1): - if pattern_re.search(self.files[i]): - self.debug_print(" removing " + self.files[i]) - del self.files[i] - files_found = 1 - - return files_found - - -# ---------------------------------------------------------------------- -# Utility functions - -def findall(dir = os.curdir): - """Find all files under 'dir' and return the list of full filenames - (relative to 'dir'). - """ - from stat import ST_MODE, S_ISREG, S_ISDIR, S_ISLNK - - list = [] - stack = [dir] - pop = stack.pop - push = stack.append - - while stack: - dir = pop() - names = os.listdir(dir) - - for name in names: - if dir != os.curdir: # avoid the dreaded "./" syndrome - fullname = os.path.join(dir, name) - else: - fullname = name - - # Avoid excess stat calls -- just one will do, thank you! - stat = os.stat(fullname) - mode = stat[ST_MODE] - if S_ISREG(mode): - list.append(fullname) - elif S_ISDIR(mode) and not S_ISLNK(mode): - push(fullname) - - return list - - -def glob_to_re(pattern): - """Translate a shell-like glob pattern to a regular expression. - - Return a string containing the regex. Differs from - 'fnmatch.translate()' in that '*' does not match "special characters" - (which are platform-specific). - """ - pattern_re = fnmatch.translate(pattern) - - # '?' and '*' in the glob pattern become '.' and '.*' in the RE, which - # IMHO is wrong -- '?' and '*' aren't supposed to match slash in Unix, - # and by extension they shouldn't match such "special characters" under - # any OS. So change all non-escaped dots in the RE to match any - # character except the special characters (currently: just os.sep). - sep = os.sep - if os.sep == '\\': - # we're using a regex to manipulate a regex, so we need - # to escape the backslash twice - sep = r'\\\\' - escaped = r'\1[^%s]' % sep - pattern_re = re.sub(r'((?= self.threshold: - if args: - msg = msg % args - if level in (WARN, ERROR, FATAL): - stream = sys.stderr - else: - stream = sys.stdout - stream.write('%s\n' % msg) - stream.flush() - - def log(self, level, msg, *args): - self._log(level, msg, args) - - def debug(self, msg, *args): - self._log(DEBUG, msg, args) - - def info(self, msg, *args): - self._log(INFO, msg, args) - - def warn(self, msg, *args): - self._log(WARN, msg, args) - - def error(self, msg, *args): - self._log(ERROR, msg, args) - - def fatal(self, msg, *args): - self._log(FATAL, msg, args) - -_global_log = Log() -log = _global_log.log -debug = _global_log.debug -info = _global_log.info -warn = _global_log.warn -error = _global_log.error -fatal = _global_log.fatal - -def set_threshold(level): - # return the old threshold for use from tests - old = _global_log.threshold - _global_log.threshold = level - return old - -def set_verbosity(v): - if v <= 0: - set_threshold(WARN) - elif v == 1: - set_threshold(INFO) - elif v >= 2: - set_threshold(DEBUG) diff --git a/PythonLib/extra/distutils/msvc9compiler.py b/PythonLib/extra/distutils/msvc9compiler.py deleted file mode 100644 index 7ec9b92a..00000000 --- a/PythonLib/extra/distutils/msvc9compiler.py +++ /dev/null @@ -1,801 +0,0 @@ -"""distutils.msvc9compiler - -Contains MSVCCompiler, an implementation of the abstract CCompiler class -for the Microsoft Visual Studio 2008. - -The module is compatible with VS 2005 and VS 2008. You can find legacy support -for older versions of VS in distutils.msvccompiler. -""" - -# Written by Perry Stoll -# hacked by Robin Becker and Thomas Heller to do a better job of -# finding DevStudio (through the registry) -# ported to VS2005 and VS 2008 by Christian Heimes - -__revision__ = "$Id$" - -import os -import subprocess -import sys -import re - -from distutils.errors import (DistutilsExecError, DistutilsPlatformError, - CompileError, LibError, LinkError) -from distutils.ccompiler import CCompiler, gen_lib_options -from distutils import log -from distutils.util import get_platform - -import _winreg - -RegOpenKeyEx = _winreg.OpenKeyEx -RegEnumKey = _winreg.EnumKey -RegEnumValue = _winreg.EnumValue -RegError = _winreg.error - -HKEYS = (_winreg.HKEY_USERS, - _winreg.HKEY_CURRENT_USER, - _winreg.HKEY_LOCAL_MACHINE, - _winreg.HKEY_CLASSES_ROOT) - -NATIVE_WIN64 = (sys.platform == 'win32' and sys.maxsize > 2**32) -if NATIVE_WIN64: - # Visual C++ is a 32-bit application, so we need to look in - # the corresponding registry branch, if we're running a - # 64-bit Python on Win64 - VS_BASE = r"Software\Wow6432Node\Microsoft\VisualStudio\%0.1f" - VSEXPRESS_BASE = r"Software\Wow6432Node\Microsoft\VCExpress\%0.1f" - WINSDK_BASE = r"Software\Wow6432Node\Microsoft\Microsoft SDKs\Windows" - NET_BASE = r"Software\Wow6432Node\Microsoft\.NETFramework" -else: - VS_BASE = r"Software\Microsoft\VisualStudio\%0.1f" - VSEXPRESS_BASE = r"Software\Microsoft\VCExpress\%0.1f" - WINSDK_BASE = r"Software\Microsoft\Microsoft SDKs\Windows" - NET_BASE = r"Software\Microsoft\.NETFramework" - -# A map keyed by get_platform() return values to values accepted by -# 'vcvarsall.bat'. Note a cross-compile may combine these (eg, 'x86_amd64' is -# the param to cross-compile on x86 targetting amd64.) -PLAT_TO_VCVARS = { - 'win32' : 'x86', - 'win-amd64' : 'amd64', - 'win-ia64' : 'ia64', -} - -class Reg: - """Helper class to read values from the registry - """ - - def get_value(cls, path, key): - for base in HKEYS: - d = cls.read_values(base, path) - if d and key in d: - return d[key] - raise KeyError(key) - get_value = classmethod(get_value) - - def read_keys(cls, base, key): - """Return list of registry keys.""" - try: - handle = RegOpenKeyEx(base, key) - except RegError: - return None - L = [] - i = 0 - while True: - try: - k = RegEnumKey(handle, i) - except RegError: - break - L.append(k) - i += 1 - return L - read_keys = classmethod(read_keys) - - def read_values(cls, base, key): - """Return dict of registry keys and values. - - All names are converted to lowercase. - """ - try: - handle = RegOpenKeyEx(base, key) - except RegError: - return None - d = {} - i = 0 - while True: - try: - name, value, type = RegEnumValue(handle, i) - except RegError: - break - name = name.lower() - d[cls.convert_mbcs(name)] = cls.convert_mbcs(value) - i += 1 - return d - read_values = classmethod(read_values) - - def convert_mbcs(s): - dec = getattr(s, "decode", None) - if dec is not None: - try: - s = dec("mbcs") - except UnicodeError: - pass - return s - convert_mbcs = staticmethod(convert_mbcs) - -class MacroExpander: - - def __init__(self, version): - self.macros = {} - self.vsbase = VS_BASE % version - self.load_macros(version) - - def set_macro(self, macro, path, key): - self.macros["$(%s)" % macro] = Reg.get_value(path, key) - - def load_macros(self, version): - self.set_macro("VCInstallDir", self.vsbase + r"\Setup\VC", "productdir") - self.set_macro("VSInstallDir", self.vsbase + r"\Setup\VS", "productdir") - self.set_macro("FrameworkDir", NET_BASE, "installroot") - try: - if version >= 8.0: - self.set_macro("FrameworkSDKDir", NET_BASE, - "sdkinstallrootv2.0") - else: - raise KeyError("sdkinstallrootv2.0") - except KeyError: - raise DistutilsPlatformError( - """Python was built with Visual Studio 2008; -extensions must be built with a compiler than can generate compatible binaries. -Visual Studio 2008 was not found on this system. If you have Cygwin installed, -you can try compiling with MingW32, by passing "-c mingw32" to setup.py.""") - - if version >= 9.0: - self.set_macro("FrameworkVersion", self.vsbase, "clr version") - self.set_macro("WindowsSdkDir", WINSDK_BASE, "currentinstallfolder") - else: - p = r"Software\Microsoft\NET Framework Setup\Product" - for base in HKEYS: - try: - h = RegOpenKeyEx(base, p) - except RegError: - continue - key = RegEnumKey(h, 0) - d = Reg.get_value(base, r"%s\%s" % (p, key)) - self.macros["$(FrameworkVersion)"] = d["version"] - - def sub(self, s): - for k, v in self.macros.items(): - s = s.replace(k, v) - return s - -def get_build_version(): - """Return the version of MSVC that was used to build Python. - - For Python 2.3 and up, the version number is included in - sys.version. For earlier versions, assume the compiler is MSVC 6. - """ - prefix = "MSC v." - i = sys.version.find(prefix) - if i == -1: - return 6 - i = i + len(prefix) - s, rest = sys.version[i:].split(" ", 1) - majorVersion = int(s[:-2]) - 6 - minorVersion = int(s[2:3]) / 10.0 - # I don't think paths are affected by minor version in version 6 - if majorVersion == 6: - minorVersion = 0 - if majorVersion >= 6: - return majorVersion + minorVersion - # else we don't know what version of the compiler this is - return None - -def normalize_and_reduce_paths(paths): - """Return a list of normalized paths with duplicates removed. - - The current order of paths is maintained. - """ - # Paths are normalized so things like: /a and /a/ aren't both preserved. - reduced_paths = [] - for p in paths: - np = os.path.normpath(p) - # XXX(nnorwitz): O(n**2), if reduced_paths gets long perhaps use a set. - if np not in reduced_paths: - reduced_paths.append(np) - return reduced_paths - -def removeDuplicates(variable): - """Remove duplicate values of an environment variable. - """ - oldList = variable.split(os.pathsep) - newList = [] - for i in oldList: - if i not in newList: - newList.append(i) - newVariable = os.pathsep.join(newList) - return newVariable - -def find_vcvarsall(version): - """Find the vcvarsall.bat file - - At first it tries to find the productdir of VS 2008 in the registry. If - that fails it falls back to the VS90COMNTOOLS env var. - """ - vsbase = VS_BASE % version - try: - productdir = Reg.get_value(r"%s\Setup\VC" % vsbase, - "productdir") - except KeyError: - productdir = None - - # trying Express edition - if productdir is None: - vsbase = VSEXPRESS_BASE % version - try: - productdir = Reg.get_value(r"%s\Setup\VC" % vsbase, - "productdir") - except KeyError: - productdir = None - log.debug("Unable to find productdir in registry") - - if not productdir or not os.path.isdir(productdir): - toolskey = "VS%0.f0COMNTOOLS" % version - toolsdir = os.environ.get(toolskey, None) - - if toolsdir and os.path.isdir(toolsdir): - productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC") - productdir = os.path.abspath(productdir) - if not os.path.isdir(productdir): - log.debug("%s is not a valid directory" % productdir) - return None - else: - log.debug("Env var %s is not set or invalid" % toolskey) - if not productdir: - log.debug("No productdir found") - return None - vcvarsall = os.path.join(productdir, "vcvarsall.bat") - if os.path.isfile(vcvarsall): - return vcvarsall - log.debug("Unable to find vcvarsall.bat") - return None - -def query_vcvarsall(version, arch="x86"): - """Launch vcvarsall.bat and read the settings from its environment - """ - vcvarsall = find_vcvarsall(version) - interesting = set(("include", "lib", "libpath", "path")) - result = {} - - if vcvarsall is None: - raise DistutilsPlatformError("Unable to find vcvarsall.bat") - log.debug("Calling 'vcvarsall.bat %s' (version=%s)", arch, version) - popen = subprocess.Popen('"%s" %s & set' % (vcvarsall, arch), - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - try: - stdout, stderr = popen.communicate() - if popen.wait() != 0: - raise DistutilsPlatformError(stderr.decode("mbcs")) - - stdout = stdout.decode("mbcs") - for line in stdout.split("\n"): - line = Reg.convert_mbcs(line) - if '=' not in line: - continue - line = line.strip() - key, value = line.split('=', 1) - key = key.lower() - if key in interesting: - if value.endswith(os.pathsep): - value = value[:-1] - result[key] = removeDuplicates(value) - - finally: - popen.stdout.close() - popen.stderr.close() - - if len(result) != len(interesting): - raise ValueError(str(list(result.keys()))) - - return result - -# More globals -VERSION = get_build_version() -if VERSION < 8.0: - raise DistutilsPlatformError("VC %0.1f is not supported by this module" % VERSION) -# MACROS = MacroExpander(VERSION) - -class MSVCCompiler(CCompiler) : - """Concrete class that implements an interface to Microsoft Visual C++, - as defined by the CCompiler abstract class.""" - - compiler_type = 'msvc' - - # Just set this so CCompiler's constructor doesn't barf. We currently - # don't use the 'set_executables()' bureaucracy provided by CCompiler, - # as it really isn't necessary for this sort of single-compiler class. - # Would be nice to have a consistent interface with UnixCCompiler, - # though, so it's worth thinking about. - executables = {} - - # Private class data (need to distinguish C from C++ source for compiler) - _c_extensions = ['.c'] - _cpp_extensions = ['.cc', '.cpp', '.cxx'] - _rc_extensions = ['.rc'] - _mc_extensions = ['.mc'] - - # Needed for the filename generation methods provided by the - # base class, CCompiler. - src_extensions = (_c_extensions + _cpp_extensions + - _rc_extensions + _mc_extensions) - res_extension = '.res' - obj_extension = '.obj' - static_lib_extension = '.lib' - shared_lib_extension = '.dll' - static_lib_format = shared_lib_format = '%s%s' - exe_extension = '.exe' - - def __init__(self, verbose=0, dry_run=0, force=0): - CCompiler.__init__ (self, verbose, dry_run, force) - self.__version = VERSION - self.__root = r"Software\Microsoft\VisualStudio" - # self.__macros = MACROS - self.__paths = [] - # target platform (.plat_name is consistent with 'bdist') - self.plat_name = None - self.__arch = None # deprecated name - self.initialized = False - - def initialize(self, plat_name=None): - # multi-init means we would need to check platform same each time... - assert not self.initialized, "don't init multiple times" - if plat_name is None: - plat_name = get_platform() - # sanity check for platforms to prevent obscure errors later. - ok_plats = 'win32', 'win-amd64', 'win-ia64' - if plat_name not in ok_plats: - raise DistutilsPlatformError("--plat-name must be one of %s" % - (ok_plats,)) - - if "DISTUTILS_USE_SDK" in os.environ and "MSSdk" in os.environ and self.find_exe("cl.exe"): - # Assume that the SDK set up everything alright; don't try to be - # smarter - self.cc = "cl.exe" - self.linker = "link.exe" - self.lib = "lib.exe" - self.rc = "rc.exe" - self.mc = "mc.exe" - else: - # On x86, 'vcvars32.bat amd64' creates an env that doesn't work; - # to cross compile, you use 'x86_amd64'. - # On AMD64, 'vcvars32.bat amd64' is a native build env; to cross - # compile use 'x86' (ie, it runs the x86 compiler directly) - # No idea how itanium handles this, if at all. - if plat_name == get_platform() or plat_name == 'win32': - # native build or cross-compile to win32 - plat_spec = PLAT_TO_VCVARS[plat_name] - else: - # cross compile from win32 -> some 64bit - plat_spec = PLAT_TO_VCVARS[get_platform()] + '_' + \ - PLAT_TO_VCVARS[plat_name] - - vc_env = query_vcvarsall(VERSION, plat_spec) - - # take care to only use strings in the environment. - self.__paths = vc_env['path'].encode('mbcs').split(os.pathsep) - os.environ['lib'] = vc_env['lib'].encode('mbcs') - os.environ['include'] = vc_env['include'].encode('mbcs') - - if len(self.__paths) == 0: - raise DistutilsPlatformError("Python was built with %s, " - "and extensions need to be built with the same " - "version of the compiler, but it isn't installed." - % self.__product) - - self.cc = self.find_exe("cl.exe") - self.linker = self.find_exe("link.exe") - self.lib = self.find_exe("lib.exe") - self.rc = self.find_exe("rc.exe") # resource compiler - self.mc = self.find_exe("mc.exe") # message compiler - #self.set_path_env_var('lib') - #self.set_path_env_var('include') - - # extend the MSVC path with the current path - try: - for p in os.environ['path'].split(';'): - self.__paths.append(p) - except KeyError: - pass - self.__paths = normalize_and_reduce_paths(self.__paths) - os.environ['path'] = ";".join(self.__paths) - - self.preprocess_options = None - if self.__arch == "x86": - self.compile_options = [ '/nologo', '/Ox', '/MD', '/W3', - '/DNDEBUG'] - self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3', - '/Z7', '/D_DEBUG'] - else: - # Win64 - self.compile_options = [ '/nologo', '/Ox', '/MD', '/W3', '/GS-' , - '/DNDEBUG'] - self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3', '/GS-', - '/Z7', '/D_DEBUG'] - - self.ldflags_shared = ['/DLL', '/nologo', '/INCREMENTAL:NO'] - if self.__version >= 7: - self.ldflags_shared_debug = [ - '/DLL', '/nologo', '/INCREMENTAL:no', '/DEBUG', '/pdb:None' - ] - self.ldflags_static = [ '/nologo'] - - self.initialized = True - - # -- Worker methods ------------------------------------------------ - - def object_filenames(self, - source_filenames, - strip_dir=0, - output_dir=''): - # Copied from ccompiler.py, extended to return .res as 'object'-file - # for .rc input file - if output_dir is None: output_dir = '' - obj_names = [] - for src_name in source_filenames: - (base, ext) = os.path.splitext (src_name) - base = os.path.splitdrive(base)[1] # Chop off the drive - base = base[os.path.isabs(base):] # If abs, chop off leading / - if ext not in self.src_extensions: - # Better to raise an exception instead of silently continuing - # and later complain about sources and targets having - # different lengths - raise CompileError ("Don't know how to compile %s" % src_name) - if strip_dir: - base = os.path.basename (base) - if ext in self._rc_extensions: - obj_names.append (os.path.join (output_dir, - base + self.res_extension)) - elif ext in self._mc_extensions: - obj_names.append (os.path.join (output_dir, - base + self.res_extension)) - else: - obj_names.append (os.path.join (output_dir, - base + self.obj_extension)) - return obj_names - - - def compile(self, sources, - output_dir=None, macros=None, include_dirs=None, debug=0, - extra_preargs=None, extra_postargs=None, depends=None): - - if not self.initialized: - self.initialize() - compile_info = self._setup_compile(output_dir, macros, include_dirs, - sources, depends, extra_postargs) - macros, objects, extra_postargs, pp_opts, build = compile_info - - compile_opts = extra_preargs or [] - compile_opts.append ('/c') - if debug: - compile_opts.extend(self.compile_options_debug) - else: - compile_opts.extend(self.compile_options) - - for obj in objects: - try: - src, ext = build[obj] - except KeyError: - continue - if debug: - # pass the full pathname to MSVC in debug mode, - # this allows the debugger to find the source file - # without asking the user to browse for it - src = os.path.abspath(src) - - if ext in self._c_extensions: - input_opt = "/Tc" + src - elif ext in self._cpp_extensions: - input_opt = "/Tp" + src - elif ext in self._rc_extensions: - # compile .RC to .RES file - input_opt = src - output_opt = "/fo" + obj - try: - self.spawn([self.rc] + pp_opts + - [output_opt] + [input_opt]) - except DistutilsExecError, msg: - raise CompileError(msg) - continue - elif ext in self._mc_extensions: - # Compile .MC to .RC file to .RES file. - # * '-h dir' specifies the directory for the - # generated include file - # * '-r dir' specifies the target directory of the - # generated RC file and the binary message resource - # it includes - # - # For now (since there are no options to change this), - # we use the source-directory for the include file and - # the build directory for the RC file and message - # resources. This works at least for win32all. - h_dir = os.path.dirname(src) - rc_dir = os.path.dirname(obj) - try: - # first compile .MC to .RC and .H file - self.spawn([self.mc] + - ['-h', h_dir, '-r', rc_dir] + [src]) - base, _ = os.path.splitext (os.path.basename (src)) - rc_file = os.path.join (rc_dir, base + '.rc') - # then compile .RC to .RES file - self.spawn([self.rc] + - ["/fo" + obj] + [rc_file]) - - except DistutilsExecError, msg: - raise CompileError(msg) - continue - else: - # how to handle this file? - raise CompileError("Don't know how to compile %s to %s" - % (src, obj)) - - output_opt = "/Fo" + obj - try: - self.spawn([self.cc] + compile_opts + pp_opts + - [input_opt, output_opt] + - extra_postargs) - except DistutilsExecError, msg: - raise CompileError(msg) - - return objects - - - def create_static_lib(self, - objects, - output_libname, - output_dir=None, - debug=0, - target_lang=None): - - if not self.initialized: - self.initialize() - (objects, output_dir) = self._fix_object_args(objects, output_dir) - output_filename = self.library_filename(output_libname, - output_dir=output_dir) - - if self._need_link(objects, output_filename): - lib_args = objects + ['/OUT:' + output_filename] - if debug: - pass # XXX what goes here? - try: - self.spawn([self.lib] + lib_args) - except DistutilsExecError, msg: - raise LibError(msg) - else: - log.debug("skipping %s (up-to-date)", output_filename) - - - def link(self, - target_desc, - objects, - output_filename, - output_dir=None, - libraries=None, - library_dirs=None, - runtime_library_dirs=None, - export_symbols=None, - debug=0, - extra_preargs=None, - extra_postargs=None, - build_temp=None, - target_lang=None): - - if not self.initialized: - self.initialize() - (objects, output_dir) = self._fix_object_args(objects, output_dir) - fixed_args = self._fix_lib_args(libraries, library_dirs, - runtime_library_dirs) - (libraries, library_dirs, runtime_library_dirs) = fixed_args - - if runtime_library_dirs: - self.warn ("I don't know what to do with 'runtime_library_dirs': " - + str (runtime_library_dirs)) - - lib_opts = gen_lib_options(self, - library_dirs, runtime_library_dirs, - libraries) - if output_dir is not None: - output_filename = os.path.join(output_dir, output_filename) - - if self._need_link(objects, output_filename): - if target_desc == CCompiler.EXECUTABLE: - if debug: - ldflags = self.ldflags_shared_debug[1:] - else: - ldflags = self.ldflags_shared[1:] - else: - if debug: - ldflags = self.ldflags_shared_debug - else: - ldflags = self.ldflags_shared - - export_opts = [] - for sym in (export_symbols or []): - export_opts.append("/EXPORT:" + sym) - - ld_args = (ldflags + lib_opts + export_opts + - objects + ['/OUT:' + output_filename]) - - # The MSVC linker generates .lib and .exp files, which cannot be - # suppressed by any linker switches. The .lib files may even be - # needed! Make sure they are generated in the temporary build - # directory. Since they have different names for debug and release - # builds, they can go into the same directory. - build_temp = os.path.dirname(objects[0]) - if export_symbols is not None: - (dll_name, dll_ext) = os.path.splitext( - os.path.basename(output_filename)) - implib_file = os.path.join( - build_temp, - self.library_filename(dll_name)) - ld_args.append ('/IMPLIB:' + implib_file) - - self.manifest_setup_ldargs(output_filename, build_temp, ld_args) - - if extra_preargs: - ld_args[:0] = extra_preargs - if extra_postargs: - ld_args.extend(extra_postargs) - - self.mkpath(os.path.dirname(output_filename)) - try: - self.spawn([self.linker] + ld_args) - except DistutilsExecError, msg: - raise LinkError(msg) - - # embed the manifest - # XXX - this is somewhat fragile - if mt.exe fails, distutils - # will still consider the DLL up-to-date, but it will not have a - # manifest. Maybe we should link to a temp file? OTOH, that - # implies a build environment error that shouldn't go undetected. - mfinfo = self.manifest_get_embed_info(target_desc, ld_args) - if mfinfo is not None: - mffilename, mfid = mfinfo - out_arg = '-outputresource:%s;%s' % (output_filename, mfid) - try: - self.spawn(['mt.exe', '-nologo', '-manifest', - mffilename, out_arg]) - except DistutilsExecError, msg: - raise LinkError(msg) - else: - log.debug("skipping %s (up-to-date)", output_filename) - - def manifest_setup_ldargs(self, output_filename, build_temp, ld_args): - # If we need a manifest at all, an embedded manifest is recommended. - # See MSDN article titled - # "How to: Embed a Manifest Inside a C/C++ Application" - # (currently at http://msdn2.microsoft.com/en-us/library/ms235591(VS.80).aspx) - # Ask the linker to generate the manifest in the temp dir, so - # we can check it, and possibly embed it, later. - temp_manifest = os.path.join( - build_temp, - os.path.basename(output_filename) + ".manifest") - ld_args.append('/MANIFESTFILE:' + temp_manifest) - - def manifest_get_embed_info(self, target_desc, ld_args): - # If a manifest should be embedded, return a tuple of - # (manifest_filename, resource_id). Returns None if no manifest - # should be embedded. See http://bugs.python.org/issue7833 for why - # we want to avoid any manifest for extension modules if we can) - for arg in ld_args: - if arg.startswith("/MANIFESTFILE:"): - temp_manifest = arg.split(":", 1)[1] - break - else: - # no /MANIFESTFILE so nothing to do. - return None - if target_desc == CCompiler.EXECUTABLE: - # by default, executables always get the manifest with the - # CRT referenced. - mfid = 1 - else: - # Extension modules try and avoid any manifest if possible. - mfid = 2 - temp_manifest = self._remove_visual_c_ref(temp_manifest) - if temp_manifest is None: - return None - return temp_manifest, mfid - - def _remove_visual_c_ref(self, manifest_file): - try: - # Remove references to the Visual C runtime, so they will - # fall through to the Visual C dependency of Python.exe. - # This way, when installed for a restricted user (e.g. - # runtimes are not in WinSxS folder, but in Python's own - # folder), the runtimes do not need to be in every folder - # with .pyd's. - # Returns either the filename of the modified manifest or - # None if no manifest should be embedded. - manifest_f = open(manifest_file) - try: - manifest_buf = manifest_f.read() - finally: - manifest_f.close() - pattern = re.compile( - r"""|)""", - re.DOTALL) - manifest_buf = re.sub(pattern, "", manifest_buf) - pattern = "\s*" - manifest_buf = re.sub(pattern, "", manifest_buf) - # Now see if any other assemblies are referenced - if not, we - # don't want a manifest embedded. - pattern = re.compile( - r"""|)""", re.DOTALL) - if re.search(pattern, manifest_buf) is None: - return None - - manifest_f = open(manifest_file, 'w') - try: - manifest_f.write(manifest_buf) - return manifest_file - finally: - manifest_f.close() - except IOError: - pass - - # -- Miscellaneous methods ----------------------------------------- - # These are all used by the 'gen_lib_options() function, in - # ccompiler.py. - - def library_dir_option(self, dir): - return "/LIBPATH:" + dir - - def runtime_library_dir_option(self, dir): - raise DistutilsPlatformError( - "don't know how to set runtime library search path for MSVC++") - - def library_option(self, lib): - return self.library_filename(lib) - - - def find_library_file(self, dirs, lib, debug=0): - # Prefer a debugging library if found (and requested), but deal - # with it if we don't have one. - if debug: - try_names = [lib + "_d", lib] - else: - try_names = [lib] - for dir in dirs: - for name in try_names: - libfile = os.path.join(dir, self.library_filename (name)) - if os.path.exists(libfile): - return libfile - else: - # Oops, didn't find it in *any* of 'dirs' - return None - - # Helper methods for using the MSVC registry settings - - def find_exe(self, exe): - """Return path to an MSVC executable program. - - Tries to find the program in several places: first, one of the - MSVC program search paths from the registry; next, the directories - in the PATH environment variable. If any of those work, return an - absolute path that is known to exist. If none of them work, just - return the original program name, 'exe'. - """ - for p in self.__paths: - fn = os.path.join(os.path.abspath(p), exe) - if os.path.isfile(fn): - return fn - - # didn't find it; try existing path - for p in os.environ['Path'].split(';'): - fn = os.path.join(os.path.abspath(p),exe) - if os.path.isfile(fn): - return fn - - return exe diff --git a/PythonLib/extra/distutils/msvccompiler.py b/PythonLib/extra/distutils/msvccompiler.py deleted file mode 100644 index 0e69fd36..00000000 --- a/PythonLib/extra/distutils/msvccompiler.py +++ /dev/null @@ -1,659 +0,0 @@ -"""distutils.msvccompiler - -Contains MSVCCompiler, an implementation of the abstract CCompiler class -for the Microsoft Visual Studio. -""" - -# Written by Perry Stoll -# hacked by Robin Becker and Thomas Heller to do a better job of -# finding DevStudio (through the registry) - -__revision__ = "$Id$" - -import sys -import os -import string - -from distutils.errors import (DistutilsExecError, DistutilsPlatformError, - CompileError, LibError, LinkError) -from distutils.ccompiler import CCompiler, gen_lib_options -from distutils import log - -_can_read_reg = 0 -try: - import _winreg - - _can_read_reg = 1 - hkey_mod = _winreg - - RegOpenKeyEx = _winreg.OpenKeyEx - RegEnumKey = _winreg.EnumKey - RegEnumValue = _winreg.EnumValue - RegError = _winreg.error - -except ImportError: - try: - import win32api - import win32con - _can_read_reg = 1 - hkey_mod = win32con - - RegOpenKeyEx = win32api.RegOpenKeyEx - RegEnumKey = win32api.RegEnumKey - RegEnumValue = win32api.RegEnumValue - RegError = win32api.error - - except ImportError: - log.info("Warning: Can't read registry to find the " - "necessary compiler setting\n" - "Make sure that Python modules _winreg, " - "win32api or win32con are installed.") - pass - -if _can_read_reg: - HKEYS = (hkey_mod.HKEY_USERS, - hkey_mod.HKEY_CURRENT_USER, - hkey_mod.HKEY_LOCAL_MACHINE, - hkey_mod.HKEY_CLASSES_ROOT) - -def read_keys(base, key): - """Return list of registry keys.""" - - try: - handle = RegOpenKeyEx(base, key) - except RegError: - return None - L = [] - i = 0 - while 1: - try: - k = RegEnumKey(handle, i) - except RegError: - break - L.append(k) - i = i + 1 - return L - -def read_values(base, key): - """Return dict of registry keys and values. - - All names are converted to lowercase. - """ - try: - handle = RegOpenKeyEx(base, key) - except RegError: - return None - d = {} - i = 0 - while 1: - try: - name, value, type = RegEnumValue(handle, i) - except RegError: - break - name = name.lower() - d[convert_mbcs(name)] = convert_mbcs(value) - i = i + 1 - return d - -def convert_mbcs(s): - enc = getattr(s, "encode", None) - if enc is not None: - try: - s = enc("mbcs") - except UnicodeError: - pass - return s - -class MacroExpander: - - def __init__(self, version): - self.macros = {} - self.load_macros(version) - - def set_macro(self, macro, path, key): - for base in HKEYS: - d = read_values(base, path) - if d: - self.macros["$(%s)" % macro] = d[key] - break - - def load_macros(self, version): - vsbase = r"Software\Microsoft\VisualStudio\%0.1f" % version - self.set_macro("VCInstallDir", vsbase + r"\Setup\VC", "productdir") - self.set_macro("VSInstallDir", vsbase + r"\Setup\VS", "productdir") - net = r"Software\Microsoft\.NETFramework" - self.set_macro("FrameworkDir", net, "installroot") - try: - if version > 7.0: - self.set_macro("FrameworkSDKDir", net, "sdkinstallrootv1.1") - else: - self.set_macro("FrameworkSDKDir", net, "sdkinstallroot") - except KeyError: - raise DistutilsPlatformError, \ - ("""Python was built with Visual Studio 2003; -extensions must be built with a compiler than can generate compatible binaries. -Visual Studio 2003 was not found on this system. If you have Cygwin installed, -you can try compiling with MingW32, by passing "-c mingw32" to setup.py.""") - - p = r"Software\Microsoft\NET Framework Setup\Product" - for base in HKEYS: - try: - h = RegOpenKeyEx(base, p) - except RegError: - continue - key = RegEnumKey(h, 0) - d = read_values(base, r"%s\%s" % (p, key)) - self.macros["$(FrameworkVersion)"] = d["version"] - - def sub(self, s): - for k, v in self.macros.items(): - s = string.replace(s, k, v) - return s - -def get_build_version(): - """Return the version of MSVC that was used to build Python. - - For Python 2.3 and up, the version number is included in - sys.version. For earlier versions, assume the compiler is MSVC 6. - """ - - prefix = "MSC v." - i = string.find(sys.version, prefix) - if i == -1: - return 6 - i = i + len(prefix) - s, rest = sys.version[i:].split(" ", 1) - majorVersion = int(s[:-2]) - 6 - minorVersion = int(s[2:3]) / 10.0 - # I don't think paths are affected by minor version in version 6 - if majorVersion == 6: - minorVersion = 0 - if majorVersion >= 6: - return majorVersion + minorVersion - # else we don't know what version of the compiler this is - return None - -def get_build_architecture(): - """Return the processor architecture. - - Possible results are "Intel", "Itanium", or "AMD64". - """ - - prefix = " bit (" - i = string.find(sys.version, prefix) - if i == -1: - return "Intel" - j = string.find(sys.version, ")", i) - return sys.version[i+len(prefix):j] - -def normalize_and_reduce_paths(paths): - """Return a list of normalized paths with duplicates removed. - - The current order of paths is maintained. - """ - # Paths are normalized so things like: /a and /a/ aren't both preserved. - reduced_paths = [] - for p in paths: - np = os.path.normpath(p) - # XXX(nnorwitz): O(n**2), if reduced_paths gets long perhaps use a set. - if np not in reduced_paths: - reduced_paths.append(np) - return reduced_paths - - -class MSVCCompiler (CCompiler) : - """Concrete class that implements an interface to Microsoft Visual C++, - as defined by the CCompiler abstract class.""" - - compiler_type = 'msvc' - - # Just set this so CCompiler's constructor doesn't barf. We currently - # don't use the 'set_executables()' bureaucracy provided by CCompiler, - # as it really isn't necessary for this sort of single-compiler class. - # Would be nice to have a consistent interface with UnixCCompiler, - # though, so it's worth thinking about. - executables = {} - - # Private class data (need to distinguish C from C++ source for compiler) - _c_extensions = ['.c'] - _cpp_extensions = ['.cc', '.cpp', '.cxx'] - _rc_extensions = ['.rc'] - _mc_extensions = ['.mc'] - - # Needed for the filename generation methods provided by the - # base class, CCompiler. - src_extensions = (_c_extensions + _cpp_extensions + - _rc_extensions + _mc_extensions) - res_extension = '.res' - obj_extension = '.obj' - static_lib_extension = '.lib' - shared_lib_extension = '.dll' - static_lib_format = shared_lib_format = '%s%s' - exe_extension = '.exe' - - def __init__ (self, verbose=0, dry_run=0, force=0): - CCompiler.__init__ (self, verbose, dry_run, force) - self.__version = get_build_version() - self.__arch = get_build_architecture() - if self.__arch == "Intel": - # x86 - if self.__version >= 7: - self.__root = r"Software\Microsoft\VisualStudio" - self.__macros = MacroExpander(self.__version) - else: - self.__root = r"Software\Microsoft\Devstudio" - self.__product = "Visual Studio version %s" % self.__version - else: - # Win64. Assume this was built with the platform SDK - self.__product = "Microsoft SDK compiler %s" % (self.__version + 6) - - self.initialized = False - - def initialize(self): - self.__paths = [] - if "DISTUTILS_USE_SDK" in os.environ and "MSSdk" in os.environ and self.find_exe("cl.exe"): - # Assume that the SDK set up everything alright; don't try to be - # smarter - self.cc = "cl.exe" - self.linker = "link.exe" - self.lib = "lib.exe" - self.rc = "rc.exe" - self.mc = "mc.exe" - else: - self.__paths = self.get_msvc_paths("path") - - if len (self.__paths) == 0: - raise DistutilsPlatformError, \ - ("Python was built with %s, " - "and extensions need to be built with the same " - "version of the compiler, but it isn't installed." % self.__product) - - self.cc = self.find_exe("cl.exe") - self.linker = self.find_exe("link.exe") - self.lib = self.find_exe("lib.exe") - self.rc = self.find_exe("rc.exe") # resource compiler - self.mc = self.find_exe("mc.exe") # message compiler - self.set_path_env_var('lib') - self.set_path_env_var('include') - - # extend the MSVC path with the current path - try: - for p in string.split(os.environ['path'], ';'): - self.__paths.append(p) - except KeyError: - pass - self.__paths = normalize_and_reduce_paths(self.__paths) - os.environ['path'] = string.join(self.__paths, ';') - - self.preprocess_options = None - if self.__arch == "Intel": - self.compile_options = [ '/nologo', '/Ox', '/MD', '/W3', '/GX' , - '/DNDEBUG'] - self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3', '/GX', - '/Z7', '/D_DEBUG'] - else: - # Win64 - self.compile_options = [ '/nologo', '/Ox', '/MD', '/W3', '/GS-' , - '/DNDEBUG'] - self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3', '/GS-', - '/Z7', '/D_DEBUG'] - - self.ldflags_shared = ['/DLL', '/nologo', '/INCREMENTAL:NO'] - if self.__version >= 7: - self.ldflags_shared_debug = [ - '/DLL', '/nologo', '/INCREMENTAL:no', '/DEBUG' - ] - else: - self.ldflags_shared_debug = [ - '/DLL', '/nologo', '/INCREMENTAL:no', '/pdb:None', '/DEBUG' - ] - self.ldflags_static = [ '/nologo'] - - self.initialized = True - - # -- Worker methods ------------------------------------------------ - - def object_filenames (self, - source_filenames, - strip_dir=0, - output_dir=''): - # Copied from ccompiler.py, extended to return .res as 'object'-file - # for .rc input file - if output_dir is None: output_dir = '' - obj_names = [] - for src_name in source_filenames: - (base, ext) = os.path.splitext (src_name) - base = os.path.splitdrive(base)[1] # Chop off the drive - base = base[os.path.isabs(base):] # If abs, chop off leading / - if ext not in self.src_extensions: - # Better to raise an exception instead of silently continuing - # and later complain about sources and targets having - # different lengths - raise CompileError ("Don't know how to compile %s" % src_name) - if strip_dir: - base = os.path.basename (base) - if ext in self._rc_extensions: - obj_names.append (os.path.join (output_dir, - base + self.res_extension)) - elif ext in self._mc_extensions: - obj_names.append (os.path.join (output_dir, - base + self.res_extension)) - else: - obj_names.append (os.path.join (output_dir, - base + self.obj_extension)) - return obj_names - - # object_filenames () - - - def compile(self, sources, - output_dir=None, macros=None, include_dirs=None, debug=0, - extra_preargs=None, extra_postargs=None, depends=None): - - if not self.initialized: self.initialize() - macros, objects, extra_postargs, pp_opts, build = \ - self._setup_compile(output_dir, macros, include_dirs, sources, - depends, extra_postargs) - - compile_opts = extra_preargs or [] - compile_opts.append ('/c') - if debug: - compile_opts.extend(self.compile_options_debug) - else: - compile_opts.extend(self.compile_options) - - for obj in objects: - try: - src, ext = build[obj] - except KeyError: - continue - if debug: - # pass the full pathname to MSVC in debug mode, - # this allows the debugger to find the source file - # without asking the user to browse for it - src = os.path.abspath(src) - - if ext in self._c_extensions: - input_opt = "/Tc" + src - elif ext in self._cpp_extensions: - input_opt = "/Tp" + src - elif ext in self._rc_extensions: - # compile .RC to .RES file - input_opt = src - output_opt = "/fo" + obj - try: - self.spawn ([self.rc] + pp_opts + - [output_opt] + [input_opt]) - except DistutilsExecError, msg: - raise CompileError, msg - continue - elif ext in self._mc_extensions: - - # Compile .MC to .RC file to .RES file. - # * '-h dir' specifies the directory for the - # generated include file - # * '-r dir' specifies the target directory of the - # generated RC file and the binary message resource - # it includes - # - # For now (since there are no options to change this), - # we use the source-directory for the include file and - # the build directory for the RC file and message - # resources. This works at least for win32all. - - h_dir = os.path.dirname (src) - rc_dir = os.path.dirname (obj) - try: - # first compile .MC to .RC and .H file - self.spawn ([self.mc] + - ['-h', h_dir, '-r', rc_dir] + [src]) - base, _ = os.path.splitext (os.path.basename (src)) - rc_file = os.path.join (rc_dir, base + '.rc') - # then compile .RC to .RES file - self.spawn ([self.rc] + - ["/fo" + obj] + [rc_file]) - - except DistutilsExecError, msg: - raise CompileError, msg - continue - else: - # how to handle this file? - raise CompileError ( - "Don't know how to compile %s to %s" % \ - (src, obj)) - - output_opt = "/Fo" + obj - try: - self.spawn ([self.cc] + compile_opts + pp_opts + - [input_opt, output_opt] + - extra_postargs) - except DistutilsExecError, msg: - raise CompileError, msg - - return objects - - # compile () - - - def create_static_lib (self, - objects, - output_libname, - output_dir=None, - debug=0, - target_lang=None): - - if not self.initialized: self.initialize() - (objects, output_dir) = self._fix_object_args (objects, output_dir) - output_filename = \ - self.library_filename (output_libname, output_dir=output_dir) - - if self._need_link (objects, output_filename): - lib_args = objects + ['/OUT:' + output_filename] - if debug: - pass # XXX what goes here? - try: - self.spawn ([self.lib] + lib_args) - except DistutilsExecError, msg: - raise LibError, msg - - else: - log.debug("skipping %s (up-to-date)", output_filename) - - # create_static_lib () - - def link (self, - target_desc, - objects, - output_filename, - output_dir=None, - libraries=None, - library_dirs=None, - runtime_library_dirs=None, - export_symbols=None, - debug=0, - extra_preargs=None, - extra_postargs=None, - build_temp=None, - target_lang=None): - - if not self.initialized: self.initialize() - (objects, output_dir) = self._fix_object_args (objects, output_dir) - (libraries, library_dirs, runtime_library_dirs) = \ - self._fix_lib_args (libraries, library_dirs, runtime_library_dirs) - - if runtime_library_dirs: - self.warn ("I don't know what to do with 'runtime_library_dirs': " - + str (runtime_library_dirs)) - - lib_opts = gen_lib_options (self, - library_dirs, runtime_library_dirs, - libraries) - if output_dir is not None: - output_filename = os.path.join (output_dir, output_filename) - - if self._need_link (objects, output_filename): - - if target_desc == CCompiler.EXECUTABLE: - if debug: - ldflags = self.ldflags_shared_debug[1:] - else: - ldflags = self.ldflags_shared[1:] - else: - if debug: - ldflags = self.ldflags_shared_debug - else: - ldflags = self.ldflags_shared - - export_opts = [] - for sym in (export_symbols or []): - export_opts.append("/EXPORT:" + sym) - - ld_args = (ldflags + lib_opts + export_opts + - objects + ['/OUT:' + output_filename]) - - # The MSVC linker generates .lib and .exp files, which cannot be - # suppressed by any linker switches. The .lib files may even be - # needed! Make sure they are generated in the temporary build - # directory. Since they have different names for debug and release - # builds, they can go into the same directory. - if export_symbols is not None: - (dll_name, dll_ext) = os.path.splitext( - os.path.basename(output_filename)) - implib_file = os.path.join( - os.path.dirname(objects[0]), - self.library_filename(dll_name)) - ld_args.append ('/IMPLIB:' + implib_file) - - if extra_preargs: - ld_args[:0] = extra_preargs - if extra_postargs: - ld_args.extend(extra_postargs) - - self.mkpath (os.path.dirname (output_filename)) - try: - self.spawn ([self.linker] + ld_args) - except DistutilsExecError, msg: - raise LinkError, msg - - else: - log.debug("skipping %s (up-to-date)", output_filename) - - # link () - - - # -- Miscellaneous methods ----------------------------------------- - # These are all used by the 'gen_lib_options() function, in - # ccompiler.py. - - def library_dir_option (self, dir): - return "/LIBPATH:" + dir - - def runtime_library_dir_option (self, dir): - raise DistutilsPlatformError, \ - "don't know how to set runtime library search path for MSVC++" - - def library_option (self, lib): - return self.library_filename (lib) - - - def find_library_file (self, dirs, lib, debug=0): - # Prefer a debugging library if found (and requested), but deal - # with it if we don't have one. - if debug: - try_names = [lib + "_d", lib] - else: - try_names = [lib] - for dir in dirs: - for name in try_names: - libfile = os.path.join(dir, self.library_filename (name)) - if os.path.exists(libfile): - return libfile - else: - # Oops, didn't find it in *any* of 'dirs' - return None - - # find_library_file () - - # Helper methods for using the MSVC registry settings - - def find_exe(self, exe): - """Return path to an MSVC executable program. - - Tries to find the program in several places: first, one of the - MSVC program search paths from the registry; next, the directories - in the PATH environment variable. If any of those work, return an - absolute path that is known to exist. If none of them work, just - return the original program name, 'exe'. - """ - - for p in self.__paths: - fn = os.path.join(os.path.abspath(p), exe) - if os.path.isfile(fn): - return fn - - # didn't find it; try existing path - for p in string.split(os.environ['Path'],';'): - fn = os.path.join(os.path.abspath(p),exe) - if os.path.isfile(fn): - return fn - - return exe - - def get_msvc_paths(self, path, platform='x86'): - """Get a list of devstudio directories (include, lib or path). - - Return a list of strings. The list will be empty if unable to - access the registry or appropriate registry keys not found. - """ - - if not _can_read_reg: - return [] - - path = path + " dirs" - if self.__version >= 7: - key = (r"%s\%0.1f\VC\VC_OBJECTS_PLATFORM_INFO\Win32\Directories" - % (self.__root, self.__version)) - else: - key = (r"%s\6.0\Build System\Components\Platforms" - r"\Win32 (%s)\Directories" % (self.__root, platform)) - - for base in HKEYS: - d = read_values(base, key) - if d: - if self.__version >= 7: - return string.split(self.__macros.sub(d[path]), ";") - else: - return string.split(d[path], ";") - # MSVC 6 seems to create the registry entries we need only when - # the GUI is run. - if self.__version == 6: - for base in HKEYS: - if read_values(base, r"%s\6.0" % self.__root) is not None: - self.warn("It seems you have Visual Studio 6 installed, " - "but the expected registry settings are not present.\n" - "You must at least run the Visual Studio GUI once " - "so that these entries are created.") - break - return [] - - def set_path_env_var(self, name): - """Set environment variable 'name' to an MSVC path type value. - - This is equivalent to a SET command prior to execution of spawned - commands. - """ - - if name == "lib": - p = self.get_msvc_paths("library") - else: - p = self.get_msvc_paths(name) - if p: - os.environ[name] = string.join(p, ';') - - -if get_build_version() >= 8.0: - log.debug("Importing new compiler from distutils.msvc9compiler") - OldMSVCCompiler = MSVCCompiler - from distutils.msvc9compiler import MSVCCompiler - # get_build_architecture not really relevant now we support cross-compile - from distutils.msvc9compiler import MacroExpander diff --git a/PythonLib/extra/distutils/spawn.py b/PythonLib/extra/distutils/spawn.py deleted file mode 100644 index 7306099f..00000000 --- a/PythonLib/extra/distutils/spawn.py +++ /dev/null @@ -1,199 +0,0 @@ -"""distutils.spawn - -Provides the 'spawn()' function, a front-end to various platform- -specific functions for launching another program in a sub-process. -Also provides the 'find_executable()' to search the path for a given -executable name. -""" - -__revision__ = "$Id$" - -import sys -import os - -from distutils.errors import DistutilsPlatformError, DistutilsExecError -from distutils import log - -def spawn(cmd, search_path=1, verbose=0, dry_run=0): - """Run another program, specified as a command list 'cmd', in a new process. - - 'cmd' is just the argument list for the new process, ie. - cmd[0] is the program to run and cmd[1:] are the rest of its arguments. - There is no way to run a program with a name different from that of its - executable. - - If 'search_path' is true (the default), the system's executable - search path will be used to find the program; otherwise, cmd[0] - must be the exact path to the executable. If 'dry_run' is true, - the command will not actually be run. - - Raise DistutilsExecError if running the program fails in any way; just - return on success. - """ - if os.name == 'posix': - _spawn_posix(cmd, search_path, dry_run=dry_run) - elif os.name == 'nt': - _spawn_nt(cmd, search_path, dry_run=dry_run) - elif os.name == 'os2': - _spawn_os2(cmd, search_path, dry_run=dry_run) - else: - raise DistutilsPlatformError, \ - "don't know how to spawn programs on platform '%s'" % os.name - -def _nt_quote_args(args): - """Quote command-line arguments for DOS/Windows conventions. - - Just wraps every argument which contains blanks in double quotes, and - returns a new argument list. - """ - # XXX this doesn't seem very robust to me -- but if the Windows guys - # say it'll work, I guess I'll have to accept it. (What if an arg - # contains quotes? What other magic characters, other than spaces, - # have to be escaped? Is there an escaping mechanism other than - # quoting?) - for i, arg in enumerate(args): - if ' ' in arg: - args[i] = '"%s"' % arg - return args - -def _spawn_nt(cmd, search_path=1, verbose=0, dry_run=0): - executable = cmd[0] - cmd = _nt_quote_args(cmd) - if search_path: - # either we find one or it stays the same - executable = find_executable(executable) or executable - log.info(' '.join([executable] + cmd[1:])) - if not dry_run: - # spawn for NT requires a full path to the .exe - try: - rc = os.spawnv(os.P_WAIT, executable, cmd) - except OSError, exc: - # this seems to happen when the command isn't found - raise DistutilsExecError, \ - "command '%s' failed: %s" % (cmd[0], exc[-1]) - if rc != 0: - # and this reflects the command running but failing - raise DistutilsExecError, \ - "command '%s' failed with exit status %d" % (cmd[0], rc) - -def _spawn_os2(cmd, search_path=1, verbose=0, dry_run=0): - executable = cmd[0] - if search_path: - # either we find one or it stays the same - executable = find_executable(executable) or executable - log.info(' '.join([executable] + cmd[1:])) - if not dry_run: - # spawnv for OS/2 EMX requires a full path to the .exe - try: - rc = os.spawnv(os.P_WAIT, executable, cmd) - except OSError, exc: - # this seems to happen when the command isn't found - raise DistutilsExecError, \ - "command '%s' failed: %s" % (cmd[0], exc[-1]) - if rc != 0: - # and this reflects the command running but failing - log.debug("command '%s' failed with exit status %d" % (cmd[0], rc)) - raise DistutilsExecError, \ - "command '%s' failed with exit status %d" % (cmd[0], rc) - -if sys.platform == 'darwin': - from distutils import sysconfig - _cfg_target = None - _cfg_target_split = None - -def _spawn_posix(cmd, search_path=1, verbose=0, dry_run=0): - log.info(' '.join(cmd)) - if dry_run: - return - exec_fn = search_path and os.execvp or os.execv - exec_args = [cmd[0], cmd] - if sys.platform == 'darwin': - global _cfg_target, _cfg_target_split - if _cfg_target is None: - _cfg_target = sysconfig.get_config_var( - 'MACOSX_DEPLOYMENT_TARGET') or '' - if _cfg_target: - _cfg_target_split = [int(x) for x in _cfg_target.split('.')] - if _cfg_target: - # ensure that the deployment target of build process is not less - # than that used when the interpreter was built. This ensures - # extension modules are built with correct compatibility values - cur_target = os.environ.get('MACOSX_DEPLOYMENT_TARGET', _cfg_target) - if _cfg_target_split > [int(x) for x in cur_target.split('.')]: - my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: ' - 'now "%s" but "%s" during configure' - % (cur_target, _cfg_target)) - raise DistutilsPlatformError(my_msg) - env = dict(os.environ, - MACOSX_DEPLOYMENT_TARGET=cur_target) - exec_fn = search_path and os.execvpe or os.execve - exec_args.append(env) - pid = os.fork() - - if pid == 0: # in the child - try: - exec_fn(*exec_args) - except OSError, e: - sys.stderr.write("unable to execute %s: %s\n" % - (cmd[0], e.strerror)) - os._exit(1) - - sys.stderr.write("unable to execute %s for unknown reasons" % cmd[0]) - os._exit(1) - else: # in the parent - # Loop until the child either exits or is terminated by a signal - # (ie. keep waiting if it's merely stopped) - while 1: - try: - pid, status = os.waitpid(pid, 0) - except OSError, exc: - import errno - if exc.errno == errno.EINTR: - continue - raise DistutilsExecError, \ - "command '%s' failed: %s" % (cmd[0], exc[-1]) - if os.WIFSIGNALED(status): - raise DistutilsExecError, \ - "command '%s' terminated by signal %d" % \ - (cmd[0], os.WTERMSIG(status)) - - elif os.WIFEXITED(status): - exit_status = os.WEXITSTATUS(status) - if exit_status == 0: - return # hey, it succeeded! - else: - raise DistutilsExecError, \ - "command '%s' failed with exit status %d" % \ - (cmd[0], exit_status) - - elif os.WIFSTOPPED(status): - continue - - else: - raise DistutilsExecError, \ - "unknown error executing '%s': termination status %d" % \ - (cmd[0], status) - -def find_executable(executable, path=None): - """Tries to find 'executable' in the directories listed in 'path'. - - A string listing directories separated by 'os.pathsep'; defaults to - os.environ['PATH']. Returns the complete filename or None if not found. - """ - if path is None: - path = os.environ['PATH'] - paths = path.split(os.pathsep) - base, ext = os.path.splitext(executable) - - if (sys.platform == 'win32' or os.name == 'os2') and (ext != '.exe'): - executable = executable + '.exe' - - if not os.path.isfile(executable): - for p in paths: - f = os.path.join(p, executable) - if os.path.isfile(f): - # the file exists, we have a shot at spawn working - return f - return None - else: - return executable diff --git a/PythonLib/extra/distutils/sysconfig.py b/PythonLib/extra/distutils/sysconfig.py deleted file mode 100644 index 4aa93346..00000000 --- a/PythonLib/extra/distutils/sysconfig.py +++ /dev/null @@ -1,482 +0,0 @@ -"""Provide access to Python's configuration information. The specific -configuration variables available depend heavily on the platform and -configuration. The values may be retrieved using -get_config_var(name), and the list of variables is available via -get_config_vars().keys(). Additional convenience functions are also -available. - -Written by: Fred L. Drake, Jr. -Email: -""" - -__revision__ = "$Id$" - -import os -import re -import string -import sys - -from distutils.errors import DistutilsPlatformError - -# These are needed in a couple of spots, so just compute them once. -PREFIX = os.path.normpath(sys.prefix) -EXEC_PREFIX = os.path.normpath(sys.exec_prefix) - -# Path to the base directory of the project. On Windows the binary may -# live in project/PCBuild9. If we're dealing with an x64 Windows build, -# it'll live in project/PCbuild/amd64. -project_base = os.path.dirname(os.path.abspath(sys.executable)) -if os.name == "nt" and "pcbuild" in project_base[-8:].lower(): - project_base = os.path.abspath(os.path.join(project_base, os.path.pardir)) -# PC/VS7.1 -if os.name == "nt" and "\\pc\\v" in project_base[-10:].lower(): - project_base = os.path.abspath(os.path.join(project_base, os.path.pardir, - os.path.pardir)) -# PC/AMD64 -if os.name == "nt" and "\\pcbuild\\amd64" in project_base[-14:].lower(): - project_base = os.path.abspath(os.path.join(project_base, os.path.pardir, - os.path.pardir)) - -# set for cross builds -if "_PYTHON_PROJECT_BASE" in os.environ: - # this is the build directory, at least for posix - project_base = os.path.normpath(os.environ["_PYTHON_PROJECT_BASE"]) - -# python_build: (Boolean) if true, we're either building Python or -# building an extension with an un-installed Python, so we use -# different (hard-wired) directories. -# Setup.local is available for Makefile builds including VPATH builds, -# Setup.dist is available on Windows -def _python_build(): - for fn in ("Setup.dist", "Setup.local"): - if os.path.isfile(os.path.join(project_base, "Modules", fn)): - return True - return False -python_build = _python_build() - - -def get_python_version(): - """Return a string containing the major and minor Python version, - leaving off the patchlevel. Sample return values could be '1.5' - or '2.2'. - """ - return sys.version[:3] - - -def get_python_inc(plat_specific=0, prefix=None): - """Return the directory containing installed Python header files. - - If 'plat_specific' is false (the default), this is the path to the - non-platform-specific header files, i.e. Python.h and so on; - otherwise, this is the path to platform-specific header files - (namely pyconfig.h). - - If 'prefix' is supplied, use it instead of sys.prefix or - sys.exec_prefix -- i.e., ignore 'plat_specific'. - """ - if prefix is None: - prefix = plat_specific and EXEC_PREFIX or PREFIX - - if os.name == "posix": - if python_build: - buildir = os.path.dirname(sys.executable) - if plat_specific: - # python.h is located in the buildir - inc_dir = buildir - else: - # the source dir is relative to the buildir - srcdir = os.path.abspath(os.path.join(buildir, - get_config_var('srcdir'))) - # Include is located in the srcdir - inc_dir = os.path.join(srcdir, "Include") - return inc_dir - return os.path.join(prefix, "include", "python" + get_python_version()) - elif os.name == "nt": - return os.path.join(prefix, "include") - elif os.name == "os2": - return os.path.join(prefix, "Include") - else: - raise DistutilsPlatformError( - "I don't know where Python installs its C header files " - "on platform '%s'" % os.name) - - -def get_python_lib(plat_specific=0, standard_lib=0, prefix=None): - """Return the directory containing the Python library (standard or - site additions). - - If 'plat_specific' is true, return the directory containing - platform-specific modules, i.e. any module from a non-pure-Python - module distribution; otherwise, return the platform-shared library - directory. If 'standard_lib' is true, return the directory - containing standard Python library modules; otherwise, return the - directory for site-specific modules. - - If 'prefix' is supplied, use it instead of sys.prefix or - sys.exec_prefix -- i.e., ignore 'plat_specific'. - """ - if prefix is None: - prefix = plat_specific and EXEC_PREFIX or PREFIX - - if os.name == "posix": - libpython = os.path.join(prefix, - "lib", "python" + get_python_version()) - if standard_lib: - return libpython - else: - return os.path.join(libpython, "site-packages") - - elif os.name == "nt": - if standard_lib: - return os.path.join(prefix, "Lib") - else: - if get_python_version() < "2.2": - return prefix - else: - return os.path.join(prefix, "Lib", "site-packages") - - elif os.name == "os2": - if standard_lib: - return os.path.join(prefix, "Lib") - else: - return os.path.join(prefix, "Lib", "site-packages") - - else: - raise DistutilsPlatformError( - "I don't know where Python installs its library " - "on platform '%s'" % os.name) - - - -def customize_compiler(compiler): - """Do any platform-specific customization of a CCompiler instance. - - Mainly needed on Unix, so we can plug in the information that - varies across Unices and is stored in Python's Makefile. - """ - if compiler.compiler_type == "unix": - if sys.platform == "darwin": - # Perform first-time customization of compiler-related - # config vars on OS X now that we know we need a compiler. - # This is primarily to support Pythons from binary - # installers. The kind and paths to build tools on - # the user system may vary significantly from the system - # that Python itself was built on. Also the user OS - # version and build tools may not support the same set - # of CPU architectures for universal builds. - global _config_vars - if not _config_vars.get('CUSTOMIZED_OSX_COMPILER', ''): - import _osx_support - _osx_support.customize_compiler(_config_vars) - _config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True' - - (cc, cxx, opt, cflags, ccshared, ldshared, so_ext, ar, ar_flags) = \ - get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS', - 'CCSHARED', 'LDSHARED', 'SO', 'AR', - 'ARFLAGS') - - if 'CC' in os.environ: - newcc = os.environ['CC'] - if (sys.platform == 'darwin' - and 'LDSHARED' not in os.environ - and ldshared.startswith(cc)): - # On OS X, if CC is overridden, use that as the default - # command for LDSHARED as well - ldshared = newcc + ldshared[len(cc):] - cc = newcc - if 'CXX' in os.environ: - cxx = os.environ['CXX'] - if 'LDSHARED' in os.environ: - ldshared = os.environ['LDSHARED'] - if 'CPP' in os.environ: - cpp = os.environ['CPP'] - else: - cpp = cc + " -E" # not always - if 'LDFLAGS' in os.environ: - ldshared = ldshared + ' ' + os.environ['LDFLAGS'] - if 'CFLAGS' in os.environ: - cflags = opt + ' ' + os.environ['CFLAGS'] - ldshared = ldshared + ' ' + os.environ['CFLAGS'] - if 'CPPFLAGS' in os.environ: - cpp = cpp + ' ' + os.environ['CPPFLAGS'] - cflags = cflags + ' ' + os.environ['CPPFLAGS'] - ldshared = ldshared + ' ' + os.environ['CPPFLAGS'] - if 'AR' in os.environ: - ar = os.environ['AR'] - if 'ARFLAGS' in os.environ: - archiver = ar + ' ' + os.environ['ARFLAGS'] - else: - archiver = ar + ' ' + ar_flags - - cc_cmd = cc + ' ' + cflags - compiler.set_executables( - preprocessor=cpp, - compiler=cc_cmd, - compiler_so=cc_cmd + ' ' + ccshared, - compiler_cxx=cxx, - linker_so=ldshared, - linker_exe=cc, - archiver=archiver) - - compiler.shared_lib_extension = so_ext - - -def get_config_h_filename(): - """Return full pathname of installed pyconfig.h file.""" - if python_build: - if os.name == "nt": - inc_dir = os.path.join(project_base, "PC") - else: - inc_dir = project_base - else: - inc_dir = get_python_inc(plat_specific=1) - if get_python_version() < '2.2': - config_h = 'config.h' - else: - # The name of the config.h file changed in 2.2 - config_h = 'pyconfig.h' - return os.path.join(inc_dir, config_h) - - -def get_makefile_filename(): - """Return full pathname of installed Makefile from the Python build.""" - if python_build: - return os.path.join(project_base, "Makefile") - lib_dir = get_python_lib(plat_specific=1, standard_lib=1) - return os.path.join(lib_dir, "config", "Makefile") - - -def parse_config_h(fp, g=None): - """Parse a config.h-style file. - - A dictionary containing name/value pairs is returned. If an - optional dictionary is passed in as the second argument, it is - used instead of a new dictionary. - """ - if g is None: - g = {} - define_rx = re.compile("#define ([A-Z][A-Za-z0-9_]+) (.*)\n") - undef_rx = re.compile("/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n") - # - while 1: - line = fp.readline() - if not line: - break - m = define_rx.match(line) - if m: - n, v = m.group(1, 2) - try: v = int(v) - except ValueError: pass - g[n] = v - else: - m = undef_rx.match(line) - if m: - g[m.group(1)] = 0 - return g - - -# Regexes needed for parsing Makefile (and similar syntaxes, -# like old-style Setup files). -_variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)") -_findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)") -_findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}") - -def parse_makefile(fn, g=None): - """Parse a Makefile-style file. - - A dictionary containing name/value pairs is returned. If an - optional dictionary is passed in as the second argument, it is - used instead of a new dictionary. - """ - from distutils.text_file import TextFile - fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1) - - if g is None: - g = {} - done = {} - notdone = {} - - while 1: - line = fp.readline() - if line is None: # eof - break - m = _variable_rx.match(line) - if m: - n, v = m.group(1, 2) - v = v.strip() - # `$$' is a literal `$' in make - tmpv = v.replace('$$', '') - - if "$" in tmpv: - notdone[n] = v - else: - try: - v = int(v) - except ValueError: - # insert literal `$' - done[n] = v.replace('$$', '$') - else: - done[n] = v - - # do variable interpolation here - while notdone: - for name in notdone.keys(): - value = notdone[name] - m = _findvar1_rx.search(value) or _findvar2_rx.search(value) - if m: - n = m.group(1) - found = True - if n in done: - item = str(done[n]) - elif n in notdone: - # get it on a subsequent round - found = False - elif n in os.environ: - # do it like make: fall back to environment - item = os.environ[n] - else: - done[n] = item = "" - if found: - after = value[m.end():] - value = value[:m.start()] + item + after - if "$" in after: - notdone[name] = value - else: - try: value = int(value) - except ValueError: - done[name] = value.strip() - else: - done[name] = value - del notdone[name] - else: - # bogus variable reference; just drop it since we can't deal - del notdone[name] - - fp.close() - - # strip spurious spaces - for k, v in done.items(): - if isinstance(v, str): - done[k] = v.strip() - - # save the results in the global dictionary - g.update(done) - return g - - -def expand_makefile_vars(s, vars): - """Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in - 'string' according to 'vars' (a dictionary mapping variable names to - values). Variables not present in 'vars' are silently expanded to the - empty string. The variable values in 'vars' should not contain further - variable expansions; if 'vars' is the output of 'parse_makefile()', - you're fine. Returns a variable-expanded version of 's'. - """ - - # This algorithm does multiple expansion, so if vars['foo'] contains - # "${bar}", it will expand ${foo} to ${bar}, and then expand - # ${bar}... and so forth. This is fine as long as 'vars' comes from - # 'parse_makefile()', which takes care of such expansions eagerly, - # according to make's variable expansion semantics. - - while 1: - m = _findvar1_rx.search(s) or _findvar2_rx.search(s) - if m: - (beg, end) = m.span() - s = s[0:beg] + vars.get(m.group(1)) + s[end:] - else: - break - return s - - -_config_vars = None - -def _init_posix(): - """Initialize the module as appropriate for POSIX systems.""" - # _sysconfigdata is generated at build time, see the sysconfig module - from _sysconfigdata import build_time_vars - global _config_vars - _config_vars = {} - _config_vars.update(build_time_vars) - - -def _init_nt(): - """Initialize the module as appropriate for NT""" - g = {} - # set basic install directories - g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1) - g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1) - - # XXX hmmm.. a normal install puts include files here - g['INCLUDEPY'] = get_python_inc(plat_specific=0) - - g['SO'] = '.pyd' - g['EXE'] = ".exe" - g['VERSION'] = get_python_version().replace(".", "") - g['BINDIR'] = os.path.dirname(os.path.abspath(sys.executable)) - - global _config_vars - _config_vars = g - - -def _init_os2(): - """Initialize the module as appropriate for OS/2""" - g = {} - # set basic install directories - g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1) - g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1) - - # XXX hmmm.. a normal install puts include files here - g['INCLUDEPY'] = get_python_inc(plat_specific=0) - - g['SO'] = '.pyd' - g['EXE'] = ".exe" - - global _config_vars - _config_vars = g - - -def get_config_vars(*args): - """With no arguments, return a dictionary of all configuration - variables relevant for the current platform. Generally this includes - everything needed to build extensions and install both pure modules and - extensions. On Unix, this means every variable defined in Python's - installed Makefile; on Windows and Mac OS it's a much smaller set. - - With arguments, return a list of values that result from looking up - each argument in the configuration variable dictionary. - """ - global _config_vars - if _config_vars is None: - func = globals().get("_init_" + os.name) - if func: - func() - else: - _config_vars = {} - - # Normalized versions of prefix and exec_prefix are handy to have; - # in fact, these are the standard versions used most places in the - # Distutils. - _config_vars['prefix'] = PREFIX - _config_vars['exec_prefix'] = EXEC_PREFIX - - # OS X platforms require special customization to handle - # multi-architecture, multi-os-version installers - if sys.platform == 'darwin': - import _osx_support - _osx_support.customize_config_vars(_config_vars) - - if args: - vals = [] - for name in args: - vals.append(_config_vars.get(name)) - return vals - else: - return _config_vars - -def get_config_var(name): - """Return the value of a single variable using the dictionary - returned by 'get_config_vars()'. Equivalent to - get_config_vars().get(name) - """ - return get_config_vars().get(name) diff --git a/PythonLib/extra/distutils/text_file.py b/PythonLib/extra/distutils/text_file.py deleted file mode 100644 index 09a798b1..00000000 --- a/PythonLib/extra/distutils/text_file.py +++ /dev/null @@ -1,304 +0,0 @@ -"""text_file - -provides the TextFile class, which gives an interface to text files -that (optionally) takes care of stripping comments, ignoring blank -lines, and joining lines with backslashes.""" - -__revision__ = "$Id$" - -import sys - - -class TextFile: - - """Provides a file-like object that takes care of all the things you - commonly want to do when processing a text file that has some - line-by-line syntax: strip comments (as long as "#" is your - comment character), skip blank lines, join adjacent lines by - escaping the newline (ie. backslash at end of line), strip - leading and/or trailing whitespace. All of these are optional - and independently controllable. - - Provides a 'warn()' method so you can generate warning messages that - report physical line number, even if the logical line in question - spans multiple physical lines. Also provides 'unreadline()' for - implementing line-at-a-time lookahead. - - Constructor is called as: - - TextFile (filename=None, file=None, **options) - - It bombs (RuntimeError) if both 'filename' and 'file' are None; - 'filename' should be a string, and 'file' a file object (or - something that provides 'readline()' and 'close()' methods). It is - recommended that you supply at least 'filename', so that TextFile - can include it in warning messages. If 'file' is not supplied, - TextFile creates its own using the 'open()' builtin. - - The options are all boolean, and affect the value returned by - 'readline()': - strip_comments [default: true] - strip from "#" to end-of-line, as well as any whitespace - leading up to the "#" -- unless it is escaped by a backslash - lstrip_ws [default: false] - strip leading whitespace from each line before returning it - rstrip_ws [default: true] - strip trailing whitespace (including line terminator!) from - each line before returning it - skip_blanks [default: true} - skip lines that are empty *after* stripping comments and - whitespace. (If both lstrip_ws and rstrip_ws are false, - then some lines may consist of solely whitespace: these will - *not* be skipped, even if 'skip_blanks' is true.) - join_lines [default: false] - if a backslash is the last non-newline character on a line - after stripping comments and whitespace, join the following line - to it to form one "logical line"; if N consecutive lines end - with a backslash, then N+1 physical lines will be joined to - form one logical line. - collapse_join [default: false] - strip leading whitespace from lines that are joined to their - predecessor; only matters if (join_lines and not lstrip_ws) - - Note that since 'rstrip_ws' can strip the trailing newline, the - semantics of 'readline()' must differ from those of the builtin file - object's 'readline()' method! In particular, 'readline()' returns - None for end-of-file: an empty string might just be a blank line (or - an all-whitespace line), if 'rstrip_ws' is true but 'skip_blanks' is - not.""" - - default_options = { 'strip_comments': 1, - 'skip_blanks': 1, - 'lstrip_ws': 0, - 'rstrip_ws': 1, - 'join_lines': 0, - 'collapse_join': 0, - } - - def __init__ (self, filename=None, file=None, **options): - """Construct a new TextFile object. At least one of 'filename' - (a string) and 'file' (a file-like object) must be supplied. - They keyword argument options are described above and affect - the values returned by 'readline()'.""" - - if filename is None and file is None: - raise RuntimeError, \ - "you must supply either or both of 'filename' and 'file'" - - # set values for all options -- either from client option hash - # or fallback to default_options - for opt in self.default_options.keys(): - if opt in options: - setattr (self, opt, options[opt]) - - else: - setattr (self, opt, self.default_options[opt]) - - # sanity check client option hash - for opt in options.keys(): - if opt not in self.default_options: - raise KeyError, "invalid TextFile option '%s'" % opt - - if file is None: - self.open (filename) - else: - self.filename = filename - self.file = file - self.current_line = 0 # assuming that file is at BOF! - - # 'linebuf' is a stack of lines that will be emptied before we - # actually read from the file; it's only populated by an - # 'unreadline()' operation - self.linebuf = [] - - - def open (self, filename): - """Open a new file named 'filename'. This overrides both the - 'filename' and 'file' arguments to the constructor.""" - - self.filename = filename - self.file = open (self.filename, 'r') - self.current_line = 0 - - - def close (self): - """Close the current file and forget everything we know about it - (filename, current line number).""" - - self.file.close () - self.file = None - self.filename = None - self.current_line = None - - - def gen_error (self, msg, line=None): - outmsg = [] - if line is None: - line = self.current_line - outmsg.append(self.filename + ", ") - if isinstance(line, (list, tuple)): - outmsg.append("lines %d-%d: " % tuple (line)) - else: - outmsg.append("line %d: " % line) - outmsg.append(str(msg)) - return ''.join(outmsg) - - - def error (self, msg, line=None): - raise ValueError, "error: " + self.gen_error(msg, line) - - def warn (self, msg, line=None): - """Print (to stderr) a warning message tied to the current logical - line in the current file. If the current logical line in the - file spans multiple physical lines, the warning refers to the - whole range, eg. "lines 3-5". If 'line' supplied, it overrides - the current line number; it may be a list or tuple to indicate a - range of physical lines, or an integer for a single physical - line.""" - sys.stderr.write("warning: " + self.gen_error(msg, line) + "\n") - - - def readline (self): - """Read and return a single logical line from the current file (or - from an internal buffer if lines have previously been "unread" - with 'unreadline()'). If the 'join_lines' option is true, this - may involve reading multiple physical lines concatenated into a - single string. Updates the current line number, so calling - 'warn()' after 'readline()' emits a warning about the physical - line(s) just read. Returns None on end-of-file, since the empty - string can occur if 'rstrip_ws' is true but 'strip_blanks' is - not.""" - - # If any "unread" lines waiting in 'linebuf', return the top - # one. (We don't actually buffer read-ahead data -- lines only - # get put in 'linebuf' if the client explicitly does an - # 'unreadline()'. - if self.linebuf: - line = self.linebuf[-1] - del self.linebuf[-1] - return line - - buildup_line = '' - - while 1: - # read the line, make it None if EOF - line = self.file.readline() - if line == '': line = None - - if self.strip_comments and line: - - # Look for the first "#" in the line. If none, never - # mind. If we find one and it's the first character, or - # is not preceded by "\", then it starts a comment -- - # strip the comment, strip whitespace before it, and - # carry on. Otherwise, it's just an escaped "#", so - # unescape it (and any other escaped "#"'s that might be - # lurking in there) and otherwise leave the line alone. - - pos = line.find("#") - if pos == -1: # no "#" -- no comments - pass - - # It's definitely a comment -- either "#" is the first - # character, or it's elsewhere and unescaped. - elif pos == 0 or line[pos-1] != "\\": - # Have to preserve the trailing newline, because it's - # the job of a later step (rstrip_ws) to remove it -- - # and if rstrip_ws is false, we'd better preserve it! - # (NB. this means that if the final line is all comment - # and has no trailing newline, we will think that it's - # EOF; I think that's OK.) - eol = (line[-1] == '\n') and '\n' or '' - line = line[0:pos] + eol - - # If all that's left is whitespace, then skip line - # *now*, before we try to join it to 'buildup_line' -- - # that way constructs like - # hello \\ - # # comment that should be ignored - # there - # result in "hello there". - if line.strip() == "": - continue - - else: # it's an escaped "#" - line = line.replace("\\#", "#") - - - # did previous line end with a backslash? then accumulate - if self.join_lines and buildup_line: - # oops: end of file - if line is None: - self.warn ("continuation line immediately precedes " - "end-of-file") - return buildup_line - - if self.collapse_join: - line = line.lstrip() - line = buildup_line + line - - # careful: pay attention to line number when incrementing it - if isinstance(self.current_line, list): - self.current_line[1] = self.current_line[1] + 1 - else: - self.current_line = [self.current_line, - self.current_line+1] - # just an ordinary line, read it as usual - else: - if line is None: # eof - return None - - # still have to be careful about incrementing the line number! - if isinstance(self.current_line, list): - self.current_line = self.current_line[1] + 1 - else: - self.current_line = self.current_line + 1 - - - # strip whitespace however the client wants (leading and - # trailing, or one or the other, or neither) - if self.lstrip_ws and self.rstrip_ws: - line = line.strip() - elif self.lstrip_ws: - line = line.lstrip() - elif self.rstrip_ws: - line = line.rstrip() - - # blank line (whether we rstrip'ed or not)? skip to next line - # if appropriate - if (line == '' or line == '\n') and self.skip_blanks: - continue - - if self.join_lines: - if line[-1] == '\\': - buildup_line = line[:-1] - continue - - if line[-2:] == '\\\n': - buildup_line = line[0:-2] + '\n' - continue - - # well, I guess there's some actual content there: return it - return line - - # readline () - - - def readlines (self): - """Read and return the list of all logical lines remaining in the - current file.""" - - lines = [] - while 1: - line = self.readline() - if line is None: - return lines - lines.append (line) - - - def unreadline (self, line): - """Push 'line' (a string) onto an internal buffer that will be - checked by future 'readline()' calls. Handy for implementing - a parser with line-at-a-time lookahead.""" - - self.linebuf.append (line) diff --git a/PythonLib/extra/distutils/unixccompiler.py b/PythonLib/extra/distutils/unixccompiler.py deleted file mode 100644 index 2aa1cb1d..00000000 --- a/PythonLib/extra/distutils/unixccompiler.py +++ /dev/null @@ -1,288 +0,0 @@ -"""distutils.unixccompiler - -Contains the UnixCCompiler class, a subclass of CCompiler that handles -the "typical" Unix-style command-line C compiler: - * macros defined with -Dname[=value] - * macros undefined with -Uname - * include search directories specified with -Idir - * libraries specified with -lllib - * library search directories specified with -Ldir - * compile handled by 'cc' (or similar) executable with -c option: - compiles .c to .o - * link static library handled by 'ar' command (possibly with 'ranlib') - * link shared library handled by 'cc -shared' -""" - -__revision__ = "$Id$" - -import os, sys, re -from types import StringType, NoneType - -from distutils import sysconfig -from distutils.dep_util import newer -from distutils.ccompiler import \ - CCompiler, gen_preprocess_options, gen_lib_options -from distutils.errors import \ - DistutilsExecError, CompileError, LibError, LinkError -from distutils import log - -if sys.platform == 'darwin': - import _osx_support - -# XXX Things not currently handled: -# * optimization/debug/warning flags; we just use whatever's in Python's -# Makefile and live with it. Is this adequate? If not, we might -# have to have a bunch of subclasses GNUCCompiler, SGICCompiler, -# SunCCompiler, and I suspect down that road lies madness. -# * even if we don't know a warning flag from an optimization flag, -# we need some way for outsiders to feed preprocessor/compiler/linker -# flags in to us -- eg. a sysadmin might want to mandate certain flags -# via a site config file, or a user might want to set something for -# compiling this module distribution only via the setup.py command -# line, whatever. As long as these options come from something on the -# current system, they can be as system-dependent as they like, and we -# should just happily stuff them into the preprocessor/compiler/linker -# options and carry on. - - -class UnixCCompiler(CCompiler): - - compiler_type = 'unix' - - # These are used by CCompiler in two places: the constructor sets - # instance attributes 'preprocessor', 'compiler', etc. from them, and - # 'set_executable()' allows any of these to be set. The defaults here - # are pretty generic; they will probably have to be set by an outsider - # (eg. using information discovered by the sysconfig about building - # Python extensions). - executables = {'preprocessor' : None, - 'compiler' : ["cc"], - 'compiler_so' : ["cc"], - 'compiler_cxx' : ["cc"], - 'linker_so' : ["cc", "-shared"], - 'linker_exe' : ["cc"], - 'archiver' : ["ar", "-cr"], - 'ranlib' : None, - } - - if sys.platform[:6] == "darwin": - executables['ranlib'] = ["ranlib"] - - # Needed for the filename generation methods provided by the base - # class, CCompiler. NB. whoever instantiates/uses a particular - # UnixCCompiler instance should set 'shared_lib_ext' -- we set a - # reasonable common default here, but it's not necessarily used on all - # Unices! - - src_extensions = [".c",".C",".cc",".cxx",".cpp",".m"] - obj_extension = ".o" - static_lib_extension = ".a" - shared_lib_extension = ".so" - dylib_lib_extension = ".dylib" - static_lib_format = shared_lib_format = dylib_lib_format = "lib%s%s" - if sys.platform == "cygwin": - exe_extension = ".exe" - - def preprocess(self, source, - output_file=None, macros=None, include_dirs=None, - extra_preargs=None, extra_postargs=None): - ignore, macros, include_dirs = \ - self._fix_compile_args(None, macros, include_dirs) - pp_opts = gen_preprocess_options(macros, include_dirs) - pp_args = self.preprocessor + pp_opts - if output_file: - pp_args.extend(['-o', output_file]) - if extra_preargs: - pp_args[:0] = extra_preargs - if extra_postargs: - pp_args.extend(extra_postargs) - pp_args.append(source) - - # We need to preprocess: either we're being forced to, or we're - # generating output to stdout, or there's a target output file and - # the source file is newer than the target (or the target doesn't - # exist). - if self.force or output_file is None or newer(source, output_file): - if output_file: - self.mkpath(os.path.dirname(output_file)) - try: - self.spawn(pp_args) - except DistutilsExecError, msg: - raise CompileError, msg - - def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts): - compiler_so = self.compiler_so - if sys.platform == 'darwin': - compiler_so = _osx_support.compiler_fixup(compiler_so, - cc_args + extra_postargs) - try: - self.spawn(compiler_so + cc_args + [src, '-o', obj] + - extra_postargs) - except DistutilsExecError, msg: - raise CompileError, msg - - def create_static_lib(self, objects, output_libname, - output_dir=None, debug=0, target_lang=None): - objects, output_dir = self._fix_object_args(objects, output_dir) - - output_filename = \ - self.library_filename(output_libname, output_dir=output_dir) - - if self._need_link(objects, output_filename): - self.mkpath(os.path.dirname(output_filename)) - self.spawn(self.archiver + - [output_filename] + - objects + self.objects) - - # Not many Unices required ranlib anymore -- SunOS 4.x is, I - # think the only major Unix that does. Maybe we need some - # platform intelligence here to skip ranlib if it's not - # needed -- or maybe Python's configure script took care of - # it for us, hence the check for leading colon. - if self.ranlib: - try: - self.spawn(self.ranlib + [output_filename]) - except DistutilsExecError, msg: - raise LibError, msg - else: - log.debug("skipping %s (up-to-date)", output_filename) - - def link(self, target_desc, objects, - output_filename, output_dir=None, libraries=None, - library_dirs=None, runtime_library_dirs=None, - export_symbols=None, debug=0, extra_preargs=None, - extra_postargs=None, build_temp=None, target_lang=None): - objects, output_dir = self._fix_object_args(objects, output_dir) - libraries, library_dirs, runtime_library_dirs = \ - self._fix_lib_args(libraries, library_dirs, runtime_library_dirs) - - lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs, - libraries) - if type(output_dir) not in (StringType, NoneType): - raise TypeError, "'output_dir' must be a string or None" - if output_dir is not None: - output_filename = os.path.join(output_dir, output_filename) - - if self._need_link(objects, output_filename): - ld_args = (objects + self.objects + - lib_opts + ['-o', output_filename]) - if debug: - ld_args[:0] = ['-g'] - if extra_preargs: - ld_args[:0] = extra_preargs - if extra_postargs: - ld_args.extend(extra_postargs) - self.mkpath(os.path.dirname(output_filename)) - try: - if target_desc == CCompiler.EXECUTABLE: - linker = self.linker_exe[:] - else: - linker = self.linker_so[:] - if target_lang == "c++" and self.compiler_cxx: - # skip over environment variable settings if /usr/bin/env - # is used to set up the linker's environment. - # This is needed on OSX. Note: this assumes that the - # normal and C++ compiler have the same environment - # settings. - i = 0 - if os.path.basename(linker[0]) == "env": - i = 1 - while '=' in linker[i]: - i = i + 1 - - linker[i] = self.compiler_cxx[i] - - if sys.platform == 'darwin': - linker = _osx_support.compiler_fixup(linker, ld_args) - - self.spawn(linker + ld_args) - except DistutilsExecError, msg: - raise LinkError, msg - else: - log.debug("skipping %s (up-to-date)", output_filename) - - # -- Miscellaneous methods ----------------------------------------- - # These are all used by the 'gen_lib_options() function, in - # ccompiler.py. - - def library_dir_option(self, dir): - return "-L" + dir - - def _is_gcc(self, compiler_name): - return "gcc" in compiler_name or "g++" in compiler_name - - def runtime_library_dir_option(self, dir): - # XXX Hackish, at the very least. See Python bug #445902: - # http://sourceforge.net/tracker/index.php - # ?func=detail&aid=445902&group_id=5470&atid=105470 - # Linkers on different platforms need different options to - # specify that directories need to be added to the list of - # directories searched for dependencies when a dynamic library - # is sought. GCC has to be told to pass the -R option through - # to the linker, whereas other compilers just know this. - # Other compilers may need something slightly different. At - # this time, there's no way to determine this information from - # the configuration data stored in the Python installation, so - # we use this hack. - compiler = os.path.basename(sysconfig.get_config_var("CC")) - if sys.platform[:6] == "darwin": - # MacOSX's linker doesn't understand the -R flag at all - return "-L" + dir - elif sys.platform[:5] == "hp-ux": - if self._is_gcc(compiler): - return ["-Wl,+s", "-L" + dir] - return ["+s", "-L" + dir] - elif sys.platform[:7] == "irix646" or sys.platform[:6] == "osf1V5": - return ["-rpath", dir] - elif self._is_gcc(compiler): - return "-Wl,-R" + dir - else: - return "-R" + dir - - def library_option(self, lib): - return "-l" + lib - - def find_library_file(self, dirs, lib, debug=0): - shared_f = self.library_filename(lib, lib_type='shared') - dylib_f = self.library_filename(lib, lib_type='dylib') - static_f = self.library_filename(lib, lib_type='static') - - if sys.platform == 'darwin': - # On OSX users can specify an alternate SDK using - # '-isysroot', calculate the SDK root if it is specified - # (and use it further on) - cflags = sysconfig.get_config_var('CFLAGS') - m = re.search(r'-isysroot\s+(\S+)', cflags) - if m is None: - sysroot = '/' - else: - sysroot = m.group(1) - - - - for dir in dirs: - shared = os.path.join(dir, shared_f) - dylib = os.path.join(dir, dylib_f) - static = os.path.join(dir, static_f) - - if sys.platform == 'darwin' and ( - dir.startswith('/System/') or ( - dir.startswith('/usr/') and not dir.startswith('/usr/local/'))): - - shared = os.path.join(sysroot, dir[1:], shared_f) - dylib = os.path.join(sysroot, dir[1:], dylib_f) - static = os.path.join(sysroot, dir[1:], static_f) - - # We're second-guessing the linker here, with not much hard - # data to go on: GCC seems to prefer the shared library, so I'm - # assuming that *all* Unix C compilers do. And of course I'm - # ignoring even GCC's "-static" option. So sue me. - if os.path.exists(dylib): - return dylib - elif os.path.exists(shared): - return shared - elif os.path.exists(static): - return static - - # Oops, didn't find it in *any* of 'dirs' - return None diff --git a/PythonLib/extra/distutils/util.py b/PythonLib/extra/distutils/util.py deleted file mode 100644 index ea6ed8a9..00000000 --- a/PythonLib/extra/distutils/util.py +++ /dev/null @@ -1,492 +0,0 @@ -"""distutils.util - -Miscellaneous utility functions -- anything that doesn't fit into -one of the other *util.py modules. -""" - -__revision__ = "$Id$" - -import sys, os, string, re -from distutils.errors import DistutilsPlatformError -from distutils.dep_util import newer -from distutils.spawn import spawn -from distutils import log -from distutils.errors import DistutilsByteCompileError - -def get_platform (): - """Return a string that identifies the current platform. This is used - mainly to distinguish platform-specific build directories and - platform-specific built distributions. Typically includes the OS name - and version and the architecture (as supplied by 'os.uname()'), - although the exact information included depends on the OS; eg. for IRIX - the architecture isn't particularly important (IRIX only runs on SGI - hardware), but for Linux the kernel version isn't particularly - important. - - Examples of returned values: - linux-i586 - linux-alpha (?) - solaris-2.6-sun4u - irix-5.3 - irix64-6.2 - - Windows will return one of: - win-amd64 (64bit Windows on AMD64 (aka x86_64, Intel64, EM64T, etc) - win-ia64 (64bit Windows on Itanium) - win32 (all others - specifically, sys.platform is returned) - - For other non-POSIX platforms, currently just returns 'sys.platform'. - """ - if os.name == 'nt': - # sniff sys.version for architecture. - prefix = " bit (" - i = string.find(sys.version, prefix) - if i == -1: - return sys.platform - j = string.find(sys.version, ")", i) - look = sys.version[i+len(prefix):j].lower() - if look=='amd64': - return 'win-amd64' - if look=='itanium': - return 'win-ia64' - return sys.platform - - # Set for cross builds explicitly - if "_PYTHON_HOST_PLATFORM" in os.environ: - return os.environ["_PYTHON_HOST_PLATFORM"] - - if os.name != "posix" or not hasattr(os, 'uname'): - # XXX what about the architecture? NT is Intel or Alpha, - # Mac OS is M68k or PPC, etc. - return sys.platform - - # Try to distinguish various flavours of Unix - - (osname, host, release, version, machine) = os.uname() - - # Convert the OS name to lowercase, remove '/' characters - # (to accommodate BSD/OS), and translate spaces (for "Power Macintosh") - osname = string.lower(osname) - osname = string.replace(osname, '/', '') - machine = string.replace(machine, ' ', '_') - machine = string.replace(machine, '/', '-') - - if osname[:5] == "linux": - # At least on Linux/Intel, 'machine' is the processor -- - # i386, etc. - # XXX what about Alpha, SPARC, etc? - return "%s-%s" % (osname, machine) - elif osname[:5] == "sunos": - if release[0] >= "5": # SunOS 5 == Solaris 2 - osname = "solaris" - release = "%d.%s" % (int(release[0]) - 3, release[2:]) - # We can't use "platform.architecture()[0]" because a - # bootstrap problem. We use a dict to get an error - # if some suspicious happens. - bitness = {2147483647:"32bit", 9223372036854775807:"64bit"} - machine += ".%s" % bitness[sys.maxint] - # fall through to standard osname-release-machine representation - elif osname[:4] == "irix": # could be "irix64"! - return "%s-%s" % (osname, release) - elif osname[:3] == "aix": - return "%s-%s.%s" % (osname, version, release) - elif osname[:6] == "cygwin": - osname = "cygwin" - rel_re = re.compile (r'[\d.]+') - m = rel_re.match(release) - if m: - release = m.group() - elif osname[:6] == "darwin": - import _osx_support, distutils.sysconfig - osname, release, machine = _osx_support.get_platform_osx( - distutils.sysconfig.get_config_vars(), - osname, release, machine) - - return "%s-%s-%s" % (osname, release, machine) - -# get_platform () - - -def convert_path (pathname): - """Return 'pathname' as a name that will work on the native filesystem, - i.e. split it on '/' and put it back together again using the current - directory separator. Needed because filenames in the setup script are - always supplied in Unix style, and have to be converted to the local - convention before we can actually use them in the filesystem. Raises - ValueError on non-Unix-ish systems if 'pathname' either starts or - ends with a slash. - """ - if os.sep == '/': - return pathname - if not pathname: - return pathname - if pathname[0] == '/': - raise ValueError, "path '%s' cannot be absolute" % pathname - if pathname[-1] == '/': - raise ValueError, "path '%s' cannot end with '/'" % pathname - - paths = string.split(pathname, '/') - while '.' in paths: - paths.remove('.') - if not paths: - return os.curdir - return os.path.join(*paths) - -# convert_path () - - -def change_root (new_root, pathname): - """Return 'pathname' with 'new_root' prepended. If 'pathname' is - relative, this is equivalent to "os.path.join(new_root,pathname)". - Otherwise, it requires making 'pathname' relative and then joining the - two, which is tricky on DOS/Windows and Mac OS. - """ - if os.name == 'posix': - if not os.path.isabs(pathname): - return os.path.join(new_root, pathname) - else: - return os.path.join(new_root, pathname[1:]) - - elif os.name == 'nt': - (drive, path) = os.path.splitdrive(pathname) - if path[0] == '\\': - path = path[1:] - return os.path.join(new_root, path) - - elif os.name == 'os2': - (drive, path) = os.path.splitdrive(pathname) - if path[0] == os.sep: - path = path[1:] - return os.path.join(new_root, path) - - else: - raise DistutilsPlatformError, \ - "nothing known about platform '%s'" % os.name - - -_environ_checked = 0 -def check_environ (): - """Ensure that 'os.environ' has all the environment variables we - guarantee that users can use in config files, command-line options, - etc. Currently this includes: - HOME - user's home directory (Unix only) - PLAT - description of the current platform, including hardware - and OS (see 'get_platform()') - """ - global _environ_checked - if _environ_checked: - return - - if os.name == 'posix' and 'HOME' not in os.environ: - import pwd - os.environ['HOME'] = pwd.getpwuid(os.getuid())[5] - - if 'PLAT' not in os.environ: - os.environ['PLAT'] = get_platform() - - _environ_checked = 1 - - -def subst_vars (s, local_vars): - """Perform shell/Perl-style variable substitution on 'string'. Every - occurrence of '$' followed by a name is considered a variable, and - variable is substituted by the value found in the 'local_vars' - dictionary, or in 'os.environ' if it's not in 'local_vars'. - 'os.environ' is first checked/augmented to guarantee that it contains - certain values: see 'check_environ()'. Raise ValueError for any - variables not found in either 'local_vars' or 'os.environ'. - """ - check_environ() - def _subst (match, local_vars=local_vars): - var_name = match.group(1) - if var_name in local_vars: - return str(local_vars[var_name]) - else: - return os.environ[var_name] - - try: - return re.sub(r'\$([a-zA-Z_][a-zA-Z_0-9]*)', _subst, s) - except KeyError, var: - raise ValueError, "invalid variable '$%s'" % var - -# subst_vars () - - -def grok_environment_error (exc, prefix="error: "): - """Generate a useful error message from an EnvironmentError (IOError or - OSError) exception object. Handles Python 1.5.1 and 1.5.2 styles, and - does what it can to deal with exception objects that don't have a - filename (which happens when the error is due to a two-file operation, - such as 'rename()' or 'link()'. Returns the error message as a string - prefixed with 'prefix'. - """ - # check for Python 1.5.2-style {IO,OS}Error exception objects - if hasattr(exc, 'filename') and hasattr(exc, 'strerror'): - if exc.filename: - error = prefix + "%s: %s" % (exc.filename, exc.strerror) - else: - # two-argument functions in posix module don't - # include the filename in the exception object! - error = prefix + "%s" % exc.strerror - else: - error = prefix + str(exc[-1]) - - return error - - -# Needed by 'split_quoted()' -_wordchars_re = _squote_re = _dquote_re = None -def _init_regex(): - global _wordchars_re, _squote_re, _dquote_re - _wordchars_re = re.compile(r'[^\\\'\"%s ]*' % string.whitespace) - _squote_re = re.compile(r"'(?:[^'\\]|\\.)*'") - _dquote_re = re.compile(r'"(?:[^"\\]|\\.)*"') - -def split_quoted (s): - """Split a string up according to Unix shell-like rules for quotes and - backslashes. In short: words are delimited by spaces, as long as those - spaces are not escaped by a backslash, or inside a quoted string. - Single and double quotes are equivalent, and the quote characters can - be backslash-escaped. The backslash is stripped from any two-character - escape sequence, leaving only the escaped character. The quote - characters are stripped from any quoted string. Returns a list of - words. - """ - - # This is a nice algorithm for splitting up a single string, since it - # doesn't require character-by-character examination. It was a little - # bit of a brain-bender to get it working right, though... - if _wordchars_re is None: _init_regex() - - s = string.strip(s) - words = [] - pos = 0 - - while s: - m = _wordchars_re.match(s, pos) - end = m.end() - if end == len(s): - words.append(s[:end]) - break - - if s[end] in string.whitespace: # unescaped, unquoted whitespace: now - words.append(s[:end]) # we definitely have a word delimiter - s = string.lstrip(s[end:]) - pos = 0 - - elif s[end] == '\\': # preserve whatever is being escaped; - # will become part of the current word - s = s[:end] + s[end+1:] - pos = end+1 - - else: - if s[end] == "'": # slurp singly-quoted string - m = _squote_re.match(s, end) - elif s[end] == '"': # slurp doubly-quoted string - m = _dquote_re.match(s, end) - else: - raise RuntimeError, \ - "this can't happen (bad char '%c')" % s[end] - - if m is None: - raise ValueError, \ - "bad string (mismatched %s quotes?)" % s[end] - - (beg, end) = m.span() - s = s[:beg] + s[beg+1:end-1] + s[end:] - pos = m.end() - 2 - - if pos >= len(s): - words.append(s) - break - - return words - -# split_quoted () - - -def execute (func, args, msg=None, verbose=0, dry_run=0): - """Perform some action that affects the outside world (eg. by - writing to the filesystem). Such actions are special because they - are disabled by the 'dry_run' flag. This method takes care of all - that bureaucracy for you; all you have to do is supply the - function to call and an argument tuple for it (to embody the - "external action" being performed), and an optional message to - print. - """ - if msg is None: - msg = "%s%r" % (func.__name__, args) - if msg[-2:] == ',)': # correct for singleton tuple - msg = msg[0:-2] + ')' - - log.info(msg) - if not dry_run: - func(*args) - - -def strtobool (val): - """Convert a string representation of truth to true (1) or false (0). - - True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values - are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if - 'val' is anything else. - """ - val = string.lower(val) - if val in ('y', 'yes', 't', 'true', 'on', '1'): - return 1 - elif val in ('n', 'no', 'f', 'false', 'off', '0'): - return 0 - else: - raise ValueError, "invalid truth value %r" % (val,) - - -def byte_compile (py_files, - optimize=0, force=0, - prefix=None, base_dir=None, - verbose=1, dry_run=0, - direct=None): - """Byte-compile a collection of Python source files to either .pyc - or .pyo files in the same directory. 'py_files' is a list of files - to compile; any files that don't end in ".py" are silently skipped. - 'optimize' must be one of the following: - 0 - don't optimize (generate .pyc) - 1 - normal optimization (like "python -O") - 2 - extra optimization (like "python -OO") - If 'force' is true, all files are recompiled regardless of - timestamps. - - The source filename encoded in each bytecode file defaults to the - filenames listed in 'py_files'; you can modify these with 'prefix' and - 'basedir'. 'prefix' is a string that will be stripped off of each - source filename, and 'base_dir' is a directory name that will be - prepended (after 'prefix' is stripped). You can supply either or both - (or neither) of 'prefix' and 'base_dir', as you wish. - - If 'dry_run' is true, doesn't actually do anything that would - affect the filesystem. - - Byte-compilation is either done directly in this interpreter process - with the standard py_compile module, or indirectly by writing a - temporary script and executing it. Normally, you should let - 'byte_compile()' figure out to use direct compilation or not (see - the source for details). The 'direct' flag is used by the script - generated in indirect mode; unless you know what you're doing, leave - it set to None. - """ - # nothing is done if sys.dont_write_bytecode is True - if sys.dont_write_bytecode: - raise DistutilsByteCompileError('byte-compiling is disabled.') - - # First, if the caller didn't force us into direct or indirect mode, - # figure out which mode we should be in. We take a conservative - # approach: choose direct mode *only* if the current interpreter is - # in debug mode and optimize is 0. If we're not in debug mode (-O - # or -OO), we don't know which level of optimization this - # interpreter is running with, so we can't do direct - # byte-compilation and be certain that it's the right thing. Thus, - # always compile indirectly if the current interpreter is in either - # optimize mode, or if either optimization level was requested by - # the caller. - if direct is None: - direct = (__debug__ and optimize == 0) - - # "Indirect" byte-compilation: write a temporary script and then - # run it with the appropriate flags. - if not direct: - try: - from tempfile import mkstemp - (script_fd, script_name) = mkstemp(".py") - except ImportError: - from tempfile import mktemp - (script_fd, script_name) = None, mktemp(".py") - log.info("writing byte-compilation script '%s'", script_name) - if not dry_run: - if script_fd is not None: - script = os.fdopen(script_fd, "w") - else: - script = open(script_name, "w") - - script.write("""\ -from distutils.util import byte_compile -files = [ -""") - - # XXX would be nice to write absolute filenames, just for - # safety's sake (script should be more robust in the face of - # chdir'ing before running it). But this requires abspath'ing - # 'prefix' as well, and that breaks the hack in build_lib's - # 'byte_compile()' method that carefully tacks on a trailing - # slash (os.sep really) to make sure the prefix here is "just - # right". This whole prefix business is rather delicate -- the - # problem is that it's really a directory, but I'm treating it - # as a dumb string, so trailing slashes and so forth matter. - - #py_files = map(os.path.abspath, py_files) - #if prefix: - # prefix = os.path.abspath(prefix) - - script.write(string.join(map(repr, py_files), ",\n") + "]\n") - script.write(""" -byte_compile(files, optimize=%r, force=%r, - prefix=%r, base_dir=%r, - verbose=%r, dry_run=0, - direct=1) -""" % (optimize, force, prefix, base_dir, verbose)) - - script.close() - - cmd = [sys.executable, script_name] - if optimize == 1: - cmd.insert(1, "-O") - elif optimize == 2: - cmd.insert(1, "-OO") - spawn(cmd, dry_run=dry_run) - execute(os.remove, (script_name,), "removing %s" % script_name, - dry_run=dry_run) - - # "Direct" byte-compilation: use the py_compile module to compile - # right here, right now. Note that the script generated in indirect - # mode simply calls 'byte_compile()' in direct mode, a weird sort of - # cross-process recursion. Hey, it works! - else: - from py_compile import compile - - for file in py_files: - if file[-3:] != ".py": - # This lets us be lazy and not filter filenames in - # the "install_lib" command. - continue - - # Terminology from the py_compile module: - # cfile - byte-compiled file - # dfile - purported source filename (same as 'file' by default) - cfile = file + (__debug__ and "c" or "o") - dfile = file - if prefix: - if file[:len(prefix)] != prefix: - raise ValueError, \ - ("invalid prefix: filename %r doesn't start with %r" - % (file, prefix)) - dfile = dfile[len(prefix):] - if base_dir: - dfile = os.path.join(base_dir, dfile) - - cfile_base = os.path.basename(cfile) - if direct: - if force or newer(file, cfile): - log.info("byte-compiling %s to %s", file, cfile_base) - if not dry_run: - compile(file, cfile, dfile) - else: - log.debug("skipping byte-compilation of %s to %s", - file, cfile_base) - -# byte_compile () - -def rfc822_escape (header): - """Return a version of the string escaped for inclusion in an - RFC-822 header, by ensuring there are 8 spaces space after each newline. - """ - lines = string.split(header, '\n') - header = string.join(lines, '\n' + 8*' ') - return header diff --git a/PythonLib/extra/distutils/version.py b/PythonLib/extra/distutils/version.py deleted file mode 100644 index 0fb5b6e2..00000000 --- a/PythonLib/extra/distutils/version.py +++ /dev/null @@ -1,299 +0,0 @@ -# -# distutils/version.py -# -# Implements multiple version numbering conventions for the -# Python Module Distribution Utilities. -# -# $Id$ -# - -"""Provides classes to represent module version numbers (one class for -each style of version numbering). There are currently two such classes -implemented: StrictVersion and LooseVersion. - -Every version number class implements the following interface: - * the 'parse' method takes a string and parses it to some internal - representation; if the string is an invalid version number, - 'parse' raises a ValueError exception - * the class constructor takes an optional string argument which, - if supplied, is passed to 'parse' - * __str__ reconstructs the string that was passed to 'parse' (or - an equivalent string -- ie. one that will generate an equivalent - version number instance) - * __repr__ generates Python code to recreate the version number instance - * __cmp__ compares the current instance with either another instance - of the same class or a string (which will be parsed to an instance - of the same class, thus must follow the same rules) -""" - -import string, re -from types import StringType - -class Version: - """Abstract base class for version numbering classes. Just provides - constructor (__init__) and reproducer (__repr__), because those - seem to be the same for all version numbering classes. - """ - - def __init__ (self, vstring=None): - if vstring: - self.parse(vstring) - - def __repr__ (self): - return "%s ('%s')" % (self.__class__.__name__, str(self)) - - -# Interface for version-number classes -- must be implemented -# by the following classes (the concrete ones -- Version should -# be treated as an abstract class). -# __init__ (string) - create and take same action as 'parse' -# (string parameter is optional) -# parse (string) - convert a string representation to whatever -# internal representation is appropriate for -# this style of version numbering -# __str__ (self) - convert back to a string; should be very similar -# (if not identical to) the string supplied to parse -# __repr__ (self) - generate Python code to recreate -# the instance -# __cmp__ (self, other) - compare two version numbers ('other' may -# be an unparsed version string, or another -# instance of your version class) - - -class StrictVersion (Version): - - """Version numbering for anal retentives and software idealists. - Implements the standard interface for version number classes as - described above. A version number consists of two or three - dot-separated numeric components, with an optional "pre-release" tag - on the end. The pre-release tag consists of the letter 'a' or 'b' - followed by a number. If the numeric components of two version - numbers are equal, then one with a pre-release tag will always - be deemed earlier (lesser) than one without. - - The following are valid version numbers (shown in the order that - would be obtained by sorting according to the supplied cmp function): - - 0.4 0.4.0 (these two are equivalent) - 0.4.1 - 0.5a1 - 0.5b3 - 0.5 - 0.9.6 - 1.0 - 1.0.4a3 - 1.0.4b1 - 1.0.4 - - The following are examples of invalid version numbers: - - 1 - 2.7.2.2 - 1.3.a4 - 1.3pl1 - 1.3c4 - - The rationale for this version numbering system will be explained - in the distutils documentation. - """ - - version_re = re.compile(r'^(\d+) \. (\d+) (\. (\d+))? ([ab](\d+))?$', - re.VERBOSE) - - - def parse (self, vstring): - match = self.version_re.match(vstring) - if not match: - raise ValueError, "invalid version number '%s'" % vstring - - (major, minor, patch, prerelease, prerelease_num) = \ - match.group(1, 2, 4, 5, 6) - - if patch: - self.version = tuple(map(string.atoi, [major, minor, patch])) - else: - self.version = tuple(map(string.atoi, [major, minor]) + [0]) - - if prerelease: - self.prerelease = (prerelease[0], string.atoi(prerelease_num)) - else: - self.prerelease = None - - - def __str__ (self): - - if self.version[2] == 0: - vstring = string.join(map(str, self.version[0:2]), '.') - else: - vstring = string.join(map(str, self.version), '.') - - if self.prerelease: - vstring = vstring + self.prerelease[0] + str(self.prerelease[1]) - - return vstring - - - def __cmp__ (self, other): - if isinstance(other, StringType): - other = StrictVersion(other) - - compare = cmp(self.version, other.version) - if (compare == 0): # have to compare prerelease - - # case 1: neither has prerelease; they're equal - # case 2: self has prerelease, other doesn't; other is greater - # case 3: self doesn't have prerelease, other does: self is greater - # case 4: both have prerelease: must compare them! - - if (not self.prerelease and not other.prerelease): - return 0 - elif (self.prerelease and not other.prerelease): - return -1 - elif (not self.prerelease and other.prerelease): - return 1 - elif (self.prerelease and other.prerelease): - return cmp(self.prerelease, other.prerelease) - - else: # numeric versions don't match -- - return compare # prerelease stuff doesn't matter - - -# end class StrictVersion - - -# The rules according to Greg Stein: -# 1) a version number has 1 or more numbers separated by a period or by -# sequences of letters. If only periods, then these are compared -# left-to-right to determine an ordering. -# 2) sequences of letters are part of the tuple for comparison and are -# compared lexicographically -# 3) recognize the numeric components may have leading zeroes -# -# The LooseVersion class below implements these rules: a version number -# string is split up into a tuple of integer and string components, and -# comparison is a simple tuple comparison. This means that version -# numbers behave in a predictable and obvious way, but a way that might -# not necessarily be how people *want* version numbers to behave. There -# wouldn't be a problem if people could stick to purely numeric version -# numbers: just split on period and compare the numbers as tuples. -# However, people insist on putting letters into their version numbers; -# the most common purpose seems to be: -# - indicating a "pre-release" version -# ('alpha', 'beta', 'a', 'b', 'pre', 'p') -# - indicating a post-release patch ('p', 'pl', 'patch') -# but of course this can't cover all version number schemes, and there's -# no way to know what a programmer means without asking him. -# -# The problem is what to do with letters (and other non-numeric -# characters) in a version number. The current implementation does the -# obvious and predictable thing: keep them as strings and compare -# lexically within a tuple comparison. This has the desired effect if -# an appended letter sequence implies something "post-release": -# eg. "0.99" < "0.99pl14" < "1.0", and "5.001" < "5.001m" < "5.002". -# -# However, if letters in a version number imply a pre-release version, -# the "obvious" thing isn't correct. Eg. you would expect that -# "1.5.1" < "1.5.2a2" < "1.5.2", but under the tuple/lexical comparison -# implemented here, this just isn't so. -# -# Two possible solutions come to mind. The first is to tie the -# comparison algorithm to a particular set of semantic rules, as has -# been done in the StrictVersion class above. This works great as long -# as everyone can go along with bondage and discipline. Hopefully a -# (large) subset of Python module programmers will agree that the -# particular flavour of bondage and discipline provided by StrictVersion -# provides enough benefit to be worth using, and will submit their -# version numbering scheme to its domination. The free-thinking -# anarchists in the lot will never give in, though, and something needs -# to be done to accommodate them. -# -# Perhaps a "moderately strict" version class could be implemented that -# lets almost anything slide (syntactically), and makes some heuristic -# assumptions about non-digits in version number strings. This could -# sink into special-case-hell, though; if I was as talented and -# idiosyncratic as Larry Wall, I'd go ahead and implement a class that -# somehow knows that "1.2.1" < "1.2.2a2" < "1.2.2" < "1.2.2pl3", and is -# just as happy dealing with things like "2g6" and "1.13++". I don't -# think I'm smart enough to do it right though. -# -# In any case, I've coded the test suite for this module (see -# ../test/test_version.py) specifically to fail on things like comparing -# "1.2a2" and "1.2". That's not because the *code* is doing anything -# wrong, it's because the simple, obvious design doesn't match my -# complicated, hairy expectations for real-world version numbers. It -# would be a snap to fix the test suite to say, "Yep, LooseVersion does -# the Right Thing" (ie. the code matches the conception). But I'd rather -# have a conception that matches common notions about version numbers. - -class LooseVersion (Version): - - """Version numbering for anarchists and software realists. - Implements the standard interface for version number classes as - described above. A version number consists of a series of numbers, - separated by either periods or strings of letters. When comparing - version numbers, the numeric components will be compared - numerically, and the alphabetic components lexically. The following - are all valid version numbers, in no particular order: - - 1.5.1 - 1.5.2b2 - 161 - 3.10a - 8.02 - 3.4j - 1996.07.12 - 3.2.pl0 - 3.1.1.6 - 2g6 - 11g - 0.960923 - 2.2beta29 - 1.13++ - 5.5.kw - 2.0b1pl0 - - In fact, there is no such thing as an invalid version number under - this scheme; the rules for comparison are simple and predictable, - but may not always give the results you want (for some definition - of "want"). - """ - - component_re = re.compile(r'(\d+ | [a-z]+ | \.)', re.VERBOSE) - - def __init__ (self, vstring=None): - if vstring: - self.parse(vstring) - - - def parse (self, vstring): - # I've given up on thinking I can reconstruct the version string - # from the parsed tuple -- so I just store the string here for - # use by __str__ - self.vstring = vstring - components = filter(lambda x: x and x != '.', - self.component_re.split(vstring)) - for i in range(len(components)): - try: - components[i] = int(components[i]) - except ValueError: - pass - - self.version = components - - - def __str__ (self): - return self.vstring - - - def __repr__ (self): - return "LooseVersion ('%s')" % str(self) - - - def __cmp__ (self, other): - if isinstance(other, StringType): - other = LooseVersion(other) - - return cmp(self.version, other.version) - - -# end class LooseVersion diff --git a/PythonLib/extra/distutils/versionpredicate.py b/PythonLib/extra/distutils/versionpredicate.py deleted file mode 100644 index ba8b6c02..00000000 --- a/PythonLib/extra/distutils/versionpredicate.py +++ /dev/null @@ -1,164 +0,0 @@ -"""Module for parsing and testing package version predicate strings. -""" -import re -import distutils.version -import operator - - -re_validPackage = re.compile(r"(?i)^\s*([a-z_]\w*(?:\.[a-z_]\w*)*)(.*)") -# (package) (rest) - -re_paren = re.compile(r"^\s*\((.*)\)\s*$") # (list) inside of parentheses -re_splitComparison = re.compile(r"^\s*(<=|>=|<|>|!=|==)\s*([^\s,]+)\s*$") -# (comp) (version) - - -def splitUp(pred): - """Parse a single version comparison. - - Return (comparison string, StrictVersion) - """ - res = re_splitComparison.match(pred) - if not res: - raise ValueError("bad package restriction syntax: %r" % pred) - comp, verStr = res.groups() - return (comp, distutils.version.StrictVersion(verStr)) - -compmap = {"<": operator.lt, "<=": operator.le, "==": operator.eq, - ">": operator.gt, ">=": operator.ge, "!=": operator.ne} - -class VersionPredicate: - """Parse and test package version predicates. - - >>> v = VersionPredicate('pyepat.abc (>1.0, <3333.3a1, !=1555.1b3)') - - The `name` attribute provides the full dotted name that is given:: - - >>> v.name - 'pyepat.abc' - - The str() of a `VersionPredicate` provides a normalized - human-readable version of the expression:: - - >>> print v - pyepat.abc (> 1.0, < 3333.3a1, != 1555.1b3) - - The `satisfied_by()` method can be used to determine with a given - version number is included in the set described by the version - restrictions:: - - >>> v.satisfied_by('1.1') - True - >>> v.satisfied_by('1.4') - True - >>> v.satisfied_by('1.0') - False - >>> v.satisfied_by('4444.4') - False - >>> v.satisfied_by('1555.1b3') - False - - `VersionPredicate` is flexible in accepting extra whitespace:: - - >>> v = VersionPredicate(' pat( == 0.1 ) ') - >>> v.name - 'pat' - >>> v.satisfied_by('0.1') - True - >>> v.satisfied_by('0.2') - False - - If any version numbers passed in do not conform to the - restrictions of `StrictVersion`, a `ValueError` is raised:: - - >>> v = VersionPredicate('p1.p2.p3.p4(>=1.0, <=1.3a1, !=1.2zb3)') - Traceback (most recent call last): - ... - ValueError: invalid version number '1.2zb3' - - It the module or package name given does not conform to what's - allowed as a legal module or package name, `ValueError` is - raised:: - - >>> v = VersionPredicate('foo-bar') - Traceback (most recent call last): - ... - ValueError: expected parenthesized list: '-bar' - - >>> v = VersionPredicate('foo bar (12.21)') - Traceback (most recent call last): - ... - ValueError: expected parenthesized list: 'bar (12.21)' - - """ - - def __init__(self, versionPredicateStr): - """Parse a version predicate string. - """ - # Fields: - # name: package name - # pred: list of (comparison string, StrictVersion) - - versionPredicateStr = versionPredicateStr.strip() - if not versionPredicateStr: - raise ValueError("empty package restriction") - match = re_validPackage.match(versionPredicateStr) - if not match: - raise ValueError("bad package name in %r" % versionPredicateStr) - self.name, paren = match.groups() - paren = paren.strip() - if paren: - match = re_paren.match(paren) - if not match: - raise ValueError("expected parenthesized list: %r" % paren) - str = match.groups()[0] - self.pred = [splitUp(aPred) for aPred in str.split(",")] - if not self.pred: - raise ValueError("empty parenthesized list in %r" - % versionPredicateStr) - else: - self.pred = [] - - def __str__(self): - if self.pred: - seq = [cond + " " + str(ver) for cond, ver in self.pred] - return self.name + " (" + ", ".join(seq) + ")" - else: - return self.name - - def satisfied_by(self, version): - """True if version is compatible with all the predicates in self. - The parameter version must be acceptable to the StrictVersion - constructor. It may be either a string or StrictVersion. - """ - for cond, ver in self.pred: - if not compmap[cond](version, ver): - return False - return True - - -_provision_rx = None - -def split_provision(value): - """Return the name and optional version number of a provision. - - The version number, if given, will be returned as a `StrictVersion` - instance, otherwise it will be `None`. - - >>> split_provision('mypkg') - ('mypkg', None) - >>> split_provision(' mypkg( 1.2 ) ') - ('mypkg', StrictVersion ('1.2')) - """ - global _provision_rx - if _provision_rx is None: - _provision_rx = re.compile( - "([a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*)(?:\s*\(\s*([^)\s]+)\s*\))?$") - value = value.strip() - m = _provision_rx.match(value) - if not m: - raise ValueError("illegal provides specification: %r" % value) - ver = m.group(2) or None - if ver: - ver = distutils.version.StrictVersion(ver) - return m.group(1), ver diff --git a/PythonLib/extra/lib2to3/Grammar.txt b/PythonLib/extra/lib2to3/Grammar.txt deleted file mode 100644 index 1e1f24cf..00000000 --- a/PythonLib/extra/lib2to3/Grammar.txt +++ /dev/null @@ -1,158 +0,0 @@ -# Grammar for 2to3. This grammar supports Python 2.x and 3.x. - -# Note: Changing the grammar specified in this file will most likely -# require corresponding changes in the parser module -# (../Modules/parsermodule.c). If you can't make the changes to -# that module yourself, please co-ordinate the required changes -# with someone who can; ask around on python-dev for help. Fred -# Drake will probably be listening there. - -# NOTE WELL: You should also follow all the steps listed in PEP 306, -# "How to Change Python's Grammar" - -# Commands for Kees Blom's railroad program -#diagram:token NAME -#diagram:token NUMBER -#diagram:token STRING -#diagram:token NEWLINE -#diagram:token ENDMARKER -#diagram:token INDENT -#diagram:output\input python.bla -#diagram:token DEDENT -#diagram:output\textwidth 20.04cm\oddsidemargin 0.0cm\evensidemargin 0.0cm -#diagram:rules - -# Start symbols for the grammar: -# file_input is a module or sequence of commands read from an input file; -# single_input is a single interactive statement; -# eval_input is the input for the eval() and input() functions. -# NB: compound_stmt in single_input is followed by extra NEWLINE! -file_input: (NEWLINE | stmt)* ENDMARKER -single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE -eval_input: testlist NEWLINE* ENDMARKER - -decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE -decorators: decorator+ -decorated: decorators (classdef | funcdef) -funcdef: 'def' NAME parameters ['->' test] ':' suite -parameters: '(' [typedargslist] ')' -typedargslist: ((tfpdef ['=' test] ',')* - ('*' [tname] (',' tname ['=' test])* [',' '**' tname] | '**' tname) - | tfpdef ['=' test] (',' tfpdef ['=' test])* [',']) -tname: NAME [':' test] -tfpdef: tname | '(' tfplist ')' -tfplist: tfpdef (',' tfpdef)* [','] -varargslist: ((vfpdef ['=' test] ',')* - ('*' [vname] (',' vname ['=' test])* [',' '**' vname] | '**' vname) - | vfpdef ['=' test] (',' vfpdef ['=' test])* [',']) -vname: NAME -vfpdef: vname | '(' vfplist ')' -vfplist: vfpdef (',' vfpdef)* [','] - -stmt: simple_stmt | compound_stmt -simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE -small_stmt: (expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt | - import_stmt | global_stmt | exec_stmt | assert_stmt) -expr_stmt: testlist_star_expr (augassign (yield_expr|testlist) | - ('=' (yield_expr|testlist_star_expr))*) -testlist_star_expr: (test|star_expr) (',' (test|star_expr))* [','] -augassign: ('+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' | - '<<=' | '>>=' | '**=' | '//=') -# For normal assignments, additional restrictions enforced by the interpreter -print_stmt: 'print' ( [ test (',' test)* [','] ] | - '>>' test [ (',' test)+ [','] ] ) -del_stmt: 'del' exprlist -pass_stmt: 'pass' -flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt -break_stmt: 'break' -continue_stmt: 'continue' -return_stmt: 'return' [testlist] -yield_stmt: yield_expr -raise_stmt: 'raise' [test ['from' test | ',' test [',' test]]] -import_stmt: import_name | import_from -import_name: 'import' dotted_as_names -import_from: ('from' ('.'* dotted_name | '.'+) - 'import' ('*' | '(' import_as_names ')' | import_as_names)) -import_as_name: NAME ['as' NAME] -dotted_as_name: dotted_name ['as' NAME] -import_as_names: import_as_name (',' import_as_name)* [','] -dotted_as_names: dotted_as_name (',' dotted_as_name)* -dotted_name: NAME ('.' NAME)* -global_stmt: ('global' | 'nonlocal') NAME (',' NAME)* -exec_stmt: 'exec' expr ['in' test [',' test]] -assert_stmt: 'assert' test [',' test] - -compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated -if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] -while_stmt: 'while' test ':' suite ['else' ':' suite] -for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] -try_stmt: ('try' ':' suite - ((except_clause ':' suite)+ - ['else' ':' suite] - ['finally' ':' suite] | - 'finally' ':' suite)) -with_stmt: 'with' with_item (',' with_item)* ':' suite -with_item: test ['as' expr] -with_var: 'as' expr -# NB compile.c makes sure that the default except clause is last -except_clause: 'except' [test [(',' | 'as') test]] -suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT - -# Backward compatibility cruft to support: -# [ x for x in lambda: True, lambda: False if x() ] -# even while also allowing: -# lambda x: 5 if x else 2 -# (But not a mix of the two) -testlist_safe: old_test [(',' old_test)+ [',']] -old_test: or_test | old_lambdef -old_lambdef: 'lambda' [varargslist] ':' old_test - -test: or_test ['if' or_test 'else' test] | lambdef -or_test: and_test ('or' and_test)* -and_test: not_test ('and' not_test)* -not_test: 'not' not_test | comparison -comparison: expr (comp_op expr)* -comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not' -star_expr: '*' expr -expr: xor_expr ('|' xor_expr)* -xor_expr: and_expr ('^' and_expr)* -and_expr: shift_expr ('&' shift_expr)* -shift_expr: arith_expr (('<<'|'>>') arith_expr)* -arith_expr: term (('+'|'-') term)* -term: factor (('*'|'/'|'%'|'//') factor)* -factor: ('+'|'-'|'~') factor | power -power: atom trailer* ['**' factor] -atom: ('(' [yield_expr|testlist_gexp] ')' | - '[' [listmaker] ']' | - '{' [dictsetmaker] '}' | - '`' testlist1 '`' | - NAME | NUMBER | STRING+ | '.' '.' '.') -listmaker: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] ) -testlist_gexp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] ) -lambdef: 'lambda' [varargslist] ':' test -trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME -subscriptlist: subscript (',' subscript)* [','] -subscript: test | [test] ':' [test] [sliceop] -sliceop: ':' [test] -exprlist: (expr|star_expr) (',' (expr|star_expr))* [','] -testlist: test (',' test)* [','] -dictsetmaker: ( (test ':' test (comp_for | (',' test ':' test)* [','])) | - (test (comp_for | (',' test)* [','])) ) - -classdef: 'class' NAME ['(' [arglist] ')'] ':' suite - -arglist: (argument ',')* (argument [','] - |'*' test (',' argument)* [',' '**' test] - |'**' test) -argument: test [comp_for] | test '=' test # Really [keyword '='] test - -comp_iter: comp_for | comp_if -comp_for: 'for' exprlist 'in' testlist_safe [comp_iter] -comp_if: 'if' old_test [comp_iter] - -testlist1: test (',' test)* - -# not used in grammar, but may appear in "node" passed from Parser to Compiler -encoding_decl: NAME - -yield_expr: 'yield' [testlist] diff --git a/PythonLib/extra/lib2to3/__init__.py b/PythonLib/extra/lib2to3/__init__.py deleted file mode 100644 index ea30561d..00000000 --- a/PythonLib/extra/lib2to3/__init__.py +++ /dev/null @@ -1 +0,0 @@ -#empty diff --git a/PythonLib/extra/lib2to3/fixes/fix_apply.py b/PythonLib/extra/lib2to3/fixes/fix_apply.py deleted file mode 100644 index a7dc3a04..00000000 --- a/PythonLib/extra/lib2to3/fixes/fix_apply.py +++ /dev/null @@ -1,59 +0,0 @@ -# Copyright 2006 Google, Inc. All Rights Reserved. -# Licensed to PSF under a Contributor Agreement. - -"""Fixer for apply(). - -This converts apply(func, v, k) into (func)(*v, **k).""" - -# Local imports -from .. import pytree -from ..pgen2 import token -from .. import fixer_base -from ..fixer_util import Call, Comma, parenthesize - -class FixApply(fixer_base.BaseFix): - BM_compatible = True - - PATTERN = """ - power< 'apply' - trailer< - '(' - arglist< - (not argument - ')' - > - > - """ - - def transform(self, node, results): - syms = self.syms - assert results - func = results["func"] - args = results["args"] - kwds = results.get("kwds") - prefix = node.prefix - func = func.clone() - if (func.type not in (token.NAME, syms.atom) and - (func.type != syms.power or - func.children[-2].type == token.DOUBLESTAR)): - # Need to parenthesize - func = parenthesize(func) - func.prefix = "" - args = args.clone() - args.prefix = "" - if kwds is not None: - kwds = kwds.clone() - kwds.prefix = "" - l_newargs = [pytree.Leaf(token.STAR, u"*"), args] - if kwds is not None: - l_newargs.extend([Comma(), - pytree.Leaf(token.DOUBLESTAR, u"**"), - kwds]) - l_newargs[-2].prefix = u" " # that's the ** token - # XXX Sometimes we could be cleverer, e.g. apply(f, (x, y) + t) - # can be translated into f(x, y, *t) instead of f(*(x, y) + t) - #new = pytree.Node(syms.power, (func, ArgList(l_newargs))) - return Call(func, l_newargs, prefix=prefix) diff --git a/PythonLib/extra/lib2to3/fixes/fix_callable.py b/PythonLib/extra/lib2to3/fixes/fix_callable.py deleted file mode 100644 index df33d614..00000000 --- a/PythonLib/extra/lib2to3/fixes/fix_callable.py +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright 2007 Google, Inc. All Rights Reserved. -# Licensed to PSF under a Contributor Agreement. - -"""Fixer for callable(). - -This converts callable(obj) into isinstance(obj, collections.Callable), adding a -collections import if needed.""" - -# Local imports -from lib2to3 import fixer_base -from lib2to3.fixer_util import Call, Name, String, Attr, touch_import - -class FixCallable(fixer_base.BaseFix): - BM_compatible = True - - order = "pre" - - # Ignore callable(*args) or use of keywords. - # Either could be a hint that the builtin callable() is not being used. - PATTERN = """ - power< 'callable' - trailer< lpar='(' - ( not(arglist | argument) any ','> ) - rpar=')' > - after=any* - > - """ - - def transform(self, node, results): - func = results['func'] - - touch_import(None, u'collections', node=node) - - args = [func.clone(), String(u', ')] - args.extend(Attr(Name(u'collections'), Name(u'Callable'))) - return Call(Name(u'isinstance'), args, prefix=node.prefix) diff --git a/PythonLib/extra/lib2to3/fixes/fix_filter.py b/PythonLib/extra/lib2to3/fixes/fix_filter.py deleted file mode 100644 index 18ee2ffc..00000000 --- a/PythonLib/extra/lib2to3/fixes/fix_filter.py +++ /dev/null @@ -1,76 +0,0 @@ -# Copyright 2007 Google, Inc. All Rights Reserved. -# Licensed to PSF under a Contributor Agreement. - -"""Fixer that changes filter(F, X) into list(filter(F, X)). - -We avoid the transformation if the filter() call is directly contained -in iter(<>), list(<>), tuple(<>), sorted(<>), ...join(<>), or -for V in <>:. - -NOTE: This is still not correct if the original code was depending on -filter(F, X) to return a string if X is a string and a tuple if X is a -tuple. That would require type inference, which we don't do. Let -Python 2.6 figure it out. -""" - -# Local imports -from ..pgen2 import token -from .. import fixer_base -from ..fixer_util import Name, Call, ListComp, in_special_context - -class FixFilter(fixer_base.ConditionalFix): - BM_compatible = True - - PATTERN = """ - filter_lambda=power< - 'filter' - trailer< - '(' - arglist< - lambdef< 'lambda' - (fp=NAME | vfpdef< '(' fp=NAME ')'> ) ':' xp=any - > - ',' - it=any - > - ')' - > - > - | - power< - 'filter' - trailer< '(' arglist< none='None' ',' seq=any > ')' > - > - | - power< - 'filter' - args=trailer< '(' [any] ')' > - > - """ - - skip_on = "future_builtins.filter" - - def transform(self, node, results): - if self.should_skip(node): - return - - if "filter_lambda" in results: - new = ListComp(results.get("fp").clone(), - results.get("fp").clone(), - results.get("it").clone(), - results.get("xp").clone()) - - elif "none" in results: - new = ListComp(Name(u"_f"), - Name(u"_f"), - results["seq"].clone(), - Name(u"_f")) - - else: - if in_special_context(node): - return None - new = node.clone() - new.prefix = u"" - new = Call(Name(u"list"), [new]) - new.prefix = node.prefix - return new diff --git a/PythonLib/extra/lib2to3/fixes/fix_intern.py b/PythonLib/extra/lib2to3/fixes/fix_intern.py deleted file mode 100644 index e7bb5052..00000000 --- a/PythonLib/extra/lib2to3/fixes/fix_intern.py +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright 2006 Georg Brandl. -# Licensed to PSF under a Contributor Agreement. - -"""Fixer for intern(). - -intern(s) -> sys.intern(s)""" - -# Local imports -from .. import pytree -from .. import fixer_base -from ..fixer_util import Name, Attr, touch_import - - -class FixIntern(fixer_base.BaseFix): - BM_compatible = True - order = "pre" - - PATTERN = """ - power< 'intern' - trailer< lpar='(' - ( not(arglist | argument) any ','> ) - rpar=')' > - after=any* - > - """ - - def transform(self, node, results): - syms = self.syms - obj = results["obj"].clone() - if obj.type == syms.arglist: - newarglist = obj.clone() - else: - newarglist = pytree.Node(syms.arglist, [obj.clone()]) - after = results["after"] - if after: - after = [n.clone() for n in after] - new = pytree.Node(syms.power, - Attr(Name(u"sys"), Name(u"intern")) + - [pytree.Node(syms.trailer, - [results["lpar"].clone(), - newarglist, - results["rpar"].clone()])] + after) - new.prefix = node.prefix - touch_import(None, u'sys', node) - return new diff --git a/PythonLib/extra/lib2to3/fixes/fix_map.py b/PythonLib/extra/lib2to3/fixes/fix_map.py deleted file mode 100644 index 7a7d0dbc..00000000 --- a/PythonLib/extra/lib2to3/fixes/fix_map.py +++ /dev/null @@ -1,91 +0,0 @@ -# Copyright 2007 Google, Inc. All Rights Reserved. -# Licensed to PSF under a Contributor Agreement. - -"""Fixer that changes map(F, ...) into list(map(F, ...)) unless there -exists a 'from future_builtins import map' statement in the top-level -namespace. - -As a special case, map(None, X) is changed into list(X). (This is -necessary because the semantics are changed in this case -- the new -map(None, X) is equivalent to [(x,) for x in X].) - -We avoid the transformation (except for the special case mentioned -above) if the map() call is directly contained in iter(<>), list(<>), -tuple(<>), sorted(<>), ...join(<>), or for V in <>:. - -NOTE: This is still not correct if the original code was depending on -map(F, X, Y, ...) to go on until the longest argument is exhausted, -substituting None for missing values -- like zip(), it now stops as -soon as the shortest argument is exhausted. -""" - -# Local imports -from ..pgen2 import token -from .. import fixer_base -from ..fixer_util import Name, Call, ListComp, in_special_context -from ..pygram import python_symbols as syms - -class FixMap(fixer_base.ConditionalFix): - BM_compatible = True - - PATTERN = """ - map_none=power< - 'map' - trailer< '(' arglist< 'None' ',' arg=any [','] > ')' > - > - | - map_lambda=power< - 'map' - trailer< - '(' - arglist< - lambdef< 'lambda' - (fp=NAME | vfpdef< '(' fp=NAME ')'> ) ':' xp=any - > - ',' - it=any - > - ')' - > - > - | - power< - 'map' trailer< '(' [arglist=any] ')' > - > - """ - - skip_on = 'future_builtins.map' - - def transform(self, node, results): - if self.should_skip(node): - return - - if node.parent.type == syms.simple_stmt: - self.warning(node, "You should use a for loop here") - new = node.clone() - new.prefix = u"" - new = Call(Name(u"list"), [new]) - elif "map_lambda" in results: - new = ListComp(results["xp"].clone(), - results["fp"].clone(), - results["it"].clone()) - else: - if "map_none" in results: - new = results["arg"].clone() - else: - if "arglist" in results: - args = results["arglist"] - if args.type == syms.arglist and \ - args.children[0].type == token.NAME and \ - args.children[0].value == "None": - self.warning(node, "cannot convert map(None, ...) " - "with multiple arguments because map() " - "now truncates to the shortest sequence") - return - if in_special_context(node): - return None - new = node.clone() - new.prefix = u"" - new = Call(Name(u"list"), [new]) - new.prefix = node.prefix - return new diff --git a/PythonLib/extra/lib2to3/fixes/fix_numliterals.py b/PythonLib/extra/lib2to3/fixes/fix_numliterals.py deleted file mode 100644 index b0c23f80..00000000 --- a/PythonLib/extra/lib2to3/fixes/fix_numliterals.py +++ /dev/null @@ -1,28 +0,0 @@ -"""Fixer that turns 1L into 1, 0755 into 0o755. -""" -# Copyright 2007 Georg Brandl. -# Licensed to PSF under a Contributor Agreement. - -# Local imports -from ..pgen2 import token -from .. import fixer_base -from ..fixer_util import Number - - -class FixNumliterals(fixer_base.BaseFix): - # This is so simple that we don't need the pattern compiler. - - _accept_type = token.NUMBER - - def match(self, node): - # Override - return (node.value.startswith(u"0") or node.value[-1] in u"Ll") - - def transform(self, node, results): - val = node.value - if val[-1] in u'Ll': - val = val[:-1] - elif val.startswith(u'0') and val.isdigit() and len(set(val)) > 1: - val = u"0o" + val[1:] - - return Number(val, prefix=node.prefix) diff --git a/PythonLib/extra/lib2to3/fixes/fix_operator.py b/PythonLib/extra/lib2to3/fixes/fix_operator.py deleted file mode 100644 index 7bf2c0dd..00000000 --- a/PythonLib/extra/lib2to3/fixes/fix_operator.py +++ /dev/null @@ -1,96 +0,0 @@ -"""Fixer for operator functions. - -operator.isCallable(obj) -> hasattr(obj, '__call__') -operator.sequenceIncludes(obj) -> operator.contains(obj) -operator.isSequenceType(obj) -> isinstance(obj, collections.Sequence) -operator.isMappingType(obj) -> isinstance(obj, collections.Mapping) -operator.isNumberType(obj) -> isinstance(obj, numbers.Number) -operator.repeat(obj, n) -> operator.mul(obj, n) -operator.irepeat(obj, n) -> operator.imul(obj, n) -""" - -# Local imports -from lib2to3 import fixer_base -from lib2to3.fixer_util import Call, Name, String, touch_import - - -def invocation(s): - def dec(f): - f.invocation = s - return f - return dec - - -class FixOperator(fixer_base.BaseFix): - BM_compatible = True - order = "pre" - - methods = """ - method=('isCallable'|'sequenceIncludes' - |'isSequenceType'|'isMappingType'|'isNumberType' - |'repeat'|'irepeat') - """ - obj = "'(' obj=any ')'" - PATTERN = """ - power< module='operator' - trailer< '.' %(methods)s > trailer< %(obj)s > > - | - power< %(methods)s trailer< %(obj)s > > - """ % dict(methods=methods, obj=obj) - - def transform(self, node, results): - method = self._check_method(node, results) - if method is not None: - return method(node, results) - - @invocation("operator.contains(%s)") - def _sequenceIncludes(self, node, results): - return self._handle_rename(node, results, u"contains") - - @invocation("hasattr(%s, '__call__')") - def _isCallable(self, node, results): - obj = results["obj"] - args = [obj.clone(), String(u", "), String(u"'__call__'")] - return Call(Name(u"hasattr"), args, prefix=node.prefix) - - @invocation("operator.mul(%s)") - def _repeat(self, node, results): - return self._handle_rename(node, results, u"mul") - - @invocation("operator.imul(%s)") - def _irepeat(self, node, results): - return self._handle_rename(node, results, u"imul") - - @invocation("isinstance(%s, collections.Sequence)") - def _isSequenceType(self, node, results): - return self._handle_type2abc(node, results, u"collections", u"Sequence") - - @invocation("isinstance(%s, collections.Mapping)") - def _isMappingType(self, node, results): - return self._handle_type2abc(node, results, u"collections", u"Mapping") - - @invocation("isinstance(%s, numbers.Number)") - def _isNumberType(self, node, results): - return self._handle_type2abc(node, results, u"numbers", u"Number") - - def _handle_rename(self, node, results, name): - method = results["method"][0] - method.value = name - method.changed() - - def _handle_type2abc(self, node, results, module, abc): - touch_import(None, module, node) - obj = results["obj"] - args = [obj.clone(), String(u", " + u".".join([module, abc]))] - return Call(Name(u"isinstance"), args, prefix=node.prefix) - - def _check_method(self, node, results): - method = getattr(self, "_" + results["method"][0].value.encode("ascii")) - if callable(method): - if "module" in results: - return method - else: - sub = (unicode(results["obj"]),) - invocation_str = unicode(method.invocation) % sub - self.warning(node, u"You should use '%s' here." % invocation_str) - return None diff --git a/PythonLib/extra/lib2to3/fixes/fix_unicode.py b/PythonLib/extra/lib2to3/fixes/fix_unicode.py deleted file mode 100644 index 2d776f61..00000000 --- a/PythonLib/extra/lib2to3/fixes/fix_unicode.py +++ /dev/null @@ -1,42 +0,0 @@ -r"""Fixer for unicode. - -* Changes unicode to str and unichr to chr. - -* If "...\u..." is not unicode literal change it into "...\\u...". - -* Change u"..." into "...". - -""" - -from ..pgen2 import token -from .. import fixer_base - -_mapping = {u"unichr" : u"chr", u"unicode" : u"str"} - -class FixUnicode(fixer_base.BaseFix): - BM_compatible = True - PATTERN = "STRING | 'unicode' | 'unichr'" - - def start_tree(self, tree, filename): - super(FixUnicode, self).start_tree(tree, filename) - self.unicode_literals = 'unicode_literals' in tree.future_features - - def transform(self, node, results): - if node.type == token.NAME: - new = node.clone() - new.value = _mapping[node.value] - return new - elif node.type == token.STRING: - val = node.value - if not self.unicode_literals and val[0] in u'\'"' and u'\\' in val: - val = ur'\\'.join([ - v.replace(u'\\u', ur'\\u').replace(u'\\U', ur'\\U') - for v in val.split(ur'\\') - ]) - if val[0] in u'uU': - val = val[1:] - if val == node.value: - return node - new = node.clone() - new.value = val - return new diff --git a/PythonLib/extra/lib2to3/fixes/fix_zip.py b/PythonLib/extra/lib2to3/fixes/fix_zip.py deleted file mode 100644 index c5d7b66d..00000000 --- a/PythonLib/extra/lib2to3/fixes/fix_zip.py +++ /dev/null @@ -1,35 +0,0 @@ -""" -Fixer that changes zip(seq0, seq1, ...) into list(zip(seq0, seq1, ...) -unless there exists a 'from future_builtins import zip' statement in the -top-level namespace. - -We avoid the transformation if the zip() call is directly contained in -iter(<>), list(<>), tuple(<>), sorted(<>), ...join(<>), or for V in <>:. -""" - -# Local imports -from .. import fixer_base -from ..fixer_util import Name, Call, in_special_context - -class FixZip(fixer_base.ConditionalFix): - - BM_compatible = True - PATTERN = """ - power< 'zip' args=trailer< '(' [any] ')' > - > - """ - - skip_on = "future_builtins.zip" - - def transform(self, node, results): - if self.should_skip(node): - return - - if in_special_context(node): - return None - - new = node.clone() - new.prefix = u"" - new = Call(Name(u"list"), [new]) - new.prefix = node.prefix - return new diff --git a/PythonLib/extra/lib2to3/pgen2/parse.py b/PythonLib/extra/lib2to3/pgen2/parse.py deleted file mode 100644 index 6bebdbba..00000000 --- a/PythonLib/extra/lib2to3/pgen2/parse.py +++ /dev/null @@ -1,201 +0,0 @@ -# Copyright 2004-2005 Elemental Security, Inc. All Rights Reserved. -# Licensed to PSF under a Contributor Agreement. - -"""Parser engine for the grammar tables generated by pgen. - -The grammar table must be loaded first. - -See Parser/parser.c in the Python distribution for additional info on -how this parsing engine works. - -""" - -# Local imports -from . import token - -class ParseError(Exception): - """Exception to signal the parser is stuck.""" - - def __init__(self, msg, type, value, context): - Exception.__init__(self, "%s: type=%r, value=%r, context=%r" % - (msg, type, value, context)) - self.msg = msg - self.type = type - self.value = value - self.context = context - -class Parser(object): - """Parser engine. - - The proper usage sequence is: - - p = Parser(grammar, [converter]) # create instance - p.setup([start]) # prepare for parsing - : - if p.addtoken(...): # parse a token; may raise ParseError - break - root = p.rootnode # root of abstract syntax tree - - A Parser instance may be reused by calling setup() repeatedly. - - A Parser instance contains state pertaining to the current token - sequence, and should not be used concurrently by different threads - to parse separate token sequences. - - See driver.py for how to get input tokens by tokenizing a file or - string. - - Parsing is complete when addtoken() returns True; the root of the - abstract syntax tree can then be retrieved from the rootnode - instance variable. When a syntax error occurs, addtoken() raises - the ParseError exception. There is no error recovery; the parser - cannot be used after a syntax error was reported (but it can be - reinitialized by calling setup()). - - """ - - def __init__(self, grammar, convert=None): - """Constructor. - - The grammar argument is a grammar.Grammar instance; see the - grammar module for more information. - - The parser is not ready yet for parsing; you must call the - setup() method to get it started. - - The optional convert argument is a function mapping concrete - syntax tree nodes to abstract syntax tree nodes. If not - given, no conversion is done and the syntax tree produced is - the concrete syntax tree. If given, it must be a function of - two arguments, the first being the grammar (a grammar.Grammar - instance), and the second being the concrete syntax tree node - to be converted. The syntax tree is converted from the bottom - up. - - A concrete syntax tree node is a (type, value, context, nodes) - tuple, where type is the node type (a token or symbol number), - value is None for symbols and a string for tokens, context is - None or an opaque value used for error reporting (typically a - (lineno, offset) pair), and nodes is a list of children for - symbols, and None for tokens. - - An abstract syntax tree node may be anything; this is entirely - up to the converter function. - - """ - self.grammar = grammar - self.convert = convert or (lambda grammar, node: node) - - def setup(self, start=None): - """Prepare for parsing. - - This *must* be called before starting to parse. - - The optional argument is an alternative start symbol; it - defaults to the grammar's start symbol. - - You can use a Parser instance to parse any number of programs; - each time you call setup() the parser is reset to an initial - state determined by the (implicit or explicit) start symbol. - - """ - if start is None: - start = self.grammar.start - # Each stack entry is a tuple: (dfa, state, node). - # A node is a tuple: (type, value, context, children), - # where children is a list of nodes or None, and context may be None. - newnode = (start, None, None, []) - stackentry = (self.grammar.dfas[start], 0, newnode) - self.stack = [stackentry] - self.rootnode = None - self.used_names = set() # Aliased to self.rootnode.used_names in pop() - - def addtoken(self, type, value, context): - """Add a token; return True iff this is the end of the program.""" - # Map from token to label - ilabel = self.classify(type, value, context) - # Loop until the token is shifted; may raise exceptions - while True: - dfa, state, node = self.stack[-1] - states, first = dfa - arcs = states[state] - # Look for a state with this label - for i, newstate in arcs: - t, v = self.grammar.labels[i] - if ilabel == i: - # Look it up in the list of labels - assert t < 256 - # Shift a token; we're done with it - self.shift(type, value, newstate, context) - # Pop while we are in an accept-only state - state = newstate - while states[state] == [(0, state)]: - self.pop() - if not self.stack: - # Done parsing! - return True - dfa, state, node = self.stack[-1] - states, first = dfa - # Done with this token - return False - elif t >= 256: - # See if it's a symbol and if we're in its first set - itsdfa = self.grammar.dfas[t] - itsstates, itsfirst = itsdfa - if ilabel in itsfirst: - # Push a symbol - self.push(t, self.grammar.dfas[t], newstate, context) - break # To continue the outer while loop - else: - if (0, state) in arcs: - # An accepting state, pop it and try something else - self.pop() - if not self.stack: - # Done parsing, but another token is input - raise ParseError("too much input", - type, value, context) - else: - # No success finding a transition - raise ParseError("bad input", type, value, context) - - def classify(self, type, value, context): - """Turn a token into a label. (Internal)""" - if type == token.NAME: - # Keep a listing of all used names - self.used_names.add(value) - # Check for reserved words - ilabel = self.grammar.keywords.get(value) - if ilabel is not None: - return ilabel - ilabel = self.grammar.tokens.get(type) - if ilabel is None: - raise ParseError("bad token", type, value, context) - return ilabel - - def shift(self, type, value, newstate, context): - """Shift a token. (Internal)""" - dfa, state, node = self.stack[-1] - newnode = (type, value, context, None) - newnode = self.convert(self.grammar, newnode) - if newnode is not None: - node[-1].append(newnode) - self.stack[-1] = (dfa, newstate, node) - - def push(self, type, newdfa, newstate, context): - """Push a nonterminal. (Internal)""" - dfa, state, node = self.stack[-1] - newnode = (type, None, context, []) - self.stack[-1] = (dfa, newstate, node) - self.stack.append((newdfa, 0, newnode)) - - def pop(self): - """Pop a nonterminal. (Internal)""" - popdfa, popstate, popnode = self.stack.pop() - newnode = self.convert(self.grammar, popnode) - if newnode is not None: - if self.stack: - dfa, state, node = self.stack[-1] - node[-1].append(newnode) - else: - self.rootnode = newnode - self.rootnode.used_names = self.used_names diff --git a/PythonLib/extra/lib2to3/pygram.py b/PythonLib/extra/lib2to3/pygram.py deleted file mode 100644 index 621ff24c..00000000 --- a/PythonLib/extra/lib2to3/pygram.py +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright 2006 Google, Inc. All Rights Reserved. -# Licensed to PSF under a Contributor Agreement. - -"""Export the Python grammar and symbols.""" - -# Python imports -import os - -# Local imports -from .pgen2 import token -from .pgen2 import driver -from . import pytree - -# The grammar file -_GRAMMAR_FILE = os.path.join(os.path.dirname(__file__), "Grammar.txt") -_PATTERN_GRAMMAR_FILE = os.path.join(os.path.dirname(__file__), - "PatternGrammar.txt") - - -class Symbols(object): - - def __init__(self, grammar): - """Initializer. - - Creates an attribute for each grammar symbol (nonterminal), - whose value is the symbol's type (an int >= 256). - """ - for name, symbol in grammar.symbol2number.iteritems(): - setattr(self, name, symbol) - - -python_grammar = driver.load_grammar(_GRAMMAR_FILE) - -python_symbols = Symbols(python_grammar) - -python_grammar_no_print_statement = python_grammar.copy() -del python_grammar_no_print_statement.keywords["print"] - -pattern_grammar = driver.load_grammar(_PATTERN_GRAMMAR_FILE) -pattern_symbols = Symbols(pattern_grammar) diff --git a/PythonLib/extra/lib2to3/tests/__init__.py b/PythonLib/extra/lib2to3/tests/__init__.py deleted file mode 100644 index cfaea0de..00000000 --- a/PythonLib/extra/lib2to3/tests/__init__.py +++ /dev/null @@ -1,24 +0,0 @@ -"""Make tests/ into a package. This allows us to "import tests" and -have tests.all_tests be a TestSuite representing all test cases -from all test_*.py files in tests/.""" -# Author: Collin Winter - -import os -import os.path -import unittest -import types - -from . import support - -all_tests = unittest.TestSuite() - -tests_dir = os.path.join(os.path.dirname(__file__), '..', 'tests') -tests = [t[0:-3] for t in os.listdir(tests_dir) - if t.startswith('test_') and t.endswith('.py')] - -loader = unittest.TestLoader() - -for t in tests: - __import__("",globals(),locals(),[t],level=1) - mod = globals()[t] - all_tests.addTests(loader.loadTestsFromModule(mod)) diff --git a/PythonLib/extra/lib2to3/tests/data/README b/PythonLib/extra/lib2to3/tests/data/README deleted file mode 100644 index 7aa47e40..00000000 --- a/PythonLib/extra/lib2to3/tests/data/README +++ /dev/null @@ -1,6 +0,0 @@ -In this directory: -- py2_test_grammar.py -- test file that exercises most/all of Python 2.x's grammar. -- py3_test_grammar.py -- test file that exercises most/all of Python 3.x's grammar. -- infinite_recursion.py -- test file that causes lib2to3's faster recursive pattern matching - scheme to fail, but passes when lib2to3 falls back to iterative pattern matching. -- fixes/ -- for use by test_refactor.py diff --git a/PythonLib/extra/lib2to3/tests/data/bom.py b/PythonLib/extra/lib2to3/tests/data/bom.py deleted file mode 100644 index 9bc3975a..00000000 --- a/PythonLib/extra/lib2to3/tests/data/bom.py +++ /dev/null @@ -1,2 +0,0 @@ -# coding: utf-8 -print "BOM BOOM!" diff --git a/PythonLib/extra/lib2to3/tests/data/crlf.py b/PythonLib/extra/lib2to3/tests/data/crlf.py deleted file mode 100644 index dbe2d7bb..00000000 --- a/PythonLib/extra/lib2to3/tests/data/crlf.py +++ /dev/null @@ -1,3 +0,0 @@ -print "hi" - -print "Like bad Windows newlines?" diff --git a/PythonLib/extra/lib2to3/tests/data/different_encoding.py b/PythonLib/extra/lib2to3/tests/data/different_encoding.py deleted file mode 100644 index 9f32bd04..00000000 --- a/PythonLib/extra/lib2to3/tests/data/different_encoding.py +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -print u'ßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ' - -def f(x): - print '%s\t-> α(%2i):%s β(%s)' diff --git a/PythonLib/extra/lib2to3/tests/data/false_encoding.py b/PythonLib/extra/lib2to3/tests/data/false_encoding.py deleted file mode 100644 index f4e59e78..00000000 --- a/PythonLib/extra/lib2to3/tests/data/false_encoding.py +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env python -print '#coding=0' diff --git a/PythonLib/extra/lib2to3/tests/data/fixers/bad_order.py b/PythonLib/extra/lib2to3/tests/data/fixers/bad_order.py deleted file mode 100644 index 061bbf20..00000000 --- a/PythonLib/extra/lib2to3/tests/data/fixers/bad_order.py +++ /dev/null @@ -1,5 +0,0 @@ -from lib2to3.fixer_base import BaseFix - -class FixBadOrder(BaseFix): - - order = "crazy" diff --git a/PythonLib/extra/lib2to3/tests/data/fixers/myfixes/fix_explicit.py b/PythonLib/extra/lib2to3/tests/data/fixers/myfixes/fix_explicit.py deleted file mode 100644 index cbe16f6f..00000000 --- a/PythonLib/extra/lib2to3/tests/data/fixers/myfixes/fix_explicit.py +++ /dev/null @@ -1,6 +0,0 @@ -from lib2to3.fixer_base import BaseFix - -class FixExplicit(BaseFix): - explicit = True - - def match(self): return False diff --git a/PythonLib/extra/lib2to3/tests/data/fixers/myfixes/fix_first.py b/PythonLib/extra/lib2to3/tests/data/fixers/myfixes/fix_first.py deleted file mode 100644 index a88821f0..00000000 --- a/PythonLib/extra/lib2to3/tests/data/fixers/myfixes/fix_first.py +++ /dev/null @@ -1,6 +0,0 @@ -from lib2to3.fixer_base import BaseFix - -class FixFirst(BaseFix): - run_order = 1 - - def match(self, node): return False diff --git a/PythonLib/extra/lib2to3/tests/data/fixers/myfixes/fix_last.py b/PythonLib/extra/lib2to3/tests/data/fixers/myfixes/fix_last.py deleted file mode 100644 index 9a077d41..00000000 --- a/PythonLib/extra/lib2to3/tests/data/fixers/myfixes/fix_last.py +++ /dev/null @@ -1,7 +0,0 @@ -from lib2to3.fixer_base import BaseFix - -class FixLast(BaseFix): - - run_order = 10 - - def match(self, node): return False diff --git a/PythonLib/extra/lib2to3/tests/data/fixers/myfixes/fix_parrot.py b/PythonLib/extra/lib2to3/tests/data/fixers/myfixes/fix_parrot.py deleted file mode 100644 index 6db79adf..00000000 --- a/PythonLib/extra/lib2to3/tests/data/fixers/myfixes/fix_parrot.py +++ /dev/null @@ -1,13 +0,0 @@ -from lib2to3.fixer_base import BaseFix -from lib2to3.fixer_util import Name - -class FixParrot(BaseFix): - """ - Change functions named 'parrot' to 'cheese'. - """ - - PATTERN = """funcdef < 'def' name='parrot' any* >""" - - def transform(self, node, results): - name = results["name"] - name.replace(Name("cheese", name.prefix)) diff --git a/PythonLib/extra/lib2to3/tests/data/fixers/myfixes/fix_preorder.py b/PythonLib/extra/lib2to3/tests/data/fixers/myfixes/fix_preorder.py deleted file mode 100644 index b9bfbba9..00000000 --- a/PythonLib/extra/lib2to3/tests/data/fixers/myfixes/fix_preorder.py +++ /dev/null @@ -1,6 +0,0 @@ -from lib2to3.fixer_base import BaseFix - -class FixPreorder(BaseFix): - order = "pre" - - def match(self, node): return False diff --git a/PythonLib/extra/lib2to3/tests/data/fixers/no_fixer_cls.py b/PythonLib/extra/lib2to3/tests/data/fixers/no_fixer_cls.py deleted file mode 100644 index 506f7949..00000000 --- a/PythonLib/extra/lib2to3/tests/data/fixers/no_fixer_cls.py +++ /dev/null @@ -1 +0,0 @@ -# This is empty so trying to fetch the fixer class gives an AttributeError diff --git a/PythonLib/extra/lib2to3/tests/data/fixers/parrot_example.py b/PythonLib/extra/lib2to3/tests/data/fixers/parrot_example.py deleted file mode 100644 index 08529280..00000000 --- a/PythonLib/extra/lib2to3/tests/data/fixers/parrot_example.py +++ /dev/null @@ -1,2 +0,0 @@ -def parrot(): - pass diff --git a/PythonLib/extra/lib2to3/tests/data/infinite_recursion.py b/PythonLib/extra/lib2to3/tests/data/infinite_recursion.py deleted file mode 100644 index 71715ef2..00000000 --- a/PythonLib/extra/lib2to3/tests/data/infinite_recursion.py +++ /dev/null @@ -1,2669 +0,0 @@ -# This file is used to verify that 2to3 falls back to a slower, iterative pattern matching -# scheme in the event that the faster recursive system fails due to infinite recursion. -from ctypes import * -STRING = c_char_p - - -OSUnknownByteOrder = 0 -UIT_PROMPT = 1 -P_PGID = 2 -P_PID = 1 -UIT_ERROR = 5 -UIT_INFO = 4 -UIT_NONE = 0 -P_ALL = 0 -UIT_VERIFY = 2 -OSBigEndian = 2 -UIT_BOOLEAN = 3 -OSLittleEndian = 1 -__darwin_nl_item = c_int -__darwin_wctrans_t = c_int -__darwin_wctype_t = c_ulong -__int8_t = c_byte -__uint8_t = c_ubyte -__int16_t = c_short -__uint16_t = c_ushort -__int32_t = c_int -__uint32_t = c_uint -__int64_t = c_longlong -__uint64_t = c_ulonglong -__darwin_intptr_t = c_long -__darwin_natural_t = c_uint -__darwin_ct_rune_t = c_int -class __mbstate_t(Union): - pass -__mbstate_t._pack_ = 4 -__mbstate_t._fields_ = [ - ('__mbstate8', c_char * 128), - ('_mbstateL', c_longlong), -] -assert sizeof(__mbstate_t) == 128, sizeof(__mbstate_t) -assert alignment(__mbstate_t) == 4, alignment(__mbstate_t) -__darwin_mbstate_t = __mbstate_t -__darwin_ptrdiff_t = c_int -__darwin_size_t = c_ulong -__darwin_va_list = STRING -__darwin_wchar_t = c_int -__darwin_rune_t = __darwin_wchar_t -__darwin_wint_t = c_int -__darwin_clock_t = c_ulong -__darwin_socklen_t = __uint32_t -__darwin_ssize_t = c_long -__darwin_time_t = c_long -sig_atomic_t = c_int -class sigcontext(Structure): - pass -sigcontext._fields_ = [ - ('sc_onstack', c_int), - ('sc_mask', c_int), - ('sc_eax', c_uint), - ('sc_ebx', c_uint), - ('sc_ecx', c_uint), - ('sc_edx', c_uint), - ('sc_edi', c_uint), - ('sc_esi', c_uint), - ('sc_ebp', c_uint), - ('sc_esp', c_uint), - ('sc_ss', c_uint), - ('sc_eflags', c_uint), - ('sc_eip', c_uint), - ('sc_cs', c_uint), - ('sc_ds', c_uint), - ('sc_es', c_uint), - ('sc_fs', c_uint), - ('sc_gs', c_uint), -] -assert sizeof(sigcontext) == 72, sizeof(sigcontext) -assert alignment(sigcontext) == 4, alignment(sigcontext) -u_int8_t = c_ubyte -u_int16_t = c_ushort -u_int32_t = c_uint -u_int64_t = c_ulonglong -int32_t = c_int -register_t = int32_t -user_addr_t = u_int64_t -user_size_t = u_int64_t -int64_t = c_longlong -user_ssize_t = int64_t -user_long_t = int64_t -user_ulong_t = u_int64_t -user_time_t = int64_t -syscall_arg_t = u_int64_t - -# values for unnamed enumeration -class aes_key_st(Structure): - pass -aes_key_st._fields_ = [ - ('rd_key', c_ulong * 60), - ('rounds', c_int), -] -assert sizeof(aes_key_st) == 244, sizeof(aes_key_st) -assert alignment(aes_key_st) == 4, alignment(aes_key_st) -AES_KEY = aes_key_st -class asn1_ctx_st(Structure): - pass -asn1_ctx_st._fields_ = [ - ('p', POINTER(c_ubyte)), - ('eos', c_int), - ('error', c_int), - ('inf', c_int), - ('tag', c_int), - ('xclass', c_int), - ('slen', c_long), - ('max', POINTER(c_ubyte)), - ('q', POINTER(c_ubyte)), - ('pp', POINTER(POINTER(c_ubyte))), - ('line', c_int), -] -assert sizeof(asn1_ctx_st) == 44, sizeof(asn1_ctx_st) -assert alignment(asn1_ctx_st) == 4, alignment(asn1_ctx_st) -ASN1_CTX = asn1_ctx_st -class asn1_object_st(Structure): - pass -asn1_object_st._fields_ = [ - ('sn', STRING), - ('ln', STRING), - ('nid', c_int), - ('length', c_int), - ('data', POINTER(c_ubyte)), - ('flags', c_int), -] -assert sizeof(asn1_object_st) == 24, sizeof(asn1_object_st) -assert alignment(asn1_object_st) == 4, alignment(asn1_object_st) -ASN1_OBJECT = asn1_object_st -class asn1_string_st(Structure): - pass -asn1_string_st._fields_ = [ - ('length', c_int), - ('type', c_int), - ('data', POINTER(c_ubyte)), - ('flags', c_long), -] -assert sizeof(asn1_string_st) == 16, sizeof(asn1_string_st) -assert alignment(asn1_string_st) == 4, alignment(asn1_string_st) -ASN1_STRING = asn1_string_st -class ASN1_ENCODING_st(Structure): - pass -ASN1_ENCODING_st._fields_ = [ - ('enc', POINTER(c_ubyte)), - ('len', c_long), - ('modified', c_int), -] -assert sizeof(ASN1_ENCODING_st) == 12, sizeof(ASN1_ENCODING_st) -assert alignment(ASN1_ENCODING_st) == 4, alignment(ASN1_ENCODING_st) -ASN1_ENCODING = ASN1_ENCODING_st -class asn1_string_table_st(Structure): - pass -asn1_string_table_st._fields_ = [ - ('nid', c_int), - ('minsize', c_long), - ('maxsize', c_long), - ('mask', c_ulong), - ('flags', c_ulong), -] -assert sizeof(asn1_string_table_st) == 20, sizeof(asn1_string_table_st) -assert alignment(asn1_string_table_st) == 4, alignment(asn1_string_table_st) -ASN1_STRING_TABLE = asn1_string_table_st -class ASN1_TEMPLATE_st(Structure): - pass -ASN1_TEMPLATE_st._fields_ = [ -] -ASN1_TEMPLATE = ASN1_TEMPLATE_st -class ASN1_ITEM_st(Structure): - pass -ASN1_ITEM = ASN1_ITEM_st -ASN1_ITEM_st._fields_ = [ -] -class ASN1_TLC_st(Structure): - pass -ASN1_TLC = ASN1_TLC_st -ASN1_TLC_st._fields_ = [ -] -class ASN1_VALUE_st(Structure): - pass -ASN1_VALUE_st._fields_ = [ -] -ASN1_VALUE = ASN1_VALUE_st -ASN1_ITEM_EXP = ASN1_ITEM -class asn1_type_st(Structure): - pass -class N12asn1_type_st4DOLLAR_11E(Union): - pass -ASN1_BOOLEAN = c_int -ASN1_INTEGER = asn1_string_st -ASN1_ENUMERATED = asn1_string_st -ASN1_BIT_STRING = asn1_string_st -ASN1_OCTET_STRING = asn1_string_st -ASN1_PRINTABLESTRING = asn1_string_st -ASN1_T61STRING = asn1_string_st -ASN1_IA5STRING = asn1_string_st -ASN1_GENERALSTRING = asn1_string_st -ASN1_BMPSTRING = asn1_string_st -ASN1_UNIVERSALSTRING = asn1_string_st -ASN1_UTCTIME = asn1_string_st -ASN1_GENERALIZEDTIME = asn1_string_st -ASN1_VISIBLESTRING = asn1_string_st -ASN1_UTF8STRING = asn1_string_st -N12asn1_type_st4DOLLAR_11E._fields_ = [ - ('ptr', STRING), - ('boolean', ASN1_BOOLEAN), - ('asn1_string', POINTER(ASN1_STRING)), - ('object', POINTER(ASN1_OBJECT)), - ('integer', POINTER(ASN1_INTEGER)), - ('enumerated', POINTER(ASN1_ENUMERATED)), - ('bit_string', POINTER(ASN1_BIT_STRING)), - ('octet_string', POINTER(ASN1_OCTET_STRING)), - ('printablestring', POINTER(ASN1_PRINTABLESTRING)), - ('t61string', POINTER(ASN1_T61STRING)), - ('ia5string', POINTER(ASN1_IA5STRING)), - ('generalstring', POINTER(ASN1_GENERALSTRING)), - ('bmpstring', POINTER(ASN1_BMPSTRING)), - ('universalstring', POINTER(ASN1_UNIVERSALSTRING)), - ('utctime', POINTER(ASN1_UTCTIME)), - ('generalizedtime', POINTER(ASN1_GENERALIZEDTIME)), - ('visiblestring', POINTER(ASN1_VISIBLESTRING)), - ('utf8string', POINTER(ASN1_UTF8STRING)), - ('set', POINTER(ASN1_STRING)), - ('sequence', POINTER(ASN1_STRING)), -] -assert sizeof(N12asn1_type_st4DOLLAR_11E) == 4, sizeof(N12asn1_type_st4DOLLAR_11E) -assert alignment(N12asn1_type_st4DOLLAR_11E) == 4, alignment(N12asn1_type_st4DOLLAR_11E) -asn1_type_st._fields_ = [ - ('type', c_int), - ('value', N12asn1_type_st4DOLLAR_11E), -] -assert sizeof(asn1_type_st) == 8, sizeof(asn1_type_st) -assert alignment(asn1_type_st) == 4, alignment(asn1_type_st) -ASN1_TYPE = asn1_type_st -class asn1_method_st(Structure): - pass -asn1_method_st._fields_ = [ - ('i2d', CFUNCTYPE(c_int)), - ('d2i', CFUNCTYPE(STRING)), - ('create', CFUNCTYPE(STRING)), - ('destroy', CFUNCTYPE(None)), -] -assert sizeof(asn1_method_st) == 16, sizeof(asn1_method_st) -assert alignment(asn1_method_st) == 4, alignment(asn1_method_st) -ASN1_METHOD = asn1_method_st -class asn1_header_st(Structure): - pass -asn1_header_st._fields_ = [ - ('header', POINTER(ASN1_OCTET_STRING)), - ('data', STRING), - ('meth', POINTER(ASN1_METHOD)), -] -assert sizeof(asn1_header_st) == 12, sizeof(asn1_header_st) -assert alignment(asn1_header_st) == 4, alignment(asn1_header_st) -ASN1_HEADER = asn1_header_st -class BIT_STRING_BITNAME_st(Structure): - pass -BIT_STRING_BITNAME_st._fields_ = [ - ('bitnum', c_int), - ('lname', STRING), - ('sname', STRING), -] -assert sizeof(BIT_STRING_BITNAME_st) == 12, sizeof(BIT_STRING_BITNAME_st) -assert alignment(BIT_STRING_BITNAME_st) == 4, alignment(BIT_STRING_BITNAME_st) -BIT_STRING_BITNAME = BIT_STRING_BITNAME_st -class bio_st(Structure): - pass -BIO = bio_st -bio_info_cb = CFUNCTYPE(None, POINTER(bio_st), c_int, STRING, c_int, c_long, c_long) -class bio_method_st(Structure): - pass -bio_method_st._fields_ = [ - ('type', c_int), - ('name', STRING), - ('bwrite', CFUNCTYPE(c_int, POINTER(BIO), STRING, c_int)), - ('bread', CFUNCTYPE(c_int, POINTER(BIO), STRING, c_int)), - ('bputs', CFUNCTYPE(c_int, POINTER(BIO), STRING)), - ('bgets', CFUNCTYPE(c_int, POINTER(BIO), STRING, c_int)), - ('ctrl', CFUNCTYPE(c_long, POINTER(BIO), c_int, c_long, c_void_p)), - ('create', CFUNCTYPE(c_int, POINTER(BIO))), - ('destroy', CFUNCTYPE(c_int, POINTER(BIO))), - ('callback_ctrl', CFUNCTYPE(c_long, POINTER(BIO), c_int, POINTER(bio_info_cb))), -] -assert sizeof(bio_method_st) == 40, sizeof(bio_method_st) -assert alignment(bio_method_st) == 4, alignment(bio_method_st) -BIO_METHOD = bio_method_st -class crypto_ex_data_st(Structure): - pass -class stack_st(Structure): - pass -STACK = stack_st -crypto_ex_data_st._fields_ = [ - ('sk', POINTER(STACK)), - ('dummy', c_int), -] -assert sizeof(crypto_ex_data_st) == 8, sizeof(crypto_ex_data_st) -assert alignment(crypto_ex_data_st) == 4, alignment(crypto_ex_data_st) -CRYPTO_EX_DATA = crypto_ex_data_st -bio_st._fields_ = [ - ('method', POINTER(BIO_METHOD)), - ('callback', CFUNCTYPE(c_long, POINTER(bio_st), c_int, STRING, c_int, c_long, c_long)), - ('cb_arg', STRING), - ('init', c_int), - ('shutdown', c_int), - ('flags', c_int), - ('retry_reason', c_int), - ('num', c_int), - ('ptr', c_void_p), - ('next_bio', POINTER(bio_st)), - ('prev_bio', POINTER(bio_st)), - ('references', c_int), - ('num_read', c_ulong), - ('num_write', c_ulong), - ('ex_data', CRYPTO_EX_DATA), -] -assert sizeof(bio_st) == 64, sizeof(bio_st) -assert alignment(bio_st) == 4, alignment(bio_st) -class bio_f_buffer_ctx_struct(Structure): - pass -bio_f_buffer_ctx_struct._fields_ = [ - ('ibuf_size', c_int), - ('obuf_size', c_int), - ('ibuf', STRING), - ('ibuf_len', c_int), - ('ibuf_off', c_int), - ('obuf', STRING), - ('obuf_len', c_int), - ('obuf_off', c_int), -] -assert sizeof(bio_f_buffer_ctx_struct) == 32, sizeof(bio_f_buffer_ctx_struct) -assert alignment(bio_f_buffer_ctx_struct) == 4, alignment(bio_f_buffer_ctx_struct) -BIO_F_BUFFER_CTX = bio_f_buffer_ctx_struct -class hostent(Structure): - pass -hostent._fields_ = [ -] -class bf_key_st(Structure): - pass -bf_key_st._fields_ = [ - ('P', c_uint * 18), - ('S', c_uint * 1024), -] -assert sizeof(bf_key_st) == 4168, sizeof(bf_key_st) -assert alignment(bf_key_st) == 4, alignment(bf_key_st) -BF_KEY = bf_key_st -class bignum_st(Structure): - pass -bignum_st._fields_ = [ - ('d', POINTER(c_ulong)), - ('top', c_int), - ('dmax', c_int), - ('neg', c_int), - ('flags', c_int), -] -assert sizeof(bignum_st) == 20, sizeof(bignum_st) -assert alignment(bignum_st) == 4, alignment(bignum_st) -BIGNUM = bignum_st -class bignum_ctx(Structure): - pass -bignum_ctx._fields_ = [ -] -BN_CTX = bignum_ctx -class bn_blinding_st(Structure): - pass -bn_blinding_st._fields_ = [ - ('init', c_int), - ('A', POINTER(BIGNUM)), - ('Ai', POINTER(BIGNUM)), - ('mod', POINTER(BIGNUM)), - ('thread_id', c_ulong), -] -assert sizeof(bn_blinding_st) == 20, sizeof(bn_blinding_st) -assert alignment(bn_blinding_st) == 4, alignment(bn_blinding_st) -BN_BLINDING = bn_blinding_st -class bn_mont_ctx_st(Structure): - pass -bn_mont_ctx_st._fields_ = [ - ('ri', c_int), - ('RR', BIGNUM), - ('N', BIGNUM), - ('Ni', BIGNUM), - ('n0', c_ulong), - ('flags', c_int), -] -assert sizeof(bn_mont_ctx_st) == 72, sizeof(bn_mont_ctx_st) -assert alignment(bn_mont_ctx_st) == 4, alignment(bn_mont_ctx_st) -BN_MONT_CTX = bn_mont_ctx_st -class bn_recp_ctx_st(Structure): - pass -bn_recp_ctx_st._fields_ = [ - ('N', BIGNUM), - ('Nr', BIGNUM), - ('num_bits', c_int), - ('shift', c_int), - ('flags', c_int), -] -assert sizeof(bn_recp_ctx_st) == 52, sizeof(bn_recp_ctx_st) -assert alignment(bn_recp_ctx_st) == 4, alignment(bn_recp_ctx_st) -BN_RECP_CTX = bn_recp_ctx_st -class buf_mem_st(Structure): - pass -buf_mem_st._fields_ = [ - ('length', c_int), - ('data', STRING), - ('max', c_int), -] -assert sizeof(buf_mem_st) == 12, sizeof(buf_mem_st) -assert alignment(buf_mem_st) == 4, alignment(buf_mem_st) -BUF_MEM = buf_mem_st -class cast_key_st(Structure): - pass -cast_key_st._fields_ = [ - ('data', c_ulong * 32), - ('short_key', c_int), -] -assert sizeof(cast_key_st) == 132, sizeof(cast_key_st) -assert alignment(cast_key_st) == 4, alignment(cast_key_st) -CAST_KEY = cast_key_st -class comp_method_st(Structure): - pass -comp_method_st._fields_ = [ - ('type', c_int), - ('name', STRING), - ('init', CFUNCTYPE(c_int)), - ('finish', CFUNCTYPE(None)), - ('compress', CFUNCTYPE(c_int)), - ('expand', CFUNCTYPE(c_int)), - ('ctrl', CFUNCTYPE(c_long)), - ('callback_ctrl', CFUNCTYPE(c_long)), -] -assert sizeof(comp_method_st) == 32, sizeof(comp_method_st) -assert alignment(comp_method_st) == 4, alignment(comp_method_st) -COMP_METHOD = comp_method_st -class comp_ctx_st(Structure): - pass -comp_ctx_st._fields_ = [ - ('meth', POINTER(COMP_METHOD)), - ('compress_in', c_ulong), - ('compress_out', c_ulong), - ('expand_in', c_ulong), - ('expand_out', c_ulong), - ('ex_data', CRYPTO_EX_DATA), -] -assert sizeof(comp_ctx_st) == 28, sizeof(comp_ctx_st) -assert alignment(comp_ctx_st) == 4, alignment(comp_ctx_st) -COMP_CTX = comp_ctx_st -class CRYPTO_dynlock_value(Structure): - pass -CRYPTO_dynlock_value._fields_ = [ -] -class CRYPTO_dynlock(Structure): - pass -CRYPTO_dynlock._fields_ = [ - ('references', c_int), - ('data', POINTER(CRYPTO_dynlock_value)), -] -assert sizeof(CRYPTO_dynlock) == 8, sizeof(CRYPTO_dynlock) -assert alignment(CRYPTO_dynlock) == 4, alignment(CRYPTO_dynlock) -BIO_dummy = bio_st -CRYPTO_EX_new = CFUNCTYPE(c_int, c_void_p, c_void_p, POINTER(CRYPTO_EX_DATA), c_int, c_long, c_void_p) -CRYPTO_EX_free = CFUNCTYPE(None, c_void_p, c_void_p, POINTER(CRYPTO_EX_DATA), c_int, c_long, c_void_p) -CRYPTO_EX_dup = CFUNCTYPE(c_int, POINTER(CRYPTO_EX_DATA), POINTER(CRYPTO_EX_DATA), c_void_p, c_int, c_long, c_void_p) -class crypto_ex_data_func_st(Structure): - pass -crypto_ex_data_func_st._fields_ = [ - ('argl', c_long), - ('argp', c_void_p), - ('new_func', POINTER(CRYPTO_EX_new)), - ('free_func', POINTER(CRYPTO_EX_free)), - ('dup_func', POINTER(CRYPTO_EX_dup)), -] -assert sizeof(crypto_ex_data_func_st) == 20, sizeof(crypto_ex_data_func_st) -assert alignment(crypto_ex_data_func_st) == 4, alignment(crypto_ex_data_func_st) -CRYPTO_EX_DATA_FUNCS = crypto_ex_data_func_st -class st_CRYPTO_EX_DATA_IMPL(Structure): - pass -CRYPTO_EX_DATA_IMPL = st_CRYPTO_EX_DATA_IMPL -st_CRYPTO_EX_DATA_IMPL._fields_ = [ -] -CRYPTO_MEM_LEAK_CB = CFUNCTYPE(c_void_p, c_ulong, STRING, c_int, c_int, c_void_p) -DES_cblock = c_ubyte * 8 -const_DES_cblock = c_ubyte * 8 -class DES_ks(Structure): - pass -class N6DES_ks3DOLLAR_9E(Union): - pass -N6DES_ks3DOLLAR_9E._fields_ = [ - ('cblock', DES_cblock), - ('deslong', c_ulong * 2), -] -assert sizeof(N6DES_ks3DOLLAR_9E) == 8, sizeof(N6DES_ks3DOLLAR_9E) -assert alignment(N6DES_ks3DOLLAR_9E) == 4, alignment(N6DES_ks3DOLLAR_9E) -DES_ks._fields_ = [ - ('ks', N6DES_ks3DOLLAR_9E * 16), -] -assert sizeof(DES_ks) == 128, sizeof(DES_ks) -assert alignment(DES_ks) == 4, alignment(DES_ks) -DES_key_schedule = DES_ks -_ossl_old_des_cblock = c_ubyte * 8 -class _ossl_old_des_ks_struct(Structure): - pass -class N23_ossl_old_des_ks_struct4DOLLAR_10E(Union): - pass -N23_ossl_old_des_ks_struct4DOLLAR_10E._fields_ = [ - ('_', _ossl_old_des_cblock), - ('pad', c_ulong * 2), -] -assert sizeof(N23_ossl_old_des_ks_struct4DOLLAR_10E) == 8, sizeof(N23_ossl_old_des_ks_struct4DOLLAR_10E) -assert alignment(N23_ossl_old_des_ks_struct4DOLLAR_10E) == 4, alignment(N23_ossl_old_des_ks_struct4DOLLAR_10E) -_ossl_old_des_ks_struct._fields_ = [ - ('ks', N23_ossl_old_des_ks_struct4DOLLAR_10E), -] -assert sizeof(_ossl_old_des_ks_struct) == 8, sizeof(_ossl_old_des_ks_struct) -assert alignment(_ossl_old_des_ks_struct) == 4, alignment(_ossl_old_des_ks_struct) -_ossl_old_des_key_schedule = _ossl_old_des_ks_struct * 16 -class dh_st(Structure): - pass -DH = dh_st -class dh_method(Structure): - pass -dh_method._fields_ = [ - ('name', STRING), - ('generate_key', CFUNCTYPE(c_int, POINTER(DH))), - ('compute_key', CFUNCTYPE(c_int, POINTER(c_ubyte), POINTER(BIGNUM), POINTER(DH))), - ('bn_mod_exp', CFUNCTYPE(c_int, POINTER(DH), POINTER(BIGNUM), POINTER(BIGNUM), POINTER(BIGNUM), POINTER(BIGNUM), POINTER(BN_CTX), POINTER(BN_MONT_CTX))), - ('init', CFUNCTYPE(c_int, POINTER(DH))), - ('finish', CFUNCTYPE(c_int, POINTER(DH))), - ('flags', c_int), - ('app_data', STRING), -] -assert sizeof(dh_method) == 32, sizeof(dh_method) -assert alignment(dh_method) == 4, alignment(dh_method) -DH_METHOD = dh_method -class engine_st(Structure): - pass -ENGINE = engine_st -dh_st._fields_ = [ - ('pad', c_int), - ('version', c_int), - ('p', POINTER(BIGNUM)), - ('g', POINTER(BIGNUM)), - ('length', c_long), - ('pub_key', POINTER(BIGNUM)), - ('priv_key', POINTER(BIGNUM)), - ('flags', c_int), - ('method_mont_p', STRING), - ('q', POINTER(BIGNUM)), - ('j', POINTER(BIGNUM)), - ('seed', POINTER(c_ubyte)), - ('seedlen', c_int), - ('counter', POINTER(BIGNUM)), - ('references', c_int), - ('ex_data', CRYPTO_EX_DATA), - ('meth', POINTER(DH_METHOD)), - ('engine', POINTER(ENGINE)), -] -assert sizeof(dh_st) == 76, sizeof(dh_st) -assert alignment(dh_st) == 4, alignment(dh_st) -class dsa_st(Structure): - pass -DSA = dsa_st -class DSA_SIG_st(Structure): - pass -DSA_SIG_st._fields_ = [ - ('r', POINTER(BIGNUM)), - ('s', POINTER(BIGNUM)), -] -assert sizeof(DSA_SIG_st) == 8, sizeof(DSA_SIG_st) -assert alignment(DSA_SIG_st) == 4, alignment(DSA_SIG_st) -DSA_SIG = DSA_SIG_st -class dsa_method(Structure): - pass -dsa_method._fields_ = [ - ('name', STRING), - ('dsa_do_sign', CFUNCTYPE(POINTER(DSA_SIG), POINTER(c_ubyte), c_int, POINTER(DSA))), - ('dsa_sign_setup', CFUNCTYPE(c_int, POINTER(DSA), POINTER(BN_CTX), POINTER(POINTER(BIGNUM)), POINTER(POINTER(BIGNUM)))), - ('dsa_do_verify', CFUNCTYPE(c_int, POINTER(c_ubyte), c_int, POINTER(DSA_SIG), POINTER(DSA))), - ('dsa_mod_exp', CFUNCTYPE(c_int, POINTER(DSA), POINTER(BIGNUM), POINTER(BIGNUM), POINTER(BIGNUM), POINTER(BIGNUM), POINTER(BIGNUM), POINTER(BIGNUM), POINTER(BN_CTX), POINTER(BN_MONT_CTX))), - ('bn_mod_exp', CFUNCTYPE(c_int, POINTER(DSA), POINTER(BIGNUM), POINTER(BIGNUM), POINTER(BIGNUM), POINTER(BIGNUM), POINTER(BN_CTX), POINTER(BN_MONT_CTX))), - ('init', CFUNCTYPE(c_int, POINTER(DSA))), - ('finish', CFUNCTYPE(c_int, POINTER(DSA))), - ('flags', c_int), - ('app_data', STRING), -] -assert sizeof(dsa_method) == 40, sizeof(dsa_method) -assert alignment(dsa_method) == 4, alignment(dsa_method) -DSA_METHOD = dsa_method -dsa_st._fields_ = [ - ('pad', c_int), - ('version', c_long), - ('write_params', c_int), - ('p', POINTER(BIGNUM)), - ('q', POINTER(BIGNUM)), - ('g', POINTER(BIGNUM)), - ('pub_key', POINTER(BIGNUM)), - ('priv_key', POINTER(BIGNUM)), - ('kinv', POINTER(BIGNUM)), - ('r', POINTER(BIGNUM)), - ('flags', c_int), - ('method_mont_p', STRING), - ('references', c_int), - ('ex_data', CRYPTO_EX_DATA), - ('meth', POINTER(DSA_METHOD)), - ('engine', POINTER(ENGINE)), -] -assert sizeof(dsa_st) == 68, sizeof(dsa_st) -assert alignment(dsa_st) == 4, alignment(dsa_st) -class evp_pkey_st(Structure): - pass -class N11evp_pkey_st4DOLLAR_12E(Union): - pass -class rsa_st(Structure): - pass -N11evp_pkey_st4DOLLAR_12E._fields_ = [ - ('ptr', STRING), - ('rsa', POINTER(rsa_st)), - ('dsa', POINTER(dsa_st)), - ('dh', POINTER(dh_st)), -] -assert sizeof(N11evp_pkey_st4DOLLAR_12E) == 4, sizeof(N11evp_pkey_st4DOLLAR_12E) -assert alignment(N11evp_pkey_st4DOLLAR_12E) == 4, alignment(N11evp_pkey_st4DOLLAR_12E) -evp_pkey_st._fields_ = [ - ('type', c_int), - ('save_type', c_int), - ('references', c_int), - ('pkey', N11evp_pkey_st4DOLLAR_12E), - ('save_parameters', c_int), - ('attributes', POINTER(STACK)), -] -assert sizeof(evp_pkey_st) == 24, sizeof(evp_pkey_st) -assert alignment(evp_pkey_st) == 4, alignment(evp_pkey_st) -class env_md_st(Structure): - pass -class env_md_ctx_st(Structure): - pass -EVP_MD_CTX = env_md_ctx_st -env_md_st._fields_ = [ - ('type', c_int), - ('pkey_type', c_int), - ('md_size', c_int), - ('flags', c_ulong), - ('init', CFUNCTYPE(c_int, POINTER(EVP_MD_CTX))), - ('update', CFUNCTYPE(c_int, POINTER(EVP_MD_CTX), c_void_p, c_ulong)), - ('final', CFUNCTYPE(c_int, POINTER(EVP_MD_CTX), POINTER(c_ubyte))), - ('copy', CFUNCTYPE(c_int, POINTER(EVP_MD_CTX), POINTER(EVP_MD_CTX))), - ('cleanup', CFUNCTYPE(c_int, POINTER(EVP_MD_CTX))), - ('sign', CFUNCTYPE(c_int)), - ('verify', CFUNCTYPE(c_int)), - ('required_pkey_type', c_int * 5), - ('block_size', c_int), - ('ctx_size', c_int), -] -assert sizeof(env_md_st) == 72, sizeof(env_md_st) -assert alignment(env_md_st) == 4, alignment(env_md_st) -EVP_MD = env_md_st -env_md_ctx_st._fields_ = [ - ('digest', POINTER(EVP_MD)), - ('engine', POINTER(ENGINE)), - ('flags', c_ulong), - ('md_data', c_void_p), -] -assert sizeof(env_md_ctx_st) == 16, sizeof(env_md_ctx_st) -assert alignment(env_md_ctx_st) == 4, alignment(env_md_ctx_st) -class evp_cipher_st(Structure): - pass -class evp_cipher_ctx_st(Structure): - pass -EVP_CIPHER_CTX = evp_cipher_ctx_st -evp_cipher_st._fields_ = [ - ('nid', c_int), - ('block_size', c_int), - ('key_len', c_int), - ('iv_len', c_int), - ('flags', c_ulong), - ('init', CFUNCTYPE(c_int, POINTER(EVP_CIPHER_CTX), POINTER(c_ubyte), POINTER(c_ubyte), c_int)), - ('do_cipher', CFUNCTYPE(c_int, POINTER(EVP_CIPHER_CTX), POINTER(c_ubyte), POINTER(c_ubyte), c_uint)), - ('cleanup', CFUNCTYPE(c_int, POINTER(EVP_CIPHER_CTX))), - ('ctx_size', c_int), - ('set_asn1_parameters', CFUNCTYPE(c_int, POINTER(EVP_CIPHER_CTX), POINTER(ASN1_TYPE))), - ('get_asn1_parameters', CFUNCTYPE(c_int, POINTER(EVP_CIPHER_CTX), POINTER(ASN1_TYPE))), - ('ctrl', CFUNCTYPE(c_int, POINTER(EVP_CIPHER_CTX), c_int, c_int, c_void_p)), - ('app_data', c_void_p), -] -assert sizeof(evp_cipher_st) == 52, sizeof(evp_cipher_st) -assert alignment(evp_cipher_st) == 4, alignment(evp_cipher_st) -class evp_cipher_info_st(Structure): - pass -EVP_CIPHER = evp_cipher_st -evp_cipher_info_st._fields_ = [ - ('cipher', POINTER(EVP_CIPHER)), - ('iv', c_ubyte * 16), -] -assert sizeof(evp_cipher_info_st) == 20, sizeof(evp_cipher_info_st) -assert alignment(evp_cipher_info_st) == 4, alignment(evp_cipher_info_st) -EVP_CIPHER_INFO = evp_cipher_info_st -evp_cipher_ctx_st._fields_ = [ - ('cipher', POINTER(EVP_CIPHER)), - ('engine', POINTER(ENGINE)), - ('encrypt', c_int), - ('buf_len', c_int), - ('oiv', c_ubyte * 16), - ('iv', c_ubyte * 16), - ('buf', c_ubyte * 32), - ('num', c_int), - ('app_data', c_void_p), - ('key_len', c_int), - ('flags', c_ulong), - ('cipher_data', c_void_p), - ('final_used', c_int), - ('block_mask', c_int), - ('final', c_ubyte * 32), -] -assert sizeof(evp_cipher_ctx_st) == 140, sizeof(evp_cipher_ctx_st) -assert alignment(evp_cipher_ctx_st) == 4, alignment(evp_cipher_ctx_st) -class evp_Encode_Ctx_st(Structure): - pass -evp_Encode_Ctx_st._fields_ = [ - ('num', c_int), - ('length', c_int), - ('enc_data', c_ubyte * 80), - ('line_num', c_int), - ('expect_nl', c_int), -] -assert sizeof(evp_Encode_Ctx_st) == 96, sizeof(evp_Encode_Ctx_st) -assert alignment(evp_Encode_Ctx_st) == 4, alignment(evp_Encode_Ctx_st) -EVP_ENCODE_CTX = evp_Encode_Ctx_st -EVP_PBE_KEYGEN = CFUNCTYPE(c_int, POINTER(EVP_CIPHER_CTX), STRING, c_int, POINTER(ASN1_TYPE), POINTER(EVP_CIPHER), POINTER(EVP_MD), c_int) -class lhash_node_st(Structure): - pass -lhash_node_st._fields_ = [ - ('data', c_void_p), - ('next', POINTER(lhash_node_st)), - ('hash', c_ulong), -] -assert sizeof(lhash_node_st) == 12, sizeof(lhash_node_st) -assert alignment(lhash_node_st) == 4, alignment(lhash_node_st) -LHASH_NODE = lhash_node_st -LHASH_COMP_FN_TYPE = CFUNCTYPE(c_int, c_void_p, c_void_p) -LHASH_HASH_FN_TYPE = CFUNCTYPE(c_ulong, c_void_p) -LHASH_DOALL_FN_TYPE = CFUNCTYPE(None, c_void_p) -LHASH_DOALL_ARG_FN_TYPE = CFUNCTYPE(None, c_void_p, c_void_p) -class lhash_st(Structure): - pass -lhash_st._fields_ = [ - ('b', POINTER(POINTER(LHASH_NODE))), - ('comp', LHASH_COMP_FN_TYPE), - ('hash', LHASH_HASH_FN_TYPE), - ('num_nodes', c_uint), - ('num_alloc_nodes', c_uint), - ('p', c_uint), - ('pmax', c_uint), - ('up_load', c_ulong), - ('down_load', c_ulong), - ('num_items', c_ulong), - ('num_expands', c_ulong), - ('num_expand_reallocs', c_ulong), - ('num_contracts', c_ulong), - ('num_contract_reallocs', c_ulong), - ('num_hash_calls', c_ulong), - ('num_comp_calls', c_ulong), - ('num_insert', c_ulong), - ('num_replace', c_ulong), - ('num_delete', c_ulong), - ('num_no_delete', c_ulong), - ('num_retrieve', c_ulong), - ('num_retrieve_miss', c_ulong), - ('num_hash_comps', c_ulong), - ('error', c_int), -] -assert sizeof(lhash_st) == 96, sizeof(lhash_st) -assert alignment(lhash_st) == 4, alignment(lhash_st) -LHASH = lhash_st -class MD2state_st(Structure): - pass -MD2state_st._fields_ = [ - ('num', c_int), - ('data', c_ubyte * 16), - ('cksm', c_uint * 16), - ('state', c_uint * 16), -] -assert sizeof(MD2state_st) == 148, sizeof(MD2state_st) -assert alignment(MD2state_st) == 4, alignment(MD2state_st) -MD2_CTX = MD2state_st -class MD4state_st(Structure): - pass -MD4state_st._fields_ = [ - ('A', c_uint), - ('B', c_uint), - ('C', c_uint), - ('D', c_uint), - ('Nl', c_uint), - ('Nh', c_uint), - ('data', c_uint * 16), - ('num', c_int), -] -assert sizeof(MD4state_st) == 92, sizeof(MD4state_st) -assert alignment(MD4state_st) == 4, alignment(MD4state_st) -MD4_CTX = MD4state_st -class MD5state_st(Structure): - pass -MD5state_st._fields_ = [ - ('A', c_uint), - ('B', c_uint), - ('C', c_uint), - ('D', c_uint), - ('Nl', c_uint), - ('Nh', c_uint), - ('data', c_uint * 16), - ('num', c_int), -] -assert sizeof(MD5state_st) == 92, sizeof(MD5state_st) -assert alignment(MD5state_st) == 4, alignment(MD5state_st) -MD5_CTX = MD5state_st -class mdc2_ctx_st(Structure): - pass -mdc2_ctx_st._fields_ = [ - ('num', c_int), - ('data', c_ubyte * 8), - ('h', DES_cblock), - ('hh', DES_cblock), - ('pad_type', c_int), -] -assert sizeof(mdc2_ctx_st) == 32, sizeof(mdc2_ctx_st) -assert alignment(mdc2_ctx_st) == 4, alignment(mdc2_ctx_st) -MDC2_CTX = mdc2_ctx_st -class obj_name_st(Structure): - pass -obj_name_st._fields_ = [ - ('type', c_int), - ('alias', c_int), - ('name', STRING), - ('data', STRING), -] -assert sizeof(obj_name_st) == 16, sizeof(obj_name_st) -assert alignment(obj_name_st) == 4, alignment(obj_name_st) -OBJ_NAME = obj_name_st -ASN1_TIME = asn1_string_st -ASN1_NULL = c_int -EVP_PKEY = evp_pkey_st -class x509_st(Structure): - pass -X509 = x509_st -class X509_algor_st(Structure): - pass -X509_ALGOR = X509_algor_st -class X509_crl_st(Structure): - pass -X509_CRL = X509_crl_st -class X509_name_st(Structure): - pass -X509_NAME = X509_name_st -class x509_store_st(Structure): - pass -X509_STORE = x509_store_st -class x509_store_ctx_st(Structure): - pass -X509_STORE_CTX = x509_store_ctx_st -engine_st._fields_ = [ -] -class PEM_Encode_Seal_st(Structure): - pass -PEM_Encode_Seal_st._fields_ = [ - ('encode', EVP_ENCODE_CTX), - ('md', EVP_MD_CTX), - ('cipher', EVP_CIPHER_CTX), -] -assert sizeof(PEM_Encode_Seal_st) == 252, sizeof(PEM_Encode_Seal_st) -assert alignment(PEM_Encode_Seal_st) == 4, alignment(PEM_Encode_Seal_st) -PEM_ENCODE_SEAL_CTX = PEM_Encode_Seal_st -class pem_recip_st(Structure): - pass -pem_recip_st._fields_ = [ - ('name', STRING), - ('dn', POINTER(X509_NAME)), - ('cipher', c_int), - ('key_enc', c_int), -] -assert sizeof(pem_recip_st) == 16, sizeof(pem_recip_st) -assert alignment(pem_recip_st) == 4, alignment(pem_recip_st) -PEM_USER = pem_recip_st -class pem_ctx_st(Structure): - pass -class N10pem_ctx_st4DOLLAR_16E(Structure): - pass -N10pem_ctx_st4DOLLAR_16E._fields_ = [ - ('version', c_int), - ('mode', c_int), -] -assert sizeof(N10pem_ctx_st4DOLLAR_16E) == 8, sizeof(N10pem_ctx_st4DOLLAR_16E) -assert alignment(N10pem_ctx_st4DOLLAR_16E) == 4, alignment(N10pem_ctx_st4DOLLAR_16E) -class N10pem_ctx_st4DOLLAR_17E(Structure): - pass -N10pem_ctx_st4DOLLAR_17E._fields_ = [ - ('cipher', c_int), -] -assert sizeof(N10pem_ctx_st4DOLLAR_17E) == 4, sizeof(N10pem_ctx_st4DOLLAR_17E) -assert alignment(N10pem_ctx_st4DOLLAR_17E) == 4, alignment(N10pem_ctx_st4DOLLAR_17E) -pem_ctx_st._fields_ = [ - ('type', c_int), - ('proc_type', N10pem_ctx_st4DOLLAR_16E), - ('domain', STRING), - ('DEK_info', N10pem_ctx_st4DOLLAR_17E), - ('originator', POINTER(PEM_USER)), - ('num_recipient', c_int), - ('recipient', POINTER(POINTER(PEM_USER))), - ('x509_chain', POINTER(STACK)), - ('md', POINTER(EVP_MD)), - ('md_enc', c_int), - ('md_len', c_int), - ('md_data', STRING), - ('dec', POINTER(EVP_CIPHER)), - ('key_len', c_int), - ('key', POINTER(c_ubyte)), - ('data_enc', c_int), - ('data_len', c_int), - ('data', POINTER(c_ubyte)), -] -assert sizeof(pem_ctx_st) == 76, sizeof(pem_ctx_st) -assert alignment(pem_ctx_st) == 4, alignment(pem_ctx_st) -PEM_CTX = pem_ctx_st -pem_password_cb = CFUNCTYPE(c_int, STRING, c_int, c_int, c_void_p) -class pkcs7_issuer_and_serial_st(Structure): - pass -pkcs7_issuer_and_serial_st._fields_ = [ - ('issuer', POINTER(X509_NAME)), - ('serial', POINTER(ASN1_INTEGER)), -] -assert sizeof(pkcs7_issuer_and_serial_st) == 8, sizeof(pkcs7_issuer_and_serial_st) -assert alignment(pkcs7_issuer_and_serial_st) == 4, alignment(pkcs7_issuer_and_serial_st) -PKCS7_ISSUER_AND_SERIAL = pkcs7_issuer_and_serial_st -class pkcs7_signer_info_st(Structure): - pass -pkcs7_signer_info_st._fields_ = [ - ('version', POINTER(ASN1_INTEGER)), - ('issuer_and_serial', POINTER(PKCS7_ISSUER_AND_SERIAL)), - ('digest_alg', POINTER(X509_ALGOR)), - ('auth_attr', POINTER(STACK)), - ('digest_enc_alg', POINTER(X509_ALGOR)), - ('enc_digest', POINTER(ASN1_OCTET_STRING)), - ('unauth_attr', POINTER(STACK)), - ('pkey', POINTER(EVP_PKEY)), -] -assert sizeof(pkcs7_signer_info_st) == 32, sizeof(pkcs7_signer_info_st) -assert alignment(pkcs7_signer_info_st) == 4, alignment(pkcs7_signer_info_st) -PKCS7_SIGNER_INFO = pkcs7_signer_info_st -class pkcs7_recip_info_st(Structure): - pass -pkcs7_recip_info_st._fields_ = [ - ('version', POINTER(ASN1_INTEGER)), - ('issuer_and_serial', POINTER(PKCS7_ISSUER_AND_SERIAL)), - ('key_enc_algor', POINTER(X509_ALGOR)), - ('enc_key', POINTER(ASN1_OCTET_STRING)), - ('cert', POINTER(X509)), -] -assert sizeof(pkcs7_recip_info_st) == 20, sizeof(pkcs7_recip_info_st) -assert alignment(pkcs7_recip_info_st) == 4, alignment(pkcs7_recip_info_st) -PKCS7_RECIP_INFO = pkcs7_recip_info_st -class pkcs7_signed_st(Structure): - pass -class pkcs7_st(Structure): - pass -pkcs7_signed_st._fields_ = [ - ('version', POINTER(ASN1_INTEGER)), - ('md_algs', POINTER(STACK)), - ('cert', POINTER(STACK)), - ('crl', POINTER(STACK)), - ('signer_info', POINTER(STACK)), - ('contents', POINTER(pkcs7_st)), -] -assert sizeof(pkcs7_signed_st) == 24, sizeof(pkcs7_signed_st) -assert alignment(pkcs7_signed_st) == 4, alignment(pkcs7_signed_st) -PKCS7_SIGNED = pkcs7_signed_st -class pkcs7_enc_content_st(Structure): - pass -pkcs7_enc_content_st._fields_ = [ - ('content_type', POINTER(ASN1_OBJECT)), - ('algorithm', POINTER(X509_ALGOR)), - ('enc_data', POINTER(ASN1_OCTET_STRING)), - ('cipher', POINTER(EVP_CIPHER)), -] -assert sizeof(pkcs7_enc_content_st) == 16, sizeof(pkcs7_enc_content_st) -assert alignment(pkcs7_enc_content_st) == 4, alignment(pkcs7_enc_content_st) -PKCS7_ENC_CONTENT = pkcs7_enc_content_st -class pkcs7_enveloped_st(Structure): - pass -pkcs7_enveloped_st._fields_ = [ - ('version', POINTER(ASN1_INTEGER)), - ('recipientinfo', POINTER(STACK)), - ('enc_data', POINTER(PKCS7_ENC_CONTENT)), -] -assert sizeof(pkcs7_enveloped_st) == 12, sizeof(pkcs7_enveloped_st) -assert alignment(pkcs7_enveloped_st) == 4, alignment(pkcs7_enveloped_st) -PKCS7_ENVELOPE = pkcs7_enveloped_st -class pkcs7_signedandenveloped_st(Structure): - pass -pkcs7_signedandenveloped_st._fields_ = [ - ('version', POINTER(ASN1_INTEGER)), - ('md_algs', POINTER(STACK)), - ('cert', POINTER(STACK)), - ('crl', POINTER(STACK)), - ('signer_info', POINTER(STACK)), - ('enc_data', POINTER(PKCS7_ENC_CONTENT)), - ('recipientinfo', POINTER(STACK)), -] -assert sizeof(pkcs7_signedandenveloped_st) == 28, sizeof(pkcs7_signedandenveloped_st) -assert alignment(pkcs7_signedandenveloped_st) == 4, alignment(pkcs7_signedandenveloped_st) -PKCS7_SIGN_ENVELOPE = pkcs7_signedandenveloped_st -class pkcs7_digest_st(Structure): - pass -pkcs7_digest_st._fields_ = [ - ('version', POINTER(ASN1_INTEGER)), - ('md', POINTER(X509_ALGOR)), - ('contents', POINTER(pkcs7_st)), - ('digest', POINTER(ASN1_OCTET_STRING)), -] -assert sizeof(pkcs7_digest_st) == 16, sizeof(pkcs7_digest_st) -assert alignment(pkcs7_digest_st) == 4, alignment(pkcs7_digest_st) -PKCS7_DIGEST = pkcs7_digest_st -class pkcs7_encrypted_st(Structure): - pass -pkcs7_encrypted_st._fields_ = [ - ('version', POINTER(ASN1_INTEGER)), - ('enc_data', POINTER(PKCS7_ENC_CONTENT)), -] -assert sizeof(pkcs7_encrypted_st) == 8, sizeof(pkcs7_encrypted_st) -assert alignment(pkcs7_encrypted_st) == 4, alignment(pkcs7_encrypted_st) -PKCS7_ENCRYPT = pkcs7_encrypted_st -class N8pkcs7_st4DOLLAR_15E(Union): - pass -N8pkcs7_st4DOLLAR_15E._fields_ = [ - ('ptr', STRING), - ('data', POINTER(ASN1_OCTET_STRING)), - ('sign', POINTER(PKCS7_SIGNED)), - ('enveloped', POINTER(PKCS7_ENVELOPE)), - ('signed_and_enveloped', POINTER(PKCS7_SIGN_ENVELOPE)), - ('digest', POINTER(PKCS7_DIGEST)), - ('encrypted', POINTER(PKCS7_ENCRYPT)), - ('other', POINTER(ASN1_TYPE)), -] -assert sizeof(N8pkcs7_st4DOLLAR_15E) == 4, sizeof(N8pkcs7_st4DOLLAR_15E) -assert alignment(N8pkcs7_st4DOLLAR_15E) == 4, alignment(N8pkcs7_st4DOLLAR_15E) -pkcs7_st._fields_ = [ - ('asn1', POINTER(c_ubyte)), - ('length', c_long), - ('state', c_int), - ('detached', c_int), - ('type', POINTER(ASN1_OBJECT)), - ('d', N8pkcs7_st4DOLLAR_15E), -] -assert sizeof(pkcs7_st) == 24, sizeof(pkcs7_st) -assert alignment(pkcs7_st) == 4, alignment(pkcs7_st) -PKCS7 = pkcs7_st -class rc2_key_st(Structure): - pass -rc2_key_st._fields_ = [ - ('data', c_uint * 64), -] -assert sizeof(rc2_key_st) == 256, sizeof(rc2_key_st) -assert alignment(rc2_key_st) == 4, alignment(rc2_key_st) -RC2_KEY = rc2_key_st -class rc4_key_st(Structure): - pass -rc4_key_st._fields_ = [ - ('x', c_ubyte), - ('y', c_ubyte), - ('data', c_ubyte * 256), -] -assert sizeof(rc4_key_st) == 258, sizeof(rc4_key_st) -assert alignment(rc4_key_st) == 1, alignment(rc4_key_st) -RC4_KEY = rc4_key_st -class rc5_key_st(Structure): - pass -rc5_key_st._fields_ = [ - ('rounds', c_int), - ('data', c_ulong * 34), -] -assert sizeof(rc5_key_st) == 140, sizeof(rc5_key_st) -assert alignment(rc5_key_st) == 4, alignment(rc5_key_st) -RC5_32_KEY = rc5_key_st -class RIPEMD160state_st(Structure): - pass -RIPEMD160state_st._fields_ = [ - ('A', c_uint), - ('B', c_uint), - ('C', c_uint), - ('D', c_uint), - ('E', c_uint), - ('Nl', c_uint), - ('Nh', c_uint), - ('data', c_uint * 16), - ('num', c_int), -] -assert sizeof(RIPEMD160state_st) == 96, sizeof(RIPEMD160state_st) -assert alignment(RIPEMD160state_st) == 4, alignment(RIPEMD160state_st) -RIPEMD160_CTX = RIPEMD160state_st -RSA = rsa_st -class rsa_meth_st(Structure): - pass -rsa_meth_st._fields_ = [ - ('name', STRING), - ('rsa_pub_enc', CFUNCTYPE(c_int, c_int, POINTER(c_ubyte), POINTER(c_ubyte), POINTER(RSA), c_int)), - ('rsa_pub_dec', CFUNCTYPE(c_int, c_int, POINTER(c_ubyte), POINTER(c_ubyte), POINTER(RSA), c_int)), - ('rsa_priv_enc', CFUNCTYPE(c_int, c_int, POINTER(c_ubyte), POINTER(c_ubyte), POINTER(RSA), c_int)), - ('rsa_priv_dec', CFUNCTYPE(c_int, c_int, POINTER(c_ubyte), POINTER(c_ubyte), POINTER(RSA), c_int)), - ('rsa_mod_exp', CFUNCTYPE(c_int, POINTER(BIGNUM), POINTER(BIGNUM), POINTER(RSA))), - ('bn_mod_exp', CFUNCTYPE(c_int, POINTER(BIGNUM), POINTER(BIGNUM), POINTER(BIGNUM), POINTER(BIGNUM), POINTER(BN_CTX), POINTER(BN_MONT_CTX))), - ('init', CFUNCTYPE(c_int, POINTER(RSA))), - ('finish', CFUNCTYPE(c_int, POINTER(RSA))), - ('flags', c_int), - ('app_data', STRING), - ('rsa_sign', CFUNCTYPE(c_int, c_int, POINTER(c_ubyte), c_uint, POINTER(c_ubyte), POINTER(c_uint), POINTER(RSA))), - ('rsa_verify', CFUNCTYPE(c_int, c_int, POINTER(c_ubyte), c_uint, POINTER(c_ubyte), c_uint, POINTER(RSA))), -] -assert sizeof(rsa_meth_st) == 52, sizeof(rsa_meth_st) -assert alignment(rsa_meth_st) == 4, alignment(rsa_meth_st) -RSA_METHOD = rsa_meth_st -rsa_st._fields_ = [ - ('pad', c_int), - ('version', c_long), - ('meth', POINTER(RSA_METHOD)), - ('engine', POINTER(ENGINE)), - ('n', POINTER(BIGNUM)), - ('e', POINTER(BIGNUM)), - ('d', POINTER(BIGNUM)), - ('p', POINTER(BIGNUM)), - ('q', POINTER(BIGNUM)), - ('dmp1', POINTER(BIGNUM)), - ('dmq1', POINTER(BIGNUM)), - ('iqmp', POINTER(BIGNUM)), - ('ex_data', CRYPTO_EX_DATA), - ('references', c_int), - ('flags', c_int), - ('_method_mod_n', POINTER(BN_MONT_CTX)), - ('_method_mod_p', POINTER(BN_MONT_CTX)), - ('_method_mod_q', POINTER(BN_MONT_CTX)), - ('bignum_data', STRING), - ('blinding', POINTER(BN_BLINDING)), -] -assert sizeof(rsa_st) == 84, sizeof(rsa_st) -assert alignment(rsa_st) == 4, alignment(rsa_st) -openssl_fptr = CFUNCTYPE(None) -class SHAstate_st(Structure): - pass -SHAstate_st._fields_ = [ - ('h0', c_uint), - ('h1', c_uint), - ('h2', c_uint), - ('h3', c_uint), - ('h4', c_uint), - ('Nl', c_uint), - ('Nh', c_uint), - ('data', c_uint * 16), - ('num', c_int), -] -assert sizeof(SHAstate_st) == 96, sizeof(SHAstate_st) -assert alignment(SHAstate_st) == 4, alignment(SHAstate_st) -SHA_CTX = SHAstate_st -class ssl_st(Structure): - pass -ssl_crock_st = POINTER(ssl_st) -class ssl_cipher_st(Structure): - pass -ssl_cipher_st._fields_ = [ - ('valid', c_int), - ('name', STRING), - ('id', c_ulong), - ('algorithms', c_ulong), - ('algo_strength', c_ulong), - ('algorithm2', c_ulong), - ('strength_bits', c_int), - ('alg_bits', c_int), - ('mask', c_ulong), - ('mask_strength', c_ulong), -] -assert sizeof(ssl_cipher_st) == 40, sizeof(ssl_cipher_st) -assert alignment(ssl_cipher_st) == 4, alignment(ssl_cipher_st) -SSL_CIPHER = ssl_cipher_st -SSL = ssl_st -class ssl_ctx_st(Structure): - pass -SSL_CTX = ssl_ctx_st -class ssl_method_st(Structure): - pass -class ssl3_enc_method(Structure): - pass -ssl_method_st._fields_ = [ - ('version', c_int), - ('ssl_new', CFUNCTYPE(c_int, POINTER(SSL))), - ('ssl_clear', CFUNCTYPE(None, POINTER(SSL))), - ('ssl_free', CFUNCTYPE(None, POINTER(SSL))), - ('ssl_accept', CFUNCTYPE(c_int, POINTER(SSL))), - ('ssl_connect', CFUNCTYPE(c_int, POINTER(SSL))), - ('ssl_read', CFUNCTYPE(c_int, POINTER(SSL), c_void_p, c_int)), - ('ssl_peek', CFUNCTYPE(c_int, POINTER(SSL), c_void_p, c_int)), - ('ssl_write', CFUNCTYPE(c_int, POINTER(SSL), c_void_p, c_int)), - ('ssl_shutdown', CFUNCTYPE(c_int, POINTER(SSL))), - ('ssl_renegotiate', CFUNCTYPE(c_int, POINTER(SSL))), - ('ssl_renegotiate_check', CFUNCTYPE(c_int, POINTER(SSL))), - ('ssl_ctrl', CFUNCTYPE(c_long, POINTER(SSL), c_int, c_long, c_void_p)), - ('ssl_ctx_ctrl', CFUNCTYPE(c_long, POINTER(SSL_CTX), c_int, c_long, c_void_p)), - ('get_cipher_by_char', CFUNCTYPE(POINTER(SSL_CIPHER), POINTER(c_ubyte))), - ('put_cipher_by_char', CFUNCTYPE(c_int, POINTER(SSL_CIPHER), POINTER(c_ubyte))), - ('ssl_pending', CFUNCTYPE(c_int, POINTER(SSL))), - ('num_ciphers', CFUNCTYPE(c_int)), - ('get_cipher', CFUNCTYPE(POINTER(SSL_CIPHER), c_uint)), - ('get_ssl_method', CFUNCTYPE(POINTER(ssl_method_st), c_int)), - ('get_timeout', CFUNCTYPE(c_long)), - ('ssl3_enc', POINTER(ssl3_enc_method)), - ('ssl_version', CFUNCTYPE(c_int)), - ('ssl_callback_ctrl', CFUNCTYPE(c_long, POINTER(SSL), c_int, CFUNCTYPE(None))), - ('ssl_ctx_callback_ctrl', CFUNCTYPE(c_long, POINTER(SSL_CTX), c_int, CFUNCTYPE(None))), -] -assert sizeof(ssl_method_st) == 100, sizeof(ssl_method_st) -assert alignment(ssl_method_st) == 4, alignment(ssl_method_st) -ssl3_enc_method._fields_ = [ -] -SSL_METHOD = ssl_method_st -class ssl_session_st(Structure): - pass -class sess_cert_st(Structure): - pass -ssl_session_st._fields_ = [ - ('ssl_version', c_int), - ('key_arg_length', c_uint), - ('key_arg', c_ubyte * 8), - ('master_key_length', c_int), - ('master_key', c_ubyte * 48), - ('session_id_length', c_uint), - ('session_id', c_ubyte * 32), - ('sid_ctx_length', c_uint), - ('sid_ctx', c_ubyte * 32), - ('not_resumable', c_int), - ('sess_cert', POINTER(sess_cert_st)), - ('peer', POINTER(X509)), - ('verify_result', c_long), - ('references', c_int), - ('timeout', c_long), - ('time', c_long), - ('compress_meth', c_int), - ('cipher', POINTER(SSL_CIPHER)), - ('cipher_id', c_ulong), - ('ciphers', POINTER(STACK)), - ('ex_data', CRYPTO_EX_DATA), - ('prev', POINTER(ssl_session_st)), - ('next', POINTER(ssl_session_st)), -] -assert sizeof(ssl_session_st) == 200, sizeof(ssl_session_st) -assert alignment(ssl_session_st) == 4, alignment(ssl_session_st) -sess_cert_st._fields_ = [ -] -SSL_SESSION = ssl_session_st -GEN_SESSION_CB = CFUNCTYPE(c_int, POINTER(SSL), POINTER(c_ubyte), POINTER(c_uint)) -class ssl_comp_st(Structure): - pass -ssl_comp_st._fields_ = [ - ('id', c_int), - ('name', STRING), - ('method', POINTER(COMP_METHOD)), -] -assert sizeof(ssl_comp_st) == 12, sizeof(ssl_comp_st) -assert alignment(ssl_comp_st) == 4, alignment(ssl_comp_st) -SSL_COMP = ssl_comp_st -class N10ssl_ctx_st4DOLLAR_18E(Structure): - pass -N10ssl_ctx_st4DOLLAR_18E._fields_ = [ - ('sess_connect', c_int), - ('sess_connect_renegotiate', c_int), - ('sess_connect_good', c_int), - ('sess_accept', c_int), - ('sess_accept_renegotiate', c_int), - ('sess_accept_good', c_int), - ('sess_miss', c_int), - ('sess_timeout', c_int), - ('sess_cache_full', c_int), - ('sess_hit', c_int), - ('sess_cb_hit', c_int), -] -assert sizeof(N10ssl_ctx_st4DOLLAR_18E) == 44, sizeof(N10ssl_ctx_st4DOLLAR_18E) -assert alignment(N10ssl_ctx_st4DOLLAR_18E) == 4, alignment(N10ssl_ctx_st4DOLLAR_18E) -class cert_st(Structure): - pass -ssl_ctx_st._fields_ = [ - ('method', POINTER(SSL_METHOD)), - ('cipher_list', POINTER(STACK)), - ('cipher_list_by_id', POINTER(STACK)), - ('cert_store', POINTER(x509_store_st)), - ('sessions', POINTER(lhash_st)), - ('session_cache_size', c_ulong), - ('session_cache_head', POINTER(ssl_session_st)), - ('session_cache_tail', POINTER(ssl_session_st)), - ('session_cache_mode', c_int), - ('session_timeout', c_long), - ('new_session_cb', CFUNCTYPE(c_int, POINTER(ssl_st), POINTER(SSL_SESSION))), - ('remove_session_cb', CFUNCTYPE(None, POINTER(ssl_ctx_st), POINTER(SSL_SESSION))), - ('get_session_cb', CFUNCTYPE(POINTER(SSL_SESSION), POINTER(ssl_st), POINTER(c_ubyte), c_int, POINTER(c_int))), - ('stats', N10ssl_ctx_st4DOLLAR_18E), - ('references', c_int), - ('app_verify_callback', CFUNCTYPE(c_int, POINTER(X509_STORE_CTX), c_void_p)), - ('app_verify_arg', c_void_p), - ('default_passwd_callback', POINTER(pem_password_cb)), - ('default_passwd_callback_userdata', c_void_p), - ('client_cert_cb', CFUNCTYPE(c_int, POINTER(SSL), POINTER(POINTER(X509)), POINTER(POINTER(EVP_PKEY)))), - ('ex_data', CRYPTO_EX_DATA), - ('rsa_md5', POINTER(EVP_MD)), - ('md5', POINTER(EVP_MD)), - ('sha1', POINTER(EVP_MD)), - ('extra_certs', POINTER(STACK)), - ('comp_methods', POINTER(STACK)), - ('info_callback', CFUNCTYPE(None, POINTER(SSL), c_int, c_int)), - ('client_CA', POINTER(STACK)), - ('options', c_ulong), - ('mode', c_ulong), - ('max_cert_list', c_long), - ('cert', POINTER(cert_st)), - ('read_ahead', c_int), - ('msg_callback', CFUNCTYPE(None, c_int, c_int, c_int, c_void_p, c_ulong, POINTER(SSL), c_void_p)), - ('msg_callback_arg', c_void_p), - ('verify_mode', c_int), - ('verify_depth', c_int), - ('sid_ctx_length', c_uint), - ('sid_ctx', c_ubyte * 32), - ('default_verify_callback', CFUNCTYPE(c_int, c_int, POINTER(X509_STORE_CTX))), - ('generate_session_id', GEN_SESSION_CB), - ('purpose', c_int), - ('trust', c_int), - ('quiet_shutdown', c_int), -] -assert sizeof(ssl_ctx_st) == 248, sizeof(ssl_ctx_st) -assert alignment(ssl_ctx_st) == 4, alignment(ssl_ctx_st) -cert_st._fields_ = [ -] -class ssl2_state_st(Structure): - pass -class ssl3_state_st(Structure): - pass -ssl_st._fields_ = [ - ('version', c_int), - ('type', c_int), - ('method', POINTER(SSL_METHOD)), - ('rbio', POINTER(BIO)), - ('wbio', POINTER(BIO)), - ('bbio', POINTER(BIO)), - ('rwstate', c_int), - ('in_handshake', c_int), - ('handshake_func', CFUNCTYPE(c_int)), - ('server', c_int), - ('new_session', c_int), - ('quiet_shutdown', c_int), - ('shutdown', c_int), - ('state', c_int), - ('rstate', c_int), - ('init_buf', POINTER(BUF_MEM)), - ('init_msg', c_void_p), - ('init_num', c_int), - ('init_off', c_int), - ('packet', POINTER(c_ubyte)), - ('packet_length', c_uint), - ('s2', POINTER(ssl2_state_st)), - ('s3', POINTER(ssl3_state_st)), - ('read_ahead', c_int), - ('msg_callback', CFUNCTYPE(None, c_int, c_int, c_int, c_void_p, c_ulong, POINTER(SSL), c_void_p)), - ('msg_callback_arg', c_void_p), - ('hit', c_int), - ('purpose', c_int), - ('trust', c_int), - ('cipher_list', POINTER(STACK)), - ('cipher_list_by_id', POINTER(STACK)), - ('enc_read_ctx', POINTER(EVP_CIPHER_CTX)), - ('read_hash', POINTER(EVP_MD)), - ('expand', POINTER(COMP_CTX)), - ('enc_write_ctx', POINTER(EVP_CIPHER_CTX)), - ('write_hash', POINTER(EVP_MD)), - ('compress', POINTER(COMP_CTX)), - ('cert', POINTER(cert_st)), - ('sid_ctx_length', c_uint), - ('sid_ctx', c_ubyte * 32), - ('session', POINTER(SSL_SESSION)), - ('generate_session_id', GEN_SESSION_CB), - ('verify_mode', c_int), - ('verify_depth', c_int), - ('verify_callback', CFUNCTYPE(c_int, c_int, POINTER(X509_STORE_CTX))), - ('info_callback', CFUNCTYPE(None, POINTER(SSL), c_int, c_int)), - ('error', c_int), - ('error_code', c_int), - ('ctx', POINTER(SSL_CTX)), - ('debug', c_int), - ('verify_result', c_long), - ('ex_data', CRYPTO_EX_DATA), - ('client_CA', POINTER(STACK)), - ('references', c_int), - ('options', c_ulong), - ('mode', c_ulong), - ('max_cert_list', c_long), - ('first_packet', c_int), - ('client_version', c_int), -] -assert sizeof(ssl_st) == 268, sizeof(ssl_st) -assert alignment(ssl_st) == 4, alignment(ssl_st) -class N13ssl2_state_st4DOLLAR_19E(Structure): - pass -N13ssl2_state_st4DOLLAR_19E._fields_ = [ - ('conn_id_length', c_uint), - ('cert_type', c_uint), - ('cert_length', c_uint), - ('csl', c_uint), - ('clear', c_uint), - ('enc', c_uint), - ('ccl', c_ubyte * 32), - ('cipher_spec_length', c_uint), - ('session_id_length', c_uint), - ('clen', c_uint), - ('rlen', c_uint), -] -assert sizeof(N13ssl2_state_st4DOLLAR_19E) == 72, sizeof(N13ssl2_state_st4DOLLAR_19E) -assert alignment(N13ssl2_state_st4DOLLAR_19E) == 4, alignment(N13ssl2_state_st4DOLLAR_19E) -ssl2_state_st._fields_ = [ - ('three_byte_header', c_int), - ('clear_text', c_int), - ('escape', c_int), - ('ssl2_rollback', c_int), - ('wnum', c_uint), - ('wpend_tot', c_int), - ('wpend_buf', POINTER(c_ubyte)), - ('wpend_off', c_int), - ('wpend_len', c_int), - ('wpend_ret', c_int), - ('rbuf_left', c_int), - ('rbuf_offs', c_int), - ('rbuf', POINTER(c_ubyte)), - ('wbuf', POINTER(c_ubyte)), - ('write_ptr', POINTER(c_ubyte)), - ('padding', c_uint), - ('rlength', c_uint), - ('ract_data_length', c_int), - ('wlength', c_uint), - ('wact_data_length', c_int), - ('ract_data', POINTER(c_ubyte)), - ('wact_data', POINTER(c_ubyte)), - ('mac_data', POINTER(c_ubyte)), - ('read_key', POINTER(c_ubyte)), - ('write_key', POINTER(c_ubyte)), - ('challenge_length', c_uint), - ('challenge', c_ubyte * 32), - ('conn_id_length', c_uint), - ('conn_id', c_ubyte * 16), - ('key_material_length', c_uint), - ('key_material', c_ubyte * 48), - ('read_sequence', c_ulong), - ('write_sequence', c_ulong), - ('tmp', N13ssl2_state_st4DOLLAR_19E), -] -assert sizeof(ssl2_state_st) == 288, sizeof(ssl2_state_st) -assert alignment(ssl2_state_st) == 4, alignment(ssl2_state_st) -SSL2_STATE = ssl2_state_st -class ssl3_record_st(Structure): - pass -ssl3_record_st._fields_ = [ - ('type', c_int), - ('length', c_uint), - ('off', c_uint), - ('data', POINTER(c_ubyte)), - ('input', POINTER(c_ubyte)), - ('comp', POINTER(c_ubyte)), -] -assert sizeof(ssl3_record_st) == 24, sizeof(ssl3_record_st) -assert alignment(ssl3_record_st) == 4, alignment(ssl3_record_st) -SSL3_RECORD = ssl3_record_st -class ssl3_buffer_st(Structure): - pass -size_t = __darwin_size_t -ssl3_buffer_st._fields_ = [ - ('buf', POINTER(c_ubyte)), - ('len', size_t), - ('offset', c_int), - ('left', c_int), -] -assert sizeof(ssl3_buffer_st) == 16, sizeof(ssl3_buffer_st) -assert alignment(ssl3_buffer_st) == 4, alignment(ssl3_buffer_st) -SSL3_BUFFER = ssl3_buffer_st -class N13ssl3_state_st4DOLLAR_20E(Structure): - pass -N13ssl3_state_st4DOLLAR_20E._fields_ = [ - ('cert_verify_md', c_ubyte * 72), - ('finish_md', c_ubyte * 72), - ('finish_md_len', c_int), - ('peer_finish_md', c_ubyte * 72), - ('peer_finish_md_len', c_int), - ('message_size', c_ulong), - ('message_type', c_int), - ('new_cipher', POINTER(SSL_CIPHER)), - ('dh', POINTER(DH)), - ('next_state', c_int), - ('reuse_message', c_int), - ('cert_req', c_int), - ('ctype_num', c_int), - ('ctype', c_char * 7), - ('ca_names', POINTER(STACK)), - ('use_rsa_tmp', c_int), - ('key_block_length', c_int), - ('key_block', POINTER(c_ubyte)), - ('new_sym_enc', POINTER(EVP_CIPHER)), - ('new_hash', POINTER(EVP_MD)), - ('new_compression', POINTER(SSL_COMP)), - ('cert_request', c_int), -] -assert sizeof(N13ssl3_state_st4DOLLAR_20E) == 296, sizeof(N13ssl3_state_st4DOLLAR_20E) -assert alignment(N13ssl3_state_st4DOLLAR_20E) == 4, alignment(N13ssl3_state_st4DOLLAR_20E) -ssl3_state_st._fields_ = [ - ('flags', c_long), - ('delay_buf_pop_ret', c_int), - ('read_sequence', c_ubyte * 8), - ('read_mac_secret', c_ubyte * 36), - ('write_sequence', c_ubyte * 8), - ('write_mac_secret', c_ubyte * 36), - ('server_random', c_ubyte * 32), - ('client_random', c_ubyte * 32), - ('need_empty_fragments', c_int), - ('empty_fragment_done', c_int), - ('rbuf', SSL3_BUFFER), - ('wbuf', SSL3_BUFFER), - ('rrec', SSL3_RECORD), - ('wrec', SSL3_RECORD), - ('alert_fragment', c_ubyte * 2), - ('alert_fragment_len', c_uint), - ('handshake_fragment', c_ubyte * 4), - ('handshake_fragment_len', c_uint), - ('wnum', c_uint), - ('wpend_tot', c_int), - ('wpend_type', c_int), - ('wpend_ret', c_int), - ('wpend_buf', POINTER(c_ubyte)), - ('finish_dgst1', EVP_MD_CTX), - ('finish_dgst2', EVP_MD_CTX), - ('change_cipher_spec', c_int), - ('warn_alert', c_int), - ('fatal_alert', c_int), - ('alert_dispatch', c_int), - ('send_alert', c_ubyte * 2), - ('renegotiate', c_int), - ('total_renegotiations', c_int), - ('num_renegotiations', c_int), - ('in_read_app_data', c_int), - ('tmp', N13ssl3_state_st4DOLLAR_20E), -] -assert sizeof(ssl3_state_st) == 648, sizeof(ssl3_state_st) -assert alignment(ssl3_state_st) == 4, alignment(ssl3_state_st) -SSL3_STATE = ssl3_state_st -stack_st._fields_ = [ - ('num', c_int), - ('data', POINTER(STRING)), - ('sorted', c_int), - ('num_alloc', c_int), - ('comp', CFUNCTYPE(c_int, POINTER(STRING), POINTER(STRING))), -] -assert sizeof(stack_st) == 20, sizeof(stack_st) -assert alignment(stack_st) == 4, alignment(stack_st) -class ui_st(Structure): - pass -ui_st._fields_ = [ -] -UI = ui_st -class ui_method_st(Structure): - pass -ui_method_st._fields_ = [ -] -UI_METHOD = ui_method_st -class ui_string_st(Structure): - pass -ui_string_st._fields_ = [ -] -UI_STRING = ui_string_st - -# values for enumeration 'UI_string_types' -UI_string_types = c_int # enum -class X509_objects_st(Structure): - pass -X509_objects_st._fields_ = [ - ('nid', c_int), - ('a2i', CFUNCTYPE(c_int)), - ('i2a', CFUNCTYPE(c_int)), -] -assert sizeof(X509_objects_st) == 12, sizeof(X509_objects_st) -assert alignment(X509_objects_st) == 4, alignment(X509_objects_st) -X509_OBJECTS = X509_objects_st -X509_algor_st._fields_ = [ - ('algorithm', POINTER(ASN1_OBJECT)), - ('parameter', POINTER(ASN1_TYPE)), -] -assert sizeof(X509_algor_st) == 8, sizeof(X509_algor_st) -assert alignment(X509_algor_st) == 4, alignment(X509_algor_st) -class X509_val_st(Structure): - pass -X509_val_st._fields_ = [ - ('notBefore', POINTER(ASN1_TIME)), - ('notAfter', POINTER(ASN1_TIME)), -] -assert sizeof(X509_val_st) == 8, sizeof(X509_val_st) -assert alignment(X509_val_st) == 4, alignment(X509_val_st) -X509_VAL = X509_val_st -class X509_pubkey_st(Structure): - pass -X509_pubkey_st._fields_ = [ - ('algor', POINTER(X509_ALGOR)), - ('public_key', POINTER(ASN1_BIT_STRING)), - ('pkey', POINTER(EVP_PKEY)), -] -assert sizeof(X509_pubkey_st) == 12, sizeof(X509_pubkey_st) -assert alignment(X509_pubkey_st) == 4, alignment(X509_pubkey_st) -X509_PUBKEY = X509_pubkey_st -class X509_sig_st(Structure): - pass -X509_sig_st._fields_ = [ - ('algor', POINTER(X509_ALGOR)), - ('digest', POINTER(ASN1_OCTET_STRING)), -] -assert sizeof(X509_sig_st) == 8, sizeof(X509_sig_st) -assert alignment(X509_sig_st) == 4, alignment(X509_sig_st) -X509_SIG = X509_sig_st -class X509_name_entry_st(Structure): - pass -X509_name_entry_st._fields_ = [ - ('object', POINTER(ASN1_OBJECT)), - ('value', POINTER(ASN1_STRING)), - ('set', c_int), - ('size', c_int), -] -assert sizeof(X509_name_entry_st) == 16, sizeof(X509_name_entry_st) -assert alignment(X509_name_entry_st) == 4, alignment(X509_name_entry_st) -X509_NAME_ENTRY = X509_name_entry_st -X509_name_st._fields_ = [ - ('entries', POINTER(STACK)), - ('modified', c_int), - ('bytes', POINTER(BUF_MEM)), - ('hash', c_ulong), -] -assert sizeof(X509_name_st) == 16, sizeof(X509_name_st) -assert alignment(X509_name_st) == 4, alignment(X509_name_st) -class X509_extension_st(Structure): - pass -X509_extension_st._fields_ = [ - ('object', POINTER(ASN1_OBJECT)), - ('critical', ASN1_BOOLEAN), - ('value', POINTER(ASN1_OCTET_STRING)), -] -assert sizeof(X509_extension_st) == 12, sizeof(X509_extension_st) -assert alignment(X509_extension_st) == 4, alignment(X509_extension_st) -X509_EXTENSION = X509_extension_st -class x509_attributes_st(Structure): - pass -class N18x509_attributes_st4DOLLAR_13E(Union): - pass -N18x509_attributes_st4DOLLAR_13E._fields_ = [ - ('ptr', STRING), - ('set', POINTER(STACK)), - ('single', POINTER(ASN1_TYPE)), -] -assert sizeof(N18x509_attributes_st4DOLLAR_13E) == 4, sizeof(N18x509_attributes_st4DOLLAR_13E) -assert alignment(N18x509_attributes_st4DOLLAR_13E) == 4, alignment(N18x509_attributes_st4DOLLAR_13E) -x509_attributes_st._fields_ = [ - ('object', POINTER(ASN1_OBJECT)), - ('single', c_int), - ('value', N18x509_attributes_st4DOLLAR_13E), -] -assert sizeof(x509_attributes_st) == 12, sizeof(x509_attributes_st) -assert alignment(x509_attributes_st) == 4, alignment(x509_attributes_st) -X509_ATTRIBUTE = x509_attributes_st -class X509_req_info_st(Structure): - pass -X509_req_info_st._fields_ = [ - ('enc', ASN1_ENCODING), - ('version', POINTER(ASN1_INTEGER)), - ('subject', POINTER(X509_NAME)), - ('pubkey', POINTER(X509_PUBKEY)), - ('attributes', POINTER(STACK)), -] -assert sizeof(X509_req_info_st) == 28, sizeof(X509_req_info_st) -assert alignment(X509_req_info_st) == 4, alignment(X509_req_info_st) -X509_REQ_INFO = X509_req_info_st -class X509_req_st(Structure): - pass -X509_req_st._fields_ = [ - ('req_info', POINTER(X509_REQ_INFO)), - ('sig_alg', POINTER(X509_ALGOR)), - ('signature', POINTER(ASN1_BIT_STRING)), - ('references', c_int), -] -assert sizeof(X509_req_st) == 16, sizeof(X509_req_st) -assert alignment(X509_req_st) == 4, alignment(X509_req_st) -X509_REQ = X509_req_st -class x509_cinf_st(Structure): - pass -x509_cinf_st._fields_ = [ - ('version', POINTER(ASN1_INTEGER)), - ('serialNumber', POINTER(ASN1_INTEGER)), - ('signature', POINTER(X509_ALGOR)), - ('issuer', POINTER(X509_NAME)), - ('validity', POINTER(X509_VAL)), - ('subject', POINTER(X509_NAME)), - ('key', POINTER(X509_PUBKEY)), - ('issuerUID', POINTER(ASN1_BIT_STRING)), - ('subjectUID', POINTER(ASN1_BIT_STRING)), - ('extensions', POINTER(STACK)), -] -assert sizeof(x509_cinf_st) == 40, sizeof(x509_cinf_st) -assert alignment(x509_cinf_st) == 4, alignment(x509_cinf_st) -X509_CINF = x509_cinf_st -class x509_cert_aux_st(Structure): - pass -x509_cert_aux_st._fields_ = [ - ('trust', POINTER(STACK)), - ('reject', POINTER(STACK)), - ('alias', POINTER(ASN1_UTF8STRING)), - ('keyid', POINTER(ASN1_OCTET_STRING)), - ('other', POINTER(STACK)), -] -assert sizeof(x509_cert_aux_st) == 20, sizeof(x509_cert_aux_st) -assert alignment(x509_cert_aux_st) == 4, alignment(x509_cert_aux_st) -X509_CERT_AUX = x509_cert_aux_st -class AUTHORITY_KEYID_st(Structure): - pass -x509_st._fields_ = [ - ('cert_info', POINTER(X509_CINF)), - ('sig_alg', POINTER(X509_ALGOR)), - ('signature', POINTER(ASN1_BIT_STRING)), - ('valid', c_int), - ('references', c_int), - ('name', STRING), - ('ex_data', CRYPTO_EX_DATA), - ('ex_pathlen', c_long), - ('ex_flags', c_ulong), - ('ex_kusage', c_ulong), - ('ex_xkusage', c_ulong), - ('ex_nscert', c_ulong), - ('skid', POINTER(ASN1_OCTET_STRING)), - ('akid', POINTER(AUTHORITY_KEYID_st)), - ('sha1_hash', c_ubyte * 20), - ('aux', POINTER(X509_CERT_AUX)), -] -assert sizeof(x509_st) == 84, sizeof(x509_st) -assert alignment(x509_st) == 4, alignment(x509_st) -AUTHORITY_KEYID_st._fields_ = [ -] -class x509_trust_st(Structure): - pass -x509_trust_st._fields_ = [ - ('trust', c_int), - ('flags', c_int), - ('check_trust', CFUNCTYPE(c_int, POINTER(x509_trust_st), POINTER(X509), c_int)), - ('name', STRING), - ('arg1', c_int), - ('arg2', c_void_p), -] -assert sizeof(x509_trust_st) == 24, sizeof(x509_trust_st) -assert alignment(x509_trust_st) == 4, alignment(x509_trust_st) -X509_TRUST = x509_trust_st -class X509_revoked_st(Structure): - pass -X509_revoked_st._fields_ = [ - ('serialNumber', POINTER(ASN1_INTEGER)), - ('revocationDate', POINTER(ASN1_TIME)), - ('extensions', POINTER(STACK)), - ('sequence', c_int), -] -assert sizeof(X509_revoked_st) == 16, sizeof(X509_revoked_st) -assert alignment(X509_revoked_st) == 4, alignment(X509_revoked_st) -X509_REVOKED = X509_revoked_st -class X509_crl_info_st(Structure): - pass -X509_crl_info_st._fields_ = [ - ('version', POINTER(ASN1_INTEGER)), - ('sig_alg', POINTER(X509_ALGOR)), - ('issuer', POINTER(X509_NAME)), - ('lastUpdate', POINTER(ASN1_TIME)), - ('nextUpdate', POINTER(ASN1_TIME)), - ('revoked', POINTER(STACK)), - ('extensions', POINTER(STACK)), - ('enc', ASN1_ENCODING), -] -assert sizeof(X509_crl_info_st) == 40, sizeof(X509_crl_info_st) -assert alignment(X509_crl_info_st) == 4, alignment(X509_crl_info_st) -X509_CRL_INFO = X509_crl_info_st -X509_crl_st._fields_ = [ - ('crl', POINTER(X509_CRL_INFO)), - ('sig_alg', POINTER(X509_ALGOR)), - ('signature', POINTER(ASN1_BIT_STRING)), - ('references', c_int), -] -assert sizeof(X509_crl_st) == 16, sizeof(X509_crl_st) -assert alignment(X509_crl_st) == 4, alignment(X509_crl_st) -class private_key_st(Structure): - pass -private_key_st._fields_ = [ - ('version', c_int), - ('enc_algor', POINTER(X509_ALGOR)), - ('enc_pkey', POINTER(ASN1_OCTET_STRING)), - ('dec_pkey', POINTER(EVP_PKEY)), - ('key_length', c_int), - ('key_data', STRING), - ('key_free', c_int), - ('cipher', EVP_CIPHER_INFO), - ('references', c_int), -] -assert sizeof(private_key_st) == 52, sizeof(private_key_st) -assert alignment(private_key_st) == 4, alignment(private_key_st) -X509_PKEY = private_key_st -class X509_info_st(Structure): - pass -X509_info_st._fields_ = [ - ('x509', POINTER(X509)), - ('crl', POINTER(X509_CRL)), - ('x_pkey', POINTER(X509_PKEY)), - ('enc_cipher', EVP_CIPHER_INFO), - ('enc_len', c_int), - ('enc_data', STRING), - ('references', c_int), -] -assert sizeof(X509_info_st) == 44, sizeof(X509_info_st) -assert alignment(X509_info_st) == 4, alignment(X509_info_st) -X509_INFO = X509_info_st -class Netscape_spkac_st(Structure): - pass -Netscape_spkac_st._fields_ = [ - ('pubkey', POINTER(X509_PUBKEY)), - ('challenge', POINTER(ASN1_IA5STRING)), -] -assert sizeof(Netscape_spkac_st) == 8, sizeof(Netscape_spkac_st) -assert alignment(Netscape_spkac_st) == 4, alignment(Netscape_spkac_st) -NETSCAPE_SPKAC = Netscape_spkac_st -class Netscape_spki_st(Structure): - pass -Netscape_spki_st._fields_ = [ - ('spkac', POINTER(NETSCAPE_SPKAC)), - ('sig_algor', POINTER(X509_ALGOR)), - ('signature', POINTER(ASN1_BIT_STRING)), -] -assert sizeof(Netscape_spki_st) == 12, sizeof(Netscape_spki_st) -assert alignment(Netscape_spki_st) == 4, alignment(Netscape_spki_st) -NETSCAPE_SPKI = Netscape_spki_st -class Netscape_certificate_sequence(Structure): - pass -Netscape_certificate_sequence._fields_ = [ - ('type', POINTER(ASN1_OBJECT)), - ('certs', POINTER(STACK)), -] -assert sizeof(Netscape_certificate_sequence) == 8, sizeof(Netscape_certificate_sequence) -assert alignment(Netscape_certificate_sequence) == 4, alignment(Netscape_certificate_sequence) -NETSCAPE_CERT_SEQUENCE = Netscape_certificate_sequence -class PBEPARAM_st(Structure): - pass -PBEPARAM_st._fields_ = [ - ('salt', POINTER(ASN1_OCTET_STRING)), - ('iter', POINTER(ASN1_INTEGER)), -] -assert sizeof(PBEPARAM_st) == 8, sizeof(PBEPARAM_st) -assert alignment(PBEPARAM_st) == 4, alignment(PBEPARAM_st) -PBEPARAM = PBEPARAM_st -class PBE2PARAM_st(Structure): - pass -PBE2PARAM_st._fields_ = [ - ('keyfunc', POINTER(X509_ALGOR)), - ('encryption', POINTER(X509_ALGOR)), -] -assert sizeof(PBE2PARAM_st) == 8, sizeof(PBE2PARAM_st) -assert alignment(PBE2PARAM_st) == 4, alignment(PBE2PARAM_st) -PBE2PARAM = PBE2PARAM_st -class PBKDF2PARAM_st(Structure): - pass -PBKDF2PARAM_st._fields_ = [ - ('salt', POINTER(ASN1_TYPE)), - ('iter', POINTER(ASN1_INTEGER)), - ('keylength', POINTER(ASN1_INTEGER)), - ('prf', POINTER(X509_ALGOR)), -] -assert sizeof(PBKDF2PARAM_st) == 16, sizeof(PBKDF2PARAM_st) -assert alignment(PBKDF2PARAM_st) == 4, alignment(PBKDF2PARAM_st) -PBKDF2PARAM = PBKDF2PARAM_st -class pkcs8_priv_key_info_st(Structure): - pass -pkcs8_priv_key_info_st._fields_ = [ - ('broken', c_int), - ('version', POINTER(ASN1_INTEGER)), - ('pkeyalg', POINTER(X509_ALGOR)), - ('pkey', POINTER(ASN1_TYPE)), - ('attributes', POINTER(STACK)), -] -assert sizeof(pkcs8_priv_key_info_st) == 20, sizeof(pkcs8_priv_key_info_st) -assert alignment(pkcs8_priv_key_info_st) == 4, alignment(pkcs8_priv_key_info_st) -PKCS8_PRIV_KEY_INFO = pkcs8_priv_key_info_st -class x509_hash_dir_st(Structure): - pass -x509_hash_dir_st._fields_ = [ - ('num_dirs', c_int), - ('dirs', POINTER(STRING)), - ('dirs_type', POINTER(c_int)), - ('num_dirs_alloced', c_int), -] -assert sizeof(x509_hash_dir_st) == 16, sizeof(x509_hash_dir_st) -assert alignment(x509_hash_dir_st) == 4, alignment(x509_hash_dir_st) -X509_HASH_DIR_CTX = x509_hash_dir_st -class x509_file_st(Structure): - pass -x509_file_st._fields_ = [ - ('num_paths', c_int), - ('num_alloced', c_int), - ('paths', POINTER(STRING)), - ('path_type', POINTER(c_int)), -] -assert sizeof(x509_file_st) == 16, sizeof(x509_file_st) -assert alignment(x509_file_st) == 4, alignment(x509_file_st) -X509_CERT_FILE_CTX = x509_file_st -class x509_object_st(Structure): - pass -class N14x509_object_st4DOLLAR_14E(Union): - pass -N14x509_object_st4DOLLAR_14E._fields_ = [ - ('ptr', STRING), - ('x509', POINTER(X509)), - ('crl', POINTER(X509_CRL)), - ('pkey', POINTER(EVP_PKEY)), -] -assert sizeof(N14x509_object_st4DOLLAR_14E) == 4, sizeof(N14x509_object_st4DOLLAR_14E) -assert alignment(N14x509_object_st4DOLLAR_14E) == 4, alignment(N14x509_object_st4DOLLAR_14E) -x509_object_st._fields_ = [ - ('type', c_int), - ('data', N14x509_object_st4DOLLAR_14E), -] -assert sizeof(x509_object_st) == 8, sizeof(x509_object_st) -assert alignment(x509_object_st) == 4, alignment(x509_object_st) -X509_OBJECT = x509_object_st -class x509_lookup_st(Structure): - pass -X509_LOOKUP = x509_lookup_st -class x509_lookup_method_st(Structure): - pass -x509_lookup_method_st._fields_ = [ - ('name', STRING), - ('new_item', CFUNCTYPE(c_int, POINTER(X509_LOOKUP))), - ('free', CFUNCTYPE(None, POINTER(X509_LOOKUP))), - ('init', CFUNCTYPE(c_int, POINTER(X509_LOOKUP))), - ('shutdown', CFUNCTYPE(c_int, POINTER(X509_LOOKUP))), - ('ctrl', CFUNCTYPE(c_int, POINTER(X509_LOOKUP), c_int, STRING, c_long, POINTER(STRING))), - ('get_by_subject', CFUNCTYPE(c_int, POINTER(X509_LOOKUP), c_int, POINTER(X509_NAME), POINTER(X509_OBJECT))), - ('get_by_issuer_serial', CFUNCTYPE(c_int, POINTER(X509_LOOKUP), c_int, POINTER(X509_NAME), POINTER(ASN1_INTEGER), POINTER(X509_OBJECT))), - ('get_by_fingerprint', CFUNCTYPE(c_int, POINTER(X509_LOOKUP), c_int, POINTER(c_ubyte), c_int, POINTER(X509_OBJECT))), - ('get_by_alias', CFUNCTYPE(c_int, POINTER(X509_LOOKUP), c_int, STRING, c_int, POINTER(X509_OBJECT))), -] -assert sizeof(x509_lookup_method_st) == 40, sizeof(x509_lookup_method_st) -assert alignment(x509_lookup_method_st) == 4, alignment(x509_lookup_method_st) -X509_LOOKUP_METHOD = x509_lookup_method_st -x509_store_st._fields_ = [ - ('cache', c_int), - ('objs', POINTER(STACK)), - ('get_cert_methods', POINTER(STACK)), - ('flags', c_ulong), - ('purpose', c_int), - ('trust', c_int), - ('verify', CFUNCTYPE(c_int, POINTER(X509_STORE_CTX))), - ('verify_cb', CFUNCTYPE(c_int, c_int, POINTER(X509_STORE_CTX))), - ('get_issuer', CFUNCTYPE(c_int, POINTER(POINTER(X509)), POINTER(X509_STORE_CTX), POINTER(X509))), - ('check_issued', CFUNCTYPE(c_int, POINTER(X509_STORE_CTX), POINTER(X509), POINTER(X509))), - ('check_revocation', CFUNCTYPE(c_int, POINTER(X509_STORE_CTX))), - ('get_crl', CFUNCTYPE(c_int, POINTER(X509_STORE_CTX), POINTER(POINTER(X509_CRL)), POINTER(X509))), - ('check_crl', CFUNCTYPE(c_int, POINTER(X509_STORE_CTX), POINTER(X509_CRL))), - ('cert_crl', CFUNCTYPE(c_int, POINTER(X509_STORE_CTX), POINTER(X509_CRL), POINTER(X509))), - ('cleanup', CFUNCTYPE(c_int, POINTER(X509_STORE_CTX))), - ('ex_data', CRYPTO_EX_DATA), - ('references', c_int), - ('depth', c_int), -] -assert sizeof(x509_store_st) == 76, sizeof(x509_store_st) -assert alignment(x509_store_st) == 4, alignment(x509_store_st) -x509_lookup_st._fields_ = [ - ('init', c_int), - ('skip', c_int), - ('method', POINTER(X509_LOOKUP_METHOD)), - ('method_data', STRING), - ('store_ctx', POINTER(X509_STORE)), -] -assert sizeof(x509_lookup_st) == 20, sizeof(x509_lookup_st) -assert alignment(x509_lookup_st) == 4, alignment(x509_lookup_st) -time_t = __darwin_time_t -x509_store_ctx_st._fields_ = [ - ('ctx', POINTER(X509_STORE)), - ('current_method', c_int), - ('cert', POINTER(X509)), - ('untrusted', POINTER(STACK)), - ('purpose', c_int), - ('trust', c_int), - ('check_time', time_t), - ('flags', c_ulong), - ('other_ctx', c_void_p), - ('verify', CFUNCTYPE(c_int, POINTER(X509_STORE_CTX))), - ('verify_cb', CFUNCTYPE(c_int, c_int, POINTER(X509_STORE_CTX))), - ('get_issuer', CFUNCTYPE(c_int, POINTER(POINTER(X509)), POINTER(X509_STORE_CTX), POINTER(X509))), - ('check_issued', CFUNCTYPE(c_int, POINTER(X509_STORE_CTX), POINTER(X509), POINTER(X509))), - ('check_revocation', CFUNCTYPE(c_int, POINTER(X509_STORE_CTX))), - ('get_crl', CFUNCTYPE(c_int, POINTER(X509_STORE_CTX), POINTER(POINTER(X509_CRL)), POINTER(X509))), - ('check_crl', CFUNCTYPE(c_int, POINTER(X509_STORE_CTX), POINTER(X509_CRL))), - ('cert_crl', CFUNCTYPE(c_int, POINTER(X509_STORE_CTX), POINTER(X509_CRL), POINTER(X509))), - ('cleanup', CFUNCTYPE(c_int, POINTER(X509_STORE_CTX))), - ('depth', c_int), - ('valid', c_int), - ('last_untrusted', c_int), - ('chain', POINTER(STACK)), - ('error_depth', c_int), - ('error', c_int), - ('current_cert', POINTER(X509)), - ('current_issuer', POINTER(X509)), - ('current_crl', POINTER(X509_CRL)), - ('ex_data', CRYPTO_EX_DATA), -] -assert sizeof(x509_store_ctx_st) == 116, sizeof(x509_store_ctx_st) -assert alignment(x509_store_ctx_st) == 4, alignment(x509_store_ctx_st) -va_list = __darwin_va_list -__darwin_off_t = __int64_t -fpos_t = __darwin_off_t -class __sbuf(Structure): - pass -__sbuf._fields_ = [ - ('_base', POINTER(c_ubyte)), - ('_size', c_int), -] -assert sizeof(__sbuf) == 8, sizeof(__sbuf) -assert alignment(__sbuf) == 4, alignment(__sbuf) -class __sFILEX(Structure): - pass -__sFILEX._fields_ = [ -] -class __sFILE(Structure): - pass -__sFILE._pack_ = 4 -__sFILE._fields_ = [ - ('_p', POINTER(c_ubyte)), - ('_r', c_int), - ('_w', c_int), - ('_flags', c_short), - ('_file', c_short), - ('_bf', __sbuf), - ('_lbfsize', c_int), - ('_cookie', c_void_p), - ('_close', CFUNCTYPE(c_int, c_void_p)), - ('_read', CFUNCTYPE(c_int, c_void_p, STRING, c_int)), - ('_seek', CFUNCTYPE(fpos_t, c_void_p, c_longlong, c_int)), - ('_write', CFUNCTYPE(c_int, c_void_p, STRING, c_int)), - ('_ub', __sbuf), - ('_extra', POINTER(__sFILEX)), - ('_ur', c_int), - ('_ubuf', c_ubyte * 3), - ('_nbuf', c_ubyte * 1), - ('_lb', __sbuf), - ('_blksize', c_int), - ('_offset', fpos_t), -] -assert sizeof(__sFILE) == 88, sizeof(__sFILE) -assert alignment(__sFILE) == 4, alignment(__sFILE) -FILE = __sFILE -ct_rune_t = __darwin_ct_rune_t -rune_t = __darwin_rune_t -class div_t(Structure): - pass -div_t._fields_ = [ - ('quot', c_int), - ('rem', c_int), -] -assert sizeof(div_t) == 8, sizeof(div_t) -assert alignment(div_t) == 4, alignment(div_t) -class ldiv_t(Structure): - pass -ldiv_t._fields_ = [ - ('quot', c_long), - ('rem', c_long), -] -assert sizeof(ldiv_t) == 8, sizeof(ldiv_t) -assert alignment(ldiv_t) == 4, alignment(ldiv_t) -class lldiv_t(Structure): - pass -lldiv_t._pack_ = 4 -lldiv_t._fields_ = [ - ('quot', c_longlong), - ('rem', c_longlong), -] -assert sizeof(lldiv_t) == 16, sizeof(lldiv_t) -assert alignment(lldiv_t) == 4, alignment(lldiv_t) -__darwin_dev_t = __int32_t -dev_t = __darwin_dev_t -__darwin_mode_t = __uint16_t -mode_t = __darwin_mode_t -class mcontext(Structure): - pass -mcontext._fields_ = [ -] -class mcontext64(Structure): - pass -mcontext64._fields_ = [ -] -class __darwin_pthread_handler_rec(Structure): - pass -__darwin_pthread_handler_rec._fields_ = [ - ('__routine', CFUNCTYPE(None, c_void_p)), - ('__arg', c_void_p), - ('__next', POINTER(__darwin_pthread_handler_rec)), -] -assert sizeof(__darwin_pthread_handler_rec) == 12, sizeof(__darwin_pthread_handler_rec) -assert alignment(__darwin_pthread_handler_rec) == 4, alignment(__darwin_pthread_handler_rec) -class _opaque_pthread_attr_t(Structure): - pass -_opaque_pthread_attr_t._fields_ = [ - ('__sig', c_long), - ('__opaque', c_char * 36), -] -assert sizeof(_opaque_pthread_attr_t) == 40, sizeof(_opaque_pthread_attr_t) -assert alignment(_opaque_pthread_attr_t) == 4, alignment(_opaque_pthread_attr_t) -class _opaque_pthread_cond_t(Structure): - pass -_opaque_pthread_cond_t._fields_ = [ - ('__sig', c_long), - ('__opaque', c_char * 24), -] -assert sizeof(_opaque_pthread_cond_t) == 28, sizeof(_opaque_pthread_cond_t) -assert alignment(_opaque_pthread_cond_t) == 4, alignment(_opaque_pthread_cond_t) -class _opaque_pthread_condattr_t(Structure): - pass -_opaque_pthread_condattr_t._fields_ = [ - ('__sig', c_long), - ('__opaque', c_char * 4), -] -assert sizeof(_opaque_pthread_condattr_t) == 8, sizeof(_opaque_pthread_condattr_t) -assert alignment(_opaque_pthread_condattr_t) == 4, alignment(_opaque_pthread_condattr_t) -class _opaque_pthread_mutex_t(Structure): - pass -_opaque_pthread_mutex_t._fields_ = [ - ('__sig', c_long), - ('__opaque', c_char * 40), -] -assert sizeof(_opaque_pthread_mutex_t) == 44, sizeof(_opaque_pthread_mutex_t) -assert alignment(_opaque_pthread_mutex_t) == 4, alignment(_opaque_pthread_mutex_t) -class _opaque_pthread_mutexattr_t(Structure): - pass -_opaque_pthread_mutexattr_t._fields_ = [ - ('__sig', c_long), - ('__opaque', c_char * 8), -] -assert sizeof(_opaque_pthread_mutexattr_t) == 12, sizeof(_opaque_pthread_mutexattr_t) -assert alignment(_opaque_pthread_mutexattr_t) == 4, alignment(_opaque_pthread_mutexattr_t) -class _opaque_pthread_once_t(Structure): - pass -_opaque_pthread_once_t._fields_ = [ - ('__sig', c_long), - ('__opaque', c_char * 4), -] -assert sizeof(_opaque_pthread_once_t) == 8, sizeof(_opaque_pthread_once_t) -assert alignment(_opaque_pthread_once_t) == 4, alignment(_opaque_pthread_once_t) -class _opaque_pthread_rwlock_t(Structure): - pass -_opaque_pthread_rwlock_t._fields_ = [ - ('__sig', c_long), - ('__opaque', c_char * 124), -] -assert sizeof(_opaque_pthread_rwlock_t) == 128, sizeof(_opaque_pthread_rwlock_t) -assert alignment(_opaque_pthread_rwlock_t) == 4, alignment(_opaque_pthread_rwlock_t) -class _opaque_pthread_rwlockattr_t(Structure): - pass -_opaque_pthread_rwlockattr_t._fields_ = [ - ('__sig', c_long), - ('__opaque', c_char * 12), -] -assert sizeof(_opaque_pthread_rwlockattr_t) == 16, sizeof(_opaque_pthread_rwlockattr_t) -assert alignment(_opaque_pthread_rwlockattr_t) == 4, alignment(_opaque_pthread_rwlockattr_t) -class _opaque_pthread_t(Structure): - pass -_opaque_pthread_t._fields_ = [ - ('__sig', c_long), - ('__cleanup_stack', POINTER(__darwin_pthread_handler_rec)), - ('__opaque', c_char * 596), -] -assert sizeof(_opaque_pthread_t) == 604, sizeof(_opaque_pthread_t) -assert alignment(_opaque_pthread_t) == 4, alignment(_opaque_pthread_t) -__darwin_blkcnt_t = __int64_t -__darwin_blksize_t = __int32_t -__darwin_fsblkcnt_t = c_uint -__darwin_fsfilcnt_t = c_uint -__darwin_gid_t = __uint32_t -__darwin_id_t = __uint32_t -__darwin_ino_t = __uint32_t -__darwin_mach_port_name_t = __darwin_natural_t -__darwin_mach_port_t = __darwin_mach_port_name_t -__darwin_mcontext_t = POINTER(mcontext) -__darwin_mcontext64_t = POINTER(mcontext64) -__darwin_pid_t = __int32_t -__darwin_pthread_attr_t = _opaque_pthread_attr_t -__darwin_pthread_cond_t = _opaque_pthread_cond_t -__darwin_pthread_condattr_t = _opaque_pthread_condattr_t -__darwin_pthread_key_t = c_ulong -__darwin_pthread_mutex_t = _opaque_pthread_mutex_t -__darwin_pthread_mutexattr_t = _opaque_pthread_mutexattr_t -__darwin_pthread_once_t = _opaque_pthread_once_t -__darwin_pthread_rwlock_t = _opaque_pthread_rwlock_t -__darwin_pthread_rwlockattr_t = _opaque_pthread_rwlockattr_t -__darwin_pthread_t = POINTER(_opaque_pthread_t) -__darwin_sigset_t = __uint32_t -__darwin_suseconds_t = __int32_t -__darwin_uid_t = __uint32_t -__darwin_useconds_t = __uint32_t -__darwin_uuid_t = c_ubyte * 16 -class sigaltstack(Structure): - pass -sigaltstack._fields_ = [ - ('ss_sp', c_void_p), - ('ss_size', __darwin_size_t), - ('ss_flags', c_int), -] -assert sizeof(sigaltstack) == 12, sizeof(sigaltstack) -assert alignment(sigaltstack) == 4, alignment(sigaltstack) -__darwin_stack_t = sigaltstack -class ucontext(Structure): - pass -ucontext._fields_ = [ - ('uc_onstack', c_int), - ('uc_sigmask', __darwin_sigset_t), - ('uc_stack', __darwin_stack_t), - ('uc_link', POINTER(ucontext)), - ('uc_mcsize', __darwin_size_t), - ('uc_mcontext', __darwin_mcontext_t), -] -assert sizeof(ucontext) == 32, sizeof(ucontext) -assert alignment(ucontext) == 4, alignment(ucontext) -__darwin_ucontext_t = ucontext -class ucontext64(Structure): - pass -ucontext64._fields_ = [ - ('uc_onstack', c_int), - ('uc_sigmask', __darwin_sigset_t), - ('uc_stack', __darwin_stack_t), - ('uc_link', POINTER(ucontext64)), - ('uc_mcsize', __darwin_size_t), - ('uc_mcontext64', __darwin_mcontext64_t), -] -assert sizeof(ucontext64) == 32, sizeof(ucontext64) -assert alignment(ucontext64) == 4, alignment(ucontext64) -__darwin_ucontext64_t = ucontext64 -class timeval(Structure): - pass -timeval._fields_ = [ - ('tv_sec', __darwin_time_t), - ('tv_usec', __darwin_suseconds_t), -] -assert sizeof(timeval) == 8, sizeof(timeval) -assert alignment(timeval) == 4, alignment(timeval) -rlim_t = __int64_t -class rusage(Structure): - pass -rusage._fields_ = [ - ('ru_utime', timeval), - ('ru_stime', timeval), - ('ru_maxrss', c_long), - ('ru_ixrss', c_long), - ('ru_idrss', c_long), - ('ru_isrss', c_long), - ('ru_minflt', c_long), - ('ru_majflt', c_long), - ('ru_nswap', c_long), - ('ru_inblock', c_long), - ('ru_oublock', c_long), - ('ru_msgsnd', c_long), - ('ru_msgrcv', c_long), - ('ru_nsignals', c_long), - ('ru_nvcsw', c_long), - ('ru_nivcsw', c_long), -] -assert sizeof(rusage) == 72, sizeof(rusage) -assert alignment(rusage) == 4, alignment(rusage) -class rlimit(Structure): - pass -rlimit._pack_ = 4 -rlimit._fields_ = [ - ('rlim_cur', rlim_t), - ('rlim_max', rlim_t), -] -assert sizeof(rlimit) == 16, sizeof(rlimit) -assert alignment(rlimit) == 4, alignment(rlimit) -mcontext_t = __darwin_mcontext_t -mcontext64_t = __darwin_mcontext64_t -pthread_attr_t = __darwin_pthread_attr_t -sigset_t = __darwin_sigset_t -ucontext_t = __darwin_ucontext_t -ucontext64_t = __darwin_ucontext64_t -uid_t = __darwin_uid_t -class sigval(Union): - pass -sigval._fields_ = [ - ('sival_int', c_int), - ('sival_ptr', c_void_p), -] -assert sizeof(sigval) == 4, sizeof(sigval) -assert alignment(sigval) == 4, alignment(sigval) -class sigevent(Structure): - pass -sigevent._fields_ = [ - ('sigev_notify', c_int), - ('sigev_signo', c_int), - ('sigev_value', sigval), - ('sigev_notify_function', CFUNCTYPE(None, sigval)), - ('sigev_notify_attributes', POINTER(pthread_attr_t)), -] -assert sizeof(sigevent) == 20, sizeof(sigevent) -assert alignment(sigevent) == 4, alignment(sigevent) -class __siginfo(Structure): - pass -pid_t = __darwin_pid_t -__siginfo._fields_ = [ - ('si_signo', c_int), - ('si_errno', c_int), - ('si_code', c_int), - ('si_pid', pid_t), - ('si_uid', uid_t), - ('si_status', c_int), - ('si_addr', c_void_p), - ('si_value', sigval), - ('si_band', c_long), - ('pad', c_ulong * 7), -] -assert sizeof(__siginfo) == 64, sizeof(__siginfo) -assert alignment(__siginfo) == 4, alignment(__siginfo) -siginfo_t = __siginfo -class __sigaction_u(Union): - pass -__sigaction_u._fields_ = [ - ('__sa_handler', CFUNCTYPE(None, c_int)), - ('__sa_sigaction', CFUNCTYPE(None, c_int, POINTER(__siginfo), c_void_p)), -] -assert sizeof(__sigaction_u) == 4, sizeof(__sigaction_u) -assert alignment(__sigaction_u) == 4, alignment(__sigaction_u) -class __sigaction(Structure): - pass -__sigaction._fields_ = [ - ('__sigaction_u', __sigaction_u), - ('sa_tramp', CFUNCTYPE(None, c_void_p, c_int, c_int, POINTER(siginfo_t), c_void_p)), - ('sa_mask', sigset_t), - ('sa_flags', c_int), -] -assert sizeof(__sigaction) == 16, sizeof(__sigaction) -assert alignment(__sigaction) == 4, alignment(__sigaction) -class sigaction(Structure): - pass -sigaction._fields_ = [ - ('__sigaction_u', __sigaction_u), - ('sa_mask', sigset_t), - ('sa_flags', c_int), -] -assert sizeof(sigaction) == 12, sizeof(sigaction) -assert alignment(sigaction) == 4, alignment(sigaction) -sig_t = CFUNCTYPE(None, c_int) -stack_t = __darwin_stack_t -class sigvec(Structure): - pass -sigvec._fields_ = [ - ('sv_handler', CFUNCTYPE(None, c_int)), - ('sv_mask', c_int), - ('sv_flags', c_int), -] -assert sizeof(sigvec) == 12, sizeof(sigvec) -assert alignment(sigvec) == 4, alignment(sigvec) -class sigstack(Structure): - pass -sigstack._fields_ = [ - ('ss_sp', STRING), - ('ss_onstack', c_int), -] -assert sizeof(sigstack) == 8, sizeof(sigstack) -assert alignment(sigstack) == 4, alignment(sigstack) -u_char = c_ubyte -u_short = c_ushort -u_int = c_uint -u_long = c_ulong -ushort = c_ushort -uint = c_uint -u_quad_t = u_int64_t -quad_t = int64_t -qaddr_t = POINTER(quad_t) -caddr_t = STRING -daddr_t = int32_t -fixpt_t = u_int32_t -blkcnt_t = __darwin_blkcnt_t -blksize_t = __darwin_blksize_t -gid_t = __darwin_gid_t -in_addr_t = __uint32_t -in_port_t = __uint16_t -ino_t = __darwin_ino_t -key_t = __int32_t -nlink_t = __uint16_t -off_t = __darwin_off_t -segsz_t = int32_t -swblk_t = int32_t -clock_t = __darwin_clock_t -ssize_t = __darwin_ssize_t -useconds_t = __darwin_useconds_t -suseconds_t = __darwin_suseconds_t -fd_mask = __int32_t -class fd_set(Structure): - pass -fd_set._fields_ = [ - ('fds_bits', __int32_t * 32), -] -assert sizeof(fd_set) == 128, sizeof(fd_set) -assert alignment(fd_set) == 4, alignment(fd_set) -pthread_cond_t = __darwin_pthread_cond_t -pthread_condattr_t = __darwin_pthread_condattr_t -pthread_mutex_t = __darwin_pthread_mutex_t -pthread_mutexattr_t = __darwin_pthread_mutexattr_t -pthread_once_t = __darwin_pthread_once_t -pthread_rwlock_t = __darwin_pthread_rwlock_t -pthread_rwlockattr_t = __darwin_pthread_rwlockattr_t -pthread_t = __darwin_pthread_t -pthread_key_t = __darwin_pthread_key_t -fsblkcnt_t = __darwin_fsblkcnt_t -fsfilcnt_t = __darwin_fsfilcnt_t - -# values for enumeration 'idtype_t' -idtype_t = c_int # enum -id_t = __darwin_id_t -class wait(Union): - pass -class N4wait3DOLLAR_3E(Structure): - pass -N4wait3DOLLAR_3E._fields_ = [ - ('w_Termsig', c_uint, 7), - ('w_Coredump', c_uint, 1), - ('w_Retcode', c_uint, 8), - ('w_Filler', c_uint, 16), -] -assert sizeof(N4wait3DOLLAR_3E) == 4, sizeof(N4wait3DOLLAR_3E) -assert alignment(N4wait3DOLLAR_3E) == 4, alignment(N4wait3DOLLAR_3E) -class N4wait3DOLLAR_4E(Structure): - pass -N4wait3DOLLAR_4E._fields_ = [ - ('w_Stopval', c_uint, 8), - ('w_Stopsig', c_uint, 8), - ('w_Filler', c_uint, 16), -] -assert sizeof(N4wait3DOLLAR_4E) == 4, sizeof(N4wait3DOLLAR_4E) -assert alignment(N4wait3DOLLAR_4E) == 4, alignment(N4wait3DOLLAR_4E) -wait._fields_ = [ - ('w_status', c_int), - ('w_T', N4wait3DOLLAR_3E), - ('w_S', N4wait3DOLLAR_4E), -] -assert sizeof(wait) == 4, sizeof(wait) -assert alignment(wait) == 4, alignment(wait) -class timespec(Structure): - pass -timespec._fields_ = [ - ('tv_sec', time_t), - ('tv_nsec', c_long), -] -assert sizeof(timespec) == 8, sizeof(timespec) -assert alignment(timespec) == 4, alignment(timespec) -class tm(Structure): - pass -tm._fields_ = [ - ('tm_sec', c_int), - ('tm_min', c_int), - ('tm_hour', c_int), - ('tm_mday', c_int), - ('tm_mon', c_int), - ('tm_year', c_int), - ('tm_wday', c_int), - ('tm_yday', c_int), - ('tm_isdst', c_int), - ('tm_gmtoff', c_long), - ('tm_zone', STRING), -] -assert sizeof(tm) == 44, sizeof(tm) -assert alignment(tm) == 4, alignment(tm) -__gnuc_va_list = STRING -ptrdiff_t = c_int -int8_t = c_byte -int16_t = c_short -uint8_t = c_ubyte -uint16_t = c_ushort -uint32_t = c_uint -uint64_t = c_ulonglong -int_least8_t = int8_t -int_least16_t = int16_t -int_least32_t = int32_t -int_least64_t = int64_t -uint_least8_t = uint8_t -uint_least16_t = uint16_t -uint_least32_t = uint32_t -uint_least64_t = uint64_t -int_fast8_t = int8_t -int_fast16_t = int16_t -int_fast32_t = int32_t -int_fast64_t = int64_t -uint_fast8_t = uint8_t -uint_fast16_t = uint16_t -uint_fast32_t = uint32_t -uint_fast64_t = uint64_t -intptr_t = c_long -uintptr_t = c_ulong -intmax_t = c_longlong -uintmax_t = c_ulonglong -__all__ = ['ENGINE', 'pkcs7_enc_content_st', '__int16_t', - 'X509_REVOKED', 'SSL_CTX', 'UIT_BOOLEAN', - '__darwin_time_t', 'ucontext64_t', 'int_fast32_t', - 'pem_ctx_st', 'uint8_t', 'fpos_t', 'X509', 'COMP_CTX', - 'tm', 'N10pem_ctx_st4DOLLAR_17E', 'swblk_t', - 'ASN1_TEMPLATE', '__darwin_pthread_t', 'fixpt_t', - 'BIO_METHOD', 'ASN1_PRINTABLESTRING', 'EVP_ENCODE_CTX', - 'dh_method', 'bio_f_buffer_ctx_struct', 'in_port_t', - 'X509_SIG', '__darwin_ssize_t', '__darwin_sigset_t', - 'wait', 'uint_fast16_t', 'N12asn1_type_st4DOLLAR_11E', - 'uint_least8_t', 'pthread_rwlock_t', 'ASN1_IA5STRING', - 'fsfilcnt_t', 'ucontext', '__uint64_t', 'timespec', - 'x509_cinf_st', 'COMP_METHOD', 'MD5_CTX', 'buf_mem_st', - 'ASN1_ENCODING_st', 'PBEPARAM', 'X509_NAME_ENTRY', - '__darwin_va_list', 'ucontext_t', 'lhash_st', - 'N4wait3DOLLAR_4E', '__darwin_uuid_t', - '_ossl_old_des_ks_struct', 'id_t', 'ASN1_BIT_STRING', - 'va_list', '__darwin_wchar_t', 'pthread_key_t', - 'pkcs7_signer_info_st', 'ASN1_METHOD', 'DSA_SIG', 'DSA', - 'UIT_NONE', 'pthread_t', '__darwin_useconds_t', - 'uint_fast8_t', 'UI_STRING', 'DES_cblock', - '__darwin_mcontext64_t', 'rlim_t', 'PEM_Encode_Seal_st', - 'SHAstate_st', 'u_quad_t', 'openssl_fptr', - '_opaque_pthread_rwlockattr_t', - 'N18x509_attributes_st4DOLLAR_13E', - '__darwin_pthread_rwlock_t', 'daddr_t', 'ui_string_st', - 'x509_file_st', 'X509_req_info_st', 'int_least64_t', - 'evp_Encode_Ctx_st', 'X509_OBJECTS', 'CRYPTO_EX_DATA', - '__int8_t', 'AUTHORITY_KEYID_st', '_opaque_pthread_attr_t', - 'sigstack', 'EVP_CIPHER_CTX', 'X509_extension_st', 'pid_t', - 'RSA_METHOD', 'PEM_USER', 'pem_recip_st', 'env_md_ctx_st', - 'rc5_key_st', 'ui_st', 'X509_PUBKEY', 'u_int8_t', - 'ASN1_ITEM_st', 'pkcs7_recip_info_st', 'ssl2_state_st', - 'off_t', 'N10ssl_ctx_st4DOLLAR_18E', 'crypto_ex_data_st', - 'ui_method_st', '__darwin_pthread_rwlockattr_t', - 'CRYPTO_EX_dup', '__darwin_ino_t', '__sFILE', - 'OSUnknownByteOrder', 'BN_MONT_CTX', 'ASN1_NULL', 'time_t', - 'CRYPTO_EX_new', 'asn1_type_st', 'CRYPTO_EX_DATA_FUNCS', - 'user_time_t', 'BIGNUM', 'pthread_rwlockattr_t', - 'ASN1_VALUE_st', 'DH_METHOD', '__darwin_off_t', - '_opaque_pthread_t', 'bn_blinding_st', 'RSA', 'ssize_t', - 'mcontext64_t', 'user_long_t', 'fsblkcnt_t', 'cert_st', - '__darwin_pthread_condattr_t', 'X509_PKEY', - '__darwin_id_t', '__darwin_nl_item', 'SSL2_STATE', 'FILE', - 'pthread_mutexattr_t', 'size_t', - '_ossl_old_des_key_schedule', 'pkcs7_issuer_and_serial_st', - 'sigval', 'CRYPTO_MEM_LEAK_CB', 'X509_NAME', 'blkcnt_t', - 'uint_least16_t', '__darwin_dev_t', 'evp_cipher_info_st', - 'BN_BLINDING', 'ssl3_state_st', 'uint_least64_t', - 'user_addr_t', 'DES_key_schedule', 'RIPEMD160_CTX', - 'u_char', 'X509_algor_st', 'uid_t', 'sess_cert_st', - 'u_int64_t', 'u_int16_t', 'sigset_t', '__darwin_ptrdiff_t', - 'ASN1_CTX', 'STACK', '__int32_t', 'UI_METHOD', - 'NETSCAPE_SPKI', 'UIT_PROMPT', 'st_CRYPTO_EX_DATA_IMPL', - 'cast_key_st', 'X509_HASH_DIR_CTX', 'sigevent', - 'user_ssize_t', 'clock_t', 'aes_key_st', - '__darwin_socklen_t', '__darwin_intptr_t', 'int_fast64_t', - 'asn1_string_table_st', 'uint_fast32_t', - 'ASN1_VISIBLESTRING', 'DSA_SIG_st', 'obj_name_st', - 'X509_LOOKUP_METHOD', 'u_int32_t', 'EVP_CIPHER_INFO', - '__gnuc_va_list', 'AES_KEY', 'PKCS7_ISSUER_AND_SERIAL', - 'BN_CTX', '__darwin_blkcnt_t', 'key_t', 'SHA_CTX', - 'pkcs7_signed_st', 'SSL', 'N10pem_ctx_st4DOLLAR_16E', - 'pthread_attr_t', 'EVP_MD', 'uint', 'ASN1_BOOLEAN', - 'ino_t', '__darwin_clock_t', 'ASN1_OCTET_STRING', - 'asn1_ctx_st', 'BIO_F_BUFFER_CTX', 'bn_mont_ctx_st', - 'X509_REQ_INFO', 'PEM_CTX', 'sigvec', - '__darwin_pthread_mutexattr_t', 'x509_attributes_st', - 'stack_t', '__darwin_mode_t', '__mbstate_t', - 'asn1_object_st', 'ASN1_ENCODING', '__uint8_t', - 'LHASH_NODE', 'PKCS7_SIGNER_INFO', 'asn1_method_st', - 'stack_st', 'bio_info_cb', 'div_t', 'UIT_VERIFY', - 'PBEPARAM_st', 'N4wait3DOLLAR_3E', 'quad_t', '__siginfo', - '__darwin_mbstate_t', 'rsa_st', 'ASN1_UNIVERSALSTRING', - 'uint64_t', 'ssl_comp_st', 'X509_OBJECT', 'pthread_cond_t', - 'DH', '__darwin_wctype_t', 'PKCS7_ENVELOPE', 'ASN1_TLC_st', - 'sig_atomic_t', 'BIO', 'nlink_t', 'BUF_MEM', 'SSL3_RECORD', - 'bio_method_st', 'timeval', 'UI_string_types', 'BIO_dummy', - 'ssl_ctx_st', 'NETSCAPE_CERT_SEQUENCE', - 'BIT_STRING_BITNAME_st', '__darwin_pthread_attr_t', - 'int8_t', '__darwin_wint_t', 'OBJ_NAME', - 'PKCS8_PRIV_KEY_INFO', 'PBE2PARAM_st', - 'LHASH_DOALL_FN_TYPE', 'x509_st', 'X509_VAL', 'dev_t', - 'ASN1_TEMPLATE_st', 'MD5state_st', '__uint16_t', - 'LHASH_DOALL_ARG_FN_TYPE', 'mdc2_ctx_st', 'SSL3_STATE', - 'ssl3_buffer_st', 'ASN1_ITEM_EXP', - '_opaque_pthread_condattr_t', 'mode_t', 'ASN1_VALUE', - 'qaddr_t', '__darwin_gid_t', 'EVP_PKEY', 'CRYPTO_EX_free', - '_ossl_old_des_cblock', 'X509_INFO', 'asn1_string_st', - 'intptr_t', 'UIT_INFO', 'int_fast8_t', 'sigaltstack', - 'env_md_st', 'LHASH', '__darwin_ucontext_t', - 'PKCS7_SIGN_ENVELOPE', '__darwin_mcontext_t', 'ct_rune_t', - 'MD2_CTX', 'pthread_once_t', 'SSL3_BUFFER', 'fd_mask', - 'ASN1_TYPE', 'PKCS7_SIGNED', 'ssl3_record_st', 'BF_KEY', - 'MD4state_st', 'MD4_CTX', 'int16_t', 'SSL_CIPHER', - 'rune_t', 'X509_TRUST', 'siginfo_t', 'X509_STORE', - '__sbuf', 'X509_STORE_CTX', '__darwin_blksize_t', 'ldiv_t', - 'ASN1_TIME', 'SSL_METHOD', 'X509_LOOKUP', - 'Netscape_spki_st', 'P_PID', 'sigaction', 'sig_t', - 'hostent', 'x509_cert_aux_st', '_opaque_pthread_cond_t', - 'segsz_t', 'ushort', '__darwin_ct_rune_t', 'fd_set', - 'BN_RECP_CTX', 'x509_lookup_st', 'uint16_t', 'pkcs7_st', - 'asn1_header_st', '__darwin_pthread_key_t', - 'x509_trust_st', '__darwin_pthread_handler_rec', 'int32_t', - 'X509_CRL_INFO', 'N11evp_pkey_st4DOLLAR_12E', 'MDC2_CTX', - 'N23_ossl_old_des_ks_struct4DOLLAR_10E', 'ASN1_HEADER', - 'X509_crl_info_st', 'LHASH_HASH_FN_TYPE', - '_opaque_pthread_mutexattr_t', 'ssl_st', - 'N8pkcs7_st4DOLLAR_15E', 'evp_pkey_st', - 'pkcs7_signedandenveloped_st', '__darwin_mach_port_t', - 'EVP_PBE_KEYGEN', '_opaque_pthread_mutex_t', - 'ASN1_UTCTIME', 'mcontext', 'crypto_ex_data_func_st', - 'u_long', 'PBKDF2PARAM_st', 'rc4_key_st', 'DSA_METHOD', - 'EVP_CIPHER', 'BIT_STRING_BITNAME', 'PKCS7_RECIP_INFO', - 'ssl3_enc_method', 'X509_CERT_AUX', 'uintmax_t', - 'int_fast16_t', 'RC5_32_KEY', 'ucontext64', 'ASN1_INTEGER', - 'u_short', 'N14x509_object_st4DOLLAR_14E', 'mcontext64', - 'X509_sig_st', 'ASN1_GENERALSTRING', 'PKCS7', '__sFILEX', - 'X509_name_entry_st', 'ssl_session_st', 'caddr_t', - 'bignum_st', 'X509_CINF', '__darwin_pthread_cond_t', - 'ASN1_TLC', 'PKCS7_ENCRYPT', 'NETSCAPE_SPKAC', - 'Netscape_spkac_st', 'idtype_t', 'UIT_ERROR', - 'uint_fast64_t', 'in_addr_t', 'pthread_mutex_t', - '__int64_t', 'ASN1_BMPSTRING', 'uint32_t', - 'PEM_ENCODE_SEAL_CTX', 'suseconds_t', 'ASN1_OBJECT', - 'X509_val_st', 'private_key_st', 'CRYPTO_dynlock', - 'X509_objects_st', 'CRYPTO_EX_DATA_IMPL', - 'pthread_condattr_t', 'PKCS7_DIGEST', 'uint_least32_t', - 'ASN1_STRING', '__uint32_t', 'P_PGID', 'rsa_meth_st', - 'X509_crl_st', 'RC2_KEY', '__darwin_fsfilcnt_t', - 'X509_revoked_st', 'PBE2PARAM', 'blksize_t', - 'Netscape_certificate_sequence', 'ssl_cipher_st', - 'bignum_ctx', 'register_t', 'ASN1_UTF8STRING', - 'pkcs7_encrypted_st', 'RC4_KEY', '__darwin_ucontext64_t', - 'N13ssl2_state_st4DOLLAR_19E', 'bn_recp_ctx_st', - 'CAST_KEY', 'X509_ATTRIBUTE', '__darwin_suseconds_t', - '__sigaction', 'user_ulong_t', 'syscall_arg_t', - 'evp_cipher_ctx_st', 'X509_ALGOR', 'mcontext_t', - 'const_DES_cblock', '__darwin_fsblkcnt_t', 'dsa_st', - 'int_least8_t', 'MD2state_st', 'X509_EXTENSION', - 'GEN_SESSION_CB', 'int_least16_t', '__darwin_wctrans_t', - 'PBKDF2PARAM', 'x509_lookup_method_st', 'pem_password_cb', - 'X509_info_st', 'x509_store_st', '__darwin_natural_t', - 'X509_pubkey_st', 'pkcs7_digest_st', '__darwin_size_t', - 'ASN1_STRING_TABLE', 'OSLittleEndian', 'RIPEMD160state_st', - 'pkcs7_enveloped_st', 'UI', 'ptrdiff_t', 'X509_REQ', - 'CRYPTO_dynlock_value', 'X509_req_st', 'x509_store_ctx_st', - 'N13ssl3_state_st4DOLLAR_20E', 'lhash_node_st', - '__darwin_pthread_mutex_t', 'LHASH_COMP_FN_TYPE', - '__darwin_rune_t', 'rlimit', '__darwin_pthread_once_t', - 'OSBigEndian', 'uintptr_t', '__darwin_uid_t', 'u_int', - 'ASN1_T61STRING', 'gid_t', 'ssl_method_st', 'ASN1_ITEM', - 'ASN1_ENUMERATED', '_opaque_pthread_rwlock_t', - 'pkcs8_priv_key_info_st', 'intmax_t', 'sigcontext', - 'X509_CRL', 'rc2_key_st', 'engine_st', 'x509_object_st', - '_opaque_pthread_once_t', 'DES_ks', 'SSL_COMP', - 'dsa_method', 'int64_t', 'bio_st', 'bf_key_st', - 'ASN1_GENERALIZEDTIME', 'PKCS7_ENC_CONTENT', - '__darwin_pid_t', 'lldiv_t', 'comp_method_st', - 'EVP_MD_CTX', 'evp_cipher_st', 'X509_name_st', - 'x509_hash_dir_st', '__darwin_mach_port_name_t', - 'useconds_t', 'user_size_t', 'SSL_SESSION', 'rusage', - 'ssl_crock_st', 'int_least32_t', '__sigaction_u', 'dh_st', - 'P_ALL', '__darwin_stack_t', 'N6DES_ks3DOLLAR_9E', - 'comp_ctx_st', 'X509_CERT_FILE_CTX'] diff --git a/PythonLib/extra/lib2to3/tests/data/py2_test_grammar.py b/PythonLib/extra/lib2to3/tests/data/py2_test_grammar.py deleted file mode 100644 index b5a4137d..00000000 --- a/PythonLib/extra/lib2to3/tests/data/py2_test_grammar.py +++ /dev/null @@ -1,974 +0,0 @@ -# Python test set -- part 1, grammar. -# This just tests whether the parser accepts them all. - -# NOTE: When you run this test as a script from the command line, you -# get warnings about certain hex/oct constants. Since those are -# issued by the parser, you can't suppress them by adding a -# filterwarnings() call to this module. Therefore, to shut up the -# regression test, the filterwarnings() call has been added to -# regrtest.py. - -from test.test_support import run_unittest, check_syntax_error -import unittest -import sys -# testing import * -from sys import * - -class TokenTests(unittest.TestCase): - - def testBackslash(self): - # Backslash means line continuation: - x = 1 \ - + 1 - self.assertEquals(x, 2, 'backslash for line continuation') - - # Backslash does not means continuation in comments :\ - x = 0 - self.assertEquals(x, 0, 'backslash ending comment') - - def testPlainIntegers(self): - self.assertEquals(0xff, 255) - self.assertEquals(0377, 255) - self.assertEquals(2147483647, 017777777777) - # "0x" is not a valid literal - self.assertRaises(SyntaxError, eval, "0x") - from sys import maxint - if maxint == 2147483647: - self.assertEquals(-2147483647-1, -020000000000) - # XXX -2147483648 - self.assert_(037777777777 > 0) - self.assert_(0xffffffff > 0) - for s in '2147483648', '040000000000', '0x100000000': - try: - x = eval(s) - except OverflowError: - self.fail("OverflowError on huge integer literal %r" % s) - elif maxint == 9223372036854775807: - self.assertEquals(-9223372036854775807-1, -01000000000000000000000) - self.assert_(01777777777777777777777 > 0) - self.assert_(0xffffffffffffffff > 0) - for s in '9223372036854775808', '02000000000000000000000', \ - '0x10000000000000000': - try: - x = eval(s) - except OverflowError: - self.fail("OverflowError on huge integer literal %r" % s) - else: - self.fail('Weird maxint value %r' % maxint) - - def testLongIntegers(self): - x = 0L - x = 0l - x = 0xffffffffffffffffL - x = 0xffffffffffffffffl - x = 077777777777777777L - x = 077777777777777777l - x = 123456789012345678901234567890L - x = 123456789012345678901234567890l - - def testFloats(self): - x = 3.14 - x = 314. - x = 0.314 - # XXX x = 000.314 - x = .314 - x = 3e14 - x = 3E14 - x = 3e-14 - x = 3e+14 - x = 3.e14 - x = .3e14 - x = 3.1e4 - - def testStringLiterals(self): - x = ''; y = ""; self.assert_(len(x) == 0 and x == y) - x = '\''; y = "'"; self.assert_(len(x) == 1 and x == y and ord(x) == 39) - x = '"'; y = "\""; self.assert_(len(x) == 1 and x == y and ord(x) == 34) - x = "doesn't \"shrink\" does it" - y = 'doesn\'t "shrink" does it' - self.assert_(len(x) == 24 and x == y) - x = "does \"shrink\" doesn't it" - y = 'does "shrink" doesn\'t it' - self.assert_(len(x) == 24 and x == y) - x = """ -The "quick" -brown fox -jumps over -the 'lazy' dog. -""" - y = '\nThe "quick"\nbrown fox\njumps over\nthe \'lazy\' dog.\n' - self.assertEquals(x, y) - y = ''' -The "quick" -brown fox -jumps over -the 'lazy' dog. -''' - self.assertEquals(x, y) - y = "\n\ -The \"quick\"\n\ -brown fox\n\ -jumps over\n\ -the 'lazy' dog.\n\ -" - self.assertEquals(x, y) - y = '\n\ -The \"quick\"\n\ -brown fox\n\ -jumps over\n\ -the \'lazy\' dog.\n\ -' - self.assertEquals(x, y) - - -class GrammarTests(unittest.TestCase): - - # single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE - # XXX can't test in a script -- this rule is only used when interactive - - # file_input: (NEWLINE | stmt)* ENDMARKER - # Being tested as this very moment this very module - - # expr_input: testlist NEWLINE - # XXX Hard to test -- used only in calls to input() - - def testEvalInput(self): - # testlist ENDMARKER - x = eval('1, 0 or 1') - - def testFuncdef(self): - ### 'def' NAME parameters ':' suite - ### parameters: '(' [varargslist] ')' - ### varargslist: (fpdef ['=' test] ',')* ('*' NAME [',' ('**'|'*' '*') NAME] - ### | ('**'|'*' '*') NAME) - ### | fpdef ['=' test] (',' fpdef ['=' test])* [','] - ### fpdef: NAME | '(' fplist ')' - ### fplist: fpdef (',' fpdef)* [','] - ### arglist: (argument ',')* (argument | *' test [',' '**' test] | '**' test) - ### argument: [test '='] test # Really [keyword '='] test - def f1(): pass - f1() - f1(*()) - f1(*(), **{}) - def f2(one_argument): pass - def f3(two, arguments): pass - def f4(two, (compound, (argument, list))): pass - def f5((compound, first), two): pass - self.assertEquals(f2.func_code.co_varnames, ('one_argument',)) - self.assertEquals(f3.func_code.co_varnames, ('two', 'arguments')) - if sys.platform.startswith('java'): - self.assertEquals(f4.func_code.co_varnames, - ('two', '(compound, (argument, list))', 'compound', 'argument', - 'list',)) - self.assertEquals(f5.func_code.co_varnames, - ('(compound, first)', 'two', 'compound', 'first')) - else: - self.assertEquals(f4.func_code.co_varnames, - ('two', '.1', 'compound', 'argument', 'list')) - self.assertEquals(f5.func_code.co_varnames, - ('.0', 'two', 'compound', 'first')) - def a1(one_arg,): pass - def a2(two, args,): pass - def v0(*rest): pass - def v1(a, *rest): pass - def v2(a, b, *rest): pass - def v3(a, (b, c), *rest): return a, b, c, rest - - f1() - f2(1) - f2(1,) - f3(1, 2) - f3(1, 2,) - f4(1, (2, (3, 4))) - v0() - v0(1) - v0(1,) - v0(1,2) - v0(1,2,3,4,5,6,7,8,9,0) - v1(1) - v1(1,) - v1(1,2) - v1(1,2,3) - v1(1,2,3,4,5,6,7,8,9,0) - v2(1,2) - v2(1,2,3) - v2(1,2,3,4) - v2(1,2,3,4,5,6,7,8,9,0) - v3(1,(2,3)) - v3(1,(2,3),4) - v3(1,(2,3),4,5,6,7,8,9,0) - - # ceval unpacks the formal arguments into the first argcount names; - # thus, the names nested inside tuples must appear after these names. - if sys.platform.startswith('java'): - self.assertEquals(v3.func_code.co_varnames, ('a', '(b, c)', 'rest', 'b', 'c')) - else: - self.assertEquals(v3.func_code.co_varnames, ('a', '.1', 'rest', 'b', 'c')) - self.assertEquals(v3(1, (2, 3), 4), (1, 2, 3, (4,))) - def d01(a=1): pass - d01() - d01(1) - d01(*(1,)) - d01(**{'a':2}) - def d11(a, b=1): pass - d11(1) - d11(1, 2) - d11(1, **{'b':2}) - def d21(a, b, c=1): pass - d21(1, 2) - d21(1, 2, 3) - d21(*(1, 2, 3)) - d21(1, *(2, 3)) - d21(1, 2, *(3,)) - d21(1, 2, **{'c':3}) - def d02(a=1, b=2): pass - d02() - d02(1) - d02(1, 2) - d02(*(1, 2)) - d02(1, *(2,)) - d02(1, **{'b':2}) - d02(**{'a': 1, 'b': 2}) - def d12(a, b=1, c=2): pass - d12(1) - d12(1, 2) - d12(1, 2, 3) - def d22(a, b, c=1, d=2): pass - d22(1, 2) - d22(1, 2, 3) - d22(1, 2, 3, 4) - def d01v(a=1, *rest): pass - d01v() - d01v(1) - d01v(1, 2) - d01v(*(1, 2, 3, 4)) - d01v(*(1,)) - d01v(**{'a':2}) - def d11v(a, b=1, *rest): pass - d11v(1) - d11v(1, 2) - d11v(1, 2, 3) - def d21v(a, b, c=1, *rest): pass - d21v(1, 2) - d21v(1, 2, 3) - d21v(1, 2, 3, 4) - d21v(*(1, 2, 3, 4)) - d21v(1, 2, **{'c': 3}) - def d02v(a=1, b=2, *rest): pass - d02v() - d02v(1) - d02v(1, 2) - d02v(1, 2, 3) - d02v(1, *(2, 3, 4)) - d02v(**{'a': 1, 'b': 2}) - def d12v(a, b=1, c=2, *rest): pass - d12v(1) - d12v(1, 2) - d12v(1, 2, 3) - d12v(1, 2, 3, 4) - d12v(*(1, 2, 3, 4)) - d12v(1, 2, *(3, 4, 5)) - d12v(1, *(2,), **{'c': 3}) - def d22v(a, b, c=1, d=2, *rest): pass - d22v(1, 2) - d22v(1, 2, 3) - d22v(1, 2, 3, 4) - d22v(1, 2, 3, 4, 5) - d22v(*(1, 2, 3, 4)) - d22v(1, 2, *(3, 4, 5)) - d22v(1, *(2, 3), **{'d': 4}) - def d31v((x)): pass - d31v(1) - def d32v((x,)): pass - d32v((1,)) - - # keyword arguments after *arglist - def f(*args, **kwargs): - return args, kwargs - self.assertEquals(f(1, x=2, *[3, 4], y=5), ((1, 3, 4), - {'x':2, 'y':5})) - self.assertRaises(SyntaxError, eval, "f(1, *(2,3), 4)") - self.assertRaises(SyntaxError, eval, "f(1, x=2, *(3,4), x=5)") - - # Check ast errors in *args and *kwargs - check_syntax_error(self, "f(*g(1=2))") - check_syntax_error(self, "f(**g(1=2))") - - def testLambdef(self): - ### lambdef: 'lambda' [varargslist] ':' test - l1 = lambda : 0 - self.assertEquals(l1(), 0) - l2 = lambda : a[d] # XXX just testing the expression - l3 = lambda : [2 < x for x in [-1, 3, 0L]] - self.assertEquals(l3(), [0, 1, 0]) - l4 = lambda x = lambda y = lambda z=1 : z : y() : x() - self.assertEquals(l4(), 1) - l5 = lambda x, y, z=2: x + y + z - self.assertEquals(l5(1, 2), 5) - self.assertEquals(l5(1, 2, 3), 6) - check_syntax_error(self, "lambda x: x = 2") - check_syntax_error(self, "lambda (None,): None") - - ### stmt: simple_stmt | compound_stmt - # Tested below - - def testSimpleStmt(self): - ### simple_stmt: small_stmt (';' small_stmt)* [';'] - x = 1; pass; del x - def foo(): - # verify statements that end with semi-colons - x = 1; pass; del x; - foo() - - ### small_stmt: expr_stmt | print_stmt | pass_stmt | del_stmt | flow_stmt | import_stmt | global_stmt | access_stmt | exec_stmt - # Tested below - - def testExprStmt(self): - # (exprlist '=')* exprlist - 1 - 1, 2, 3 - x = 1 - x = 1, 2, 3 - x = y = z = 1, 2, 3 - x, y, z = 1, 2, 3 - abc = a, b, c = x, y, z = xyz = 1, 2, (3, 4) - - check_syntax_error(self, "x + 1 = 1") - check_syntax_error(self, "a + 1 = b + 2") - - def testPrintStmt(self): - # 'print' (test ',')* [test] - import StringIO - - # Can't test printing to real stdout without comparing output - # which is not available in unittest. - save_stdout = sys.stdout - sys.stdout = StringIO.StringIO() - - print 1, 2, 3 - print 1, 2, 3, - print - print 0 or 1, 0 or 1, - print 0 or 1 - - # 'print' '>>' test ',' - print >> sys.stdout, 1, 2, 3 - print >> sys.stdout, 1, 2, 3, - print >> sys.stdout - print >> sys.stdout, 0 or 1, 0 or 1, - print >> sys.stdout, 0 or 1 - - # test printing to an instance - class Gulp: - def write(self, msg): pass - - gulp = Gulp() - print >> gulp, 1, 2, 3 - print >> gulp, 1, 2, 3, - print >> gulp - print >> gulp, 0 or 1, 0 or 1, - print >> gulp, 0 or 1 - - # test print >> None - def driver(): - oldstdout = sys.stdout - sys.stdout = Gulp() - try: - tellme(Gulp()) - tellme() - finally: - sys.stdout = oldstdout - - # we should see this once - def tellme(file=sys.stdout): - print >> file, 'hello world' - - driver() - - # we should not see this at all - def tellme(file=None): - print >> file, 'goodbye universe' - - driver() - - self.assertEqual(sys.stdout.getvalue(), '''\ -1 2 3 -1 2 3 -1 1 1 -1 2 3 -1 2 3 -1 1 1 -hello world -''') - sys.stdout = save_stdout - - # syntax errors - check_syntax_error(self, 'print ,') - check_syntax_error(self, 'print >> x,') - - def testDelStmt(self): - # 'del' exprlist - abc = [1,2,3] - x, y, z = abc - xyz = x, y, z - - del abc - del x, y, (z, xyz) - - def testPassStmt(self): - # 'pass' - pass - - # flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt - # Tested below - - def testBreakStmt(self): - # 'break' - while 1: break - - def testContinueStmt(self): - # 'continue' - i = 1 - while i: i = 0; continue - - msg = "" - while not msg: - msg = "ok" - try: - continue - msg = "continue failed to continue inside try" - except: - msg = "continue inside try called except block" - if msg != "ok": - self.fail(msg) - - msg = "" - while not msg: - msg = "finally block not called" - try: - continue - finally: - msg = "ok" - if msg != "ok": - self.fail(msg) - - def test_break_continue_loop(self): - # This test warrants an explanation. It is a test specifically for SF bugs - # #463359 and #462937. The bug is that a 'break' statement executed or - # exception raised inside a try/except inside a loop, *after* a continue - # statement has been executed in that loop, will cause the wrong number of - # arguments to be popped off the stack and the instruction pointer reset to - # a very small number (usually 0.) Because of this, the following test - # *must* written as a function, and the tracking vars *must* be function - # arguments with default values. Otherwise, the test will loop and loop. - - def test_inner(extra_burning_oil = 1, count=0): - big_hippo = 2 - while big_hippo: - count += 1 - try: - if extra_burning_oil and big_hippo == 1: - extra_burning_oil -= 1 - break - big_hippo -= 1 - continue - except: - raise - if count > 2 or big_hippo <> 1: - self.fail("continue then break in try/except in loop broken!") - test_inner() - - def testReturn(self): - # 'return' [testlist] - def g1(): return - def g2(): return 1 - g1() - x = g2() - check_syntax_error(self, "class foo:return 1") - - def testYield(self): - check_syntax_error(self, "class foo:yield 1") - - def testRaise(self): - # 'raise' test [',' test] - try: raise RuntimeError, 'just testing' - except RuntimeError: pass - try: raise KeyboardInterrupt - except KeyboardInterrupt: pass - - def testImport(self): - # 'import' dotted_as_names - import sys - import time, sys - # 'from' dotted_name 'import' ('*' | '(' import_as_names ')' | import_as_names) - from time import time - from time import (time) - # not testable inside a function, but already done at top of the module - # from sys import * - from sys import path, argv - from sys import (path, argv) - from sys import (path, argv,) - - def testGlobal(self): - # 'global' NAME (',' NAME)* - global a - global a, b - global one, two, three, four, five, six, seven, eight, nine, ten - - def testExec(self): - # 'exec' expr ['in' expr [',' expr]] - z = None - del z - exec 'z=1+1\n' - if z != 2: self.fail('exec \'z=1+1\'\\n') - del z - exec 'z=1+1' - if z != 2: self.fail('exec \'z=1+1\'') - z = None - del z - import types - if hasattr(types, "UnicodeType"): - exec r"""if 1: - exec u'z=1+1\n' - if z != 2: self.fail('exec u\'z=1+1\'\\n') - del z - exec u'z=1+1' - if z != 2: self.fail('exec u\'z=1+1\'')""" - g = {} - exec 'z = 1' in g - if g.has_key('__builtins__'): del g['__builtins__'] - if g != {'z': 1}: self.fail('exec \'z = 1\' in g') - g = {} - l = {} - - import warnings - warnings.filterwarnings("ignore", "global statement", module="") - exec 'global a; a = 1; b = 2' in g, l - if g.has_key('__builtins__'): del g['__builtins__'] - if l.has_key('__builtins__'): del l['__builtins__'] - if (g, l) != ({'a':1}, {'b':2}): - self.fail('exec ... in g (%s), l (%s)' %(g,l)) - - def testAssert(self): - # assert_stmt: 'assert' test [',' test] - assert 1 - assert 1, 1 - assert lambda x:x - assert 1, lambda x:x+1 - try: - assert 0, "msg" - except AssertionError, e: - self.assertEquals(e.args[0], "msg") - else: - if __debug__: - self.fail("AssertionError not raised by assert 0") - - ### compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef - # Tested below - - def testIf(self): - # 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] - if 1: pass - if 1: pass - else: pass - if 0: pass - elif 0: pass - if 0: pass - elif 0: pass - elif 0: pass - elif 0: pass - else: pass - - def testWhile(self): - # 'while' test ':' suite ['else' ':' suite] - while 0: pass - while 0: pass - else: pass - - # Issue1920: "while 0" is optimized away, - # ensure that the "else" clause is still present. - x = 0 - while 0: - x = 1 - else: - x = 2 - self.assertEquals(x, 2) - - def testFor(self): - # 'for' exprlist 'in' exprlist ':' suite ['else' ':' suite] - for i in 1, 2, 3: pass - for i, j, k in (): pass - else: pass - class Squares: - def __init__(self, max): - self.max = max - self.sofar = [] - def __len__(self): return len(self.sofar) - def __getitem__(self, i): - if not 0 <= i < self.max: raise IndexError - n = len(self.sofar) - while n <= i: - self.sofar.append(n*n) - n = n+1 - return self.sofar[i] - n = 0 - for x in Squares(10): n = n+x - if n != 285: - self.fail('for over growing sequence') - - result = [] - for x, in [(1,), (2,), (3,)]: - result.append(x) - self.assertEqual(result, [1, 2, 3]) - - def testTry(self): - ### try_stmt: 'try' ':' suite (except_clause ':' suite)+ ['else' ':' suite] - ### | 'try' ':' suite 'finally' ':' suite - ### except_clause: 'except' [expr [('as' | ',') expr]] - try: - 1/0 - except ZeroDivisionError: - pass - else: - pass - try: 1/0 - except EOFError: pass - except TypeError as msg: pass - except RuntimeError, msg: pass - except: pass - else: pass - try: 1/0 - except (EOFError, TypeError, ZeroDivisionError): pass - try: 1/0 - except (EOFError, TypeError, ZeroDivisionError), msg: pass - try: pass - finally: pass - - def testSuite(self): - # simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT - if 1: pass - if 1: - pass - if 1: - # - # - # - pass - pass - # - pass - # - - def testTest(self): - ### and_test ('or' and_test)* - ### and_test: not_test ('and' not_test)* - ### not_test: 'not' not_test | comparison - if not 1: pass - if 1 and 1: pass - if 1 or 1: pass - if not not not 1: pass - if not 1 and 1 and 1: pass - if 1 and 1 or 1 and 1 and 1 or not 1 and 1: pass - - def testComparison(self): - ### comparison: expr (comp_op expr)* - ### comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not' - if 1: pass - x = (1 == 1) - if 1 == 1: pass - if 1 != 1: pass - if 1 <> 1: pass - if 1 < 1: pass - if 1 > 1: pass - if 1 <= 1: pass - if 1 >= 1: pass - if 1 is 1: pass - if 1 is not 1: pass - if 1 in (): pass - if 1 not in (): pass - if 1 < 1 > 1 == 1 >= 1 <= 1 <> 1 != 1 in 1 not in 1 is 1 is not 1: pass - - def testBinaryMaskOps(self): - x = 1 & 1 - x = 1 ^ 1 - x = 1 | 1 - - def testShiftOps(self): - x = 1 << 1 - x = 1 >> 1 - x = 1 << 1 >> 1 - - def testAdditiveOps(self): - x = 1 - x = 1 + 1 - x = 1 - 1 - 1 - x = 1 - 1 + 1 - 1 + 1 - - def testMultiplicativeOps(self): - x = 1 * 1 - x = 1 / 1 - x = 1 % 1 - x = 1 / 1 * 1 % 1 - - def testUnaryOps(self): - x = +1 - x = -1 - x = ~1 - x = ~1 ^ 1 & 1 | 1 & 1 ^ -1 - x = -1*1/1 + 1*1 - ---1*1 - - def testSelectors(self): - ### trailer: '(' [testlist] ')' | '[' subscript ']' | '.' NAME - ### subscript: expr | [expr] ':' [expr] - - import sys, time - c = sys.path[0] - x = time.time() - x = sys.modules['time'].time() - a = '01234' - c = a[0] - c = a[-1] - s = a[0:5] - s = a[:5] - s = a[0:] - s = a[:] - s = a[-5:] - s = a[:-1] - s = a[-4:-3] - # A rough test of SF bug 1333982. http://python.org/sf/1333982 - # The testing here is fairly incomplete. - # Test cases should include: commas with 1 and 2 colons - d = {} - d[1] = 1 - d[1,] = 2 - d[1,2] = 3 - d[1,2,3] = 4 - L = list(d) - L.sort() - self.assertEquals(str(L), '[1, (1,), (1, 2), (1, 2, 3)]') - - def testAtoms(self): - ### atom: '(' [testlist] ')' | '[' [testlist] ']' | '{' [dictmaker] '}' | '`' testlist '`' | NAME | NUMBER | STRING - ### dictmaker: test ':' test (',' test ':' test)* [','] - - x = (1) - x = (1 or 2 or 3) - x = (1 or 2 or 3, 2, 3) - - x = [] - x = [1] - x = [1 or 2 or 3] - x = [1 or 2 or 3, 2, 3] - x = [] - - x = {} - x = {'one': 1} - x = {'one': 1,} - x = {'one' or 'two': 1 or 2} - x = {'one': 1, 'two': 2} - x = {'one': 1, 'two': 2,} - x = {'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6} - - x = `x` - x = `1 or 2 or 3` - self.assertEqual(`1,2`, '(1, 2)') - - x = x - x = 'x' - x = 123 - - ### exprlist: expr (',' expr)* [','] - ### testlist: test (',' test)* [','] - # These have been exercised enough above - - def testClassdef(self): - # 'class' NAME ['(' [testlist] ')'] ':' suite - class B: pass - class B2(): pass - class C1(B): pass - class C2(B): pass - class D(C1, C2, B): pass - class C: - def meth1(self): pass - def meth2(self, arg): pass - def meth3(self, a1, a2): pass - # decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE - # decorators: decorator+ - # decorated: decorators (classdef | funcdef) - def class_decorator(x): - x.decorated = True - return x - @class_decorator - class G: - pass - self.assertEqual(G.decorated, True) - - def testListcomps(self): - # list comprehension tests - nums = [1, 2, 3, 4, 5] - strs = ["Apple", "Banana", "Coconut"] - spcs = [" Apple", " Banana ", "Coco nut "] - - self.assertEqual([s.strip() for s in spcs], ['Apple', 'Banana', 'Coco nut']) - self.assertEqual([3 * x for x in nums], [3, 6, 9, 12, 15]) - self.assertEqual([x for x in nums if x > 2], [3, 4, 5]) - self.assertEqual([(i, s) for i in nums for s in strs], - [(1, 'Apple'), (1, 'Banana'), (1, 'Coconut'), - (2, 'Apple'), (2, 'Banana'), (2, 'Coconut'), - (3, 'Apple'), (3, 'Banana'), (3, 'Coconut'), - (4, 'Apple'), (4, 'Banana'), (4, 'Coconut'), - (5, 'Apple'), (5, 'Banana'), (5, 'Coconut')]) - self.assertEqual([(i, s) for i in nums for s in [f for f in strs if "n" in f]], - [(1, 'Banana'), (1, 'Coconut'), (2, 'Banana'), (2, 'Coconut'), - (3, 'Banana'), (3, 'Coconut'), (4, 'Banana'), (4, 'Coconut'), - (5, 'Banana'), (5, 'Coconut')]) - self.assertEqual([(lambda a:[a**i for i in range(a+1)])(j) for j in range(5)], - [[1], [1, 1], [1, 2, 4], [1, 3, 9, 27], [1, 4, 16, 64, 256]]) - - def test_in_func(l): - return [None < x < 3 for x in l if x > 2] - - self.assertEqual(test_in_func(nums), [False, False, False]) - - def test_nested_front(): - self.assertEqual([[y for y in [x, x + 1]] for x in [1,3,5]], - [[1, 2], [3, 4], [5, 6]]) - - test_nested_front() - - check_syntax_error(self, "[i, s for i in nums for s in strs]") - check_syntax_error(self, "[x if y]") - - suppliers = [ - (1, "Boeing"), - (2, "Ford"), - (3, "Macdonalds") - ] - - parts = [ - (10, "Airliner"), - (20, "Engine"), - (30, "Cheeseburger") - ] - - suppart = [ - (1, 10), (1, 20), (2, 20), (3, 30) - ] - - x = [ - (sname, pname) - for (sno, sname) in suppliers - for (pno, pname) in parts - for (sp_sno, sp_pno) in suppart - if sno == sp_sno and pno == sp_pno - ] - - self.assertEqual(x, [('Boeing', 'Airliner'), ('Boeing', 'Engine'), ('Ford', 'Engine'), - ('Macdonalds', 'Cheeseburger')]) - - def testGenexps(self): - # generator expression tests - g = ([x for x in range(10)] for x in range(1)) - self.assertEqual(g.next(), [x for x in range(10)]) - try: - g.next() - self.fail('should produce StopIteration exception') - except StopIteration: - pass - - a = 1 - try: - g = (a for d in a) - g.next() - self.fail('should produce TypeError') - except TypeError: - pass - - self.assertEqual(list((x, y) for x in 'abcd' for y in 'abcd'), [(x, y) for x in 'abcd' for y in 'abcd']) - self.assertEqual(list((x, y) for x in 'ab' for y in 'xy'), [(x, y) for x in 'ab' for y in 'xy']) - - a = [x for x in range(10)] - b = (x for x in (y for y in a)) - self.assertEqual(sum(b), sum([x for x in range(10)])) - - self.assertEqual(sum(x**2 for x in range(10)), sum([x**2 for x in range(10)])) - self.assertEqual(sum(x*x for x in range(10) if x%2), sum([x*x for x in range(10) if x%2])) - self.assertEqual(sum(x for x in (y for y in range(10))), sum([x for x in range(10)])) - self.assertEqual(sum(x for x in (y for y in (z for z in range(10)))), sum([x for x in range(10)])) - self.assertEqual(sum(x for x in [y for y in (z for z in range(10))]), sum([x for x in range(10)])) - self.assertEqual(sum(x for x in (y for y in (z for z in range(10) if True)) if True), sum([x for x in range(10)])) - self.assertEqual(sum(x for x in (y for y in (z for z in range(10) if True) if False) if True), 0) - check_syntax_error(self, "foo(x for x in range(10), 100)") - check_syntax_error(self, "foo(100, x for x in range(10))") - - def testComprehensionSpecials(self): - # test for outmost iterable precomputation - x = 10; g = (i for i in range(x)); x = 5 - self.assertEqual(len(list(g)), 10) - - # This should hold, since we're only precomputing outmost iterable. - x = 10; t = False; g = ((i,j) for i in range(x) if t for j in range(x)) - x = 5; t = True; - self.assertEqual([(i,j) for i in range(10) for j in range(5)], list(g)) - - # Grammar allows multiple adjacent 'if's in listcomps and genexps, - # even though it's silly. Make sure it works (ifelse broke this.) - self.assertEqual([ x for x in range(10) if x % 2 if x % 3 ], [1, 5, 7]) - self.assertEqual(list(x for x in range(10) if x % 2 if x % 3), [1, 5, 7]) - - # verify unpacking single element tuples in listcomp/genexp. - self.assertEqual([x for x, in [(4,), (5,), (6,)]], [4, 5, 6]) - self.assertEqual(list(x for x, in [(7,), (8,), (9,)]), [7, 8, 9]) - - def test_with_statement(self): - class manager(object): - def __enter__(self): - return (1, 2) - def __exit__(self, *args): - pass - - with manager(): - pass - with manager() as x: - pass - with manager() as (x, y): - pass - with manager(), manager(): - pass - with manager() as x, manager() as y: - pass - with manager() as x, manager(): - pass - - def testIfElseExpr(self): - # Test ifelse expressions in various cases - def _checkeval(msg, ret): - "helper to check that evaluation of expressions is done correctly" - print x - return ret - - self.assertEqual([ x() for x in lambda: True, lambda: False if x() ], [True]) - self.assertEqual([ x() for x in (lambda: True, lambda: False) if x() ], [True]) - self.assertEqual([ x(False) for x in (lambda x: False if x else True, lambda x: True if x else False) if x(False) ], [True]) - self.assertEqual((5 if 1 else _checkeval("check 1", 0)), 5) - self.assertEqual((_checkeval("check 2", 0) if 0 else 5), 5) - self.assertEqual((5 and 6 if 0 else 1), 1) - self.assertEqual(((5 and 6) if 0 else 1), 1) - self.assertEqual((5 and (6 if 1 else 1)), 6) - self.assertEqual((0 or _checkeval("check 3", 2) if 0 else 3), 3) - self.assertEqual((1 or _checkeval("check 4", 2) if 1 else _checkeval("check 5", 3)), 1) - self.assertEqual((0 or 5 if 1 else _checkeval("check 6", 3)), 5) - self.assertEqual((not 5 if 1 else 1), False) - self.assertEqual((not 5 if 0 else 1), 1) - self.assertEqual((6 + 1 if 1 else 2), 7) - self.assertEqual((6 - 1 if 1 else 2), 5) - self.assertEqual((6 * 2 if 1 else 4), 12) - self.assertEqual((6 / 2 if 1 else 3), 3) - self.assertEqual((6 < 4 if 0 else 2), 2) - - -def test_main(): - run_unittest(TokenTests, GrammarTests) - -if __name__ == '__main__': - test_main() diff --git a/PythonLib/extra/lib2to3/tests/data/py3_test_grammar.py b/PythonLib/extra/lib2to3/tests/data/py3_test_grammar.py deleted file mode 100644 index c0bf7f27..00000000 --- a/PythonLib/extra/lib2to3/tests/data/py3_test_grammar.py +++ /dev/null @@ -1,923 +0,0 @@ -# Python test set -- part 1, grammar. -# This just tests whether the parser accepts them all. - -# NOTE: When you run this test as a script from the command line, you -# get warnings about certain hex/oct constants. Since those are -# issued by the parser, you can't suppress them by adding a -# filterwarnings() call to this module. Therefore, to shut up the -# regression test, the filterwarnings() call has been added to -# regrtest.py. - -from test.support import run_unittest, check_syntax_error -import unittest -import sys -# testing import * -from sys import * - -class TokenTests(unittest.TestCase): - - def testBackslash(self): - # Backslash means line continuation: - x = 1 \ - + 1 - self.assertEquals(x, 2, 'backslash for line continuation') - - # Backslash does not means continuation in comments :\ - x = 0 - self.assertEquals(x, 0, 'backslash ending comment') - - def testPlainIntegers(self): - self.assertEquals(type(000), type(0)) - self.assertEquals(0xff, 255) - self.assertEquals(0o377, 255) - self.assertEquals(2147483647, 0o17777777777) - self.assertEquals(0b1001, 9) - # "0x" is not a valid literal - self.assertRaises(SyntaxError, eval, "0x") - from sys import maxsize - if maxsize == 2147483647: - self.assertEquals(-2147483647-1, -0o20000000000) - # XXX -2147483648 - self.assert_(0o37777777777 > 0) - self.assert_(0xffffffff > 0) - self.assert_(0b1111111111111111111111111111111 > 0) - for s in ('2147483648', '0o40000000000', '0x100000000', - '0b10000000000000000000000000000000'): - try: - x = eval(s) - except OverflowError: - self.fail("OverflowError on huge integer literal %r" % s) - elif maxsize == 9223372036854775807: - self.assertEquals(-9223372036854775807-1, -0o1000000000000000000000) - self.assert_(0o1777777777777777777777 > 0) - self.assert_(0xffffffffffffffff > 0) - self.assert_(0b11111111111111111111111111111111111111111111111111111111111111 > 0) - for s in '9223372036854775808', '0o2000000000000000000000', \ - '0x10000000000000000', \ - '0b100000000000000000000000000000000000000000000000000000000000000': - try: - x = eval(s) - except OverflowError: - self.fail("OverflowError on huge integer literal %r" % s) - else: - self.fail('Weird maxsize value %r' % maxsize) - - def testLongIntegers(self): - x = 0 - x = 0xffffffffffffffff - x = 0Xffffffffffffffff - x = 0o77777777777777777 - x = 0O77777777777777777 - x = 123456789012345678901234567890 - x = 0b100000000000000000000000000000000000000000000000000000000000000000000 - x = 0B111111111111111111111111111111111111111111111111111111111111111111111 - - def testFloats(self): - x = 3.14 - x = 314. - x = 0.314 - # XXX x = 000.314 - x = .314 - x = 3e14 - x = 3E14 - x = 3e-14 - x = 3e+14 - x = 3.e14 - x = .3e14 - x = 3.1e4 - - def testStringLiterals(self): - x = ''; y = ""; self.assert_(len(x) == 0 and x == y) - x = '\''; y = "'"; self.assert_(len(x) == 1 and x == y and ord(x) == 39) - x = '"'; y = "\""; self.assert_(len(x) == 1 and x == y and ord(x) == 34) - x = "doesn't \"shrink\" does it" - y = 'doesn\'t "shrink" does it' - self.assert_(len(x) == 24 and x == y) - x = "does \"shrink\" doesn't it" - y = 'does "shrink" doesn\'t it' - self.assert_(len(x) == 24 and x == y) - x = """ -The "quick" -brown fox -jumps over -the 'lazy' dog. -""" - y = '\nThe "quick"\nbrown fox\njumps over\nthe \'lazy\' dog.\n' - self.assertEquals(x, y) - y = ''' -The "quick" -brown fox -jumps over -the 'lazy' dog. -''' - self.assertEquals(x, y) - y = "\n\ -The \"quick\"\n\ -brown fox\n\ -jumps over\n\ -the 'lazy' dog.\n\ -" - self.assertEquals(x, y) - y = '\n\ -The \"quick\"\n\ -brown fox\n\ -jumps over\n\ -the \'lazy\' dog.\n\ -' - self.assertEquals(x, y) - - def testEllipsis(self): - x = ... - self.assert_(x is Ellipsis) - self.assertRaises(SyntaxError, eval, ".. .") - -class GrammarTests(unittest.TestCase): - - # single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE - # XXX can't test in a script -- this rule is only used when interactive - - # file_input: (NEWLINE | stmt)* ENDMARKER - # Being tested as this very moment this very module - - # expr_input: testlist NEWLINE - # XXX Hard to test -- used only in calls to input() - - def testEvalInput(self): - # testlist ENDMARKER - x = eval('1, 0 or 1') - - def testFuncdef(self): - ### [decorators] 'def' NAME parameters ['->' test] ':' suite - ### decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE - ### decorators: decorator+ - ### parameters: '(' [typedargslist] ')' - ### typedargslist: ((tfpdef ['=' test] ',')* - ### ('*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef] | '**' tfpdef) - ### | tfpdef ['=' test] (',' tfpdef ['=' test])* [',']) - ### tfpdef: NAME [':' test] - ### varargslist: ((vfpdef ['=' test] ',')* - ### ('*' [vfpdef] (',' vfpdef ['=' test])* [',' '**' vfpdef] | '**' vfpdef) - ### | vfpdef ['=' test] (',' vfpdef ['=' test])* [',']) - ### vfpdef: NAME - def f1(): pass - f1() - f1(*()) - f1(*(), **{}) - def f2(one_argument): pass - def f3(two, arguments): pass - self.assertEquals(f2.__code__.co_varnames, ('one_argument',)) - self.assertEquals(f3.__code__.co_varnames, ('two', 'arguments')) - def a1(one_arg,): pass - def a2(two, args,): pass - def v0(*rest): pass - def v1(a, *rest): pass - def v2(a, b, *rest): pass - - f1() - f2(1) - f2(1,) - f3(1, 2) - f3(1, 2,) - v0() - v0(1) - v0(1,) - v0(1,2) - v0(1,2,3,4,5,6,7,8,9,0) - v1(1) - v1(1,) - v1(1,2) - v1(1,2,3) - v1(1,2,3,4,5,6,7,8,9,0) - v2(1,2) - v2(1,2,3) - v2(1,2,3,4) - v2(1,2,3,4,5,6,7,8,9,0) - - def d01(a=1): pass - d01() - d01(1) - d01(*(1,)) - d01(**{'a':2}) - def d11(a, b=1): pass - d11(1) - d11(1, 2) - d11(1, **{'b':2}) - def d21(a, b, c=1): pass - d21(1, 2) - d21(1, 2, 3) - d21(*(1, 2, 3)) - d21(1, *(2, 3)) - d21(1, 2, *(3,)) - d21(1, 2, **{'c':3}) - def d02(a=1, b=2): pass - d02() - d02(1) - d02(1, 2) - d02(*(1, 2)) - d02(1, *(2,)) - d02(1, **{'b':2}) - d02(**{'a': 1, 'b': 2}) - def d12(a, b=1, c=2): pass - d12(1) - d12(1, 2) - d12(1, 2, 3) - def d22(a, b, c=1, d=2): pass - d22(1, 2) - d22(1, 2, 3) - d22(1, 2, 3, 4) - def d01v(a=1, *rest): pass - d01v() - d01v(1) - d01v(1, 2) - d01v(*(1, 2, 3, 4)) - d01v(*(1,)) - d01v(**{'a':2}) - def d11v(a, b=1, *rest): pass - d11v(1) - d11v(1, 2) - d11v(1, 2, 3) - def d21v(a, b, c=1, *rest): pass - d21v(1, 2) - d21v(1, 2, 3) - d21v(1, 2, 3, 4) - d21v(*(1, 2, 3, 4)) - d21v(1, 2, **{'c': 3}) - def d02v(a=1, b=2, *rest): pass - d02v() - d02v(1) - d02v(1, 2) - d02v(1, 2, 3) - d02v(1, *(2, 3, 4)) - d02v(**{'a': 1, 'b': 2}) - def d12v(a, b=1, c=2, *rest): pass - d12v(1) - d12v(1, 2) - d12v(1, 2, 3) - d12v(1, 2, 3, 4) - d12v(*(1, 2, 3, 4)) - d12v(1, 2, *(3, 4, 5)) - d12v(1, *(2,), **{'c': 3}) - def d22v(a, b, c=1, d=2, *rest): pass - d22v(1, 2) - d22v(1, 2, 3) - d22v(1, 2, 3, 4) - d22v(1, 2, 3, 4, 5) - d22v(*(1, 2, 3, 4)) - d22v(1, 2, *(3, 4, 5)) - d22v(1, *(2, 3), **{'d': 4}) - - # keyword argument type tests - try: - str('x', **{b'foo':1 }) - except TypeError: - pass - else: - self.fail('Bytes should not work as keyword argument names') - # keyword only argument tests - def pos0key1(*, key): return key - pos0key1(key=100) - def pos2key2(p1, p2, *, k1, k2=100): return p1,p2,k1,k2 - pos2key2(1, 2, k1=100) - pos2key2(1, 2, k1=100, k2=200) - pos2key2(1, 2, k2=100, k1=200) - def pos2key2dict(p1, p2, *, k1=100, k2, **kwarg): return p1,p2,k1,k2,kwarg - pos2key2dict(1,2,k2=100,tokwarg1=100,tokwarg2=200) - pos2key2dict(1,2,tokwarg1=100,tokwarg2=200, k2=100) - - # keyword arguments after *arglist - def f(*args, **kwargs): - return args, kwargs - self.assertEquals(f(1, x=2, *[3, 4], y=5), ((1, 3, 4), - {'x':2, 'y':5})) - self.assertRaises(SyntaxError, eval, "f(1, *(2,3), 4)") - self.assertRaises(SyntaxError, eval, "f(1, x=2, *(3,4), x=5)") - - # argument annotation tests - def f(x) -> list: pass - self.assertEquals(f.__annotations__, {'return': list}) - def f(x:int): pass - self.assertEquals(f.__annotations__, {'x': int}) - def f(*x:str): pass - self.assertEquals(f.__annotations__, {'x': str}) - def f(**x:float): pass - self.assertEquals(f.__annotations__, {'x': float}) - def f(x, y:1+2): pass - self.assertEquals(f.__annotations__, {'y': 3}) - def f(a, b:1, c:2, d): pass - self.assertEquals(f.__annotations__, {'b': 1, 'c': 2}) - def f(a, b:1, c:2, d, e:3=4, f=5, *g:6): pass - self.assertEquals(f.__annotations__, - {'b': 1, 'c': 2, 'e': 3, 'g': 6}) - def f(a, b:1, c:2, d, e:3=4, f=5, *g:6, h:7, i=8, j:9=10, - **k:11) -> 12: pass - self.assertEquals(f.__annotations__, - {'b': 1, 'c': 2, 'e': 3, 'g': 6, 'h': 7, 'j': 9, - 'k': 11, 'return': 12}) - # Check for SF Bug #1697248 - mixing decorators and a return annotation - def null(x): return x - @null - def f(x) -> list: pass - self.assertEquals(f.__annotations__, {'return': list}) - - # test MAKE_CLOSURE with a variety of oparg's - closure = 1 - def f(): return closure - def f(x=1): return closure - def f(*, k=1): return closure - def f() -> int: return closure - - # Check ast errors in *args and *kwargs - check_syntax_error(self, "f(*g(1=2))") - check_syntax_error(self, "f(**g(1=2))") - - def testLambdef(self): - ### lambdef: 'lambda' [varargslist] ':' test - l1 = lambda : 0 - self.assertEquals(l1(), 0) - l2 = lambda : a[d] # XXX just testing the expression - l3 = lambda : [2 < x for x in [-1, 3, 0]] - self.assertEquals(l3(), [0, 1, 0]) - l4 = lambda x = lambda y = lambda z=1 : z : y() : x() - self.assertEquals(l4(), 1) - l5 = lambda x, y, z=2: x + y + z - self.assertEquals(l5(1, 2), 5) - self.assertEquals(l5(1, 2, 3), 6) - check_syntax_error(self, "lambda x: x = 2") - check_syntax_error(self, "lambda (None,): None") - l6 = lambda x, y, *, k=20: x+y+k - self.assertEquals(l6(1,2), 1+2+20) - self.assertEquals(l6(1,2,k=10), 1+2+10) - - - ### stmt: simple_stmt | compound_stmt - # Tested below - - def testSimpleStmt(self): - ### simple_stmt: small_stmt (';' small_stmt)* [';'] - x = 1; pass; del x - def foo(): - # verify statements that end with semi-colons - x = 1; pass; del x; - foo() - - ### small_stmt: expr_stmt | pass_stmt | del_stmt | flow_stmt | import_stmt | global_stmt | access_stmt - # Tested below - - def testExprStmt(self): - # (exprlist '=')* exprlist - 1 - 1, 2, 3 - x = 1 - x = 1, 2, 3 - x = y = z = 1, 2, 3 - x, y, z = 1, 2, 3 - abc = a, b, c = x, y, z = xyz = 1, 2, (3, 4) - - check_syntax_error(self, "x + 1 = 1") - check_syntax_error(self, "a + 1 = b + 2") - - def testDelStmt(self): - # 'del' exprlist - abc = [1,2,3] - x, y, z = abc - xyz = x, y, z - - del abc - del x, y, (z, xyz) - - def testPassStmt(self): - # 'pass' - pass - - # flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt - # Tested below - - def testBreakStmt(self): - # 'break' - while 1: break - - def testContinueStmt(self): - # 'continue' - i = 1 - while i: i = 0; continue - - msg = "" - while not msg: - msg = "ok" - try: - continue - msg = "continue failed to continue inside try" - except: - msg = "continue inside try called except block" - if msg != "ok": - self.fail(msg) - - msg = "" - while not msg: - msg = "finally block not called" - try: - continue - finally: - msg = "ok" - if msg != "ok": - self.fail(msg) - - def test_break_continue_loop(self): - # This test warrants an explanation. It is a test specifically for SF bugs - # #463359 and #462937. The bug is that a 'break' statement executed or - # exception raised inside a try/except inside a loop, *after* a continue - # statement has been executed in that loop, will cause the wrong number of - # arguments to be popped off the stack and the instruction pointer reset to - # a very small number (usually 0.) Because of this, the following test - # *must* written as a function, and the tracking vars *must* be function - # arguments with default values. Otherwise, the test will loop and loop. - - def test_inner(extra_burning_oil = 1, count=0): - big_hippo = 2 - while big_hippo: - count += 1 - try: - if extra_burning_oil and big_hippo == 1: - extra_burning_oil -= 1 - break - big_hippo -= 1 - continue - except: - raise - if count > 2 or big_hippo != 1: - self.fail("continue then break in try/except in loop broken!") - test_inner() - - def testReturn(self): - # 'return' [testlist] - def g1(): return - def g2(): return 1 - g1() - x = g2() - check_syntax_error(self, "class foo:return 1") - - def testYield(self): - check_syntax_error(self, "class foo:yield 1") - - def testRaise(self): - # 'raise' test [',' test] - try: raise RuntimeError('just testing') - except RuntimeError: pass - try: raise KeyboardInterrupt - except KeyboardInterrupt: pass - - def testImport(self): - # 'import' dotted_as_names - import sys - import time, sys - # 'from' dotted_name 'import' ('*' | '(' import_as_names ')' | import_as_names) - from time import time - from time import (time) - # not testable inside a function, but already done at top of the module - # from sys import * - from sys import path, argv - from sys import (path, argv) - from sys import (path, argv,) - - def testGlobal(self): - # 'global' NAME (',' NAME)* - global a - global a, b - global one, two, three, four, five, six, seven, eight, nine, ten - - def testNonlocal(self): - # 'nonlocal' NAME (',' NAME)* - x = 0 - y = 0 - def f(): - nonlocal x - nonlocal x, y - - def testAssert(self): - # assert_stmt: 'assert' test [',' test] - assert 1 - assert 1, 1 - assert lambda x:x - assert 1, lambda x:x+1 - try: - assert 0, "msg" - except AssertionError as e: - self.assertEquals(e.args[0], "msg") - else: - if __debug__: - self.fail("AssertionError not raised by assert 0") - - ### compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef - # Tested below - - def testIf(self): - # 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] - if 1: pass - if 1: pass - else: pass - if 0: pass - elif 0: pass - if 0: pass - elif 0: pass - elif 0: pass - elif 0: pass - else: pass - - def testWhile(self): - # 'while' test ':' suite ['else' ':' suite] - while 0: pass - while 0: pass - else: pass - - # Issue1920: "while 0" is optimized away, - # ensure that the "else" clause is still present. - x = 0 - while 0: - x = 1 - else: - x = 2 - self.assertEquals(x, 2) - - def testFor(self): - # 'for' exprlist 'in' exprlist ':' suite ['else' ':' suite] - for i in 1, 2, 3: pass - for i, j, k in (): pass - else: pass - class Squares: - def __init__(self, max): - self.max = max - self.sofar = [] - def __len__(self): return len(self.sofar) - def __getitem__(self, i): - if not 0 <= i < self.max: raise IndexError - n = len(self.sofar) - while n <= i: - self.sofar.append(n*n) - n = n+1 - return self.sofar[i] - n = 0 - for x in Squares(10): n = n+x - if n != 285: - self.fail('for over growing sequence') - - result = [] - for x, in [(1,), (2,), (3,)]: - result.append(x) - self.assertEqual(result, [1, 2, 3]) - - def testTry(self): - ### try_stmt: 'try' ':' suite (except_clause ':' suite)+ ['else' ':' suite] - ### | 'try' ':' suite 'finally' ':' suite - ### except_clause: 'except' [expr ['as' expr]] - try: - 1/0 - except ZeroDivisionError: - pass - else: - pass - try: 1/0 - except EOFError: pass - except TypeError as msg: pass - except RuntimeError as msg: pass - except: pass - else: pass - try: 1/0 - except (EOFError, TypeError, ZeroDivisionError): pass - try: 1/0 - except (EOFError, TypeError, ZeroDivisionError) as msg: pass - try: pass - finally: pass - - def testSuite(self): - # simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT - if 1: pass - if 1: - pass - if 1: - # - # - # - pass - pass - # - pass - # - - def testTest(self): - ### and_test ('or' and_test)* - ### and_test: not_test ('and' not_test)* - ### not_test: 'not' not_test | comparison - if not 1: pass - if 1 and 1: pass - if 1 or 1: pass - if not not not 1: pass - if not 1 and 1 and 1: pass - if 1 and 1 or 1 and 1 and 1 or not 1 and 1: pass - - def testComparison(self): - ### comparison: expr (comp_op expr)* - ### comp_op: '<'|'>'|'=='|'>='|'<='|'!='|'in'|'not' 'in'|'is'|'is' 'not' - if 1: pass - x = (1 == 1) - if 1 == 1: pass - if 1 != 1: pass - if 1 < 1: pass - if 1 > 1: pass - if 1 <= 1: pass - if 1 >= 1: pass - if 1 is 1: pass - if 1 is not 1: pass - if 1 in (): pass - if 1 not in (): pass - if 1 < 1 > 1 == 1 >= 1 <= 1 != 1 in 1 not in 1 is 1 is not 1: pass - - def testBinaryMaskOps(self): - x = 1 & 1 - x = 1 ^ 1 - x = 1 | 1 - - def testShiftOps(self): - x = 1 << 1 - x = 1 >> 1 - x = 1 << 1 >> 1 - - def testAdditiveOps(self): - x = 1 - x = 1 + 1 - x = 1 - 1 - 1 - x = 1 - 1 + 1 - 1 + 1 - - def testMultiplicativeOps(self): - x = 1 * 1 - x = 1 / 1 - x = 1 % 1 - x = 1 / 1 * 1 % 1 - - def testUnaryOps(self): - x = +1 - x = -1 - x = ~1 - x = ~1 ^ 1 & 1 | 1 & 1 ^ -1 - x = -1*1/1 + 1*1 - ---1*1 - - def testSelectors(self): - ### trailer: '(' [testlist] ')' | '[' subscript ']' | '.' NAME - ### subscript: expr | [expr] ':' [expr] - - import sys, time - c = sys.path[0] - x = time.time() - x = sys.modules['time'].time() - a = '01234' - c = a[0] - c = a[-1] - s = a[0:5] - s = a[:5] - s = a[0:] - s = a[:] - s = a[-5:] - s = a[:-1] - s = a[-4:-3] - # A rough test of SF bug 1333982. http://python.org/sf/1333982 - # The testing here is fairly incomplete. - # Test cases should include: commas with 1 and 2 colons - d = {} - d[1] = 1 - d[1,] = 2 - d[1,2] = 3 - d[1,2,3] = 4 - L = list(d) - L.sort(key=lambda x: x if isinstance(x, tuple) else ()) - self.assertEquals(str(L), '[1, (1,), (1, 2), (1, 2, 3)]') - - def testAtoms(self): - ### atom: '(' [testlist] ')' | '[' [testlist] ']' | '{' [dictsetmaker] '}' | NAME | NUMBER | STRING - ### dictsetmaker: (test ':' test (',' test ':' test)* [',']) | (test (',' test)* [',']) - - x = (1) - x = (1 or 2 or 3) - x = (1 or 2 or 3, 2, 3) - - x = [] - x = [1] - x = [1 or 2 or 3] - x = [1 or 2 or 3, 2, 3] - x = [] - - x = {} - x = {'one': 1} - x = {'one': 1,} - x = {'one' or 'two': 1 or 2} - x = {'one': 1, 'two': 2} - x = {'one': 1, 'two': 2,} - x = {'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6} - - x = {'one'} - x = {'one', 1,} - x = {'one', 'two', 'three'} - x = {2, 3, 4,} - - x = x - x = 'x' - x = 123 - - ### exprlist: expr (',' expr)* [','] - ### testlist: test (',' test)* [','] - # These have been exercised enough above - - def testClassdef(self): - # 'class' NAME ['(' [testlist] ')'] ':' suite - class B: pass - class B2(): pass - class C1(B): pass - class C2(B): pass - class D(C1, C2, B): pass - class C: - def meth1(self): pass - def meth2(self, arg): pass - def meth3(self, a1, a2): pass - - # decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE - # decorators: decorator+ - # decorated: decorators (classdef | funcdef) - def class_decorator(x): return x - @class_decorator - class G: pass - - def testDictcomps(self): - # dictorsetmaker: ( (test ':' test (comp_for | - # (',' test ':' test)* [','])) | - # (test (comp_for | (',' test)* [','])) ) - nums = [1, 2, 3] - self.assertEqual({i:i+1 for i in nums}, {1: 2, 2: 3, 3: 4}) - - def testListcomps(self): - # list comprehension tests - nums = [1, 2, 3, 4, 5] - strs = ["Apple", "Banana", "Coconut"] - spcs = [" Apple", " Banana ", "Coco nut "] - - self.assertEqual([s.strip() for s in spcs], ['Apple', 'Banana', 'Coco nut']) - self.assertEqual([3 * x for x in nums], [3, 6, 9, 12, 15]) - self.assertEqual([x for x in nums if x > 2], [3, 4, 5]) - self.assertEqual([(i, s) for i in nums for s in strs], - [(1, 'Apple'), (1, 'Banana'), (1, 'Coconut'), - (2, 'Apple'), (2, 'Banana'), (2, 'Coconut'), - (3, 'Apple'), (3, 'Banana'), (3, 'Coconut'), - (4, 'Apple'), (4, 'Banana'), (4, 'Coconut'), - (5, 'Apple'), (5, 'Banana'), (5, 'Coconut')]) - self.assertEqual([(i, s) for i in nums for s in [f for f in strs if "n" in f]], - [(1, 'Banana'), (1, 'Coconut'), (2, 'Banana'), (2, 'Coconut'), - (3, 'Banana'), (3, 'Coconut'), (4, 'Banana'), (4, 'Coconut'), - (5, 'Banana'), (5, 'Coconut')]) - self.assertEqual([(lambda a:[a**i for i in range(a+1)])(j) for j in range(5)], - [[1], [1, 1], [1, 2, 4], [1, 3, 9, 27], [1, 4, 16, 64, 256]]) - - def test_in_func(l): - return [0 < x < 3 for x in l if x > 2] - - self.assertEqual(test_in_func(nums), [False, False, False]) - - def test_nested_front(): - self.assertEqual([[y for y in [x, x + 1]] for x in [1,3,5]], - [[1, 2], [3, 4], [5, 6]]) - - test_nested_front() - - check_syntax_error(self, "[i, s for i in nums for s in strs]") - check_syntax_error(self, "[x if y]") - - suppliers = [ - (1, "Boeing"), - (2, "Ford"), - (3, "Macdonalds") - ] - - parts = [ - (10, "Airliner"), - (20, "Engine"), - (30, "Cheeseburger") - ] - - suppart = [ - (1, 10), (1, 20), (2, 20), (3, 30) - ] - - x = [ - (sname, pname) - for (sno, sname) in suppliers - for (pno, pname) in parts - for (sp_sno, sp_pno) in suppart - if sno == sp_sno and pno == sp_pno - ] - - self.assertEqual(x, [('Boeing', 'Airliner'), ('Boeing', 'Engine'), ('Ford', 'Engine'), - ('Macdonalds', 'Cheeseburger')]) - - def testGenexps(self): - # generator expression tests - g = ([x for x in range(10)] for x in range(1)) - self.assertEqual(next(g), [x for x in range(10)]) - try: - next(g) - self.fail('should produce StopIteration exception') - except StopIteration: - pass - - a = 1 - try: - g = (a for d in a) - next(g) - self.fail('should produce TypeError') - except TypeError: - pass - - self.assertEqual(list((x, y) for x in 'abcd' for y in 'abcd'), [(x, y) for x in 'abcd' for y in 'abcd']) - self.assertEqual(list((x, y) for x in 'ab' for y in 'xy'), [(x, y) for x in 'ab' for y in 'xy']) - - a = [x for x in range(10)] - b = (x for x in (y for y in a)) - self.assertEqual(sum(b), sum([x for x in range(10)])) - - self.assertEqual(sum(x**2 for x in range(10)), sum([x**2 for x in range(10)])) - self.assertEqual(sum(x*x for x in range(10) if x%2), sum([x*x for x in range(10) if x%2])) - self.assertEqual(sum(x for x in (y for y in range(10))), sum([x for x in range(10)])) - self.assertEqual(sum(x for x in (y for y in (z for z in range(10)))), sum([x for x in range(10)])) - self.assertEqual(sum(x for x in [y for y in (z for z in range(10))]), sum([x for x in range(10)])) - self.assertEqual(sum(x for x in (y for y in (z for z in range(10) if True)) if True), sum([x for x in range(10)])) - self.assertEqual(sum(x for x in (y for y in (z for z in range(10) if True) if False) if True), 0) - check_syntax_error(self, "foo(x for x in range(10), 100)") - check_syntax_error(self, "foo(100, x for x in range(10))") - - def testComprehensionSpecials(self): - # test for outmost iterable precomputation - x = 10; g = (i for i in range(x)); x = 5 - self.assertEqual(len(list(g)), 10) - - # This should hold, since we're only precomputing outmost iterable. - x = 10; t = False; g = ((i,j) for i in range(x) if t for j in range(x)) - x = 5; t = True; - self.assertEqual([(i,j) for i in range(10) for j in range(5)], list(g)) - - # Grammar allows multiple adjacent 'if's in listcomps and genexps, - # even though it's silly. Make sure it works (ifelse broke this.) - self.assertEqual([ x for x in range(10) if x % 2 if x % 3 ], [1, 5, 7]) - self.assertEqual(list(x for x in range(10) if x % 2 if x % 3), [1, 5, 7]) - - # verify unpacking single element tuples in listcomp/genexp. - self.assertEqual([x for x, in [(4,), (5,), (6,)]], [4, 5, 6]) - self.assertEqual(list(x for x, in [(7,), (8,), (9,)]), [7, 8, 9]) - - def test_with_statement(self): - class manager(object): - def __enter__(self): - return (1, 2) - def __exit__(self, *args): - pass - - with manager(): - pass - with manager() as x: - pass - with manager() as (x, y): - pass - with manager(), manager(): - pass - with manager() as x, manager() as y: - pass - with manager() as x, manager(): - pass - - def testIfElseExpr(self): - # Test ifelse expressions in various cases - def _checkeval(msg, ret): - "helper to check that evaluation of expressions is done correctly" - print(x) - return ret - - # the next line is not allowed anymore - #self.assertEqual([ x() for x in lambda: True, lambda: False if x() ], [True]) - self.assertEqual([ x() for x in (lambda: True, lambda: False) if x() ], [True]) - self.assertEqual([ x(False) for x in (lambda x: False if x else True, lambda x: True if x else False) if x(False) ], [True]) - self.assertEqual((5 if 1 else _checkeval("check 1", 0)), 5) - self.assertEqual((_checkeval("check 2", 0) if 0 else 5), 5) - self.assertEqual((5 and 6 if 0 else 1), 1) - self.assertEqual(((5 and 6) if 0 else 1), 1) - self.assertEqual((5 and (6 if 1 else 1)), 6) - self.assertEqual((0 or _checkeval("check 3", 2) if 0 else 3), 3) - self.assertEqual((1 or _checkeval("check 4", 2) if 1 else _checkeval("check 5", 3)), 1) - self.assertEqual((0 or 5 if 1 else _checkeval("check 6", 3)), 5) - self.assertEqual((not 5 if 1 else 1), False) - self.assertEqual((not 5 if 0 else 1), 1) - self.assertEqual((6 + 1 if 1 else 2), 7) - self.assertEqual((6 - 1 if 1 else 2), 5) - self.assertEqual((6 * 2 if 1 else 4), 12) - self.assertEqual((6 / 2 if 1 else 3), 3) - self.assertEqual((6 < 4 if 0 else 2), 2) - - -def test_main(): - run_unittest(TokenTests, GrammarTests) - -if __name__ == '__main__': - test_main() diff --git a/PythonLib/extra/lib2to3/tests/pytree_idempotency.py b/PythonLib/extra/lib2to3/tests/pytree_idempotency.py deleted file mode 100644 index 243f7e8e..00000000 --- a/PythonLib/extra/lib2to3/tests/pytree_idempotency.py +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/env python -# Copyright 2006 Google, Inc. All Rights Reserved. -# Licensed to PSF under a Contributor Agreement. - -"""Main program for testing the infrastructure.""" - -__author__ = "Guido van Rossum " - -# Support imports (need to be imported first) -from . import support - -# Python imports -import os -import sys -import logging - -# Local imports -from .. import pytree -import pgen2 -from pgen2 import driver - -logging.basicConfig() - -def main(): - gr = driver.load_grammar("Grammar.txt") - dr = driver.Driver(gr, convert=pytree.convert) - - fn = "example.py" - tree = dr.parse_file(fn, debug=True) - if not diff(fn, tree): - print "No diffs." - if not sys.argv[1:]: - return # Pass a dummy argument to run the complete test suite below - - problems = [] - - # Process every imported module - for name in sys.modules: - mod = sys.modules[name] - if mod is None or not hasattr(mod, "__file__"): - continue - fn = mod.__file__ - if fn.endswith(".pyc"): - fn = fn[:-1] - if not fn.endswith(".py"): - continue - print >>sys.stderr, "Parsing", fn - tree = dr.parse_file(fn, debug=True) - if diff(fn, tree): - problems.append(fn) - - # Process every single module on sys.path (but not in packages) - for dir in sys.path: - try: - names = os.listdir(dir) - except os.error: - continue - print >>sys.stderr, "Scanning", dir, "..." - for name in names: - if not name.endswith(".py"): - continue - print >>sys.stderr, "Parsing", name - fn = os.path.join(dir, name) - try: - tree = dr.parse_file(fn, debug=True) - except pgen2.parse.ParseError, err: - print "ParseError:", err - else: - if diff(fn, tree): - problems.append(fn) - - # Show summary of problem files - if not problems: - print "No problems. Congratulations!" - else: - print "Problems in following files:" - for fn in problems: - print "***", fn - -def diff(fn, tree): - f = open("@", "w") - try: - f.write(str(tree)) - finally: - f.close() - try: - return os.system("diff -u %s @" % fn) - finally: - os.remove("@") - -if __name__ == "__main__": - main() diff --git a/PythonLib/extra/lib2to3/tests/support.py b/PythonLib/extra/lib2to3/tests/support.py deleted file mode 100644 index 36469351..00000000 --- a/PythonLib/extra/lib2to3/tests/support.py +++ /dev/null @@ -1,54 +0,0 @@ -"""Support code for test_*.py files""" -# Author: Collin Winter - -# Python imports -import unittest -import sys -import os -import os.path -import re -from textwrap import dedent - -# Local imports -from lib2to3 import pytree, refactor -from lib2to3.pgen2 import driver - -test_dir = os.path.dirname(__file__) -proj_dir = os.path.normpath(os.path.join(test_dir, "..")) -grammar_path = os.path.join(test_dir, "..", "Grammar.txt") -grammar = driver.load_grammar(grammar_path) -driver = driver.Driver(grammar, convert=pytree.convert) - -def parse_string(string): - return driver.parse_string(reformat(string), debug=True) - -def run_all_tests(test_mod=None, tests=None): - if tests is None: - tests = unittest.TestLoader().loadTestsFromModule(test_mod) - unittest.TextTestRunner(verbosity=2).run(tests) - -def reformat(string): - return dedent(string) + u"\n\n" - -def get_refactorer(fixer_pkg="lib2to3", fixers=None, options=None): - """ - A convenience function for creating a RefactoringTool for tests. - - fixers is a list of fixers for the RefactoringTool to use. By default - "lib2to3.fixes.*" is used. options is an optional dictionary of options to - be passed to the RefactoringTool. - """ - if fixers is not None: - fixers = [fixer_pkg + ".fixes.fix_" + fix for fix in fixers] - else: - fixers = refactor.get_fixers_from_package(fixer_pkg + ".fixes") - options = options or {} - return refactor.RefactoringTool(fixers, options, explicit=True) - -def all_project_files(): - for dirpath, dirnames, filenames in os.walk(proj_dir): - for filename in filenames: - if filename.endswith(".py"): - yield os.path.join(dirpath, filename) - -TestCase = unittest.TestCase diff --git a/PythonLib/extra/lib2to3/tests/test_all_fixers.py b/PythonLib/extra/lib2to3/tests/test_all_fixers.py deleted file mode 100644 index f64b3d94..00000000 --- a/PythonLib/extra/lib2to3/tests/test_all_fixers.py +++ /dev/null @@ -1,23 +0,0 @@ -"""Tests that run all fixer modules over an input stream. - -This has been broken out into its own test module because of its -running time. -""" -# Author: Collin Winter - -# Python imports -import unittest - -# Local imports -from lib2to3 import refactor -from . import support - - -class Test_all(support.TestCase): - - def setUp(self): - self.refactor = support.get_refactorer() - - def test_all_project_files(self): - for filepath in support.all_project_files(): - self.refactor.refactor_file(filepath) diff --git a/PythonLib/extra/lib2to3/tests/test_fixers.py b/PythonLib/extra/lib2to3/tests/test_fixers.py deleted file mode 100644 index 6801c170..00000000 --- a/PythonLib/extra/lib2to3/tests/test_fixers.py +++ /dev/null @@ -1,4578 +0,0 @@ -""" Test suite for the fixer modules """ - -# Python imports -import os -import unittest -from itertools import chain -from operator import itemgetter - -# Local imports -from lib2to3 import pygram, pytree, refactor, fixer_util -from lib2to3.tests import support - - -class FixerTestCase(support.TestCase): - - # Other test cases can subclass this class and replace "fixer_pkg" with - # their own. - def setUp(self, fix_list=None, fixer_pkg="lib2to3", options=None): - if fix_list is None: - fix_list = [self.fixer] - self.refactor = support.get_refactorer(fixer_pkg, fix_list, options) - self.fixer_log = [] - self.filename = u"" - - for fixer in chain(self.refactor.pre_order, - self.refactor.post_order): - fixer.log = self.fixer_log - - def _check(self, before, after): - before = support.reformat(before) - after = support.reformat(after) - tree = self.refactor.refactor_string(before, self.filename) - self.assertEqual(after, unicode(tree)) - return tree - - def check(self, before, after, ignore_warnings=False): - tree = self._check(before, after) - self.assertTrue(tree.was_changed) - if not ignore_warnings: - self.assertEqual(self.fixer_log, []) - - def warns(self, before, after, message, unchanged=False): - tree = self._check(before, after) - self.assertTrue(message in "".join(self.fixer_log)) - if not unchanged: - self.assertTrue(tree.was_changed) - - def warns_unchanged(self, before, message): - self.warns(before, before, message, unchanged=True) - - def unchanged(self, before, ignore_warnings=False): - self._check(before, before) - if not ignore_warnings: - self.assertEqual(self.fixer_log, []) - - def assert_runs_after(self, *names): - fixes = [self.fixer] - fixes.extend(names) - r = support.get_refactorer("lib2to3", fixes) - (pre, post) = r.get_fixers() - n = "fix_" + self.fixer - if post and post[-1].__class__.__module__.endswith(n): - # We're the last fixer to run - return - if pre and pre[-1].__class__.__module__.endswith(n) and not post: - # We're the last in pre and post is empty - return - self.fail("Fixer run order (%s) is incorrect; %s should be last."\ - %(", ".join([x.__class__.__module__ for x in (pre+post)]), n)) - -class Test_ne(FixerTestCase): - fixer = "ne" - - def test_basic(self): - b = """if x <> y: - pass""" - - a = """if x != y: - pass""" - self.check(b, a) - - def test_no_spaces(self): - b = """if x<>y: - pass""" - - a = """if x!=y: - pass""" - self.check(b, a) - - def test_chained(self): - b = """if x<>y<>z: - pass""" - - a = """if x!=y!=z: - pass""" - self.check(b, a) - -class Test_has_key(FixerTestCase): - fixer = "has_key" - - def test_1(self): - b = """x = d.has_key("x") or d.has_key("y")""" - a = """x = "x" in d or "y" in d""" - self.check(b, a) - - def test_2(self): - b = """x = a.b.c.d.has_key("x") ** 3""" - a = """x = ("x" in a.b.c.d) ** 3""" - self.check(b, a) - - def test_3(self): - b = """x = a.b.has_key(1 + 2).__repr__()""" - a = """x = (1 + 2 in a.b).__repr__()""" - self.check(b, a) - - def test_4(self): - b = """x = a.b.has_key(1 + 2).__repr__() ** -3 ** 4""" - a = """x = (1 + 2 in a.b).__repr__() ** -3 ** 4""" - self.check(b, a) - - def test_5(self): - b = """x = a.has_key(f or g)""" - a = """x = (f or g) in a""" - self.check(b, a) - - def test_6(self): - b = """x = a + b.has_key(c)""" - a = """x = a + (c in b)""" - self.check(b, a) - - def test_7(self): - b = """x = a.has_key(lambda: 12)""" - a = """x = (lambda: 12) in a""" - self.check(b, a) - - def test_8(self): - b = """x = a.has_key(a for a in b)""" - a = """x = (a for a in b) in a""" - self.check(b, a) - - def test_9(self): - b = """if not a.has_key(b): pass""" - a = """if b not in a: pass""" - self.check(b, a) - - def test_10(self): - b = """if not a.has_key(b).__repr__(): pass""" - a = """if not (b in a).__repr__(): pass""" - self.check(b, a) - - def test_11(self): - b = """if not a.has_key(b) ** 2: pass""" - a = """if not (b in a) ** 2: pass""" - self.check(b, a) - -class Test_apply(FixerTestCase): - fixer = "apply" - - def test_1(self): - b = """x = apply(f, g + h)""" - a = """x = f(*g + h)""" - self.check(b, a) - - def test_2(self): - b = """y = apply(f, g, h)""" - a = """y = f(*g, **h)""" - self.check(b, a) - - def test_3(self): - b = """z = apply(fs[0], g or h, h or g)""" - a = """z = fs[0](*g or h, **h or g)""" - self.check(b, a) - - def test_4(self): - b = """apply(f, (x, y) + t)""" - a = """f(*(x, y) + t)""" - self.check(b, a) - - def test_5(self): - b = """apply(f, args,)""" - a = """f(*args)""" - self.check(b, a) - - def test_6(self): - b = """apply(f, args, kwds,)""" - a = """f(*args, **kwds)""" - self.check(b, a) - - # Test that complex functions are parenthesized - - def test_complex_1(self): - b = """x = apply(f+g, args)""" - a = """x = (f+g)(*args)""" - self.check(b, a) - - def test_complex_2(self): - b = """x = apply(f*g, args)""" - a = """x = (f*g)(*args)""" - self.check(b, a) - - def test_complex_3(self): - b = """x = apply(f**g, args)""" - a = """x = (f**g)(*args)""" - self.check(b, a) - - # But dotted names etc. not - - def test_dotted_name(self): - b = """x = apply(f.g, args)""" - a = """x = f.g(*args)""" - self.check(b, a) - - def test_subscript(self): - b = """x = apply(f[x], args)""" - a = """x = f[x](*args)""" - self.check(b, a) - - def test_call(self): - b = """x = apply(f(), args)""" - a = """x = f()(*args)""" - self.check(b, a) - - # Extreme case - def test_extreme(self): - b = """x = apply(a.b.c.d.e.f, args, kwds)""" - a = """x = a.b.c.d.e.f(*args, **kwds)""" - self.check(b, a) - - # XXX Comments in weird places still get lost - def test_weird_comments(self): - b = """apply( # foo - f, # bar - args)""" - a = """f(*args)""" - self.check(b, a) - - # These should *not* be touched - - def test_unchanged_1(self): - s = """apply()""" - self.unchanged(s) - - def test_unchanged_2(self): - s = """apply(f)""" - self.unchanged(s) - - def test_unchanged_3(self): - s = """apply(f,)""" - self.unchanged(s) - - def test_unchanged_4(self): - s = """apply(f, args, kwds, extras)""" - self.unchanged(s) - - def test_unchanged_5(self): - s = """apply(f, *args, **kwds)""" - self.unchanged(s) - - def test_unchanged_6(self): - s = """apply(f, *args)""" - self.unchanged(s) - - def test_unchanged_7(self): - s = """apply(func=f, args=args, kwds=kwds)""" - self.unchanged(s) - - def test_unchanged_8(self): - s = """apply(f, args=args, kwds=kwds)""" - self.unchanged(s) - - def test_unchanged_9(self): - s = """apply(f, args, kwds=kwds)""" - self.unchanged(s) - - def test_space_1(self): - a = """apply( f, args, kwds)""" - b = """f(*args, **kwds)""" - self.check(a, b) - - def test_space_2(self): - a = """apply( f ,args,kwds )""" - b = """f(*args, **kwds)""" - self.check(a, b) - -class Test_intern(FixerTestCase): - fixer = "intern" - - def test_prefix_preservation(self): - b = """x = intern( a )""" - a = """import sys\nx = sys.intern( a )""" - self.check(b, a) - - b = """y = intern("b" # test - )""" - a = """import sys\ny = sys.intern("b" # test - )""" - self.check(b, a) - - b = """z = intern(a+b+c.d, )""" - a = """import sys\nz = sys.intern(a+b+c.d, )""" - self.check(b, a) - - def test(self): - b = """x = intern(a)""" - a = """import sys\nx = sys.intern(a)""" - self.check(b, a) - - b = """z = intern(a+b+c.d,)""" - a = """import sys\nz = sys.intern(a+b+c.d,)""" - self.check(b, a) - - b = """intern("y%s" % 5).replace("y", "")""" - a = """import sys\nsys.intern("y%s" % 5).replace("y", "")""" - self.check(b, a) - - # These should not be refactored - - def test_unchanged(self): - s = """intern(a=1)""" - self.unchanged(s) - - s = """intern(f, g)""" - self.unchanged(s) - - s = """intern(*h)""" - self.unchanged(s) - - s = """intern(**i)""" - self.unchanged(s) - - s = """intern()""" - self.unchanged(s) - -class Test_reduce(FixerTestCase): - fixer = "reduce" - - def test_simple_call(self): - b = "reduce(a, b, c)" - a = "from functools import reduce\nreduce(a, b, c)" - self.check(b, a) - - def test_bug_7253(self): - # fix_tuple_params was being bad and orphaning nodes in the tree. - b = "def x(arg): reduce(sum, [])" - a = "from functools import reduce\ndef x(arg): reduce(sum, [])" - self.check(b, a) - - def test_call_with_lambda(self): - b = "reduce(lambda x, y: x + y, seq)" - a = "from functools import reduce\nreduce(lambda x, y: x + y, seq)" - self.check(b, a) - - def test_unchanged(self): - s = "reduce(a)" - self.unchanged(s) - - s = "reduce(a, b=42)" - self.unchanged(s) - - s = "reduce(a, b, c, d)" - self.unchanged(s) - - s = "reduce(**c)" - self.unchanged(s) - - s = "reduce()" - self.unchanged(s) - -class Test_print(FixerTestCase): - fixer = "print" - - def test_prefix_preservation(self): - b = """print 1, 1+1, 1+1+1""" - a = """print(1, 1+1, 1+1+1)""" - self.check(b, a) - - def test_idempotency(self): - s = """print()""" - self.unchanged(s) - - s = """print('')""" - self.unchanged(s) - - def test_idempotency_print_as_function(self): - self.refactor.driver.grammar = pygram.python_grammar_no_print_statement - s = """print(1, 1+1, 1+1+1)""" - self.unchanged(s) - - s = """print()""" - self.unchanged(s) - - s = """print('')""" - self.unchanged(s) - - def test_1(self): - b = """print 1, 1+1, 1+1+1""" - a = """print(1, 1+1, 1+1+1)""" - self.check(b, a) - - def test_2(self): - b = """print 1, 2""" - a = """print(1, 2)""" - self.check(b, a) - - def test_3(self): - b = """print""" - a = """print()""" - self.check(b, a) - - def test_4(self): - # from bug 3000 - b = """print whatever; print""" - a = """print(whatever); print()""" - self.check(b, a) - - def test_5(self): - b = """print; print whatever;""" - a = """print(); print(whatever);""" - self.check(b, a) - - def test_tuple(self): - b = """print (a, b, c)""" - a = """print((a, b, c))""" - self.check(b, a) - - # trailing commas - - def test_trailing_comma_1(self): - b = """print 1, 2, 3,""" - a = """print(1, 2, 3, end=' ')""" - self.check(b, a) - - def test_trailing_comma_2(self): - b = """print 1, 2,""" - a = """print(1, 2, end=' ')""" - self.check(b, a) - - def test_trailing_comma_3(self): - b = """print 1,""" - a = """print(1, end=' ')""" - self.check(b, a) - - # >> stuff - - def test_vargs_without_trailing_comma(self): - b = """print >>sys.stderr, 1, 2, 3""" - a = """print(1, 2, 3, file=sys.stderr)""" - self.check(b, a) - - def test_with_trailing_comma(self): - b = """print >>sys.stderr, 1, 2,""" - a = """print(1, 2, end=' ', file=sys.stderr)""" - self.check(b, a) - - def test_no_trailing_comma(self): - b = """print >>sys.stderr, 1+1""" - a = """print(1+1, file=sys.stderr)""" - self.check(b, a) - - def test_spaces_before_file(self): - b = """print >> sys.stderr""" - a = """print(file=sys.stderr)""" - self.check(b, a) - - def test_with_future_print_function(self): - s = "from __future__ import print_function\n" \ - "print('Hai!', end=' ')" - self.unchanged(s) - - b = "print 'Hello, world!'" - a = "print('Hello, world!')" - self.check(b, a) - - -class Test_exec(FixerTestCase): - fixer = "exec" - - def test_prefix_preservation(self): - b = """ exec code in ns1, ns2""" - a = """ exec(code, ns1, ns2)""" - self.check(b, a) - - def test_basic(self): - b = """exec code""" - a = """exec(code)""" - self.check(b, a) - - def test_with_globals(self): - b = """exec code in ns""" - a = """exec(code, ns)""" - self.check(b, a) - - def test_with_globals_locals(self): - b = """exec code in ns1, ns2""" - a = """exec(code, ns1, ns2)""" - self.check(b, a) - - def test_complex_1(self): - b = """exec (a.b()) in ns""" - a = """exec((a.b()), ns)""" - self.check(b, a) - - def test_complex_2(self): - b = """exec a.b() + c in ns""" - a = """exec(a.b() + c, ns)""" - self.check(b, a) - - # These should not be touched - - def test_unchanged_1(self): - s = """exec(code)""" - self.unchanged(s) - - def test_unchanged_2(self): - s = """exec (code)""" - self.unchanged(s) - - def test_unchanged_3(self): - s = """exec(code, ns)""" - self.unchanged(s) - - def test_unchanged_4(self): - s = """exec(code, ns1, ns2)""" - self.unchanged(s) - -class Test_repr(FixerTestCase): - fixer = "repr" - - def test_prefix_preservation(self): - b = """x = `1 + 2`""" - a = """x = repr(1 + 2)""" - self.check(b, a) - - def test_simple_1(self): - b = """x = `1 + 2`""" - a = """x = repr(1 + 2)""" - self.check(b, a) - - def test_simple_2(self): - b = """y = `x`""" - a = """y = repr(x)""" - self.check(b, a) - - def test_complex(self): - b = """z = `y`.__repr__()""" - a = """z = repr(y).__repr__()""" - self.check(b, a) - - def test_tuple(self): - b = """x = `1, 2, 3`""" - a = """x = repr((1, 2, 3))""" - self.check(b, a) - - def test_nested(self): - b = """x = `1 + `2``""" - a = """x = repr(1 + repr(2))""" - self.check(b, a) - - def test_nested_tuples(self): - b = """x = `1, 2 + `3, 4``""" - a = """x = repr((1, 2 + repr((3, 4))))""" - self.check(b, a) - -class Test_except(FixerTestCase): - fixer = "except" - - def test_prefix_preservation(self): - b = """ - try: - pass - except (RuntimeError, ImportError), e: - pass""" - a = """ - try: - pass - except (RuntimeError, ImportError) as e: - pass""" - self.check(b, a) - - def test_simple(self): - b = """ - try: - pass - except Foo, e: - pass""" - a = """ - try: - pass - except Foo as e: - pass""" - self.check(b, a) - - def test_simple_no_space_before_target(self): - b = """ - try: - pass - except Foo,e: - pass""" - a = """ - try: - pass - except Foo as e: - pass""" - self.check(b, a) - - def test_tuple_unpack(self): - b = """ - def foo(): - try: - pass - except Exception, (f, e): - pass - except ImportError, e: - pass""" - - a = """ - def foo(): - try: - pass - except Exception as xxx_todo_changeme: - (f, e) = xxx_todo_changeme.args - pass - except ImportError as e: - pass""" - self.check(b, a) - - def test_multi_class(self): - b = """ - try: - pass - except (RuntimeError, ImportError), e: - pass""" - - a = """ - try: - pass - except (RuntimeError, ImportError) as e: - pass""" - self.check(b, a) - - def test_list_unpack(self): - b = """ - try: - pass - except Exception, [a, b]: - pass""" - - a = """ - try: - pass - except Exception as xxx_todo_changeme: - [a, b] = xxx_todo_changeme.args - pass""" - self.check(b, a) - - def test_weird_target_1(self): - b = """ - try: - pass - except Exception, d[5]: - pass""" - - a = """ - try: - pass - except Exception as xxx_todo_changeme: - d[5] = xxx_todo_changeme - pass""" - self.check(b, a) - - def test_weird_target_2(self): - b = """ - try: - pass - except Exception, a.foo: - pass""" - - a = """ - try: - pass - except Exception as xxx_todo_changeme: - a.foo = xxx_todo_changeme - pass""" - self.check(b, a) - - def test_weird_target_3(self): - b = """ - try: - pass - except Exception, a().foo: - pass""" - - a = """ - try: - pass - except Exception as xxx_todo_changeme: - a().foo = xxx_todo_changeme - pass""" - self.check(b, a) - - def test_bare_except(self): - b = """ - try: - pass - except Exception, a: - pass - except: - pass""" - - a = """ - try: - pass - except Exception as a: - pass - except: - pass""" - self.check(b, a) - - def test_bare_except_and_else_finally(self): - b = """ - try: - pass - except Exception, a: - pass - except: - pass - else: - pass - finally: - pass""" - - a = """ - try: - pass - except Exception as a: - pass - except: - pass - else: - pass - finally: - pass""" - self.check(b, a) - - def test_multi_fixed_excepts_before_bare_except(self): - b = """ - try: - pass - except TypeError, b: - pass - except Exception, a: - pass - except: - pass""" - - a = """ - try: - pass - except TypeError as b: - pass - except Exception as a: - pass - except: - pass""" - self.check(b, a) - - def test_one_line_suites(self): - b = """ - try: raise TypeError - except TypeError, e: - pass - """ - a = """ - try: raise TypeError - except TypeError as e: - pass - """ - self.check(b, a) - b = """ - try: - raise TypeError - except TypeError, e: pass - """ - a = """ - try: - raise TypeError - except TypeError as e: pass - """ - self.check(b, a) - b = """ - try: raise TypeError - except TypeError, e: pass - """ - a = """ - try: raise TypeError - except TypeError as e: pass - """ - self.check(b, a) - b = """ - try: raise TypeError - except TypeError, e: pass - else: function() - finally: done() - """ - a = """ - try: raise TypeError - except TypeError as e: pass - else: function() - finally: done() - """ - self.check(b, a) - - # These should not be touched: - - def test_unchanged_1(self): - s = """ - try: - pass - except: - pass""" - self.unchanged(s) - - def test_unchanged_2(self): - s = """ - try: - pass - except Exception: - pass""" - self.unchanged(s) - - def test_unchanged_3(self): - s = """ - try: - pass - except (Exception, SystemExit): - pass""" - self.unchanged(s) - -class Test_raise(FixerTestCase): - fixer = "raise" - - def test_basic(self): - b = """raise Exception, 5""" - a = """raise Exception(5)""" - self.check(b, a) - - def test_prefix_preservation(self): - b = """raise Exception,5""" - a = """raise Exception(5)""" - self.check(b, a) - - b = """raise Exception, 5""" - a = """raise Exception(5)""" - self.check(b, a) - - def test_with_comments(self): - b = """raise Exception, 5 # foo""" - a = """raise Exception(5) # foo""" - self.check(b, a) - - b = """raise E, (5, 6) % (a, b) # foo""" - a = """raise E((5, 6) % (a, b)) # foo""" - self.check(b, a) - - b = """def foo(): - raise Exception, 5, 6 # foo""" - a = """def foo(): - raise Exception(5).with_traceback(6) # foo""" - self.check(b, a) - - def test_None_value(self): - b = """raise Exception(5), None, tb""" - a = """raise Exception(5).with_traceback(tb)""" - self.check(b, a) - - def test_tuple_value(self): - b = """raise Exception, (5, 6, 7)""" - a = """raise Exception(5, 6, 7)""" - self.check(b, a) - - def test_tuple_detection(self): - b = """raise E, (5, 6) % (a, b)""" - a = """raise E((5, 6) % (a, b))""" - self.check(b, a) - - def test_tuple_exc_1(self): - b = """raise (((E1, E2), E3), E4), V""" - a = """raise E1(V)""" - self.check(b, a) - - def test_tuple_exc_2(self): - b = """raise (E1, (E2, E3), E4), V""" - a = """raise E1(V)""" - self.check(b, a) - - # These should produce a warning - - def test_string_exc(self): - s = """raise 'foo'""" - self.warns_unchanged(s, "Python 3 does not support string exceptions") - - def test_string_exc_val(self): - s = """raise "foo", 5""" - self.warns_unchanged(s, "Python 3 does not support string exceptions") - - def test_string_exc_val_tb(self): - s = """raise "foo", 5, 6""" - self.warns_unchanged(s, "Python 3 does not support string exceptions") - - # These should result in traceback-assignment - - def test_tb_1(self): - b = """def foo(): - raise Exception, 5, 6""" - a = """def foo(): - raise Exception(5).with_traceback(6)""" - self.check(b, a) - - def test_tb_2(self): - b = """def foo(): - a = 5 - raise Exception, 5, 6 - b = 6""" - a = """def foo(): - a = 5 - raise Exception(5).with_traceback(6) - b = 6""" - self.check(b, a) - - def test_tb_3(self): - b = """def foo(): - raise Exception,5,6""" - a = """def foo(): - raise Exception(5).with_traceback(6)""" - self.check(b, a) - - def test_tb_4(self): - b = """def foo(): - a = 5 - raise Exception,5,6 - b = 6""" - a = """def foo(): - a = 5 - raise Exception(5).with_traceback(6) - b = 6""" - self.check(b, a) - - def test_tb_5(self): - b = """def foo(): - raise Exception, (5, 6, 7), 6""" - a = """def foo(): - raise Exception(5, 6, 7).with_traceback(6)""" - self.check(b, a) - - def test_tb_6(self): - b = """def foo(): - a = 5 - raise Exception, (5, 6, 7), 6 - b = 6""" - a = """def foo(): - a = 5 - raise Exception(5, 6, 7).with_traceback(6) - b = 6""" - self.check(b, a) - -class Test_throw(FixerTestCase): - fixer = "throw" - - def test_1(self): - b = """g.throw(Exception, 5)""" - a = """g.throw(Exception(5))""" - self.check(b, a) - - def test_2(self): - b = """g.throw(Exception,5)""" - a = """g.throw(Exception(5))""" - self.check(b, a) - - def test_3(self): - b = """g.throw(Exception, (5, 6, 7))""" - a = """g.throw(Exception(5, 6, 7))""" - self.check(b, a) - - def test_4(self): - b = """5 + g.throw(Exception, 5)""" - a = """5 + g.throw(Exception(5))""" - self.check(b, a) - - # These should produce warnings - - def test_warn_1(self): - s = """g.throw("foo")""" - self.warns_unchanged(s, "Python 3 does not support string exceptions") - - def test_warn_2(self): - s = """g.throw("foo", 5)""" - self.warns_unchanged(s, "Python 3 does not support string exceptions") - - def test_warn_3(self): - s = """g.throw("foo", 5, 6)""" - self.warns_unchanged(s, "Python 3 does not support string exceptions") - - # These should not be touched - - def test_untouched_1(self): - s = """g.throw(Exception)""" - self.unchanged(s) - - def test_untouched_2(self): - s = """g.throw(Exception(5, 6))""" - self.unchanged(s) - - def test_untouched_3(self): - s = """5 + g.throw(Exception(5, 6))""" - self.unchanged(s) - - # These should result in traceback-assignment - - def test_tb_1(self): - b = """def foo(): - g.throw(Exception, 5, 6)""" - a = """def foo(): - g.throw(Exception(5).with_traceback(6))""" - self.check(b, a) - - def test_tb_2(self): - b = """def foo(): - a = 5 - g.throw(Exception, 5, 6) - b = 6""" - a = """def foo(): - a = 5 - g.throw(Exception(5).with_traceback(6)) - b = 6""" - self.check(b, a) - - def test_tb_3(self): - b = """def foo(): - g.throw(Exception,5,6)""" - a = """def foo(): - g.throw(Exception(5).with_traceback(6))""" - self.check(b, a) - - def test_tb_4(self): - b = """def foo(): - a = 5 - g.throw(Exception,5,6) - b = 6""" - a = """def foo(): - a = 5 - g.throw(Exception(5).with_traceback(6)) - b = 6""" - self.check(b, a) - - def test_tb_5(self): - b = """def foo(): - g.throw(Exception, (5, 6, 7), 6)""" - a = """def foo(): - g.throw(Exception(5, 6, 7).with_traceback(6))""" - self.check(b, a) - - def test_tb_6(self): - b = """def foo(): - a = 5 - g.throw(Exception, (5, 6, 7), 6) - b = 6""" - a = """def foo(): - a = 5 - g.throw(Exception(5, 6, 7).with_traceback(6)) - b = 6""" - self.check(b, a) - - def test_tb_7(self): - b = """def foo(): - a + g.throw(Exception, 5, 6)""" - a = """def foo(): - a + g.throw(Exception(5).with_traceback(6))""" - self.check(b, a) - - def test_tb_8(self): - b = """def foo(): - a = 5 - a + g.throw(Exception, 5, 6) - b = 6""" - a = """def foo(): - a = 5 - a + g.throw(Exception(5).with_traceback(6)) - b = 6""" - self.check(b, a) - -class Test_long(FixerTestCase): - fixer = "long" - - def test_1(self): - b = """x = long(x)""" - a = """x = int(x)""" - self.check(b, a) - - def test_2(self): - b = """y = isinstance(x, long)""" - a = """y = isinstance(x, int)""" - self.check(b, a) - - def test_3(self): - b = """z = type(x) in (int, long)""" - a = """z = type(x) in (int, int)""" - self.check(b, a) - - def test_unchanged(self): - s = """long = True""" - self.unchanged(s) - - s = """s.long = True""" - self.unchanged(s) - - s = """def long(): pass""" - self.unchanged(s) - - s = """class long(): pass""" - self.unchanged(s) - - s = """def f(long): pass""" - self.unchanged(s) - - s = """def f(g, long): pass""" - self.unchanged(s) - - s = """def f(x, long=True): pass""" - self.unchanged(s) - - def test_prefix_preservation(self): - b = """x = long( x )""" - a = """x = int( x )""" - self.check(b, a) - - -class Test_execfile(FixerTestCase): - fixer = "execfile" - - def test_conversion(self): - b = """execfile("fn")""" - a = """exec(compile(open("fn").read(), "fn", 'exec'))""" - self.check(b, a) - - b = """execfile("fn", glob)""" - a = """exec(compile(open("fn").read(), "fn", 'exec'), glob)""" - self.check(b, a) - - b = """execfile("fn", glob, loc)""" - a = """exec(compile(open("fn").read(), "fn", 'exec'), glob, loc)""" - self.check(b, a) - - b = """execfile("fn", globals=glob)""" - a = """exec(compile(open("fn").read(), "fn", 'exec'), globals=glob)""" - self.check(b, a) - - b = """execfile("fn", locals=loc)""" - a = """exec(compile(open("fn").read(), "fn", 'exec'), locals=loc)""" - self.check(b, a) - - b = """execfile("fn", globals=glob, locals=loc)""" - a = """exec(compile(open("fn").read(), "fn", 'exec'), globals=glob, locals=loc)""" - self.check(b, a) - - def test_spacing(self): - b = """execfile( "fn" )""" - a = """exec(compile(open( "fn" ).read(), "fn", 'exec'))""" - self.check(b, a) - - b = """execfile("fn", globals = glob)""" - a = """exec(compile(open("fn").read(), "fn", 'exec'), globals = glob)""" - self.check(b, a) - - -class Test_isinstance(FixerTestCase): - fixer = "isinstance" - - def test_remove_multiple_items(self): - b = """isinstance(x, (int, int, int))""" - a = """isinstance(x, int)""" - self.check(b, a) - - b = """isinstance(x, (int, float, int, int, float))""" - a = """isinstance(x, (int, float))""" - self.check(b, a) - - b = """isinstance(x, (int, float, int, int, float, str))""" - a = """isinstance(x, (int, float, str))""" - self.check(b, a) - - b = """isinstance(foo() + bar(), (x(), y(), x(), int, int))""" - a = """isinstance(foo() + bar(), (x(), y(), x(), int))""" - self.check(b, a) - - def test_prefix_preservation(self): - b = """if isinstance( foo(), ( bar, bar, baz )) : pass""" - a = """if isinstance( foo(), ( bar, baz )) : pass""" - self.check(b, a) - - def test_unchanged(self): - self.unchanged("isinstance(x, (str, int))") - -class Test_dict(FixerTestCase): - fixer = "dict" - - def test_prefix_preservation(self): - b = "if d. keys ( ) : pass" - a = "if list(d. keys ( )) : pass" - self.check(b, a) - - b = "if d. items ( ) : pass" - a = "if list(d. items ( )) : pass" - self.check(b, a) - - b = "if d. iterkeys ( ) : pass" - a = "if iter(d. keys ( )) : pass" - self.check(b, a) - - b = "[i for i in d. iterkeys( ) ]" - a = "[i for i in d. keys( ) ]" - self.check(b, a) - - b = "if d. viewkeys ( ) : pass" - a = "if d. keys ( ) : pass" - self.check(b, a) - - b = "[i for i in d. viewkeys( ) ]" - a = "[i for i in d. keys( ) ]" - self.check(b, a) - - def test_trailing_comment(self): - b = "d.keys() # foo" - a = "list(d.keys()) # foo" - self.check(b, a) - - b = "d.items() # foo" - a = "list(d.items()) # foo" - self.check(b, a) - - b = "d.iterkeys() # foo" - a = "iter(d.keys()) # foo" - self.check(b, a) - - b = """[i for i in d.iterkeys() # foo - ]""" - a = """[i for i in d.keys() # foo - ]""" - self.check(b, a) - - b = """[i for i in d.iterkeys() # foo - ]""" - a = """[i for i in d.keys() # foo - ]""" - self.check(b, a) - - b = "d.viewitems() # foo" - a = "d.items() # foo" - self.check(b, a) - - def test_unchanged(self): - for wrapper in fixer_util.consuming_calls: - s = "s = %s(d.keys())" % wrapper - self.unchanged(s) - - s = "s = %s(d.values())" % wrapper - self.unchanged(s) - - s = "s = %s(d.items())" % wrapper - self.unchanged(s) - - def test_01(self): - b = "d.keys()" - a = "list(d.keys())" - self.check(b, a) - - b = "a[0].foo().keys()" - a = "list(a[0].foo().keys())" - self.check(b, a) - - def test_02(self): - b = "d.items()" - a = "list(d.items())" - self.check(b, a) - - def test_03(self): - b = "d.values()" - a = "list(d.values())" - self.check(b, a) - - def test_04(self): - b = "d.iterkeys()" - a = "iter(d.keys())" - self.check(b, a) - - def test_05(self): - b = "d.iteritems()" - a = "iter(d.items())" - self.check(b, a) - - def test_06(self): - b = "d.itervalues()" - a = "iter(d.values())" - self.check(b, a) - - def test_07(self): - s = "list(d.keys())" - self.unchanged(s) - - def test_08(self): - s = "sorted(d.keys())" - self.unchanged(s) - - def test_09(self): - b = "iter(d.keys())" - a = "iter(list(d.keys()))" - self.check(b, a) - - def test_10(self): - b = "foo(d.keys())" - a = "foo(list(d.keys()))" - self.check(b, a) - - def test_11(self): - b = "for i in d.keys(): print i" - a = "for i in list(d.keys()): print i" - self.check(b, a) - - def test_12(self): - b = "for i in d.iterkeys(): print i" - a = "for i in d.keys(): print i" - self.check(b, a) - - def test_13(self): - b = "[i for i in d.keys()]" - a = "[i for i in list(d.keys())]" - self.check(b, a) - - def test_14(self): - b = "[i for i in d.iterkeys()]" - a = "[i for i in d.keys()]" - self.check(b, a) - - def test_15(self): - b = "(i for i in d.keys())" - a = "(i for i in list(d.keys()))" - self.check(b, a) - - def test_16(self): - b = "(i for i in d.iterkeys())" - a = "(i for i in d.keys())" - self.check(b, a) - - def test_17(self): - b = "iter(d.iterkeys())" - a = "iter(d.keys())" - self.check(b, a) - - def test_18(self): - b = "list(d.iterkeys())" - a = "list(d.keys())" - self.check(b, a) - - def test_19(self): - b = "sorted(d.iterkeys())" - a = "sorted(d.keys())" - self.check(b, a) - - def test_20(self): - b = "foo(d.iterkeys())" - a = "foo(iter(d.keys()))" - self.check(b, a) - - def test_21(self): - b = "print h.iterkeys().next()" - a = "print iter(h.keys()).next()" - self.check(b, a) - - def test_22(self): - b = "print h.keys()[0]" - a = "print list(h.keys())[0]" - self.check(b, a) - - def test_23(self): - b = "print list(h.iterkeys().next())" - a = "print list(iter(h.keys()).next())" - self.check(b, a) - - def test_24(self): - b = "for x in h.keys()[0]: print x" - a = "for x in list(h.keys())[0]: print x" - self.check(b, a) - - def test_25(self): - b = "d.viewkeys()" - a = "d.keys()" - self.check(b, a) - - def test_26(self): - b = "d.viewitems()" - a = "d.items()" - self.check(b, a) - - def test_27(self): - b = "d.viewvalues()" - a = "d.values()" - self.check(b, a) - - def test_28(self): - b = "[i for i in d.viewkeys()]" - a = "[i for i in d.keys()]" - self.check(b, a) - - def test_29(self): - b = "(i for i in d.viewkeys())" - a = "(i for i in d.keys())" - self.check(b, a) - - def test_30(self): - b = "iter(d.viewkeys())" - a = "iter(d.keys())" - self.check(b, a) - - def test_31(self): - b = "list(d.viewkeys())" - a = "list(d.keys())" - self.check(b, a) - - def test_32(self): - b = "sorted(d.viewkeys())" - a = "sorted(d.keys())" - self.check(b, a) - -class Test_xrange(FixerTestCase): - fixer = "xrange" - - def test_prefix_preservation(self): - b = """x = xrange( 10 )""" - a = """x = range( 10 )""" - self.check(b, a) - - b = """x = xrange( 1 , 10 )""" - a = """x = range( 1 , 10 )""" - self.check(b, a) - - b = """x = xrange( 0 , 10 , 2 )""" - a = """x = range( 0 , 10 , 2 )""" - self.check(b, a) - - def test_single_arg(self): - b = """x = xrange(10)""" - a = """x = range(10)""" - self.check(b, a) - - def test_two_args(self): - b = """x = xrange(1, 10)""" - a = """x = range(1, 10)""" - self.check(b, a) - - def test_three_args(self): - b = """x = xrange(0, 10, 2)""" - a = """x = range(0, 10, 2)""" - self.check(b, a) - - def test_wrap_in_list(self): - b = """x = range(10, 3, 9)""" - a = """x = list(range(10, 3, 9))""" - self.check(b, a) - - b = """x = foo(range(10, 3, 9))""" - a = """x = foo(list(range(10, 3, 9)))""" - self.check(b, a) - - b = """x = range(10, 3, 9) + [4]""" - a = """x = list(range(10, 3, 9)) + [4]""" - self.check(b, a) - - b = """x = range(10)[::-1]""" - a = """x = list(range(10))[::-1]""" - self.check(b, a) - - b = """x = range(10) [3]""" - a = """x = list(range(10)) [3]""" - self.check(b, a) - - def test_xrange_in_for(self): - b = """for i in xrange(10):\n j=i""" - a = """for i in range(10):\n j=i""" - self.check(b, a) - - b = """[i for i in xrange(10)]""" - a = """[i for i in range(10)]""" - self.check(b, a) - - def test_range_in_for(self): - self.unchanged("for i in range(10): pass") - self.unchanged("[i for i in range(10)]") - - def test_in_contains_test(self): - self.unchanged("x in range(10, 3, 9)") - - def test_in_consuming_context(self): - for call in fixer_util.consuming_calls: - self.unchanged("a = %s(range(10))" % call) - -class Test_xrange_with_reduce(FixerTestCase): - - def setUp(self): - super(Test_xrange_with_reduce, self).setUp(["xrange", "reduce"]) - - def test_double_transform(self): - b = """reduce(x, xrange(5))""" - a = """from functools import reduce -reduce(x, range(5))""" - self.check(b, a) - -class Test_raw_input(FixerTestCase): - fixer = "raw_input" - - def test_prefix_preservation(self): - b = """x = raw_input( )""" - a = """x = input( )""" - self.check(b, a) - - b = """x = raw_input( '' )""" - a = """x = input( '' )""" - self.check(b, a) - - def test_1(self): - b = """x = raw_input()""" - a = """x = input()""" - self.check(b, a) - - def test_2(self): - b = """x = raw_input('')""" - a = """x = input('')""" - self.check(b, a) - - def test_3(self): - b = """x = raw_input('prompt')""" - a = """x = input('prompt')""" - self.check(b, a) - - def test_4(self): - b = """x = raw_input(foo(a) + 6)""" - a = """x = input(foo(a) + 6)""" - self.check(b, a) - - def test_5(self): - b = """x = raw_input(invite).split()""" - a = """x = input(invite).split()""" - self.check(b, a) - - def test_6(self): - b = """x = raw_input(invite) . split ()""" - a = """x = input(invite) . split ()""" - self.check(b, a) - - def test_8(self): - b = "x = int(raw_input())" - a = "x = int(input())" - self.check(b, a) - -class Test_funcattrs(FixerTestCase): - fixer = "funcattrs" - - attrs = ["closure", "doc", "name", "defaults", "code", "globals", "dict"] - - def test(self): - for attr in self.attrs: - b = "a.func_%s" % attr - a = "a.__%s__" % attr - self.check(b, a) - - b = "self.foo.func_%s.foo_bar" % attr - a = "self.foo.__%s__.foo_bar" % attr - self.check(b, a) - - def test_unchanged(self): - for attr in self.attrs: - s = "foo(func_%s + 5)" % attr - self.unchanged(s) - - s = "f(foo.__%s__)" % attr - self.unchanged(s) - - s = "f(foo.__%s__.foo)" % attr - self.unchanged(s) - -class Test_xreadlines(FixerTestCase): - fixer = "xreadlines" - - def test_call(self): - b = "for x in f.xreadlines(): pass" - a = "for x in f: pass" - self.check(b, a) - - b = "for x in foo().xreadlines(): pass" - a = "for x in foo(): pass" - self.check(b, a) - - b = "for x in (5 + foo()).xreadlines(): pass" - a = "for x in (5 + foo()): pass" - self.check(b, a) - - def test_attr_ref(self): - b = "foo(f.xreadlines + 5)" - a = "foo(f.__iter__ + 5)" - self.check(b, a) - - b = "foo(f().xreadlines + 5)" - a = "foo(f().__iter__ + 5)" - self.check(b, a) - - b = "foo((5 + f()).xreadlines + 5)" - a = "foo((5 + f()).__iter__ + 5)" - self.check(b, a) - - def test_unchanged(self): - s = "for x in f.xreadlines(5): pass" - self.unchanged(s) - - s = "for x in f.xreadlines(k=5): pass" - self.unchanged(s) - - s = "for x in f.xreadlines(*k, **v): pass" - self.unchanged(s) - - s = "foo(xreadlines)" - self.unchanged(s) - - -class ImportsFixerTests: - - def test_import_module(self): - for old, new in self.modules.items(): - b = "import %s" % old - a = "import %s" % new - self.check(b, a) - - b = "import foo, %s, bar" % old - a = "import foo, %s, bar" % new - self.check(b, a) - - def test_import_from(self): - for old, new in self.modules.items(): - b = "from %s import foo" % old - a = "from %s import foo" % new - self.check(b, a) - - b = "from %s import foo, bar" % old - a = "from %s import foo, bar" % new - self.check(b, a) - - b = "from %s import (yes, no)" % old - a = "from %s import (yes, no)" % new - self.check(b, a) - - def test_import_module_as(self): - for old, new in self.modules.items(): - b = "import %s as foo_bar" % old - a = "import %s as foo_bar" % new - self.check(b, a) - - b = "import %s as foo_bar" % old - a = "import %s as foo_bar" % new - self.check(b, a) - - def test_import_from_as(self): - for old, new in self.modules.items(): - b = "from %s import foo as bar" % old - a = "from %s import foo as bar" % new - self.check(b, a) - - def test_star(self): - for old, new in self.modules.items(): - b = "from %s import *" % old - a = "from %s import *" % new - self.check(b, a) - - def test_import_module_usage(self): - for old, new in self.modules.items(): - b = """ - import %s - foo(%s.bar) - """ % (old, old) - a = """ - import %s - foo(%s.bar) - """ % (new, new) - self.check(b, a) - - b = """ - from %s import x - %s = 23 - """ % (old, old) - a = """ - from %s import x - %s = 23 - """ % (new, old) - self.check(b, a) - - s = """ - def f(): - %s.method() - """ % (old,) - self.unchanged(s) - - # test nested usage - b = """ - import %s - %s.bar(%s.foo) - """ % (old, old, old) - a = """ - import %s - %s.bar(%s.foo) - """ % (new, new, new) - self.check(b, a) - - b = """ - import %s - x.%s - """ % (old, old) - a = """ - import %s - x.%s - """ % (new, old) - self.check(b, a) - - -class Test_imports(FixerTestCase, ImportsFixerTests): - fixer = "imports" - from ..fixes.fix_imports import MAPPING as modules - - def test_multiple_imports(self): - b = """import urlparse, cStringIO""" - a = """import urllib.parse, io""" - self.check(b, a) - - def test_multiple_imports_as(self): - b = """ - import copy_reg as bar, HTMLParser as foo, urlparse - s = urlparse.spam(bar.foo()) - """ - a = """ - import copyreg as bar, html.parser as foo, urllib.parse - s = urllib.parse.spam(bar.foo()) - """ - self.check(b, a) - - -class Test_imports2(FixerTestCase, ImportsFixerTests): - fixer = "imports2" - from ..fixes.fix_imports2 import MAPPING as modules - - -class Test_imports_fixer_order(FixerTestCase, ImportsFixerTests): - - def setUp(self): - super(Test_imports_fixer_order, self).setUp(['imports', 'imports2']) - from ..fixes.fix_imports2 import MAPPING as mapping2 - self.modules = mapping2.copy() - from ..fixes.fix_imports import MAPPING as mapping1 - for key in ('dbhash', 'dumbdbm', 'dbm', 'gdbm'): - self.modules[key] = mapping1[key] - - def test_after_local_imports_refactoring(self): - for fix in ("imports", "imports2"): - self.fixer = fix - self.assert_runs_after("import") - - -class Test_urllib(FixerTestCase): - fixer = "urllib" - from ..fixes.fix_urllib import MAPPING as modules - - def test_import_module(self): - for old, changes in self.modules.items(): - b = "import %s" % old - a = "import %s" % ", ".join(map(itemgetter(0), changes)) - self.check(b, a) - - def test_import_from(self): - for old, changes in self.modules.items(): - all_members = [] - for new, members in changes: - for member in members: - all_members.append(member) - b = "from %s import %s" % (old, member) - a = "from %s import %s" % (new, member) - self.check(b, a) - - s = "from foo import %s" % member - self.unchanged(s) - - b = "from %s import %s" % (old, ", ".join(members)) - a = "from %s import %s" % (new, ", ".join(members)) - self.check(b, a) - - s = "from foo import %s" % ", ".join(members) - self.unchanged(s) - - # test the breaking of a module into multiple replacements - b = "from %s import %s" % (old, ", ".join(all_members)) - a = "\n".join(["from %s import %s" % (new, ", ".join(members)) - for (new, members) in changes]) - self.check(b, a) - - def test_import_module_as(self): - for old in self.modules: - s = "import %s as foo" % old - self.warns_unchanged(s, "This module is now multiple modules") - - def test_import_from_as(self): - for old, changes in self.modules.items(): - for new, members in changes: - for member in members: - b = "from %s import %s as foo_bar" % (old, member) - a = "from %s import %s as foo_bar" % (new, member) - self.check(b, a) - b = "from %s import %s as blah, %s" % (old, member, member) - a = "from %s import %s as blah, %s" % (new, member, member) - self.check(b, a) - - def test_star(self): - for old in self.modules: - s = "from %s import *" % old - self.warns_unchanged(s, "Cannot handle star imports") - - def test_indented(self): - b = """ -def foo(): - from urllib import urlencode, urlopen -""" - a = """ -def foo(): - from urllib.parse import urlencode - from urllib.request import urlopen -""" - self.check(b, a) - - b = """ -def foo(): - other() - from urllib import urlencode, urlopen -""" - a = """ -def foo(): - other() - from urllib.parse import urlencode - from urllib.request import urlopen -""" - self.check(b, a) - - - - def test_import_module_usage(self): - for old, changes in self.modules.items(): - for new, members in changes: - for member in members: - new_import = ", ".join([n for (n, mems) - in self.modules[old]]) - b = """ - import %s - foo(%s.%s) - """ % (old, old, member) - a = """ - import %s - foo(%s.%s) - """ % (new_import, new, member) - self.check(b, a) - b = """ - import %s - %s.%s(%s.%s) - """ % (old, old, member, old, member) - a = """ - import %s - %s.%s(%s.%s) - """ % (new_import, new, member, new, member) - self.check(b, a) - - -class Test_input(FixerTestCase): - fixer = "input" - - def test_prefix_preservation(self): - b = """x = input( )""" - a = """x = eval(input( ))""" - self.check(b, a) - - b = """x = input( '' )""" - a = """x = eval(input( '' ))""" - self.check(b, a) - - def test_trailing_comment(self): - b = """x = input() # foo""" - a = """x = eval(input()) # foo""" - self.check(b, a) - - def test_idempotency(self): - s = """x = eval(input())""" - self.unchanged(s) - - s = """x = eval(input(''))""" - self.unchanged(s) - - s = """x = eval(input(foo(5) + 9))""" - self.unchanged(s) - - def test_1(self): - b = """x = input()""" - a = """x = eval(input())""" - self.check(b, a) - - def test_2(self): - b = """x = input('')""" - a = """x = eval(input(''))""" - self.check(b, a) - - def test_3(self): - b = """x = input('prompt')""" - a = """x = eval(input('prompt'))""" - self.check(b, a) - - def test_4(self): - b = """x = input(foo(5) + 9)""" - a = """x = eval(input(foo(5) + 9))""" - self.check(b, a) - -class Test_tuple_params(FixerTestCase): - fixer = "tuple_params" - - def test_unchanged_1(self): - s = """def foo(): pass""" - self.unchanged(s) - - def test_unchanged_2(self): - s = """def foo(a, b, c): pass""" - self.unchanged(s) - - def test_unchanged_3(self): - s = """def foo(a=3, b=4, c=5): pass""" - self.unchanged(s) - - def test_1(self): - b = """ - def foo(((a, b), c)): - x = 5""" - - a = """ - def foo(xxx_todo_changeme): - ((a, b), c) = xxx_todo_changeme - x = 5""" - self.check(b, a) - - def test_2(self): - b = """ - def foo(((a, b), c), d): - x = 5""" - - a = """ - def foo(xxx_todo_changeme, d): - ((a, b), c) = xxx_todo_changeme - x = 5""" - self.check(b, a) - - def test_3(self): - b = """ - def foo(((a, b), c), d) -> e: - x = 5""" - - a = """ - def foo(xxx_todo_changeme, d) -> e: - ((a, b), c) = xxx_todo_changeme - x = 5""" - self.check(b, a) - - def test_semicolon(self): - b = """ - def foo(((a, b), c)): x = 5; y = 7""" - - a = """ - def foo(xxx_todo_changeme): ((a, b), c) = xxx_todo_changeme; x = 5; y = 7""" - self.check(b, a) - - def test_keywords(self): - b = """ - def foo(((a, b), c), d, e=5) -> z: - x = 5""" - - a = """ - def foo(xxx_todo_changeme, d, e=5) -> z: - ((a, b), c) = xxx_todo_changeme - x = 5""" - self.check(b, a) - - def test_varargs(self): - b = """ - def foo(((a, b), c), d, *vargs, **kwargs) -> z: - x = 5""" - - a = """ - def foo(xxx_todo_changeme, d, *vargs, **kwargs) -> z: - ((a, b), c) = xxx_todo_changeme - x = 5""" - self.check(b, a) - - def test_multi_1(self): - b = """ - def foo(((a, b), c), (d, e, f)) -> z: - x = 5""" - - a = """ - def foo(xxx_todo_changeme, xxx_todo_changeme1) -> z: - ((a, b), c) = xxx_todo_changeme - (d, e, f) = xxx_todo_changeme1 - x = 5""" - self.check(b, a) - - def test_multi_2(self): - b = """ - def foo(x, ((a, b), c), d, (e, f, g), y) -> z: - x = 5""" - - a = """ - def foo(x, xxx_todo_changeme, d, xxx_todo_changeme1, y) -> z: - ((a, b), c) = xxx_todo_changeme - (e, f, g) = xxx_todo_changeme1 - x = 5""" - self.check(b, a) - - def test_docstring(self): - b = """ - def foo(((a, b), c), (d, e, f)) -> z: - "foo foo foo foo" - x = 5""" - - a = """ - def foo(xxx_todo_changeme, xxx_todo_changeme1) -> z: - "foo foo foo foo" - ((a, b), c) = xxx_todo_changeme - (d, e, f) = xxx_todo_changeme1 - x = 5""" - self.check(b, a) - - def test_lambda_no_change(self): - s = """lambda x: x + 5""" - self.unchanged(s) - - def test_lambda_parens_single_arg(self): - b = """lambda (x): x + 5""" - a = """lambda x: x + 5""" - self.check(b, a) - - b = """lambda(x): x + 5""" - a = """lambda x: x + 5""" - self.check(b, a) - - b = """lambda ((((x)))): x + 5""" - a = """lambda x: x + 5""" - self.check(b, a) - - b = """lambda((((x)))): x + 5""" - a = """lambda x: x + 5""" - self.check(b, a) - - def test_lambda_simple(self): - b = """lambda (x, y): x + f(y)""" - a = """lambda x_y: x_y[0] + f(x_y[1])""" - self.check(b, a) - - b = """lambda(x, y): x + f(y)""" - a = """lambda x_y: x_y[0] + f(x_y[1])""" - self.check(b, a) - - b = """lambda (((x, y))): x + f(y)""" - a = """lambda x_y: x_y[0] + f(x_y[1])""" - self.check(b, a) - - b = """lambda(((x, y))): x + f(y)""" - a = """lambda x_y: x_y[0] + f(x_y[1])""" - self.check(b, a) - - def test_lambda_one_tuple(self): - b = """lambda (x,): x + f(x)""" - a = """lambda x1: x1[0] + f(x1[0])""" - self.check(b, a) - - b = """lambda (((x,))): x + f(x)""" - a = """lambda x1: x1[0] + f(x1[0])""" - self.check(b, a) - - def test_lambda_simple_multi_use(self): - b = """lambda (x, y): x + x + f(x) + x""" - a = """lambda x_y: x_y[0] + x_y[0] + f(x_y[0]) + x_y[0]""" - self.check(b, a) - - def test_lambda_simple_reverse(self): - b = """lambda (x, y): y + x""" - a = """lambda x_y: x_y[1] + x_y[0]""" - self.check(b, a) - - def test_lambda_nested(self): - b = """lambda (x, (y, z)): x + y + z""" - a = """lambda x_y_z: x_y_z[0] + x_y_z[1][0] + x_y_z[1][1]""" - self.check(b, a) - - b = """lambda (((x, (y, z)))): x + y + z""" - a = """lambda x_y_z: x_y_z[0] + x_y_z[1][0] + x_y_z[1][1]""" - self.check(b, a) - - def test_lambda_nested_multi_use(self): - b = """lambda (x, (y, z)): x + y + f(y)""" - a = """lambda x_y_z: x_y_z[0] + x_y_z[1][0] + f(x_y_z[1][0])""" - self.check(b, a) - -class Test_methodattrs(FixerTestCase): - fixer = "methodattrs" - - attrs = ["func", "self", "class"] - - def test(self): - for attr in self.attrs: - b = "a.im_%s" % attr - if attr == "class": - a = "a.__self__.__class__" - else: - a = "a.__%s__" % attr - self.check(b, a) - - b = "self.foo.im_%s.foo_bar" % attr - if attr == "class": - a = "self.foo.__self__.__class__.foo_bar" - else: - a = "self.foo.__%s__.foo_bar" % attr - self.check(b, a) - - def test_unchanged(self): - for attr in self.attrs: - s = "foo(im_%s + 5)" % attr - self.unchanged(s) - - s = "f(foo.__%s__)" % attr - self.unchanged(s) - - s = "f(foo.__%s__.foo)" % attr - self.unchanged(s) - -class Test_next(FixerTestCase): - fixer = "next" - - def test_1(self): - b = """it.next()""" - a = """next(it)""" - self.check(b, a) - - def test_2(self): - b = """a.b.c.d.next()""" - a = """next(a.b.c.d)""" - self.check(b, a) - - def test_3(self): - b = """(a + b).next()""" - a = """next((a + b))""" - self.check(b, a) - - def test_4(self): - b = """a().next()""" - a = """next(a())""" - self.check(b, a) - - def test_5(self): - b = """a().next() + b""" - a = """next(a()) + b""" - self.check(b, a) - - def test_6(self): - b = """c( a().next() + b)""" - a = """c( next(a()) + b)""" - self.check(b, a) - - def test_prefix_preservation_1(self): - b = """ - for a in b: - foo(a) - a.next() - """ - a = """ - for a in b: - foo(a) - next(a) - """ - self.check(b, a) - - def test_prefix_preservation_2(self): - b = """ - for a in b: - foo(a) # abc - # def - a.next() - """ - a = """ - for a in b: - foo(a) # abc - # def - next(a) - """ - self.check(b, a) - - def test_prefix_preservation_3(self): - b = """ - next = 5 - for a in b: - foo(a) - a.next() - """ - a = """ - next = 5 - for a in b: - foo(a) - a.__next__() - """ - self.check(b, a, ignore_warnings=True) - - def test_prefix_preservation_4(self): - b = """ - next = 5 - for a in b: - foo(a) # abc - # def - a.next() - """ - a = """ - next = 5 - for a in b: - foo(a) # abc - # def - a.__next__() - """ - self.check(b, a, ignore_warnings=True) - - def test_prefix_preservation_5(self): - b = """ - next = 5 - for a in b: - foo(foo(a), # abc - a.next()) - """ - a = """ - next = 5 - for a in b: - foo(foo(a), # abc - a.__next__()) - """ - self.check(b, a, ignore_warnings=True) - - def test_prefix_preservation_6(self): - b = """ - for a in b: - foo(foo(a), # abc - a.next()) - """ - a = """ - for a in b: - foo(foo(a), # abc - next(a)) - """ - self.check(b, a) - - def test_method_1(self): - b = """ - class A: - def next(self): - pass - """ - a = """ - class A: - def __next__(self): - pass - """ - self.check(b, a) - - def test_method_2(self): - b = """ - class A(object): - def next(self): - pass - """ - a = """ - class A(object): - def __next__(self): - pass - """ - self.check(b, a) - - def test_method_3(self): - b = """ - class A: - def next(x): - pass - """ - a = """ - class A: - def __next__(x): - pass - """ - self.check(b, a) - - def test_method_4(self): - b = """ - class A: - def __init__(self, foo): - self.foo = foo - - def next(self): - pass - - def __iter__(self): - return self - """ - a = """ - class A: - def __init__(self, foo): - self.foo = foo - - def __next__(self): - pass - - def __iter__(self): - return self - """ - self.check(b, a) - - def test_method_unchanged(self): - s = """ - class A: - def next(self, a, b): - pass - """ - self.unchanged(s) - - def test_shadowing_assign_simple(self): - s = """ - next = foo - - class A: - def next(self, a, b): - pass - """ - self.warns_unchanged(s, "Calls to builtin next() possibly shadowed") - - def test_shadowing_assign_tuple_1(self): - s = """ - (next, a) = foo - - class A: - def next(self, a, b): - pass - """ - self.warns_unchanged(s, "Calls to builtin next() possibly shadowed") - - def test_shadowing_assign_tuple_2(self): - s = """ - (a, (b, (next, c)), a) = foo - - class A: - def next(self, a, b): - pass - """ - self.warns_unchanged(s, "Calls to builtin next() possibly shadowed") - - def test_shadowing_assign_list_1(self): - s = """ - [next, a] = foo - - class A: - def next(self, a, b): - pass - """ - self.warns_unchanged(s, "Calls to builtin next() possibly shadowed") - - def test_shadowing_assign_list_2(self): - s = """ - [a, [b, [next, c]], a] = foo - - class A: - def next(self, a, b): - pass - """ - self.warns_unchanged(s, "Calls to builtin next() possibly shadowed") - - def test_builtin_assign(self): - s = """ - def foo(): - __builtin__.next = foo - - class A: - def next(self, a, b): - pass - """ - self.warns_unchanged(s, "Calls to builtin next() possibly shadowed") - - def test_builtin_assign_in_tuple(self): - s = """ - def foo(): - (a, __builtin__.next) = foo - - class A: - def next(self, a, b): - pass - """ - self.warns_unchanged(s, "Calls to builtin next() possibly shadowed") - - def test_builtin_assign_in_list(self): - s = """ - def foo(): - [a, __builtin__.next] = foo - - class A: - def next(self, a, b): - pass - """ - self.warns_unchanged(s, "Calls to builtin next() possibly shadowed") - - def test_assign_to_next(self): - s = """ - def foo(): - A.next = foo - - class A: - def next(self, a, b): - pass - """ - self.unchanged(s) - - def test_assign_to_next_in_tuple(self): - s = """ - def foo(): - (a, A.next) = foo - - class A: - def next(self, a, b): - pass - """ - self.unchanged(s) - - def test_assign_to_next_in_list(self): - s = """ - def foo(): - [a, A.next] = foo - - class A: - def next(self, a, b): - pass - """ - self.unchanged(s) - - def test_shadowing_import_1(self): - s = """ - import foo.bar as next - - class A: - def next(self, a, b): - pass - """ - self.warns_unchanged(s, "Calls to builtin next() possibly shadowed") - - def test_shadowing_import_2(self): - s = """ - import bar, bar.foo as next - - class A: - def next(self, a, b): - pass - """ - self.warns_unchanged(s, "Calls to builtin next() possibly shadowed") - - def test_shadowing_import_3(self): - s = """ - import bar, bar.foo as next, baz - - class A: - def next(self, a, b): - pass - """ - self.warns_unchanged(s, "Calls to builtin next() possibly shadowed") - - def test_shadowing_import_from_1(self): - s = """ - from x import next - - class A: - def next(self, a, b): - pass - """ - self.warns_unchanged(s, "Calls to builtin next() possibly shadowed") - - def test_shadowing_import_from_2(self): - s = """ - from x.a import next - - class A: - def next(self, a, b): - pass - """ - self.warns_unchanged(s, "Calls to builtin next() possibly shadowed") - - def test_shadowing_import_from_3(self): - s = """ - from x import a, next, b - - class A: - def next(self, a, b): - pass - """ - self.warns_unchanged(s, "Calls to builtin next() possibly shadowed") - - def test_shadowing_import_from_4(self): - s = """ - from x.a import a, next, b - - class A: - def next(self, a, b): - pass - """ - self.warns_unchanged(s, "Calls to builtin next() possibly shadowed") - - def test_shadowing_funcdef_1(self): - s = """ - def next(a): - pass - - class A: - def next(self, a, b): - pass - """ - self.warns_unchanged(s, "Calls to builtin next() possibly shadowed") - - def test_shadowing_funcdef_2(self): - b = """ - def next(a): - pass - - class A: - def next(self): - pass - - it.next() - """ - a = """ - def next(a): - pass - - class A: - def __next__(self): - pass - - it.__next__() - """ - self.warns(b, a, "Calls to builtin next() possibly shadowed") - - def test_shadowing_global_1(self): - s = """ - def f(): - global next - next = 5 - """ - self.warns_unchanged(s, "Calls to builtin next() possibly shadowed") - - def test_shadowing_global_2(self): - s = """ - def f(): - global a, next, b - next = 5 - """ - self.warns_unchanged(s, "Calls to builtin next() possibly shadowed") - - def test_shadowing_for_simple(self): - s = """ - for next in it(): - pass - - b = 5 - c = 6 - """ - self.warns_unchanged(s, "Calls to builtin next() possibly shadowed") - - def test_shadowing_for_tuple_1(self): - s = """ - for next, b in it(): - pass - - b = 5 - c = 6 - """ - self.warns_unchanged(s, "Calls to builtin next() possibly shadowed") - - def test_shadowing_for_tuple_2(self): - s = """ - for a, (next, c), b in it(): - pass - - b = 5 - c = 6 - """ - self.warns_unchanged(s, "Calls to builtin next() possibly shadowed") - - def test_noncall_access_1(self): - b = """gnext = g.next""" - a = """gnext = g.__next__""" - self.check(b, a) - - def test_noncall_access_2(self): - b = """f(g.next + 5)""" - a = """f(g.__next__ + 5)""" - self.check(b, a) - - def test_noncall_access_3(self): - b = """f(g().next + 5)""" - a = """f(g().__next__ + 5)""" - self.check(b, a) - -class Test_nonzero(FixerTestCase): - fixer = "nonzero" - - def test_1(self): - b = """ - class A: - def __nonzero__(self): - pass - """ - a = """ - class A: - def __bool__(self): - pass - """ - self.check(b, a) - - def test_2(self): - b = """ - class A(object): - def __nonzero__(self): - pass - """ - a = """ - class A(object): - def __bool__(self): - pass - """ - self.check(b, a) - - def test_unchanged_1(self): - s = """ - class A(object): - def __bool__(self): - pass - """ - self.unchanged(s) - - def test_unchanged_2(self): - s = """ - class A(object): - def __nonzero__(self, a): - pass - """ - self.unchanged(s) - - def test_unchanged_func(self): - s = """ - def __nonzero__(self): - pass - """ - self.unchanged(s) - -class Test_numliterals(FixerTestCase): - fixer = "numliterals" - - def test_octal_1(self): - b = """0755""" - a = """0o755""" - self.check(b, a) - - def test_long_int_1(self): - b = """a = 12L""" - a = """a = 12""" - self.check(b, a) - - def test_long_int_2(self): - b = """a = 12l""" - a = """a = 12""" - self.check(b, a) - - def test_long_hex(self): - b = """b = 0x12l""" - a = """b = 0x12""" - self.check(b, a) - - def test_comments_and_spacing(self): - b = """b = 0x12L""" - a = """b = 0x12""" - self.check(b, a) - - b = """b = 0755 # spam""" - a = """b = 0o755 # spam""" - self.check(b, a) - - def test_unchanged_int(self): - s = """5""" - self.unchanged(s) - - def test_unchanged_float(self): - s = """5.0""" - self.unchanged(s) - - def test_unchanged_octal(self): - s = """0o755""" - self.unchanged(s) - - def test_unchanged_hex(self): - s = """0xABC""" - self.unchanged(s) - - def test_unchanged_exp(self): - s = """5.0e10""" - self.unchanged(s) - - def test_unchanged_complex_int(self): - s = """5 + 4j""" - self.unchanged(s) - - def test_unchanged_complex_float(self): - s = """5.4 + 4.9j""" - self.unchanged(s) - - def test_unchanged_complex_bare(self): - s = """4j""" - self.unchanged(s) - s = """4.4j""" - self.unchanged(s) - -class Test_renames(FixerTestCase): - fixer = "renames" - - modules = {"sys": ("maxint", "maxsize"), - } - - def test_import_from(self): - for mod, (old, new) in self.modules.items(): - b = "from %s import %s" % (mod, old) - a = "from %s import %s" % (mod, new) - self.check(b, a) - - s = "from foo import %s" % old - self.unchanged(s) - - def test_import_from_as(self): - for mod, (old, new) in self.modules.items(): - b = "from %s import %s as foo_bar" % (mod, old) - a = "from %s import %s as foo_bar" % (mod, new) - self.check(b, a) - - def test_import_module_usage(self): - for mod, (old, new) in self.modules.items(): - b = """ - import %s - foo(%s, %s.%s) - """ % (mod, mod, mod, old) - a = """ - import %s - foo(%s, %s.%s) - """ % (mod, mod, mod, new) - self.check(b, a) - - def XXX_test_from_import_usage(self): - # not implemented yet - for mod, (old, new) in self.modules.items(): - b = """ - from %s import %s - foo(%s, %s) - """ % (mod, old, mod, old) - a = """ - from %s import %s - foo(%s, %s) - """ % (mod, new, mod, new) - self.check(b, a) - -class Test_unicode(FixerTestCase): - fixer = "unicode" - - def test_whitespace(self): - b = """unicode( x)""" - a = """str( x)""" - self.check(b, a) - - b = """ unicode(x )""" - a = """ str(x )""" - self.check(b, a) - - b = """ u'h'""" - a = """ 'h'""" - self.check(b, a) - - def test_unicode_call(self): - b = """unicode(x, y, z)""" - a = """str(x, y, z)""" - self.check(b, a) - - def test_unichr(self): - b = """unichr(u'h')""" - a = """chr('h')""" - self.check(b, a) - - def test_unicode_literal_1(self): - b = '''u"x"''' - a = '''"x"''' - self.check(b, a) - - def test_unicode_literal_2(self): - b = """ur'x'""" - a = """r'x'""" - self.check(b, a) - - def test_unicode_literal_3(self): - b = """UR'''x''' """ - a = """R'''x''' """ - self.check(b, a) - - def test_native_literal_escape_u(self): - b = """'\\\\\\u20ac\\U0001d121\\\\u20ac'""" - a = """'\\\\\\\\u20ac\\\\U0001d121\\\\u20ac'""" - self.check(b, a) - - b = """r'\\\\\\u20ac\\U0001d121\\\\u20ac'""" - a = """r'\\\\\\u20ac\\U0001d121\\\\u20ac'""" - self.check(b, a) - - def test_bytes_literal_escape_u(self): - b = """b'\\\\\\u20ac\\U0001d121\\\\u20ac'""" - a = """b'\\\\\\u20ac\\U0001d121\\\\u20ac'""" - self.check(b, a) - - b = """br'\\\\\\u20ac\\U0001d121\\\\u20ac'""" - a = """br'\\\\\\u20ac\\U0001d121\\\\u20ac'""" - self.check(b, a) - - def test_unicode_literal_escape_u(self): - b = """u'\\\\\\u20ac\\U0001d121\\\\u20ac'""" - a = """'\\\\\\u20ac\\U0001d121\\\\u20ac'""" - self.check(b, a) - - b = """ur'\\\\\\u20ac\\U0001d121\\\\u20ac'""" - a = """r'\\\\\\u20ac\\U0001d121\\\\u20ac'""" - self.check(b, a) - - def test_native_unicode_literal_escape_u(self): - f = 'from __future__ import unicode_literals\n' - b = f + """'\\\\\\u20ac\\U0001d121\\\\u20ac'""" - a = f + """'\\\\\\u20ac\\U0001d121\\\\u20ac'""" - self.check(b, a) - - b = f + """r'\\\\\\u20ac\\U0001d121\\\\u20ac'""" - a = f + """r'\\\\\\u20ac\\U0001d121\\\\u20ac'""" - self.check(b, a) - -class Test_callable(FixerTestCase): - fixer = "callable" - - def test_prefix_preservation(self): - b = """callable( x)""" - a = """import collections\nisinstance( x, collections.Callable)""" - self.check(b, a) - - b = """if callable(x): pass""" - a = """import collections -if isinstance(x, collections.Callable): pass""" - self.check(b, a) - - def test_callable_call(self): - b = """callable(x)""" - a = """import collections\nisinstance(x, collections.Callable)""" - self.check(b, a) - - def test_global_import(self): - b = """ -def spam(foo): - callable(foo)"""[1:] - a = """ -import collections -def spam(foo): - isinstance(foo, collections.Callable)"""[1:] - self.check(b, a) - - b = """ -import collections -def spam(foo): - callable(foo)"""[1:] - # same output if it was already imported - self.check(b, a) - - b = """ -from collections import * -def spam(foo): - callable(foo)"""[1:] - a = """ -from collections import * -import collections -def spam(foo): - isinstance(foo, collections.Callable)"""[1:] - self.check(b, a) - - b = """ -do_stuff() -do_some_other_stuff() -assert callable(do_stuff)"""[1:] - a = """ -import collections -do_stuff() -do_some_other_stuff() -assert isinstance(do_stuff, collections.Callable)"""[1:] - self.check(b, a) - - b = """ -if isinstance(do_stuff, Callable): - assert callable(do_stuff) - do_stuff(do_stuff) - if not callable(do_stuff): - exit(1) - else: - assert callable(do_stuff) -else: - assert not callable(do_stuff)"""[1:] - a = """ -import collections -if isinstance(do_stuff, Callable): - assert isinstance(do_stuff, collections.Callable) - do_stuff(do_stuff) - if not isinstance(do_stuff, collections.Callable): - exit(1) - else: - assert isinstance(do_stuff, collections.Callable) -else: - assert not isinstance(do_stuff, collections.Callable)"""[1:] - self.check(b, a) - - def test_callable_should_not_change(self): - a = """callable(*x)""" - self.unchanged(a) - - a = """callable(x, y)""" - self.unchanged(a) - - a = """callable(x, kw=y)""" - self.unchanged(a) - - a = """callable()""" - self.unchanged(a) - -class Test_filter(FixerTestCase): - fixer = "filter" - - def test_prefix_preservation(self): - b = """x = filter( foo, 'abc' )""" - a = """x = list(filter( foo, 'abc' ))""" - self.check(b, a) - - b = """x = filter( None , 'abc' )""" - a = """x = [_f for _f in 'abc' if _f]""" - self.check(b, a) - - def test_filter_basic(self): - b = """x = filter(None, 'abc')""" - a = """x = [_f for _f in 'abc' if _f]""" - self.check(b, a) - - b = """x = len(filter(f, 'abc'))""" - a = """x = len(list(filter(f, 'abc')))""" - self.check(b, a) - - b = """x = filter(lambda x: x%2 == 0, range(10))""" - a = """x = [x for x in range(10) if x%2 == 0]""" - self.check(b, a) - - # Note the parens around x - b = """x = filter(lambda (x): x%2 == 0, range(10))""" - a = """x = [x for x in range(10) if x%2 == 0]""" - self.check(b, a) - - # XXX This (rare) case is not supported -## b = """x = filter(f, 'abc')[0]""" -## a = """x = list(filter(f, 'abc'))[0]""" -## self.check(b, a) - - def test_filter_nochange(self): - a = """b.join(filter(f, 'abc'))""" - self.unchanged(a) - a = """(a + foo(5)).join(filter(f, 'abc'))""" - self.unchanged(a) - a = """iter(filter(f, 'abc'))""" - self.unchanged(a) - a = """list(filter(f, 'abc'))""" - self.unchanged(a) - a = """list(filter(f, 'abc'))[0]""" - self.unchanged(a) - a = """set(filter(f, 'abc'))""" - self.unchanged(a) - a = """set(filter(f, 'abc')).pop()""" - self.unchanged(a) - a = """tuple(filter(f, 'abc'))""" - self.unchanged(a) - a = """any(filter(f, 'abc'))""" - self.unchanged(a) - a = """all(filter(f, 'abc'))""" - self.unchanged(a) - a = """sum(filter(f, 'abc'))""" - self.unchanged(a) - a = """sorted(filter(f, 'abc'))""" - self.unchanged(a) - a = """sorted(filter(f, 'abc'), key=blah)""" - self.unchanged(a) - a = """sorted(filter(f, 'abc'), key=blah)[0]""" - self.unchanged(a) - a = """enumerate(filter(f, 'abc'))""" - self.unchanged(a) - a = """enumerate(filter(f, 'abc'), start=1)""" - self.unchanged(a) - a = """for i in filter(f, 'abc'): pass""" - self.unchanged(a) - a = """[x for x in filter(f, 'abc')]""" - self.unchanged(a) - a = """(x for x in filter(f, 'abc'))""" - self.unchanged(a) - - def test_future_builtins(self): - a = "from future_builtins import spam, filter; filter(f, 'ham')" - self.unchanged(a) - - b = """from future_builtins import spam; x = filter(f, 'abc')""" - a = """from future_builtins import spam; x = list(filter(f, 'abc'))""" - self.check(b, a) - - a = "from future_builtins import *; filter(f, 'ham')" - self.unchanged(a) - -class Test_map(FixerTestCase): - fixer = "map" - - def check(self, b, a): - self.unchanged("from future_builtins import map; " + b, a) - super(Test_map, self).check(b, a) - - def test_prefix_preservation(self): - b = """x = map( f, 'abc' )""" - a = """x = list(map( f, 'abc' ))""" - self.check(b, a) - - def test_trailing_comment(self): - b = """x = map(f, 'abc') # foo""" - a = """x = list(map(f, 'abc')) # foo""" - self.check(b, a) - - def test_None_with_multiple_arguments(self): - s = """x = map(None, a, b, c)""" - self.warns_unchanged(s, "cannot convert map(None, ...) with " - "multiple arguments") - - def test_map_basic(self): - b = """x = map(f, 'abc')""" - a = """x = list(map(f, 'abc'))""" - self.check(b, a) - - b = """x = len(map(f, 'abc', 'def'))""" - a = """x = len(list(map(f, 'abc', 'def')))""" - self.check(b, a) - - b = """x = map(None, 'abc')""" - a = """x = list('abc')""" - self.check(b, a) - - b = """x = map(lambda x: x+1, range(4))""" - a = """x = [x+1 for x in range(4)]""" - self.check(b, a) - - # Note the parens around x - b = """x = map(lambda (x): x+1, range(4))""" - a = """x = [x+1 for x in range(4)]""" - self.check(b, a) - - b = """ - foo() - # foo - map(f, x) - """ - a = """ - foo() - # foo - list(map(f, x)) - """ - self.warns(b, a, "You should use a for loop here") - - # XXX This (rare) case is not supported -## b = """x = map(f, 'abc')[0]""" -## a = """x = list(map(f, 'abc'))[0]""" -## self.check(b, a) - - def test_map_nochange(self): - a = """b.join(map(f, 'abc'))""" - self.unchanged(a) - a = """(a + foo(5)).join(map(f, 'abc'))""" - self.unchanged(a) - a = """iter(map(f, 'abc'))""" - self.unchanged(a) - a = """list(map(f, 'abc'))""" - self.unchanged(a) - a = """list(map(f, 'abc'))[0]""" - self.unchanged(a) - a = """set(map(f, 'abc'))""" - self.unchanged(a) - a = """set(map(f, 'abc')).pop()""" - self.unchanged(a) - a = """tuple(map(f, 'abc'))""" - self.unchanged(a) - a = """any(map(f, 'abc'))""" - self.unchanged(a) - a = """all(map(f, 'abc'))""" - self.unchanged(a) - a = """sum(map(f, 'abc'))""" - self.unchanged(a) - a = """sorted(map(f, 'abc'))""" - self.unchanged(a) - a = """sorted(map(f, 'abc'), key=blah)""" - self.unchanged(a) - a = """sorted(map(f, 'abc'), key=blah)[0]""" - self.unchanged(a) - a = """enumerate(map(f, 'abc'))""" - self.unchanged(a) - a = """enumerate(map(f, 'abc'), start=1)""" - self.unchanged(a) - a = """for i in map(f, 'abc'): pass""" - self.unchanged(a) - a = """[x for x in map(f, 'abc')]""" - self.unchanged(a) - a = """(x for x in map(f, 'abc'))""" - self.unchanged(a) - - def test_future_builtins(self): - a = "from future_builtins import spam, map, eggs; map(f, 'ham')" - self.unchanged(a) - - b = """from future_builtins import spam, eggs; x = map(f, 'abc')""" - a = """from future_builtins import spam, eggs; x = list(map(f, 'abc'))""" - self.check(b, a) - - a = "from future_builtins import *; map(f, 'ham')" - self.unchanged(a) - -class Test_zip(FixerTestCase): - fixer = "zip" - - def check(self, b, a): - self.unchanged("from future_builtins import zip; " + b, a) - super(Test_zip, self).check(b, a) - - def test_zip_basic(self): - b = """x = zip(a, b, c)""" - a = """x = list(zip(a, b, c))""" - self.check(b, a) - - b = """x = len(zip(a, b))""" - a = """x = len(list(zip(a, b)))""" - self.check(b, a) - - def test_zip_nochange(self): - a = """b.join(zip(a, b))""" - self.unchanged(a) - a = """(a + foo(5)).join(zip(a, b))""" - self.unchanged(a) - a = """iter(zip(a, b))""" - self.unchanged(a) - a = """list(zip(a, b))""" - self.unchanged(a) - a = """list(zip(a, b))[0]""" - self.unchanged(a) - a = """set(zip(a, b))""" - self.unchanged(a) - a = """set(zip(a, b)).pop()""" - self.unchanged(a) - a = """tuple(zip(a, b))""" - self.unchanged(a) - a = """any(zip(a, b))""" - self.unchanged(a) - a = """all(zip(a, b))""" - self.unchanged(a) - a = """sum(zip(a, b))""" - self.unchanged(a) - a = """sorted(zip(a, b))""" - self.unchanged(a) - a = """sorted(zip(a, b), key=blah)""" - self.unchanged(a) - a = """sorted(zip(a, b), key=blah)[0]""" - self.unchanged(a) - a = """enumerate(zip(a, b))""" - self.unchanged(a) - a = """enumerate(zip(a, b), start=1)""" - self.unchanged(a) - a = """for i in zip(a, b): pass""" - self.unchanged(a) - a = """[x for x in zip(a, b)]""" - self.unchanged(a) - a = """(x for x in zip(a, b))""" - self.unchanged(a) - - def test_future_builtins(self): - a = "from future_builtins import spam, zip, eggs; zip(a, b)" - self.unchanged(a) - - b = """from future_builtins import spam, eggs; x = zip(a, b)""" - a = """from future_builtins import spam, eggs; x = list(zip(a, b))""" - self.check(b, a) - - a = "from future_builtins import *; zip(a, b)" - self.unchanged(a) - -class Test_standarderror(FixerTestCase): - fixer = "standarderror" - - def test(self): - b = """x = StandardError()""" - a = """x = Exception()""" - self.check(b, a) - - b = """x = StandardError(a, b, c)""" - a = """x = Exception(a, b, c)""" - self.check(b, a) - - b = """f(2 + StandardError(a, b, c))""" - a = """f(2 + Exception(a, b, c))""" - self.check(b, a) - -class Test_types(FixerTestCase): - fixer = "types" - - def test_basic_types_convert(self): - b = """types.StringType""" - a = """bytes""" - self.check(b, a) - - b = """types.DictType""" - a = """dict""" - self.check(b, a) - - b = """types . IntType""" - a = """int""" - self.check(b, a) - - b = """types.ListType""" - a = """list""" - self.check(b, a) - - b = """types.LongType""" - a = """int""" - self.check(b, a) - - b = """types.NoneType""" - a = """type(None)""" - self.check(b, a) - -class Test_idioms(FixerTestCase): - fixer = "idioms" - - def test_while(self): - b = """while 1: foo()""" - a = """while True: foo()""" - self.check(b, a) - - b = """while 1: foo()""" - a = """while True: foo()""" - self.check(b, a) - - b = """ - while 1: - foo() - """ - a = """ - while True: - foo() - """ - self.check(b, a) - - def test_while_unchanged(self): - s = """while 11: foo()""" - self.unchanged(s) - - s = """while 0: foo()""" - self.unchanged(s) - - s = """while foo(): foo()""" - self.unchanged(s) - - s = """while []: foo()""" - self.unchanged(s) - - def test_eq_simple(self): - b = """type(x) == T""" - a = """isinstance(x, T)""" - self.check(b, a) - - b = """if type(x) == T: pass""" - a = """if isinstance(x, T): pass""" - self.check(b, a) - - def test_eq_reverse(self): - b = """T == type(x)""" - a = """isinstance(x, T)""" - self.check(b, a) - - b = """if T == type(x): pass""" - a = """if isinstance(x, T): pass""" - self.check(b, a) - - def test_eq_expression(self): - b = """type(x+y) == d.get('T')""" - a = """isinstance(x+y, d.get('T'))""" - self.check(b, a) - - b = """type( x + y) == d.get('T')""" - a = """isinstance(x + y, d.get('T'))""" - self.check(b, a) - - def test_is_simple(self): - b = """type(x) is T""" - a = """isinstance(x, T)""" - self.check(b, a) - - b = """if type(x) is T: pass""" - a = """if isinstance(x, T): pass""" - self.check(b, a) - - def test_is_reverse(self): - b = """T is type(x)""" - a = """isinstance(x, T)""" - self.check(b, a) - - b = """if T is type(x): pass""" - a = """if isinstance(x, T): pass""" - self.check(b, a) - - def test_is_expression(self): - b = """type(x+y) is d.get('T')""" - a = """isinstance(x+y, d.get('T'))""" - self.check(b, a) - - b = """type( x + y) is d.get('T')""" - a = """isinstance(x + y, d.get('T'))""" - self.check(b, a) - - def test_is_not_simple(self): - b = """type(x) is not T""" - a = """not isinstance(x, T)""" - self.check(b, a) - - b = """if type(x) is not T: pass""" - a = """if not isinstance(x, T): pass""" - self.check(b, a) - - def test_is_not_reverse(self): - b = """T is not type(x)""" - a = """not isinstance(x, T)""" - self.check(b, a) - - b = """if T is not type(x): pass""" - a = """if not isinstance(x, T): pass""" - self.check(b, a) - - def test_is_not_expression(self): - b = """type(x+y) is not d.get('T')""" - a = """not isinstance(x+y, d.get('T'))""" - self.check(b, a) - - b = """type( x + y) is not d.get('T')""" - a = """not isinstance(x + y, d.get('T'))""" - self.check(b, a) - - def test_ne_simple(self): - b = """type(x) != T""" - a = """not isinstance(x, T)""" - self.check(b, a) - - b = """if type(x) != T: pass""" - a = """if not isinstance(x, T): pass""" - self.check(b, a) - - def test_ne_reverse(self): - b = """T != type(x)""" - a = """not isinstance(x, T)""" - self.check(b, a) - - b = """if T != type(x): pass""" - a = """if not isinstance(x, T): pass""" - self.check(b, a) - - def test_ne_expression(self): - b = """type(x+y) != d.get('T')""" - a = """not isinstance(x+y, d.get('T'))""" - self.check(b, a) - - b = """type( x + y) != d.get('T')""" - a = """not isinstance(x + y, d.get('T'))""" - self.check(b, a) - - def test_type_unchanged(self): - a = """type(x).__name__""" - self.unchanged(a) - - def test_sort_list_call(self): - b = """ - v = list(t) - v.sort() - foo(v) - """ - a = """ - v = sorted(t) - foo(v) - """ - self.check(b, a) - - b = """ - v = list(foo(b) + d) - v.sort() - foo(v) - """ - a = """ - v = sorted(foo(b) + d) - foo(v) - """ - self.check(b, a) - - b = """ - while x: - v = list(t) - v.sort() - foo(v) - """ - a = """ - while x: - v = sorted(t) - foo(v) - """ - self.check(b, a) - - b = """ - v = list(t) - # foo - v.sort() - foo(v) - """ - a = """ - v = sorted(t) - # foo - foo(v) - """ - self.check(b, a) - - b = r""" - v = list( t) - v.sort() - foo(v) - """ - a = r""" - v = sorted( t) - foo(v) - """ - self.check(b, a) - - b = r""" - try: - m = list(s) - m.sort() - except: pass - """ - - a = r""" - try: - m = sorted(s) - except: pass - """ - self.check(b, a) - - b = r""" - try: - m = list(s) - # foo - m.sort() - except: pass - """ - - a = r""" - try: - m = sorted(s) - # foo - except: pass - """ - self.check(b, a) - - b = r""" - m = list(s) - # more comments - m.sort()""" - - a = r""" - m = sorted(s) - # more comments""" - self.check(b, a) - - def test_sort_simple_expr(self): - b = """ - v = t - v.sort() - foo(v) - """ - a = """ - v = sorted(t) - foo(v) - """ - self.check(b, a) - - b = """ - v = foo(b) - v.sort() - foo(v) - """ - a = """ - v = sorted(foo(b)) - foo(v) - """ - self.check(b, a) - - b = """ - v = b.keys() - v.sort() - foo(v) - """ - a = """ - v = sorted(b.keys()) - foo(v) - """ - self.check(b, a) - - b = """ - v = foo(b) + d - v.sort() - foo(v) - """ - a = """ - v = sorted(foo(b) + d) - foo(v) - """ - self.check(b, a) - - b = """ - while x: - v = t - v.sort() - foo(v) - """ - a = """ - while x: - v = sorted(t) - foo(v) - """ - self.check(b, a) - - b = """ - v = t - # foo - v.sort() - foo(v) - """ - a = """ - v = sorted(t) - # foo - foo(v) - """ - self.check(b, a) - - b = r""" - v = t - v.sort() - foo(v) - """ - a = r""" - v = sorted(t) - foo(v) - """ - self.check(b, a) - - def test_sort_unchanged(self): - s = """ - v = list(t) - w.sort() - foo(w) - """ - self.unchanged(s) - - s = """ - v = list(t) - v.sort(u) - foo(v) - """ - self.unchanged(s) - -class Test_basestring(FixerTestCase): - fixer = "basestring" - - def test_basestring(self): - b = """isinstance(x, basestring)""" - a = """isinstance(x, str)""" - self.check(b, a) - -class Test_buffer(FixerTestCase): - fixer = "buffer" - - def test_buffer(self): - b = """x = buffer(y)""" - a = """x = memoryview(y)""" - self.check(b, a) - - def test_slicing(self): - b = """buffer(y)[4:5]""" - a = """memoryview(y)[4:5]""" - self.check(b, a) - -class Test_future(FixerTestCase): - fixer = "future" - - def test_future(self): - b = """from __future__ import braces""" - a = """""" - self.check(b, a) - - b = """# comment\nfrom __future__ import braces""" - a = """# comment\n""" - self.check(b, a) - - b = """from __future__ import braces\n# comment""" - a = """\n# comment""" - self.check(b, a) - - def test_run_order(self): - self.assert_runs_after('print') - -class Test_itertools(FixerTestCase): - fixer = "itertools" - - def checkall(self, before, after): - # Because we need to check with and without the itertools prefix - # and on each of the three functions, these loops make it all - # much easier - for i in ('itertools.', ''): - for f in ('map', 'filter', 'zip'): - b = before %(i+'i'+f) - a = after %(f) - self.check(b, a) - - def test_0(self): - # A simple example -- test_1 covers exactly the same thing, - # but it's not quite as clear. - b = "itertools.izip(a, b)" - a = "zip(a, b)" - self.check(b, a) - - def test_1(self): - b = """%s(f, a)""" - a = """%s(f, a)""" - self.checkall(b, a) - - def test_qualified(self): - b = """itertools.ifilterfalse(a, b)""" - a = """itertools.filterfalse(a, b)""" - self.check(b, a) - - b = """itertools.izip_longest(a, b)""" - a = """itertools.zip_longest(a, b)""" - self.check(b, a) - - def test_2(self): - b = """ifilterfalse(a, b)""" - a = """filterfalse(a, b)""" - self.check(b, a) - - b = """izip_longest(a, b)""" - a = """zip_longest(a, b)""" - self.check(b, a) - - def test_space_1(self): - b = """ %s(f, a)""" - a = """ %s(f, a)""" - self.checkall(b, a) - - def test_space_2(self): - b = """ itertools.ifilterfalse(a, b)""" - a = """ itertools.filterfalse(a, b)""" - self.check(b, a) - - b = """ itertools.izip_longest(a, b)""" - a = """ itertools.zip_longest(a, b)""" - self.check(b, a) - - def test_run_order(self): - self.assert_runs_after('map', 'zip', 'filter') - - -class Test_itertools_imports(FixerTestCase): - fixer = 'itertools_imports' - - def test_reduced(self): - b = "from itertools import imap, izip, foo" - a = "from itertools import foo" - self.check(b, a) - - b = "from itertools import bar, imap, izip, foo" - a = "from itertools import bar, foo" - self.check(b, a) - - b = "from itertools import chain, imap, izip" - a = "from itertools import chain" - self.check(b, a) - - def test_comments(self): - b = "#foo\nfrom itertools import imap, izip" - a = "#foo\n" - self.check(b, a) - - def test_none(self): - b = "from itertools import imap, izip" - a = "" - self.check(b, a) - - b = "from itertools import izip" - a = "" - self.check(b, a) - - def test_import_as(self): - b = "from itertools import izip, bar as bang, imap" - a = "from itertools import bar as bang" - self.check(b, a) - - b = "from itertools import izip as _zip, imap, bar" - a = "from itertools import bar" - self.check(b, a) - - b = "from itertools import imap as _map" - a = "" - self.check(b, a) - - b = "from itertools import imap as _map, izip as _zip" - a = "" - self.check(b, a) - - s = "from itertools import bar as bang" - self.unchanged(s) - - def test_ifilter_and_zip_longest(self): - for name in "filterfalse", "zip_longest": - b = "from itertools import i%s" % (name,) - a = "from itertools import %s" % (name,) - self.check(b, a) - - b = "from itertools import imap, i%s, foo" % (name,) - a = "from itertools import %s, foo" % (name,) - self.check(b, a) - - b = "from itertools import bar, i%s, foo" % (name,) - a = "from itertools import bar, %s, foo" % (name,) - self.check(b, a) - - def test_import_star(self): - s = "from itertools import *" - self.unchanged(s) - - - def test_unchanged(self): - s = "from itertools import foo" - self.unchanged(s) - - -class Test_import(FixerTestCase): - fixer = "import" - - def setUp(self): - super(Test_import, self).setUp() - # Need to replace fix_import's exists method - # so we can check that it's doing the right thing - self.files_checked = [] - self.present_files = set() - self.always_exists = True - def fake_exists(name): - self.files_checked.append(name) - return self.always_exists or (name in self.present_files) - - from lib2to3.fixes import fix_import - fix_import.exists = fake_exists - - def tearDown(self): - from lib2to3.fixes import fix_import - fix_import.exists = os.path.exists - - def check_both(self, b, a): - self.always_exists = True - super(Test_import, self).check(b, a) - self.always_exists = False - super(Test_import, self).unchanged(b) - - def test_files_checked(self): - def p(path): - # Takes a unix path and returns a path with correct separators - return os.path.pathsep.join(path.split("/")) - - self.always_exists = False - self.present_files = set(['__init__.py']) - expected_extensions = ('.py', os.path.sep, '.pyc', '.so', '.sl', '.pyd') - names_to_test = (p("/spam/eggs.py"), "ni.py", p("../../shrubbery.py")) - - for name in names_to_test: - self.files_checked = [] - self.filename = name - self.unchanged("import jam") - - if os.path.dirname(name): - name = os.path.dirname(name) + '/jam' - else: - name = 'jam' - expected_checks = set(name + ext for ext in expected_extensions) - expected_checks.add("__init__.py") - - self.assertEqual(set(self.files_checked), expected_checks) - - def test_not_in_package(self): - s = "import bar" - self.always_exists = False - self.present_files = set(["bar.py"]) - self.unchanged(s) - - def test_with_absolute_import_enabled(self): - s = "from __future__ import absolute_import\nimport bar" - self.always_exists = False - self.present_files = set(["__init__.py", "bar.py"]) - self.unchanged(s) - - def test_in_package(self): - b = "import bar" - a = "from . import bar" - self.always_exists = False - self.present_files = set(["__init__.py", "bar.py"]) - self.check(b, a) - - def test_import_from_package(self): - b = "import bar" - a = "from . import bar" - self.always_exists = False - self.present_files = set(["__init__.py", "bar" + os.path.sep]) - self.check(b, a) - - def test_already_relative_import(self): - s = "from . import bar" - self.unchanged(s) - - def test_comments_and_indent(self): - b = "import bar # Foo" - a = "from . import bar # Foo" - self.check(b, a) - - def test_from(self): - b = "from foo import bar, baz" - a = "from .foo import bar, baz" - self.check_both(b, a) - - b = "from foo import bar" - a = "from .foo import bar" - self.check_both(b, a) - - b = "from foo import (bar, baz)" - a = "from .foo import (bar, baz)" - self.check_both(b, a) - - def test_dotted_from(self): - b = "from green.eggs import ham" - a = "from .green.eggs import ham" - self.check_both(b, a) - - def test_from_as(self): - b = "from green.eggs import ham as spam" - a = "from .green.eggs import ham as spam" - self.check_both(b, a) - - def test_import(self): - b = "import foo" - a = "from . import foo" - self.check_both(b, a) - - b = "import foo, bar" - a = "from . import foo, bar" - self.check_both(b, a) - - b = "import foo, bar, x" - a = "from . import foo, bar, x" - self.check_both(b, a) - - b = "import x, y, z" - a = "from . import x, y, z" - self.check_both(b, a) - - def test_import_as(self): - b = "import foo as x" - a = "from . import foo as x" - self.check_both(b, a) - - b = "import a as b, b as c, c as d" - a = "from . import a as b, b as c, c as d" - self.check_both(b, a) - - def test_local_and_absolute(self): - self.always_exists = False - self.present_files = set(["foo.py", "__init__.py"]) - - s = "import foo, bar" - self.warns_unchanged(s, "absolute and local imports together") - - def test_dotted_import(self): - b = "import foo.bar" - a = "from . import foo.bar" - self.check_both(b, a) - - def test_dotted_import_as(self): - b = "import foo.bar as bang" - a = "from . import foo.bar as bang" - self.check_both(b, a) - - def test_prefix(self): - b = """ - # prefix - import foo.bar - """ - a = """ - # prefix - from . import foo.bar - """ - self.check_both(b, a) - - -class Test_set_literal(FixerTestCase): - - fixer = "set_literal" - - def test_basic(self): - b = """set([1, 2, 3])""" - a = """{1, 2, 3}""" - self.check(b, a) - - b = """set((1, 2, 3))""" - a = """{1, 2, 3}""" - self.check(b, a) - - b = """set((1,))""" - a = """{1}""" - self.check(b, a) - - b = """set([1])""" - self.check(b, a) - - b = """set((a, b))""" - a = """{a, b}""" - self.check(b, a) - - b = """set([a, b])""" - self.check(b, a) - - b = """set((a*234, f(args=23)))""" - a = """{a*234, f(args=23)}""" - self.check(b, a) - - b = """set([a*23, f(23)])""" - a = """{a*23, f(23)}""" - self.check(b, a) - - b = """set([a-234**23])""" - a = """{a-234**23}""" - self.check(b, a) - - def test_listcomps(self): - b = """set([x for x in y])""" - a = """{x for x in y}""" - self.check(b, a) - - b = """set([x for x in y if x == m])""" - a = """{x for x in y if x == m}""" - self.check(b, a) - - b = """set([x for x in y for a in b])""" - a = """{x for x in y for a in b}""" - self.check(b, a) - - b = """set([f(x) - 23 for x in y])""" - a = """{f(x) - 23 for x in y}""" - self.check(b, a) - - def test_whitespace(self): - b = """set( [1, 2])""" - a = """{1, 2}""" - self.check(b, a) - - b = """set([1 , 2])""" - a = """{1 , 2}""" - self.check(b, a) - - b = """set([ 1 ])""" - a = """{ 1 }""" - self.check(b, a) - - b = """set( [1] )""" - a = """{1}""" - self.check(b, a) - - b = """set([ 1, 2 ])""" - a = """{ 1, 2 }""" - self.check(b, a) - - b = """set([x for x in y ])""" - a = """{x for x in y }""" - self.check(b, a) - - b = """set( - [1, 2] - ) - """ - a = """{1, 2}\n""" - self.check(b, a) - - def test_comments(self): - b = """set((1, 2)) # Hi""" - a = """{1, 2} # Hi""" - self.check(b, a) - - # This isn't optimal behavior, but the fixer is optional. - b = """ - # Foo - set( # Bar - (1, 2) - ) - """ - a = """ - # Foo - {1, 2} - """ - self.check(b, a) - - def test_unchanged(self): - s = """set()""" - self.unchanged(s) - - s = """set(a)""" - self.unchanged(s) - - s = """set(a, b, c)""" - self.unchanged(s) - - # Don't transform generators because they might have to be lazy. - s = """set(x for x in y)""" - self.unchanged(s) - - s = """set(x for x in y if z)""" - self.unchanged(s) - - s = """set(a*823-23**2 + f(23))""" - self.unchanged(s) - - -class Test_sys_exc(FixerTestCase): - fixer = "sys_exc" - - def test_0(self): - b = "sys.exc_type" - a = "sys.exc_info()[0]" - self.check(b, a) - - def test_1(self): - b = "sys.exc_value" - a = "sys.exc_info()[1]" - self.check(b, a) - - def test_2(self): - b = "sys.exc_traceback" - a = "sys.exc_info()[2]" - self.check(b, a) - - def test_3(self): - b = "sys.exc_type # Foo" - a = "sys.exc_info()[0] # Foo" - self.check(b, a) - - def test_4(self): - b = "sys. exc_type" - a = "sys. exc_info()[0]" - self.check(b, a) - - def test_5(self): - b = "sys .exc_type" - a = "sys .exc_info()[0]" - self.check(b, a) - - -class Test_paren(FixerTestCase): - fixer = "paren" - - def test_0(self): - b = """[i for i in 1, 2 ]""" - a = """[i for i in (1, 2) ]""" - self.check(b, a) - - def test_1(self): - b = """[i for i in 1, 2, ]""" - a = """[i for i in (1, 2,) ]""" - self.check(b, a) - - def test_2(self): - b = """[i for i in 1, 2 ]""" - a = """[i for i in (1, 2) ]""" - self.check(b, a) - - def test_3(self): - b = """[i for i in 1, 2 if i]""" - a = """[i for i in (1, 2) if i]""" - self.check(b, a) - - def test_4(self): - b = """[i for i in 1, 2 ]""" - a = """[i for i in (1, 2) ]""" - self.check(b, a) - - def test_5(self): - b = """(i for i in 1, 2)""" - a = """(i for i in (1, 2))""" - self.check(b, a) - - def test_6(self): - b = """(i for i in 1 ,2 if i)""" - a = """(i for i in (1 ,2) if i)""" - self.check(b, a) - - def test_unchanged_0(self): - s = """[i for i in (1, 2)]""" - self.unchanged(s) - - def test_unchanged_1(self): - s = """[i for i in foo()]""" - self.unchanged(s) - - def test_unchanged_2(self): - s = """[i for i in (1, 2) if nothing]""" - self.unchanged(s) - - def test_unchanged_3(self): - s = """(i for i in (1, 2))""" - self.unchanged(s) - - def test_unchanged_4(self): - s = """[i for i in m]""" - self.unchanged(s) - -class Test_metaclass(FixerTestCase): - - fixer = 'metaclass' - - def test_unchanged(self): - self.unchanged("class X(): pass") - self.unchanged("class X(object): pass") - self.unchanged("class X(object1, object2): pass") - self.unchanged("class X(object1, object2, object3): pass") - self.unchanged("class X(metaclass=Meta): pass") - self.unchanged("class X(b, arg=23, metclass=Meta): pass") - self.unchanged("class X(b, arg=23, metaclass=Meta, other=42): pass") - - s = """ - class X: - def __metaclass__(self): pass - """ - self.unchanged(s) - - s = """ - class X: - a[23] = 74 - """ - self.unchanged(s) - - def test_comments(self): - b = """ - class X: - # hi - __metaclass__ = AppleMeta - """ - a = """ - class X(metaclass=AppleMeta): - # hi - pass - """ - self.check(b, a) - - b = """ - class X: - __metaclass__ = Meta - # Bedtime! - """ - a = """ - class X(metaclass=Meta): - pass - # Bedtime! - """ - self.check(b, a) - - def test_meta(self): - # no-parent class, odd body - b = """ - class X(): - __metaclass__ = Q - pass - """ - a = """ - class X(metaclass=Q): - pass - """ - self.check(b, a) - - # one parent class, no body - b = """class X(object): __metaclass__ = Q""" - a = """class X(object, metaclass=Q): pass""" - self.check(b, a) - - - # one parent, simple body - b = """ - class X(object): - __metaclass__ = Meta - bar = 7 - """ - a = """ - class X(object, metaclass=Meta): - bar = 7 - """ - self.check(b, a) - - b = """ - class X: - __metaclass__ = Meta; x = 4; g = 23 - """ - a = """ - class X(metaclass=Meta): - x = 4; g = 23 - """ - self.check(b, a) - - # one parent, simple body, __metaclass__ last - b = """ - class X(object): - bar = 7 - __metaclass__ = Meta - """ - a = """ - class X(object, metaclass=Meta): - bar = 7 - """ - self.check(b, a) - - # redefining __metaclass__ - b = """ - class X(): - __metaclass__ = A - __metaclass__ = B - bar = 7 - """ - a = """ - class X(metaclass=B): - bar = 7 - """ - self.check(b, a) - - # multiple inheritance, simple body - b = """ - class X(clsA, clsB): - __metaclass__ = Meta - bar = 7 - """ - a = """ - class X(clsA, clsB, metaclass=Meta): - bar = 7 - """ - self.check(b, a) - - # keywords in the class statement - b = """class m(a, arg=23): __metaclass__ = Meta""" - a = """class m(a, arg=23, metaclass=Meta): pass""" - self.check(b, a) - - b = """ - class X(expression(2 + 4)): - __metaclass__ = Meta - """ - a = """ - class X(expression(2 + 4), metaclass=Meta): - pass - """ - self.check(b, a) - - b = """ - class X(expression(2 + 4), x**4): - __metaclass__ = Meta - """ - a = """ - class X(expression(2 + 4), x**4, metaclass=Meta): - pass - """ - self.check(b, a) - - b = """ - class X: - __metaclass__ = Meta - save.py = 23 - """ - a = """ - class X(metaclass=Meta): - save.py = 23 - """ - self.check(b, a) - - -class Test_getcwdu(FixerTestCase): - - fixer = 'getcwdu' - - def test_basic(self): - b = """os.getcwdu""" - a = """os.getcwd""" - self.check(b, a) - - b = """os.getcwdu()""" - a = """os.getcwd()""" - self.check(b, a) - - b = """meth = os.getcwdu""" - a = """meth = os.getcwd""" - self.check(b, a) - - b = """os.getcwdu(args)""" - a = """os.getcwd(args)""" - self.check(b, a) - - def test_comment(self): - b = """os.getcwdu() # Foo""" - a = """os.getcwd() # Foo""" - self.check(b, a) - - def test_unchanged(self): - s = """os.getcwd()""" - self.unchanged(s) - - s = """getcwdu()""" - self.unchanged(s) - - s = """os.getcwdb()""" - self.unchanged(s) - - def test_indentation(self): - b = """ - if 1: - os.getcwdu() - """ - a = """ - if 1: - os.getcwd() - """ - self.check(b, a) - - def test_multilation(self): - b = """os .getcwdu()""" - a = """os .getcwd()""" - self.check(b, a) - - b = """os. getcwdu""" - a = """os. getcwd""" - self.check(b, a) - - b = """os.getcwdu ( )""" - a = """os.getcwd ( )""" - self.check(b, a) - - -class Test_operator(FixerTestCase): - - fixer = "operator" - - def test_operator_isCallable(self): - b = "operator.isCallable(x)" - a = "hasattr(x, '__call__')" - self.check(b, a) - - def test_operator_sequenceIncludes(self): - b = "operator.sequenceIncludes(x, y)" - a = "operator.contains(x, y)" - self.check(b, a) - - b = "operator .sequenceIncludes(x, y)" - a = "operator .contains(x, y)" - self.check(b, a) - - b = "operator. sequenceIncludes(x, y)" - a = "operator. contains(x, y)" - self.check(b, a) - - def test_operator_isSequenceType(self): - b = "operator.isSequenceType(x)" - a = "import collections\nisinstance(x, collections.Sequence)" - self.check(b, a) - - def test_operator_isMappingType(self): - b = "operator.isMappingType(x)" - a = "import collections\nisinstance(x, collections.Mapping)" - self.check(b, a) - - def test_operator_isNumberType(self): - b = "operator.isNumberType(x)" - a = "import numbers\nisinstance(x, numbers.Number)" - self.check(b, a) - - def test_operator_repeat(self): - b = "operator.repeat(x, n)" - a = "operator.mul(x, n)" - self.check(b, a) - - b = "operator .repeat(x, n)" - a = "operator .mul(x, n)" - self.check(b, a) - - b = "operator. repeat(x, n)" - a = "operator. mul(x, n)" - self.check(b, a) - - def test_operator_irepeat(self): - b = "operator.irepeat(x, n)" - a = "operator.imul(x, n)" - self.check(b, a) - - b = "operator .irepeat(x, n)" - a = "operator .imul(x, n)" - self.check(b, a) - - b = "operator. irepeat(x, n)" - a = "operator. imul(x, n)" - self.check(b, a) - - def test_bare_isCallable(self): - s = "isCallable(x)" - t = "You should use 'hasattr(x, '__call__')' here." - self.warns_unchanged(s, t) - - def test_bare_sequenceIncludes(self): - s = "sequenceIncludes(x, y)" - t = "You should use 'operator.contains(x, y)' here." - self.warns_unchanged(s, t) - - def test_bare_operator_isSequenceType(self): - s = "isSequenceType(z)" - t = "You should use 'isinstance(z, collections.Sequence)' here." - self.warns_unchanged(s, t) - - def test_bare_operator_isMappingType(self): - s = "isMappingType(x)" - t = "You should use 'isinstance(x, collections.Mapping)' here." - self.warns_unchanged(s, t) - - def test_bare_operator_isNumberType(self): - s = "isNumberType(y)" - t = "You should use 'isinstance(y, numbers.Number)' here." - self.warns_unchanged(s, t) - - def test_bare_operator_repeat(self): - s = "repeat(x, n)" - t = "You should use 'operator.mul(x, n)' here." - self.warns_unchanged(s, t) - - def test_bare_operator_irepeat(self): - s = "irepeat(y, 187)" - t = "You should use 'operator.imul(y, 187)' here." - self.warns_unchanged(s, t) - - -class Test_exitfunc(FixerTestCase): - - fixer = "exitfunc" - - def test_simple(self): - b = """ - import sys - sys.exitfunc = my_atexit - """ - a = """ - import sys - import atexit - atexit.register(my_atexit) - """ - self.check(b, a) - - def test_names_import(self): - b = """ - import sys, crumbs - sys.exitfunc = my_func - """ - a = """ - import sys, crumbs, atexit - atexit.register(my_func) - """ - self.check(b, a) - - def test_complex_expression(self): - b = """ - import sys - sys.exitfunc = do(d)/a()+complex(f=23, g=23)*expression - """ - a = """ - import sys - import atexit - atexit.register(do(d)/a()+complex(f=23, g=23)*expression) - """ - self.check(b, a) - - def test_comments(self): - b = """ - import sys # Foo - sys.exitfunc = f # Blah - """ - a = """ - import sys - import atexit # Foo - atexit.register(f) # Blah - """ - self.check(b, a) - - b = """ - import apples, sys, crumbs, larry # Pleasant comments - sys.exitfunc = func - """ - a = """ - import apples, sys, crumbs, larry, atexit # Pleasant comments - atexit.register(func) - """ - self.check(b, a) - - def test_in_a_function(self): - b = """ - import sys - def f(): - sys.exitfunc = func - """ - a = """ - import sys - import atexit - def f(): - atexit.register(func) - """ - self.check(b, a) - - def test_no_sys_import(self): - b = """sys.exitfunc = f""" - a = """atexit.register(f)""" - msg = ("Can't find sys import; Please add an atexit import at the " - "top of your file.") - self.warns(b, a, msg) - - - def test_unchanged(self): - s = """f(sys.exitfunc)""" - self.unchanged(s) diff --git a/PythonLib/extra/lib2to3/tests/test_main.py b/PythonLib/extra/lib2to3/tests/test_main.py deleted file mode 100644 index 7f8b25ca..00000000 --- a/PythonLib/extra/lib2to3/tests/test_main.py +++ /dev/null @@ -1,149 +0,0 @@ -# -*- coding: utf-8 -*- -import sys -import codecs -import logging -import os -import re -import shutil -import StringIO -import sys -import tempfile -import unittest - -from lib2to3 import main - - -TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), "data") -PY2_TEST_MODULE = os.path.join(TEST_DATA_DIR, "py2_test_grammar.py") - - -class TestMain(unittest.TestCase): - - if not hasattr(unittest.TestCase, 'assertNotRegex'): - # This method was only introduced in 3.2. - def assertNotRegex(self, text, regexp, msg=None): - import re - if not hasattr(regexp, 'search'): - regexp = re.compile(regexp) - if regexp.search(text): - self.fail("regexp %s MATCHED text %r" % (regexp.pattern, text)) - - def setUp(self): - self.temp_dir = None # tearDown() will rmtree this directory if set. - - def tearDown(self): - # Clean up logging configuration down by main. - del logging.root.handlers[:] - if self.temp_dir: - shutil.rmtree(self.temp_dir) - - def run_2to3_capture(self, args, in_capture, out_capture, err_capture): - save_stdin = sys.stdin - save_stdout = sys.stdout - save_stderr = sys.stderr - sys.stdin = in_capture - sys.stdout = out_capture - sys.stderr = err_capture - try: - return main.main("lib2to3.fixes", args) - finally: - sys.stdin = save_stdin - sys.stdout = save_stdout - sys.stderr = save_stderr - - def test_unencodable_diff(self): - input_stream = StringIO.StringIO(u"print 'nothing'\nprint u'über'\n") - out = StringIO.StringIO() - out_enc = codecs.getwriter("ascii")(out) - err = StringIO.StringIO() - ret = self.run_2to3_capture(["-"], input_stream, out_enc, err) - self.assertEqual(ret, 0) - output = out.getvalue() - self.assertTrue("-print 'nothing'" in output) - self.assertTrue("WARNING: couldn't encode 's diff for " - "your terminal" in err.getvalue()) - - def setup_test_source_trees(self): - """Setup a test source tree and output destination tree.""" - self.temp_dir = tempfile.mkdtemp() # tearDown() cleans this up. - self.py2_src_dir = os.path.join(self.temp_dir, "python2_project") - self.py3_dest_dir = os.path.join(self.temp_dir, "python3_project") - os.mkdir(self.py2_src_dir) - os.mkdir(self.py3_dest_dir) - # Turn it into a package with a few files. - self.setup_files = [] - open(os.path.join(self.py2_src_dir, "__init__.py"), "w").close() - self.setup_files.append("__init__.py") - shutil.copy(PY2_TEST_MODULE, self.py2_src_dir) - self.setup_files.append(os.path.basename(PY2_TEST_MODULE)) - self.trivial_py2_file = os.path.join(self.py2_src_dir, "trivial.py") - self.init_py2_file = os.path.join(self.py2_src_dir, "__init__.py") - with open(self.trivial_py2_file, "w") as trivial: - trivial.write("print 'I need a simple conversion.'") - self.setup_files.append("trivial.py") - - def test_filename_changing_on_output_single_dir(self): - """2to3 a single directory with a new output dir and suffix.""" - self.setup_test_source_trees() - out = StringIO.StringIO() - err = StringIO.StringIO() - suffix = "TEST" - ret = self.run_2to3_capture( - ["-n", "--add-suffix", suffix, "--write-unchanged-files", - "--no-diffs", "--output-dir", - self.py3_dest_dir, self.py2_src_dir], - StringIO.StringIO(""), out, err) - self.assertEqual(ret, 0) - stderr = err.getvalue() - self.assertIn(" implies -w.", stderr) - self.assertIn( - "Output in %r will mirror the input directory %r layout" % ( - self.py3_dest_dir, self.py2_src_dir), stderr) - self.assertEqual(set(name+suffix for name in self.setup_files), - set(os.listdir(self.py3_dest_dir))) - for name in self.setup_files: - self.assertIn("Writing converted %s to %s" % ( - os.path.join(self.py2_src_dir, name), - os.path.join(self.py3_dest_dir, name+suffix)), stderr) - sep = re.escape(os.sep) - self.assertRegexpMatches( - stderr, r"No changes to .*/__init__\.py".replace("/", sep)) - self.assertNotRegex( - stderr, r"No changes to .*/trivial\.py".replace("/", sep)) - - def test_filename_changing_on_output_two_files(self): - """2to3 two files in one directory with a new output dir.""" - self.setup_test_source_trees() - err = StringIO.StringIO() - py2_files = [self.trivial_py2_file, self.init_py2_file] - expected_files = set(os.path.basename(name) for name in py2_files) - ret = self.run_2to3_capture( - ["-n", "-w", "--write-unchanged-files", - "--no-diffs", "--output-dir", self.py3_dest_dir] + py2_files, - StringIO.StringIO(""), StringIO.StringIO(), err) - self.assertEqual(ret, 0) - stderr = err.getvalue() - self.assertIn( - "Output in %r will mirror the input directory %r layout" % ( - self.py3_dest_dir, self.py2_src_dir), stderr) - self.assertEqual(expected_files, set(os.listdir(self.py3_dest_dir))) - - def test_filename_changing_on_output_single_file(self): - """2to3 a single file with a new output dir.""" - self.setup_test_source_trees() - err = StringIO.StringIO() - ret = self.run_2to3_capture( - ["-n", "-w", "--no-diffs", "--output-dir", self.py3_dest_dir, - self.trivial_py2_file], - StringIO.StringIO(""), StringIO.StringIO(), err) - self.assertEqual(ret, 0) - stderr = err.getvalue() - self.assertIn( - "Output in %r will mirror the input directory %r layout" % ( - self.py3_dest_dir, self.py2_src_dir), stderr) - self.assertEqual(set([os.path.basename(self.trivial_py2_file)]), - set(os.listdir(self.py3_dest_dir))) - - -if __name__ == '__main__': - unittest.main() diff --git a/PythonLib/extra/lib2to3/tests/test_parser.py b/PythonLib/extra/lib2to3/tests/test_parser.py deleted file mode 100644 index f66cb6b3..00000000 --- a/PythonLib/extra/lib2to3/tests/test_parser.py +++ /dev/null @@ -1,227 +0,0 @@ -"""Test suite for 2to3's parser and grammar files. - -This is the place to add tests for changes to 2to3's grammar, such as those -merging the grammars for Python 2 and 3. In addition to specific tests for -parts of the grammar we've changed, we also make sure we can parse the -test_grammar.py files from both Python 2 and Python 3. -""" - -from __future__ import with_statement - -# Testing imports -from . import support -from .support import driver, test_dir - -# Python imports -import os -import sys - -# Local imports -from lib2to3.pgen2 import tokenize -from ..pgen2.parse import ParseError -from lib2to3.pygram import python_symbols as syms - - -class TestDriver(support.TestCase): - - def test_formfeed(self): - s = """print 1\n\x0Cprint 2\n""" - t = driver.parse_string(s) - self.assertEqual(t.children[0].children[0].type, syms.print_stmt) - self.assertEqual(t.children[1].children[0].type, syms.print_stmt) - - -class GrammarTest(support.TestCase): - def validate(self, code): - support.parse_string(code) - - def invalid_syntax(self, code): - try: - self.validate(code) - except ParseError: - pass - else: - raise AssertionError("Syntax shouldn't have been valid") - - -class TestRaiseChanges(GrammarTest): - def test_2x_style_1(self): - self.validate("raise") - - def test_2x_style_2(self): - self.validate("raise E, V") - - def test_2x_style_3(self): - self.validate("raise E, V, T") - - def test_2x_style_invalid_1(self): - self.invalid_syntax("raise E, V, T, Z") - - def test_3x_style(self): - self.validate("raise E1 from E2") - - def test_3x_style_invalid_1(self): - self.invalid_syntax("raise E, V from E1") - - def test_3x_style_invalid_2(self): - self.invalid_syntax("raise E from E1, E2") - - def test_3x_style_invalid_3(self): - self.invalid_syntax("raise from E1, E2") - - def test_3x_style_invalid_4(self): - self.invalid_syntax("raise E from") - - -# Adaptated from Python 3's Lib/test/test_grammar.py:GrammarTests.testFuncdef -class TestFunctionAnnotations(GrammarTest): - def test_1(self): - self.validate("""def f(x) -> list: pass""") - - def test_2(self): - self.validate("""def f(x:int): pass""") - - def test_3(self): - self.validate("""def f(*x:str): pass""") - - def test_4(self): - self.validate("""def f(**x:float): pass""") - - def test_5(self): - self.validate("""def f(x, y:1+2): pass""") - - def test_6(self): - self.validate("""def f(a, (b:1, c:2, d)): pass""") - - def test_7(self): - self.validate("""def f(a, (b:1, c:2, d), e:3=4, f=5, *g:6): pass""") - - def test_8(self): - s = """def f(a, (b:1, c:2, d), e:3=4, f=5, - *g:6, h:7, i=8, j:9=10, **k:11) -> 12: pass""" - self.validate(s) - - -class TestExcept(GrammarTest): - def test_new(self): - s = """ - try: - x - except E as N: - y""" - self.validate(s) - - def test_old(self): - s = """ - try: - x - except E, N: - y""" - self.validate(s) - - -# Adapted from Python 3's Lib/test/test_grammar.py:GrammarTests.testAtoms -class TestSetLiteral(GrammarTest): - def test_1(self): - self.validate("""x = {'one'}""") - - def test_2(self): - self.validate("""x = {'one', 1,}""") - - def test_3(self): - self.validate("""x = {'one', 'two', 'three'}""") - - def test_4(self): - self.validate("""x = {2, 3, 4,}""") - - -class TestNumericLiterals(GrammarTest): - def test_new_octal_notation(self): - self.validate("""0o7777777777777""") - self.invalid_syntax("""0o7324528887""") - - def test_new_binary_notation(self): - self.validate("""0b101010""") - self.invalid_syntax("""0b0101021""") - - -class TestClassDef(GrammarTest): - def test_new_syntax(self): - self.validate("class B(t=7): pass") - self.validate("class B(t, *args): pass") - self.validate("class B(t, **kwargs): pass") - self.validate("class B(t, *args, **kwargs): pass") - self.validate("class B(t, y=9, *args, **kwargs): pass") - - -class TestParserIdempotency(support.TestCase): - - """A cut-down version of pytree_idempotency.py.""" - - def test_all_project_files(self): - if sys.platform.startswith("win"): - # XXX something with newlines goes wrong on Windows. - return - for filepath in support.all_project_files(): - with open(filepath, "rb") as fp: - encoding = tokenize.detect_encoding(fp.readline)[0] - self.assertTrue(encoding is not None, - "can't detect encoding for %s" % filepath) - with open(filepath, "r") as fp: - source = fp.read() - source = source.decode(encoding) - tree = driver.parse_string(source) - new = unicode(tree) - if diff(filepath, new, encoding): - self.fail("Idempotency failed: %s" % filepath) - - def test_extended_unpacking(self): - driver.parse_string("a, *b, c = x\n") - driver.parse_string("[*a, b] = x\n") - driver.parse_string("(z, *y, w) = m\n") - driver.parse_string("for *z, m in d: pass\n") - -class TestLiterals(GrammarTest): - - def validate(self, s): - driver.parse_string(support.dedent(s) + "\n\n") - - def test_multiline_bytes_literals(self): - s = """ - md5test(b"\xaa" * 80, - (b"Test Using Larger Than Block-Size Key " - b"and Larger Than One Block-Size Data"), - "6f630fad67cda0ee1fb1f562db3aa53e") - """ - self.validate(s) - - def test_multiline_bytes_tripquote_literals(self): - s = ''' - b""" - - - """ - ''' - self.validate(s) - - def test_multiline_str_literals(self): - s = """ - md5test("\xaa" * 80, - ("Test Using Larger Than Block-Size Key " - "and Larger Than One Block-Size Data"), - "6f630fad67cda0ee1fb1f562db3aa53e") - """ - self.validate(s) - - -def diff(fn, result, encoding): - f = open("@", "w") - try: - f.write(result.encode(encoding)) - finally: - f.close() - try: - fn = fn.replace('"', '\\"') - return os.system('diff -u "%s" @' % fn) - finally: - os.remove("@") diff --git a/PythonLib/extra/lib2to3/tests/test_pytree.py b/PythonLib/extra/lib2to3/tests/test_pytree.py deleted file mode 100644 index ac7d9006..00000000 --- a/PythonLib/extra/lib2to3/tests/test_pytree.py +++ /dev/null @@ -1,494 +0,0 @@ -# Copyright 2006 Google, Inc. All Rights Reserved. -# Licensed to PSF under a Contributor Agreement. - -"""Unit tests for pytree.py. - -NOTE: Please *don't* add doc strings to individual test methods! -In verbose mode, printing of the module, class and method name is much -more helpful than printing of (the first line of) the docstring, -especially when debugging a test. -""" - -from __future__ import with_statement - -import sys -import warnings - -# Testing imports -from . import support - -from lib2to3 import pytree - -try: - sorted -except NameError: - def sorted(lst): - l = list(lst) - l.sort() - return l - -class TestNodes(support.TestCase): - - """Unit tests for nodes (Base, Leaf, Node).""" - - if sys.version_info >= (2,6): - # warnings.catch_warnings is new in 2.6. - def test_deprecated_prefix_methods(self): - l = pytree.Leaf(100, "foo") - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter("always", DeprecationWarning) - self.assertEqual(l.get_prefix(), "") - l.set_prefix("hi") - self.assertEqual(l.prefix, "hi") - self.assertEqual(len(w), 2) - for warning in w: - self.assertTrue(warning.category is DeprecationWarning) - self.assertEqual(str(w[0].message), "get_prefix() is deprecated; " \ - "use the prefix property") - self.assertEqual(str(w[1].message), "set_prefix() is deprecated; " \ - "use the prefix property") - - def test_instantiate_base(self): - if __debug__: - # Test that instantiating Base() raises an AssertionError - self.assertRaises(AssertionError, pytree.Base) - - def test_leaf(self): - l1 = pytree.Leaf(100, "foo") - self.assertEqual(l1.type, 100) - self.assertEqual(l1.value, "foo") - - def test_leaf_repr(self): - l1 = pytree.Leaf(100, "foo") - self.assertEqual(repr(l1), "Leaf(100, 'foo')") - - def test_leaf_str(self): - l1 = pytree.Leaf(100, "foo") - self.assertEqual(str(l1), "foo") - l2 = pytree.Leaf(100, "foo", context=(" ", (10, 1))) - self.assertEqual(str(l2), " foo") - - def test_leaf_str_numeric_value(self): - # Make sure that the Leaf's value is stringified. Failing to - # do this can cause a TypeError in certain situations. - l1 = pytree.Leaf(2, 5) - l1.prefix = "foo_" - self.assertEqual(str(l1), "foo_5") - - def test_leaf_equality(self): - l1 = pytree.Leaf(100, "foo") - l2 = pytree.Leaf(100, "foo", context=(" ", (1, 0))) - self.assertEqual(l1, l2) - l3 = pytree.Leaf(101, "foo") - l4 = pytree.Leaf(100, "bar") - self.assertNotEqual(l1, l3) - self.assertNotEqual(l1, l4) - - def test_leaf_prefix(self): - l1 = pytree.Leaf(100, "foo") - self.assertEqual(l1.prefix, "") - self.assertFalse(l1.was_changed) - l1.prefix = " ##\n\n" - self.assertEqual(l1.prefix, " ##\n\n") - self.assertTrue(l1.was_changed) - - def test_node(self): - l1 = pytree.Leaf(100, "foo") - l2 = pytree.Leaf(200, "bar") - n1 = pytree.Node(1000, [l1, l2]) - self.assertEqual(n1.type, 1000) - self.assertEqual(n1.children, [l1, l2]) - - def test_node_repr(self): - l1 = pytree.Leaf(100, "foo") - l2 = pytree.Leaf(100, "bar", context=(" ", (1, 0))) - n1 = pytree.Node(1000, [l1, l2]) - self.assertEqual(repr(n1), - "Node(1000, [%s, %s])" % (repr(l1), repr(l2))) - - def test_node_str(self): - l1 = pytree.Leaf(100, "foo") - l2 = pytree.Leaf(100, "bar", context=(" ", (1, 0))) - n1 = pytree.Node(1000, [l1, l2]) - self.assertEqual(str(n1), "foo bar") - - def test_node_prefix(self): - l1 = pytree.Leaf(100, "foo") - self.assertEqual(l1.prefix, "") - n1 = pytree.Node(1000, [l1]) - self.assertEqual(n1.prefix, "") - n1.prefix = " " - self.assertEqual(n1.prefix, " ") - self.assertEqual(l1.prefix, " ") - - def test_get_suffix(self): - l1 = pytree.Leaf(100, "foo", prefix="a") - l2 = pytree.Leaf(100, "bar", prefix="b") - n1 = pytree.Node(1000, [l1, l2]) - - self.assertEqual(l1.get_suffix(), l2.prefix) - self.assertEqual(l2.get_suffix(), "") - self.assertEqual(n1.get_suffix(), "") - - l3 = pytree.Leaf(100, "bar", prefix="c") - n2 = pytree.Node(1000, [n1, l3]) - - self.assertEqual(n1.get_suffix(), l3.prefix) - self.assertEqual(l3.get_suffix(), "") - self.assertEqual(n2.get_suffix(), "") - - def test_node_equality(self): - n1 = pytree.Node(1000, ()) - n2 = pytree.Node(1000, [], context=(" ", (1, 0))) - self.assertEqual(n1, n2) - n3 = pytree.Node(1001, ()) - self.assertNotEqual(n1, n3) - - def test_node_recursive_equality(self): - l1 = pytree.Leaf(100, "foo") - l2 = pytree.Leaf(100, "foo") - n1 = pytree.Node(1000, [l1]) - n2 = pytree.Node(1000, [l2]) - self.assertEqual(n1, n2) - l3 = pytree.Leaf(100, "bar") - n3 = pytree.Node(1000, [l3]) - self.assertNotEqual(n1, n3) - - def test_replace(self): - l1 = pytree.Leaf(100, "foo") - l2 = pytree.Leaf(100, "+") - l3 = pytree.Leaf(100, "bar") - n1 = pytree.Node(1000, [l1, l2, l3]) - self.assertEqual(n1.children, [l1, l2, l3]) - self.assertTrue(isinstance(n1.children, list)) - self.assertFalse(n1.was_changed) - l2new = pytree.Leaf(100, "-") - l2.replace(l2new) - self.assertEqual(n1.children, [l1, l2new, l3]) - self.assertTrue(isinstance(n1.children, list)) - self.assertTrue(n1.was_changed) - - def test_replace_with_list(self): - l1 = pytree.Leaf(100, "foo") - l2 = pytree.Leaf(100, "+") - l3 = pytree.Leaf(100, "bar") - n1 = pytree.Node(1000, [l1, l2, l3]) - - l2.replace([pytree.Leaf(100, "*"), pytree.Leaf(100, "*")]) - self.assertEqual(str(n1), "foo**bar") - self.assertTrue(isinstance(n1.children, list)) - - def test_leaves(self): - l1 = pytree.Leaf(100, "foo") - l2 = pytree.Leaf(100, "bar") - l3 = pytree.Leaf(100, "fooey") - n2 = pytree.Node(1000, [l1, l2]) - n3 = pytree.Node(1000, [l3]) - n1 = pytree.Node(1000, [n2, n3]) - - self.assertEqual(list(n1.leaves()), [l1, l2, l3]) - - def test_depth(self): - l1 = pytree.Leaf(100, "foo") - l2 = pytree.Leaf(100, "bar") - n2 = pytree.Node(1000, [l1, l2]) - n3 = pytree.Node(1000, []) - n1 = pytree.Node(1000, [n2, n3]) - - self.assertEqual(l1.depth(), 2) - self.assertEqual(n3.depth(), 1) - self.assertEqual(n1.depth(), 0) - - def test_post_order(self): - l1 = pytree.Leaf(100, "foo") - l2 = pytree.Leaf(100, "bar") - l3 = pytree.Leaf(100, "fooey") - c1 = pytree.Node(1000, [l1, l2]) - n1 = pytree.Node(1000, [c1, l3]) - self.assertEqual(list(n1.post_order()), [l1, l2, c1, l3, n1]) - - def test_pre_order(self): - l1 = pytree.Leaf(100, "foo") - l2 = pytree.Leaf(100, "bar") - l3 = pytree.Leaf(100, "fooey") - c1 = pytree.Node(1000, [l1, l2]) - n1 = pytree.Node(1000, [c1, l3]) - self.assertEqual(list(n1.pre_order()), [n1, c1, l1, l2, l3]) - - def test_changed(self): - l1 = pytree.Leaf(100, "f") - self.assertFalse(l1.was_changed) - l1.changed() - self.assertTrue(l1.was_changed) - - l1 = pytree.Leaf(100, "f") - n1 = pytree.Node(1000, [l1]) - self.assertFalse(n1.was_changed) - n1.changed() - self.assertTrue(n1.was_changed) - - l1 = pytree.Leaf(100, "foo") - l2 = pytree.Leaf(100, "+") - l3 = pytree.Leaf(100, "bar") - n1 = pytree.Node(1000, [l1, l2, l3]) - n2 = pytree.Node(1000, [n1]) - self.assertFalse(l1.was_changed) - self.assertFalse(n1.was_changed) - self.assertFalse(n2.was_changed) - - n1.changed() - self.assertTrue(n1.was_changed) - self.assertTrue(n2.was_changed) - self.assertFalse(l1.was_changed) - - def test_leaf_constructor_prefix(self): - for prefix in ("xyz_", ""): - l1 = pytree.Leaf(100, "self", prefix=prefix) - self.assertTrue(str(l1), prefix + "self") - self.assertEqual(l1.prefix, prefix) - - def test_node_constructor_prefix(self): - for prefix in ("xyz_", ""): - l1 = pytree.Leaf(100, "self") - l2 = pytree.Leaf(100, "foo", prefix="_") - n1 = pytree.Node(1000, [l1, l2], prefix=prefix) - self.assertTrue(str(n1), prefix + "self_foo") - self.assertEqual(n1.prefix, prefix) - self.assertEqual(l1.prefix, prefix) - self.assertEqual(l2.prefix, "_") - - def test_remove(self): - l1 = pytree.Leaf(100, "foo") - l2 = pytree.Leaf(100, "foo") - n1 = pytree.Node(1000, [l1, l2]) - n2 = pytree.Node(1000, [n1]) - - self.assertEqual(n1.remove(), 0) - self.assertEqual(n2.children, []) - self.assertEqual(l1.parent, n1) - self.assertEqual(n1.parent, None) - self.assertEqual(n2.parent, None) - self.assertFalse(n1.was_changed) - self.assertTrue(n2.was_changed) - - self.assertEqual(l2.remove(), 1) - self.assertEqual(l1.remove(), 0) - self.assertEqual(n1.children, []) - self.assertEqual(l1.parent, None) - self.assertEqual(n1.parent, None) - self.assertEqual(n2.parent, None) - self.assertTrue(n1.was_changed) - self.assertTrue(n2.was_changed) - - def test_remove_parentless(self): - n1 = pytree.Node(1000, []) - n1.remove() - self.assertEqual(n1.parent, None) - - l1 = pytree.Leaf(100, "foo") - l1.remove() - self.assertEqual(l1.parent, None) - - def test_node_set_child(self): - l1 = pytree.Leaf(100, "foo") - n1 = pytree.Node(1000, [l1]) - - l2 = pytree.Leaf(100, "bar") - n1.set_child(0, l2) - self.assertEqual(l1.parent, None) - self.assertEqual(l2.parent, n1) - self.assertEqual(n1.children, [l2]) - - n2 = pytree.Node(1000, [l1]) - n2.set_child(0, n1) - self.assertEqual(l1.parent, None) - self.assertEqual(n1.parent, n2) - self.assertEqual(n2.parent, None) - self.assertEqual(n2.children, [n1]) - - self.assertRaises(IndexError, n1.set_child, 4, l2) - # I don't care what it raises, so long as it's an exception - self.assertRaises(Exception, n1.set_child, 0, list) - - def test_node_insert_child(self): - l1 = pytree.Leaf(100, "foo") - n1 = pytree.Node(1000, [l1]) - - l2 = pytree.Leaf(100, "bar") - n1.insert_child(0, l2) - self.assertEqual(l2.parent, n1) - self.assertEqual(n1.children, [l2, l1]) - - l3 = pytree.Leaf(100, "abc") - n1.insert_child(2, l3) - self.assertEqual(n1.children, [l2, l1, l3]) - - # I don't care what it raises, so long as it's an exception - self.assertRaises(Exception, n1.insert_child, 0, list) - - def test_node_append_child(self): - n1 = pytree.Node(1000, []) - - l1 = pytree.Leaf(100, "foo") - n1.append_child(l1) - self.assertEqual(l1.parent, n1) - self.assertEqual(n1.children, [l1]) - - l2 = pytree.Leaf(100, "bar") - n1.append_child(l2) - self.assertEqual(l2.parent, n1) - self.assertEqual(n1.children, [l1, l2]) - - # I don't care what it raises, so long as it's an exception - self.assertRaises(Exception, n1.append_child, list) - - def test_node_next_sibling(self): - n1 = pytree.Node(1000, []) - n2 = pytree.Node(1000, []) - p1 = pytree.Node(1000, [n1, n2]) - - self.assertTrue(n1.next_sibling is n2) - self.assertEqual(n2.next_sibling, None) - self.assertEqual(p1.next_sibling, None) - - def test_leaf_next_sibling(self): - l1 = pytree.Leaf(100, "a") - l2 = pytree.Leaf(100, "b") - p1 = pytree.Node(1000, [l1, l2]) - - self.assertTrue(l1.next_sibling is l2) - self.assertEqual(l2.next_sibling, None) - self.assertEqual(p1.next_sibling, None) - - def test_node_prev_sibling(self): - n1 = pytree.Node(1000, []) - n2 = pytree.Node(1000, []) - p1 = pytree.Node(1000, [n1, n2]) - - self.assertTrue(n2.prev_sibling is n1) - self.assertEqual(n1.prev_sibling, None) - self.assertEqual(p1.prev_sibling, None) - - def test_leaf_prev_sibling(self): - l1 = pytree.Leaf(100, "a") - l2 = pytree.Leaf(100, "b") - p1 = pytree.Node(1000, [l1, l2]) - - self.assertTrue(l2.prev_sibling is l1) - self.assertEqual(l1.prev_sibling, None) - self.assertEqual(p1.prev_sibling, None) - - -class TestPatterns(support.TestCase): - - """Unit tests for tree matching patterns.""" - - def test_basic_patterns(self): - # Build a tree - l1 = pytree.Leaf(100, "foo") - l2 = pytree.Leaf(100, "bar") - l3 = pytree.Leaf(100, "foo") - n1 = pytree.Node(1000, [l1, l2]) - n2 = pytree.Node(1000, [l3]) - root = pytree.Node(1000, [n1, n2]) - # Build a pattern matching a leaf - pl = pytree.LeafPattern(100, "foo", name="pl") - r = {} - self.assertFalse(pl.match(root, results=r)) - self.assertEqual(r, {}) - self.assertFalse(pl.match(n1, results=r)) - self.assertEqual(r, {}) - self.assertFalse(pl.match(n2, results=r)) - self.assertEqual(r, {}) - self.assertTrue(pl.match(l1, results=r)) - self.assertEqual(r, {"pl": l1}) - r = {} - self.assertFalse(pl.match(l2, results=r)) - self.assertEqual(r, {}) - # Build a pattern matching a node - pn = pytree.NodePattern(1000, [pl], name="pn") - self.assertFalse(pn.match(root, results=r)) - self.assertEqual(r, {}) - self.assertFalse(pn.match(n1, results=r)) - self.assertEqual(r, {}) - self.assertTrue(pn.match(n2, results=r)) - self.assertEqual(r, {"pn": n2, "pl": l3}) - r = {} - self.assertFalse(pn.match(l1, results=r)) - self.assertEqual(r, {}) - self.assertFalse(pn.match(l2, results=r)) - self.assertEqual(r, {}) - - def test_wildcard(self): - # Build a tree for testing - l1 = pytree.Leaf(100, "foo") - l2 = pytree.Leaf(100, "bar") - l3 = pytree.Leaf(100, "foo") - n1 = pytree.Node(1000, [l1, l2]) - n2 = pytree.Node(1000, [l3]) - root = pytree.Node(1000, [n1, n2]) - # Build a pattern - pl = pytree.LeafPattern(100, "foo", name="pl") - pn = pytree.NodePattern(1000, [pl], name="pn") - pw = pytree.WildcardPattern([[pn], [pl, pl]], name="pw") - r = {} - self.assertFalse(pw.match_seq([root], r)) - self.assertEqual(r, {}) - self.assertFalse(pw.match_seq([n1], r)) - self.assertEqual(r, {}) - self.assertTrue(pw.match_seq([n2], r)) - # These are easier to debug - self.assertEqual(sorted(r.keys()), ["pl", "pn", "pw"]) - self.assertEqual(r["pl"], l1) - self.assertEqual(r["pn"], n2) - self.assertEqual(r["pw"], [n2]) - # But this is equivalent - self.assertEqual(r, {"pl": l1, "pn": n2, "pw": [n2]}) - r = {} - self.assertTrue(pw.match_seq([l1, l3], r)) - self.assertEqual(r, {"pl": l3, "pw": [l1, l3]}) - self.assertTrue(r["pl"] is l3) - r = {} - - def test_generate_matches(self): - la = pytree.Leaf(1, "a") - lb = pytree.Leaf(1, "b") - lc = pytree.Leaf(1, "c") - ld = pytree.Leaf(1, "d") - le = pytree.Leaf(1, "e") - lf = pytree.Leaf(1, "f") - leaves = [la, lb, lc, ld, le, lf] - root = pytree.Node(1000, leaves) - pa = pytree.LeafPattern(1, "a", "pa") - pb = pytree.LeafPattern(1, "b", "pb") - pc = pytree.LeafPattern(1, "c", "pc") - pd = pytree.LeafPattern(1, "d", "pd") - pe = pytree.LeafPattern(1, "e", "pe") - pf = pytree.LeafPattern(1, "f", "pf") - pw = pytree.WildcardPattern([[pa, pb, pc], [pd, pe], - [pa, pb], [pc, pd], [pe, pf]], - min=1, max=4, name="pw") - self.assertEqual([x[0] for x in pw.generate_matches(leaves)], - [3, 5, 2, 4, 6]) - pr = pytree.NodePattern(type=1000, content=[pw], name="pr") - matches = list(pytree.generate_matches([pr], [root])) - self.assertEqual(len(matches), 1) - c, r = matches[0] - self.assertEqual(c, 1) - self.assertEqual(str(r["pr"]), "abcdef") - self.assertEqual(r["pw"], [la, lb, lc, ld, le, lf]) - for c in "abcdef": - self.assertEqual(r["p" + c], pytree.Leaf(1, c)) - - def test_has_key_example(self): - pattern = pytree.NodePattern(331, - (pytree.LeafPattern(7), - pytree.WildcardPattern(name="args"), - pytree.LeafPattern(8))) - l1 = pytree.Leaf(7, "(") - l2 = pytree.Leaf(3, "x") - l3 = pytree.Leaf(8, ")") - node = pytree.Node(331, [l1, l2, l3]) - r = {} - self.assertTrue(pattern.match(node, r)) - self.assertEqual(r["args"], [l2]) diff --git a/PythonLib/extra/lib2to3/tests/test_refactor.py b/PythonLib/extra/lib2to3/tests/test_refactor.py deleted file mode 100644 index 543fd421..00000000 --- a/PythonLib/extra/lib2to3/tests/test_refactor.py +++ /dev/null @@ -1,321 +0,0 @@ -""" -Unit tests for refactor.py. -""" - -from __future__ import with_statement - -import sys -import os -import codecs -import operator -import StringIO -import tempfile -import shutil -import unittest -import warnings - -from lib2to3 import refactor, pygram, fixer_base -from lib2to3.pgen2 import token - -from . import support - - -TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), "data") -FIXER_DIR = os.path.join(TEST_DATA_DIR, "fixers") - -sys.path.append(FIXER_DIR) -try: - _DEFAULT_FIXERS = refactor.get_fixers_from_package("myfixes") -finally: - sys.path.pop() - -_2TO3_FIXERS = refactor.get_fixers_from_package("lib2to3.fixes") - -class TestRefactoringTool(unittest.TestCase): - - def setUp(self): - sys.path.append(FIXER_DIR) - - def tearDown(self): - sys.path.pop() - - def check_instances(self, instances, classes): - for inst, cls in zip(instances, classes): - if not isinstance(inst, cls): - self.fail("%s are not instances of %s" % instances, classes) - - def rt(self, options=None, fixers=_DEFAULT_FIXERS, explicit=None): - return refactor.RefactoringTool(fixers, options, explicit) - - def test_print_function_option(self): - rt = self.rt({"print_function" : True}) - self.assertTrue(rt.grammar is pygram.python_grammar_no_print_statement) - self.assertTrue(rt.driver.grammar is - pygram.python_grammar_no_print_statement) - - def test_write_unchanged_files_option(self): - rt = self.rt() - self.assertFalse(rt.write_unchanged_files) - rt = self.rt({"write_unchanged_files" : True}) - self.assertTrue(rt.write_unchanged_files) - - def test_fixer_loading_helpers(self): - contents = ["explicit", "first", "last", "parrot", "preorder"] - non_prefixed = refactor.get_all_fix_names("myfixes") - prefixed = refactor.get_all_fix_names("myfixes", False) - full_names = refactor.get_fixers_from_package("myfixes") - self.assertEqual(prefixed, ["fix_" + name for name in contents]) - self.assertEqual(non_prefixed, contents) - self.assertEqual(full_names, - ["myfixes.fix_" + name for name in contents]) - - def test_detect_future_features(self): - run = refactor._detect_future_features - fs = frozenset - empty = fs() - self.assertEqual(run(""), empty) - self.assertEqual(run("from __future__ import print_function"), - fs(("print_function",))) - self.assertEqual(run("from __future__ import generators"), - fs(("generators",))) - self.assertEqual(run("from __future__ import generators, feature"), - fs(("generators", "feature"))) - inp = "from __future__ import generators, print_function" - self.assertEqual(run(inp), fs(("generators", "print_function"))) - inp ="from __future__ import print_function, generators" - self.assertEqual(run(inp), fs(("print_function", "generators"))) - inp = "from __future__ import (print_function,)" - self.assertEqual(run(inp), fs(("print_function",))) - inp = "from __future__ import (generators, print_function)" - self.assertEqual(run(inp), fs(("generators", "print_function"))) - inp = "from __future__ import (generators, nested_scopes)" - self.assertEqual(run(inp), fs(("generators", "nested_scopes"))) - inp = """from __future__ import generators -from __future__ import print_function""" - self.assertEqual(run(inp), fs(("generators", "print_function"))) - invalid = ("from", - "from 4", - "from x", - "from x 5", - "from x im", - "from x import", - "from x import 4", - ) - for inp in invalid: - self.assertEqual(run(inp), empty) - inp = "'docstring'\nfrom __future__ import print_function" - self.assertEqual(run(inp), fs(("print_function",))) - inp = "'docstring'\n'somng'\nfrom __future__ import print_function" - self.assertEqual(run(inp), empty) - inp = "# comment\nfrom __future__ import print_function" - self.assertEqual(run(inp), fs(("print_function",))) - inp = "# comment\n'doc'\nfrom __future__ import print_function" - self.assertEqual(run(inp), fs(("print_function",))) - inp = "class x: pass\nfrom __future__ import print_function" - self.assertEqual(run(inp), empty) - - def test_get_headnode_dict(self): - class NoneFix(fixer_base.BaseFix): - pass - - class FileInputFix(fixer_base.BaseFix): - PATTERN = "file_input< any * >" - - class SimpleFix(fixer_base.BaseFix): - PATTERN = "'name'" - - no_head = NoneFix({}, []) - with_head = FileInputFix({}, []) - simple = SimpleFix({}, []) - d = refactor._get_headnode_dict([no_head, with_head, simple]) - top_fixes = d.pop(pygram.python_symbols.file_input) - self.assertEqual(top_fixes, [with_head, no_head]) - name_fixes = d.pop(token.NAME) - self.assertEqual(name_fixes, [simple, no_head]) - for fixes in d.itervalues(): - self.assertEqual(fixes, [no_head]) - - def test_fixer_loading(self): - from myfixes.fix_first import FixFirst - from myfixes.fix_last import FixLast - from myfixes.fix_parrot import FixParrot - from myfixes.fix_preorder import FixPreorder - - rt = self.rt() - pre, post = rt.get_fixers() - - self.check_instances(pre, [FixPreorder]) - self.check_instances(post, [FixFirst, FixParrot, FixLast]) - - def test_naughty_fixers(self): - self.assertRaises(ImportError, self.rt, fixers=["not_here"]) - self.assertRaises(refactor.FixerError, self.rt, fixers=["no_fixer_cls"]) - self.assertRaises(refactor.FixerError, self.rt, fixers=["bad_order"]) - - def test_refactor_string(self): - rt = self.rt() - input = "def parrot(): pass\n\n" - tree = rt.refactor_string(input, "") - self.assertNotEqual(str(tree), input) - - input = "def f(): pass\n\n" - tree = rt.refactor_string(input, "") - self.assertEqual(str(tree), input) - - def test_refactor_stdin(self): - - class MyRT(refactor.RefactoringTool): - - def print_output(self, old_text, new_text, filename, equal): - results.extend([old_text, new_text, filename, equal]) - - results = [] - rt = MyRT(_DEFAULT_FIXERS) - save = sys.stdin - sys.stdin = StringIO.StringIO("def parrot(): pass\n\n") - try: - rt.refactor_stdin() - finally: - sys.stdin = save - expected = ["def parrot(): pass\n\n", - "def cheese(): pass\n\n", - "", False] - self.assertEqual(results, expected) - - def check_file_refactoring(self, test_file, fixers=_2TO3_FIXERS, - options=None, mock_log_debug=None, - actually_write=True): - tmpdir = tempfile.mkdtemp(prefix="2to3-test_refactor") - self.addCleanup(shutil.rmtree, tmpdir) - # make a copy of the tested file that we can write to - shutil.copy(test_file, tmpdir) - test_file = os.path.join(tmpdir, os.path.basename(test_file)) - os.chmod(test_file, 0o644) - - def read_file(): - with open(test_file, "rb") as fp: - return fp.read() - - old_contents = read_file() - rt = self.rt(fixers=fixers, options=options) - if mock_log_debug: - rt.log_debug = mock_log_debug - - rt.refactor_file(test_file) - self.assertEqual(old_contents, read_file()) - - if not actually_write: - return - rt.refactor_file(test_file, True) - new_contents = read_file() - self.assertNotEqual(old_contents, new_contents) - return new_contents - - def test_refactor_file(self): - test_file = os.path.join(FIXER_DIR, "parrot_example.py") - self.check_file_refactoring(test_file, _DEFAULT_FIXERS) - - def test_refactor_file_write_unchanged_file(self): - test_file = os.path.join(FIXER_DIR, "parrot_example.py") - debug_messages = [] - def recording_log_debug(msg, *args): - debug_messages.append(msg % args) - self.check_file_refactoring(test_file, fixers=(), - options={"write_unchanged_files": True}, - mock_log_debug=recording_log_debug, - actually_write=False) - # Testing that it logged this message when write=False was passed is - # sufficient to see that it did not bail early after "No changes". - message_regex = r"Not writing changes to .*%s%s" % ( - os.sep, os.path.basename(test_file)) - for message in debug_messages: - if "Not writing changes" in message: - self.assertRegexpMatches(message, message_regex) - break - else: - self.fail("%r not matched in %r" % (message_regex, debug_messages)) - - def test_refactor_dir(self): - def check(structure, expected): - def mock_refactor_file(self, f, *args): - got.append(f) - save_func = refactor.RefactoringTool.refactor_file - refactor.RefactoringTool.refactor_file = mock_refactor_file - rt = self.rt() - got = [] - dir = tempfile.mkdtemp(prefix="2to3-test_refactor") - try: - os.mkdir(os.path.join(dir, "a_dir")) - for fn in structure: - open(os.path.join(dir, fn), "wb").close() - rt.refactor_dir(dir) - finally: - refactor.RefactoringTool.refactor_file = save_func - shutil.rmtree(dir) - self.assertEqual(got, - [os.path.join(dir, path) for path in expected]) - check([], []) - tree = ["nothing", - "hi.py", - ".dumb", - ".after.py", - "notpy.npy", - "sappy"] - expected = ["hi.py"] - check(tree, expected) - tree = ["hi.py", - os.path.join("a_dir", "stuff.py")] - check(tree, tree) - - def test_file_encoding(self): - fn = os.path.join(TEST_DATA_DIR, "different_encoding.py") - self.check_file_refactoring(fn) - - def test_false_file_encoding(self): - fn = os.path.join(TEST_DATA_DIR, "false_encoding.py") - data = self.check_file_refactoring(fn) - - def test_bom(self): - fn = os.path.join(TEST_DATA_DIR, "bom.py") - data = self.check_file_refactoring(fn) - self.assertTrue(data.startswith(codecs.BOM_UTF8)) - - def test_crlf_newlines(self): - old_sep = os.linesep - os.linesep = "\r\n" - try: - fn = os.path.join(TEST_DATA_DIR, "crlf.py") - fixes = refactor.get_fixers_from_package("lib2to3.fixes") - self.check_file_refactoring(fn, fixes) - finally: - os.linesep = old_sep - - def test_refactor_docstring(self): - rt = self.rt() - - doc = """ ->>> example() -42 -""" - out = rt.refactor_docstring(doc, "") - self.assertEqual(out, doc) - - doc = """ ->>> def parrot(): -... return 43 -""" - out = rt.refactor_docstring(doc, "") - self.assertNotEqual(out, doc) - - def test_explicit(self): - from myfixes.fix_explicit import FixExplicit - - rt = self.rt(fixers=["myfixes.fix_explicit"]) - self.assertEqual(len(rt.post_order), 0) - - rt = self.rt(explicit=["myfixes.fix_explicit"]) - for fix in rt.post_order: - if isinstance(fix, FixExplicit): - break - else: - self.fail("explicit fixer not loaded") diff --git a/PythonLib/extra/lib2to3/tests/test_util.py b/PythonLib/extra/lib2to3/tests/test_util.py deleted file mode 100644 index 2fab8b9a..00000000 --- a/PythonLib/extra/lib2to3/tests/test_util.py +++ /dev/null @@ -1,594 +0,0 @@ -""" Test suite for the code in fixer_util """ - -# Testing imports -from . import support - -# Python imports -import os.path - -# Local imports -from lib2to3.pytree import Node, Leaf -from lib2to3 import fixer_util -from lib2to3.fixer_util import Attr, Name, Call, Comma -from lib2to3.pgen2 import token - -def parse(code, strip_levels=0): - # The topmost node is file_input, which we don't care about. - # The next-topmost node is a *_stmt node, which we also don't care about - tree = support.parse_string(code) - for i in range(strip_levels): - tree = tree.children[0] - tree.parent = None - return tree - -class MacroTestCase(support.TestCase): - def assertStr(self, node, string): - if isinstance(node, (tuple, list)): - node = Node(fixer_util.syms.simple_stmt, node) - self.assertEqual(str(node), string) - - -class Test_is_tuple(support.TestCase): - def is_tuple(self, string): - return fixer_util.is_tuple(parse(string, strip_levels=2)) - - def test_valid(self): - self.assertTrue(self.is_tuple("(a, b)")) - self.assertTrue(self.is_tuple("(a, (b, c))")) - self.assertTrue(self.is_tuple("((a, (b, c)),)")) - self.assertTrue(self.is_tuple("(a,)")) - self.assertTrue(self.is_tuple("()")) - - def test_invalid(self): - self.assertFalse(self.is_tuple("(a)")) - self.assertFalse(self.is_tuple("('foo') % (b, c)")) - - -class Test_is_list(support.TestCase): - def is_list(self, string): - return fixer_util.is_list(parse(string, strip_levels=2)) - - def test_valid(self): - self.assertTrue(self.is_list("[]")) - self.assertTrue(self.is_list("[a]")) - self.assertTrue(self.is_list("[a, b]")) - self.assertTrue(self.is_list("[a, [b, c]]")) - self.assertTrue(self.is_list("[[a, [b, c]],]")) - - def test_invalid(self): - self.assertFalse(self.is_list("[]+[]")) - - -class Test_Attr(MacroTestCase): - def test(self): - call = parse("foo()", strip_levels=2) - - self.assertStr(Attr(Name("a"), Name("b")), "a.b") - self.assertStr(Attr(call, Name("b")), "foo().b") - - def test_returns(self): - attr = Attr(Name("a"), Name("b")) - self.assertEqual(type(attr), list) - - -class Test_Name(MacroTestCase): - def test(self): - self.assertStr(Name("a"), "a") - self.assertStr(Name("foo.foo().bar"), "foo.foo().bar") - self.assertStr(Name("a", prefix="b"), "ba") - - -class Test_Call(MacroTestCase): - def _Call(self, name, args=None, prefix=None): - """Help the next test""" - children = [] - if isinstance(args, list): - for arg in args: - children.append(arg) - children.append(Comma()) - children.pop() - return Call(Name(name), children, prefix) - - def test(self): - kids = [None, - [Leaf(token.NUMBER, 1), Leaf(token.NUMBER, 2), - Leaf(token.NUMBER, 3)], - [Leaf(token.NUMBER, 1), Leaf(token.NUMBER, 3), - Leaf(token.NUMBER, 2), Leaf(token.NUMBER, 4)], - [Leaf(token.STRING, "b"), Leaf(token.STRING, "j", prefix=" ")] - ] - self.assertStr(self._Call("A"), "A()") - self.assertStr(self._Call("b", kids[1]), "b(1,2,3)") - self.assertStr(self._Call("a.b().c", kids[2]), "a.b().c(1,3,2,4)") - self.assertStr(self._Call("d", kids[3], prefix=" "), " d(b, j)") - - -class Test_does_tree_import(support.TestCase): - def _find_bind_rec(self, name, node): - # Search a tree for a binding -- used to find the starting - # point for these tests. - c = fixer_util.find_binding(name, node) - if c: return c - for child in node.children: - c = self._find_bind_rec(name, child) - if c: return c - - def does_tree_import(self, package, name, string): - node = parse(string) - # Find the binding of start -- that's what we'll go from - node = self._find_bind_rec('start', node) - return fixer_util.does_tree_import(package, name, node) - - def try_with(self, string): - failing_tests = (("a", "a", "from a import b"), - ("a.d", "a", "from a.d import b"), - ("d.a", "a", "from d.a import b"), - (None, "a", "import b"), - (None, "a", "import b, c, d")) - for package, name, import_ in failing_tests: - n = self.does_tree_import(package, name, import_ + "\n" + string) - self.assertFalse(n) - n = self.does_tree_import(package, name, string + "\n" + import_) - self.assertFalse(n) - - passing_tests = (("a", "a", "from a import a"), - ("x", "a", "from x import a"), - ("x", "a", "from x import b, c, a, d"), - ("x.b", "a", "from x.b import a"), - ("x.b", "a", "from x.b import b, c, a, d"), - (None, "a", "import a"), - (None, "a", "import b, c, a, d")) - for package, name, import_ in passing_tests: - n = self.does_tree_import(package, name, import_ + "\n" + string) - self.assertTrue(n) - n = self.does_tree_import(package, name, string + "\n" + import_) - self.assertTrue(n) - - def test_in_function(self): - self.try_with("def foo():\n\tbar.baz()\n\tstart=3") - -class Test_find_binding(support.TestCase): - def find_binding(self, name, string, package=None): - return fixer_util.find_binding(name, parse(string), package) - - def test_simple_assignment(self): - self.assertTrue(self.find_binding("a", "a = b")) - self.assertTrue(self.find_binding("a", "a = [b, c, d]")) - self.assertTrue(self.find_binding("a", "a = foo()")) - self.assertTrue(self.find_binding("a", "a = foo().foo.foo[6][foo]")) - self.assertFalse(self.find_binding("a", "foo = a")) - self.assertFalse(self.find_binding("a", "foo = (a, b, c)")) - - def test_tuple_assignment(self): - self.assertTrue(self.find_binding("a", "(a,) = b")) - self.assertTrue(self.find_binding("a", "(a, b, c) = [b, c, d]")) - self.assertTrue(self.find_binding("a", "(c, (d, a), b) = foo()")) - self.assertTrue(self.find_binding("a", "(a, b) = foo().foo[6][foo]")) - self.assertFalse(self.find_binding("a", "(foo, b) = (b, a)")) - self.assertFalse(self.find_binding("a", "(foo, (b, c)) = (a, b, c)")) - - def test_list_assignment(self): - self.assertTrue(self.find_binding("a", "[a] = b")) - self.assertTrue(self.find_binding("a", "[a, b, c] = [b, c, d]")) - self.assertTrue(self.find_binding("a", "[c, [d, a], b] = foo()")) - self.assertTrue(self.find_binding("a", "[a, b] = foo().foo[a][foo]")) - self.assertFalse(self.find_binding("a", "[foo, b] = (b, a)")) - self.assertFalse(self.find_binding("a", "[foo, [b, c]] = (a, b, c)")) - - def test_invalid_assignments(self): - self.assertFalse(self.find_binding("a", "foo.a = 5")) - self.assertFalse(self.find_binding("a", "foo[a] = 5")) - self.assertFalse(self.find_binding("a", "foo(a) = 5")) - self.assertFalse(self.find_binding("a", "foo(a, b) = 5")) - - def test_simple_import(self): - self.assertTrue(self.find_binding("a", "import a")) - self.assertTrue(self.find_binding("a", "import b, c, a, d")) - self.assertFalse(self.find_binding("a", "import b")) - self.assertFalse(self.find_binding("a", "import b, c, d")) - - def test_from_import(self): - self.assertTrue(self.find_binding("a", "from x import a")) - self.assertTrue(self.find_binding("a", "from a import a")) - self.assertTrue(self.find_binding("a", "from x import b, c, a, d")) - self.assertTrue(self.find_binding("a", "from x.b import a")) - self.assertTrue(self.find_binding("a", "from x.b import b, c, a, d")) - self.assertFalse(self.find_binding("a", "from a import b")) - self.assertFalse(self.find_binding("a", "from a.d import b")) - self.assertFalse(self.find_binding("a", "from d.a import b")) - - def test_import_as(self): - self.assertTrue(self.find_binding("a", "import b as a")) - self.assertTrue(self.find_binding("a", "import b as a, c, a as f, d")) - self.assertFalse(self.find_binding("a", "import a as f")) - self.assertFalse(self.find_binding("a", "import b, c as f, d as e")) - - def test_from_import_as(self): - self.assertTrue(self.find_binding("a", "from x import b as a")) - self.assertTrue(self.find_binding("a", "from x import g as a, d as b")) - self.assertTrue(self.find_binding("a", "from x.b import t as a")) - self.assertTrue(self.find_binding("a", "from x.b import g as a, d")) - self.assertFalse(self.find_binding("a", "from a import b as t")) - self.assertFalse(self.find_binding("a", "from a.d import b as t")) - self.assertFalse(self.find_binding("a", "from d.a import b as t")) - - def test_simple_import_with_package(self): - self.assertTrue(self.find_binding("b", "import b")) - self.assertTrue(self.find_binding("b", "import b, c, d")) - self.assertFalse(self.find_binding("b", "import b", "b")) - self.assertFalse(self.find_binding("b", "import b, c, d", "c")) - - def test_from_import_with_package(self): - self.assertTrue(self.find_binding("a", "from x import a", "x")) - self.assertTrue(self.find_binding("a", "from a import a", "a")) - self.assertTrue(self.find_binding("a", "from x import *", "x")) - self.assertTrue(self.find_binding("a", "from x import b, c, a, d", "x")) - self.assertTrue(self.find_binding("a", "from x.b import a", "x.b")) - self.assertTrue(self.find_binding("a", "from x.b import *", "x.b")) - self.assertTrue(self.find_binding("a", "from x.b import b, c, a, d", "x.b")) - self.assertFalse(self.find_binding("a", "from a import b", "a")) - self.assertFalse(self.find_binding("a", "from a.d import b", "a.d")) - self.assertFalse(self.find_binding("a", "from d.a import b", "a.d")) - self.assertFalse(self.find_binding("a", "from x.y import *", "a.b")) - - def test_import_as_with_package(self): - self.assertFalse(self.find_binding("a", "import b.c as a", "b.c")) - self.assertFalse(self.find_binding("a", "import a as f", "f")) - self.assertFalse(self.find_binding("a", "import a as f", "a")) - - def test_from_import_as_with_package(self): - # Because it would take a lot of special-case code in the fixers - # to deal with from foo import bar as baz, we'll simply always - # fail if there is an "from ... import ... as ..." - self.assertFalse(self.find_binding("a", "from x import b as a", "x")) - self.assertFalse(self.find_binding("a", "from x import g as a, d as b", "x")) - self.assertFalse(self.find_binding("a", "from x.b import t as a", "x.b")) - self.assertFalse(self.find_binding("a", "from x.b import g as a, d", "x.b")) - self.assertFalse(self.find_binding("a", "from a import b as t", "a")) - self.assertFalse(self.find_binding("a", "from a import b as t", "b")) - self.assertFalse(self.find_binding("a", "from a import b as t", "t")) - - def test_function_def(self): - self.assertTrue(self.find_binding("a", "def a(): pass")) - self.assertTrue(self.find_binding("a", "def a(b, c, d): pass")) - self.assertTrue(self.find_binding("a", "def a(): b = 7")) - self.assertFalse(self.find_binding("a", "def d(b, (c, a), e): pass")) - self.assertFalse(self.find_binding("a", "def d(a=7): pass")) - self.assertFalse(self.find_binding("a", "def d(a): pass")) - self.assertFalse(self.find_binding("a", "def d(): a = 7")) - - s = """ - def d(): - def a(): - pass""" - self.assertFalse(self.find_binding("a", s)) - - def test_class_def(self): - self.assertTrue(self.find_binding("a", "class a: pass")) - self.assertTrue(self.find_binding("a", "class a(): pass")) - self.assertTrue(self.find_binding("a", "class a(b): pass")) - self.assertTrue(self.find_binding("a", "class a(b, c=8): pass")) - self.assertFalse(self.find_binding("a", "class d: pass")) - self.assertFalse(self.find_binding("a", "class d(a): pass")) - self.assertFalse(self.find_binding("a", "class d(b, a=7): pass")) - self.assertFalse(self.find_binding("a", "class d(b, *a): pass")) - self.assertFalse(self.find_binding("a", "class d(b, **a): pass")) - self.assertFalse(self.find_binding("a", "class d: a = 7")) - - s = """ - class d(): - class a(): - pass""" - self.assertFalse(self.find_binding("a", s)) - - def test_for(self): - self.assertTrue(self.find_binding("a", "for a in r: pass")) - self.assertTrue(self.find_binding("a", "for a, b in r: pass")) - self.assertTrue(self.find_binding("a", "for (a, b) in r: pass")) - self.assertTrue(self.find_binding("a", "for c, (a,) in r: pass")) - self.assertTrue(self.find_binding("a", "for c, (a, b) in r: pass")) - self.assertTrue(self.find_binding("a", "for c in r: a = c")) - self.assertFalse(self.find_binding("a", "for c in a: pass")) - - def test_for_nested(self): - s = """ - for b in r: - for a in b: - pass""" - self.assertTrue(self.find_binding("a", s)) - - s = """ - for b in r: - for a, c in b: - pass""" - self.assertTrue(self.find_binding("a", s)) - - s = """ - for b in r: - for (a, c) in b: - pass""" - self.assertTrue(self.find_binding("a", s)) - - s = """ - for b in r: - for (a,) in b: - pass""" - self.assertTrue(self.find_binding("a", s)) - - s = """ - for b in r: - for c, (a, d) in b: - pass""" - self.assertTrue(self.find_binding("a", s)) - - s = """ - for b in r: - for c in b: - a = 7""" - self.assertTrue(self.find_binding("a", s)) - - s = """ - for b in r: - for c in b: - d = a""" - self.assertFalse(self.find_binding("a", s)) - - s = """ - for b in r: - for c in a: - d = 7""" - self.assertFalse(self.find_binding("a", s)) - - def test_if(self): - self.assertTrue(self.find_binding("a", "if b in r: a = c")) - self.assertFalse(self.find_binding("a", "if a in r: d = e")) - - def test_if_nested(self): - s = """ - if b in r: - if c in d: - a = c""" - self.assertTrue(self.find_binding("a", s)) - - s = """ - if b in r: - if c in d: - c = a""" - self.assertFalse(self.find_binding("a", s)) - - def test_while(self): - self.assertTrue(self.find_binding("a", "while b in r: a = c")) - self.assertFalse(self.find_binding("a", "while a in r: d = e")) - - def test_while_nested(self): - s = """ - while b in r: - while c in d: - a = c""" - self.assertTrue(self.find_binding("a", s)) - - s = """ - while b in r: - while c in d: - c = a""" - self.assertFalse(self.find_binding("a", s)) - - def test_try_except(self): - s = """ - try: - a = 6 - except: - b = 8""" - self.assertTrue(self.find_binding("a", s)) - - s = """ - try: - b = 8 - except: - a = 6""" - self.assertTrue(self.find_binding("a", s)) - - s = """ - try: - b = 8 - except KeyError: - pass - except: - a = 6""" - self.assertTrue(self.find_binding("a", s)) - - s = """ - try: - b = 8 - except: - b = 6""" - self.assertFalse(self.find_binding("a", s)) - - def test_try_except_nested(self): - s = """ - try: - try: - a = 6 - except: - pass - except: - b = 8""" - self.assertTrue(self.find_binding("a", s)) - - s = """ - try: - b = 8 - except: - try: - a = 6 - except: - pass""" - self.assertTrue(self.find_binding("a", s)) - - s = """ - try: - b = 8 - except: - try: - pass - except: - a = 6""" - self.assertTrue(self.find_binding("a", s)) - - s = """ - try: - try: - b = 8 - except KeyError: - pass - except: - a = 6 - except: - pass""" - self.assertTrue(self.find_binding("a", s)) - - s = """ - try: - pass - except: - try: - b = 8 - except KeyError: - pass - except: - a = 6""" - self.assertTrue(self.find_binding("a", s)) - - s = """ - try: - b = 8 - except: - b = 6""" - self.assertFalse(self.find_binding("a", s)) - - s = """ - try: - try: - b = 8 - except: - c = d - except: - try: - b = 6 - except: - t = 8 - except: - o = y""" - self.assertFalse(self.find_binding("a", s)) - - def test_try_except_finally(self): - s = """ - try: - c = 6 - except: - b = 8 - finally: - a = 9""" - self.assertTrue(self.find_binding("a", s)) - - s = """ - try: - b = 8 - finally: - a = 6""" - self.assertTrue(self.find_binding("a", s)) - - s = """ - try: - b = 8 - finally: - b = 6""" - self.assertFalse(self.find_binding("a", s)) - - s = """ - try: - b = 8 - except: - b = 9 - finally: - b = 6""" - self.assertFalse(self.find_binding("a", s)) - - def test_try_except_finally_nested(self): - s = """ - try: - c = 6 - except: - b = 8 - finally: - try: - a = 9 - except: - b = 9 - finally: - c = 9""" - self.assertTrue(self.find_binding("a", s)) - - s = """ - try: - b = 8 - finally: - try: - pass - finally: - a = 6""" - self.assertTrue(self.find_binding("a", s)) - - s = """ - try: - b = 8 - finally: - try: - b = 6 - finally: - b = 7""" - self.assertFalse(self.find_binding("a", s)) - -class Test_touch_import(support.TestCase): - - def test_after_docstring(self): - node = parse('"""foo"""\nbar()') - fixer_util.touch_import(None, "foo", node) - self.assertEqual(str(node), '"""foo"""\nimport foo\nbar()\n\n') - - def test_after_imports(self): - node = parse('"""foo"""\nimport bar\nbar()') - fixer_util.touch_import(None, "foo", node) - self.assertEqual(str(node), '"""foo"""\nimport bar\nimport foo\nbar()\n\n') - - def test_beginning(self): - node = parse('bar()') - fixer_util.touch_import(None, "foo", node) - self.assertEqual(str(node), 'import foo\nbar()\n\n') - - def test_from_import(self): - node = parse('bar()') - fixer_util.touch_import("html", "escape", node) - self.assertEqual(str(node), 'from html import escape\nbar()\n\n') - - def test_name_import(self): - node = parse('bar()') - fixer_util.touch_import(None, "cgi", node) - self.assertEqual(str(node), 'import cgi\nbar()\n\n') - -class Test_find_indentation(support.TestCase): - - def test_nothing(self): - fi = fixer_util.find_indentation - node = parse("node()") - self.assertEqual(fi(node), u"") - node = parse("") - self.assertEqual(fi(node), u"") - - def test_simple(self): - fi = fixer_util.find_indentation - node = parse("def f():\n x()") - self.assertEqual(fi(node), u"") - self.assertEqual(fi(node.children[0].children[4].children[2]), u" ") - node = parse("def f():\n x()\n y()") - self.assertEqual(fi(node.children[0].children[4].children[4]), u" ") diff --git a/PythonLib/full/BaseHTTPServer.py b/PythonLib/full/BaseHTTPServer.py deleted file mode 100644 index deaf2f96..00000000 --- a/PythonLib/full/BaseHTTPServer.py +++ /dev/null @@ -1,603 +0,0 @@ -"""HTTP server base class. - -Note: the class in this module doesn't implement any HTTP request; see -SimpleHTTPServer for simple implementations of GET, HEAD and POST -(including CGI scripts). It does, however, optionally implement HTTP/1.1 -persistent connections, as of version 0.3. - -Contents: - -- BaseHTTPRequestHandler: HTTP request handler base class -- test: test function - -XXX To do: - -- log requests even later (to capture byte count) -- log user-agent header and other interesting goodies -- send error log to separate file -""" - - -# See also: -# -# HTTP Working Group T. Berners-Lee -# INTERNET-DRAFT R. T. Fielding -# H. Frystyk Nielsen -# Expires September 8, 1995 March 8, 1995 -# -# URL: http://www.ics.uci.edu/pub/ietf/http/draft-ietf-http-v10-spec-00.txt -# -# and -# -# Network Working Group R. Fielding -# Request for Comments: 2616 et al -# Obsoletes: 2068 June 1999 -# Category: Standards Track -# -# URL: http://www.faqs.org/rfcs/rfc2616.html - -# Log files -# --------- -# -# Here's a quote from the NCSA httpd docs about log file format. -# -# | The logfile format is as follows. Each line consists of: -# | -# | host rfc931 authuser [DD/Mon/YYYY:hh:mm:ss] "request" ddd bbbb -# | -# | host: Either the DNS name or the IP number of the remote client -# | rfc931: Any information returned by identd for this person, -# | - otherwise. -# | authuser: If user sent a userid for authentication, the user name, -# | - otherwise. -# | DD: Day -# | Mon: Month (calendar name) -# | YYYY: Year -# | hh: hour (24-hour format, the machine's timezone) -# | mm: minutes -# | ss: seconds -# | request: The first line of the HTTP request as sent by the client. -# | ddd: the status code returned by the server, - if not available. -# | bbbb: the total number of bytes sent, -# | *not including the HTTP/1.0 header*, - if not available -# | -# | You can determine the name of the file accessed through request. -# -# (Actually, the latter is only true if you know the server configuration -# at the time the request was made!) - -__version__ = "0.3" - -__all__ = ["HTTPServer", "BaseHTTPRequestHandler"] - -import sys -import time -import socket # For gethostbyaddr() -from warnings import filterwarnings, catch_warnings -with catch_warnings(): - if sys.py3kwarning: - filterwarnings("ignore", ".*mimetools has been removed", - DeprecationWarning) - import mimetools -import SocketServer - -# Default error message template -DEFAULT_ERROR_MESSAGE = """\ - -Error response - - -

Error response

-

Error code %(code)d. -

Message: %(message)s. -

Error code explanation: %(code)s = %(explain)s. - -""" - -DEFAULT_ERROR_CONTENT_TYPE = "text/html" - -def _quote_html(html): - return html.replace("&", "&").replace("<", "<").replace(">", ">") - -class HTTPServer(SocketServer.TCPServer): - - allow_reuse_address = 1 # Seems to make sense in testing environment - - def server_bind(self): - """Override server_bind to store the server name.""" - SocketServer.TCPServer.server_bind(self) - host, port = self.socket.getsockname()[:2] - self.server_name = socket.getfqdn(host) - self.server_port = port - - -class BaseHTTPRequestHandler(SocketServer.StreamRequestHandler): - - """HTTP request handler base class. - - The following explanation of HTTP serves to guide you through the - code as well as to expose any misunderstandings I may have about - HTTP (so you don't need to read the code to figure out I'm wrong - :-). - - HTTP (HyperText Transfer Protocol) is an extensible protocol on - top of a reliable stream transport (e.g. TCP/IP). The protocol - recognizes three parts to a request: - - 1. One line identifying the request type and path - 2. An optional set of RFC-822-style headers - 3. An optional data part - - The headers and data are separated by a blank line. - - The first line of the request has the form - - - - where is a (case-sensitive) keyword such as GET or POST, - is a string containing path information for the request, - and should be the string "HTTP/1.0" or "HTTP/1.1". - is encoded using the URL encoding scheme (using %xx to signify - the ASCII character with hex code xx). - - The specification specifies that lines are separated by CRLF but - for compatibility with the widest range of clients recommends - servers also handle LF. Similarly, whitespace in the request line - is treated sensibly (allowing multiple spaces between components - and allowing trailing whitespace). - - Similarly, for output, lines ought to be separated by CRLF pairs - but most clients grok LF characters just fine. - - If the first line of the request has the form - - - - (i.e. is left out) then this is assumed to be an HTTP - 0.9 request; this form has no optional headers and data part and - the reply consists of just the data. - - The reply form of the HTTP 1.x protocol again has three parts: - - 1. One line giving the response code - 2. An optional set of RFC-822-style headers - 3. The data - - Again, the headers and data are separated by a blank line. - - The response code line has the form - - - - where is the protocol version ("HTTP/1.0" or "HTTP/1.1"), - is a 3-digit response code indicating success or - failure of the request, and is an optional - human-readable string explaining what the response code means. - - This server parses the request and the headers, and then calls a - function specific to the request type (). Specifically, - a request SPAM will be handled by a method do_SPAM(). If no - such method exists the server sends an error response to the - client. If it exists, it is called with no arguments: - - do_SPAM() - - Note that the request name is case sensitive (i.e. SPAM and spam - are different requests). - - The various request details are stored in instance variables: - - - client_address is the client IP address in the form (host, - port); - - - command, path and version are the broken-down request line; - - - headers is an instance of mimetools.Message (or a derived - class) containing the header information; - - - rfile is a file object open for reading positioned at the - start of the optional input data part; - - - wfile is a file object open for writing. - - IT IS IMPORTANT TO ADHERE TO THE PROTOCOL FOR WRITING! - - The first thing to be written must be the response line. Then - follow 0 or more header lines, then a blank line, and then the - actual data (if any). The meaning of the header lines depends on - the command executed by the server; in most cases, when data is - returned, there should be at least one header line of the form - - Content-type: / - - where and should be registered MIME types, - e.g. "text/html" or "text/plain". - - """ - - # The Python system version, truncated to its first component. - sys_version = "Python/" + sys.version.split()[0] - - # The server software version. You may want to override this. - # The format is multiple whitespace-separated strings, - # where each string is of the form name[/version]. - server_version = "BaseHTTP/" + __version__ - - # The default request version. This only affects responses up until - # the point where the request line is parsed, so it mainly decides what - # the client gets back when sending a malformed request line. - # Most web servers default to HTTP 0.9, i.e. don't send a status line. - default_request_version = "HTTP/0.9" - - def parse_request(self): - """Parse a request (internal). - - The request should be stored in self.raw_requestline; the results - are in self.command, self.path, self.request_version and - self.headers. - - Return True for success, False for failure; on failure, an - error is sent back. - - """ - self.command = None # set in case of error on the first line - self.request_version = version = self.default_request_version - self.close_connection = 1 - requestline = self.raw_requestline - requestline = requestline.rstrip('\r\n') - self.requestline = requestline - words = requestline.split() - if len(words) == 3: - command, path, version = words - if version[:5] != 'HTTP/': - self.send_error(400, "Bad request version (%r)" % version) - return False - try: - base_version_number = version.split('/', 1)[1] - version_number = base_version_number.split(".") - # RFC 2145 section 3.1 says there can be only one "." and - # - major and minor numbers MUST be treated as - # separate integers; - # - HTTP/2.4 is a lower version than HTTP/2.13, which in - # turn is lower than HTTP/12.3; - # - Leading zeros MUST be ignored by recipients. - if len(version_number) != 2: - raise ValueError - version_number = int(version_number[0]), int(version_number[1]) - except (ValueError, IndexError): - self.send_error(400, "Bad request version (%r)" % version) - return False - if version_number >= (1, 1) and self.protocol_version >= "HTTP/1.1": - self.close_connection = 0 - if version_number >= (2, 0): - self.send_error(505, - "Invalid HTTP Version (%s)" % base_version_number) - return False - elif len(words) == 2: - command, path = words - self.close_connection = 1 - if command != 'GET': - self.send_error(400, - "Bad HTTP/0.9 request type (%r)" % command) - return False - elif not words: - return False - else: - self.send_error(400, "Bad request syntax (%r)" % requestline) - return False - self.command, self.path, self.request_version = command, path, version - - # Examine the headers and look for a Connection directive - self.headers = self.MessageClass(self.rfile, 0) - - conntype = self.headers.get('Connection', "") - if conntype.lower() == 'close': - self.close_connection = 1 - elif (conntype.lower() == 'keep-alive' and - self.protocol_version >= "HTTP/1.1"): - self.close_connection = 0 - return True - - def handle_one_request(self): - """Handle a single HTTP request. - - You normally don't need to override this method; see the class - __doc__ string for information on how to handle specific HTTP - commands such as GET and POST. - - """ - try: - self.raw_requestline = self.rfile.readline(65537) - if len(self.raw_requestline) > 65536: - self.requestline = '' - self.request_version = '' - self.command = '' - self.send_error(414) - return - if not self.raw_requestline: - self.close_connection = 1 - return - if not self.parse_request(): - # An error code has been sent, just exit - return - mname = 'do_' + self.command - if not hasattr(self, mname): - self.send_error(501, "Unsupported method (%r)" % self.command) - return - method = getattr(self, mname) - method() - self.wfile.flush() #actually send the response if not already done. - except socket.timeout, e: - #a read or a write timed out. Discard this connection - self.log_error("Request timed out: %r", e) - self.close_connection = 1 - return - - def handle(self): - """Handle multiple requests if necessary.""" - self.close_connection = 1 - - self.handle_one_request() - while not self.close_connection: - self.handle_one_request() - - def send_error(self, code, message=None): - """Send and log an error reply. - - Arguments are the error code, and a detailed message. - The detailed message defaults to the short entry matching the - response code. - - This sends an error response (so it must be called before any - output has been generated), logs the error, and finally sends - a piece of HTML explaining the error to the user. - - """ - - try: - short, long = self.responses[code] - except KeyError: - short, long = '???', '???' - if message is None: - message = short - explain = long - self.log_error("code %d, message %s", code, message) - # using _quote_html to prevent Cross Site Scripting attacks (see bug #1100201) - content = (self.error_message_format % - {'code': code, 'message': _quote_html(message), 'explain': explain}) - self.send_response(code, message) - self.send_header("Content-Type", self.error_content_type) - self.send_header('Connection', 'close') - self.end_headers() - if self.command != 'HEAD' and code >= 200 and code not in (204, 304): - self.wfile.write(content) - - error_message_format = DEFAULT_ERROR_MESSAGE - error_content_type = DEFAULT_ERROR_CONTENT_TYPE - - def send_response(self, code, message=None): - """Send the response header and log the response code. - - Also send two standard headers with the server software - version and the current date. - - """ - self.log_request(code) - if message is None: - if code in self.responses: - message = self.responses[code][0] - else: - message = '' - if self.request_version != 'HTTP/0.9': - self.wfile.write("%s %d %s\r\n" % - (self.protocol_version, code, message)) - # print (self.protocol_version, code, message) - self.send_header('Server', self.version_string()) - self.send_header('Date', self.date_time_string()) - - def send_header(self, keyword, value): - """Send a MIME header.""" - if self.request_version != 'HTTP/0.9': - self.wfile.write("%s: %s\r\n" % (keyword, value)) - - if keyword.lower() == 'connection': - if value.lower() == 'close': - self.close_connection = 1 - elif value.lower() == 'keep-alive': - self.close_connection = 0 - - def end_headers(self): - """Send the blank line ending the MIME headers.""" - if self.request_version != 'HTTP/0.9': - self.wfile.write("\r\n") - - def log_request(self, code='-', size='-'): - """Log an accepted request. - - This is called by send_response(). - - """ - - self.log_message('"%s" %s %s', - self.requestline, str(code), str(size)) - - def log_error(self, format, *args): - """Log an error. - - This is called when a request cannot be fulfilled. By - default it passes the message on to log_message(). - - Arguments are the same as for log_message(). - - XXX This should go to the separate error log. - - """ - - self.log_message(format, *args) - - def log_message(self, format, *args): - """Log an arbitrary message. - - This is used by all other logging functions. Override - it if you have specific logging wishes. - - The first argument, FORMAT, is a format string for the - message to be logged. If the format string contains - any % escapes requiring parameters, they should be - specified as subsequent arguments (it's just like - printf!). - - The client ip address and current date/time are prefixed to every - message. - - """ - - sys.stderr.write("%s - - [%s] %s\n" % - (self.client_address[0], - self.log_date_time_string(), - format%args)) - - def version_string(self): - """Return the server software version string.""" - return self.server_version + ' ' + self.sys_version - - def date_time_string(self, timestamp=None): - """Return the current date and time formatted for a message header.""" - if timestamp is None: - timestamp = time.time() - year, month, day, hh, mm, ss, wd, y, z = time.gmtime(timestamp) - s = "%s, %02d %3s %4d %02d:%02d:%02d GMT" % ( - self.weekdayname[wd], - day, self.monthname[month], year, - hh, mm, ss) - return s - - def log_date_time_string(self): - """Return the current time formatted for logging.""" - now = time.time() - year, month, day, hh, mm, ss, x, y, z = time.localtime(now) - s = "%02d/%3s/%04d %02d:%02d:%02d" % ( - day, self.monthname[month], year, hh, mm, ss) - return s - - weekdayname = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] - - monthname = [None, - 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', - 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] - - def address_string(self): - """Return the client address formatted for logging. - - This version looks up the full hostname using gethostbyaddr(), - and tries to find a name that contains at least one dot. - - """ - - host, port = self.client_address[:2] - return socket.getfqdn(host) - - # Essentially static class variables - - # The version of the HTTP protocol we support. - # Set this to HTTP/1.1 to enable automatic keepalive - protocol_version = "HTTP/1.0" - - # The Message-like class used to parse headers - MessageClass = mimetools.Message - - # Table mapping response codes to messages; entries have the - # form {code: (shortmessage, longmessage)}. - # See RFC 2616. - responses = { - 100: ('Continue', 'Request received, please continue'), - 101: ('Switching Protocols', - 'Switching to new protocol; obey Upgrade header'), - - 200: ('OK', 'Request fulfilled, document follows'), - 201: ('Created', 'Document created, URL follows'), - 202: ('Accepted', - 'Request accepted, processing continues off-line'), - 203: ('Non-Authoritative Information', 'Request fulfilled from cache'), - 204: ('No Content', 'Request fulfilled, nothing follows'), - 205: ('Reset Content', 'Clear input form for further input.'), - 206: ('Partial Content', 'Partial content follows.'), - - 300: ('Multiple Choices', - 'Object has several resources -- see URI list'), - 301: ('Moved Permanently', 'Object moved permanently -- see URI list'), - 302: ('Found', 'Object moved temporarily -- see URI list'), - 303: ('See Other', 'Object moved -- see Method and URL list'), - 304: ('Not Modified', - 'Document has not changed since given time'), - 305: ('Use Proxy', - 'You must use proxy specified in Location to access this ' - 'resource.'), - 307: ('Temporary Redirect', - 'Object moved temporarily -- see URI list'), - - 400: ('Bad Request', - 'Bad request syntax or unsupported method'), - 401: ('Unauthorized', - 'No permission -- see authorization schemes'), - 402: ('Payment Required', - 'No payment -- see charging schemes'), - 403: ('Forbidden', - 'Request forbidden -- authorization will not help'), - 404: ('Not Found', 'Nothing matches the given URI'), - 405: ('Method Not Allowed', - 'Specified method is invalid for this resource.'), - 406: ('Not Acceptable', 'URI not available in preferred format.'), - 407: ('Proxy Authentication Required', 'You must authenticate with ' - 'this proxy before proceeding.'), - 408: ('Request Timeout', 'Request timed out; try again later.'), - 409: ('Conflict', 'Request conflict.'), - 410: ('Gone', - 'URI no longer exists and has been permanently removed.'), - 411: ('Length Required', 'Client must specify Content-Length.'), - 412: ('Precondition Failed', 'Precondition in headers is false.'), - 413: ('Request Entity Too Large', 'Entity is too large.'), - 414: ('Request-URI Too Long', 'URI is too long.'), - 415: ('Unsupported Media Type', 'Entity body in unsupported format.'), - 416: ('Requested Range Not Satisfiable', - 'Cannot satisfy request range.'), - 417: ('Expectation Failed', - 'Expect condition could not be satisfied.'), - - 500: ('Internal Server Error', 'Server got itself in trouble'), - 501: ('Not Implemented', - 'Server does not support this operation'), - 502: ('Bad Gateway', 'Invalid responses from another server/proxy.'), - 503: ('Service Unavailable', - 'The server cannot process the request due to a high load'), - 504: ('Gateway Timeout', - 'The gateway server did not receive a timely response'), - 505: ('HTTP Version Not Supported', 'Cannot fulfill request.'), - } - - -def test(HandlerClass = BaseHTTPRequestHandler, - ServerClass = HTTPServer, protocol="HTTP/1.0"): - """Test the HTTP request handler class. - - This runs an HTTP server on port 8000 (or the first command line - argument). - - """ - - if sys.argv[1:]: - port = int(sys.argv[1]) - else: - port = 8000 - server_address = ('', port) - - HandlerClass.protocol_version = protocol - httpd = ServerClass(server_address, HandlerClass) - - sa = httpd.socket.getsockname() - print "Serving HTTP on", sa[0], "port", sa[1], "..." - httpd.serve_forever() - - -if __name__ == '__main__': - test() diff --git a/PythonLib/full/Bastion.py b/PythonLib/full/Bastion.py deleted file mode 100644 index d0dddbfd..00000000 --- a/PythonLib/full/Bastion.py +++ /dev/null @@ -1,180 +0,0 @@ -"""Bastionification utility. - -A bastion (for another object -- the 'original') is an object that has -the same methods as the original but does not give access to its -instance variables. Bastions have a number of uses, but the most -obvious one is to provide code executing in restricted mode with a -safe interface to an object implemented in unrestricted mode. - -The bastionification routine has an optional second argument which is -a filter function. Only those methods for which the filter method -(called with the method name as argument) returns true are accessible. -The default filter method returns true unless the method name begins -with an underscore. - -There are a number of possible implementations of bastions. We use a -'lazy' approach where the bastion's __getattr__() discipline does all -the work for a particular method the first time it is used. This is -usually fastest, especially if the user doesn't call all available -methods. The retrieved methods are stored as instance variables of -the bastion, so the overhead is only occurred on the first use of each -method. - -Detail: the bastion class has a __repr__() discipline which includes -the repr() of the original object. This is precomputed when the -bastion is created. - -""" -from warnings import warnpy3k -warnpy3k("the Bastion module has been removed in Python 3.0", stacklevel=2) -del warnpy3k - -__all__ = ["BastionClass", "Bastion"] - -from types import MethodType - - -class BastionClass: - - """Helper class used by the Bastion() function. - - You could subclass this and pass the subclass as the bastionclass - argument to the Bastion() function, as long as the constructor has - the same signature (a get() function and a name for the object). - - """ - - def __init__(self, get, name): - """Constructor. - - Arguments: - - get - a function that gets the attribute value (by name) - name - a human-readable name for the original object - (suggestion: use repr(object)) - - """ - self._get_ = get - self._name_ = name - - def __repr__(self): - """Return a representation string. - - This includes the name passed in to the constructor, so that - if you print the bastion during debugging, at least you have - some idea of what it is. - - """ - return "" % self._name_ - - def __getattr__(self, name): - """Get an as-yet undefined attribute value. - - This calls the get() function that was passed to the - constructor. The result is stored as an instance variable so - that the next time the same attribute is requested, - __getattr__() won't be invoked. - - If the get() function raises an exception, this is simply - passed on -- exceptions are not cached. - - """ - attribute = self._get_(name) - self.__dict__[name] = attribute - return attribute - - -def Bastion(object, filter = lambda name: name[:1] != '_', - name=None, bastionclass=BastionClass): - """Create a bastion for an object, using an optional filter. - - See the Bastion module's documentation for background. - - Arguments: - - object - the original object - filter - a predicate that decides whether a function name is OK; - by default all names are OK that don't start with '_' - name - the name of the object; default repr(object) - bastionclass - class used to create the bastion; default BastionClass - - """ - - raise RuntimeError, "This code is not secure in Python 2.2 and later" - - # Note: we define *two* ad-hoc functions here, get1 and get2. - # Both are intended to be called in the same way: get(name). - # It is clear that the real work (getting the attribute - # from the object and calling the filter) is done in get1. - # Why can't we pass get1 to the bastion? Because the user - # would be able to override the filter argument! With get2, - # overriding the default argument is no security loophole: - # all it does is call it. - # Also notice that we can't place the object and filter as - # instance variables on the bastion object itself, since - # the user has full access to all instance variables! - - def get1(name, object=object, filter=filter): - """Internal function for Bastion(). See source comments.""" - if filter(name): - attribute = getattr(object, name) - if type(attribute) == MethodType: - return attribute - raise AttributeError, name - - def get2(name, get1=get1): - """Internal function for Bastion(). See source comments.""" - return get1(name) - - if name is None: - name = repr(object) - return bastionclass(get2, name) - - -def _test(): - """Test the Bastion() function.""" - class Original: - def __init__(self): - self.sum = 0 - def add(self, n): - self._add(n) - def _add(self, n): - self.sum = self.sum + n - def total(self): - return self.sum - o = Original() - b = Bastion(o) - testcode = """if 1: - b.add(81) - b.add(18) - print "b.total() =", b.total() - try: - print "b.sum =", b.sum, - except: - print "inaccessible" - else: - print "accessible" - try: - print "b._add =", b._add, - except: - print "inaccessible" - else: - print "accessible" - try: - print "b._get_.func_defaults =", map(type, b._get_.func_defaults), - except: - print "inaccessible" - else: - print "accessible" - \n""" - exec testcode - print '='*20, "Using rexec:", '='*20 - import rexec - r = rexec.RExec() - m = r.add_module('__main__') - m.b = b - r.r_exec(testcode) - - -if __name__ == '__main__': - _test() diff --git a/PythonLib/full/CGIHTTPServer.py b/PythonLib/full/CGIHTTPServer.py deleted file mode 100644 index 50e0f7ae..00000000 --- a/PythonLib/full/CGIHTTPServer.py +++ /dev/null @@ -1,377 +0,0 @@ -"""CGI-savvy HTTP Server. - -This module builds on SimpleHTTPServer by implementing GET and POST -requests to cgi-bin scripts. - -If the os.fork() function is not present (e.g. on Windows), -os.popen2() is used as a fallback, with slightly altered semantics; if -that function is not present either (e.g. on Macintosh), only Python -scripts are supported, and they are executed by the current process. - -In all cases, the implementation is intentionally naive -- all -requests are executed sychronously. - -SECURITY WARNING: DON'T USE THIS CODE UNLESS YOU ARE INSIDE A FIREWALL --- it may execute arbitrary Python code or external programs. - -Note that status code 200 is sent prior to execution of a CGI script, so -scripts cannot send other status codes such as 302 (redirect). -""" - - -__version__ = "0.4" - -__all__ = ["CGIHTTPRequestHandler"] - -import os -import sys -import urllib -import BaseHTTPServer -import SimpleHTTPServer -import select -import copy - - -class CGIHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): - - """Complete HTTP server with GET, HEAD and POST commands. - - GET and HEAD also support running CGI scripts. - - The POST command is *only* implemented for CGI scripts. - - """ - - # Determine platform specifics - have_fork = hasattr(os, 'fork') - have_popen2 = hasattr(os, 'popen2') - have_popen3 = hasattr(os, 'popen3') - - # Make rfile unbuffered -- we need to read one line and then pass - # the rest to a subprocess, so we can't use buffered input. - rbufsize = 0 - - def do_POST(self): - """Serve a POST request. - - This is only implemented for CGI scripts. - - """ - - if self.is_cgi(): - self.run_cgi() - else: - self.send_error(501, "Can only POST to CGI scripts") - - def send_head(self): - """Version of send_head that support CGI scripts""" - if self.is_cgi(): - return self.run_cgi() - else: - return SimpleHTTPServer.SimpleHTTPRequestHandler.send_head(self) - - def is_cgi(self): - """Test whether self.path corresponds to a CGI script. - - Returns True and updates the cgi_info attribute to the tuple - (dir, rest) if self.path requires running a CGI script. - Returns False otherwise. - - If any exception is raised, the caller should assume that - self.path was rejected as invalid and act accordingly. - - The default implementation tests whether the normalized url - path begins with one of the strings in self.cgi_directories - (and the next character is a '/' or the end of the string). - """ - collapsed_path = _url_collapse_path(self.path) - dir_sep = collapsed_path.find('/', 1) - head, tail = collapsed_path[:dir_sep], collapsed_path[dir_sep+1:] - if head in self.cgi_directories: - self.cgi_info = head, tail - return True - return False - - cgi_directories = ['/cgi-bin', '/htbin'] - - def is_executable(self, path): - """Test whether argument path is an executable file.""" - return executable(path) - - def is_python(self, path): - """Test whether argument path is a Python script.""" - head, tail = os.path.splitext(path) - return tail.lower() in (".py", ".pyw") - - def run_cgi(self): - """Execute a CGI script.""" - dir, rest = self.cgi_info - - i = rest.find('/') - while i >= 0: - nextdir = rest[:i] - nextrest = rest[i+1:] - - scriptdir = self.translate_path(nextdir) - if os.path.isdir(scriptdir): - dir, rest = nextdir, nextrest - i = rest.find('/') - else: - break - - # find an explicit query string, if present. - i = rest.rfind('?') - if i >= 0: - rest, query = rest[:i], rest[i+1:] - else: - query = '' - - # dissect the part after the directory name into a script name & - # a possible additional path, to be stored in PATH_INFO. - i = rest.find('/') - if i >= 0: - script, rest = rest[:i], rest[i:] - else: - script, rest = rest, '' - - scriptname = dir + '/' + script - scriptfile = self.translate_path(scriptname) - if not os.path.exists(scriptfile): - self.send_error(404, "No such CGI script (%r)" % scriptname) - return - if not os.path.isfile(scriptfile): - self.send_error(403, "CGI script is not a plain file (%r)" % - scriptname) - return - ispy = self.is_python(scriptname) - if not ispy: - if not (self.have_fork or self.have_popen2 or self.have_popen3): - self.send_error(403, "CGI script is not a Python script (%r)" % - scriptname) - return - if not self.is_executable(scriptfile): - self.send_error(403, "CGI script is not executable (%r)" % - scriptname) - return - - # Reference: http://hoohoo.ncsa.uiuc.edu/cgi/env.html - # XXX Much of the following could be prepared ahead of time! - env = copy.deepcopy(os.environ) - env['SERVER_SOFTWARE'] = self.version_string() - env['SERVER_NAME'] = self.server.server_name - env['GATEWAY_INTERFACE'] = 'CGI/1.1' - env['SERVER_PROTOCOL'] = self.protocol_version - env['SERVER_PORT'] = str(self.server.server_port) - env['REQUEST_METHOD'] = self.command - uqrest = urllib.unquote(rest) - env['PATH_INFO'] = uqrest - env['PATH_TRANSLATED'] = self.translate_path(uqrest) - env['SCRIPT_NAME'] = scriptname - if query: - env['QUERY_STRING'] = query - host = self.address_string() - if host != self.client_address[0]: - env['REMOTE_HOST'] = host - env['REMOTE_ADDR'] = self.client_address[0] - authorization = self.headers.getheader("authorization") - if authorization: - authorization = authorization.split() - if len(authorization) == 2: - import base64, binascii - env['AUTH_TYPE'] = authorization[0] - if authorization[0].lower() == "basic": - try: - authorization = base64.decodestring(authorization[1]) - except binascii.Error: - pass - else: - authorization = authorization.split(':') - if len(authorization) == 2: - env['REMOTE_USER'] = authorization[0] - # XXX REMOTE_IDENT - if self.headers.typeheader is None: - env['CONTENT_TYPE'] = self.headers.type - else: - env['CONTENT_TYPE'] = self.headers.typeheader - length = self.headers.getheader('content-length') - if length: - env['CONTENT_LENGTH'] = length - referer = self.headers.getheader('referer') - if referer: - env['HTTP_REFERER'] = referer - accept = [] - for line in self.headers.getallmatchingheaders('accept'): - if line[:1] in "\t\n\r ": - accept.append(line.strip()) - else: - accept = accept + line[7:].split(',') - env['HTTP_ACCEPT'] = ','.join(accept) - ua = self.headers.getheader('user-agent') - if ua: - env['HTTP_USER_AGENT'] = ua - co = filter(None, self.headers.getheaders('cookie')) - if co: - env['HTTP_COOKIE'] = ', '.join(co) - # XXX Other HTTP_* headers - # Since we're setting the env in the parent, provide empty - # values to override previously set values - for k in ('QUERY_STRING', 'REMOTE_HOST', 'CONTENT_LENGTH', - 'HTTP_USER_AGENT', 'HTTP_COOKIE', 'HTTP_REFERER'): - env.setdefault(k, "") - - self.send_response(200, "Script output follows") - - decoded_query = query.replace('+', ' ') - - if self.have_fork: - # Unix -- fork as we should - args = [script] - if '=' not in decoded_query: - args.append(decoded_query) - nobody = nobody_uid() - self.wfile.flush() # Always flush before forking - pid = os.fork() - if pid != 0: - # Parent - pid, sts = os.waitpid(pid, 0) - # throw away additional data [see bug #427345] - while select.select([self.rfile], [], [], 0)[0]: - if not self.rfile.read(1): - break - if sts: - self.log_error("CGI script exit status %#x", sts) - return - # Child - try: - try: - os.setuid(nobody) - except os.error: - pass - os.dup2(self.rfile.fileno(), 0) - os.dup2(self.wfile.fileno(), 1) - os.execve(scriptfile, args, env) - except: - self.server.handle_error(self.request, self.client_address) - os._exit(127) - - else: - # Non Unix - use subprocess - import subprocess - cmdline = [scriptfile] - if self.is_python(scriptfile): - interp = sys.executable - if interp.lower().endswith("w.exe"): - # On Windows, use python.exe, not pythonw.exe - interp = interp[:-5] + interp[-4:] - cmdline = [interp, '-u'] + cmdline - if '=' not in query: - cmdline.append(query) - - self.log_message("command: %s", subprocess.list2cmdline(cmdline)) - try: - nbytes = int(length) - except (TypeError, ValueError): - nbytes = 0 - p = subprocess.Popen(cmdline, - stdin = subprocess.PIPE, - stdout = subprocess.PIPE, - stderr = subprocess.PIPE, - env = env - ) - if self.command.lower() == "post" and nbytes > 0: - data = self.rfile.read(nbytes) - else: - data = None - # throw away additional data [see bug #427345] - while select.select([self.rfile._sock], [], [], 0)[0]: - if not self.rfile._sock.recv(1): - break - stdout, stderr = p.communicate(data) - self.wfile.write(stdout) - if stderr: - self.log_error('%s', stderr) - p.stderr.close() - p.stdout.close() - status = p.returncode - if status: - self.log_error("CGI script exit status %#x", status) - else: - self.log_message("CGI script exited OK") - - -def _url_collapse_path(path): - """ - Given a URL path, remove extra '/'s and '.' path elements and collapse - any '..' references and returns a colllapsed path. - - Implements something akin to RFC-2396 5.2 step 6 to parse relative paths. - The utility of this function is limited to is_cgi method and helps - preventing some security attacks. - - Returns: A tuple of (head, tail) where tail is everything after the final / - and head is everything before it. Head will always start with a '/' and, - if it contains anything else, never have a trailing '/'. - - Raises: IndexError if too many '..' occur within the path. - - """ - # Similar to os.path.split(os.path.normpath(path)) but specific to URL - # path semantics rather than local operating system semantics. - path_parts = path.split('/') - head_parts = [] - for part in path_parts[:-1]: - if part == '..': - head_parts.pop() # IndexError if more '..' than prior parts - elif part and part != '.': - head_parts.append( part ) - if path_parts: - tail_part = path_parts.pop() - if tail_part: - if tail_part == '..': - head_parts.pop() - tail_part = '' - elif tail_part == '.': - tail_part = '' - else: - tail_part = '' - - splitpath = ('/' + '/'.join(head_parts), tail_part) - collapsed_path = "/".join(splitpath) - - return collapsed_path - - -nobody = None - -def nobody_uid(): - """Internal routine to get nobody's uid""" - global nobody - if nobody: - return nobody - try: - import pwd - except ImportError: - return -1 - try: - nobody = pwd.getpwnam('nobody')[2] - except KeyError: - nobody = 1 + max(map(lambda x: x[2], pwd.getpwall())) - return nobody - - -def executable(path): - """Test for executable file.""" - try: - st = os.stat(path) - except os.error: - return False - return st.st_mode & 0111 != 0 - - -def test(HandlerClass = CGIHTTPRequestHandler, - ServerClass = BaseHTTPServer.HTTPServer): - SimpleHTTPServer.test(HandlerClass, ServerClass) - - -if __name__ == '__main__': - test() diff --git a/PythonLib/full/ConfigParser.py b/PythonLib/full/ConfigParser.py deleted file mode 100644 index 7e6cdbc3..00000000 --- a/PythonLib/full/ConfigParser.py +++ /dev/null @@ -1,753 +0,0 @@ -"""Configuration file parser. - -A setup file consists of sections, lead by a "[section]" header, -and followed by "name: value" entries, with continuations and such in -the style of RFC 822. - -The option values can contain format strings which refer to other values in -the same section, or values in a special [DEFAULT] section. - -For example: - - something: %(dir)s/whatever - -would resolve the "%(dir)s" to the value of dir. All reference -expansions are done late, on demand. - -Intrinsic defaults can be specified by passing them into the -ConfigParser constructor as a dictionary. - -class: - -ConfigParser -- responsible for parsing a list of - configuration files, and managing the parsed database. - - methods: - - __init__(defaults=None) - create the parser and specify a dictionary of intrinsic defaults. The - keys must be strings, the values must be appropriate for %()s string - interpolation. Note that `__name__' is always an intrinsic default; - its value is the section's name. - - sections() - return all the configuration section names, sans DEFAULT - - has_section(section) - return whether the given section exists - - has_option(section, option) - return whether the given option exists in the given section - - options(section) - return list of configuration options for the named section - - read(filenames) - read and parse the list of named configuration files, given by - name. A single filename is also allowed. Non-existing files - are ignored. Return list of successfully read files. - - readfp(fp, filename=None) - read and parse one configuration file, given as a file object. - The filename defaults to fp.name; it is only used in error - messages (if fp has no `name' attribute, the string `' is used). - - get(section, option, raw=False, vars=None) - return a string value for the named option. All % interpolations are - expanded in the return values, based on the defaults passed into the - constructor and the DEFAULT section. Additional substitutions may be - provided using the `vars' argument, which must be a dictionary whose - contents override any pre-existing defaults. - - getint(section, options) - like get(), but convert value to an integer - - getfloat(section, options) - like get(), but convert value to a float - - getboolean(section, options) - like get(), but convert value to a boolean (currently case - insensitively defined as 0, false, no, off for False, and 1, true, - yes, on for True). Returns False or True. - - items(section, raw=False, vars=None) - return a list of tuples with (name, value) for each option - in the section. - - remove_section(section) - remove the given file section and all its options - - remove_option(section, option) - remove the given option from the given section - - set(section, option, value) - set the given option - - write(fp) - write the configuration state in .ini format -""" - -try: - from collections import OrderedDict as _default_dict -except ImportError: - # fallback for setup.py which hasn't yet built _collections - _default_dict = dict - -import re - -__all__ = ["NoSectionError", "DuplicateSectionError", "NoOptionError", - "InterpolationError", "InterpolationDepthError", - "InterpolationSyntaxError", "ParsingError", - "MissingSectionHeaderError", - "ConfigParser", "SafeConfigParser", "RawConfigParser", - "DEFAULTSECT", "MAX_INTERPOLATION_DEPTH"] - -DEFAULTSECT = "DEFAULT" - -MAX_INTERPOLATION_DEPTH = 10 - - - -# exception classes -class Error(Exception): - """Base class for ConfigParser exceptions.""" - - def _get_message(self): - """Getter for 'message'; needed only to override deprecation in - BaseException.""" - return self.__message - - def _set_message(self, value): - """Setter for 'message'; needed only to override deprecation in - BaseException.""" - self.__message = value - - # BaseException.message has been deprecated since Python 2.6. To prevent - # DeprecationWarning from popping up over this pre-existing attribute, use - # a new property that takes lookup precedence. - message = property(_get_message, _set_message) - - def __init__(self, msg=''): - self.message = msg - Exception.__init__(self, msg) - - def __repr__(self): - return self.message - - __str__ = __repr__ - -class NoSectionError(Error): - """Raised when no section matches a requested option.""" - - def __init__(self, section): - Error.__init__(self, 'No section: %r' % (section,)) - self.section = section - self.args = (section, ) - -class DuplicateSectionError(Error): - """Raised when a section is multiply-created.""" - - def __init__(self, section): - Error.__init__(self, "Section %r already exists" % section) - self.section = section - self.args = (section, ) - -class NoOptionError(Error): - """A requested option was not found.""" - - def __init__(self, option, section): - Error.__init__(self, "No option %r in section: %r" % - (option, section)) - self.option = option - self.section = section - self.args = (option, section) - -class InterpolationError(Error): - """Base class for interpolation-related exceptions.""" - - def __init__(self, option, section, msg): - Error.__init__(self, msg) - self.option = option - self.section = section - self.args = (option, section, msg) - -class InterpolationMissingOptionError(InterpolationError): - """A string substitution required a setting which was not available.""" - - def __init__(self, option, section, rawval, reference): - msg = ("Bad value substitution:\n" - "\tsection: [%s]\n" - "\toption : %s\n" - "\tkey : %s\n" - "\trawval : %s\n" - % (section, option, reference, rawval)) - InterpolationError.__init__(self, option, section, msg) - self.reference = reference - self.args = (option, section, rawval, reference) - -class InterpolationSyntaxError(InterpolationError): - """Raised when the source text into which substitutions are made - does not conform to the required syntax.""" - -class InterpolationDepthError(InterpolationError): - """Raised when substitutions are nested too deeply.""" - - def __init__(self, option, section, rawval): - msg = ("Value interpolation too deeply recursive:\n" - "\tsection: [%s]\n" - "\toption : %s\n" - "\trawval : %s\n" - % (section, option, rawval)) - InterpolationError.__init__(self, option, section, msg) - self.args = (option, section, rawval) - -class ParsingError(Error): - """Raised when a configuration file does not follow legal syntax.""" - - def __init__(self, filename): - Error.__init__(self, 'File contains parsing errors: %s' % filename) - self.filename = filename - self.errors = [] - self.args = (filename, ) - - def append(self, lineno, line): - self.errors.append((lineno, line)) - self.message += '\n\t[line %2d]: %s' % (lineno, line) - -class MissingSectionHeaderError(ParsingError): - """Raised when a key-value pair is found before any section header.""" - - def __init__(self, filename, lineno, line): - Error.__init__( - self, - 'File contains no section headers.\nfile: %s, line: %d\n%r' % - (filename, lineno, line)) - self.filename = filename - self.lineno = lineno - self.line = line - self.args = (filename, lineno, line) - - -class RawConfigParser: - def __init__(self, defaults=None, dict_type=_default_dict, - allow_no_value=False): - self._dict = dict_type - self._sections = self._dict() - self._defaults = self._dict() - if allow_no_value: - self._optcre = self.OPTCRE_NV - else: - self._optcre = self.OPTCRE - if defaults: - for key, value in defaults.items(): - self._defaults[self.optionxform(key)] = value - - def defaults(self): - return self._defaults - - def sections(self): - """Return a list of section names, excluding [DEFAULT]""" - # self._sections will never have [DEFAULT] in it - return self._sections.keys() - - def add_section(self, section): - """Create a new section in the configuration. - - Raise DuplicateSectionError if a section by the specified name - already exists. Raise ValueError if name is DEFAULT or any of it's - case-insensitive variants. - """ - if section.lower() == "default": - raise ValueError, 'Invalid section name: %s' % section - - if section in self._sections: - raise DuplicateSectionError(section) - self._sections[section] = self._dict() - - def has_section(self, section): - """Indicate whether the named section is present in the configuration. - - The DEFAULT section is not acknowledged. - """ - return section in self._sections - - def options(self, section): - """Return a list of option names for the given section name.""" - try: - opts = self._sections[section].copy() - except KeyError: - raise NoSectionError(section) - opts.update(self._defaults) - if '__name__' in opts: - del opts['__name__'] - return opts.keys() - - def read(self, filenames): - """Read and parse a filename or a list of filenames. - - Files that cannot be opened are silently ignored; this is - designed so that you can specify a list of potential - configuration file locations (e.g. current directory, user's - home directory, systemwide directory), and all existing - configuration files in the list will be read. A single - filename may also be given. - - Return list of successfully read files. - """ - if isinstance(filenames, basestring): - filenames = [filenames] - read_ok = [] - for filename in filenames: - try: - fp = open(filename) - except IOError: - continue - self._read(fp, filename) - fp.close() - read_ok.append(filename) - return read_ok - - def readfp(self, fp, filename=None): - """Like read() but the argument must be a file-like object. - - The `fp' argument must have a `readline' method. Optional - second argument is the `filename', which if not given, is - taken from fp.name. If fp has no `name' attribute, `' is - used. - - """ - if filename is None: - try: - filename = fp.name - except AttributeError: - filename = '' - self._read(fp, filename) - - def get(self, section, option): - opt = self.optionxform(option) - if section not in self._sections: - if section != DEFAULTSECT: - raise NoSectionError(section) - if opt in self._defaults: - return self._defaults[opt] - else: - raise NoOptionError(option, section) - elif opt in self._sections[section]: - return self._sections[section][opt] - elif opt in self._defaults: - return self._defaults[opt] - else: - raise NoOptionError(option, section) - - def items(self, section): - try: - d2 = self._sections[section] - except KeyError: - if section != DEFAULTSECT: - raise NoSectionError(section) - d2 = self._dict() - d = self._defaults.copy() - d.update(d2) - if "__name__" in d: - del d["__name__"] - return d.items() - - def _get(self, section, conv, option): - return conv(self.get(section, option)) - - def getint(self, section, option): - return self._get(section, int, option) - - def getfloat(self, section, option): - return self._get(section, float, option) - - _boolean_states = {'1': True, 'yes': True, 'true': True, 'on': True, - '0': False, 'no': False, 'false': False, 'off': False} - - def getboolean(self, section, option): - v = self.get(section, option) - if v.lower() not in self._boolean_states: - raise ValueError, 'Not a boolean: %s' % v - return self._boolean_states[v.lower()] - - def optionxform(self, optionstr): - return optionstr.lower() - - def has_option(self, section, option): - """Check for the existence of a given option in a given section.""" - if not section or section == DEFAULTSECT: - option = self.optionxform(option) - return option in self._defaults - elif section not in self._sections: - return False - else: - option = self.optionxform(option) - return (option in self._sections[section] - or option in self._defaults) - - def set(self, section, option, value=None): - """Set an option.""" - if not section or section == DEFAULTSECT: - sectdict = self._defaults - else: - try: - sectdict = self._sections[section] - except KeyError: - raise NoSectionError(section) - sectdict[self.optionxform(option)] = value - - def write(self, fp): - """Write an .ini-format representation of the configuration state.""" - if self._defaults: - fp.write("[%s]\n" % DEFAULTSECT) - for (key, value) in self._defaults.items(): - fp.write("%s = %s\n" % (key, str(value).replace('\n', '\n\t'))) - fp.write("\n") - for section in self._sections: - fp.write("[%s]\n" % section) - for (key, value) in self._sections[section].items(): - if key == "__name__": - continue - if (value is not None) or (self._optcre == self.OPTCRE): - key = " = ".join((key, str(value).replace('\n', '\n\t'))) - fp.write("%s\n" % (key)) - fp.write("\n") - - def remove_option(self, section, option): - """Remove an option.""" - if not section or section == DEFAULTSECT: - sectdict = self._defaults - else: - try: - sectdict = self._sections[section] - except KeyError: - raise NoSectionError(section) - option = self.optionxform(option) - existed = option in sectdict - if existed: - del sectdict[option] - return existed - - def remove_section(self, section): - """Remove a file section.""" - existed = section in self._sections - if existed: - del self._sections[section] - return existed - - # - # Regular expressions for parsing section headers and options. - # - SECTCRE = re.compile( - r'\[' # [ - r'(?P

[^]]+)' # very permissive! - r'\]' # ] - ) - OPTCRE = re.compile( - r'(?P