├── xsizet.ver ├── Application ├── Modules │ ├── requests │ │ ├── packages │ │ │ ├── urllib3 │ │ │ │ ├── contrib │ │ │ │ │ ├── __init__.py │ │ │ │ │ └── ntlmpool.py │ │ │ │ ├── packages │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── ssl_match_hostname │ │ │ │ │ │ └── __init__.py │ │ │ │ │ └── ordered_dict.py │ │ │ │ ├── __init__.py │ │ │ │ ├── filepost.py │ │ │ │ ├── _collections.py │ │ │ │ ├── exceptions.py │ │ │ │ ├── request.py │ │ │ │ ├── fields.py │ │ │ │ └── poolmanager.py │ │ │ ├── __init__.py │ │ │ └── charade │ │ │ │ ├── compat.py │ │ │ │ ├── __init__.py │ │ │ │ ├── constants.py │ │ │ │ ├── euctwprober.py │ │ │ │ ├── euckrprober.py │ │ │ │ ├── gb2312prober.py │ │ │ │ ├── big5prober.py │ │ │ │ ├── cp949prober.py │ │ │ │ ├── charsetprober.py │ │ │ │ ├── mbcsgroupprober.py │ │ │ │ ├── codingstatemachine.py │ │ │ │ ├── utf8prober.py │ │ │ │ ├── escprober.py │ │ │ │ ├── sbcsgroupprober.py │ │ │ │ ├── mbcharsetprober.py │ │ │ │ ├── eucjpprober.py │ │ │ │ ├── sjisprober.py │ │ │ │ ├── charsetgroupprober.py │ │ │ │ ├── sbcharsetprober.py │ │ │ │ ├── latin1prober.py │ │ │ │ ├── universaldetector.py │ │ │ │ ├── escsm.py │ │ │ │ └── chardistribution.py │ │ ├── certs.py │ │ ├── hooks.py │ │ ├── exceptions.py │ │ ├── __init__.py │ │ ├── compat.py │ │ ├── status_codes.py │ │ ├── structures.py │ │ ├── api.py │ │ └── auth.py │ ├── andecore.py │ ├── utils.py │ └── msh2_crc.py ├── Plugins │ ├── CGeoAccessorWrappers.32.dll │ └── CGeoAccessorWrappers.64.dll └── Logic │ ├── misc.py │ ├── zetools.py │ ├── mshjson.py │ ├── cloth.py │ ├── importer.py │ ├── exporter.py │ └── material_manager.py ├── Resources └── UI │ ├── turr.bmp │ ├── export_icon_zetools.bmp │ ├── import_icon_zetools.bmp │ ├── zetools_a2pandemic.bmp │ └── material_icon_zetools.bmp ├── .gitignore ├── Source ├── setup_86.bat ├── setup_64.bat ├── README.md └── XSIZETools_CppHelpers │ ├── XSIZETools_CppHelpers.sln │ └── XSIZETools_CppHelpers.vcxproj ├── LICENSE.txt └── README.md /xsizet.ver: -------------------------------------------------------------------------------- 1 | 1.4.0000 2 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/urllib3/contrib/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Resources/UI/turr.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Schlechtwetterfront/xsizetools/HEAD/Resources/UI/turr.bmp -------------------------------------------------------------------------------- /Application/Modules/requests/packages/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import 2 | 3 | from . import urllib3 4 | -------------------------------------------------------------------------------- /Resources/UI/export_icon_zetools.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Schlechtwetterfront/xsizetools/HEAD/Resources/UI/export_icon_zetools.bmp -------------------------------------------------------------------------------- /Resources/UI/import_icon_zetools.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Schlechtwetterfront/xsizetools/HEAD/Resources/UI/import_icon_zetools.bmp -------------------------------------------------------------------------------- /Resources/UI/zetools_a2pandemic.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Schlechtwetterfront/xsizetools/HEAD/Resources/UI/zetools_a2pandemic.bmp -------------------------------------------------------------------------------- /Resources/UI/material_icon_zetools.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Schlechtwetterfront/xsizetools/HEAD/Resources/UI/material_icon_zetools.bmp -------------------------------------------------------------------------------- /Application/Modules/requests/packages/urllib3/packages/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import 2 | 3 | from . import ssl_match_hostname 4 | 5 | -------------------------------------------------------------------------------- /Application/Plugins/CGeoAccessorWrappers.32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Schlechtwetterfront/xsizetools/HEAD/Application/Plugins/CGeoAccessorWrappers.32.dll -------------------------------------------------------------------------------- /Application/Plugins/CGeoAccessorWrappers.64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Schlechtwetterfront/xsizetools/HEAD/Application/Plugins/CGeoAccessorWrappers.64.dll -------------------------------------------------------------------------------- /Application/Modules/andecore.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Misc utilities. 3 | ''' 4 | 5 | 6 | def chunks(list_, n): 7 | '''Yield n-sized chunks from list_.''' 8 | for i in xrange(0, len(list_), n): 9 | yield list_[i:i + n] 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /Source/XSISDK/ 2 | /XSIZETools_src/ 3 | /Source/XSIZETools_CppHelpers/.vs/ 4 | /Source/XSIZETools_CppHelpers/x64/ 5 | /Source/XSIZETools_CppHelpers/Debug/ 6 | /Source/XSIZETools_CppHelpers/Release/ 7 | 8 | 9 | *.sdf 10 | *.user 11 | *.opendb 12 | *.exp 13 | *.ilk 14 | *.lib 15 | *.pdb 16 | *.db 17 | 18 | *.pyc 19 | *.log 20 | /Resources/export 21 | /Resources/import -------------------------------------------------------------------------------- /Source/setup_86.bat: -------------------------------------------------------------------------------- 1 | echo 86 2 | 3 | @echo off 4 | 5 | SET "SI_PATH=E:\Softimage\Softimage_Mod_Tool_7.5" 6 | SET "VS_PATH=E:\Programme (x86)\Microsoft Visual Studio 14.0" 7 | 8 | call "%SI_PATH%\Application\bin\setenv.bat" 9 | call "%VS_PATH%\VC\vcvarsall.bat" x86 10 | 11 | set PATH 12 | set "XSISDK_ROOT=%SI_PATH%\XSISDK" 13 | 14 | "%VS_PATH%\Common7\IDE\devenv.exe" /useenv 15 | 16 | @echo on -------------------------------------------------------------------------------- /Source/setup_64.bat: -------------------------------------------------------------------------------- 1 | echo 64 2 | 3 | @echo off 4 | 5 | SET "SI_PATH=E:\Program Files\Autodesk\Softimage 2015" 6 | SET "VS_PATH=E:\Programme (x86)\Microsoft Visual Studio 14.0" 7 | 8 | call "%SI_PATH%\Application\bin\setenv.bat" 9 | call "%VS_PATH%\VC\vcvarsall.bat" amd64 10 | 11 | set PATH 12 | set "XSISDK_ROOT=%SI_PATH%\XSISDK" 13 | 14 | "%VS_PATH%\Common7\IDE\devenv.exe" /useenv 15 | 16 | @echo on -------------------------------------------------------------------------------- /Source/README.md: -------------------------------------------------------------------------------- 1 | C++ Source 2 | === 3 | 4 | This is the C++ source for the CGeoAccessorWrappers.xx.dlls. Note that 32 builds use a different SDK and environment than the 64 builds. 5 | 6 | If you want to build with an older XSI SDK version (like 7.5) with a newer Visual Studio version then you will need to adjust 7 | the make files that come with the XSI SDK. I've found that just copying the ´´mkfiles´´ folder from a newer SDK and replacing the 8 | old one with that works just fine. -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | XSIZETools - Softimage exporter and importer for ZeroEngine (Star Wars Battlefront I + II) .msh 3D files. 2 | Code Copyright (C) Benedikt Schatz 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License v3 as published by 6 | the Free Software Foundation. 7 | 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | GNU General Public License http://www.gnu.org/licenses/. -------------------------------------------------------------------------------- /Application/Modules/requests/certs.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | certs.py 6 | ~~~~~~~~ 7 | 8 | This module returns the preferred default CA certificate bundle. 9 | 10 | If you are packaging Requests, e.g., for a Linux distribution or a managed 11 | environment, you can change the definition of where() to return a separately 12 | packaged CA bundle. 13 | """ 14 | 15 | import os.path 16 | 17 | 18 | def where(): 19 | """Return the preferred certificate bundle.""" 20 | # vendored bundle inside Requests 21 | return os.path.join(os.path.dirname(__file__), 'cacert.pem') 22 | 23 | if __name__ == '__main__': 24 | print(where()) 25 | -------------------------------------------------------------------------------- /Application/Logic/misc.py: -------------------------------------------------------------------------------- 1 | ''' 2 | UI functionality for several misc dialogs. 3 | ''' 4 | from win32com.client import constants as const 5 | import webbrowser 6 | xsi = Application 7 | 8 | 9 | def close_csr_OnClicked(): 10 | PPG.Close() 11 | xsi.DeleteObj('CSR') 12 | 13 | 14 | def ERClose_OnClicked(): 15 | PPG.Close() 16 | xsi.DeleteObj('ExportReport') 17 | 18 | 19 | def launch_gt_OnClicked(): 20 | url = 'http://gametoast.com/viewtopic.php?f=36&t=26664' 21 | webbrowser.open_new_tab(url) 22 | 23 | 24 | def launch_website_OnClicked(): 25 | url = 'http://schlechtwetterfront.github.io/xsizetools/' 26 | webbrowser.open_new_tab(url) 27 | 28 | 29 | def Close_OnClicked(): 30 | PPG.Close() 31 | xsi.DeleteObj('ZETH') 32 | -------------------------------------------------------------------------------- /Application/Modules/requests/hooks.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | requests.hooks 5 | ~~~~~~~~~~~~~~ 6 | 7 | This module provides the capabilities for the Requests hooks system. 8 | 9 | Available hooks: 10 | 11 | ``response``: 12 | The response generated from a Request. 13 | 14 | """ 15 | 16 | 17 | HOOKS = ['response'] 18 | 19 | 20 | def default_hooks(): 21 | hooks = {} 22 | for event in HOOKS: 23 | hooks[event] = [] 24 | return hooks 25 | 26 | # TODO: response is the only one 27 | 28 | 29 | def dispatch_hook(key, hooks, hook_data, **kwargs): 30 | """Dispatches a hook dictionary on a given piece of data.""" 31 | 32 | hooks = hooks or dict() 33 | 34 | if key in hooks: 35 | hooks = hooks.get(key) 36 | 37 | if hasattr(hooks, '__call__'): 38 | hooks = [hooks] 39 | 40 | for hook in hooks: 41 | _hook_data = hook(hook_data, **kwargs) 42 | if _hook_data is not None: 43 | hook_data = _hook_data 44 | 45 | return hook_data 46 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/charade/compat.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # Contributor(s): 3 | # Ian Cordasco - port to Python 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2.1 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 18 | # 02110-1301 USA 19 | ######################### END LICENSE BLOCK ######################### 20 | 21 | import sys 22 | 23 | 24 | if sys.version_info < (3, 0): 25 | base_str = (str, unicode) 26 | else: 27 | base_str = (bytes, str) 28 | 29 | 30 | def wrap_ord(a): 31 | if sys.version_info < (3, 0) and isinstance(a, base_str): 32 | return ord(a) 33 | else: 34 | return a 35 | -------------------------------------------------------------------------------- /Source/XSIZETools_CppHelpers/XSIZETools_CppHelpers.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual C++ Express 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XSIZETools_CppHelpers", "XSIZETools_CppHelpers.vcxproj", "{38E3212A-A328-4C37-BF8A-E748D81548F9}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Debug|x64 = Debug|x64 10 | Release|Win32 = Release|Win32 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {38E3212A-A328-4C37-BF8A-E748D81548F9}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {38E3212A-A328-4C37-BF8A-E748D81548F9}.Debug|Win32.Build.0 = Debug|Win32 16 | {38E3212A-A328-4C37-BF8A-E748D81548F9}.Debug|x64.ActiveCfg = Debug|x64 17 | {38E3212A-A328-4C37-BF8A-E748D81548F9}.Debug|x64.Build.0 = Debug|x64 18 | {38E3212A-A328-4C37-BF8A-E748D81548F9}.Release|Win32.ActiveCfg = Release|Win32 19 | {38E3212A-A328-4C37-BF8A-E748D81548F9}.Release|Win32.Build.0 = Release|Win32 20 | {38E3212A-A328-4C37-BF8A-E748D81548F9}.Release|x64.ActiveCfg = Release|x64 21 | {38E3212A-A328-4C37-BF8A-E748D81548F9}.Release|x64.Build.0 = Release|x64 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/charade/__init__.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # This library is free software; you can redistribute it and/or 3 | # modify it under the terms of the GNU Lesser General Public 4 | # License as published by the Free Software Foundation; either 5 | # version 2.1 of the License, or (at your option) any later version. 6 | # 7 | # This library is distributed in the hope that it will be useful, 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | # Lesser General Public License for more details. 11 | # 12 | # You should have received a copy of the GNU Lesser General Public 13 | # License along with this library; if not, write to the Free Software 14 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 15 | # 02110-1301 USA 16 | ######################### END LICENSE BLOCK ######################### 17 | 18 | __version__ = "1.0.3" 19 | from sys import version_info 20 | 21 | 22 | def detect(aBuf): 23 | if ((version_info < (3, 0) and isinstance(aBuf, unicode)) or 24 | (version_info >= (3, 0) and not isinstance(aBuf, bytes))): 25 | raise ValueError('Expected a bytes object, not a unicode object') 26 | 27 | from . import universaldetector 28 | u = universaldetector.UniversalDetector() 29 | u.reset() 30 | u.feed(aBuf) 31 | u.close() 32 | return u.result 33 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/charade/constants.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is Mozilla Universal charset detector code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 2001 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # Shy Shalom - original C code 12 | # 13 | # This library is free software; you can redistribute it and/or 14 | # modify it under the terms of the GNU Lesser General Public 15 | # License as published by the Free Software Foundation; either 16 | # version 2.1 of the License, or (at your option) any later version. 17 | # 18 | # This library is distributed in the hope that it will be useful, 19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 | # Lesser General Public License for more details. 22 | # 23 | # You should have received a copy of the GNU Lesser General Public 24 | # License along with this library; if not, write to the Free Software 25 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 26 | # 02110-1301 USA 27 | ######################### END LICENSE BLOCK ######################### 28 | 29 | _debug = 0 30 | 31 | eDetecting = 0 32 | eFoundIt = 1 33 | eNotMe = 2 34 | 35 | eStart = 0 36 | eError = 1 37 | eItsMe = 2 38 | 39 | SHORTCUT_THRESHOLD = 0.95 40 | -------------------------------------------------------------------------------- /Application/Logic/zetools.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Scripts UI functionality. 3 | ''' 4 | from win32com.client import constants as const 5 | import softimage 6 | reload(softimage) 7 | xsi = Application 8 | addonpath = xsi.InstallationPath(const.siUserAddonPath) 9 | 10 | 11 | def makeaddon_OnClicked(): 12 | oPPG = PPG.Inspected(0) 13 | addon_bone = oPPG.Parameters("addon_bone").Value 14 | print addon_bone, type(addon_bone) 15 | # Make sure the item is valid. 16 | # If no bones were found the item will be set to '1'. 17 | if addon_bone == '1': 18 | return 19 | addon_root_name = oPPG.Parameters("addon_root_name").Value 20 | xsi.GetPrim("Null", addon_root_name) 21 | xsi.MatchTransform(addon_root_name, addon_bone) 22 | 23 | 24 | def setmesh_OnClicked(): 25 | sel = xsi.Selection 26 | if sel.Count > 0: 27 | params = PPG.Inspected(0).Parameters 28 | root_name = params("addon_root_name").Value 29 | is_shadowvolume = params("addon_is_shadowvolume").Value 30 | if softimage.Softimage.get_object(root_name): 31 | if is_shadowvolume is True: 32 | xsi.CopyPaste(sel[0], '', root_name) 33 | selected_name = sel[0].Name 34 | sel[0].Name = "sv_" + selected_name 35 | elif is_shadowvolume is False: 36 | for item in sel: 37 | xsi.CopyPaste(item, '', root_name) 38 | 39 | 40 | def groupbones_OnClicked(): 41 | bones = softimage.Softimage.get_objects('bone*') 42 | if bones: 43 | xsi.CreateGroup('Bones', bones) 44 | -------------------------------------------------------------------------------- /Application/Logic/mshjson.py: -------------------------------------------------------------------------------- 1 | ''' 2 | UI functionality for the msh2text dialog. 3 | ''' 4 | xsi = Application 5 | import msh2 6 | reload(msh2) 7 | import msh2_unpack 8 | reload(msh2_unpack) 9 | import os 10 | 11 | TXTPATH = 'C:\\SWBF2_ModTools\\data_TST\\Worlds\\TST\\msh\\test\\abc.txt' 12 | MSHPATH = 'C:\\SWBF2_ModTools\\data_TST\\Worlds\\TST\\msh\\nab2_prop_fountain.msh' 13 | USE_HARD_PATHS = False 14 | 15 | 16 | def get_paths(): 17 | params = PPG.Inspected(0).Parameters 18 | if USE_HARD_PATHS or params('dev').Value: 19 | return MSHPATH, TXTPATH 20 | return params('mshpath').Value, params('txtpath').Value 21 | 22 | 23 | def msh2txt_OnClicked(): 24 | mshpath, txtpath = get_paths() 25 | if not mshpath or not txtpath: 26 | return 27 | unpacker = msh2_unpack.MSHUnpack(mshpath) 28 | msh = unpacker.unpack() 29 | if PPG.Inspected(0).Parameters('segmented').Value is True: 30 | msh.save_segmented_json(os.path.dirname(txtpath), os.path.basename(txtpath.split('.')[0])) 31 | else: 32 | msh.save_json(txtpath) 33 | 34 | 35 | def txt2msh_OnClicked(): 36 | mshpath, txtpath = get_paths() 37 | if not mshpath or not txtpath: 38 | return 39 | if PPG.Inspected(0).Parameters('segmented').Value is True: 40 | msh = msh2.Msh.load_segmented_json(os.path.dirname(txtpath), os.path.basename(txtpath.split('.')[0])) 41 | else: 42 | msh = msh2.Msh.load_json(txtpath) 43 | if PPG.Inspected(0).Parameters('dev').Value: 44 | msh.save(mshpath + '.msh') 45 | else: 46 | msh.save(mshpath) 47 | -------------------------------------------------------------------------------- /Application/Modules/requests/exceptions.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | requests.exceptions 5 | ~~~~~~~~~~~~~~~~~~~ 6 | 7 | This module contains the set of Requests' exceptions. 8 | 9 | """ 10 | 11 | 12 | class RequestException(IOError): 13 | """There was an ambiguous exception that occurred while handling your 14 | request.""" 15 | 16 | 17 | class HTTPError(RequestException): 18 | """An HTTP error occurred.""" 19 | 20 | def __init__(self, *args, **kwargs): 21 | """ Initializes HTTPError with optional `response` object. """ 22 | self.response = kwargs.pop('response', None) 23 | super(HTTPError, self).__init__(*args, **kwargs) 24 | 25 | 26 | class ConnectionError(RequestException): 27 | """A Connection error occurred.""" 28 | 29 | 30 | class SSLError(ConnectionError): 31 | """An SSL error occurred.""" 32 | 33 | 34 | class Timeout(RequestException): 35 | """The request timed out.""" 36 | 37 | 38 | class URLRequired(RequestException): 39 | """A valid URL is required to make a request.""" 40 | 41 | 42 | class TooManyRedirects(RequestException): 43 | """Too many redirects.""" 44 | 45 | 46 | class MissingSchema(RequestException, ValueError): 47 | """The URL schema (e.g. http or https) is missing.""" 48 | 49 | 50 | class InvalidSchema(RequestException, ValueError): 51 | """See defaults.py for valid schemas.""" 52 | 53 | 54 | class InvalidURL(RequestException, ValueError): 55 | """ The URL provided was somehow invalid. """ 56 | 57 | 58 | class ChunkedEncodingError(RequestException): 59 | """The server declared chunked encoding but sent an invalid chunk.""" 60 | -------------------------------------------------------------------------------- /Application/Modules/utils.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Misc utilities. 3 | ''' 4 | 5 | def add_cloth_property(model): 6 | import softimage 7 | reload(softimage) 8 | import win32com 9 | from win32com.client import constants as const 10 | ps = model.AddProperty('CustomProperty', False, 'ZECloth') 11 | ps.AddParameter3('collisions', const.siString) 12 | ps.AddParameter3('texture', const.siString) 13 | ps.AddParameter3('fixedcluster', const.siString) 14 | ps.AddParameter3('modelname', const.siString, model.Name) 15 | lay = ps.PPGLayout 16 | lay.SetAttribute(const.siUILogicFile, softimage.Softimage.get_plugin_origin('XSIZETools') + '\\Application\\Logic\\cloth.py') 17 | lay.Language = 'pythonscript' 18 | arow = lay.AddRow 19 | erow = lay.EndRow 20 | agr = lay.AddGroup 21 | egr = lay.EndGroup 22 | item = lay.AddItem 23 | button = lay.AddButton 24 | 25 | agr('Texture') 26 | item('texture', 'Texture') 27 | egr() 28 | agr('Collision') 29 | item('collisions', 'Collisions') 30 | arow() 31 | # button('pick_coll', 'Pick Collisions') 32 | button('add_coll', 'Add from Selection') 33 | button('select_coll', 'Add to Selection') 34 | button('remove_coll', 'Clear') 35 | erow() 36 | egr() 37 | arow() 38 | fixed_points_group = agr('Fixed Points', 1) 39 | fixed_points_group.SetAttribute(const.siUIWidthPercentage, 20) 40 | arow() 41 | button('pick_fixed', 'Pick') 42 | # button('add_fixed', 'Add Fixed Points') 43 | button('remove_fixed', 'Clear') 44 | erow() 45 | egr() 46 | remove_button = button('del_prop', 'Remove Cloth') 47 | remove_button.SetAttribute(const.siUICY, 40) 48 | remove_button.SetAttribute(const.siUIWidthPercentage, 80) 49 | erow() 50 | 51 | return ps 52 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/charade/euctwprober.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is mozilla.org code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 1998 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # 12 | # This library is free software; you can redistribute it and/or 13 | # modify it under the terms of the GNU Lesser General Public 14 | # License as published by the Free Software Foundation; either 15 | # version 2.1 of the License, or (at your option) any later version. 16 | # 17 | # This library is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | # Lesser General Public License for more details. 21 | # 22 | # You should have received a copy of the GNU Lesser General Public 23 | # License along with this library; if not, write to the Free Software 24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 25 | # 02110-1301 USA 26 | ######################### END LICENSE BLOCK ######################### 27 | 28 | from .mbcharsetprober import MultiByteCharSetProber 29 | from .codingstatemachine import CodingStateMachine 30 | from .chardistribution import EUCTWDistributionAnalysis 31 | from .mbcssm import EUCTWSMModel 32 | 33 | class EUCTWProber(MultiByteCharSetProber): 34 | def __init__(self): 35 | MultiByteCharSetProber.__init__(self) 36 | self._mCodingSM = CodingStateMachine(EUCTWSMModel) 37 | self._mDistributionAnalyzer = EUCTWDistributionAnalysis() 38 | self.reset() 39 | 40 | def get_charset_name(self): 41 | return "EUC-TW" 42 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/charade/euckrprober.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is mozilla.org code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 1998 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # 12 | # This library is free software; you can redistribute it and/or 13 | # modify it under the terms of the GNU Lesser General Public 14 | # License as published by the Free Software Foundation; either 15 | # version 2.1 of the License, or (at your option) any later version. 16 | # 17 | # This library is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | # Lesser General Public License for more details. 21 | # 22 | # You should have received a copy of the GNU Lesser General Public 23 | # License along with this library; if not, write to the Free Software 24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 25 | # 02110-1301 USA 26 | ######################### END LICENSE BLOCK ######################### 27 | 28 | from .mbcharsetprober import MultiByteCharSetProber 29 | from .codingstatemachine import CodingStateMachine 30 | from .chardistribution import EUCKRDistributionAnalysis 31 | from .mbcssm import EUCKRSMModel 32 | 33 | 34 | class EUCKRProber(MultiByteCharSetProber): 35 | def __init__(self): 36 | MultiByteCharSetProber.__init__(self) 37 | self._mCodingSM = CodingStateMachine(EUCKRSMModel) 38 | self._mDistributionAnalyzer = EUCKRDistributionAnalysis() 39 | self.reset() 40 | 41 | def get_charset_name(self): 42 | return "EUC-KR" 43 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/charade/gb2312prober.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is mozilla.org code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 1998 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # 12 | # This library is free software; you can redistribute it and/or 13 | # modify it under the terms of the GNU Lesser General Public 14 | # License as published by the Free Software Foundation; either 15 | # version 2.1 of the License, or (at your option) any later version. 16 | # 17 | # This library is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | # Lesser General Public License for more details. 21 | # 22 | # You should have received a copy of the GNU Lesser General Public 23 | # License along with this library; if not, write to the Free Software 24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 25 | # 02110-1301 USA 26 | ######################### END LICENSE BLOCK ######################### 27 | 28 | from .mbcharsetprober import MultiByteCharSetProber 29 | from .codingstatemachine import CodingStateMachine 30 | from .chardistribution import GB2312DistributionAnalysis 31 | from .mbcssm import GB2312SMModel 32 | 33 | class GB2312Prober(MultiByteCharSetProber): 34 | def __init__(self): 35 | MultiByteCharSetProber.__init__(self) 36 | self._mCodingSM = CodingStateMachine(GB2312SMModel) 37 | self._mDistributionAnalyzer = GB2312DistributionAnalysis() 38 | self.reset() 39 | 40 | def get_charset_name(self): 41 | return "GB2312" 42 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/charade/big5prober.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is Mozilla Communicator client code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 1998 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # 12 | # This library is free software; you can redistribute it and/or 13 | # modify it under the terms of the GNU Lesser General Public 14 | # License as published by the Free Software Foundation; either 15 | # version 2.1 of the License, or (at your option) any later version. 16 | # 17 | # This library is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | # Lesser General Public License for more details. 21 | # 22 | # You should have received a copy of the GNU Lesser General Public 23 | # License along with this library; if not, write to the Free Software 24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 25 | # 02110-1301 USA 26 | ######################### END LICENSE BLOCK ######################### 27 | 28 | from .mbcharsetprober import MultiByteCharSetProber 29 | from .codingstatemachine import CodingStateMachine 30 | from .chardistribution import Big5DistributionAnalysis 31 | from .mbcssm import Big5SMModel 32 | 33 | 34 | class Big5Prober(MultiByteCharSetProber): 35 | def __init__(self): 36 | MultiByteCharSetProber.__init__(self) 37 | self._mCodingSM = CodingStateMachine(Big5SMModel) 38 | self._mDistributionAnalyzer = Big5DistributionAnalysis() 39 | self.reset() 40 | 41 | def get_charset_name(self): 42 | return "Big5" 43 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/urllib3/__init__.py: -------------------------------------------------------------------------------- 1 | # urllib3/__init__.py 2 | # Copyright 2008-2013 Andrey Petrov and contributors (see CONTRIBUTORS.txt) 3 | # 4 | # This module is part of urllib3 and is released under 5 | # the MIT License: http://www.opensource.org/licenses/mit-license.php 6 | 7 | """ 8 | urllib3 - Thread-safe connection pooling and re-using. 9 | """ 10 | 11 | __author__ = 'Andrey Petrov (andrey.petrov@shazow.net)' 12 | __license__ = 'MIT' 13 | __version__ = 'dev' 14 | 15 | 16 | from .connectionpool import ( 17 | HTTPConnectionPool, 18 | HTTPSConnectionPool, 19 | connection_from_url 20 | ) 21 | 22 | from . import exceptions 23 | from .filepost import encode_multipart_formdata 24 | from .poolmanager import PoolManager, ProxyManager, proxy_from_url 25 | from .response import HTTPResponse 26 | from .util import make_headers, get_host, Timeout 27 | 28 | 29 | # Set default logging handler to avoid "No handler found" warnings. 30 | import logging 31 | try: # Python 2.7+ 32 | from logging import NullHandler 33 | except ImportError: 34 | class NullHandler(logging.Handler): 35 | def emit(self, record): 36 | pass 37 | 38 | logging.getLogger(__name__).addHandler(NullHandler()) 39 | 40 | def add_stderr_logger(level=logging.DEBUG): 41 | """ 42 | Helper for quickly adding a StreamHandler to the logger. Useful for 43 | debugging. 44 | 45 | Returns the handler after adding it. 46 | """ 47 | # This method needs to be in this __init__.py to get the __name__ correct 48 | # even if urllib3 is vendored within another package. 49 | logger = logging.getLogger(__name__) 50 | handler = logging.StreamHandler() 51 | handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s')) 52 | logger.addHandler(handler) 53 | logger.setLevel(level) 54 | logger.debug('Added an stderr logging handler to logger: %s' % __name__) 55 | return handler 56 | 57 | # ... Clean up. 58 | del NullHandler 59 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/charade/cp949prober.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is mozilla.org code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 1998 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # 12 | # This library is free software; you can redistribute it and/or 13 | # modify it under the terms of the GNU Lesser General Public 14 | # License as published by the Free Software Foundation; either 15 | # version 2.1 of the License, or (at your option) any later version. 16 | # 17 | # This library is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | # Lesser General Public License for more details. 21 | # 22 | # You should have received a copy of the GNU Lesser General Public 23 | # License along with this library; if not, write to the Free Software 24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 25 | # 02110-1301 USA 26 | ######################### END LICENSE BLOCK ######################### 27 | 28 | from .mbcharsetprober import MultiByteCharSetProber 29 | from .codingstatemachine import CodingStateMachine 30 | from .chardistribution import EUCKRDistributionAnalysis 31 | from .mbcssm import CP949SMModel 32 | 33 | 34 | class CP949Prober(MultiByteCharSetProber): 35 | def __init__(self): 36 | MultiByteCharSetProber.__init__(self) 37 | self._mCodingSM = CodingStateMachine(CP949SMModel) 38 | # NOTE: CP949 is a superset of EUC-KR, so the distribution should be 39 | # not different. 40 | self._mDistributionAnalyzer = EUCKRDistributionAnalysis() 41 | self.reset() 42 | 43 | def get_charset_name(self): 44 | return "CP949" 45 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/charade/charsetprober.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is Mozilla Universal charset detector code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 2001 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # Shy Shalom - original C code 12 | # 13 | # This library is free software; you can redistribute it and/or 14 | # modify it under the terms of the GNU Lesser General Public 15 | # License as published by the Free Software Foundation; either 16 | # version 2.1 of the License, or (at your option) any later version. 17 | # 18 | # This library is distributed in the hope that it will be useful, 19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 | # Lesser General Public License for more details. 22 | # 23 | # You should have received a copy of the GNU Lesser General Public 24 | # License along with this library; if not, write to the Free Software 25 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 26 | # 02110-1301 USA 27 | ######################### END LICENSE BLOCK ######################### 28 | 29 | from . import constants 30 | import re 31 | 32 | 33 | class CharSetProber: 34 | def __init__(self): 35 | pass 36 | 37 | def reset(self): 38 | self._mState = constants.eDetecting 39 | 40 | def get_charset_name(self): 41 | return None 42 | 43 | def feed(self, aBuf): 44 | pass 45 | 46 | def get_state(self): 47 | return self._mState 48 | 49 | def get_confidence(self): 50 | return 0.0 51 | 52 | def filter_high_bit_only(self, aBuf): 53 | aBuf = re.sub(b'([\x00-\x7F])+', b' ', aBuf) 54 | return aBuf 55 | 56 | def filter_without_english_letters(self, aBuf): 57 | aBuf = re.sub(b'([A-Za-z])+', b' ', aBuf) 58 | return aBuf 59 | 60 | def filter_with_english_letters(self, aBuf): 61 | # TODO 62 | return aBuf 63 | -------------------------------------------------------------------------------- /Application/Modules/requests/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # __ 4 | # /__) _ _ _ _ _/ _ 5 | # / ( (- (/ (/ (- _) / _) 6 | # / 7 | 8 | """ 9 | requests HTTP library 10 | ~~~~~~~~~~~~~~~~~~~~~ 11 | 12 | Requests is an HTTP library, written in Python, for human beings. Basic GET 13 | usage: 14 | 15 | >>> import requests 16 | >>> r = requests.get('http://python.org') 17 | >>> r.status_code 18 | 200 19 | >>> 'Python is a programming language' in r.content 20 | True 21 | 22 | ... or POST: 23 | 24 | >>> payload = dict(key1='value1', key2='value2') 25 | >>> r = requests.post("http://httpbin.org/post", data=payload) 26 | >>> print r.text 27 | { 28 | ... 29 | "form": { 30 | "key2": "value2", 31 | "key1": "value1" 32 | }, 33 | ... 34 | } 35 | 36 | The other HTTP methods are supported - see `requests.api`. Full documentation 37 | is at . 38 | 39 | :copyright: (c) 2013 by Kenneth Reitz. 40 | :license: Apache 2.0, see LICENSE for more details. 41 | 42 | """ 43 | 44 | __title__ = 'requests' 45 | __version__ = '2.0.0' 46 | __build__ = 0x020000 47 | __author__ = 'Kenneth Reitz' 48 | __license__ = 'Apache 2.0' 49 | __copyright__ = 'Copyright 2013 Kenneth Reitz' 50 | 51 | # Attempt to enable urllib3's SNI support, if possible 52 | try: 53 | from .packages.urllib3.contrib import pyopenssl 54 | pyopenssl.inject_into_urllib3() 55 | except ImportError: 56 | pass 57 | 58 | from . import utils 59 | from .models import Request, Response, PreparedRequest 60 | from .api import request, get, head, post, patch, put, delete, options 61 | from .sessions import session, Session 62 | from .status_codes import codes 63 | from .exceptions import ( 64 | RequestException, Timeout, URLRequired, 65 | TooManyRedirects, HTTPError, ConnectionError 66 | ) 67 | 68 | # Set default logging handler to avoid "No handler found" warnings. 69 | import logging 70 | try: # Python 2.7+ 71 | from logging import NullHandler 72 | except ImportError: 73 | class NullHandler(logging.Handler): 74 | def emit(self, record): 75 | pass 76 | 77 | logging.getLogger(__name__).addHandler(NullHandler()) 78 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/charade/mbcsgroupprober.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is Mozilla Universal charset detector code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 2001 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # Shy Shalom - original C code 12 | # Proofpoint, Inc. 13 | # 14 | # This library is free software; you can redistribute it and/or 15 | # modify it under the terms of the GNU Lesser General Public 16 | # License as published by the Free Software Foundation; either 17 | # version 2.1 of the License, or (at your option) any later version. 18 | # 19 | # This library is distributed in the hope that it will be useful, 20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | # Lesser General Public License for more details. 23 | # 24 | # You should have received a copy of the GNU Lesser General Public 25 | # License along with this library; if not, write to the Free Software 26 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 27 | # 02110-1301 USA 28 | ######################### END LICENSE BLOCK ######################### 29 | 30 | from .charsetgroupprober import CharSetGroupProber 31 | from .utf8prober import UTF8Prober 32 | from .sjisprober import SJISProber 33 | from .eucjpprober import EUCJPProber 34 | from .gb2312prober import GB2312Prober 35 | from .euckrprober import EUCKRProber 36 | from .cp949prober import CP949Prober 37 | from .big5prober import Big5Prober 38 | from .euctwprober import EUCTWProber 39 | 40 | 41 | class MBCSGroupProber(CharSetGroupProber): 42 | def __init__(self): 43 | CharSetGroupProber.__init__(self) 44 | self._mProbers = [ 45 | UTF8Prober(), 46 | SJISProber(), 47 | EUCJPProber(), 48 | GB2312Prober(), 49 | EUCKRProber(), 50 | CP949Prober(), 51 | Big5Prober(), 52 | EUCTWProber() 53 | ] 54 | self.reset() 55 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/charade/codingstatemachine.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is mozilla.org code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 1998 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # 12 | # This library is free software; you can redistribute it and/or 13 | # modify it under the terms of the GNU Lesser General Public 14 | # License as published by the Free Software Foundation; either 15 | # version 2.1 of the License, or (at your option) any later version. 16 | # 17 | # This library is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | # Lesser General Public License for more details. 21 | # 22 | # You should have received a copy of the GNU Lesser General Public 23 | # License along with this library; if not, write to the Free Software 24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 25 | # 02110-1301 USA 26 | ######################### END LICENSE BLOCK ######################### 27 | 28 | from .constants import eStart 29 | from .compat import wrap_ord 30 | 31 | 32 | class CodingStateMachine: 33 | def __init__(self, sm): 34 | self._mModel = sm 35 | self._mCurrentBytePos = 0 36 | self._mCurrentCharLen = 0 37 | self.reset() 38 | 39 | def reset(self): 40 | self._mCurrentState = eStart 41 | 42 | def next_state(self, c): 43 | # for each byte we get its class 44 | # if it is first byte, we also get byte length 45 | # PY3K: aBuf is a byte stream, so c is an int, not a byte 46 | byteCls = self._mModel['classTable'][wrap_ord(c)] 47 | if self._mCurrentState == eStart: 48 | self._mCurrentBytePos = 0 49 | self._mCurrentCharLen = self._mModel['charLenTable'][byteCls] 50 | # from byte's class and stateTable, we get its next state 51 | curr_state = (self._mCurrentState * self._mModel['classFactor'] 52 | + byteCls) 53 | self._mCurrentState = self._mModel['stateTable'][curr_state] 54 | self._mCurrentBytePos += 1 55 | return self._mCurrentState 56 | 57 | def get_current_charlen(self): 58 | return self._mCurrentCharLen 59 | 60 | def get_coding_state_machine(self): 61 | return self._mModel['name'] 62 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/charade/utf8prober.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is mozilla.org code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 1998 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # 12 | # This library is free software; you can redistribute it and/or 13 | # modify it under the terms of the GNU Lesser General Public 14 | # License as published by the Free Software Foundation; either 15 | # version 2.1 of the License, or (at your option) any later version. 16 | # 17 | # This library is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | # Lesser General Public License for more details. 21 | # 22 | # You should have received a copy of the GNU Lesser General Public 23 | # License along with this library; if not, write to the Free Software 24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 25 | # 02110-1301 USA 26 | ######################### END LICENSE BLOCK ######################### 27 | 28 | from . import constants 29 | from .charsetprober import CharSetProber 30 | from .codingstatemachine import CodingStateMachine 31 | from .mbcssm import UTF8SMModel 32 | 33 | ONE_CHAR_PROB = 0.5 34 | 35 | 36 | class UTF8Prober(CharSetProber): 37 | def __init__(self): 38 | CharSetProber.__init__(self) 39 | self._mCodingSM = CodingStateMachine(UTF8SMModel) 40 | self.reset() 41 | 42 | def reset(self): 43 | CharSetProber.reset(self) 44 | self._mCodingSM.reset() 45 | self._mNumOfMBChar = 0 46 | 47 | def get_charset_name(self): 48 | return "utf-8" 49 | 50 | def feed(self, aBuf): 51 | for c in aBuf: 52 | codingState = self._mCodingSM.next_state(c) 53 | if codingState == constants.eError: 54 | self._mState = constants.eNotMe 55 | break 56 | elif codingState == constants.eItsMe: 57 | self._mState = constants.eFoundIt 58 | break 59 | elif codingState == constants.eStart: 60 | if self._mCodingSM.get_current_charlen() >= 2: 61 | self._mNumOfMBChar += 1 62 | 63 | if self.get_state() == constants.eDetecting: 64 | if self.get_confidence() > constants.SHORTCUT_THRESHOLD: 65 | self._mState = constants.eFoundIt 66 | 67 | return self.get_state() 68 | 69 | def get_confidence(self): 70 | unlike = 0.99 71 | if self._mNumOfMBChar < 6: 72 | for i in range(0, self._mNumOfMBChar): 73 | unlike = unlike * ONE_CHAR_PROB 74 | return 1.0 - unlike 75 | else: 76 | return unlike 77 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/urllib3/filepost.py: -------------------------------------------------------------------------------- 1 | # urllib3/filepost.py 2 | # Copyright 2008-2013 Andrey Petrov and contributors (see CONTRIBUTORS.txt) 3 | # 4 | # This module is part of urllib3 and is released under 5 | # the MIT License: http://www.opensource.org/licenses/mit-license.php 6 | 7 | import codecs 8 | import mimetypes 9 | 10 | from uuid import uuid4 11 | from io import BytesIO 12 | 13 | from .packages import six 14 | from .packages.six import b 15 | from .fields import RequestField 16 | 17 | writer = codecs.lookup('utf-8')[3] 18 | 19 | 20 | def choose_boundary(): 21 | """ 22 | Our embarassingly-simple replacement for mimetools.choose_boundary. 23 | """ 24 | return uuid4().hex 25 | 26 | 27 | def iter_field_objects(fields): 28 | """ 29 | Iterate over fields. 30 | 31 | Supports list of (k, v) tuples and dicts, and lists of 32 | :class:`~urllib3.fields.RequestField`. 33 | 34 | """ 35 | if isinstance(fields, dict): 36 | i = six.iteritems(fields) 37 | else: 38 | i = iter(fields) 39 | 40 | for field in i: 41 | if isinstance(field, RequestField): 42 | yield field 43 | else: 44 | yield RequestField.from_tuples(*field) 45 | 46 | 47 | def iter_fields(fields): 48 | """ 49 | Iterate over fields. 50 | 51 | .. deprecated :: 52 | 53 | The addition of `~urllib3.fields.RequestField` makes this function 54 | obsolete. Instead, use :func:`iter_field_objects`, which returns 55 | `~urllib3.fields.RequestField` objects, instead. 56 | 57 | Supports list of (k, v) tuples and dicts. 58 | 59 | """ 60 | if isinstance(fields, dict): 61 | return ((k, v) for k, v in six.iteritems(fields)) 62 | 63 | return ((k, v) for k, v in fields) 64 | 65 | 66 | def encode_multipart_formdata(fields, boundary=None): 67 | """ 68 | Encode a dictionary of ``fields`` using the multipart/form-data MIME format. 69 | 70 | :param fields: 71 | Dictionary of fields or list of (key, :class:`~urllib3.fields.RequestField`). 72 | 73 | :param boundary: 74 | If not specified, then a random boundary will be generated using 75 | :func:`mimetools.choose_boundary`. 76 | """ 77 | body = BytesIO() 78 | if boundary is None: 79 | boundary = choose_boundary() 80 | 81 | for field in iter_field_objects(fields): 82 | body.write(b('--%s\r\n' % (boundary))) 83 | 84 | writer(body).write(field.render_headers()) 85 | data = field.data 86 | 87 | if isinstance(data, int): 88 | data = str(data) # Backwards compatibility 89 | 90 | if isinstance(data, six.text_type): 91 | writer(body).write(data) 92 | else: 93 | body.write(data) 94 | 95 | body.write(b'\r\n') 96 | 97 | body.write(b('--%s--\r\n' % (boundary))) 98 | 99 | content_type = str('multipart/form-data; boundary=%s' % boundary) 100 | 101 | return body.getvalue(), content_type 102 | -------------------------------------------------------------------------------- /Application/Logic/cloth.py: -------------------------------------------------------------------------------- 1 | ''' 2 | UI functionality for the cloth dialog. 3 | ''' 4 | xsi = Application 5 | from win32com.client import constants as const 6 | import win32com.client 7 | import softimage 8 | sigen = softimage.SIGeneral() 9 | ADDONPATH = xsi.InstallationPath(const.siUserAddonPath) 10 | 11 | 12 | def del_prop_OnClicked(): 13 | ppg = PPG.Inspected(0) 14 | remove_fixed(PPG.Inspected(0)) 15 | xsi.DeleteObj(ppg) 16 | PPG.Close() 17 | 18 | 19 | def pick_fixed_OnClicked(): 20 | ppg = PPG.Inspected(0) 21 | xsi.SelectObj(ppg.Parent) 22 | xsi.SetPointSelectionFilter() 23 | picked = xsi.PickElement('point', 'Pick Points', 'Pick Points') 24 | remove_fixed(PPG.Inspected(0)) 25 | xsi.CreateClusterFromSubComponent(picked[2], 'ZEFixedPoints') 26 | 27 | 28 | def remove_fixed_OnClicked(): 29 | remove_fixed(PPG.Inspected(0)) 30 | 31 | 32 | def add_fixed_OnClicked(): 33 | xsi.SetPointSelectionFilter() 34 | picked = xsi.PickElement('point', 'Pick Points', 'Pick Points') 35 | fixed = get_fixed_cluster(PPG.Inspected(0).Parent) 36 | if fixed: 37 | xsi.SIAddToCluster(fixed, picked[2]) 38 | return 39 | xsi.CreateClusterFromSubComponent(picked[2], 'ZEFixedPoints') 40 | 41 | 42 | def pick_coll_OnClicked(): 43 | picked = xsi.PickElement('object', 'Pick Collision Object(s)', 'Pick Collision Object(s)') 44 | ppg = PPG.Inspected(0) 45 | ppg.Parameters('collisions').Value = ','.join(element.FullName for element in picked[2]) 46 | 47 | 48 | def remove_coll_OnClicked(): 49 | ppg = PPG.Inspected(0) 50 | ppg.Parameters('collisions').Value = '' 51 | 52 | 53 | def add_coll_OnClicked(): 54 | ppg = PPG.Inspected(0) 55 | ppg.Parameters('collisions').Value = ','.join(element.FullName for element in xsi.Selection) 56 | 57 | 58 | def select_coll_OnClicked(): 59 | ppg = PPG.Inspected(0) 60 | if ppg.Parameters('collisions').Value: 61 | collisions = ppg.Parameters('collisions').Value.split(',') 62 | xsi.SelectObj(collisions) 63 | 64 | #################################################################### 65 | 66 | 67 | def remove_fixed(ppg): 68 | if not ppg.Parent.ActivePrimitive.GetGeometry2(0): 69 | return 70 | 71 | fixed = get_fixed_cluster(ppg.Parent) 72 | if fixed: 73 | xsi.DeleteObj(fixed) 74 | 75 | 76 | def find_model(objName): 77 | xsifact = win32com.client.Dispatch("XSI.Factory") 78 | oColl = xsifact.CreateObject("XSI.Collection") 79 | oColl.items = objName 80 | if oColl.Count > 0: 81 | return oColl(0) 82 | else: 83 | return False 84 | 85 | 86 | def get_fixed_cluster(model): 87 | geo = model.ActivePrimitive.GetGeometry2(0) 88 | for cls in geo.Clusters: 89 | if 'ZEFixed' in cls.Name: 90 | return cls 91 | 92 | 93 | def get_cloth_prop(model): 94 | try: 95 | if model: 96 | for prop in model.Properties: 97 | if 'ZECLoth' in prop.Name: 98 | return prop 99 | except: 100 | return False 101 | -------------------------------------------------------------------------------- /Application/Modules/requests/compat.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | pythoncompat 5 | """ 6 | 7 | from .packages import charade as chardet 8 | 9 | import sys 10 | 11 | # ------- 12 | # Pythons 13 | # ------- 14 | 15 | # Syntax sugar. 16 | _ver = sys.version_info 17 | 18 | #: Python 2.x? 19 | is_py2 = (_ver[0] == 2) 20 | 21 | #: Python 3.x? 22 | is_py3 = (_ver[0] == 3) 23 | 24 | #: Python 3.0.x 25 | is_py30 = (is_py3 and _ver[1] == 0) 26 | 27 | #: Python 3.1.x 28 | is_py31 = (is_py3 and _ver[1] == 1) 29 | 30 | #: Python 3.2.x 31 | is_py32 = (is_py3 and _ver[1] == 2) 32 | 33 | #: Python 3.3.x 34 | is_py33 = (is_py3 and _ver[1] == 3) 35 | 36 | #: Python 3.4.x 37 | is_py34 = (is_py3 and _ver[1] == 4) 38 | 39 | #: Python 2.7.x 40 | is_py27 = (is_py2 and _ver[1] == 7) 41 | 42 | #: Python 2.6.x 43 | is_py26 = (is_py2 and _ver[1] == 6) 44 | 45 | #: Python 2.5.x 46 | is_py25 = (is_py2 and _ver[1] == 5) 47 | 48 | #: Python 2.4.x 49 | is_py24 = (is_py2 and _ver[1] == 4) # I'm assuming this is not by choice. 50 | 51 | 52 | # --------- 53 | # Platforms 54 | # --------- 55 | 56 | 57 | # Syntax sugar. 58 | _ver = sys.version.lower() 59 | 60 | is_pypy = ('pypy' in _ver) 61 | is_jython = ('jython' in _ver) 62 | is_ironpython = ('iron' in _ver) 63 | 64 | # Assume CPython, if nothing else. 65 | is_cpython = not any((is_pypy, is_jython, is_ironpython)) 66 | 67 | # Windows-based system. 68 | is_windows = 'win32' in str(sys.platform).lower() 69 | 70 | # Standard Linux 2+ system. 71 | is_linux = ('linux' in str(sys.platform).lower()) 72 | is_osx = ('darwin' in str(sys.platform).lower()) 73 | is_hpux = ('hpux' in str(sys.platform).lower()) # Complete guess. 74 | is_solaris = ('solar==' in str(sys.platform).lower()) # Complete guess. 75 | 76 | try: 77 | import simplejson as json 78 | except ImportError: 79 | import json 80 | 81 | # --------- 82 | # Specifics 83 | # --------- 84 | 85 | if is_py2: 86 | from urllib import quote, unquote, quote_plus, unquote_plus, urlencode, getproxies, proxy_bypass 87 | from urlparse import urlparse, urlunparse, urljoin, urlsplit, urldefrag 88 | from urllib2 import parse_http_list 89 | import cookielib 90 | from Cookie import Morsel 91 | from StringIO import StringIO 92 | from .packages.urllib3.packages.ordered_dict import OrderedDict 93 | from httplib import IncompleteRead 94 | 95 | builtin_str = str 96 | bytes = str 97 | str = unicode 98 | basestring = basestring 99 | numeric_types = (int, long, float) 100 | 101 | 102 | elif is_py3: 103 | from urllib.parse import urlparse, urlunparse, urljoin, urlsplit, urlencode, quote, unquote, quote_plus, unquote_plus, urldefrag 104 | from urllib.request import parse_http_list, getproxies, proxy_bypass 105 | from http import cookiejar as cookielib 106 | from http.cookies import Morsel 107 | from io import StringIO 108 | from collections import OrderedDict 109 | from http.client import IncompleteRead 110 | 111 | builtin_str = str 112 | str = str 113 | bytes = bytes 114 | basestring = (str, bytes) 115 | numeric_types = (int, float) 116 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/urllib3/_collections.py: -------------------------------------------------------------------------------- 1 | # urllib3/_collections.py 2 | # Copyright 2008-2013 Andrey Petrov and contributors (see CONTRIBUTORS.txt) 3 | # 4 | # This module is part of urllib3 and is released under 5 | # the MIT License: http://www.opensource.org/licenses/mit-license.php 6 | 7 | from collections import MutableMapping 8 | from threading import RLock 9 | 10 | try: # Python 2.7+ 11 | from collections import OrderedDict 12 | except ImportError: 13 | from .packages.ordered_dict import OrderedDict 14 | 15 | 16 | __all__ = ['RecentlyUsedContainer'] 17 | 18 | 19 | _Null = object() 20 | 21 | 22 | class RecentlyUsedContainer(MutableMapping): 23 | """ 24 | Provides a thread-safe dict-like container which maintains up to 25 | ``maxsize`` keys while throwing away the least-recently-used keys beyond 26 | ``maxsize``. 27 | 28 | :param maxsize: 29 | Maximum number of recent elements to retain. 30 | 31 | :param dispose_func: 32 | Every time an item is evicted from the container, 33 | ``dispose_func(value)`` is called. Callback which will get called 34 | """ 35 | 36 | ContainerCls = OrderedDict 37 | 38 | def __init__(self, maxsize=10, dispose_func=None): 39 | self._maxsize = maxsize 40 | self.dispose_func = dispose_func 41 | 42 | self._container = self.ContainerCls() 43 | self.lock = RLock() 44 | 45 | def __getitem__(self, key): 46 | # Re-insert the item, moving it to the end of the eviction line. 47 | with self.lock: 48 | item = self._container.pop(key) 49 | self._container[key] = item 50 | return item 51 | 52 | def __setitem__(self, key, value): 53 | evicted_value = _Null 54 | with self.lock: 55 | # Possibly evict the existing value of 'key' 56 | evicted_value = self._container.get(key, _Null) 57 | self._container[key] = value 58 | 59 | # If we didn't evict an existing value, we might have to evict the 60 | # least recently used item from the beginning of the container. 61 | if len(self._container) > self._maxsize: 62 | _key, evicted_value = self._container.popitem(last=False) 63 | 64 | if self.dispose_func and evicted_value is not _Null: 65 | self.dispose_func(evicted_value) 66 | 67 | def __delitem__(self, key): 68 | with self.lock: 69 | value = self._container.pop(key) 70 | 71 | if self.dispose_func: 72 | self.dispose_func(value) 73 | 74 | def __len__(self): 75 | with self.lock: 76 | return len(self._container) 77 | 78 | def __iter__(self): 79 | raise NotImplementedError('Iteration over this class is unlikely to be threadsafe.') 80 | 81 | def clear(self): 82 | with self.lock: 83 | # Copy pointers to all values, then wipe the mapping 84 | # under Python 2, this copies the list of values twice :-| 85 | values = list(self._container.values()) 86 | self._container.clear() 87 | 88 | if self.dispose_func: 89 | for value in values: 90 | self.dispose_func(value) 91 | 92 | def keys(self): 93 | with self.lock: 94 | return self._container.keys() 95 | -------------------------------------------------------------------------------- /Application/Modules/requests/status_codes.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from .structures import LookupDict 4 | 5 | _codes = { 6 | 7 | # Informational. 8 | 100: ('continue',), 9 | 101: ('switching_protocols',), 10 | 102: ('processing',), 11 | 103: ('checkpoint',), 12 | 122: ('uri_too_long', 'request_uri_too_long'), 13 | 200: ('ok', 'okay', 'all_ok', 'all_okay', 'all_good', '\\o/', '✓'), 14 | 201: ('created',), 15 | 202: ('accepted',), 16 | 203: ('non_authoritative_info', 'non_authoritative_information'), 17 | 204: ('no_content',), 18 | 205: ('reset_content', 'reset'), 19 | 206: ('partial_content', 'partial'), 20 | 207: ('multi_status', 'multiple_status', 'multi_stati', 'multiple_stati'), 21 | 208: ('already_reported',), 22 | 226: ('im_used',), 23 | 24 | # Redirection. 25 | 300: ('multiple_choices',), 26 | 301: ('moved_permanently', 'moved', '\\o-'), 27 | 302: ('found',), 28 | 303: ('see_other', 'other'), 29 | 304: ('not_modified',), 30 | 305: ('use_proxy',), 31 | 306: ('switch_proxy',), 32 | 307: ('temporary_redirect', 'temporary_moved', 'temporary'), 33 | 308: ('resume_incomplete', 'resume'), 34 | 35 | # Client Error. 36 | 400: ('bad_request', 'bad'), 37 | 401: ('unauthorized',), 38 | 402: ('payment_required', 'payment'), 39 | 403: ('forbidden',), 40 | 404: ('not_found', '-o-'), 41 | 405: ('method_not_allowed', 'not_allowed'), 42 | 406: ('not_acceptable',), 43 | 407: ('proxy_authentication_required', 'proxy_auth', 'proxy_authentication'), 44 | 408: ('request_timeout', 'timeout'), 45 | 409: ('conflict',), 46 | 410: ('gone',), 47 | 411: ('length_required',), 48 | 412: ('precondition_failed', 'precondition'), 49 | 413: ('request_entity_too_large',), 50 | 414: ('request_uri_too_large',), 51 | 415: ('unsupported_media_type', 'unsupported_media', 'media_type'), 52 | 416: ('requested_range_not_satisfiable', 'requested_range', 'range_not_satisfiable'), 53 | 417: ('expectation_failed',), 54 | 418: ('im_a_teapot', 'teapot', 'i_am_a_teapot'), 55 | 422: ('unprocessable_entity', 'unprocessable'), 56 | 423: ('locked',), 57 | 424: ('failed_dependency', 'dependency'), 58 | 425: ('unordered_collection', 'unordered'), 59 | 426: ('upgrade_required', 'upgrade'), 60 | 428: ('precondition_required', 'precondition'), 61 | 429: ('too_many_requests', 'too_many'), 62 | 431: ('header_fields_too_large', 'fields_too_large'), 63 | 444: ('no_response', 'none'), 64 | 449: ('retry_with', 'retry'), 65 | 450: ('blocked_by_windows_parental_controls', 'parental_controls'), 66 | 451: ('unavailable_for_legal_reasons', 'legal_reasons'), 67 | 499: ('client_closed_request',), 68 | 69 | # Server Error. 70 | 500: ('internal_server_error', 'server_error', '/o\\', '✗'), 71 | 501: ('not_implemented',), 72 | 502: ('bad_gateway',), 73 | 503: ('service_unavailable', 'unavailable'), 74 | 504: ('gateway_timeout',), 75 | 505: ('http_version_not_supported', 'http_version'), 76 | 506: ('variant_also_negotiates',), 77 | 507: ('insufficient_storage',), 78 | 509: ('bandwidth_limit_exceeded', 'bandwidth'), 79 | 510: ('not_extended',), 80 | } 81 | 82 | codes = LookupDict(name='status_codes') 83 | 84 | for (code, titles) in list(_codes.items()): 85 | for title in titles: 86 | setattr(codes, title, code) 87 | if not title.startswith('\\'): 88 | setattr(codes, title.upper(), code) 89 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # XSIZETools 2 | 3 | **Note** If you encounter any problems with this plugin, try an earlier version by choosing one from 4 | [this link][releases]. 5 | 6 | ## Overview 7 | 8 | XSIZETools is an addon for Softimage with full export and import of 3D .msh files for ZeroEngine (Star Wars Battlefront I and II). That includes geometry, materials with all ZeroEngine-specific flags, animations, collisions and simulated cloth. 9 | 10 | In general, important updates will be gathered into a [release][releases], so choosing the latest release should give you the latest working features. Alternatively you can download the most recent commit directly with the "Download ZIP" button. 11 | 12 | For more information on usage go to the [XSIZETools homepage][homepage]. 13 | 14 | If you encounter bugs or have problems, feel free to post on the [Gametoast forums][gametoast] (you might need to use a proxy) or send me a mail via Github. 15 | 16 | ## Installation 17 | 18 | To use XSIZETools you need the following: 19 | 20 | 1. Choose one of the [releases from here][releases] and download it. 21 | 22 | 1. If you **don't** have a Softimage version of 2011 or higher, 23 | download and install [python][python27] and 24 | [pywin32][pywin27] (pywin32 must be version 217). 25 | 26 | 1. Download and install the [Visual C++ 2015 Redistributable](redist15). 27 | Download both versions by selecting the format and activating the _Download_ button. 28 | If the page doesn't automatically navigate to the Visual C++ 2015 redist select _Tools for Visual Studio 2015_ on the left and then choose _Microsoft Visual C++ 2015 Redistributable_. 29 | 30 | 1. Unzip the downloaded archive into 31 | `C:/users/%user%/Autodesk/Softimage_%version%/Addons/` or `C:/users/%user%/Softimage/Softimage_%version%/Addons/`. 32 | In the end, the directory including `README.md`, `xsizet.ver`, etc should be `C:/Users/%user%/Autodesk/Softimage_2015/Addons/xsizetools/`. 33 | 34 | ## Building from source 35 | 36 | Currently the solution is set up to use two installations of Softimage (one for x64, one for x86) with the corresponding XSISDK. 37 | 38 | Modify `setup_86.bat` and `setup_64.bat` to point it to the correct _SDK paths_ (XSISDK_ROOT) and `setenv.bat`s. After that, use `setup_86.bat` to compile the x86 version and `setup_64.bat` to compile the 64 version. 39 | 40 | ## Links 41 | 42 | - [XSIZETools Homepage][homepage] 43 | - [Gametoast Thread][gametoast] 44 | - [Python Downloads][python] 45 | - [Pywin Downloads][pywin] 46 | - [Python 2.7][python27] + [Pywin][pywin27] 47 | - [Visual C++ 2015 redist][redist15] 48 | 49 | [homepage]: http://schlechtwetterfront.github.io/xsizetools/ "XSIZETools Homepage" 50 | [gametoast]: http://gametoast.com/viewtopic.php?f=36&t=26664 "Gametoast Thread" 51 | [releases]: https://github.com/Schlechtwetterfront/xsizetools/releases "Releases" 52 | [python]: https://www.python.org/downloads/ "Python Download" 53 | [python27]: https://www.python.org/ftp/python/2.7.18/python-2.7.18.msi "Python 2.7" 54 | [pywin27]: https://sourceforge.net/projects/pywin32/files/pywin32/Build%20217/pywin32-217.win32-py2.7.exe/download "Pywin for 2.7" 55 | [pywin]: https://github.com/mhammond/pywin32/releases "Pywin Download" 56 | [redist15]: https://www.visualstudio.com/downloads/download-visual-studio-vs#d-visual-c "C++ 2015 redist" 57 | [redist86]: http://www.microsoft.com/download/en/details.aspx?id=5555 "C++ 2010 redist Download" 58 | [redist64]: http://www.microsoft.com/downloads/de-de/details.aspx?FamilyID=bd512d9e-43c8-4655-81bf-9350143d5867 "C++ 2010 redist Download" 59 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/charade/escprober.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is mozilla.org code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 1998 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # 12 | # This library is free software; you can redistribute it and/or 13 | # modify it under the terms of the GNU Lesser General Public 14 | # License as published by the Free Software Foundation; either 15 | # version 2.1 of the License, or (at your option) any later version. 16 | # 17 | # This library is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | # Lesser General Public License for more details. 21 | # 22 | # You should have received a copy of the GNU Lesser General Public 23 | # License along with this library; if not, write to the Free Software 24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 25 | # 02110-1301 USA 26 | ######################### END LICENSE BLOCK ######################### 27 | 28 | from . import constants 29 | from .escsm import (HZSMModel, ISO2022CNSMModel, ISO2022JPSMModel, 30 | ISO2022KRSMModel) 31 | from .charsetprober import CharSetProber 32 | from .codingstatemachine import CodingStateMachine 33 | from .compat import wrap_ord 34 | 35 | 36 | class EscCharSetProber(CharSetProber): 37 | def __init__(self): 38 | CharSetProber.__init__(self) 39 | self._mCodingSM = [ 40 | CodingStateMachine(HZSMModel), 41 | CodingStateMachine(ISO2022CNSMModel), 42 | CodingStateMachine(ISO2022JPSMModel), 43 | CodingStateMachine(ISO2022KRSMModel) 44 | ] 45 | self.reset() 46 | 47 | def reset(self): 48 | CharSetProber.reset(self) 49 | for codingSM in self._mCodingSM: 50 | if not codingSM: 51 | continue 52 | codingSM.active = True 53 | codingSM.reset() 54 | self._mActiveSM = len(self._mCodingSM) 55 | self._mDetectedCharset = None 56 | 57 | def get_charset_name(self): 58 | return self._mDetectedCharset 59 | 60 | def get_confidence(self): 61 | if self._mDetectedCharset: 62 | return 0.99 63 | else: 64 | return 0.00 65 | 66 | def feed(self, aBuf): 67 | for c in aBuf: 68 | # PY3K: aBuf is a byte array, so c is an int, not a byte 69 | for codingSM in self._mCodingSM: 70 | if not codingSM: 71 | continue 72 | if not codingSM.active: 73 | continue 74 | codingState = codingSM.next_state(wrap_ord(c)) 75 | if codingState == constants.eError: 76 | codingSM.active = False 77 | self._mActiveSM -= 1 78 | if self._mActiveSM <= 0: 79 | self._mState = constants.eNotMe 80 | return self.get_state() 81 | elif codingState == constants.eItsMe: 82 | self._mState = constants.eFoundIt 83 | self._mDetectedCharset = codingSM.get_coding_state_machine() # nopep8 84 | return self.get_state() 85 | 86 | return self.get_state() 87 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/charade/sbcsgroupprober.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is Mozilla Universal charset detector code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 2001 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # Shy Shalom - original C code 12 | # 13 | # This library is free software; you can redistribute it and/or 14 | # modify it under the terms of the GNU Lesser General Public 15 | # License as published by the Free Software Foundation; either 16 | # version 2.1 of the License, or (at your option) any later version. 17 | # 18 | # This library is distributed in the hope that it will be useful, 19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 | # Lesser General Public License for more details. 22 | # 23 | # You should have received a copy of the GNU Lesser General Public 24 | # License along with this library; if not, write to the Free Software 25 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 26 | # 02110-1301 USA 27 | ######################### END LICENSE BLOCK ######################### 28 | 29 | from .charsetgroupprober import CharSetGroupProber 30 | from .sbcharsetprober import SingleByteCharSetProber 31 | from .langcyrillicmodel import (Win1251CyrillicModel, Koi8rModel, 32 | Latin5CyrillicModel, MacCyrillicModel, 33 | Ibm866Model, Ibm855Model) 34 | from .langgreekmodel import Latin7GreekModel, Win1253GreekModel 35 | from .langbulgarianmodel import Latin5BulgarianModel, Win1251BulgarianModel 36 | from .langhungarianmodel import Latin2HungarianModel, Win1250HungarianModel 37 | from .langthaimodel import TIS620ThaiModel 38 | from .langhebrewmodel import Win1255HebrewModel 39 | from .hebrewprober import HebrewProber 40 | 41 | 42 | class SBCSGroupProber(CharSetGroupProber): 43 | def __init__(self): 44 | CharSetGroupProber.__init__(self) 45 | self._mProbers = [ 46 | SingleByteCharSetProber(Win1251CyrillicModel), 47 | SingleByteCharSetProber(Koi8rModel), 48 | SingleByteCharSetProber(Latin5CyrillicModel), 49 | SingleByteCharSetProber(MacCyrillicModel), 50 | SingleByteCharSetProber(Ibm866Model), 51 | SingleByteCharSetProber(Ibm855Model), 52 | SingleByteCharSetProber(Latin7GreekModel), 53 | SingleByteCharSetProber(Win1253GreekModel), 54 | SingleByteCharSetProber(Latin5BulgarianModel), 55 | SingleByteCharSetProber(Win1251BulgarianModel), 56 | SingleByteCharSetProber(Latin2HungarianModel), 57 | SingleByteCharSetProber(Win1250HungarianModel), 58 | SingleByteCharSetProber(TIS620ThaiModel), 59 | ] 60 | hebrewProber = HebrewProber() 61 | logicalHebrewProber = SingleByteCharSetProber(Win1255HebrewModel, 62 | False, hebrewProber) 63 | visualHebrewProber = SingleByteCharSetProber(Win1255HebrewModel, True, 64 | hebrewProber) 65 | hebrewProber.set_model_probers(logicalHebrewProber, visualHebrewProber) 66 | self._mProbers.extend([hebrewProber, logicalHebrewProber, 67 | visualHebrewProber]) 68 | 69 | self.reset() 70 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/charade/mbcharsetprober.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is Mozilla Universal charset detector code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 2001 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # Shy Shalom - original C code 12 | # Proofpoint, Inc. 13 | # 14 | # This library is free software; you can redistribute it and/or 15 | # modify it under the terms of the GNU Lesser General Public 16 | # License as published by the Free Software Foundation; either 17 | # version 2.1 of the License, or (at your option) any later version. 18 | # 19 | # This library is distributed in the hope that it will be useful, 20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | # Lesser General Public License for more details. 23 | # 24 | # You should have received a copy of the GNU Lesser General Public 25 | # License along with this library; if not, write to the Free Software 26 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 27 | # 02110-1301 USA 28 | ######################### END LICENSE BLOCK ######################### 29 | 30 | import sys 31 | from . import constants 32 | from .charsetprober import CharSetProber 33 | 34 | 35 | class MultiByteCharSetProber(CharSetProber): 36 | def __init__(self): 37 | CharSetProber.__init__(self) 38 | self._mDistributionAnalyzer = None 39 | self._mCodingSM = None 40 | self._mLastChar = [0, 0] 41 | 42 | def reset(self): 43 | CharSetProber.reset(self) 44 | if self._mCodingSM: 45 | self._mCodingSM.reset() 46 | if self._mDistributionAnalyzer: 47 | self._mDistributionAnalyzer.reset() 48 | self._mLastChar = [0, 0] 49 | 50 | def get_charset_name(self): 51 | pass 52 | 53 | def feed(self, aBuf): 54 | aLen = len(aBuf) 55 | for i in range(0, aLen): 56 | codingState = self._mCodingSM.next_state(aBuf[i]) 57 | if codingState == constants.eError: 58 | if constants._debug: 59 | sys.stderr.write(self.get_charset_name() 60 | + ' prober hit error at byte ' + str(i) 61 | + '\n') 62 | self._mState = constants.eNotMe 63 | break 64 | elif codingState == constants.eItsMe: 65 | self._mState = constants.eFoundIt 66 | break 67 | elif codingState == constants.eStart: 68 | charLen = self._mCodingSM.get_current_charlen() 69 | if i == 0: 70 | self._mLastChar[1] = aBuf[0] 71 | self._mDistributionAnalyzer.feed(self._mLastChar, charLen) 72 | else: 73 | self._mDistributionAnalyzer.feed(aBuf[i - 1:i + 1], 74 | charLen) 75 | 76 | self._mLastChar[0] = aBuf[aLen - 1] 77 | 78 | if self.get_state() == constants.eDetecting: 79 | if (self._mDistributionAnalyzer.got_enough_data() and 80 | (self.get_confidence() > constants.SHORTCUT_THRESHOLD)): 81 | self._mState = constants.eFoundIt 82 | 83 | return self.get_state() 84 | 85 | def get_confidence(self): 86 | return self._mDistributionAnalyzer.get_confidence() 87 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/urllib3/exceptions.py: -------------------------------------------------------------------------------- 1 | # urllib3/exceptions.py 2 | # Copyright 2008-2013 Andrey Petrov and contributors (see CONTRIBUTORS.txt) 3 | # 4 | # This module is part of urllib3 and is released under 5 | # the MIT License: http://www.opensource.org/licenses/mit-license.php 6 | 7 | 8 | ## Base Exceptions 9 | 10 | class HTTPError(Exception): 11 | "Base exception used by this module." 12 | pass 13 | 14 | 15 | class PoolError(HTTPError): 16 | "Base exception for errors caused within a pool." 17 | def __init__(self, pool, message): 18 | self.pool = pool 19 | HTTPError.__init__(self, "%s: %s" % (pool, message)) 20 | 21 | def __reduce__(self): 22 | # For pickling purposes. 23 | return self.__class__, (None, None) 24 | 25 | 26 | class RequestError(PoolError): 27 | "Base exception for PoolErrors that have associated URLs." 28 | def __init__(self, pool, url, message): 29 | self.url = url 30 | PoolError.__init__(self, pool, message) 31 | 32 | def __reduce__(self): 33 | # For pickling purposes. 34 | return self.__class__, (None, self.url, None) 35 | 36 | 37 | class SSLError(HTTPError): 38 | "Raised when SSL certificate fails in an HTTPS connection." 39 | pass 40 | 41 | 42 | class ProxyError(HTTPError): 43 | "Raised when the connection to a proxy fails." 44 | pass 45 | 46 | 47 | class DecodeError(HTTPError): 48 | "Raised when automatic decoding based on Content-Type fails." 49 | pass 50 | 51 | 52 | ## Leaf Exceptions 53 | 54 | class MaxRetryError(RequestError): 55 | "Raised when the maximum number of retries is exceeded." 56 | 57 | def __init__(self, pool, url, reason=None): 58 | self.reason = reason 59 | 60 | message = "Max retries exceeded with url: %s" % url 61 | if reason: 62 | message += " (Caused by %s: %s)" % (type(reason), reason) 63 | else: 64 | message += " (Caused by redirect)" 65 | 66 | RequestError.__init__(self, pool, url, message) 67 | 68 | 69 | class HostChangedError(RequestError): 70 | "Raised when an existing pool gets a request for a foreign host." 71 | 72 | def __init__(self, pool, url, retries=3): 73 | message = "Tried to open a foreign host with url: %s" % url 74 | RequestError.__init__(self, pool, url, message) 75 | self.retries = retries 76 | 77 | 78 | class TimeoutStateError(HTTPError): 79 | """ Raised when passing an invalid state to a timeout """ 80 | pass 81 | 82 | 83 | class TimeoutError(HTTPError): 84 | """ Raised when a socket timeout error occurs. 85 | 86 | Catching this error will catch both :exc:`ReadTimeoutErrors 87 | ` and :exc:`ConnectTimeoutErrors `. 88 | """ 89 | pass 90 | 91 | 92 | class ReadTimeoutError(TimeoutError, RequestError): 93 | "Raised when a socket timeout occurs while receiving data from a server" 94 | pass 95 | 96 | 97 | # This timeout error does not have a URL attached and needs to inherit from the 98 | # base HTTPError 99 | class ConnectTimeoutError(TimeoutError): 100 | "Raised when a socket timeout occurs while connecting to a server" 101 | pass 102 | 103 | 104 | class EmptyPoolError(PoolError): 105 | "Raised when a pool runs out of connections and no more are allowed." 106 | pass 107 | 108 | 109 | class ClosedPoolError(PoolError): 110 | "Raised when a request enters a pool after the pool has been closed." 111 | pass 112 | 113 | 114 | class LocationParseError(ValueError, HTTPError): 115 | "Raised when get_host or similar fails to parse the URL input." 116 | 117 | def __init__(self, location): 118 | message = "Failed to parse: %s" % location 119 | HTTPError.__init__(self, message) 120 | 121 | self.location = location 122 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/urllib3/packages/ssl_match_hostname/__init__.py: -------------------------------------------------------------------------------- 1 | """The match_hostname() function from Python 3.2, essential when using SSL.""" 2 | 3 | import re 4 | 5 | __version__ = '3.2.2' 6 | 7 | class CertificateError(ValueError): 8 | pass 9 | 10 | def _dnsname_match(dn, hostname, max_wildcards=1): 11 | """Matching according to RFC 6125, section 6.4.3 12 | 13 | http://tools.ietf.org/html/rfc6125#section-6.4.3 14 | """ 15 | pats = [] 16 | if not dn: 17 | return False 18 | 19 | parts = dn.split(r'.') 20 | leftmost = parts[0] 21 | 22 | wildcards = leftmost.count('*') 23 | if wildcards > max_wildcards: 24 | # Issue #17980: avoid denials of service by refusing more 25 | # than one wildcard per fragment. A survery of established 26 | # policy among SSL implementations showed it to be a 27 | # reasonable choice. 28 | raise CertificateError( 29 | "too many wildcards in certificate DNS name: " + repr(dn)) 30 | 31 | # speed up common case w/o wildcards 32 | if not wildcards: 33 | return dn.lower() == hostname.lower() 34 | 35 | # RFC 6125, section 6.4.3, subitem 1. 36 | # The client SHOULD NOT attempt to match a presented identifier in which 37 | # the wildcard character comprises a label other than the left-most label. 38 | if leftmost == '*': 39 | # When '*' is a fragment by itself, it matches a non-empty dotless 40 | # fragment. 41 | pats.append('[^.]+') 42 | elif leftmost.startswith('xn--') or hostname.startswith('xn--'): 43 | # RFC 6125, section 6.4.3, subitem 3. 44 | # The client SHOULD NOT attempt to match a presented identifier 45 | # where the wildcard character is embedded within an A-label or 46 | # U-label of an internationalized domain name. 47 | pats.append(re.escape(leftmost)) 48 | else: 49 | # Otherwise, '*' matches any dotless string, e.g. www* 50 | pats.append(re.escape(leftmost).replace(r'\*', '[^.]*')) 51 | 52 | # add the remaining fragments, ignore any wildcards 53 | for frag in parts[1:]: 54 | pats.append(re.escape(frag)) 55 | 56 | pat = re.compile(r'\A' + r'\.'.join(pats) + r'\Z', re.IGNORECASE) 57 | return pat.match(hostname) 58 | 59 | 60 | def match_hostname(cert, hostname): 61 | """Verify that *cert* (in decoded format as returned by 62 | SSLSocket.getpeercert()) matches the *hostname*. RFC 2818 and RFC 6125 63 | rules are followed, but IP addresses are not accepted for *hostname*. 64 | 65 | CertificateError is raised on failure. On success, the function 66 | returns nothing. 67 | """ 68 | if not cert: 69 | raise ValueError("empty or no certificate") 70 | dnsnames = [] 71 | san = cert.get('subjectAltName', ()) 72 | for key, value in san: 73 | if key == 'DNS': 74 | if _dnsname_match(value, hostname): 75 | return 76 | dnsnames.append(value) 77 | if not dnsnames: 78 | # The subject is only checked when there is no dNSName entry 79 | # in subjectAltName 80 | for sub in cert.get('subject', ()): 81 | for key, value in sub: 82 | # XXX according to RFC 2818, the most specific Common Name 83 | # must be used. 84 | if key == 'commonName': 85 | if _dnsname_match(value, hostname): 86 | return 87 | dnsnames.append(value) 88 | if len(dnsnames) > 1: 89 | raise CertificateError("hostname %r " 90 | "doesn't match either of %s" 91 | % (hostname, ', '.join(map(repr, dnsnames)))) 92 | elif len(dnsnames) == 1: 93 | raise CertificateError("hostname %r " 94 | "doesn't match %r" 95 | % (hostname, dnsnames[0])) 96 | else: 97 | raise CertificateError("no appropriate commonName or " 98 | "subjectAltName fields were found") 99 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/charade/eucjpprober.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is mozilla.org code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 1998 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # 12 | # This library is free software; you can redistribute it and/or 13 | # modify it under the terms of the GNU Lesser General Public 14 | # License as published by the Free Software Foundation; either 15 | # version 2.1 of the License, or (at your option) any later version. 16 | # 17 | # This library is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | # Lesser General Public License for more details. 21 | # 22 | # You should have received a copy of the GNU Lesser General Public 23 | # License along with this library; if not, write to the Free Software 24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 25 | # 02110-1301 USA 26 | ######################### END LICENSE BLOCK ######################### 27 | 28 | import sys 29 | from . import constants 30 | from .mbcharsetprober import MultiByteCharSetProber 31 | from .codingstatemachine import CodingStateMachine 32 | from .chardistribution import EUCJPDistributionAnalysis 33 | from .jpcntx import EUCJPContextAnalysis 34 | from .mbcssm import EUCJPSMModel 35 | 36 | 37 | class EUCJPProber(MultiByteCharSetProber): 38 | def __init__(self): 39 | MultiByteCharSetProber.__init__(self) 40 | self._mCodingSM = CodingStateMachine(EUCJPSMModel) 41 | self._mDistributionAnalyzer = EUCJPDistributionAnalysis() 42 | self._mContextAnalyzer = EUCJPContextAnalysis() 43 | self.reset() 44 | 45 | def reset(self): 46 | MultiByteCharSetProber.reset(self) 47 | self._mContextAnalyzer.reset() 48 | 49 | def get_charset_name(self): 50 | return "EUC-JP" 51 | 52 | def feed(self, aBuf): 53 | aLen = len(aBuf) 54 | for i in range(0, aLen): 55 | # PY3K: aBuf is a byte array, so aBuf[i] is an int, not a byte 56 | codingState = self._mCodingSM.next_state(aBuf[i]) 57 | if codingState == constants.eError: 58 | if constants._debug: 59 | sys.stderr.write(self.get_charset_name() 60 | + ' prober hit error at byte ' + str(i) 61 | + '\n') 62 | self._mState = constants.eNotMe 63 | break 64 | elif codingState == constants.eItsMe: 65 | self._mState = constants.eFoundIt 66 | break 67 | elif codingState == constants.eStart: 68 | charLen = self._mCodingSM.get_current_charlen() 69 | if i == 0: 70 | self._mLastChar[1] = aBuf[0] 71 | self._mContextAnalyzer.feed(self._mLastChar, charLen) 72 | self._mDistributionAnalyzer.feed(self._mLastChar, charLen) 73 | else: 74 | self._mContextAnalyzer.feed(aBuf[i - 1:i + 1], charLen) 75 | self._mDistributionAnalyzer.feed(aBuf[i - 1:i + 1], 76 | charLen) 77 | 78 | self._mLastChar[0] = aBuf[aLen - 1] 79 | 80 | if self.get_state() == constants.eDetecting: 81 | if (self._mContextAnalyzer.got_enough_data() and 82 | (self.get_confidence() > constants.SHORTCUT_THRESHOLD)): 83 | self._mState = constants.eFoundIt 84 | 85 | return self.get_state() 86 | 87 | def get_confidence(self): 88 | contxtCf = self._mContextAnalyzer.get_confidence() 89 | distribCf = self._mDistributionAnalyzer.get_confidence() 90 | return max(contxtCf, distribCf) 91 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/charade/sjisprober.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is mozilla.org code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 1998 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # 12 | # This library is free software; you can redistribute it and/or 13 | # modify it under the terms of the GNU Lesser General Public 14 | # License as published by the Free Software Foundation; either 15 | # version 2.1 of the License, or (at your option) any later version. 16 | # 17 | # This library is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | # Lesser General Public License for more details. 21 | # 22 | # You should have received a copy of the GNU Lesser General Public 23 | # License along with this library; if not, write to the Free Software 24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 25 | # 02110-1301 USA 26 | ######################### END LICENSE BLOCK ######################### 27 | 28 | import sys 29 | from .mbcharsetprober import MultiByteCharSetProber 30 | from .codingstatemachine import CodingStateMachine 31 | from .chardistribution import SJISDistributionAnalysis 32 | from .jpcntx import SJISContextAnalysis 33 | from .mbcssm import SJISSMModel 34 | from . import constants 35 | 36 | 37 | class SJISProber(MultiByteCharSetProber): 38 | def __init__(self): 39 | MultiByteCharSetProber.__init__(self) 40 | self._mCodingSM = CodingStateMachine(SJISSMModel) 41 | self._mDistributionAnalyzer = SJISDistributionAnalysis() 42 | self._mContextAnalyzer = SJISContextAnalysis() 43 | self.reset() 44 | 45 | def reset(self): 46 | MultiByteCharSetProber.reset(self) 47 | self._mContextAnalyzer.reset() 48 | 49 | def get_charset_name(self): 50 | return "SHIFT_JIS" 51 | 52 | def feed(self, aBuf): 53 | aLen = len(aBuf) 54 | for i in range(0, aLen): 55 | codingState = self._mCodingSM.next_state(aBuf[i]) 56 | if codingState == constants.eError: 57 | if constants._debug: 58 | sys.stderr.write(self.get_charset_name() 59 | + ' prober hit error at byte ' + str(i) 60 | + '\n') 61 | self._mState = constants.eNotMe 62 | break 63 | elif codingState == constants.eItsMe: 64 | self._mState = constants.eFoundIt 65 | break 66 | elif codingState == constants.eStart: 67 | charLen = self._mCodingSM.get_current_charlen() 68 | if i == 0: 69 | self._mLastChar[1] = aBuf[0] 70 | self._mContextAnalyzer.feed(self._mLastChar[2 - charLen:], 71 | charLen) 72 | self._mDistributionAnalyzer.feed(self._mLastChar, charLen) 73 | else: 74 | self._mContextAnalyzer.feed(aBuf[i + 1 - charLen:i + 3 75 | - charLen], charLen) 76 | self._mDistributionAnalyzer.feed(aBuf[i - 1:i + 1], 77 | charLen) 78 | 79 | self._mLastChar[0] = aBuf[aLen - 1] 80 | 81 | if self.get_state() == constants.eDetecting: 82 | if (self._mContextAnalyzer.got_enough_data() and 83 | (self.get_confidence() > constants.SHORTCUT_THRESHOLD)): 84 | self._mState = constants.eFoundIt 85 | 86 | return self.get_state() 87 | 88 | def get_confidence(self): 89 | contxtCf = self._mContextAnalyzer.get_confidence() 90 | distribCf = self._mDistributionAnalyzer.get_confidence() 91 | return max(contxtCf, distribCf) 92 | -------------------------------------------------------------------------------- /Application/Modules/requests/structures.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | requests.structures 5 | ~~~~~~~~~~~~~~~~~~~ 6 | 7 | Data structures that power Requests. 8 | 9 | """ 10 | 11 | import os 12 | import collections 13 | from itertools import islice 14 | 15 | 16 | class IteratorProxy(object): 17 | """docstring for IteratorProxy""" 18 | def __init__(self, i): 19 | self.i = i 20 | # self.i = chain.from_iterable(i) 21 | 22 | def __iter__(self): 23 | return self.i 24 | 25 | def __len__(self): 26 | if hasattr(self.i, '__len__'): 27 | return len(self.i) 28 | if hasattr(self.i, 'len'): 29 | return self.i.len 30 | if hasattr(self.i, 'fileno'): 31 | return os.fstat(self.i.fileno()).st_size 32 | 33 | def read(self, n): 34 | return "".join(islice(self.i, None, n)) 35 | 36 | 37 | class CaseInsensitiveDict(collections.MutableMapping): 38 | """ 39 | A case-insensitive ``dict``-like object. 40 | 41 | Implements all methods and operations of 42 | ``collections.MutableMapping`` as well as dict's ``copy``. Also 43 | provides ``lower_items``. 44 | 45 | All keys are expected to be strings. The structure remembers the 46 | case of the last key to be set, and ``iter(instance)``, 47 | ``keys()``, ``items()``, ``iterkeys()``, and ``iteritems()`` 48 | will contain case-sensitive keys. However, querying and contains 49 | testing is case insensitive: 50 | 51 | cid = CaseInsensitiveDict() 52 | cid['Accept'] = 'application/json' 53 | cid['aCCEPT'] == 'application/json' # True 54 | list(cid) == ['Accept'] # True 55 | 56 | For example, ``headers['content-encoding']`` will return the 57 | value of a ``'Content-Encoding'`` response header, regardless 58 | of how the header name was originally stored. 59 | 60 | If the constructor, ``.update``, or equality comparison 61 | operations are given keys that have equal ``.lower()``s, the 62 | behavior is undefined. 63 | 64 | """ 65 | def __init__(self, data=None, **kwargs): 66 | self._store = dict() 67 | if data is None: 68 | data = {} 69 | self.update(data, **kwargs) 70 | 71 | def __setitem__(self, key, value): 72 | # Use the lowercased key for lookups, but store the actual 73 | # key alongside the value. 74 | self._store[key.lower()] = (key, value) 75 | 76 | def __getitem__(self, key): 77 | return self._store[key.lower()][1] 78 | 79 | def __delitem__(self, key): 80 | del self._store[key.lower()] 81 | 82 | def __iter__(self): 83 | return (casedkey for casedkey, mappedvalue in self._store.values()) 84 | 85 | def __len__(self): 86 | return len(self._store) 87 | 88 | def lower_items(self): 89 | """Like iteritems(), but with all lowercase keys.""" 90 | return ( 91 | (lowerkey, keyval[1]) 92 | for (lowerkey, keyval) 93 | in self._store.items() 94 | ) 95 | 96 | def __eq__(self, other): 97 | if isinstance(other, collections.Mapping): 98 | other = CaseInsensitiveDict(other) 99 | else: 100 | return NotImplemented 101 | # Compare insensitively 102 | return dict(self.lower_items()) == dict(other.lower_items()) 103 | 104 | # Copy is required 105 | def copy(self): 106 | return CaseInsensitiveDict(self._store.values()) 107 | 108 | def __repr__(self): 109 | return '%s(%r)' % (self.__class__.__name__, dict(self.items())) 110 | 111 | 112 | class LookupDict(dict): 113 | """Dictionary lookup object.""" 114 | 115 | def __init__(self, name=None): 116 | self.name = name 117 | super(LookupDict, self).__init__() 118 | 119 | def __repr__(self): 120 | return '' % (self.name) 121 | 122 | def __getitem__(self, key): 123 | # We allow fall-through here, so values default to None 124 | 125 | return self.__dict__.get(key, None) 126 | 127 | def get(self, key, default=None): 128 | return self.__dict__.get(key, default) 129 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/charade/charsetgroupprober.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is Mozilla Communicator client code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 1998 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # 12 | # This library is free software; you can redistribute it and/or 13 | # modify it under the terms of the GNU Lesser General Public 14 | # License as published by the Free Software Foundation; either 15 | # version 2.1 of the License, or (at your option) any later version. 16 | # 17 | # This library is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | # Lesser General Public License for more details. 21 | # 22 | # You should have received a copy of the GNU Lesser General Public 23 | # License along with this library; if not, write to the Free Software 24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 25 | # 02110-1301 USA 26 | ######################### END LICENSE BLOCK ######################### 27 | 28 | from . import constants 29 | import sys 30 | from .charsetprober import CharSetProber 31 | 32 | 33 | class CharSetGroupProber(CharSetProber): 34 | def __init__(self): 35 | CharSetProber.__init__(self) 36 | self._mActiveNum = 0 37 | self._mProbers = [] 38 | self._mBestGuessProber = None 39 | 40 | def reset(self): 41 | CharSetProber.reset(self) 42 | self._mActiveNum = 0 43 | for prober in self._mProbers: 44 | if prober: 45 | prober.reset() 46 | prober.active = True 47 | self._mActiveNum += 1 48 | self._mBestGuessProber = None 49 | 50 | def get_charset_name(self): 51 | if not self._mBestGuessProber: 52 | self.get_confidence() 53 | if not self._mBestGuessProber: 54 | return None 55 | # self._mBestGuessProber = self._mProbers[0] 56 | return self._mBestGuessProber.get_charset_name() 57 | 58 | def feed(self, aBuf): 59 | for prober in self._mProbers: 60 | if not prober: 61 | continue 62 | if not prober.active: 63 | continue 64 | st = prober.feed(aBuf) 65 | if not st: 66 | continue 67 | if st == constants.eFoundIt: 68 | self._mBestGuessProber = prober 69 | return self.get_state() 70 | elif st == constants.eNotMe: 71 | prober.active = False 72 | self._mActiveNum -= 1 73 | if self._mActiveNum <= 0: 74 | self._mState = constants.eNotMe 75 | return self.get_state() 76 | return self.get_state() 77 | 78 | def get_confidence(self): 79 | st = self.get_state() 80 | if st == constants.eFoundIt: 81 | return 0.99 82 | elif st == constants.eNotMe: 83 | return 0.01 84 | bestConf = 0.0 85 | self._mBestGuessProber = None 86 | for prober in self._mProbers: 87 | if not prober: 88 | continue 89 | if not prober.active: 90 | if constants._debug: 91 | sys.stderr.write(prober.get_charset_name() 92 | + ' not active\n') 93 | continue 94 | cf = prober.get_confidence() 95 | if constants._debug: 96 | sys.stderr.write('%s confidence = %s\n' % 97 | (prober.get_charset_name(), cf)) 98 | if bestConf < cf: 99 | bestConf = cf 100 | self._mBestGuessProber = prober 101 | if not self._mBestGuessProber: 102 | return 0.0 103 | return bestConf 104 | # else: 105 | # self._mBestGuessProber = self._mProbers[0] 106 | # return self._mBestGuessProber.get_confidence() 107 | -------------------------------------------------------------------------------- /Application/Logic/importer.py: -------------------------------------------------------------------------------- 1 | ''' 2 | UI functionality for the import dialog. 3 | ''' 4 | import softimage 5 | import zetcore 6 | import zetimport 7 | reload(softimage) 8 | reload(zetcore) 9 | reload(zetimport) 10 | from win32com.client import constants as const 11 | import logging 12 | xsi = Application 13 | ADDONPATH = xsi.InstallationPath(const.siUserAddonPath) 14 | sigen = softimage.SIGeneral() 15 | 16 | 17 | def store_flags_OnClicked(): 18 | settings = zetcore.load_settings('import', PPG.Inspected(0)) 19 | zetcore.save_settings('import', settings) 20 | sigen.msg('Stored.') 21 | return 22 | 23 | 24 | def btexpath_OnChanged(): 25 | ppg = PPG.Inspected(0) 26 | checked = ppg.Parameters('btexpath').Value 27 | texpath = ppg.Parameters('texpath') 28 | texpath.SetCapabilityFlag(2, not checked) 29 | 30 | 31 | def help_OnClicked(): 32 | ps = xsi.ActiveSceneRoot.AddProperty('CustomProperty', False, 'ImportHelp') 33 | lay = ps.PPGLayout 34 | lay.Language = "pythonscript" 35 | agr = lay.AddGroup 36 | egr = lay.EndGroup 37 | text = lay.AddStaticText 38 | agr('Import') 39 | text('Imports null-chain and animations from an animation .msh.') 40 | egr() 41 | agr('Texture Folder') 42 | text('''Sets the texture paths to that folder. If the box is unchecked the paths 43 | will be set to the path of the .msh file.''') 44 | egr() 45 | agr('Set Frame Range') 46 | text('''Automatically sets the frame range from the animated frames in the 47 | .msh file.''') 48 | egr() 49 | agr('Apply animation') 50 | text('''Only applies the unpacked animation to the selected hierarchy. Doesn't 51 | import geometry/models or materials.''') 52 | egr() 53 | agr('Null Display Size') 54 | text('''Sets the display size of Nulls. Improves cleanness of the null 55 | chain after import.''') 56 | egr() 57 | agr('Ignore Geometry') 58 | text('''Ignore geometry on import.''') 59 | egr() 60 | agr('Ignore Geometry') 61 | text('''Ignore animation on import.''') 62 | egr() 63 | agr('Color Nulls') 64 | text('''Colors nulls according to type(bone, root, eff).''') 65 | egr() 66 | agr('Hide Effs/Roots') 67 | text('''Hides nulls of the specified type on import. 68 | Type is defined from certain strings appearing in the name: 69 | bone_l_leg is a bone, even if it's no animated/weighted to.''') 70 | egr() 71 | agr('Weld Boundary Edges') 72 | text('''Applies a Weld Op to all geo models with a value of 0.01. The Operator 73 | will persist after the import.''') 74 | egr() 75 | xsi.InspectObj(ps, '', 'ImportHelp', 4, False) 76 | for prop in xsi.ActiveSceneRoot.Properties: 77 | if prop.Name == 'ImportHelp': 78 | xsi.DeleteObj('ImportHelp') 79 | 80 | 81 | def importbutton_OnClicked(): 82 | settings = zetcore.load_settings('import', PPG.Inspected(0)) 83 | import_ = zetimport.Import(xsi, settings) 84 | try: 85 | import_.import_() 86 | except SystemExit: 87 | return 88 | except Exception as e: 89 | if sigen.msg('Encountered an error while importing, copy error to clipboard?', const.siMsgYesNo) == 6: 90 | import win32clipboard, traceback 91 | log_path = zetcore.get_import_log_path() 92 | lines = [] 93 | if log_path: 94 | with open(log_path, 'r') as file_handle: 95 | lines = file_handle.readlines()[-15:] 96 | message = ['Last 15 log lines:', '\n'] 97 | message.extend(['\t{0}'.format(line.strip('\n')) for line in lines]) 98 | message.extend(('\n', 'Traceback:', '\n')) 99 | message.extend(['\t{0}'.format(element) for element in traceback.format_exc().split('\n')]) 100 | message = '\n'.join(message) 101 | 102 | logging.exception('Failed to import') 103 | 104 | win32clipboard.OpenClipboard() 105 | win32clipboard.EmptyClipboard() 106 | try: 107 | win32clipboard.SetClipboardText(message, win32clipboard.CF_TEXT) 108 | except TypeError: 109 | win32clipboard.SetClipboardText(message) 110 | win32clipboard.CloseClipboard() 111 | else: 112 | raise 113 | return 114 | 115 | 116 | def EClose_OnClicked(): 117 | PPG.Close() 118 | xsi.DeleteObj('MSHImport') 119 | -------------------------------------------------------------------------------- /Application/Logic/exporter.py: -------------------------------------------------------------------------------- 1 | ''' 2 | UI functionality for the export dialog. 3 | ''' 4 | from win32com.client import constants as const 5 | import win32com.client 6 | import logging 7 | import softimage 8 | import zetcore 9 | import zetexport 10 | reload(zetcore) 11 | reload(softimage) 12 | reload(zetexport) 13 | xsi = Application 14 | addonpath = xsi.InstallationPath(const.siUserAddonPath) 15 | sigen = softimage.SIGeneral() 16 | 17 | 18 | def store_flags_OnClicked(): 19 | settings = zetcore.load_settings('export', PPG.Inspected(0)) 20 | zetcore.save_settings('export', settings) 21 | sigen.msg('Stored.') 22 | return 23 | 24 | 25 | def exportbutton_OnClicked(): 26 | settings = zetcore.load_settings('export', PPG.Inspected(0)) 27 | export = zetexport.Export(xsi, settings) 28 | try: 29 | export.export() 30 | except SystemExit: 31 | return 32 | except Exception as e: 33 | if sigen.msg('Encountered an error while exporting, copy error to clipboard?', const.siMsgYesNo) == 6: 34 | import win32clipboard, traceback 35 | log_path = zetcore.get_export_log_path() 36 | lines = [] 37 | if log_path: 38 | with open(log_path, 'r') as file_handle: 39 | lines = file_handle.readlines()[-15:] 40 | message = ['Last 15 log lines:', '\n'] 41 | message.extend(['\t{0}'.format(line.strip('\n')) for line in lines]) 42 | message.extend(('\n', 'Traceback:', '\n')) 43 | message.extend(['\t{0}'.format(element) for element in traceback.format_exc().split('\n')]) 44 | message = '\n'.join(message) 45 | 46 | logging.exception('Failed to export') 47 | 48 | win32clipboard.OpenClipboard() 49 | win32clipboard.EmptyClipboard() 50 | win32clipboard.SetClipboardText(message, win32clipboard.CF_TEXT) 51 | win32clipboard.CloseClipboard() 52 | else: 53 | raise 54 | return 55 | 56 | 57 | def check_sel_OnClicked(): 58 | mdls = sigen.get_all_children(xsi.Selection(0)) 59 | if not mdls: 60 | sigen.msg('No models selected.') 61 | return 62 | checksel = zetcore.CheckSel(xsi, mdls, xsi.ActiveSceneRoot, softimage.SIProgressBar()) 63 | checksel.check() 64 | checksel.build_UI() 65 | 66 | 67 | def help_OnClicked(): 68 | ps = xsi.ActiveSceneRoot.AddProperty('CustomProperty', False, 'Export Help') 69 | lay = ps.PPGLayout 70 | lay.Language = "pythonscript" 71 | agr = lay.AddGroup 72 | egr = lay.EndGroup 73 | text = lay.AddStaticText 74 | agr('Auto-Overwrite', 1) 75 | text('Overwrites output files if they already exist.') 76 | egr() 77 | agr('Root model name for .msh filename') 78 | text('''Usees the name of the hierarchy root as filename. 79 | Has to be enabled when using Batch Export.''') 80 | egr() 81 | agr('Batch Export', 1) 82 | text('''Loops through all direct children of the current 83 | selection and exports each one with all its children. Root 84 | model name for .msh filename has to be enabled for this.''') 85 | egr() 86 | agr('Animation') 87 | text('''Exports animation from the current frame range. 88 | Current frame as Basepose only exports the selected frame 89 | and the following to minimize file size. Export Animation 90 | has to be enabled.''') 91 | egr() 92 | agr('Buttons') 93 | text('''Check Sel iterates through the current hierarchy and analyses 94 | every model for problems which could break the export and smaller 95 | problems like unnecessary clusters. 96 | Store Flags stores the current config(path, checked boxes etc). 97 | Export should be self-explanatory.''') 98 | egr() 99 | xsi.InspectObj(ps, '', 'Export Help', 4, False) 100 | for prop in xsi.ActiveSceneRoot.Properties: 101 | if prop.Name == 'Export_Help': 102 | xsi.DeleteObj('Export_Help') 103 | 104 | 105 | def basepose_OnChanged(): 106 | ppg = PPG.Inspected(0) 107 | if ppg.Parameters('basepose').Value: 108 | ppg.Parameters('anim').Value = True 109 | 110 | 111 | def anim_OnChanged(): 112 | ppg = PPG.Inspected(0) 113 | if not ppg.Parameters('anim').Value: 114 | ppg.Parameters('basepose').Value = False 115 | 116 | 117 | def batch_OnChanged(): 118 | ppg = PPG.Inspected(0) 119 | if ppg.Parameters('batch').Value: 120 | ppg.Parameters('rootname').Value = True 121 | 122 | 123 | def EClose_OnClicked(): 124 | PPG.Close() 125 | xsi.DeleteObj('MSHExport') 126 | -------------------------------------------------------------------------------- /Application/Modules/requests/api.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | requests.api 5 | ~~~~~~~~~~~~ 6 | 7 | This module implements the Requests API. 8 | 9 | :copyright: (c) 2012 by Kenneth Reitz. 10 | :license: Apache2, see LICENSE for more details. 11 | 12 | """ 13 | 14 | from . import sessions 15 | 16 | 17 | def request(method, url, **kwargs): 18 | """Constructs and sends a :class:`Request `. 19 | Returns :class:`Response ` object. 20 | 21 | :param method: method for the new :class:`Request` object. 22 | :param url: URL for the new :class:`Request` object. 23 | :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`. 24 | :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. 25 | :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`. 26 | :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`. 27 | :param files: (optional) Dictionary of 'name': file-like-objects (or {'name': ('filename', fileobj)}) for multipart encoding upload. 28 | :param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth. 29 | :param timeout: (optional) Float describing the timeout of the request. 30 | :param allow_redirects: (optional) Boolean. Set to True if POST/PUT/DELETE redirect following is allowed. 31 | :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy. 32 | :param verify: (optional) if ``True``, the SSL cert will be verified. A CA_BUNDLE path can also be provided. 33 | :param stream: (optional) if ``False``, the response content will be immediately downloaded. 34 | :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair. 35 | 36 | Usage:: 37 | 38 | >>> import requests 39 | >>> req = requests.request('GET', 'http://httpbin.org/get') 40 | 41 | """ 42 | 43 | session = sessions.Session() 44 | return session.request(method=method, url=url, **kwargs) 45 | 46 | 47 | def get(url, **kwargs): 48 | """Sends a GET request. Returns :class:`Response` object. 49 | 50 | :param url: URL for the new :class:`Request` object. 51 | :param \*\*kwargs: Optional arguments that ``request`` takes. 52 | """ 53 | 54 | kwargs.setdefault('allow_redirects', True) 55 | return request('get', url, **kwargs) 56 | 57 | 58 | def options(url, **kwargs): 59 | """Sends a OPTIONS request. Returns :class:`Response` object. 60 | 61 | :param url: URL for the new :class:`Request` object. 62 | :param \*\*kwargs: Optional arguments that ``request`` takes. 63 | """ 64 | 65 | kwargs.setdefault('allow_redirects', True) 66 | return request('options', url, **kwargs) 67 | 68 | 69 | def head(url, **kwargs): 70 | """Sends a HEAD request. Returns :class:`Response` object. 71 | 72 | :param url: URL for the new :class:`Request` object. 73 | :param \*\*kwargs: Optional arguments that ``request`` takes. 74 | """ 75 | 76 | kwargs.setdefault('allow_redirects', False) 77 | return request('head', url, **kwargs) 78 | 79 | 80 | def post(url, data=None, **kwargs): 81 | """Sends a POST request. Returns :class:`Response` object. 82 | 83 | :param url: URL for the new :class:`Request` object. 84 | :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. 85 | :param \*\*kwargs: Optional arguments that ``request`` takes. 86 | """ 87 | 88 | return request('post', url, data=data, **kwargs) 89 | 90 | 91 | def put(url, data=None, **kwargs): 92 | """Sends a PUT request. Returns :class:`Response` object. 93 | 94 | :param url: URL for the new :class:`Request` object. 95 | :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. 96 | :param \*\*kwargs: Optional arguments that ``request`` takes. 97 | """ 98 | 99 | return request('put', url, data=data, **kwargs) 100 | 101 | 102 | def patch(url, data=None, **kwargs): 103 | """Sends a PATCH request. Returns :class:`Response` object. 104 | 105 | :param url: URL for the new :class:`Request` object. 106 | :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. 107 | :param \*\*kwargs: Optional arguments that ``request`` takes. 108 | """ 109 | 110 | return request('patch', url, data=data, **kwargs) 111 | 112 | 113 | def delete(url, **kwargs): 114 | """Sends a DELETE request. Returns :class:`Response` object. 115 | 116 | :param url: URL for the new :class:`Request` object. 117 | :param \*\*kwargs: Optional arguments that ``request`` takes. 118 | """ 119 | 120 | return request('delete', url, **kwargs) 121 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/urllib3/contrib/ntlmpool.py: -------------------------------------------------------------------------------- 1 | # urllib3/contrib/ntlmpool.py 2 | # Copyright 2008-2013 Andrey Petrov and contributors (see CONTRIBUTORS.txt) 3 | # 4 | # This module is part of urllib3 and is released under 5 | # the MIT License: http://www.opensource.org/licenses/mit-license.php 6 | 7 | """ 8 | NTLM authenticating pool, contributed by erikcederstran 9 | 10 | Issue #10, see: http://code.google.com/p/urllib3/issues/detail?id=10 11 | """ 12 | 13 | try: 14 | from http.client import HTTPSConnection 15 | except ImportError: 16 | from httplib import HTTPSConnection 17 | from logging import getLogger 18 | from ntlm import ntlm 19 | 20 | from urllib3 import HTTPSConnectionPool 21 | 22 | 23 | log = getLogger(__name__) 24 | 25 | 26 | class NTLMConnectionPool(HTTPSConnectionPool): 27 | """ 28 | Implements an NTLM authentication version of an urllib3 connection pool 29 | """ 30 | 31 | scheme = 'https' 32 | 33 | def __init__(self, user, pw, authurl, *args, **kwargs): 34 | """ 35 | authurl is a random URL on the server that is protected by NTLM. 36 | user is the Windows user, probably in the DOMAIN\\username format. 37 | pw is the password for the user. 38 | """ 39 | super(NTLMConnectionPool, self).__init__(*args, **kwargs) 40 | self.authurl = authurl 41 | self.rawuser = user 42 | user_parts = user.split('\\', 1) 43 | self.domain = user_parts[0].upper() 44 | self.user = user_parts[1] 45 | self.pw = pw 46 | 47 | def _new_conn(self): 48 | # Performs the NTLM handshake that secures the connection. The socket 49 | # must be kept open while requests are performed. 50 | self.num_connections += 1 51 | log.debug('Starting NTLM HTTPS connection no. %d: https://%s%s' % 52 | (self.num_connections, self.host, self.authurl)) 53 | 54 | headers = {} 55 | headers['Connection'] = 'Keep-Alive' 56 | req_header = 'Authorization' 57 | resp_header = 'www-authenticate' 58 | 59 | conn = HTTPSConnection(host=self.host, port=self.port) 60 | 61 | # Send negotiation message 62 | headers[req_header] = ( 63 | 'NTLM %s' % ntlm.create_NTLM_NEGOTIATE_MESSAGE(self.rawuser)) 64 | log.debug('Request headers: %s' % headers) 65 | conn.request('GET', self.authurl, None, headers) 66 | res = conn.getresponse() 67 | reshdr = dict(res.getheaders()) 68 | log.debug('Response status: %s %s' % (res.status, res.reason)) 69 | log.debug('Response headers: %s' % reshdr) 70 | log.debug('Response data: %s [...]' % res.read(100)) 71 | 72 | # Remove the reference to the socket, so that it can not be closed by 73 | # the response object (we want to keep the socket open) 74 | res.fp = None 75 | 76 | # Server should respond with a challenge message 77 | auth_header_values = reshdr[resp_header].split(', ') 78 | auth_header_value = None 79 | for s in auth_header_values: 80 | if s[:5] == 'NTLM ': 81 | auth_header_value = s[5:] 82 | if auth_header_value is None: 83 | raise Exception('Unexpected %s response header: %s' % 84 | (resp_header, reshdr[resp_header])) 85 | 86 | # Send authentication message 87 | ServerChallenge, NegotiateFlags = \ 88 | ntlm.parse_NTLM_CHALLENGE_MESSAGE(auth_header_value) 89 | auth_msg = ntlm.create_NTLM_AUTHENTICATE_MESSAGE(ServerChallenge, 90 | self.user, 91 | self.domain, 92 | self.pw, 93 | NegotiateFlags) 94 | headers[req_header] = 'NTLM %s' % auth_msg 95 | log.debug('Request headers: %s' % headers) 96 | conn.request('GET', self.authurl, None, headers) 97 | res = conn.getresponse() 98 | log.debug('Response status: %s %s' % (res.status, res.reason)) 99 | log.debug('Response headers: %s' % dict(res.getheaders())) 100 | log.debug('Response data: %s [...]' % res.read()[:100]) 101 | if res.status != 200: 102 | if res.status == 401: 103 | raise Exception('Server rejected request: wrong ' 104 | 'username or password') 105 | raise Exception('Wrong server response: %s %s' % 106 | (res.status, res.reason)) 107 | 108 | res.fp = None 109 | log.debug('Connection established') 110 | return conn 111 | 112 | def urlopen(self, method, url, body=None, headers=None, retries=3, 113 | redirect=True, assert_same_host=True): 114 | if headers is None: 115 | headers = {} 116 | headers['Connection'] = 'Keep-Alive' 117 | return super(NTLMConnectionPool, self).urlopen(method, url, body, 118 | headers, retries, 119 | redirect, 120 | assert_same_host) 121 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/charade/sbcharsetprober.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is Mozilla Universal charset detector code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 2001 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # Shy Shalom - original C code 12 | # 13 | # This library is free software; you can redistribute it and/or 14 | # modify it under the terms of the GNU Lesser General Public 15 | # License as published by the Free Software Foundation; either 16 | # version 2.1 of the License, or (at your option) any later version. 17 | # 18 | # This library is distributed in the hope that it will be useful, 19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 | # Lesser General Public License for more details. 22 | # 23 | # You should have received a copy of the GNU Lesser General Public 24 | # License along with this library; if not, write to the Free Software 25 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 26 | # 02110-1301 USA 27 | ######################### END LICENSE BLOCK ######################### 28 | 29 | import sys 30 | from . import constants 31 | from .charsetprober import CharSetProber 32 | from .compat import wrap_ord 33 | 34 | SAMPLE_SIZE = 64 35 | SB_ENOUGH_REL_THRESHOLD = 1024 36 | POSITIVE_SHORTCUT_THRESHOLD = 0.95 37 | NEGATIVE_SHORTCUT_THRESHOLD = 0.05 38 | SYMBOL_CAT_ORDER = 250 39 | NUMBER_OF_SEQ_CAT = 4 40 | POSITIVE_CAT = NUMBER_OF_SEQ_CAT - 1 41 | #NEGATIVE_CAT = 0 42 | 43 | 44 | class SingleByteCharSetProber(CharSetProber): 45 | def __init__(self, model, reversed=False, nameProber=None): 46 | CharSetProber.__init__(self) 47 | self._mModel = model 48 | # TRUE if we need to reverse every pair in the model lookup 49 | self._mReversed = reversed 50 | # Optional auxiliary prober for name decision 51 | self._mNameProber = nameProber 52 | self.reset() 53 | 54 | def reset(self): 55 | CharSetProber.reset(self) 56 | # char order of last character 57 | self._mLastOrder = 255 58 | self._mSeqCounters = [0] * NUMBER_OF_SEQ_CAT 59 | self._mTotalSeqs = 0 60 | self._mTotalChar = 0 61 | # characters that fall in our sampling range 62 | self._mFreqChar = 0 63 | 64 | def get_charset_name(self): 65 | if self._mNameProber: 66 | return self._mNameProber.get_charset_name() 67 | else: 68 | return self._mModel['charsetName'] 69 | 70 | def feed(self, aBuf): 71 | if not self._mModel['keepEnglishLetter']: 72 | aBuf = self.filter_without_english_letters(aBuf) 73 | aLen = len(aBuf) 74 | if not aLen: 75 | return self.get_state() 76 | for c in aBuf: 77 | order = self._mModel['charToOrderMap'][wrap_ord(c)] 78 | if order < SYMBOL_CAT_ORDER: 79 | self._mTotalChar += 1 80 | if order < SAMPLE_SIZE: 81 | self._mFreqChar += 1 82 | if self._mLastOrder < SAMPLE_SIZE: 83 | self._mTotalSeqs += 1 84 | if not self._mReversed: 85 | i = (self._mLastOrder * SAMPLE_SIZE) + order 86 | model = self._mModel['precedenceMatrix'][i] 87 | else: # reverse the order of the letters in the lookup 88 | i = (order * SAMPLE_SIZE) + self._mLastOrder 89 | model = self._mModel['precedenceMatrix'][i] 90 | self._mSeqCounters[model] += 1 91 | self._mLastOrder = order 92 | 93 | if self.get_state() == constants.eDetecting: 94 | if self._mTotalSeqs > SB_ENOUGH_REL_THRESHOLD: 95 | cf = self.get_confidence() 96 | if cf > POSITIVE_SHORTCUT_THRESHOLD: 97 | if constants._debug: 98 | sys.stderr.write('%s confidence = %s, we have a' 99 | 'winner\n' % 100 | (self._mModel['charsetName'], cf)) 101 | self._mState = constants.eFoundIt 102 | elif cf < NEGATIVE_SHORTCUT_THRESHOLD: 103 | if constants._debug: 104 | sys.stderr.write('%s confidence = %s, below negative' 105 | 'shortcut threshhold %s\n' % 106 | (self._mModel['charsetName'], cf, 107 | NEGATIVE_SHORTCUT_THRESHOLD)) 108 | self._mState = constants.eNotMe 109 | 110 | return self.get_state() 111 | 112 | def get_confidence(self): 113 | r = 0.01 114 | if self._mTotalSeqs > 0: 115 | r = ((1.0 * self._mSeqCounters[POSITIVE_CAT]) / self._mTotalSeqs 116 | / self._mModel['mTypicalPositiveRatio']) 117 | r = r * self._mFreqChar / self._mTotalChar 118 | if r >= 1.0: 119 | r = 0.99 120 | return r 121 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/charade/latin1prober.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is Mozilla Universal charset detector code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 2001 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # Shy Shalom - original C code 12 | # 13 | # This library is free software; you can redistribute it and/or 14 | # modify it under the terms of the GNU Lesser General Public 15 | # License as published by the Free Software Foundation; either 16 | # version 2.1 of the License, or (at your option) any later version. 17 | # 18 | # This library is distributed in the hope that it will be useful, 19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 | # Lesser General Public License for more details. 22 | # 23 | # You should have received a copy of the GNU Lesser General Public 24 | # License along with this library; if not, write to the Free Software 25 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 26 | # 02110-1301 USA 27 | ######################### END LICENSE BLOCK ######################### 28 | 29 | from .charsetprober import CharSetProber 30 | from .constants import eNotMe 31 | from .compat import wrap_ord 32 | 33 | FREQ_CAT_NUM = 4 34 | 35 | UDF = 0 # undefined 36 | OTH = 1 # other 37 | ASC = 2 # ascii capital letter 38 | ASS = 3 # ascii small letter 39 | ACV = 4 # accent capital vowel 40 | ACO = 5 # accent capital other 41 | ASV = 6 # accent small vowel 42 | ASO = 7 # accent small other 43 | CLASS_NUM = 8 # total classes 44 | 45 | Latin1_CharToClass = ( 46 | OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 00 - 07 47 | OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 08 - 0F 48 | OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 10 - 17 49 | OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 18 - 1F 50 | OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 20 - 27 51 | OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 28 - 2F 52 | OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 30 - 37 53 | OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 38 - 3F 54 | OTH, ASC, ASC, ASC, ASC, ASC, ASC, ASC, # 40 - 47 55 | ASC, ASC, ASC, ASC, ASC, ASC, ASC, ASC, # 48 - 4F 56 | ASC, ASC, ASC, ASC, ASC, ASC, ASC, ASC, # 50 - 57 57 | ASC, ASC, ASC, OTH, OTH, OTH, OTH, OTH, # 58 - 5F 58 | OTH, ASS, ASS, ASS, ASS, ASS, ASS, ASS, # 60 - 67 59 | ASS, ASS, ASS, ASS, ASS, ASS, ASS, ASS, # 68 - 6F 60 | ASS, ASS, ASS, ASS, ASS, ASS, ASS, ASS, # 70 - 77 61 | ASS, ASS, ASS, OTH, OTH, OTH, OTH, OTH, # 78 - 7F 62 | OTH, UDF, OTH, ASO, OTH, OTH, OTH, OTH, # 80 - 87 63 | OTH, OTH, ACO, OTH, ACO, UDF, ACO, UDF, # 88 - 8F 64 | UDF, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 90 - 97 65 | OTH, OTH, ASO, OTH, ASO, UDF, ASO, ACO, # 98 - 9F 66 | OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # A0 - A7 67 | OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # A8 - AF 68 | OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # B0 - B7 69 | OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # B8 - BF 70 | ACV, ACV, ACV, ACV, ACV, ACV, ACO, ACO, # C0 - C7 71 | ACV, ACV, ACV, ACV, ACV, ACV, ACV, ACV, # C8 - CF 72 | ACO, ACO, ACV, ACV, ACV, ACV, ACV, OTH, # D0 - D7 73 | ACV, ACV, ACV, ACV, ACV, ACO, ACO, ACO, # D8 - DF 74 | ASV, ASV, ASV, ASV, ASV, ASV, ASO, ASO, # E0 - E7 75 | ASV, ASV, ASV, ASV, ASV, ASV, ASV, ASV, # E8 - EF 76 | ASO, ASO, ASV, ASV, ASV, ASV, ASV, OTH, # F0 - F7 77 | ASV, ASV, ASV, ASV, ASV, ASO, ASO, ASO, # F8 - FF 78 | ) 79 | 80 | # 0 : illegal 81 | # 1 : very unlikely 82 | # 2 : normal 83 | # 3 : very likely 84 | Latin1ClassModel = ( 85 | # UDF OTH ASC ASS ACV ACO ASV ASO 86 | 0, 0, 0, 0, 0, 0, 0, 0, # UDF 87 | 0, 3, 3, 3, 3, 3, 3, 3, # OTH 88 | 0, 3, 3, 3, 3, 3, 3, 3, # ASC 89 | 0, 3, 3, 3, 1, 1, 3, 3, # ASS 90 | 0, 3, 3, 3, 1, 2, 1, 2, # ACV 91 | 0, 3, 3, 3, 3, 3, 3, 3, # ACO 92 | 0, 3, 1, 3, 1, 1, 1, 3, # ASV 93 | 0, 3, 1, 3, 1, 1, 3, 3, # ASO 94 | ) 95 | 96 | 97 | class Latin1Prober(CharSetProber): 98 | def __init__(self): 99 | CharSetProber.__init__(self) 100 | self.reset() 101 | 102 | def reset(self): 103 | self._mLastCharClass = OTH 104 | self._mFreqCounter = [0] * FREQ_CAT_NUM 105 | CharSetProber.reset(self) 106 | 107 | def get_charset_name(self): 108 | return "windows-1252" 109 | 110 | def feed(self, aBuf): 111 | aBuf = self.filter_with_english_letters(aBuf) 112 | for c in aBuf: 113 | charClass = Latin1_CharToClass[wrap_ord(c)] 114 | freq = Latin1ClassModel[(self._mLastCharClass * CLASS_NUM) 115 | + charClass] 116 | if freq == 0: 117 | self._mState = eNotMe 118 | break 119 | self._mFreqCounter[freq] += 1 120 | self._mLastCharClass = charClass 121 | 122 | return self.get_state() 123 | 124 | def get_confidence(self): 125 | if self.get_state() == eNotMe: 126 | return 0.01 127 | 128 | total = sum(self._mFreqCounter) 129 | if total < 0.01: 130 | confidence = 0.0 131 | else: 132 | confidence = ((self._mFreqCounter[3] / total) 133 | - (self._mFreqCounter[1] * 20.0 / total)) 134 | if confidence < 0.0: 135 | confidence = 0.0 136 | # lower the confidence of latin1 so that other more accurate 137 | # detector can take priority. 138 | confidence = confidence * 0.5 139 | return confidence 140 | -------------------------------------------------------------------------------- /Application/Modules/requests/auth.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | requests.auth 5 | ~~~~~~~~~~~~~ 6 | 7 | This module contains the authentication handlers for Requests. 8 | """ 9 | 10 | import os 11 | import re 12 | import time 13 | import hashlib 14 | import logging 15 | 16 | from base64 import b64encode 17 | 18 | from .compat import urlparse, str 19 | from .utils import parse_dict_header 20 | 21 | log = logging.getLogger(__name__) 22 | 23 | CONTENT_TYPE_FORM_URLENCODED = 'application/x-www-form-urlencoded' 24 | CONTENT_TYPE_MULTI_PART = 'multipart/form-data' 25 | 26 | 27 | def _basic_auth_str(username, password): 28 | """Returns a Basic Auth string.""" 29 | 30 | return 'Basic ' + b64encode(('%s:%s' % (username, password)).encode('latin1')).strip().decode('latin1') 31 | 32 | 33 | class AuthBase(object): 34 | """Base class that all auth implementations derive from""" 35 | 36 | def __call__(self, r): 37 | raise NotImplementedError('Auth hooks must be callable.') 38 | 39 | 40 | class HTTPBasicAuth(AuthBase): 41 | """Attaches HTTP Basic Authentication to the given Request object.""" 42 | def __init__(self, username, password): 43 | self.username = username 44 | self.password = password 45 | 46 | def __call__(self, r): 47 | r.headers['Authorization'] = _basic_auth_str(self.username, self.password) 48 | return r 49 | 50 | 51 | class HTTPProxyAuth(HTTPBasicAuth): 52 | """Attaches HTTP Proxy Authentication to a given Request object.""" 53 | def __call__(self, r): 54 | r.headers['Proxy-Authorization'] = _basic_auth_str(self.username, self.password) 55 | return r 56 | 57 | 58 | class HTTPDigestAuth(AuthBase): 59 | """Attaches HTTP Digest Authentication to the given Request object.""" 60 | def __init__(self, username, password): 61 | self.username = username 62 | self.password = password 63 | self.last_nonce = '' 64 | self.nonce_count = 0 65 | self.chal = {} 66 | 67 | def build_digest_header(self, method, url): 68 | 69 | realm = self.chal['realm'] 70 | nonce = self.chal['nonce'] 71 | qop = self.chal.get('qop') 72 | algorithm = self.chal.get('algorithm') 73 | opaque = self.chal.get('opaque') 74 | 75 | if algorithm is None: 76 | _algorithm = 'MD5' 77 | else: 78 | _algorithm = algorithm.upper() 79 | # lambdas assume digest modules are imported at the top level 80 | if _algorithm == 'MD5': 81 | def md5_utf8(x): 82 | if isinstance(x, str): 83 | x = x.encode('utf-8') 84 | return hashlib.md5(x).hexdigest() 85 | hash_utf8 = md5_utf8 86 | elif _algorithm == 'SHA': 87 | def sha_utf8(x): 88 | if isinstance(x, str): 89 | x = x.encode('utf-8') 90 | return hashlib.sha1(x).hexdigest() 91 | hash_utf8 = sha_utf8 92 | # XXX MD5-sess 93 | KD = lambda s, d: hash_utf8("%s:%s" % (s, d)) 94 | 95 | if hash_utf8 is None: 96 | return None 97 | 98 | # XXX not implemented yet 99 | entdig = None 100 | p_parsed = urlparse(url) 101 | path = p_parsed.path 102 | if p_parsed.query: 103 | path += '?' + p_parsed.query 104 | 105 | A1 = '%s:%s:%s' % (self.username, realm, self.password) 106 | A2 = '%s:%s' % (method, path) 107 | 108 | if qop is None: 109 | respdig = KD(hash_utf8(A1), "%s:%s" % (nonce, hash_utf8(A2))) 110 | elif qop == 'auth' or 'auth' in qop.split(','): 111 | if nonce == self.last_nonce: 112 | self.nonce_count += 1 113 | else: 114 | self.nonce_count = 1 115 | 116 | ncvalue = '%08x' % self.nonce_count 117 | s = str(self.nonce_count).encode('utf-8') 118 | s += nonce.encode('utf-8') 119 | s += time.ctime().encode('utf-8') 120 | s += os.urandom(8) 121 | 122 | cnonce = (hashlib.sha1(s).hexdigest()[:16]) 123 | noncebit = "%s:%s:%s:%s:%s" % (nonce, ncvalue, cnonce, qop, hash_utf8(A2)) 124 | respdig = KD(hash_utf8(A1), noncebit) 125 | else: 126 | # XXX handle auth-int. 127 | return None 128 | 129 | self.last_nonce = nonce 130 | 131 | # XXX should the partial digests be encoded too? 132 | base = 'username="%s", realm="%s", nonce="%s", uri="%s", ' \ 133 | 'response="%s"' % (self.username, realm, nonce, path, respdig) 134 | if opaque: 135 | base += ', opaque="%s"' % opaque 136 | if algorithm: 137 | base += ', algorithm="%s"' % algorithm 138 | if entdig: 139 | base += ', digest="%s"' % entdig 140 | if qop: 141 | base += ', qop=auth, nc=%s, cnonce="%s"' % (ncvalue, cnonce) 142 | 143 | return 'Digest %s' % (base) 144 | 145 | def handle_401(self, r, **kwargs): 146 | """Takes the given response and tries digest-auth, if needed.""" 147 | 148 | num_401_calls = getattr(self, 'num_401_calls', 1) 149 | s_auth = r.headers.get('www-authenticate', '') 150 | 151 | if 'digest' in s_auth.lower() and num_401_calls < 2: 152 | 153 | setattr(self, 'num_401_calls', num_401_calls + 1) 154 | pat = re.compile(r'digest ', flags=re.IGNORECASE) 155 | self.chal = parse_dict_header(pat.sub('', s_auth, count=1)) 156 | 157 | # Consume content and release the original connection 158 | # to allow our new request to reuse the same one. 159 | r.content 160 | r.raw.release_conn() 161 | prep = r.request.copy() 162 | prep.prepare_cookies(r.cookies) 163 | 164 | prep.headers['Authorization'] = self.build_digest_header( 165 | prep.method, prep.url) 166 | _r = r.connection.send(prep, **kwargs) 167 | _r.history.append(r) 168 | _r.request = prep 169 | 170 | return _r 171 | 172 | setattr(self, 'num_401_calls', 1) 173 | return r 174 | 175 | def __call__(self, r): 176 | # If we have a saved nonce, skip the 401 177 | if self.last_nonce: 178 | r.headers['Authorization'] = self.build_digest_header(r.method, r.url) 179 | r.register_hook('response', self.handle_401) 180 | return r 181 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/urllib3/request.py: -------------------------------------------------------------------------------- 1 | # urllib3/request.py 2 | # Copyright 2008-2013 Andrey Petrov and contributors (see CONTRIBUTORS.txt) 3 | # 4 | # This module is part of urllib3 and is released under 5 | # the MIT License: http://www.opensource.org/licenses/mit-license.php 6 | 7 | try: 8 | from urllib.parse import urlencode 9 | except ImportError: 10 | from urllib import urlencode 11 | 12 | from .filepost import encode_multipart_formdata 13 | 14 | 15 | __all__ = ['RequestMethods'] 16 | 17 | 18 | class RequestMethods(object): 19 | """ 20 | Convenience mixin for classes who implement a :meth:`urlopen` method, such 21 | as :class:`~urllib3.connectionpool.HTTPConnectionPool` and 22 | :class:`~urllib3.poolmanager.PoolManager`. 23 | 24 | Provides behavior for making common types of HTTP request methods and 25 | decides which type of request field encoding to use. 26 | 27 | Specifically, 28 | 29 | :meth:`.request_encode_url` is for sending requests whose fields are encoded 30 | in the URL (such as GET, HEAD, DELETE). 31 | 32 | :meth:`.request_encode_body` is for sending requests whose fields are 33 | encoded in the *body* of the request using multipart or www-form-urlencoded 34 | (such as for POST, PUT, PATCH). 35 | 36 | :meth:`.request` is for making any kind of request, it will look up the 37 | appropriate encoding format and use one of the above two methods to make 38 | the request. 39 | 40 | Initializer parameters: 41 | 42 | :param headers: 43 | Headers to include with all requests, unless other headers are given 44 | explicitly. 45 | """ 46 | 47 | _encode_url_methods = set(['DELETE', 'GET', 'HEAD', 'OPTIONS']) 48 | _encode_body_methods = set(['PATCH', 'POST', 'PUT', 'TRACE']) 49 | 50 | def __init__(self, headers=None): 51 | self.headers = headers or {} 52 | 53 | def urlopen(self, method, url, body=None, headers=None, 54 | encode_multipart=True, multipart_boundary=None, 55 | **kw): # Abstract 56 | raise NotImplemented("Classes extending RequestMethods must implement " 57 | "their own ``urlopen`` method.") 58 | 59 | def request(self, method, url, fields=None, headers=None, **urlopen_kw): 60 | """ 61 | Make a request using :meth:`urlopen` with the appropriate encoding of 62 | ``fields`` based on the ``method`` used. 63 | 64 | This is a convenience method that requires the least amount of manual 65 | effort. It can be used in most situations, while still having the option 66 | to drop down to more specific methods when necessary, such as 67 | :meth:`request_encode_url`, :meth:`request_encode_body`, 68 | or even the lowest level :meth:`urlopen`. 69 | """ 70 | method = method.upper() 71 | 72 | if method in self._encode_url_methods: 73 | return self.request_encode_url(method, url, fields=fields, 74 | headers=headers, 75 | **urlopen_kw) 76 | else: 77 | return self.request_encode_body(method, url, fields=fields, 78 | headers=headers, 79 | **urlopen_kw) 80 | 81 | def request_encode_url(self, method, url, fields=None, **urlopen_kw): 82 | """ 83 | Make a request using :meth:`urlopen` with the ``fields`` encoded in 84 | the url. This is useful for request methods like GET, HEAD, DELETE, etc. 85 | """ 86 | if fields: 87 | url += '?' + urlencode(fields) 88 | return self.urlopen(method, url, **urlopen_kw) 89 | 90 | def request_encode_body(self, method, url, fields=None, headers=None, 91 | encode_multipart=True, multipart_boundary=None, 92 | **urlopen_kw): 93 | """ 94 | Make a request using :meth:`urlopen` with the ``fields`` encoded in 95 | the body. This is useful for request methods like POST, PUT, PATCH, etc. 96 | 97 | When ``encode_multipart=True`` (default), then 98 | :meth:`urllib3.filepost.encode_multipart_formdata` is used to encode the 99 | payload with the appropriate content type. Otherwise 100 | :meth:`urllib.urlencode` is used with the 101 | 'application/x-www-form-urlencoded' content type. 102 | 103 | Multipart encoding must be used when posting files, and it's reasonably 104 | safe to use it in other times too. However, it may break request signing, 105 | such as with OAuth. 106 | 107 | Supports an optional ``fields`` parameter of key/value strings AND 108 | key/filetuple. A filetuple is a (filename, data, MIME type) tuple where 109 | the MIME type is optional. For example: :: 110 | 111 | fields = { 112 | 'foo': 'bar', 113 | 'fakefile': ('foofile.txt', 'contents of foofile'), 114 | 'realfile': ('barfile.txt', open('realfile').read()), 115 | 'typedfile': ('bazfile.bin', open('bazfile').read(), 116 | 'image/jpeg'), 117 | 'nonamefile': 'contents of nonamefile field', 118 | } 119 | 120 | When uploading a file, providing a filename (the first parameter of the 121 | tuple) is optional but recommended to best mimick behavior of browsers. 122 | 123 | Note that if ``headers`` are supplied, the 'Content-Type' header will be 124 | overwritten because it depends on the dynamic random boundary string 125 | which is used to compose the body of the request. The random boundary 126 | string can be explicitly set with the ``multipart_boundary`` parameter. 127 | """ 128 | if encode_multipart: 129 | body, content_type = encode_multipart_formdata(fields or {}, 130 | boundary=multipart_boundary) 131 | else: 132 | body, content_type = (urlencode(fields or {}), 133 | 'application/x-www-form-urlencoded') 134 | 135 | if headers is None: 136 | headers = self.headers 137 | 138 | headers_ = {'Content-Type': content_type} 139 | headers_.update(headers) 140 | 141 | return self.urlopen(method, url, body=body, headers=headers_, 142 | **urlopen_kw) 143 | -------------------------------------------------------------------------------- /Application/Modules/msh2_crc.py: -------------------------------------------------------------------------------- 1 | ''' 2 | ZeroEngine .msh model format CRC algorithm. 3 | 4 | Refer to 5 | schlechtwetterfront.github.io/ze_filetypes/msh.html 6 | for more information regarding the file format. 7 | ''' 8 | from struct import pack 9 | 10 | 11 | class CRCError(Exception): 12 | def __init__(self, val): 13 | self.val = val 14 | 15 | def __str__(self): 16 | return '{0}'.format(self.val) 17 | 18 | # CRC lookup table. 19 | TABLE_32 = ( 20 | 0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9, 21 | 0x130476DC, 0x17C56B6B, 0x1A864DB2, 0x1E475005, 22 | 0x2608EDB8, 0x22C9F00F, 0x2F8AD6D6, 0x2B4BCB61, 23 | 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD, 24 | 0x4C11DB70, 0x48D0C6C7, 0x4593E01E, 0x4152FDA9, 25 | 0x5F15ADAC, 0x5BD4B01B, 0x569796C2, 0x52568B75, 26 | 0x6A1936C8, 0x6ED82B7F, 0x639B0DA6, 0x675A1011, 27 | 0x791D4014, 0x7DDC5DA3, 0x709F7B7A, 0x745E66CD, 28 | 0x9823B6E0, 0x9CE2AB57, 0x91A18D8E, 0x95609039, 29 | 0x8B27C03C, 0x8FE6DD8B, 0x82A5FB52, 0x8664E6E5, 30 | 0xBE2B5B58, 0xBAEA46EF, 0xB7A96036, 0xB3687D81, 31 | 0xAD2F2D84, 0xA9EE3033, 0xA4AD16EA, 0xA06C0B5D, 32 | 0xD4326D90, 0xD0F37027, 0xDDB056FE, 0xD9714B49, 33 | 0xC7361B4C, 0xC3F706FB, 0xCEB42022, 0xCA753D95, 34 | 0xF23A8028, 0xF6FB9D9F, 0xFBB8BB46, 0xFF79A6F1, 35 | 0xE13EF6F4, 0xE5FFEB43, 0xE8BCCD9A, 0xEC7DD02D, 36 | 0x34867077, 0x30476DC0, 0x3D044B19, 0x39C556AE, 37 | 0x278206AB, 0x23431B1C, 0x2E003DC5, 0x2AC12072, 38 | 0x128E9DCF, 0x164F8078, 0x1B0CA6A1, 0x1FCDBB16, 39 | 0x018AEB13, 0x054BF6A4, 0x0808D07D, 0x0CC9CDCA, 40 | 0x7897AB07, 0x7C56B6B0, 0x71159069, 0x75D48DDE, 41 | 0x6B93DDDB, 0x6F52C06C, 0x6211E6B5, 0x66D0FB02, 42 | 0x5E9F46BF, 0x5A5E5B08, 0x571D7DD1, 0x53DC6066, 43 | 0x4D9B3063, 0x495A2DD4, 0x44190B0D, 0x40D816BA, 44 | 0xACA5C697, 0xA864DB20, 0xA527FDF9, 0xA1E6E04E, 45 | 0xBFA1B04B, 0xBB60ADFC, 0xB6238B25, 0xB2E29692, 46 | 0x8AAD2B2F, 0x8E6C3698, 0x832F1041, 0x87EE0DF6, 47 | 0x99A95DF3, 0x9D684044, 0x902B669D, 0x94EA7B2A, 48 | 0xE0B41DE7, 0xE4750050, 0xE9362689, 0xEDF73B3E, 49 | 0xF3B06B3B, 0xF771768C, 0xFA325055, 0xFEF34DE2, 50 | 0xC6BCF05F, 0xC27DEDE8, 0xCF3ECB31, 0xCBFFD686, 51 | 0xD5B88683, 0xD1799B34, 0xDC3ABDED, 0xD8FBA05A, 52 | 0x690CE0EE, 0x6DCDFD59, 0x608EDB80, 0x644FC637, 53 | 0x7A089632, 0x7EC98B85, 0x738AAD5C, 0x774BB0EB, 54 | 0x4F040D56, 0x4BC510E1, 0x46863638, 0x42472B8F, 55 | 0x5C007B8A, 0x58C1663D, 0x558240E4, 0x51435D53, 56 | 0x251D3B9E, 0x21DC2629, 0x2C9F00F0, 0x285E1D47, 57 | 0x36194D42, 0x32D850F5, 0x3F9B762C, 0x3B5A6B9B, 58 | 0x0315D626, 0x07D4CB91, 0x0A97ED48, 0x0E56F0FF, 59 | 0x1011A0FA, 0x14D0BD4D, 0x19939B94, 0x1D528623, 60 | 0xF12F560E, 0xF5EE4BB9, 0xF8AD6D60, 0xFC6C70D7, 61 | 0xE22B20D2, 0xE6EA3D65, 0xEBA91BBC, 0xEF68060B, 62 | 0xD727BBB6, 0xD3E6A601, 0xDEA580D8, 0xDA649D6F, 63 | 0xC423CD6A, 0xC0E2D0DD, 0xCDA1F604, 0xC960EBB3, 64 | 0xBD3E8D7E, 0xB9FF90C9, 0xB4BCB610, 0xB07DABA7, 65 | 0xAE3AFBA2, 0xAAFBE615, 0xA7B8C0CC, 0xA379DD7B, 66 | 0x9B3660C6, 0x9FF77D71, 0x92B45BA8, 0x9675461F, 67 | 0x8832161A, 0x8CF30BAD, 0x81B02D74, 0x857130C3, 68 | 0x5D8A9099, 0x594B8D2E, 0x5408ABF7, 0x50C9B640, 69 | 0x4E8EE645, 0x4A4FFBF2, 0x470CDD2B, 0x43CDC09C, 70 | 0x7B827D21, 0x7F436096, 0x7200464F, 0x76C15BF8, 71 | 0x68860BFD, 0x6C47164A, 0x61043093, 0x65C52D24, 72 | 0x119B4BE9, 0x155A565E, 0x18197087, 0x1CD86D30, 73 | 0x029F3D35, 0x065E2082, 0x0B1D065B, 0x0FDC1BEC, 74 | 0x3793A651, 0x3352BBE6, 0x3E119D3F, 0x3AD08088, 75 | 0x2497D08D, 0x2056CD3A, 0x2D15EBE3, 0x29D4F654, 76 | 0xC5A92679, 0xC1683BCE, 0xCC2B1D17, 0xC8EA00A0, 77 | 0xD6AD50A5, 0xD26C4D12, 0xDF2F6BCB, 0xDBEE767C, 78 | 0xE3A1CBC1, 0xE760D676, 0xEA23F0AF, 0xEEE2ED18, 79 | 0xF0A5BD1D, 0xF464A0AA, 0xF9278673, 0xFDE69BC4, 80 | 0x89B8FD09, 0x8D79E0BE, 0x803AC667, 0x84FBDBD0, 81 | 0x9ABC8BD5, 0x9E7D9662, 0x933EB0BB, 0x97FFAD0C, 82 | 0xAFB010B1, 0xAB710D06, 0xA6322BDF, 0xA2F33668, 83 | 0xBCB4666D, 0xB8757BDA, 0xB5365D03, 0xB1F740B4 84 | ) 85 | 86 | # Used to calculate the lowercase CRC. 87 | TOLOWER = ( 88 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 89 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 90 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 91 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 92 | 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 93 | 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 94 | 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 95 | 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 96 | 0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 97 | 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 98 | 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 99 | 0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 100 | 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 101 | 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 102 | 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 103 | 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 104 | 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 105 | 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 106 | 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 107 | 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 108 | 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 109 | 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 110 | 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 111 | 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 112 | 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 113 | 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 114 | 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 115 | 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 116 | 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 117 | 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 118 | 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 119 | 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 120 | ) 121 | 122 | 123 | def return_lowest_bits(n): 124 | '''Simulate unsigned behavior.''' 125 | return n & 0xFFFFFFFF 126 | 127 | 128 | def crc(string): 129 | '''Calculate the Zero CRC from string and return it as number.''' 130 | crc_ = 0 131 | crc_ = return_lowest_bits(~crc_) 132 | if string: 133 | for char in string: 134 | ind = (crc_ >> 24) 135 | ind = ind ^ TOLOWER[ord(char)] 136 | crc_ = return_lowest_bits(crc_ << 8) ^ TABLE_32[ind] 137 | return return_lowest_bits(~crc_) 138 | 139 | 140 | def strcrc(string): 141 | '''Calculate the Zero CRC and return it in a structure 142 | usable in .msh files.''' 143 | return pack(' 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {38E3212A-A328-4C37-BF8A-E748D81548F9} 23 | 8.1 24 | 25 | 26 | 27 | DynamicLibrary 28 | false 29 | MultiByte 30 | v140 31 | 32 | 33 | DynamicLibrary 34 | false 35 | MultiByte 36 | v140 37 | 38 | 39 | DynamicLibrary 40 | false 41 | MultiByte 42 | v140 43 | 44 | 45 | DynamicLibrary 46 | false 47 | MultiByte 48 | v140 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | <_ProjectFileVersion>10.0.30319.1 72 | CGeoAccessorWrappers.32 73 | CGeoAccessorWrappers.64 74 | 75 | 76 | ..\..\Application\Plugins\ 77 | 78 | 79 | CGeoAccessorWrappers.64 80 | ..\..\Application\Plugins\ 81 | 82 | 83 | CGeoAccessorWrappers.32 84 | ..\..\Application\Plugins\ 85 | 86 | 87 | ..\..\Application\Plugins\ 88 | 89 | 90 | 91 | Level3 92 | 93 | 94 | 95 | $(XSISDK_ROOT)\lib\nt-x86;%(AdditionalLibraryDirectories) 96 | 97 | 98 | 99 | 100 | Level3 101 | false 102 | 103 | 104 | sicppsdk.lib;sicoresdk.lib;%(AdditionalDependencies) 105 | $(XSISDK_ROOT)\lib\nt-x86;%(AdditionalLibraryDirectories) 106 | 107 | 108 | 109 | 110 | Level3 111 | 112 | 113 | 114 | $(XSISDK_ROOT)\lib\nt-x86-64;%(AdditionalLibraryDirectories) 115 | 116 | 117 | 118 | 119 | Level3 120 | 121 | 122 | $(XSISDK_ROOT)\lib\nt-x86-64;%(AdditionalLibraryDirectories) 123 | sicppsdk.lib;sicoresdk.lib;%(AdditionalDependencies) 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/charade/universaldetector.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is Mozilla Universal charset detector code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 2001 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # Shy Shalom - original C code 12 | # 13 | # This library is free software; you can redistribute it and/or 14 | # modify it under the terms of the GNU Lesser General Public 15 | # License as published by the Free Software Foundation; either 16 | # version 2.1 of the License, or (at your option) any later version. 17 | # 18 | # This library is distributed in the hope that it will be useful, 19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 | # Lesser General Public License for more details. 22 | # 23 | # You should have received a copy of the GNU Lesser General Public 24 | # License along with this library; if not, write to the Free Software 25 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 26 | # 02110-1301 USA 27 | ######################### END LICENSE BLOCK ######################### 28 | 29 | from . import constants 30 | import sys 31 | import codecs 32 | from .latin1prober import Latin1Prober # windows-1252 33 | from .mbcsgroupprober import MBCSGroupProber # multi-byte character sets 34 | from .sbcsgroupprober import SBCSGroupProber # single-byte character sets 35 | from .escprober import EscCharSetProber # ISO-2122, etc. 36 | import re 37 | 38 | MINIMUM_THRESHOLD = 0.20 39 | ePureAscii = 0 40 | eEscAscii = 1 41 | eHighbyte = 2 42 | 43 | 44 | class UniversalDetector: 45 | def __init__(self): 46 | self._highBitDetector = re.compile(b'[\x80-\xFF]') 47 | self._escDetector = re.compile(b'(\033|~{)') 48 | self._mEscCharSetProber = None 49 | self._mCharSetProbers = [] 50 | self.reset() 51 | 52 | def reset(self): 53 | self.result = {'encoding': None, 'confidence': 0.0} 54 | self.done = False 55 | self._mStart = True 56 | self._mGotData = False 57 | self._mInputState = ePureAscii 58 | self._mLastChar = b'' 59 | if self._mEscCharSetProber: 60 | self._mEscCharSetProber.reset() 61 | for prober in self._mCharSetProbers: 62 | prober.reset() 63 | 64 | def feed(self, aBuf): 65 | if self.done: 66 | return 67 | 68 | aLen = len(aBuf) 69 | if not aLen: 70 | return 71 | 72 | if not self._mGotData: 73 | # If the data starts with BOM, we know it is UTF 74 | if aBuf[:3] == codecs.BOM: 75 | # EF BB BF UTF-8 with BOM 76 | self.result = {'encoding': "UTF-8", 'confidence': 1.0} 77 | elif aBuf[:4] == codecs.BOM_UTF32_LE: 78 | # FF FE 00 00 UTF-32, little-endian BOM 79 | self.result = {'encoding': "UTF-32LE", 'confidence': 1.0} 80 | elif aBuf[:4] == codecs.BOM_UTF32_BE: 81 | # 00 00 FE FF UTF-32, big-endian BOM 82 | self.result = {'encoding': "UTF-32BE", 'confidence': 1.0} 83 | elif aBuf[:4] == b'\xFE\xFF\x00\x00': 84 | # FE FF 00 00 UCS-4, unusual octet order BOM (3412) 85 | self.result = { 86 | 'encoding': "X-ISO-10646-UCS-4-3412", 87 | 'confidence': 1.0 88 | } 89 | elif aBuf[:4] == b'\x00\x00\xFF\xFE': 90 | # 00 00 FF FE UCS-4, unusual octet order BOM (2143) 91 | self.result = { 92 | 'encoding': "X-ISO-10646-UCS-4-2143", 93 | 'confidence': 1.0 94 | } 95 | elif aBuf[:2] == codecs.BOM_LE: 96 | # FF FE UTF-16, little endian BOM 97 | self.result = {'encoding': "UTF-16LE", 'confidence': 1.0} 98 | elif aBuf[:2] == codecs.BOM_BE: 99 | # FE FF UTF-16, big endian BOM 100 | self.result = {'encoding': "UTF-16BE", 'confidence': 1.0} 101 | 102 | self._mGotData = True 103 | if self.result['encoding'] and (self.result['confidence'] > 0.0): 104 | self.done = True 105 | return 106 | 107 | if self._mInputState == ePureAscii: 108 | if self._highBitDetector.search(aBuf): 109 | self._mInputState = eHighbyte 110 | elif ((self._mInputState == ePureAscii) and 111 | self._escDetector.search(self._mLastChar + aBuf)): 112 | self._mInputState = eEscAscii 113 | 114 | self._mLastChar = aBuf[-1:] 115 | 116 | if self._mInputState == eEscAscii: 117 | if not self._mEscCharSetProber: 118 | self._mEscCharSetProber = EscCharSetProber() 119 | if self._mEscCharSetProber.feed(aBuf) == constants.eFoundIt: 120 | self.result = { 121 | 'encoding': self._mEscCharSetProber.get_charset_name(), 122 | 'confidence': self._mEscCharSetProber.get_confidence() 123 | } 124 | self.done = True 125 | elif self._mInputState == eHighbyte: 126 | if not self._mCharSetProbers: 127 | self._mCharSetProbers = [MBCSGroupProber(), SBCSGroupProber(), 128 | Latin1Prober()] 129 | for prober in self._mCharSetProbers: 130 | if prober.feed(aBuf) == constants.eFoundIt: 131 | self.result = {'encoding': prober.get_charset_name(), 132 | 'confidence': prober.get_confidence()} 133 | self.done = True 134 | break 135 | 136 | def close(self): 137 | if self.done: 138 | return 139 | if not self._mGotData: 140 | if constants._debug: 141 | sys.stderr.write('no data received!\n') 142 | return 143 | self.done = True 144 | 145 | if self._mInputState == ePureAscii: 146 | self.result = {'encoding': 'ascii', 'confidence': 1.0} 147 | return self.result 148 | 149 | if self._mInputState == eHighbyte: 150 | proberConfidence = None 151 | maxProberConfidence = 0.0 152 | maxProber = None 153 | for prober in self._mCharSetProbers: 154 | if not prober: 155 | continue 156 | proberConfidence = prober.get_confidence() 157 | if proberConfidence > maxProberConfidence: 158 | maxProberConfidence = proberConfidence 159 | maxProber = prober 160 | if maxProber and (maxProberConfidence > MINIMUM_THRESHOLD): 161 | self.result = {'encoding': maxProber.get_charset_name(), 162 | 'confidence': maxProber.get_confidence()} 163 | return self.result 164 | 165 | if constants._debug: 166 | sys.stderr.write('no probers hit minimum threshhold\n') 167 | for prober in self._mCharSetProbers[0].mProbers: 168 | if not prober: 169 | continue 170 | sys.stderr.write('%s confidence = %s\n' % 171 | (prober.get_charset_name(), 172 | prober.get_confidence())) 173 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/charade/escsm.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is mozilla.org code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 1998 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # 12 | # This library is free software; you can redistribute it and/or 13 | # modify it under the terms of the GNU Lesser General Public 14 | # License as published by the Free Software Foundation; either 15 | # version 2.1 of the License, or (at your option) any later version. 16 | # 17 | # This library is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | # Lesser General Public License for more details. 21 | # 22 | # You should have received a copy of the GNU Lesser General Public 23 | # License along with this library; if not, write to the Free Software 24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 25 | # 02110-1301 USA 26 | ######################### END LICENSE BLOCK ######################### 27 | 28 | from .constants import eStart, eError, eItsMe 29 | 30 | HZ_cls = ( 31 | 1,0,0,0,0,0,0,0, # 00 - 07 32 | 0,0,0,0,0,0,0,0, # 08 - 0f 33 | 0,0,0,0,0,0,0,0, # 10 - 17 34 | 0,0,0,1,0,0,0,0, # 18 - 1f 35 | 0,0,0,0,0,0,0,0, # 20 - 27 36 | 0,0,0,0,0,0,0,0, # 28 - 2f 37 | 0,0,0,0,0,0,0,0, # 30 - 37 38 | 0,0,0,0,0,0,0,0, # 38 - 3f 39 | 0,0,0,0,0,0,0,0, # 40 - 47 40 | 0,0,0,0,0,0,0,0, # 48 - 4f 41 | 0,0,0,0,0,0,0,0, # 50 - 57 42 | 0,0,0,0,0,0,0,0, # 58 - 5f 43 | 0,0,0,0,0,0,0,0, # 60 - 67 44 | 0,0,0,0,0,0,0,0, # 68 - 6f 45 | 0,0,0,0,0,0,0,0, # 70 - 77 46 | 0,0,0,4,0,5,2,0, # 78 - 7f 47 | 1,1,1,1,1,1,1,1, # 80 - 87 48 | 1,1,1,1,1,1,1,1, # 88 - 8f 49 | 1,1,1,1,1,1,1,1, # 90 - 97 50 | 1,1,1,1,1,1,1,1, # 98 - 9f 51 | 1,1,1,1,1,1,1,1, # a0 - a7 52 | 1,1,1,1,1,1,1,1, # a8 - af 53 | 1,1,1,1,1,1,1,1, # b0 - b7 54 | 1,1,1,1,1,1,1,1, # b8 - bf 55 | 1,1,1,1,1,1,1,1, # c0 - c7 56 | 1,1,1,1,1,1,1,1, # c8 - cf 57 | 1,1,1,1,1,1,1,1, # d0 - d7 58 | 1,1,1,1,1,1,1,1, # d8 - df 59 | 1,1,1,1,1,1,1,1, # e0 - e7 60 | 1,1,1,1,1,1,1,1, # e8 - ef 61 | 1,1,1,1,1,1,1,1, # f0 - f7 62 | 1,1,1,1,1,1,1,1, # f8 - ff 63 | ) 64 | 65 | HZ_st = ( 66 | eStart,eError, 3,eStart,eStart,eStart,eError,eError,# 00-07 67 | eError,eError,eError,eError,eItsMe,eItsMe,eItsMe,eItsMe,# 08-0f 68 | eItsMe,eItsMe,eError,eError,eStart,eStart, 4,eError,# 10-17 69 | 5,eError, 6,eError, 5, 5, 4,eError,# 18-1f 70 | 4,eError, 4, 4, 4,eError, 4,eError,# 20-27 71 | 4,eItsMe,eStart,eStart,eStart,eStart,eStart,eStart,# 28-2f 72 | ) 73 | 74 | HZCharLenTable = (0, 0, 0, 0, 0, 0) 75 | 76 | HZSMModel = {'classTable': HZ_cls, 77 | 'classFactor': 6, 78 | 'stateTable': HZ_st, 79 | 'charLenTable': HZCharLenTable, 80 | 'name': "HZ-GB-2312"} 81 | 82 | ISO2022CN_cls = ( 83 | 2,0,0,0,0,0,0,0, # 00 - 07 84 | 0,0,0,0,0,0,0,0, # 08 - 0f 85 | 0,0,0,0,0,0,0,0, # 10 - 17 86 | 0,0,0,1,0,0,0,0, # 18 - 1f 87 | 0,0,0,0,0,0,0,0, # 20 - 27 88 | 0,3,0,0,0,0,0,0, # 28 - 2f 89 | 0,0,0,0,0,0,0,0, # 30 - 37 90 | 0,0,0,0,0,0,0,0, # 38 - 3f 91 | 0,0,0,4,0,0,0,0, # 40 - 47 92 | 0,0,0,0,0,0,0,0, # 48 - 4f 93 | 0,0,0,0,0,0,0,0, # 50 - 57 94 | 0,0,0,0,0,0,0,0, # 58 - 5f 95 | 0,0,0,0,0,0,0,0, # 60 - 67 96 | 0,0,0,0,0,0,0,0, # 68 - 6f 97 | 0,0,0,0,0,0,0,0, # 70 - 77 98 | 0,0,0,0,0,0,0,0, # 78 - 7f 99 | 2,2,2,2,2,2,2,2, # 80 - 87 100 | 2,2,2,2,2,2,2,2, # 88 - 8f 101 | 2,2,2,2,2,2,2,2, # 90 - 97 102 | 2,2,2,2,2,2,2,2, # 98 - 9f 103 | 2,2,2,2,2,2,2,2, # a0 - a7 104 | 2,2,2,2,2,2,2,2, # a8 - af 105 | 2,2,2,2,2,2,2,2, # b0 - b7 106 | 2,2,2,2,2,2,2,2, # b8 - bf 107 | 2,2,2,2,2,2,2,2, # c0 - c7 108 | 2,2,2,2,2,2,2,2, # c8 - cf 109 | 2,2,2,2,2,2,2,2, # d0 - d7 110 | 2,2,2,2,2,2,2,2, # d8 - df 111 | 2,2,2,2,2,2,2,2, # e0 - e7 112 | 2,2,2,2,2,2,2,2, # e8 - ef 113 | 2,2,2,2,2,2,2,2, # f0 - f7 114 | 2,2,2,2,2,2,2,2, # f8 - ff 115 | ) 116 | 117 | ISO2022CN_st = ( 118 | eStart, 3,eError,eStart,eStart,eStart,eStart,eStart,# 00-07 119 | eStart,eError,eError,eError,eError,eError,eError,eError,# 08-0f 120 | eError,eError,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,# 10-17 121 | eItsMe,eItsMe,eItsMe,eError,eError,eError, 4,eError,# 18-1f 122 | eError,eError,eError,eItsMe,eError,eError,eError,eError,# 20-27 123 | 5, 6,eError,eError,eError,eError,eError,eError,# 28-2f 124 | eError,eError,eError,eItsMe,eError,eError,eError,eError,# 30-37 125 | eError,eError,eError,eError,eError,eItsMe,eError,eStart,# 38-3f 126 | ) 127 | 128 | ISO2022CNCharLenTable = (0, 0, 0, 0, 0, 0, 0, 0, 0) 129 | 130 | ISO2022CNSMModel = {'classTable': ISO2022CN_cls, 131 | 'classFactor': 9, 132 | 'stateTable': ISO2022CN_st, 133 | 'charLenTable': ISO2022CNCharLenTable, 134 | 'name': "ISO-2022-CN"} 135 | 136 | ISO2022JP_cls = ( 137 | 2,0,0,0,0,0,0,0, # 00 - 07 138 | 0,0,0,0,0,0,2,2, # 08 - 0f 139 | 0,0,0,0,0,0,0,0, # 10 - 17 140 | 0,0,0,1,0,0,0,0, # 18 - 1f 141 | 0,0,0,0,7,0,0,0, # 20 - 27 142 | 3,0,0,0,0,0,0,0, # 28 - 2f 143 | 0,0,0,0,0,0,0,0, # 30 - 37 144 | 0,0,0,0,0,0,0,0, # 38 - 3f 145 | 6,0,4,0,8,0,0,0, # 40 - 47 146 | 0,9,5,0,0,0,0,0, # 48 - 4f 147 | 0,0,0,0,0,0,0,0, # 50 - 57 148 | 0,0,0,0,0,0,0,0, # 58 - 5f 149 | 0,0,0,0,0,0,0,0, # 60 - 67 150 | 0,0,0,0,0,0,0,0, # 68 - 6f 151 | 0,0,0,0,0,0,0,0, # 70 - 77 152 | 0,0,0,0,0,0,0,0, # 78 - 7f 153 | 2,2,2,2,2,2,2,2, # 80 - 87 154 | 2,2,2,2,2,2,2,2, # 88 - 8f 155 | 2,2,2,2,2,2,2,2, # 90 - 97 156 | 2,2,2,2,2,2,2,2, # 98 - 9f 157 | 2,2,2,2,2,2,2,2, # a0 - a7 158 | 2,2,2,2,2,2,2,2, # a8 - af 159 | 2,2,2,2,2,2,2,2, # b0 - b7 160 | 2,2,2,2,2,2,2,2, # b8 - bf 161 | 2,2,2,2,2,2,2,2, # c0 - c7 162 | 2,2,2,2,2,2,2,2, # c8 - cf 163 | 2,2,2,2,2,2,2,2, # d0 - d7 164 | 2,2,2,2,2,2,2,2, # d8 - df 165 | 2,2,2,2,2,2,2,2, # e0 - e7 166 | 2,2,2,2,2,2,2,2, # e8 - ef 167 | 2,2,2,2,2,2,2,2, # f0 - f7 168 | 2,2,2,2,2,2,2,2, # f8 - ff 169 | ) 170 | 171 | ISO2022JP_st = ( 172 | eStart, 3,eError,eStart,eStart,eStart,eStart,eStart,# 00-07 173 | eStart,eStart,eError,eError,eError,eError,eError,eError,# 08-0f 174 | eError,eError,eError,eError,eItsMe,eItsMe,eItsMe,eItsMe,# 10-17 175 | eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eError,eError,# 18-1f 176 | eError, 5,eError,eError,eError, 4,eError,eError,# 20-27 177 | eError,eError,eError, 6,eItsMe,eError,eItsMe,eError,# 28-2f 178 | eError,eError,eError,eError,eError,eError,eItsMe,eItsMe,# 30-37 179 | eError,eError,eError,eItsMe,eError,eError,eError,eError,# 38-3f 180 | eError,eError,eError,eError,eItsMe,eError,eStart,eStart,# 40-47 181 | ) 182 | 183 | ISO2022JPCharLenTable = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0) 184 | 185 | ISO2022JPSMModel = {'classTable': ISO2022JP_cls, 186 | 'classFactor': 10, 187 | 'stateTable': ISO2022JP_st, 188 | 'charLenTable': ISO2022JPCharLenTable, 189 | 'name': "ISO-2022-JP"} 190 | 191 | ISO2022KR_cls = ( 192 | 2,0,0,0,0,0,0,0, # 00 - 07 193 | 0,0,0,0,0,0,0,0, # 08 - 0f 194 | 0,0,0,0,0,0,0,0, # 10 - 17 195 | 0,0,0,1,0,0,0,0, # 18 - 1f 196 | 0,0,0,0,3,0,0,0, # 20 - 27 197 | 0,4,0,0,0,0,0,0, # 28 - 2f 198 | 0,0,0,0,0,0,0,0, # 30 - 37 199 | 0,0,0,0,0,0,0,0, # 38 - 3f 200 | 0,0,0,5,0,0,0,0, # 40 - 47 201 | 0,0,0,0,0,0,0,0, # 48 - 4f 202 | 0,0,0,0,0,0,0,0, # 50 - 57 203 | 0,0,0,0,0,0,0,0, # 58 - 5f 204 | 0,0,0,0,0,0,0,0, # 60 - 67 205 | 0,0,0,0,0,0,0,0, # 68 - 6f 206 | 0,0,0,0,0,0,0,0, # 70 - 77 207 | 0,0,0,0,0,0,0,0, # 78 - 7f 208 | 2,2,2,2,2,2,2,2, # 80 - 87 209 | 2,2,2,2,2,2,2,2, # 88 - 8f 210 | 2,2,2,2,2,2,2,2, # 90 - 97 211 | 2,2,2,2,2,2,2,2, # 98 - 9f 212 | 2,2,2,2,2,2,2,2, # a0 - a7 213 | 2,2,2,2,2,2,2,2, # a8 - af 214 | 2,2,2,2,2,2,2,2, # b0 - b7 215 | 2,2,2,2,2,2,2,2, # b8 - bf 216 | 2,2,2,2,2,2,2,2, # c0 - c7 217 | 2,2,2,2,2,2,2,2, # c8 - cf 218 | 2,2,2,2,2,2,2,2, # d0 - d7 219 | 2,2,2,2,2,2,2,2, # d8 - df 220 | 2,2,2,2,2,2,2,2, # e0 - e7 221 | 2,2,2,2,2,2,2,2, # e8 - ef 222 | 2,2,2,2,2,2,2,2, # f0 - f7 223 | 2,2,2,2,2,2,2,2, # f8 - ff 224 | ) 225 | 226 | ISO2022KR_st = ( 227 | eStart, 3,eError,eStart,eStart,eStart,eError,eError,# 00-07 228 | eError,eError,eError,eError,eItsMe,eItsMe,eItsMe,eItsMe,# 08-0f 229 | eItsMe,eItsMe,eError,eError,eError, 4,eError,eError,# 10-17 230 | eError,eError,eError,eError, 5,eError,eError,eError,# 18-1f 231 | eError,eError,eError,eItsMe,eStart,eStart,eStart,eStart,# 20-27 232 | ) 233 | 234 | ISO2022KRCharLenTable = (0, 0, 0, 0, 0, 0) 235 | 236 | ISO2022KRSMModel = {'classTable': ISO2022KR_cls, 237 | 'classFactor': 6, 238 | 'stateTable': ISO2022KR_st, 239 | 'charLenTable': ISO2022KRCharLenTable, 240 | 'name': "ISO-2022-KR"} 241 | 242 | # flake8: noqa 243 | -------------------------------------------------------------------------------- /Application/Logic/material_manager.py: -------------------------------------------------------------------------------- 1 | ''' 2 | UI functionality for the material manager. 3 | ''' 4 | from win32com.client import constants as const 5 | import win32com.client 6 | xsi = Application 7 | addonpath = xsi.InstallationPath(const.siUserAddonPath) 8 | PROJECTPATH = xsi.InstallationPath(const.siProjectPath) 9 | 10 | 11 | def close_mat_OnClicked(): 12 | PPG.Close() 13 | xsi.DeleteObj('MaterialEdit') 14 | 15 | 16 | def help_mat_OnClicked(): 17 | ps = xsi.ActiveSceneRoot.AddProperty('CustomProperty', False, 'MatManagerHelp') 18 | lay = ps.PPGLayout 19 | lay.Language = 'pythonscript' 20 | agr = lay.AddGroup 21 | egr = lay.EndGroup 22 | text = lay.AddStaticText 23 | agr('Create', 1) 24 | text('''Create a phong material(the only supported material type) 25 | with the specified name(line edit to the left of this button.''') 26 | egr() 27 | agr('Edit', 1) 28 | text('''Inspect the first selected material ZE flags and options can be 29 | found here, too.''') 30 | egr() 31 | agr('ZEify / De-ZEify', 1) 32 | text('''Adds/Removes Zero Engine flags and material settings to the 33 | selected material(s).''') 34 | egr() 35 | agr('Remove', 1) 36 | text('''Removes the selected material(s).''') 37 | egr() 38 | agr('Assign Tex', 1) 39 | text('''A shortcut to assign a texture to the diffuse slot of 40 | the selected material. This will launch a file browser.''') 41 | egr() 42 | agr('Assign / Unassign', 1) 43 | text('''Assigns/unassigns the first selected material to the 44 | currently selected models.''') 45 | egr() 46 | xsi.InspectObj(ps, '', 'MatManagerHelp', 4, False) 47 | for prop in xsi.ActiveSceneRoot.Properties: 48 | if prop.Name == 'MatManagerHelp': 49 | xsi.DeleteObj('MatManagerHelp') 50 | 51 | 52 | def del_mat_OnClicked(): 53 | materials = get_scene_materials() 54 | ppg = PPG.Inspected(0) 55 | sel = ppg.Parameters('materials').Value 56 | split = sel.split(';') 57 | lay = ppg.PPGLayout 58 | listbox = lay.Item('materials') 59 | items = listbox.UIItems 60 | items2 = list(items[:]) 61 | for matname in split: 62 | for mat in materials: 63 | if mat.Name == matname: 64 | xsi.DeleteObj(mat) 65 | break 66 | refresh() 67 | PPG.Refresh() 68 | 69 | 70 | def create_mat_OnClicked(): 71 | ppg = PPG.Inspected(0) 72 | name = ppg.Parameters('mat_name').Value 73 | args = '$XSI_DSPRESETS\\Shaders\\Material\\Phong', name, '', '', False, '' 74 | xsi.SICreateMaterial(*args) 75 | refresh() 76 | 77 | 78 | def edit_mat_OnClicked(): 79 | materials = get_scene_materials() 80 | ppg = PPG.Inspected(0) 81 | sel = ppg.Parameters('materials').Value 82 | split = sel.split(';') 83 | for mat in materials: 84 | if mat.Name == split[0]: 85 | xsi.InspectObj(mat) 86 | 87 | 88 | def add_flags_OnClicked(): 89 | materials = get_scene_materials() 90 | ppg = PPG.Inspected(0) 91 | sel = ppg.Parameters('materials').Value 92 | split = sel.split(';') 93 | for matname in split: 94 | for mat in materials: 95 | if mat.Name == matname: 96 | if not get_msh_material_property(mat): 97 | add_msh_material_flags(mat) 98 | break 99 | refresh() 100 | 101 | 102 | def del_flags_OnClicked(): 103 | materials = get_scene_materials() 104 | ppg = PPG.Inspected(0) 105 | sel = ppg.Parameters('materials').Value 106 | split = sel.split(';') 107 | for matname in split: 108 | for mat in materials: 109 | if mat.Name == matname: 110 | prop = get_msh_material_property(mat) 111 | if prop: 112 | xsi.DeleteObj(prop) 113 | break 114 | refresh() 115 | 116 | 117 | def unassign_mat_OnClicked(): 118 | if xsi.Selection.Count == 0: 119 | msg_box('No objects selected.') 120 | return 121 | xsi.SIUnAssignMaterial(xsi.Selection) 122 | 123 | 124 | def assign_mat_OnClicked(): 125 | materials = get_scene_materials() 126 | ppg = PPG.Inspected(0) 127 | sel = ppg.Parameters('materials').Value 128 | split = sel.split(';') 129 | mat2assign = None 130 | for mat in materials: 131 | if mat.Name == split[0]: 132 | mat2assign = mat 133 | break 134 | if xsi.Selection.Count == 0: 135 | msg_box('No objects selected.') 136 | return 137 | for item in xsi.Selection: 138 | if item.Type == 'polySubComponent': 139 | cls = item.SubComponent.CreateCluster('matpolycls') 140 | xsi.SIAssignMaterial(cls, mat2assign) 141 | elif item.Type == 'poly': 142 | xsi.SIAssignMaterial(item, mat2assign) 143 | elif item.Type == 'polymsh': 144 | xsi.SIAssignMaterial(item, mat2assign) 145 | refresh() 146 | 147 | 148 | def assign_tex_OnClicked(): 149 | materials = get_scene_materials() 150 | ppg = PPG.Inspected(0) 151 | sel = ppg.Parameters('materials').Value 152 | split = sel.split(';') 153 | mats = [] 154 | for matname in split: 155 | for mat in materials: 156 | if mat.Name == matname: 157 | mats.append(mat) 158 | break 159 | xsiui = win32com.client.Dispatch('XSI.UIToolkit') 160 | fb = xsiui.FileBrowser 161 | fb.DialogTitle = 'Select a .tga file' 162 | fb.InitialDirectory = PROJECTPATH 163 | fb.Filter = 'TARGA (*.tga)|*.tga||' 164 | fb.ShowOpen() 165 | img_filepath = fb.FilePathName 166 | if img_filepath: 167 | for mat in mats: 168 | shader = xsi.CreateShaderFromPreset('$XSI_DSPRESETS\\Shaders\\Texture\\Image.Preset', mat) 169 | img_clip = xsi.SICreateImageClip2(img_filepath) 170 | xsi.SIConnectShaderToCnxPoint(img_clip, shader.tex, False) 171 | xsi.SIConnectShaderToCnxPoint(shader, mat.Shaders(0).Parameters('diffuse'), False) 172 | ############################################################################## 173 | ###################### HELPER FUNCTIONS ################################## 174 | 175 | 176 | def refresh(): 177 | mats = get_scene_materials('variants') 178 | PPG.Inspected(0).PPGLayout.Item('materials').UIItems = mats 179 | PPG.Refresh() 180 | 181 | 182 | def msg_box(message): 183 | XSIUIToolkit.MsgBox(message, 0, 'XSIZETools') 184 | return True 185 | 186 | 187 | def get_msh_material_property(material): 188 | for prop in material.Properties: 189 | if 'ZeroEngine_Flags' in prop.Name: 190 | return prop 191 | 192 | 193 | def add_msh_material_flags(mat): 194 | pset = mat.AddProperty('CustomProperty', False, 'ZeroEngine Flags') 195 | pset.AddParameter3('tex1', const.siString) 196 | pset.AddParameter3('tex2', const.siString) 197 | pset.AddParameter3('tex3', const.siString) 198 | 199 | pset.AddParameter3('emissive', const.siBool, 0, '', '', 0) 200 | pset.AddParameter3('glow', const.siBool, 0, '', '', 0) 201 | pset.AddParameter3('transparency', const.siInt4, 0, 0, 2, 0) 202 | pset.AddParameter3('hardedged', const.siBool, 0, '', '', 0) 203 | pset.AddParameter3('perpixel', const.siBool, 0, '', '', 0) 204 | pset.AddParameter3('additive', const.siBool, 0, '', '', 0) 205 | pset.AddParameter3('specular', const.siBool, 0, '', '', 0) 206 | pset.AddParameter3('rendertype', const.siInt4, 0, 0, 31, 0) 207 | pset.AddParameter3('data0', const.siInt4, 0, 0, 255, 0) 208 | pset.AddParameter3('data1', const.siInt4, 0, 0, 255, 0) 209 | 210 | lay = pset.PPGLayout 211 | 212 | lay.AddGroup('ZeroEngine Material Flags', 1) 213 | lay.AddGroup('Additional Textures', 1) 214 | lay.AddItem('tex1', 'Texture 1') 215 | lay.AddItem('tex2', 'Texture 2') 216 | lay.AddItem('tex3', 'Texture 3') 217 | lay.EndGroup() 218 | lay.AddGroup('Flags', 1) 219 | lay.AddItem('emissive', 'Emissive') 220 | lay.AddItem('glow', 'Glow') 221 | lay.AddItem('transparency', 'Transparency') 222 | lay.AddItem('hardedged', 'Hardedged Transparency') 223 | lay.AddItem('perpixel', 'Per-Pixel Lighting') 224 | lay.AddItem('additive', 'Additive Transparency') 225 | lay.AddItem('specular', 'Specular') 226 | lay.AddItem('rendertype', 'RenderType') 227 | lay.AddItem('data0', 'Data0') 228 | lay.AddItem('data1', 'Data1') 229 | lay.EndGroup() 230 | lay.EndGroup() 231 | 232 | 233 | def get_scene_materials(listtype='list'): 234 | mats = [] 235 | matlibs = xsi.ActiveProject.ActiveScene.MaterialLibraries 236 | for lib in matlibs: 237 | for mat in lib.Items: 238 | mats.append(mat) 239 | if listtype == 'variants': 240 | newmats = [] 241 | for index, mat in enumerate(mats): 242 | name = [mat.Name] 243 | prop = get_msh_material_property(mat) 244 | usedby = mat.UsedBy 245 | if usedby.Count > 0: 246 | if prop: 247 | name.append(' - ZE | {0}'.format(usedby.Count)) 248 | else: 249 | name.append(' - {0}'.format(usedby.Count)) 250 | else: 251 | if prop: 252 | name.append(' - ZE') 253 | newmats.append(''.join(name)) 254 | newmats.append(mat.Name) 255 | return newmats 256 | return mats 257 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/urllib3/packages/ordered_dict.py: -------------------------------------------------------------------------------- 1 | # Backport of OrderedDict() class that runs on Python 2.4, 2.5, 2.6, 2.7 and pypy. 2 | # Passes Python2.7's test suite and incorporates all the latest updates. 3 | # Copyright 2009 Raymond Hettinger, released under the MIT License. 4 | # http://code.activestate.com/recipes/576693/ 5 | 6 | try: 7 | from thread import get_ident as _get_ident 8 | except ImportError: 9 | from dummy_thread import get_ident as _get_ident 10 | 11 | try: 12 | from _abcoll import KeysView, ValuesView, ItemsView 13 | except ImportError: 14 | pass 15 | 16 | 17 | class OrderedDict(dict): 18 | 'Dictionary that remembers insertion order' 19 | # An inherited dict maps keys to values. 20 | # The inherited dict provides __getitem__, __len__, __contains__, and get. 21 | # The remaining methods are order-aware. 22 | # Big-O running times for all methods are the same as for regular dictionaries. 23 | 24 | # The internal self.__map dictionary maps keys to links in a doubly linked list. 25 | # The circular doubly linked list starts and ends with a sentinel element. 26 | # The sentinel element never gets deleted (this simplifies the algorithm). 27 | # Each link is stored as a list of length three: [PREV, NEXT, KEY]. 28 | 29 | def __init__(self, *args, **kwds): 30 | '''Initialize an ordered dictionary. Signature is the same as for 31 | regular dictionaries, but keyword arguments are not recommended 32 | because their insertion order is arbitrary. 33 | 34 | ''' 35 | if len(args) > 1: 36 | raise TypeError('expected at most 1 arguments, got %d' % len(args)) 37 | try: 38 | self.__root 39 | except AttributeError: 40 | self.__root = root = [] # sentinel node 41 | root[:] = [root, root, None] 42 | self.__map = {} 43 | self.__update(*args, **kwds) 44 | 45 | def __setitem__(self, key, value, dict_setitem=dict.__setitem__): 46 | 'od.__setitem__(i, y) <==> od[i]=y' 47 | # Setting a new item creates a new link which goes at the end of the linked 48 | # list, and the inherited dictionary is updated with the new key/value pair. 49 | if key not in self: 50 | root = self.__root 51 | last = root[0] 52 | last[1] = root[0] = self.__map[key] = [last, root, key] 53 | dict_setitem(self, key, value) 54 | 55 | def __delitem__(self, key, dict_delitem=dict.__delitem__): 56 | 'od.__delitem__(y) <==> del od[y]' 57 | # Deleting an existing item uses self.__map to find the link which is 58 | # then removed by updating the links in the predecessor and successor nodes. 59 | dict_delitem(self, key) 60 | link_prev, link_next, key = self.__map.pop(key) 61 | link_prev[1] = link_next 62 | link_next[0] = link_prev 63 | 64 | def __iter__(self): 65 | 'od.__iter__() <==> iter(od)' 66 | root = self.__root 67 | curr = root[1] 68 | while curr is not root: 69 | yield curr[2] 70 | curr = curr[1] 71 | 72 | def __reversed__(self): 73 | 'od.__reversed__() <==> reversed(od)' 74 | root = self.__root 75 | curr = root[0] 76 | while curr is not root: 77 | yield curr[2] 78 | curr = curr[0] 79 | 80 | def clear(self): 81 | 'od.clear() -> None. Remove all items from od.' 82 | try: 83 | for node in self.__map.itervalues(): 84 | del node[:] 85 | root = self.__root 86 | root[:] = [root, root, None] 87 | self.__map.clear() 88 | except AttributeError: 89 | pass 90 | dict.clear(self) 91 | 92 | def popitem(self, last=True): 93 | '''od.popitem() -> (k, v), return and remove a (key, value) pair. 94 | Pairs are returned in LIFO order if last is true or FIFO order if false. 95 | 96 | ''' 97 | if not self: 98 | raise KeyError('dictionary is empty') 99 | root = self.__root 100 | if last: 101 | link = root[0] 102 | link_prev = link[0] 103 | link_prev[1] = root 104 | root[0] = link_prev 105 | else: 106 | link = root[1] 107 | link_next = link[1] 108 | root[1] = link_next 109 | link_next[0] = root 110 | key = link[2] 111 | del self.__map[key] 112 | value = dict.pop(self, key) 113 | return key, value 114 | 115 | # -- the following methods do not depend on the internal structure -- 116 | 117 | def keys(self): 118 | 'od.keys() -> list of keys in od' 119 | return list(self) 120 | 121 | def values(self): 122 | 'od.values() -> list of values in od' 123 | return [self[key] for key in self] 124 | 125 | def items(self): 126 | 'od.items() -> list of (key, value) pairs in od' 127 | return [(key, self[key]) for key in self] 128 | 129 | def iterkeys(self): 130 | 'od.iterkeys() -> an iterator over the keys in od' 131 | return iter(self) 132 | 133 | def itervalues(self): 134 | 'od.itervalues -> an iterator over the values in od' 135 | for k in self: 136 | yield self[k] 137 | 138 | def iteritems(self): 139 | 'od.iteritems -> an iterator over the (key, value) items in od' 140 | for k in self: 141 | yield (k, self[k]) 142 | 143 | def update(*args, **kwds): 144 | '''od.update(E, **F) -> None. Update od from dict/iterable E and F. 145 | 146 | If E is a dict instance, does: for k in E: od[k] = E[k] 147 | If E has a .keys() method, does: for k in E.keys(): od[k] = E[k] 148 | Or if E is an iterable of items, does: for k, v in E: od[k] = v 149 | In either case, this is followed by: for k, v in F.items(): od[k] = v 150 | 151 | ''' 152 | if len(args) > 2: 153 | raise TypeError('update() takes at most 2 positional ' 154 | 'arguments (%d given)' % (len(args),)) 155 | elif not args: 156 | raise TypeError('update() takes at least 1 argument (0 given)') 157 | self = args[0] 158 | # Make progressively weaker assumptions about "other" 159 | other = () 160 | if len(args) == 2: 161 | other = args[1] 162 | if isinstance(other, dict): 163 | for key in other: 164 | self[key] = other[key] 165 | elif hasattr(other, 'keys'): 166 | for key in other.keys(): 167 | self[key] = other[key] 168 | else: 169 | for key, value in other: 170 | self[key] = value 171 | for key, value in kwds.items(): 172 | self[key] = value 173 | 174 | __update = update # let subclasses override update without breaking __init__ 175 | 176 | __marker = object() 177 | 178 | def pop(self, key, default=__marker): 179 | '''od.pop(k[,d]) -> v, remove specified key and return the corresponding value. 180 | If key is not found, d is returned if given, otherwise KeyError is raised. 181 | 182 | ''' 183 | if key in self: 184 | result = self[key] 185 | del self[key] 186 | return result 187 | if default is self.__marker: 188 | raise KeyError(key) 189 | return default 190 | 191 | def setdefault(self, key, default=None): 192 | 'od.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in od' 193 | if key in self: 194 | return self[key] 195 | self[key] = default 196 | return default 197 | 198 | def __repr__(self, _repr_running={}): 199 | 'od.__repr__() <==> repr(od)' 200 | call_key = id(self), _get_ident() 201 | if call_key in _repr_running: 202 | return '...' 203 | _repr_running[call_key] = 1 204 | try: 205 | if not self: 206 | return '%s()' % (self.__class__.__name__,) 207 | return '%s(%r)' % (self.__class__.__name__, self.items()) 208 | finally: 209 | del _repr_running[call_key] 210 | 211 | def __reduce__(self): 212 | 'Return state information for pickling' 213 | items = [[k, self[k]] for k in self] 214 | inst_dict = vars(self).copy() 215 | for k in vars(OrderedDict()): 216 | inst_dict.pop(k, None) 217 | if inst_dict: 218 | return (self.__class__, (items,), inst_dict) 219 | return self.__class__, (items,) 220 | 221 | def copy(self): 222 | 'od.copy() -> a shallow copy of od' 223 | return self.__class__(self) 224 | 225 | @classmethod 226 | def fromkeys(cls, iterable, value=None): 227 | '''OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S 228 | and values equal to v (which defaults to None). 229 | 230 | ''' 231 | d = cls() 232 | for key in iterable: 233 | d[key] = value 234 | return d 235 | 236 | def __eq__(self, other): 237 | '''od.__eq__(y) <==> od==y. Comparison to another OD is order-sensitive 238 | while comparison to a regular mapping is order-insensitive. 239 | 240 | ''' 241 | if isinstance(other, OrderedDict): 242 | return len(self)==len(other) and self.items() == other.items() 243 | return dict.__eq__(self, other) 244 | 245 | def __ne__(self, other): 246 | return not self == other 247 | 248 | # -- the following methods are only used in Python 2.7 -- 249 | 250 | def viewkeys(self): 251 | "od.viewkeys() -> a set-like object providing a view on od's keys" 252 | return KeysView(self) 253 | 254 | def viewvalues(self): 255 | "od.viewvalues() -> an object providing a view on od's values" 256 | return ValuesView(self) 257 | 258 | def viewitems(self): 259 | "od.viewitems() -> a set-like object providing a view on od's items" 260 | return ItemsView(self) 261 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/urllib3/poolmanager.py: -------------------------------------------------------------------------------- 1 | # urllib3/poolmanager.py 2 | # Copyright 2008-2013 Andrey Petrov and contributors (see CONTRIBUTORS.txt) 3 | # 4 | # This module is part of urllib3 and is released under 5 | # the MIT License: http://www.opensource.org/licenses/mit-license.php 6 | 7 | import logging 8 | 9 | try: # Python 3 10 | from urllib.parse import urljoin 11 | except ImportError: 12 | from urlparse import urljoin 13 | 14 | from ._collections import RecentlyUsedContainer 15 | from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool 16 | from .connectionpool import port_by_scheme 17 | from .request import RequestMethods 18 | from .util import parse_url 19 | 20 | 21 | __all__ = ['PoolManager', 'ProxyManager', 'proxy_from_url'] 22 | 23 | 24 | pool_classes_by_scheme = { 25 | 'http': HTTPConnectionPool, 26 | 'https': HTTPSConnectionPool, 27 | } 28 | 29 | log = logging.getLogger(__name__) 30 | 31 | SSL_KEYWORDS = ('key_file', 'cert_file', 'cert_reqs', 'ca_certs', 32 | 'ssl_version') 33 | 34 | 35 | class PoolManager(RequestMethods): 36 | """ 37 | Allows for arbitrary requests while transparently keeping track of 38 | necessary connection pools for you. 39 | 40 | :param num_pools: 41 | Number of connection pools to cache before discarding the least 42 | recently used pool. 43 | 44 | :param headers: 45 | Headers to include with all requests, unless other headers are given 46 | explicitly. 47 | 48 | :param \**connection_pool_kw: 49 | Additional parameters are used to create fresh 50 | :class:`urllib3.connectionpool.ConnectionPool` instances. 51 | 52 | Example: :: 53 | 54 | >>> manager = PoolManager(num_pools=2) 55 | >>> r = manager.request('GET', 'http://google.com/') 56 | >>> r = manager.request('GET', 'http://google.com/mail') 57 | >>> r = manager.request('GET', 'http://yahoo.com/') 58 | >>> len(manager.pools) 59 | 2 60 | 61 | """ 62 | 63 | proxy = None 64 | 65 | def __init__(self, num_pools=10, headers=None, **connection_pool_kw): 66 | RequestMethods.__init__(self, headers) 67 | self.connection_pool_kw = connection_pool_kw 68 | self.pools = RecentlyUsedContainer(num_pools, 69 | dispose_func=lambda p: p.close()) 70 | 71 | def _new_pool(self, scheme, host, port): 72 | """ 73 | Create a new :class:`ConnectionPool` based on host, port and scheme. 74 | 75 | This method is used to actually create the connection pools handed out 76 | by :meth:`connection_from_url` and companion methods. It is intended 77 | to be overridden for customization. 78 | """ 79 | pool_cls = pool_classes_by_scheme[scheme] 80 | kwargs = self.connection_pool_kw 81 | if scheme == 'http': 82 | kwargs = self.connection_pool_kw.copy() 83 | for kw in SSL_KEYWORDS: 84 | kwargs.pop(kw, None) 85 | 86 | return pool_cls(host, port, **kwargs) 87 | 88 | def clear(self): 89 | """ 90 | Empty our store of pools and direct them all to close. 91 | 92 | This will not affect in-flight connections, but they will not be 93 | re-used after completion. 94 | """ 95 | self.pools.clear() 96 | 97 | def connection_from_host(self, host, port=None, scheme='http'): 98 | """ 99 | Get a :class:`ConnectionPool` based on the host, port, and scheme. 100 | 101 | If ``port`` isn't given, it will be derived from the ``scheme`` using 102 | ``urllib3.connectionpool.port_by_scheme``. 103 | """ 104 | 105 | scheme = scheme or 'http' 106 | 107 | port = port or port_by_scheme.get(scheme, 80) 108 | 109 | pool_key = (scheme, host, port) 110 | 111 | with self.pools.lock: 112 | # If the scheme, host, or port doesn't match existing open 113 | # connections, open a new ConnectionPool. 114 | pool = self.pools.get(pool_key) 115 | if pool: 116 | return pool 117 | 118 | # Make a fresh ConnectionPool of the desired type 119 | pool = self._new_pool(scheme, host, port) 120 | self.pools[pool_key] = pool 121 | return pool 122 | 123 | def connection_from_url(self, url): 124 | """ 125 | Similar to :func:`urllib3.connectionpool.connection_from_url` but 126 | doesn't pass any additional parameters to the 127 | :class:`urllib3.connectionpool.ConnectionPool` constructor. 128 | 129 | Additional parameters are taken from the :class:`.PoolManager` 130 | constructor. 131 | """ 132 | u = parse_url(url) 133 | return self.connection_from_host(u.host, port=u.port, scheme=u.scheme) 134 | 135 | def urlopen(self, method, url, redirect=True, **kw): 136 | """ 137 | Same as :meth:`urllib3.connectionpool.HTTPConnectionPool.urlopen` 138 | with custom cross-host redirect logic and only sends the request-uri 139 | portion of the ``url``. 140 | 141 | The given ``url`` parameter must be absolute, such that an appropriate 142 | :class:`urllib3.connectionpool.ConnectionPool` can be chosen for it. 143 | """ 144 | u = parse_url(url) 145 | conn = self.connection_from_host(u.host, port=u.port, scheme=u.scheme) 146 | 147 | kw['assert_same_host'] = False 148 | kw['redirect'] = False 149 | if 'headers' not in kw: 150 | kw['headers'] = self.headers 151 | 152 | if self.proxy is not None and u.scheme == "http": 153 | response = conn.urlopen(method, url, **kw) 154 | else: 155 | response = conn.urlopen(method, u.request_uri, **kw) 156 | 157 | redirect_location = redirect and response.get_redirect_location() 158 | if not redirect_location: 159 | return response 160 | 161 | # Support relative URLs for redirecting. 162 | redirect_location = urljoin(url, redirect_location) 163 | 164 | # RFC 2616, Section 10.3.4 165 | if response.status == 303: 166 | method = 'GET' 167 | 168 | log.info("Redirecting %s -> %s" % (url, redirect_location)) 169 | kw['retries'] = kw.get('retries', 3) - 1 # Persist retries countdown 170 | kw['redirect'] = redirect 171 | return self.urlopen(method, redirect_location, **kw) 172 | 173 | 174 | class ProxyManager(PoolManager): 175 | """ 176 | Behaves just like :class:`PoolManager`, but sends all requests through 177 | the defined proxy, using the CONNECT method for HTTPS URLs. 178 | 179 | :param poxy_url: 180 | The URL of the proxy to be used. 181 | 182 | :param proxy_headers: 183 | A dictionary contaning headers that will be sent to the proxy. In case 184 | of HTTP they are being sent with each request, while in the 185 | HTTPS/CONNECT case they are sent only once. Could be used for proxy 186 | authentication. 187 | 188 | Example: 189 | >>> proxy = urllib3.ProxyManager('http://localhost:3128/') 190 | >>> r1 = proxy.request('GET', 'http://google.com/') 191 | >>> r2 = proxy.request('GET', 'http://httpbin.org/') 192 | >>> len(proxy.pools) 193 | 1 194 | >>> r3 = proxy.request('GET', 'https://httpbin.org/') 195 | >>> r4 = proxy.request('GET', 'https://twitter.com/') 196 | >>> len(proxy.pools) 197 | 3 198 | 199 | """ 200 | 201 | def __init__(self, proxy_url, num_pools=10, headers=None, 202 | proxy_headers=None, **connection_pool_kw): 203 | 204 | if isinstance(proxy_url, HTTPConnectionPool): 205 | proxy_url = '%s://%s:%i' % (proxy_url.scheme, proxy_url.host, 206 | proxy_url.port) 207 | proxy = parse_url(proxy_url) 208 | if not proxy.port: 209 | port = port_by_scheme.get(proxy.scheme, 80) 210 | proxy = proxy._replace(port=port) 211 | self.proxy = proxy 212 | self.proxy_headers = proxy_headers or {} 213 | assert self.proxy.scheme in ("http", "https"), \ 214 | 'Not supported proxy scheme %s' % self.proxy.scheme 215 | connection_pool_kw['_proxy'] = self.proxy 216 | connection_pool_kw['_proxy_headers'] = self.proxy_headers 217 | super(ProxyManager, self).__init__( 218 | num_pools, headers, **connection_pool_kw) 219 | 220 | def connection_from_host(self, host, port=None, scheme='http'): 221 | if scheme == "https": 222 | return super(ProxyManager, self).connection_from_host( 223 | host, port, scheme) 224 | 225 | return super(ProxyManager, self).connection_from_host( 226 | self.proxy.host, self.proxy.port, self.proxy.scheme) 227 | 228 | def _set_proxy_headers(self, url, headers=None): 229 | """ 230 | Sets headers needed by proxies: specifically, the Accept and Host 231 | headers. Only sets headers not provided by the user. 232 | """ 233 | headers_ = {'Accept': '*/*'} 234 | 235 | netloc = parse_url(url).netloc 236 | if netloc: 237 | headers_['Host'] = netloc 238 | 239 | if headers: 240 | headers_.update(headers) 241 | return headers_ 242 | 243 | def urlopen(self, method, url, redirect=True, **kw): 244 | "Same as HTTP(S)ConnectionPool.urlopen, ``url`` must be absolute." 245 | u = parse_url(url) 246 | 247 | if u.scheme == "http": 248 | # It's too late to set proxy headers on per-request basis for 249 | # tunnelled HTTPS connections, should use 250 | # constructor's proxy_headers instead. 251 | kw['headers'] = self._set_proxy_headers(url, kw.get('headers', 252 | self.headers)) 253 | kw['headers'].update(self.proxy_headers) 254 | 255 | return super(ProxyManager, self).urlopen(method, url, redirect, **kw) 256 | 257 | 258 | def proxy_from_url(url, **kw): 259 | return ProxyManager(proxy_url=url, **kw) 260 | -------------------------------------------------------------------------------- /Application/Modules/requests/packages/charade/chardistribution.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is Mozilla Communicator client code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 1998 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # 12 | # This library is free software; you can redistribute it and/or 13 | # modify it under the terms of the GNU Lesser General Public 14 | # License as published by the Free Software Foundation; either 15 | # version 2.1 of the License, or (at your option) any later version. 16 | # 17 | # This library is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | # Lesser General Public License for more details. 21 | # 22 | # You should have received a copy of the GNU Lesser General Public 23 | # License along with this library; if not, write to the Free Software 24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 25 | # 02110-1301 USA 26 | ######################### END LICENSE BLOCK ######################### 27 | 28 | from .euctwfreq import (EUCTWCharToFreqOrder, EUCTW_TABLE_SIZE, 29 | EUCTW_TYPICAL_DISTRIBUTION_RATIO) 30 | from .euckrfreq import (EUCKRCharToFreqOrder, EUCKR_TABLE_SIZE, 31 | EUCKR_TYPICAL_DISTRIBUTION_RATIO) 32 | from .gb2312freq import (GB2312CharToFreqOrder, GB2312_TABLE_SIZE, 33 | GB2312_TYPICAL_DISTRIBUTION_RATIO) 34 | from .big5freq import (Big5CharToFreqOrder, BIG5_TABLE_SIZE, 35 | BIG5_TYPICAL_DISTRIBUTION_RATIO) 36 | from .jisfreq import (JISCharToFreqOrder, JIS_TABLE_SIZE, 37 | JIS_TYPICAL_DISTRIBUTION_RATIO) 38 | from .compat import wrap_ord 39 | 40 | ENOUGH_DATA_THRESHOLD = 1024 41 | SURE_YES = 0.99 42 | SURE_NO = 0.01 43 | MINIMUM_DATA_THRESHOLD = 3 44 | 45 | 46 | class CharDistributionAnalysis: 47 | def __init__(self): 48 | # Mapping table to get frequency order from char order (get from 49 | # GetOrder()) 50 | self._mCharToFreqOrder = None 51 | self._mTableSize = None # Size of above table 52 | # This is a constant value which varies from language to language, 53 | # used in calculating confidence. See 54 | # http://www.mozilla.org/projects/intl/UniversalCharsetDetection.html 55 | # for further detail. 56 | self._mTypicalDistributionRatio = None 57 | self.reset() 58 | 59 | def reset(self): 60 | """reset analyser, clear any state""" 61 | # If this flag is set to True, detection is done and conclusion has 62 | # been made 63 | self._mDone = False 64 | self._mTotalChars = 0 # Total characters encountered 65 | # The number of characters whose frequency order is less than 512 66 | self._mFreqChars = 0 67 | 68 | def feed(self, aBuf, aCharLen): 69 | """feed a character with known length""" 70 | if aCharLen == 2: 71 | # we only care about 2-bytes character in our distribution analysis 72 | order = self.get_order(aBuf) 73 | else: 74 | order = -1 75 | if order >= 0: 76 | self._mTotalChars += 1 77 | # order is valid 78 | if order < self._mTableSize: 79 | if 512 > self._mCharToFreqOrder[order]: 80 | self._mFreqChars += 1 81 | 82 | def get_confidence(self): 83 | """return confidence based on existing data""" 84 | # if we didn't receive any character in our consideration range, 85 | # return negative answer 86 | if self._mTotalChars <= 0 or self._mFreqChars <= MINIMUM_DATA_THRESHOLD: 87 | return SURE_NO 88 | 89 | if self._mTotalChars != self._mFreqChars: 90 | r = (self._mFreqChars / ((self._mTotalChars - self._mFreqChars) 91 | * self._mTypicalDistributionRatio)) 92 | if r < SURE_YES: 93 | return r 94 | 95 | # normalize confidence (we don't want to be 100% sure) 96 | return SURE_YES 97 | 98 | def got_enough_data(self): 99 | # It is not necessary to receive all data to draw conclusion. 100 | # For charset detection, certain amount of data is enough 101 | return self._mTotalChars > ENOUGH_DATA_THRESHOLD 102 | 103 | def get_order(self, aBuf): 104 | # We do not handle characters based on the original encoding string, 105 | # but convert this encoding string to a number, here called order. 106 | # This allows multiple encodings of a language to share one frequency 107 | # table. 108 | return -1 109 | 110 | 111 | class EUCTWDistributionAnalysis(CharDistributionAnalysis): 112 | def __init__(self): 113 | CharDistributionAnalysis.__init__(self) 114 | self._mCharToFreqOrder = EUCTWCharToFreqOrder 115 | self._mTableSize = EUCTW_TABLE_SIZE 116 | self._mTypicalDistributionRatio = EUCTW_TYPICAL_DISTRIBUTION_RATIO 117 | 118 | def get_order(self, aBuf): 119 | # for euc-TW encoding, we are interested 120 | # first byte range: 0xc4 -- 0xfe 121 | # second byte range: 0xa1 -- 0xfe 122 | # no validation needed here. State machine has done that 123 | first_char = wrap_ord(aBuf[0]) 124 | if first_char >= 0xC4: 125 | return 94 * (first_char - 0xC4) + wrap_ord(aBuf[1]) - 0xA1 126 | else: 127 | return -1 128 | 129 | 130 | class EUCKRDistributionAnalysis(CharDistributionAnalysis): 131 | def __init__(self): 132 | CharDistributionAnalysis.__init__(self) 133 | self._mCharToFreqOrder = EUCKRCharToFreqOrder 134 | self._mTableSize = EUCKR_TABLE_SIZE 135 | self._mTypicalDistributionRatio = EUCKR_TYPICAL_DISTRIBUTION_RATIO 136 | 137 | def get_order(self, aBuf): 138 | # for euc-KR encoding, we are interested 139 | # first byte range: 0xb0 -- 0xfe 140 | # second byte range: 0xa1 -- 0xfe 141 | # no validation needed here. State machine has done that 142 | first_char = wrap_ord(aBuf[0]) 143 | if first_char >= 0xB0: 144 | return 94 * (first_char - 0xB0) + wrap_ord(aBuf[1]) - 0xA1 145 | else: 146 | return -1 147 | 148 | 149 | class GB2312DistributionAnalysis(CharDistributionAnalysis): 150 | def __init__(self): 151 | CharDistributionAnalysis.__init__(self) 152 | self._mCharToFreqOrder = GB2312CharToFreqOrder 153 | self._mTableSize = GB2312_TABLE_SIZE 154 | self._mTypicalDistributionRatio = GB2312_TYPICAL_DISTRIBUTION_RATIO 155 | 156 | def get_order(self, aBuf): 157 | # for GB2312 encoding, we are interested 158 | # first byte range: 0xb0 -- 0xfe 159 | # second byte range: 0xa1 -- 0xfe 160 | # no validation needed here. State machine has done that 161 | first_char, second_char = wrap_ord(aBuf[0]), wrap_ord(aBuf[1]) 162 | if (first_char >= 0xB0) and (second_char >= 0xA1): 163 | return 94 * (first_char - 0xB0) + second_char - 0xA1 164 | else: 165 | return -1 166 | 167 | 168 | class Big5DistributionAnalysis(CharDistributionAnalysis): 169 | def __init__(self): 170 | CharDistributionAnalysis.__init__(self) 171 | self._mCharToFreqOrder = Big5CharToFreqOrder 172 | self._mTableSize = BIG5_TABLE_SIZE 173 | self._mTypicalDistributionRatio = BIG5_TYPICAL_DISTRIBUTION_RATIO 174 | 175 | def get_order(self, aBuf): 176 | # for big5 encoding, we are interested 177 | # first byte range: 0xa4 -- 0xfe 178 | # second byte range: 0x40 -- 0x7e , 0xa1 -- 0xfe 179 | # no validation needed here. State machine has done that 180 | first_char, second_char = wrap_ord(aBuf[0]), wrap_ord(aBuf[1]) 181 | if first_char >= 0xA4: 182 | if second_char >= 0xA1: 183 | return 157 * (first_char - 0xA4) + second_char - 0xA1 + 63 184 | else: 185 | return 157 * (first_char - 0xA4) + second_char - 0x40 186 | else: 187 | return -1 188 | 189 | 190 | class SJISDistributionAnalysis(CharDistributionAnalysis): 191 | def __init__(self): 192 | CharDistributionAnalysis.__init__(self) 193 | self._mCharToFreqOrder = JISCharToFreqOrder 194 | self._mTableSize = JIS_TABLE_SIZE 195 | self._mTypicalDistributionRatio = JIS_TYPICAL_DISTRIBUTION_RATIO 196 | 197 | def get_order(self, aBuf): 198 | # for sjis encoding, we are interested 199 | # first byte range: 0x81 -- 0x9f , 0xe0 -- 0xfe 200 | # second byte range: 0x40 -- 0x7e, 0x81 -- oxfe 201 | # no validation needed here. State machine has done that 202 | first_char, second_char = wrap_ord(aBuf[0]), wrap_ord(aBuf[1]) 203 | if (first_char >= 0x81) and (first_char <= 0x9F): 204 | order = 188 * (first_char - 0x81) 205 | elif (first_char >= 0xE0) and (first_char <= 0xEF): 206 | order = 188 * (first_char - 0xE0 + 31) 207 | else: 208 | return -1 209 | order = order + second_char - 0x40 210 | if second_char > 0x7F: 211 | order = -1 212 | return order 213 | 214 | 215 | class EUCJPDistributionAnalysis(CharDistributionAnalysis): 216 | def __init__(self): 217 | CharDistributionAnalysis.__init__(self) 218 | self._mCharToFreqOrder = JISCharToFreqOrder 219 | self._mTableSize = JIS_TABLE_SIZE 220 | self._mTypicalDistributionRatio = JIS_TYPICAL_DISTRIBUTION_RATIO 221 | 222 | def get_order(self, aBuf): 223 | # for euc-JP encoding, we are interested 224 | # first byte range: 0xa0 -- 0xfe 225 | # second byte range: 0xa1 -- 0xfe 226 | # no validation needed here. State machine has done that 227 | char = wrap_ord(aBuf[0]) 228 | if char >= 0xA0: 229 | return 94 * (char - 0xA1) + wrap_ord(aBuf[1]) - 0xa1 230 | else: 231 | return -1 232 | --------------------------------------------------------------------------------