streamlit-nightly 1.43.2.dev20250307__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- streamlit/__init__.py +306 -0
- streamlit/__main__.py +20 -0
- streamlit/auth_util.py +218 -0
- streamlit/cli_util.py +105 -0
- streamlit/column_config.py +56 -0
- streamlit/commands/__init__.py +13 -0
- streamlit/commands/echo.py +126 -0
- streamlit/commands/execution_control.py +238 -0
- streamlit/commands/experimental_query_params.py +169 -0
- streamlit/commands/logo.py +189 -0
- streamlit/commands/navigation.py +385 -0
- streamlit/commands/page_config.py +311 -0
- streamlit/components/__init__.py +13 -0
- streamlit/components/lib/__init__.py +13 -0
- streamlit/components/lib/local_component_registry.py +84 -0
- streamlit/components/types/__init__.py +13 -0
- streamlit/components/types/base_component_registry.py +99 -0
- streamlit/components/types/base_custom_component.py +150 -0
- streamlit/components/v1/__init__.py +31 -0
- streamlit/components/v1/component_arrow.py +141 -0
- streamlit/components/v1/component_registry.py +130 -0
- streamlit/components/v1/components.py +38 -0
- streamlit/components/v1/custom_component.py +243 -0
- streamlit/config.py +1513 -0
- streamlit/config_option.py +311 -0
- streamlit/config_util.py +177 -0
- streamlit/connections/__init__.py +28 -0
- streamlit/connections/base_connection.py +174 -0
- streamlit/connections/snowflake_connection.py +562 -0
- streamlit/connections/snowpark_connection.py +213 -0
- streamlit/connections/sql_connection.py +425 -0
- streamlit/connections/util.py +97 -0
- streamlit/cursor.py +210 -0
- streamlit/dataframe_util.py +1416 -0
- streamlit/delta_generator.py +602 -0
- streamlit/delta_generator_singletons.py +204 -0
- streamlit/deprecation_util.py +209 -0
- streamlit/development.py +21 -0
- streamlit/elements/__init__.py +13 -0
- streamlit/elements/alert.py +234 -0
- streamlit/elements/arrow.py +962 -0
- streamlit/elements/balloons.py +47 -0
- streamlit/elements/bokeh_chart.py +133 -0
- streamlit/elements/code.py +114 -0
- streamlit/elements/deck_gl_json_chart.py +546 -0
- streamlit/elements/dialog_decorator.py +267 -0
- streamlit/elements/doc_string.py +558 -0
- streamlit/elements/empty.py +130 -0
- streamlit/elements/exception.py +331 -0
- streamlit/elements/form.py +354 -0
- streamlit/elements/graphviz_chart.py +150 -0
- streamlit/elements/heading.py +302 -0
- streamlit/elements/html.py +105 -0
- streamlit/elements/iframe.py +191 -0
- streamlit/elements/image.py +196 -0
- streamlit/elements/json.py +139 -0
- streamlit/elements/layouts.py +879 -0
- streamlit/elements/lib/__init__.py +13 -0
- streamlit/elements/lib/built_in_chart_utils.py +1157 -0
- streamlit/elements/lib/color_util.py +263 -0
- streamlit/elements/lib/column_config_utils.py +542 -0
- streamlit/elements/lib/column_types.py +2188 -0
- streamlit/elements/lib/dialog.py +147 -0
- streamlit/elements/lib/dicttools.py +154 -0
- streamlit/elements/lib/event_utils.py +37 -0
- streamlit/elements/lib/file_uploader_utils.py +66 -0
- streamlit/elements/lib/form_utils.py +77 -0
- streamlit/elements/lib/image_utils.py +441 -0
- streamlit/elements/lib/js_number.py +105 -0
- streamlit/elements/lib/mutable_status_container.py +183 -0
- streamlit/elements/lib/options_selector_utils.py +250 -0
- streamlit/elements/lib/pandas_styler_utils.py +274 -0
- streamlit/elements/lib/policies.py +194 -0
- streamlit/elements/lib/streamlit_plotly_theme.py +207 -0
- streamlit/elements/lib/subtitle_utils.py +176 -0
- streamlit/elements/lib/utils.py +250 -0
- streamlit/elements/map.py +508 -0
- streamlit/elements/markdown.py +277 -0
- streamlit/elements/media.py +793 -0
- streamlit/elements/metric.py +301 -0
- streamlit/elements/plotly_chart.py +546 -0
- streamlit/elements/progress.py +156 -0
- streamlit/elements/pyplot.py +194 -0
- streamlit/elements/snow.py +47 -0
- streamlit/elements/spinner.py +113 -0
- streamlit/elements/text.py +76 -0
- streamlit/elements/toast.py +98 -0
- streamlit/elements/vega_charts.py +1984 -0
- streamlit/elements/widgets/__init__.py +13 -0
- streamlit/elements/widgets/audio_input.py +310 -0
- streamlit/elements/widgets/button.py +1123 -0
- streamlit/elements/widgets/button_group.py +1008 -0
- streamlit/elements/widgets/camera_input.py +263 -0
- streamlit/elements/widgets/chat.py +647 -0
- streamlit/elements/widgets/checkbox.py +352 -0
- streamlit/elements/widgets/color_picker.py +265 -0
- streamlit/elements/widgets/data_editor.py +983 -0
- streamlit/elements/widgets/file_uploader.py +486 -0
- streamlit/elements/widgets/multiselect.py +338 -0
- streamlit/elements/widgets/number_input.py +545 -0
- streamlit/elements/widgets/radio.py +407 -0
- streamlit/elements/widgets/select_slider.py +437 -0
- streamlit/elements/widgets/selectbox.py +366 -0
- streamlit/elements/widgets/slider.py +880 -0
- streamlit/elements/widgets/text_widgets.py +628 -0
- streamlit/elements/widgets/time_widgets.py +970 -0
- streamlit/elements/write.py +574 -0
- streamlit/emojis.py +34 -0
- streamlit/env_util.py +61 -0
- streamlit/error_util.py +105 -0
- streamlit/errors.py +452 -0
- streamlit/external/__init__.py +13 -0
- streamlit/external/langchain/__init__.py +23 -0
- streamlit/external/langchain/streamlit_callback_handler.py +406 -0
- streamlit/file_util.py +247 -0
- streamlit/git_util.py +173 -0
- streamlit/hello/__init__.py +13 -0
- streamlit/hello/animation_demo.py +82 -0
- streamlit/hello/dataframe_demo.py +71 -0
- streamlit/hello/hello.py +37 -0
- streamlit/hello/mapping_demo.py +114 -0
- streamlit/hello/plotting_demo.py +55 -0
- streamlit/hello/streamlit_app.py +55 -0
- streamlit/hello/utils.py +28 -0
- streamlit/logger.py +130 -0
- streamlit/material_icon_names.py +25 -0
- streamlit/navigation/__init__.py +13 -0
- streamlit/navigation/page.py +302 -0
- streamlit/net_util.py +125 -0
- streamlit/platform.py +33 -0
- streamlit/proto/Alert_pb2.py +29 -0
- streamlit/proto/Alert_pb2.pyi +90 -0
- streamlit/proto/AppPage_pb2.py +27 -0
- streamlit/proto/AppPage_pb2.pyi +64 -0
- streamlit/proto/ArrowNamedDataSet_pb2.py +28 -0
- streamlit/proto/ArrowNamedDataSet_pb2.pyi +57 -0
- streamlit/proto/ArrowVegaLiteChart_pb2.py +29 -0
- streamlit/proto/ArrowVegaLiteChart_pb2.pyi +84 -0
- streamlit/proto/Arrow_pb2.py +33 -0
- streamlit/proto/Arrow_pb2.pyi +188 -0
- streamlit/proto/AudioInput_pb2.py +28 -0
- streamlit/proto/AudioInput_pb2.pyi +58 -0
- streamlit/proto/Audio_pb2.py +27 -0
- streamlit/proto/Audio_pb2.pyi +58 -0
- streamlit/proto/AuthRedirect_pb2.py +27 -0
- streamlit/proto/AuthRedirect_pb2.pyi +41 -0
- streamlit/proto/AutoRerun_pb2.py +27 -0
- streamlit/proto/AutoRerun_pb2.pyi +45 -0
- streamlit/proto/BackMsg_pb2.py +29 -0
- streamlit/proto/BackMsg_pb2.pyi +105 -0
- streamlit/proto/Balloons_pb2.py +27 -0
- streamlit/proto/Balloons_pb2.pyi +43 -0
- streamlit/proto/Block_pb2.py +53 -0
- streamlit/proto/Block_pb2.pyi +322 -0
- streamlit/proto/BokehChart_pb2.py +27 -0
- streamlit/proto/BokehChart_pb2.pyi +49 -0
- streamlit/proto/ButtonGroup_pb2.py +36 -0
- streamlit/proto/ButtonGroup_pb2.pyi +169 -0
- streamlit/proto/Button_pb2.py +27 -0
- streamlit/proto/Button_pb2.pyi +71 -0
- streamlit/proto/CameraInput_pb2.py +28 -0
- streamlit/proto/CameraInput_pb2.pyi +58 -0
- streamlit/proto/ChatInput_pb2.py +31 -0
- streamlit/proto/ChatInput_pb2.pyi +111 -0
- streamlit/proto/Checkbox_pb2.py +30 -0
- streamlit/proto/Checkbox_pb2.pyi +90 -0
- streamlit/proto/ClientState_pb2.py +30 -0
- streamlit/proto/ClientState_pb2.pyi +90 -0
- streamlit/proto/Code_pb2.py +27 -0
- streamlit/proto/Code_pb2.pyi +55 -0
- streamlit/proto/ColorPicker_pb2.py +28 -0
- streamlit/proto/ColorPicker_pb2.pyi +67 -0
- streamlit/proto/Common_pb2.py +51 -0
- streamlit/proto/Common_pb2.pyi +293 -0
- streamlit/proto/Components_pb2.py +35 -0
- streamlit/proto/Components_pb2.pyi +172 -0
- streamlit/proto/DataFrame_pb2.py +56 -0
- streamlit/proto/DataFrame_pb2.pyi +397 -0
- streamlit/proto/DateInput_pb2.py +28 -0
- streamlit/proto/DateInput_pb2.pyi +83 -0
- streamlit/proto/DeckGlJsonChart_pb2.py +29 -0
- streamlit/proto/DeckGlJsonChart_pb2.pyi +102 -0
- streamlit/proto/Delta_pb2.py +31 -0
- streamlit/proto/Delta_pb2.pyi +74 -0
- streamlit/proto/DocString_pb2.py +29 -0
- streamlit/proto/DocString_pb2.pyi +93 -0
- streamlit/proto/DownloadButton_pb2.py +27 -0
- streamlit/proto/DownloadButton_pb2.pyi +70 -0
- streamlit/proto/Element_pb2.py +78 -0
- streamlit/proto/Element_pb2.pyi +312 -0
- streamlit/proto/Empty_pb2.py +27 -0
- streamlit/proto/Empty_pb2.pyi +36 -0
- streamlit/proto/Exception_pb2.py +27 -0
- streamlit/proto/Exception_pb2.pyi +72 -0
- streamlit/proto/Favicon_pb2.py +27 -0
- streamlit/proto/Favicon_pb2.pyi +40 -0
- streamlit/proto/FileUploader_pb2.py +28 -0
- streamlit/proto/FileUploader_pb2.pyi +78 -0
- streamlit/proto/ForwardMsg_pb2.py +53 -0
- streamlit/proto/ForwardMsg_pb2.pyi +293 -0
- streamlit/proto/GitInfo_pb2.py +29 -0
- streamlit/proto/GitInfo_pb2.pyi +83 -0
- streamlit/proto/GraphVizChart_pb2.py +27 -0
- streamlit/proto/GraphVizChart_pb2.pyi +53 -0
- streamlit/proto/Heading_pb2.py +27 -0
- streamlit/proto/Heading_pb2.pyi +56 -0
- streamlit/proto/Html_pb2.py +27 -0
- streamlit/proto/Html_pb2.pyi +42 -0
- streamlit/proto/IFrame_pb2.py +27 -0
- streamlit/proto/IFrame_pb2.pyi +59 -0
- streamlit/proto/Image_pb2.py +29 -0
- streamlit/proto/Image_pb2.pyi +84 -0
- streamlit/proto/Json_pb2.py +27 -0
- streamlit/proto/Json_pb2.pyi +53 -0
- streamlit/proto/LabelVisibilityMessage_pb2.py +29 -0
- streamlit/proto/LabelVisibilityMessage_pb2.pyi +68 -0
- streamlit/proto/LinkButton_pb2.py +27 -0
- streamlit/proto/LinkButton_pb2.pyi +58 -0
- streamlit/proto/Logo_pb2.py +27 -0
- streamlit/proto/Logo_pb2.pyi +51 -0
- streamlit/proto/Markdown_pb2.py +29 -0
- streamlit/proto/Markdown_pb2.pyi +86 -0
- streamlit/proto/Metric_pb2.py +32 -0
- streamlit/proto/Metric_pb2.pyi +101 -0
- streamlit/proto/MetricsEvent_pb2.py +30 -0
- streamlit/proto/MetricsEvent_pb2.pyi +200 -0
- streamlit/proto/MultiSelect_pb2.py +28 -0
- streamlit/proto/MultiSelect_pb2.pyi +81 -0
- streamlit/proto/NamedDataSet_pb2.py +28 -0
- streamlit/proto/NamedDataSet_pb2.pyi +59 -0
- streamlit/proto/Navigation_pb2.py +30 -0
- streamlit/proto/Navigation_pb2.pyi +84 -0
- streamlit/proto/NewSession_pb2.py +51 -0
- streamlit/proto/NewSession_pb2.pyi +481 -0
- streamlit/proto/NumberInput_pb2.py +30 -0
- streamlit/proto/NumberInput_pb2.pyi +121 -0
- streamlit/proto/PageConfig_pb2.py +33 -0
- streamlit/proto/PageConfig_pb2.pyi +126 -0
- streamlit/proto/PageInfo_pb2.py +27 -0
- streamlit/proto/PageInfo_pb2.pyi +43 -0
- streamlit/proto/PageLink_pb2.py +27 -0
- streamlit/proto/PageLink_pb2.pyi +63 -0
- streamlit/proto/PageNotFound_pb2.py +27 -0
- streamlit/proto/PageNotFound_pb2.pyi +42 -0
- streamlit/proto/PageProfile_pb2.py +31 -0
- streamlit/proto/PageProfile_pb2.pyi +127 -0
- streamlit/proto/PagesChanged_pb2.py +28 -0
- streamlit/proto/PagesChanged_pb2.pyi +48 -0
- streamlit/proto/ParentMessage_pb2.py +27 -0
- streamlit/proto/ParentMessage_pb2.pyi +46 -0
- streamlit/proto/PlotlyChart_pb2.py +31 -0
- streamlit/proto/PlotlyChart_pb2.pyi +131 -0
- streamlit/proto/Progress_pb2.py +27 -0
- streamlit/proto/Progress_pb2.pyi +43 -0
- streamlit/proto/Radio_pb2.py +28 -0
- streamlit/proto/Radio_pb2.pyi +84 -0
- streamlit/proto/RootContainer_pb2.py +27 -0
- streamlit/proto/RootContainer_pb2.pyi +56 -0
- streamlit/proto/Selectbox_pb2.py +28 -0
- streamlit/proto/Selectbox_pb2.pyi +80 -0
- streamlit/proto/SessionEvent_pb2.py +28 -0
- streamlit/proto/SessionEvent_pb2.pyi +62 -0
- streamlit/proto/SessionStatus_pb2.py +27 -0
- streamlit/proto/SessionStatus_pb2.pyi +57 -0
- streamlit/proto/Skeleton_pb2.py +29 -0
- streamlit/proto/Skeleton_pb2.pyi +71 -0
- streamlit/proto/Slider_pb2.py +32 -0
- streamlit/proto/Slider_pb2.pyi +142 -0
- streamlit/proto/Snow_pb2.py +27 -0
- streamlit/proto/Snow_pb2.pyi +43 -0
- streamlit/proto/Spinner_pb2.py +27 -0
- streamlit/proto/Spinner_pb2.pyi +49 -0
- streamlit/proto/TextArea_pb2.py +28 -0
- streamlit/proto/TextArea_pb2.pyi +80 -0
- streamlit/proto/TextInput_pb2.py +30 -0
- streamlit/proto/TextInput_pb2.pyi +107 -0
- streamlit/proto/Text_pb2.py +27 -0
- streamlit/proto/Text_pb2.pyi +46 -0
- streamlit/proto/TimeInput_pb2.py +28 -0
- streamlit/proto/TimeInput_pb2.pyi +74 -0
- streamlit/proto/Toast_pb2.py +27 -0
- streamlit/proto/Toast_pb2.pyi +45 -0
- streamlit/proto/VegaLiteChart_pb2.py +29 -0
- streamlit/proto/VegaLiteChart_pb2.pyi +71 -0
- streamlit/proto/Video_pb2.py +31 -0
- streamlit/proto/Video_pb2.pyi +117 -0
- streamlit/proto/WidgetStates_pb2.py +31 -0
- streamlit/proto/WidgetStates_pb2.pyi +126 -0
- streamlit/proto/__init__.py +15 -0
- streamlit/proto/openmetrics_data_model_pb2.py +60 -0
- streamlit/proto/openmetrics_data_model_pb2.pyi +522 -0
- streamlit/py.typed +0 -0
- streamlit/runtime/__init__.py +50 -0
- streamlit/runtime/app_session.py +982 -0
- streamlit/runtime/caching/__init__.py +98 -0
- streamlit/runtime/caching/cache_data_api.py +665 -0
- streamlit/runtime/caching/cache_errors.py +142 -0
- streamlit/runtime/caching/cache_resource_api.py +527 -0
- streamlit/runtime/caching/cache_type.py +33 -0
- streamlit/runtime/caching/cache_utils.py +523 -0
- streamlit/runtime/caching/cached_message_replay.py +290 -0
- streamlit/runtime/caching/hashing.py +637 -0
- streamlit/runtime/caching/legacy_cache_api.py +169 -0
- streamlit/runtime/caching/storage/__init__.py +29 -0
- streamlit/runtime/caching/storage/cache_storage_protocol.py +239 -0
- streamlit/runtime/caching/storage/dummy_cache_storage.py +60 -0
- streamlit/runtime/caching/storage/in_memory_cache_storage_wrapper.py +145 -0
- streamlit/runtime/caching/storage/local_disk_cache_storage.py +223 -0
- streamlit/runtime/connection_factory.py +436 -0
- streamlit/runtime/context.py +280 -0
- streamlit/runtime/credentials.py +364 -0
- streamlit/runtime/forward_msg_cache.py +296 -0
- streamlit/runtime/forward_msg_queue.py +240 -0
- streamlit/runtime/fragment.py +477 -0
- streamlit/runtime/media_file_manager.py +234 -0
- streamlit/runtime/media_file_storage.py +143 -0
- streamlit/runtime/memory_media_file_storage.py +181 -0
- streamlit/runtime/memory_session_storage.py +77 -0
- streamlit/runtime/memory_uploaded_file_manager.py +138 -0
- streamlit/runtime/metrics_util.py +486 -0
- streamlit/runtime/pages_manager.py +165 -0
- streamlit/runtime/runtime.py +792 -0
- streamlit/runtime/runtime_util.py +106 -0
- streamlit/runtime/script_data.py +46 -0
- streamlit/runtime/scriptrunner/__init__.py +38 -0
- streamlit/runtime/scriptrunner/exec_code.py +159 -0
- streamlit/runtime/scriptrunner/magic.py +273 -0
- streamlit/runtime/scriptrunner/magic_funcs.py +32 -0
- streamlit/runtime/scriptrunner/script_cache.py +89 -0
- streamlit/runtime/scriptrunner/script_runner.py +756 -0
- streamlit/runtime/scriptrunner_utils/__init__.py +19 -0
- streamlit/runtime/scriptrunner_utils/exceptions.py +48 -0
- streamlit/runtime/scriptrunner_utils/script_requests.py +307 -0
- streamlit/runtime/scriptrunner_utils/script_run_context.py +287 -0
- streamlit/runtime/secrets.py +534 -0
- streamlit/runtime/session_manager.py +394 -0
- streamlit/runtime/state/__init__.py +41 -0
- streamlit/runtime/state/common.py +191 -0
- streamlit/runtime/state/query_params.py +205 -0
- streamlit/runtime/state/query_params_proxy.py +218 -0
- streamlit/runtime/state/safe_session_state.py +138 -0
- streamlit/runtime/state/session_state.py +772 -0
- streamlit/runtime/state/session_state_proxy.py +153 -0
- streamlit/runtime/state/widgets.py +135 -0
- streamlit/runtime/stats.py +109 -0
- streamlit/runtime/uploaded_file_manager.py +148 -0
- streamlit/runtime/websocket_session_manager.py +167 -0
- streamlit/source_util.py +98 -0
- streamlit/static/favicon.png +0 -0
- streamlit/static/index.html +61 -0
- streamlit/static/static/css/index.Bmkmz40k.css +1 -0
- streamlit/static/static/css/index.DpJG_94W.css +1 -0
- streamlit/static/static/css/index.DzuxGC_t.css +1 -0
- streamlit/static/static/js/FileDownload.esm.Bp9m5jrx.js +1 -0
- streamlit/static/static/js/FileHelper.D_3pbilj.js +5 -0
- streamlit/static/static/js/FormClearHelper.Ct2rwLXo.js +1 -0
- streamlit/static/static/js/Hooks.BKdzj5MJ.js +1 -0
- streamlit/static/static/js/InputInstructions.DB3QGNJP.js +1 -0
- streamlit/static/static/js/ProgressBar.D40A5xc2.js +2 -0
- streamlit/static/static/js/RenderInPortalIfExists.DLUCooTN.js +1 -0
- streamlit/static/static/js/Toolbar.BiGGIQun.js +1 -0
- streamlit/static/static/js/UploadFileInfo.C-jY39rj.js +1 -0
- streamlit/static/static/js/base-input.CQBQT24M.js +4 -0
- streamlit/static/static/js/checkbox.Buj8gd_M.js +9 -0
- streamlit/static/static/js/createDownloadLinkElement.DZMwyjvU.js +1 -0
- streamlit/static/static/js/createSuper.CesK3I23.js +1 -0
- streamlit/static/static/js/data-grid-overlay-editor.B69OOFM4.js +1 -0
- streamlit/static/static/js/downloader.BZQhlBNT.js +1 -0
- streamlit/static/static/js/es6.D9Zhqujy.js +2 -0
- streamlit/static/static/js/iframeResizer.contentWindow.CAzcBpCC.js +1 -0
- streamlit/static/static/js/index.08vcOOvb.js +1 -0
- streamlit/static/static/js/index.0uqKfJUS.js +1 -0
- streamlit/static/static/js/index.B02M5u69.js +203 -0
- streamlit/static/static/js/index.B7mcZKMx.js +1 -0
- streamlit/static/static/js/index.BAQDHFA_.js +1 -0
- streamlit/static/static/js/index.BI60cMVr.js +2 -0
- streamlit/static/static/js/index.BLug2inK.js +1 -0
- streamlit/static/static/js/index.BM6TMY8g.js +2 -0
- streamlit/static/static/js/index.BZ9p1t7G.js +1 -0
- streamlit/static/static/js/index.BZqa87a1.js +2 -0
- streamlit/static/static/js/index.BcsRUzZZ.js +1 -0
- streamlit/static/static/js/index.BgVMiY_P.js +197 -0
- streamlit/static/static/js/index.BtuGy7By.js +6 -0
- streamlit/static/static/js/index.BuDuBmrs.js +1 -0
- streamlit/static/static/js/index.BvXU2oKV.js +1 -0
- streamlit/static/static/js/index.BxcwPacT.js +73 -0
- streamlit/static/static/js/index.CWX8KB81.js +1 -0
- streamlit/static/static/js/index.CXzZTo_q.js +1 -0
- streamlit/static/static/js/index.CcRWp_KL.js +1 -0
- streamlit/static/static/js/index.Cd-_xe55.js +3 -0
- streamlit/static/static/js/index.CdG2PXln.js +4537 -0
- streamlit/static/static/js/index.CjXvXmcP.js +1 -0
- streamlit/static/static/js/index.D1HZENZx.js +776 -0
- streamlit/static/static/js/index.D21Efo64.js +1617 -0
- streamlit/static/static/js/index.D9WgGVBx.js +7 -0
- streamlit/static/static/js/index.DEcsHtvb.js +12 -0
- streamlit/static/static/js/index.DFeMfr_K.js +1 -0
- streamlit/static/static/js/index.DHFBoItz.js +1 -0
- streamlit/static/static/js/index.D_PrBKnJ.js +3 -0
- streamlit/static/static/js/index.DmuRkekN.js +3855 -0
- streamlit/static/static/js/index.Do6eY8sf.js +1 -0
- streamlit/static/static/js/index.Dz3lP2P-.js +1 -0
- streamlit/static/static/js/index.Dz_UqF-s.js +1 -0
- streamlit/static/static/js/index.GkSUsPhJ.js +1 -0
- streamlit/static/static/js/index.H1U1IC_d.js +3 -0
- streamlit/static/static/js/index.g6p_4DPr.js +1 -0
- streamlit/static/static/js/index.g9x_GKss.js +1 -0
- streamlit/static/static/js/index.zo9jm08y.js +1 -0
- streamlit/static/static/js/input.DnaFglHq.js +2 -0
- streamlit/static/static/js/inputUtils.CQWz5UKz.js +1 -0
- streamlit/static/static/js/memory.Crb9x4-F.js +1 -0
- streamlit/static/static/js/mergeWith.ouAz0sK3.js +1 -0
- streamlit/static/static/js/number-overlay-editor._UaN-O48.js +9 -0
- streamlit/static/static/js/possibleConstructorReturn.CtGjGFHz.js +1 -0
- streamlit/static/static/js/sandbox.CBybYOhV.js +1 -0
- streamlit/static/static/js/sprintf.D7DtBTRn.js +1 -0
- streamlit/static/static/js/textarea.Cb_uJt5U.js +2 -0
- streamlit/static/static/js/threshold.DjX0wlsa.js +1 -0
- streamlit/static/static/js/timepicker.DKT7pfoF.js +4 -0
- streamlit/static/static/js/timer.CAwTRJ_g.js +1 -0
- streamlit/static/static/js/toConsumableArray.05Ikp13-.js +3 -0
- streamlit/static/static/js/uniqueId.D2FMWUEI.js +1 -0
- streamlit/static/static/js/useBasicWidgetState.urnZLANY.js +1 -0
- streamlit/static/static/js/useOnInputChange.BOKIIdJ1.js +1 -0
- streamlit/static/static/js/value.CgPGBV_l.js +1 -0
- streamlit/static/static/js/withFullScreenWrapper.C_N8J0Xx.js +1 -0
- streamlit/static/static/media/KaTeX_AMS-Regular.BQhdFMY1.woff2 +0 -0
- streamlit/static/static/media/KaTeX_AMS-Regular.DMm9YOAa.woff +0 -0
- streamlit/static/static/media/KaTeX_AMS-Regular.DRggAlZN.ttf +0 -0
- streamlit/static/static/media/KaTeX_Caligraphic-Bold.ATXxdsX0.ttf +0 -0
- streamlit/static/static/media/KaTeX_Caligraphic-Bold.BEiXGLvX.woff +0 -0
- streamlit/static/static/media/KaTeX_Caligraphic-Bold.Dq_IR9rO.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Caligraphic-Regular.CTRA-rTL.woff +0 -0
- streamlit/static/static/media/KaTeX_Caligraphic-Regular.Di6jR-x-.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Caligraphic-Regular.wX97UBjC.ttf +0 -0
- streamlit/static/static/media/KaTeX_Fraktur-Bold.BdnERNNW.ttf +0 -0
- streamlit/static/static/media/KaTeX_Fraktur-Bold.BsDP51OF.woff +0 -0
- streamlit/static/static/media/KaTeX_Fraktur-Bold.CL6g_b3V.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Fraktur-Regular.CB_wures.ttf +0 -0
- streamlit/static/static/media/KaTeX_Fraktur-Regular.CTYiF6lA.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Fraktur-Regular.Dxdc4cR9.woff +0 -0
- streamlit/static/static/media/KaTeX_Main-Bold.Cx986IdX.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Main-Bold.Jm3AIy58.woff +0 -0
- streamlit/static/static/media/KaTeX_Main-Bold.waoOVXN0.ttf +0 -0
- streamlit/static/static/media/KaTeX_Main-BoldItalic.DxDJ3AOS.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Main-BoldItalic.DzxPMmG6.ttf +0 -0
- streamlit/static/static/media/KaTeX_Main-BoldItalic.SpSLRI95.woff +0 -0
- streamlit/static/static/media/KaTeX_Main-Italic.3WenGoN9.ttf +0 -0
- streamlit/static/static/media/KaTeX_Main-Italic.BMLOBm91.woff +0 -0
- streamlit/static/static/media/KaTeX_Main-Italic.NWA7e6Wa.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Main-Regular.B22Nviop.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Main-Regular.Dr94JaBh.woff +0 -0
- streamlit/static/static/media/KaTeX_Main-Regular.ypZvNtVU.ttf +0 -0
- streamlit/static/static/media/KaTeX_Math-BoldItalic.B3XSjfu4.ttf +0 -0
- streamlit/static/static/media/KaTeX_Math-BoldItalic.CZnvNsCZ.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Math-BoldItalic.iY-2wyZ7.woff +0 -0
- streamlit/static/static/media/KaTeX_Math-Italic.DA0__PXp.woff +0 -0
- streamlit/static/static/media/KaTeX_Math-Italic.flOr_0UB.ttf +0 -0
- streamlit/static/static/media/KaTeX_Math-Italic.t53AETM-.woff2 +0 -0
- streamlit/static/static/media/KaTeX_SansSerif-Bold.CFMepnvq.ttf +0 -0
- streamlit/static/static/media/KaTeX_SansSerif-Bold.D1sUS0GD.woff2 +0 -0
- streamlit/static/static/media/KaTeX_SansSerif-Bold.DbIhKOiC.woff +0 -0
- streamlit/static/static/media/KaTeX_SansSerif-Italic.C3H0VqGB.woff2 +0 -0
- streamlit/static/static/media/KaTeX_SansSerif-Italic.DN2j7dab.woff +0 -0
- streamlit/static/static/media/KaTeX_SansSerif-Italic.YYjJ1zSn.ttf +0 -0
- streamlit/static/static/media/KaTeX_SansSerif-Regular.BNo7hRIc.ttf +0 -0
- streamlit/static/static/media/KaTeX_SansSerif-Regular.CS6fqUqJ.woff +0 -0
- streamlit/static/static/media/KaTeX_SansSerif-Regular.DDBCnlJ7.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Script-Regular.C5JkGWo-.ttf +0 -0
- streamlit/static/static/media/KaTeX_Script-Regular.D3wIWfF6.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Script-Regular.D5yQViql.woff +0 -0
- streamlit/static/static/media/KaTeX_Size1-Regular.C195tn64.woff +0 -0
- streamlit/static/static/media/KaTeX_Size1-Regular.Dbsnue_I.ttf +0 -0
- streamlit/static/static/media/KaTeX_Size1-Regular.mCD8mA8B.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Size2-Regular.B7gKUWhC.ttf +0 -0
- streamlit/static/static/media/KaTeX_Size2-Regular.Dy4dx90m.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Size2-Regular.oD1tc_U0.woff +0 -0
- streamlit/static/static/media/KaTeX_Size3-Regular.CTq5MqoE.woff +0 -0
- streamlit/static/static/media/KaTeX_Size3-Regular.DgpXs0kz.ttf +0 -0
- streamlit/static/static/media/KaTeX_Size4-Regular.BF-4gkZK.woff +0 -0
- streamlit/static/static/media/KaTeX_Size4-Regular.DWFBv043.ttf +0 -0
- streamlit/static/static/media/KaTeX_Size4-Regular.Dl5lxZxV.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Typewriter-Regular.C0xS9mPB.woff +0 -0
- streamlit/static/static/media/KaTeX_Typewriter-Regular.CO6r4hn1.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Typewriter-Regular.D3Ib7_Hf.ttf +0 -0
- streamlit/static/static/media/MaterialSymbols-Rounded.DcZbplWk.woff2 +0 -0
- streamlit/static/static/media/SourceCodePro-Bold.CFEfr7-q.woff2 +0 -0
- streamlit/static/static/media/SourceCodePro-BoldItalic.C-LkFXxa.woff2 +0 -0
- streamlit/static/static/media/SourceCodePro-Italic.CxFOx7N-.woff2 +0 -0
- streamlit/static/static/media/SourceCodePro-Regular.CBOlD63d.woff2 +0 -0
- streamlit/static/static/media/SourceCodePro-SemiBold.CFHwW3Wd.woff2 +0 -0
- streamlit/static/static/media/SourceCodePro-SemiBoldItalic.Cg2yRu82.woff2 +0 -0
- streamlit/static/static/media/SourceSansPro-Bold.-6c9oR8J.woff2 +0 -0
- streamlit/static/static/media/SourceSansPro-BoldItalic.DmM_grLY.woff2 +0 -0
- streamlit/static/static/media/SourceSansPro-Italic.I1ipWe7Q.woff2 +0 -0
- streamlit/static/static/media/SourceSansPro-Regular.DZLUzqI4.woff2 +0 -0
- streamlit/static/static/media/SourceSansPro-SemiBold.sKQIyTMz.woff2 +0 -0
- streamlit/static/static/media/SourceSansPro-SemiBoldItalic.C0wP0icr.woff2 +0 -0
- streamlit/static/static/media/SourceSerifPro-Bold.8TUnKj4x.woff2 +0 -0
- streamlit/static/static/media/SourceSerifPro-BoldItalic.CBVO7Ve7.woff2 +0 -0
- streamlit/static/static/media/SourceSerifPro-Italic.DkFgL2HZ.woff2 +0 -0
- streamlit/static/static/media/SourceSerifPro-Regular.CNJNET2S.woff2 +0 -0
- streamlit/static/static/media/SourceSerifPro-SemiBold.CHyh9GC5.woff2 +0 -0
- streamlit/static/static/media/SourceSerifPro-SemiBoldItalic.CBtz8sWN.woff2 +0 -0
- streamlit/static/static/media/balloon-0.Czj7AKwE.png +0 -0
- streamlit/static/static/media/balloon-1.CNvFFrND.png +0 -0
- streamlit/static/static/media/balloon-2.DTvC6B1t.png +0 -0
- streamlit/static/static/media/balloon-3.CgSk4tbL.png +0 -0
- streamlit/static/static/media/balloon-4.mbtFrzxf.png +0 -0
- streamlit/static/static/media/balloon-5.CSwkUfRA.png +0 -0
- streamlit/static/static/media/fireworks.B4d-_KUe.gif +0 -0
- streamlit/static/static/media/flake-0.DgWaVvm5.png +0 -0
- streamlit/static/static/media/flake-1.B2r5AHMK.png +0 -0
- streamlit/static/static/media/flake-2.BnWSExPC.png +0 -0
- streamlit/static/static/media/snowflake.JU2jBHL8.svg +11 -0
- streamlit/string_util.py +203 -0
- streamlit/temporary_directory.py +56 -0
- streamlit/testing/__init__.py +13 -0
- streamlit/testing/v1/__init__.py +17 -0
- streamlit/testing/v1/app_test.py +1050 -0
- streamlit/testing/v1/element_tree.py +2083 -0
- streamlit/testing/v1/local_script_runner.py +180 -0
- streamlit/testing/v1/util.py +53 -0
- streamlit/time_util.py +75 -0
- streamlit/type_util.py +460 -0
- streamlit/url_util.py +122 -0
- streamlit/user_info.py +519 -0
- streamlit/util.py +72 -0
- streamlit/vendor/__init__.py +0 -0
- streamlit/vendor/pympler/__init__.py +0 -0
- streamlit/vendor/pympler/asizeof.py +2869 -0
- streamlit/version.py +18 -0
- streamlit/watcher/__init__.py +28 -0
- streamlit/watcher/event_based_path_watcher.py +406 -0
- streamlit/watcher/folder_black_list.py +82 -0
- streamlit/watcher/local_sources_watcher.py +233 -0
- streamlit/watcher/path_watcher.py +185 -0
- streamlit/watcher/polling_path_watcher.py +124 -0
- streamlit/watcher/util.py +207 -0
- streamlit/web/__init__.py +13 -0
- streamlit/web/bootstrap.py +353 -0
- streamlit/web/cache_storage_manager_config.py +38 -0
- streamlit/web/cli.py +369 -0
- streamlit/web/server/__init__.py +26 -0
- streamlit/web/server/app_static_file_handler.py +93 -0
- streamlit/web/server/authlib_tornado_integration.py +60 -0
- streamlit/web/server/browser_websocket_handler.py +246 -0
- streamlit/web/server/component_request_handler.py +116 -0
- streamlit/web/server/media_file_handler.py +141 -0
- streamlit/web/server/oauth_authlib_routes.py +176 -0
- streamlit/web/server/oidc_mixin.py +108 -0
- streamlit/web/server/routes.py +295 -0
- streamlit/web/server/server.py +479 -0
- streamlit/web/server/server_util.py +161 -0
- streamlit/web/server/stats_request_handler.py +95 -0
- streamlit/web/server/upload_file_request_handler.py +137 -0
- streamlit/web/server/websocket_headers.py +56 -0
- streamlit_nightly-1.43.2.dev20250307.data/scripts/streamlit.cmd +16 -0
- streamlit_nightly-1.43.2.dev20250307.dist-info/METADATA +207 -0
- streamlit_nightly-1.43.2.dev20250307.dist-info/RECORD +563 -0
- streamlit_nightly-1.43.2.dev20250307.dist-info/WHEEL +5 -0
- streamlit_nightly-1.43.2.dev20250307.dist-info/entry_points.txt +2 -0
- streamlit_nightly-1.43.2.dev20250307.dist-info/top_level.txt +1 -0
@@ -0,0 +1,2869 @@
|
|
1
|
+
# mypy: ignore-errors
|
2
|
+
|
3
|
+
"""
|
4
|
+
This is a stripped-down of asizeof.py from the pympler module. It's vendored
|
5
|
+
because pympler is unmaintained, while having a critical vulnerability.
|
6
|
+
|
7
|
+
Differences from the original asizeof module:
|
8
|
+
- Removed code for running as __main__
|
9
|
+
- Removed `adict`
|
10
|
+
- `__all__` only includes `asizeof`
|
11
|
+
|
12
|
+
The *original* original copyright, license and disclaimer are at the end of this
|
13
|
+
file, exactly as they appeared in the pympler code. pympler itself is under the
|
14
|
+
Apache license, which appears in the project root.
|
15
|
+
|
16
|
+
The original module docstring that appears in pympler follows; note that some of
|
17
|
+
it no longer pertains here, but it's preserved to document implementation
|
18
|
+
details.
|
19
|
+
"""
|
20
|
+
|
21
|
+
"""
|
22
|
+
**Public Functions** [#unsafe]_
|
23
|
+
|
24
|
+
Function **asizesof** returns a tuple containing the (approximate)
|
25
|
+
size in bytes for each given Python object separately.
|
26
|
+
|
27
|
+
Function **asized** returns for each object an instance of class
|
28
|
+
**Asized** containing all the size information of the object and
|
29
|
+
a tuple with the referents [#refs]_.
|
30
|
+
|
31
|
+
Functions **basicsize** and **itemsize** return the *basic-*
|
32
|
+
respectively *itemsize* of the given object, both in bytes. For
|
33
|
+
objects as ``array.array``, ``numpy.array``, ``numpy.ndarray``,
|
34
|
+
etc. where the item size varies depending on the instance-specific
|
35
|
+
data type, function **itemsize** returns that item size.
|
36
|
+
|
37
|
+
Function **flatsize** returns the *flat size* of a Python object
|
38
|
+
in bytes defined as the *basic size* plus the *item size* times
|
39
|
+
the *length* of the given object.
|
40
|
+
|
41
|
+
Function **leng** returns the *length* of an object, like standard
|
42
|
+
function ``len`` but extended for several types. E.g. the **leng**
|
43
|
+
of a multi-precision int (formerly long) is the number of ``digits``
|
44
|
+
[#digit]_. The length of most *mutable* sequence objects includes
|
45
|
+
an estimate of the over-allocation and therefore, the **leng** value
|
46
|
+
may differ from the standard ``len`` result. For objects like
|
47
|
+
``array.array``, ``numpy.array``, ``numpy.ndarray``, etc. function
|
48
|
+
**leng** returns the proper number of items.
|
49
|
+
|
50
|
+
Function **refs** returns (a generator for) the referents [#refs]_
|
51
|
+
of the given object.
|
52
|
+
|
53
|
+
**Public Classes** [#unsafe]_
|
54
|
+
|
55
|
+
Class **Asizer** may be used to accumulate the results of several
|
56
|
+
**asizeof** or **asizesof** calls. After creating an **Asizer**
|
57
|
+
instance, use methods **asizeof** and **asizesof** as needed to
|
58
|
+
size any number of additional objects.
|
59
|
+
|
60
|
+
Call methods **exclude_refs** and/or **exclude_types** to exclude
|
61
|
+
references to respectively instances or types of certain objects.
|
62
|
+
|
63
|
+
Use one of the **print\\_...** methods to report the statistics.
|
64
|
+
|
65
|
+
An instance of class **Asized** is returned for each object sized
|
66
|
+
by the **asized** function or method.
|
67
|
+
|
68
|
+
**Duplicate Objects**
|
69
|
+
|
70
|
+
Any duplicate, given objects are sized only once and the size
|
71
|
+
is included in the accumulated total only once. But functions
|
72
|
+
**asizesof** and **asized** will return a size value respectively
|
73
|
+
an **Asized** instance for each given object, including duplicates.
|
74
|
+
|
75
|
+
**Definitions** [#arb]_
|
76
|
+
|
77
|
+
The *length* of an objects like ``dict``, ``list``, ``set``,
|
78
|
+
``str``, ``tuple``, etc. is defined as the number of items held
|
79
|
+
in or allocated by the object. Held items are *references* to
|
80
|
+
other objects, called the *referents*.
|
81
|
+
|
82
|
+
The *size* of an object is defined as the sum of the *flat size*
|
83
|
+
of the object plus the sizes of any referents [#refs]_. Referents
|
84
|
+
are visited recursively up to the specified detail level. However,
|
85
|
+
the size of objects referenced multiple times is included only once
|
86
|
+
in the total *size*.
|
87
|
+
|
88
|
+
The *flat size* of an object is defined as the *basic size* of the
|
89
|
+
object plus the *item size* times the number of allocated *items*,
|
90
|
+
*references* to referents. The *flat size* does include the size
|
91
|
+
for the *references* to the referents, but not the size of the
|
92
|
+
referents themselves.
|
93
|
+
|
94
|
+
The *flat size* returned by function *flatsize* equals the result
|
95
|
+
of function *asizeof* with options *code=True*, *ignored=False*,
|
96
|
+
*limit=0* and option *align* set to the same value.
|
97
|
+
|
98
|
+
The accurate *flat size* for an object is obtained from function
|
99
|
+
``sys.getsizeof()`` where available. Otherwise, the *length* and
|
100
|
+
*size* of sequence objects as ``dicts``, ``lists``, ``sets``, etc.
|
101
|
+
is based on an estimate for the number of allocated items. As a
|
102
|
+
result, the reported *length* and *size* may differ substantially
|
103
|
+
from the actual *length* and *size*.
|
104
|
+
|
105
|
+
The *basic* and *item size* are obtained from the ``__basicsize__``
|
106
|
+
respectively ``__itemsize__`` attributes of the (type of the)
|
107
|
+
object. Where necessary (e.g. sequence objects), a zero
|
108
|
+
``__itemsize__`` is replaced by the size of a corresponding C type.
|
109
|
+
|
110
|
+
The overhead for Python's garbage collector (GC) is included in
|
111
|
+
the *basic size* of (GC managed) objects as well as the space
|
112
|
+
needed for ``refcounts`` (used only in certain Python builds).
|
113
|
+
|
114
|
+
Optionally, size values can be aligned to any power-of-2 multiple.
|
115
|
+
|
116
|
+
**Size of (byte)code**
|
117
|
+
|
118
|
+
The *(byte)code size* of objects like classes, functions, methods,
|
119
|
+
modules, etc. can be included by setting option *code=True*.
|
120
|
+
|
121
|
+
Iterators are handled like sequences: iterated object(s) are sized
|
122
|
+
like *referents* [#refs]_, but only up to the specified level or
|
123
|
+
recursion *limit* (and only if function ``gc.get_referents()``
|
124
|
+
returns the referent object of iterators).
|
125
|
+
|
126
|
+
Generators are sized as *(byte)code* only, but the objects are
|
127
|
+
never generated and never sized.
|
128
|
+
|
129
|
+
**New-style Classes**
|
130
|
+
|
131
|
+
All ``class``, instance and ``type`` objects are handled uniformly
|
132
|
+
such that instance objects are distinguished from class objects.
|
133
|
+
|
134
|
+
Class and type objects are represented as ``<class .... def>``
|
135
|
+
respectively ``<type ... def>`` where the ``... def`` suffix marks
|
136
|
+
the *definition object*. Instances of classes are shown as
|
137
|
+
``<class module.name>`` without the ``... def`` suffix.
|
138
|
+
|
139
|
+
**Ignored Objects**
|
140
|
+
|
141
|
+
To avoid excessive sizes, several object types are ignored [#arb]_
|
142
|
+
by default, e.g. built-in functions, built-in types and classes
|
143
|
+
[#bi]_, function globals and module referents. However, any
|
144
|
+
instances thereof and module objects will be sized when passed as
|
145
|
+
given objects. Ignored object types are included unless option
|
146
|
+
*ignored* is set accordingly.
|
147
|
+
|
148
|
+
In addition, many ``__...__`` attributes of callable objects are
|
149
|
+
ignored [#arb]_, except crucial ones, e.g. class attributes ``__dict__``,
|
150
|
+
``__doc__``, ``__name__`` and ``__slots__``. For more details, see
|
151
|
+
the type-specific ``_..._refs()`` and ``_len_...()`` functions below.
|
152
|
+
|
153
|
+
.. rubric:: Footnotes
|
154
|
+
.. [#unsafe] The functions and classes in this module are not thread-safe.
|
155
|
+
|
156
|
+
.. [#refs] The *referents* of an object are the objects referenced *by*
|
157
|
+
that object. For example, the *referents* of a ``list`` are the
|
158
|
+
objects held in the ``list``, the *referents* of a ``dict`` are
|
159
|
+
the key and value objects in the ``dict``, etc.
|
160
|
+
|
161
|
+
.. [#arb] These definitions and other assumptions are rather arbitrary
|
162
|
+
and may need corrections or adjustments.
|
163
|
+
|
164
|
+
.. [#digit] The C ``sizeof(digit)`` in bytes can be obtained from the
|
165
|
+
``int.__itemsize__`` attribute or since Python 3.1+ also from
|
166
|
+
attribute ``sys.int_info.sizeof_digit``. Function **leng**
|
167
|
+
determines the number of ``digits`` of a multi-precision int.
|
168
|
+
|
169
|
+
.. [#bi] All ``type``s and ``class``es in modules named in private set
|
170
|
+
``_ignored_modules`` are ignored like other, standard built-ins.
|
171
|
+
"""
|
172
|
+
|
173
|
+
import sys
|
174
|
+
import types as Types
|
175
|
+
import warnings
|
176
|
+
import weakref as Weakref
|
177
|
+
from inspect import isbuiltin, isclass, iscode, isframe, isfunction, ismethod, ismodule
|
178
|
+
from math import log
|
179
|
+
from os import curdir, linesep
|
180
|
+
from struct import calcsize
|
181
|
+
|
182
|
+
__all__ = ["asizeof"]
|
183
|
+
__version__ = "22.06.30"
|
184
|
+
|
185
|
+
_NN = ""
|
186
|
+
_Not_vari = _NN # non-variable item size
|
187
|
+
|
188
|
+
# Any classes and types in modules named in set _ignored_modules
|
189
|
+
# are ignored by default, like other built-ins classes and types
|
190
|
+
_ignored_modules = {
|
191
|
+
int.__module__,
|
192
|
+
"types",
|
193
|
+
Exception.__module__, # 'weakref'
|
194
|
+
__name__,
|
195
|
+
} # inluding this very module
|
196
|
+
|
197
|
+
# Sizes of some primitive C types
|
198
|
+
# XXX len(pack(T, 0)) == Struct(T).size == calcsize(T)
|
199
|
+
_sizeof_Cbyte = calcsize("c") # sizeof(unsigned char)
|
200
|
+
_sizeof_Clong = calcsize("l") # sizeof(long)
|
201
|
+
_sizeof_Cvoidp = calcsize("P") # sizeof(void*)
|
202
|
+
|
203
|
+
# sizeof(long) != sizeof(ssize_t) on LLP64
|
204
|
+
_z_P_L = "P" if _sizeof_Clong < _sizeof_Cvoidp else "L"
|
205
|
+
|
206
|
+
|
207
|
+
def _calcsize(fmt):
|
208
|
+
"""Like struct.calcsize() but with 'z' for Py_ssize_t."""
|
209
|
+
return calcsize(fmt.replace("z", _z_P_L))
|
210
|
+
|
211
|
+
|
212
|
+
# Defaults for some basic sizes with 'z' for C Py_ssize_t
|
213
|
+
_sizeof_CPyCodeObject = _calcsize("Pz10P5i0P") # sizeof(PyCodeObject)
|
214
|
+
_sizeof_CPyFrameObject = _calcsize("Pzz13P63i0P") # sizeof(PyFrameObject)
|
215
|
+
_sizeof_CPyModuleObject = _calcsize("PzP0P") # sizeof(PyModuleObject)
|
216
|
+
|
217
|
+
# Defaults for some item sizes with 'z' for C Py_ssize_t
|
218
|
+
_sizeof_CPyDictEntry = _calcsize("z2P") # sizeof(PyDictEntry)
|
219
|
+
_sizeof_Csetentry = _calcsize("lP") # sizeof(setentry)
|
220
|
+
|
221
|
+
# Get character size for internal unicode representation in Python < 3.3
|
222
|
+
u = "\0".encode("utf-8")
|
223
|
+
_sizeof_Cunicode = len(u)
|
224
|
+
del u
|
225
|
+
|
226
|
+
try: # Size of GC header, sizeof(PyGC_Head)
|
227
|
+
import _testcapi as t
|
228
|
+
|
229
|
+
_sizeof_CPyGC_Head = t.SIZEOF_PYGC_HEAD # new in Python 2.6
|
230
|
+
except (ImportError, AttributeError): # sizeof(PyGC_Head)
|
231
|
+
# alignment should be to sizeof(long double) but there
|
232
|
+
# is no way to obtain that value, assume twice double
|
233
|
+
t = calcsize("2d") - 1
|
234
|
+
_sizeof_CPyGC_Head = (_calcsize("2Pz") + t) & ~t
|
235
|
+
|
236
|
+
# Size of refcounts (Python debug build only)
|
237
|
+
t = hasattr(sys, "gettotalrefcount")
|
238
|
+
_sizeof_Crefcounts = _calcsize("2z") if t else 0
|
239
|
+
del t
|
240
|
+
|
241
|
+
# Some flags from .../Include/object.h
|
242
|
+
_Py_TPFLAGS_HEAPTYPE = 1 << 9 # Py_TPFLAGS_HEAPTYPE
|
243
|
+
_Py_TPFLAGS_HAVE_GC = 1 << 14 # Py_TPFLAGS_HAVE_GC
|
244
|
+
|
245
|
+
_Type_type = type(type) # == type and (new-style) class type
|
246
|
+
|
247
|
+
from gc import get_objects as _getobjects
|
248
|
+
from gc import get_referents as _getreferents # containers only?
|
249
|
+
|
250
|
+
if sys.platform == "ios": # Apple iOS
|
251
|
+
_gc_getobjects = _getobjects
|
252
|
+
|
253
|
+
def _getobjects(): # PYCHOK expected
|
254
|
+
# avoid Pythonista3/Python 3+ crash
|
255
|
+
return tuple(o for o in _gc_getobjects() if not _isNULL(o))
|
256
|
+
|
257
|
+
|
258
|
+
_getsizeof = sys.getsizeof # sys.getsizeof() new in Python 2.6
|
259
|
+
|
260
|
+
|
261
|
+
# Compatibility functions for more uniform
|
262
|
+
# behavior across Python version 2.2 thu 3+
|
263
|
+
|
264
|
+
|
265
|
+
def _items(obj): # dict only
|
266
|
+
"""Return iter-/generator, preferably."""
|
267
|
+
o = getattr(obj, "iteritems", obj.items)
|
268
|
+
return o() if callable(o) else (o or ())
|
269
|
+
|
270
|
+
|
271
|
+
def _keys(obj): # dict only
|
272
|
+
"""Return iter-/generator, preferably."""
|
273
|
+
o = getattr(obj, "iterkeys", obj.keys)
|
274
|
+
return o() if callable(o) else (o or ())
|
275
|
+
|
276
|
+
|
277
|
+
def _values(obj): # dict only
|
278
|
+
"""Return iter-/generator, preferably."""
|
279
|
+
o = getattr(obj, "itervalues", obj.values)
|
280
|
+
return o() if callable(o) else (o or ())
|
281
|
+
|
282
|
+
|
283
|
+
# 'cell' is holding data used in closures
|
284
|
+
c = (lambda unused: (lambda: unused))(None)
|
285
|
+
_cell_type = type(c.__closure__[0]) # type: ignore
|
286
|
+
del c
|
287
|
+
|
288
|
+
|
289
|
+
# Private functions
|
290
|
+
|
291
|
+
|
292
|
+
def _basicsize(t, base=0, heap=False, obj=None):
|
293
|
+
"""Get non-zero basicsize of type,
|
294
|
+
including the header sizes.
|
295
|
+
"""
|
296
|
+
s = max(getattr(t, "__basicsize__", 0), base)
|
297
|
+
# include gc header size
|
298
|
+
if t != _Type_type:
|
299
|
+
h = getattr(t, "__flags__", 0) & _Py_TPFLAGS_HAVE_GC
|
300
|
+
elif heap: # type, allocated on heap
|
301
|
+
h = True
|
302
|
+
else: # None has no __flags__ attr
|
303
|
+
h = getattr(obj, "__flags__", 0) & _Py_TPFLAGS_HEAPTYPE
|
304
|
+
if h:
|
305
|
+
s += _sizeof_CPyGC_Head
|
306
|
+
# include reference counters
|
307
|
+
return s + _sizeof_Crefcounts
|
308
|
+
|
309
|
+
|
310
|
+
def _classof(obj, dflt=None):
|
311
|
+
"""Return the object's class object."""
|
312
|
+
return getattr(obj, "__class__", dflt)
|
313
|
+
|
314
|
+
|
315
|
+
def _derive_typedef(typ):
|
316
|
+
"""Return single, existing super type typedef or None."""
|
317
|
+
v = [v for v in _values(_typedefs) if _issubclass(typ, v.type)]
|
318
|
+
return v[0] if len(v) == 1 else None
|
319
|
+
|
320
|
+
|
321
|
+
def _dir2(obj, pref=_NN, excl=(), slots=None, itor=_NN):
|
322
|
+
"""Return an attribute name, object 2-tuple for certain
|
323
|
+
attributes or for the ``__slots__`` attributes of the
|
324
|
+
given object, but not both. Any iterator referent
|
325
|
+
objects are returned with the given name if the
|
326
|
+
latter is non-empty.
|
327
|
+
"""
|
328
|
+
if slots: # __slots__ attrs
|
329
|
+
if hasattr(obj, slots):
|
330
|
+
# collect all inherited __slots__ attrs
|
331
|
+
# from list, tuple, or dict __slots__,
|
332
|
+
# while removing any duplicate attrs
|
333
|
+
s = {}
|
334
|
+
for c in type(obj).mro():
|
335
|
+
n = _nameof(c)
|
336
|
+
for a in getattr(c, slots, ()):
|
337
|
+
if a.startswith("__"):
|
338
|
+
a = "_" + n + a
|
339
|
+
if hasattr(obj, a):
|
340
|
+
s.setdefault(a, getattr(obj, a))
|
341
|
+
# assume __slots__ tuple-like is holding the values
|
342
|
+
# yield slots, _Slots(s) # _keys(s) ... REMOVED,
|
343
|
+
# see _Slots.__doc__ further below
|
344
|
+
for t in _items(s):
|
345
|
+
yield t # attr name, value
|
346
|
+
elif itor: # iterator referents
|
347
|
+
for o in obj: # iter(obj)
|
348
|
+
yield itor, o
|
349
|
+
else: # regular attrs
|
350
|
+
for a in dir(obj):
|
351
|
+
if a.startswith(pref) and hasattr(obj, a) and a not in excl:
|
352
|
+
yield a, getattr(obj, a)
|
353
|
+
|
354
|
+
|
355
|
+
def _infer_dict(obj):
|
356
|
+
"""Return True for likely dict object via duck typing."""
|
357
|
+
for attrs in (("items", "keys", "values"), ("iteritems", "iterkeys", "itervalues")):
|
358
|
+
attrs += "__len__", "get", "has_key" # 'update'
|
359
|
+
if all(callable(getattr(obj, a, None)) for a in attrs):
|
360
|
+
return True
|
361
|
+
return False
|
362
|
+
|
363
|
+
|
364
|
+
def _isbuiltin2(typ):
|
365
|
+
"""Return True for built-in types as in Python 2."""
|
366
|
+
# range is no longer a built-in in Python 3+
|
367
|
+
return isbuiltin(typ) or (typ is range)
|
368
|
+
|
369
|
+
|
370
|
+
def _iscell(obj):
|
371
|
+
"""Return True if obj is a cell as used in a closure."""
|
372
|
+
return isinstance(obj, _cell_type)
|
373
|
+
|
374
|
+
|
375
|
+
def _isdictype(obj):
|
376
|
+
"""Return True for known dict objects."""
|
377
|
+
c = _classof(obj)
|
378
|
+
n = _nameof(c)
|
379
|
+
return n and n in _dict_types.get(_moduleof(c), ())
|
380
|
+
|
381
|
+
|
382
|
+
def _isframe(obj):
|
383
|
+
"""Return True for a stack frame object."""
|
384
|
+
try:
|
385
|
+
return isframe(obj)
|
386
|
+
except ReferenceError:
|
387
|
+
return False
|
388
|
+
|
389
|
+
|
390
|
+
def _isignored(typ):
|
391
|
+
"""Is this a type or class to be ignored?"""
|
392
|
+
return _moduleof(typ) in _ignored_modules
|
393
|
+
|
394
|
+
|
395
|
+
def _isnamedtuple(obj):
|
396
|
+
"""Named tuples are identified via duck typing:
|
397
|
+
<http://www.Gossamer-Threads.com/lists/python/dev/1142178>
|
398
|
+
"""
|
399
|
+
return isinstance(obj, tuple) and hasattr(obj, "_fields")
|
400
|
+
|
401
|
+
|
402
|
+
def _isNULL(obj):
|
403
|
+
"""Prevent asizeof(all=True, ...) crash.
|
404
|
+
|
405
|
+
Sizing gc.get_objects() crashes in Pythonista3 with
|
406
|
+
Python 3.5.1 on iOS due to 1-tuple (<Null>,) object,
|
407
|
+
see <http://forum.omz-software.com/user/mrjean1>.
|
408
|
+
"""
|
409
|
+
return isinstance(obj, tuple) and len(obj) == 1 and repr(obj) == "(<NULL>,)"
|
410
|
+
|
411
|
+
|
412
|
+
def _issubclass(obj, Super):
|
413
|
+
"""Safe inspect.issubclass() returning None if Super is
|
414
|
+
*object* or if obj and Super are not a class or type.
|
415
|
+
"""
|
416
|
+
if Super is not object:
|
417
|
+
try:
|
418
|
+
return issubclass(obj, Super)
|
419
|
+
except TypeError:
|
420
|
+
pass
|
421
|
+
return None
|
422
|
+
|
423
|
+
|
424
|
+
def _itemsize(t, item=0):
|
425
|
+
"""Get non-zero itemsize of type."""
|
426
|
+
# replace zero value with default
|
427
|
+
return getattr(t, "__itemsize__", 0) or item
|
428
|
+
|
429
|
+
|
430
|
+
def _kwdstr(**kwds):
|
431
|
+
"""Keyword arguments as a string."""
|
432
|
+
return ", ".join(sorted("%s=%r" % kv for kv in _items(kwds)))
|
433
|
+
|
434
|
+
|
435
|
+
def _lengstr(obj):
|
436
|
+
"""Object length as a string."""
|
437
|
+
n = leng(obj)
|
438
|
+
if n is None: # no len
|
439
|
+
r = _NN
|
440
|
+
else:
|
441
|
+
x = "!" if n > _len(obj) else _NN # extended
|
442
|
+
r = " leng %d%s" % (n, x)
|
443
|
+
return r
|
444
|
+
|
445
|
+
|
446
|
+
def _moduleof(obj, dflt=_NN):
|
447
|
+
"""Return the object's module name."""
|
448
|
+
return getattr(obj, "__module__", dflt)
|
449
|
+
|
450
|
+
|
451
|
+
def _nameof(obj, dflt=_NN):
|
452
|
+
"""Return the name of an object."""
|
453
|
+
return getattr(obj, "__name__", dflt)
|
454
|
+
|
455
|
+
|
456
|
+
def _objs_opts_x(where, objs, all=None, **opts):
|
457
|
+
"""Return the given or 'all' objects plus
|
458
|
+
the remaining options and exclude flag
|
459
|
+
"""
|
460
|
+
if objs: # given objects
|
461
|
+
t, x = objs, False
|
462
|
+
elif all in (False, None):
|
463
|
+
t, x = (), True
|
464
|
+
elif all is True: # 'all' objects
|
465
|
+
t, x = _getobjects(), True
|
466
|
+
else:
|
467
|
+
raise _OptionError(where, all=all)
|
468
|
+
return t, opts, x
|
469
|
+
|
470
|
+
|
471
|
+
def _OptionError(where, Error=ValueError, **options):
|
472
|
+
"""Format an *Error* instance for invalid *option* or *options*."""
|
473
|
+
t = _plural(len(options)), _nameof(where), _kwdstr(**options)
|
474
|
+
return Error("invalid option%s: %s(%s)" % t)
|
475
|
+
|
476
|
+
|
477
|
+
def _p100(part, total, prec=1):
|
478
|
+
"""Return percentage as string."""
|
479
|
+
t = float(total)
|
480
|
+
if t > 0:
|
481
|
+
p = part * 100.0 / t
|
482
|
+
r = "%.*f%%" % (prec, p)
|
483
|
+
else:
|
484
|
+
r = "n/a"
|
485
|
+
return r
|
486
|
+
|
487
|
+
|
488
|
+
def _plural(num):
|
489
|
+
"""Return 's' if *num* is not one."""
|
490
|
+
return "s" if num != 1 else _NN
|
491
|
+
|
492
|
+
|
493
|
+
def _power_of_2(n):
|
494
|
+
"""Find the next power of 2."""
|
495
|
+
p2 = 2 ** int(log(n, 2))
|
496
|
+
while n > p2:
|
497
|
+
p2 += p2
|
498
|
+
return p2
|
499
|
+
|
500
|
+
|
501
|
+
def _prepr(obj, clip=0):
|
502
|
+
"""Prettify and clip long repr() string."""
|
503
|
+
return _repr(obj, clip=clip).strip("<>").replace("'", _NN) # remove <''>
|
504
|
+
|
505
|
+
|
506
|
+
def _printf(fmt, *args, **print3options):
|
507
|
+
"""Formatted print to sys.stdout or given stream.
|
508
|
+
|
509
|
+
*print3options* -- some keyword arguments, like Python 3+ print.
|
510
|
+
"""
|
511
|
+
if print3options: # like Python 3+
|
512
|
+
f = print3options.get("file", None) or sys.stdout
|
513
|
+
if args:
|
514
|
+
f.write(fmt % args)
|
515
|
+
else:
|
516
|
+
f.write(fmt)
|
517
|
+
f.write(print3options.get("end", linesep))
|
518
|
+
if print3options.get("flush", False):
|
519
|
+
f.flush()
|
520
|
+
elif args:
|
521
|
+
print(fmt % args)
|
522
|
+
else:
|
523
|
+
print(fmt)
|
524
|
+
|
525
|
+
|
526
|
+
def _refs(obj, named, *attrs, **kwds):
|
527
|
+
"""Return specific attribute objects of an object."""
|
528
|
+
if named:
|
529
|
+
_N = _NamedRef
|
530
|
+
else:
|
531
|
+
|
532
|
+
def _N(unused, o):
|
533
|
+
return o
|
534
|
+
|
535
|
+
for a in attrs: # cf. inspect.getmembers()
|
536
|
+
if hasattr(obj, a):
|
537
|
+
yield _N(a, getattr(obj, a))
|
538
|
+
if kwds: # kwds are _dir2() args
|
539
|
+
for a, o in _dir2(obj, **kwds):
|
540
|
+
yield _N(a, o)
|
541
|
+
|
542
|
+
|
543
|
+
def _repr(obj, clip=80):
|
544
|
+
"""Clip long repr() string."""
|
545
|
+
try: # safe repr()
|
546
|
+
r = repr(obj).replace(linesep, "\\n")
|
547
|
+
except Exception:
|
548
|
+
r = "N/A"
|
549
|
+
if len(r) > clip > 0:
|
550
|
+
h = (clip // 2) - 2
|
551
|
+
if h > 0:
|
552
|
+
r = r[:h] + "...." + r[-h:]
|
553
|
+
return r
|
554
|
+
|
555
|
+
|
556
|
+
def _SI(size, K=1024, i="i"):
|
557
|
+
"""Return size as SI string."""
|
558
|
+
if 1 < K <= size:
|
559
|
+
f = float(size)
|
560
|
+
for si in iter("KMGPTE"):
|
561
|
+
f /= K
|
562
|
+
if f < K:
|
563
|
+
return " or %.1f %s%sB" % (f, si, i)
|
564
|
+
return _NN
|
565
|
+
|
566
|
+
|
567
|
+
def _SI2(size, **kwds):
|
568
|
+
"""Return size as regular plus SI string."""
|
569
|
+
return str(size) + _SI(size, **kwds)
|
570
|
+
|
571
|
+
|
572
|
+
# Type-specific referents functions
|
573
|
+
|
574
|
+
|
575
|
+
def _cell_refs(obj, named):
|
576
|
+
try: # handle 'empty' cells
|
577
|
+
o = obj.cell_contents
|
578
|
+
if named:
|
579
|
+
o = _NamedRef("cell_contents", o)
|
580
|
+
yield o
|
581
|
+
except (AttributeError, ValueError):
|
582
|
+
pass
|
583
|
+
|
584
|
+
|
585
|
+
def _class_refs(obj, named):
|
586
|
+
"""Return specific referents of a class object."""
|
587
|
+
return _refs(
|
588
|
+
obj,
|
589
|
+
named,
|
590
|
+
"__class__",
|
591
|
+
"__doc__",
|
592
|
+
"__mro__",
|
593
|
+
"__name__",
|
594
|
+
"__slots__",
|
595
|
+
"__weakref__",
|
596
|
+
"__dict__",
|
597
|
+
) # __dict__ last
|
598
|
+
|
599
|
+
|
600
|
+
def _co_refs(obj, named):
|
601
|
+
"""Return specific referents of a code object."""
|
602
|
+
return _refs(obj, named, pref="co_")
|
603
|
+
|
604
|
+
|
605
|
+
def _dict_refs(obj, named):
|
606
|
+
"""Return key and value objects of a dict/proxy."""
|
607
|
+
try:
|
608
|
+
if named:
|
609
|
+
for k, v in _items(obj):
|
610
|
+
s = str(k)
|
611
|
+
yield _NamedRef("[K] " + s, k)
|
612
|
+
s += ": " + _repr(v)
|
613
|
+
yield _NamedRef("[V] " + s, v)
|
614
|
+
else:
|
615
|
+
for k, v in _items(obj):
|
616
|
+
yield k
|
617
|
+
yield v
|
618
|
+
except (KeyError, ReferenceError, TypeError) as x:
|
619
|
+
warnings.warn("Iterating '%s': %r" % (_classof(obj), x))
|
620
|
+
|
621
|
+
|
622
|
+
def _enum_refs(obj, named):
|
623
|
+
"""Return specific referents of an enumerate object."""
|
624
|
+
return _refs(obj, named, "__doc__")
|
625
|
+
|
626
|
+
|
627
|
+
def _exc_refs(obj, named):
|
628
|
+
"""Return specific referents of an Exception object."""
|
629
|
+
# .message raises DeprecationWarning in Python 2.6
|
630
|
+
return _refs(
|
631
|
+
obj, named, "args", "filename", "lineno", "msg", "text"
|
632
|
+
) # , 'message', 'mixed'
|
633
|
+
|
634
|
+
|
635
|
+
def _file_refs(obj, named):
|
636
|
+
"""Return specific referents of a file object."""
|
637
|
+
return _refs(obj, named, "mode", "name")
|
638
|
+
|
639
|
+
|
640
|
+
def _frame_refs(obj, named):
|
641
|
+
"""Return specific referents of a frame object."""
|
642
|
+
return _refs(obj, named, pref="f_")
|
643
|
+
|
644
|
+
|
645
|
+
def _func_refs(obj, named):
|
646
|
+
"""Return specific referents of a function or lambda object."""
|
647
|
+
return _refs(
|
648
|
+
obj,
|
649
|
+
named,
|
650
|
+
"__doc__",
|
651
|
+
"__name__",
|
652
|
+
"__code__",
|
653
|
+
"__closure__",
|
654
|
+
pref="func_",
|
655
|
+
excl=("func_globals",),
|
656
|
+
)
|
657
|
+
|
658
|
+
|
659
|
+
def _gen_refs(obj, named):
|
660
|
+
"""Return the referent(s) of a generator (expression) object."""
|
661
|
+
# only some gi_frame attrs, but none of
|
662
|
+
# the items to keep the generator intact
|
663
|
+
f = getattr(obj, "gi_frame", None)
|
664
|
+
return _refs(f, named, "f_locals", "f_code")
|
665
|
+
|
666
|
+
|
667
|
+
def _im_refs(obj, named):
|
668
|
+
"""Return specific referents of a method object."""
|
669
|
+
return _refs(obj, named, "__doc__", "__name__", "__code__", pref="im_")
|
670
|
+
|
671
|
+
|
672
|
+
def _inst_refs(obj, named):
|
673
|
+
"""Return specific referents of a class instance."""
|
674
|
+
return _refs(obj, named, "__dict__", "__class__", slots="__slots__")
|
675
|
+
|
676
|
+
|
677
|
+
def _iter_refs(obj, named):
|
678
|
+
"""Return the referent(s) of an iterator object."""
|
679
|
+
r = _getreferents(obj) # special case
|
680
|
+
return _refs(r, named, itor=_nameof(obj) or "iteref")
|
681
|
+
|
682
|
+
|
683
|
+
def _module_refs(obj, named):
|
684
|
+
"""Return specific referents of a module object."""
|
685
|
+
n = _nameof(obj) == __name__ # i.e. this module
|
686
|
+
# ignore this very module, module is essentially a dict
|
687
|
+
return () if n else _dict_refs(obj.__dict__, named)
|
688
|
+
|
689
|
+
|
690
|
+
def _namedtuple_refs(obj, named):
|
691
|
+
"""Return specific referents of obj-as-sequence and slots but exclude dict."""
|
692
|
+
for r in _refs(obj, named, "__class__", slots="__slots__"):
|
693
|
+
yield r
|
694
|
+
for r in obj:
|
695
|
+
yield r
|
696
|
+
|
697
|
+
|
698
|
+
def _prop_refs(obj, named):
|
699
|
+
"""Return specific referents of a property object."""
|
700
|
+
return _refs(obj, named, "__doc__", pref="f")
|
701
|
+
|
702
|
+
|
703
|
+
def _seq_refs(obj, unused): # named unused for PyChecker
|
704
|
+
"""Return specific referents of a frozen/set, list, tuple and xrange object."""
|
705
|
+
return obj # XXX for r in obj: yield r
|
706
|
+
|
707
|
+
|
708
|
+
def _stat_refs(obj, named):
|
709
|
+
"""Return referents of a os.stat object."""
|
710
|
+
return _refs(obj, named, pref="st_")
|
711
|
+
|
712
|
+
|
713
|
+
def _statvfs_refs(obj, named):
|
714
|
+
"""Return referents of a os.statvfs object."""
|
715
|
+
return _refs(obj, named, pref="f_")
|
716
|
+
|
717
|
+
|
718
|
+
def _tb_refs(obj, named):
|
719
|
+
"""Return specific referents of a traceback object."""
|
720
|
+
return _refs(obj, named, pref="tb_")
|
721
|
+
|
722
|
+
|
723
|
+
def _type_refs(obj, named):
|
724
|
+
"""Return specific referents of a type object."""
|
725
|
+
return _refs(
|
726
|
+
obj,
|
727
|
+
named,
|
728
|
+
"__doc__",
|
729
|
+
"__mro__",
|
730
|
+
"__name__",
|
731
|
+
"__slots__",
|
732
|
+
"__weakref__",
|
733
|
+
"__dict__",
|
734
|
+
)
|
735
|
+
|
736
|
+
|
737
|
+
def _weak_refs(obj, unused): # unused for named
|
738
|
+
"""Return weakly referent object."""
|
739
|
+
try: # ignore 'key' of KeyedRef
|
740
|
+
return (obj(),)
|
741
|
+
except Exception: # XXX ReferenceError
|
742
|
+
return ()
|
743
|
+
|
744
|
+
|
745
|
+
_all_refs = {
|
746
|
+
None,
|
747
|
+
_cell_refs,
|
748
|
+
_class_refs,
|
749
|
+
_co_refs,
|
750
|
+
_dict_refs,
|
751
|
+
_enum_refs,
|
752
|
+
_exc_refs,
|
753
|
+
_file_refs,
|
754
|
+
_frame_refs,
|
755
|
+
_func_refs,
|
756
|
+
_gen_refs,
|
757
|
+
_im_refs,
|
758
|
+
_inst_refs,
|
759
|
+
_iter_refs,
|
760
|
+
_module_refs,
|
761
|
+
_namedtuple_refs,
|
762
|
+
_prop_refs,
|
763
|
+
_seq_refs,
|
764
|
+
_stat_refs,
|
765
|
+
_statvfs_refs,
|
766
|
+
_tb_refs,
|
767
|
+
_type_refs,
|
768
|
+
_weak_refs,
|
769
|
+
} # type: Set[Union[None, Callable], ...]
|
770
|
+
|
771
|
+
|
772
|
+
# Type-specific length functions
|
773
|
+
|
774
|
+
|
775
|
+
def _len(obj):
|
776
|
+
"""Safe len()."""
|
777
|
+
try:
|
778
|
+
return len(obj)
|
779
|
+
except TypeError: # no len() nor __len__
|
780
|
+
return 0
|
781
|
+
|
782
|
+
|
783
|
+
def _len_bytearray(obj):
|
784
|
+
"""Bytearray size."""
|
785
|
+
return obj.__alloc__()
|
786
|
+
|
787
|
+
|
788
|
+
def _len_code(obj): # see .../Lib/test/test_sys.py
|
789
|
+
"""Length of code object (stack and variables only)."""
|
790
|
+
return (
|
791
|
+
_len(obj.co_freevars)
|
792
|
+
+ obj.co_stacksize
|
793
|
+
+ _len(obj.co_cellvars)
|
794
|
+
+ obj.co_nlocals
|
795
|
+
- 1
|
796
|
+
)
|
797
|
+
|
798
|
+
|
799
|
+
def _len_dict(obj):
|
800
|
+
"""Dict length in items (estimate)."""
|
801
|
+
n = len(obj) # active items
|
802
|
+
if n < 6: # ma_smalltable ...
|
803
|
+
n = 0 # ... in basicsize
|
804
|
+
else: # at least one unused
|
805
|
+
n = _power_of_2(n + 1)
|
806
|
+
return n
|
807
|
+
|
808
|
+
|
809
|
+
def _len_frame(obj):
|
810
|
+
"""Length of a frame object."""
|
811
|
+
c = getattr(obj, "f_code", None)
|
812
|
+
return _len_code(c) if c else 0
|
813
|
+
|
814
|
+
|
815
|
+
# _sizeof_Cdigit = sys.int_info.sizeof_digit # sys.int_info in Python 3.1+
|
816
|
+
# _bitsof_Cdigit = sys.int_info.bits_per_digit # (_sizeof_Cdigit * 15) // 2
|
817
|
+
# _Typedef(int).base = int.__basicsize__ # == _getsizeof(0)
|
818
|
+
# _Typedef(int).item = int.__itemsize__ # == _sizeof_Cdigit
|
819
|
+
|
820
|
+
|
821
|
+
def _len_int(obj):
|
822
|
+
"""Length of *int* (multi-precision, formerly long) in Cdigits."""
|
823
|
+
n = _getsizeof(obj, 0) - int.__basicsize__
|
824
|
+
return (n // int.__itemsize__) if n > 0 else 0
|
825
|
+
|
826
|
+
|
827
|
+
def _len_iter(obj):
|
828
|
+
"""Length (hint) of an iterator."""
|
829
|
+
n = getattr(obj, "__length_hint__", None)
|
830
|
+
return n() if n and callable(n) else _len(obj)
|
831
|
+
|
832
|
+
|
833
|
+
def _len_list(obj):
|
834
|
+
"""Length of list (estimate)."""
|
835
|
+
n = len(obj)
|
836
|
+
# estimate over-allocation
|
837
|
+
if n > 8:
|
838
|
+
n += 6 + (n >> 3)
|
839
|
+
elif n:
|
840
|
+
n += 4
|
841
|
+
return n
|
842
|
+
|
843
|
+
|
844
|
+
def _len_module(obj):
|
845
|
+
"""Module length."""
|
846
|
+
return _len(obj.__dict__) # _len(dir(obj))
|
847
|
+
|
848
|
+
|
849
|
+
def _len_set(obj):
|
850
|
+
"""Length of frozen/set (estimate)."""
|
851
|
+
n = len(obj)
|
852
|
+
if n > 8: # assume half filled
|
853
|
+
n = _power_of_2(n + n - 2)
|
854
|
+
elif n: # at least 8
|
855
|
+
n = 8
|
856
|
+
return n
|
857
|
+
|
858
|
+
|
859
|
+
def _len_slice(obj):
|
860
|
+
"""Slice length."""
|
861
|
+
try:
|
862
|
+
return (obj.stop - obj.start + 1) // obj.step
|
863
|
+
except (AttributeError, TypeError):
|
864
|
+
return 0
|
865
|
+
|
866
|
+
|
867
|
+
# REMOVED, see _Slots.__doc__
|
868
|
+
# def _len_slots(obj):
|
869
|
+
# '''Slots length.
|
870
|
+
# '''
|
871
|
+
# return len(obj) - 1
|
872
|
+
|
873
|
+
|
874
|
+
def _len_struct(obj):
|
875
|
+
"""Struct length in bytes."""
|
876
|
+
try:
|
877
|
+
return obj.size
|
878
|
+
except AttributeError:
|
879
|
+
return 0
|
880
|
+
|
881
|
+
|
882
|
+
def _len_unicode(obj):
|
883
|
+
"""Unicode size."""
|
884
|
+
return len(obj) + 1
|
885
|
+
|
886
|
+
|
887
|
+
_all_lens = {
|
888
|
+
None,
|
889
|
+
_len,
|
890
|
+
_len_bytearray,
|
891
|
+
_len_code,
|
892
|
+
_len_dict,
|
893
|
+
_len_frame,
|
894
|
+
_len_int,
|
895
|
+
_len_iter,
|
896
|
+
_len_list,
|
897
|
+
_len_module,
|
898
|
+
_len_set,
|
899
|
+
_len_slice,
|
900
|
+
_len_struct,
|
901
|
+
_len_unicode,
|
902
|
+
} # type: Set[Union[None, Callable], ...]
|
903
|
+
|
904
|
+
|
905
|
+
# More private functions and classes
|
906
|
+
|
907
|
+
# _old_style = '*' # marker, OBSOLETE
|
908
|
+
# _new_style = _NN # no marker
|
909
|
+
|
910
|
+
|
911
|
+
class _Claskey(object):
|
912
|
+
"""Wrapper for class objects."""
|
913
|
+
|
914
|
+
__slots__ = ("_obj",) # '_sty'
|
915
|
+
|
916
|
+
def __init__(self, obj):
|
917
|
+
self._obj = obj # XXX Weakref.ref(obj)
|
918
|
+
|
919
|
+
# self._sty = _new_style
|
920
|
+
|
921
|
+
def __str__(self):
|
922
|
+
r = str(self._obj)
|
923
|
+
return (r[:-1] + " def>") if r.endswith(">") else (r + " def")
|
924
|
+
|
925
|
+
__repr__ = __str__
|
926
|
+
|
927
|
+
|
928
|
+
# For most objects, the object type is used as the key in the
|
929
|
+
# _typedefs dict further below, except class and type objects
|
930
|
+
# instances. Those are wrapped with separate _Claskey or
|
931
|
+
# _Instkey instances to be able (1) to distinguish class (and
|
932
|
+
# type) instances from class (and type) definitions and (2)
|
933
|
+
# to provide similar results for repr() and str() of classes
|
934
|
+
# and instances.
|
935
|
+
|
936
|
+
_claskeys = {} # type: Dict[int, _Claskey]
|
937
|
+
_NoneNone = None, None # not a class
|
938
|
+
|
939
|
+
|
940
|
+
def _claskey(obj):
|
941
|
+
"""Wrap a class object."""
|
942
|
+
i = id(obj)
|
943
|
+
try:
|
944
|
+
k = _claskeys[i]
|
945
|
+
except KeyError:
|
946
|
+
_claskeys[i] = k = _Claskey(obj)
|
947
|
+
return k
|
948
|
+
|
949
|
+
|
950
|
+
def _key2tuple(obj): # PYCHOK expected
|
951
|
+
"""Return class and instance keys for a class."""
|
952
|
+
t = type(obj) is _Type_type # isclass(obj):
|
953
|
+
return (_claskey(obj), obj) if t else _NoneNone
|
954
|
+
|
955
|
+
|
956
|
+
def _objkey(obj): # PYCHOK expected
|
957
|
+
"""Return the key for any object."""
|
958
|
+
k = type(obj)
|
959
|
+
if k is _Type_type: # isclass(obj):
|
960
|
+
k = _claskey(obj)
|
961
|
+
return k
|
962
|
+
|
963
|
+
|
964
|
+
class _NamedRef(object):
|
965
|
+
"""Store referred object along
|
966
|
+
with the name of the referent.
|
967
|
+
"""
|
968
|
+
|
969
|
+
__slots__ = ("name", "ref")
|
970
|
+
|
971
|
+
def __init__(self, name, ref):
|
972
|
+
self.name = name
|
973
|
+
self.ref = ref
|
974
|
+
|
975
|
+
|
976
|
+
# class _Slots(tuple):
|
977
|
+
# '''Wrapper class for __slots__ attribute at class definition.
|
978
|
+
# The instance-specific __slots__ attributes are stored in
|
979
|
+
# a "tuple-like" space inside the instance, see Luciano
|
980
|
+
# Ramalho, "Fluent Python", page 274+, O'Reilly, 2016 or
|
981
|
+
# at <http://Books.Google.com/books>, then search for
|
982
|
+
# "Fluent Python" "Space Savings with the __slots__".
|
983
|
+
# '''
|
984
|
+
# pass
|
985
|
+
|
986
|
+
|
987
|
+
# all kinds of _Typedefs
|
988
|
+
i = sys.intern # Python 3+
|
989
|
+
t = (_kind_static, _kind_dynamic, _kind_derived, _kind_ignored, _kind_inferred) = (
|
990
|
+
i("static"),
|
991
|
+
i("dynamic"),
|
992
|
+
i("derived"),
|
993
|
+
i("ignored"),
|
994
|
+
i("inferred"),
|
995
|
+
)
|
996
|
+
_all_kinds = set(t)
|
997
|
+
del i, t
|
998
|
+
|
999
|
+
|
1000
|
+
class _Typedef(object):
|
1001
|
+
"""Type definition class."""
|
1002
|
+
|
1003
|
+
base = 0 # basic size in bytes
|
1004
|
+
both = None # both data and code if True, code only if False
|
1005
|
+
item = 0 # item size in bytes
|
1006
|
+
kind = None # _kind_... value
|
1007
|
+
leng = None # _len_...() function or None
|
1008
|
+
refs = None # _..._refs() function or None
|
1009
|
+
type = None # original type
|
1010
|
+
vari = None # item size attr name or _Not_vari
|
1011
|
+
xtyp = None # if True, not _getsizeof'd
|
1012
|
+
|
1013
|
+
def __init__(self, **kwds):
|
1014
|
+
self.reset(**kwds)
|
1015
|
+
|
1016
|
+
def __lt__(self, unused): # for Python 3+
|
1017
|
+
return True
|
1018
|
+
|
1019
|
+
def __repr__(self):
|
1020
|
+
return repr(self.args())
|
1021
|
+
|
1022
|
+
def __str__(self):
|
1023
|
+
t = [str(self.base), str(self.item)]
|
1024
|
+
for f in (self.leng, self.refs):
|
1025
|
+
t.append(_nameof(f) or "n/a")
|
1026
|
+
if not self.both:
|
1027
|
+
t.append("(code only)")
|
1028
|
+
return ", ".join(t)
|
1029
|
+
|
1030
|
+
def args(self): # as args tuple
|
1031
|
+
"""Return all attributes as arguments tuple."""
|
1032
|
+
return (
|
1033
|
+
self.base,
|
1034
|
+
self.item,
|
1035
|
+
self.leng,
|
1036
|
+
self.refs,
|
1037
|
+
self.both,
|
1038
|
+
self.kind,
|
1039
|
+
self.type,
|
1040
|
+
self.xtyp,
|
1041
|
+
)
|
1042
|
+
|
1043
|
+
def dup(self, other=None, **kwds):
|
1044
|
+
"""Duplicate attributes of dict or other typedef."""
|
1045
|
+
t = other or _dict_typedef
|
1046
|
+
d = t.kwds()
|
1047
|
+
d.update(kwds)
|
1048
|
+
self.reset(**d)
|
1049
|
+
|
1050
|
+
def flat(self, obj, mask=0):
|
1051
|
+
"""Return the aligned flat size."""
|
1052
|
+
s = self.base
|
1053
|
+
if self.leng and self.item > 0: # include items
|
1054
|
+
s += self.leng(obj) * self.item
|
1055
|
+
# workaround sys.getsizeof bug for _array types
|
1056
|
+
# (in some Python versions) and for other types
|
1057
|
+
# with variable .itemsize like numpy.arrays, etc.
|
1058
|
+
if not self.xtyp:
|
1059
|
+
s = _getsizeof(obj, s)
|
1060
|
+
if mask: # alignment mask
|
1061
|
+
s = (s + mask) & ~mask
|
1062
|
+
# if (mask + 1) & mask:
|
1063
|
+
# raise _OptionError(self.flat, mask=mask)
|
1064
|
+
return s
|
1065
|
+
|
1066
|
+
def format(self):
|
1067
|
+
"""Return format dict."""
|
1068
|
+
a = _nameof(self.leng)
|
1069
|
+
return dict(
|
1070
|
+
leng=((" (%s)" % (a,)) if a else _NN),
|
1071
|
+
item="var" if self.vari else self.item,
|
1072
|
+
code=_NN if self.both else " (code only)",
|
1073
|
+
base=self.base,
|
1074
|
+
kind=self.kind,
|
1075
|
+
)
|
1076
|
+
|
1077
|
+
def kwds(self):
|
1078
|
+
"""Return all attributes as keywords dict."""
|
1079
|
+
return dict(
|
1080
|
+
base=self.base,
|
1081
|
+
both=self.both,
|
1082
|
+
item=self.item,
|
1083
|
+
kind=self.kind,
|
1084
|
+
leng=self.leng,
|
1085
|
+
refs=self.refs,
|
1086
|
+
type=self.type,
|
1087
|
+
vari=self.vari,
|
1088
|
+
xtyp=self.xtyp,
|
1089
|
+
)
|
1090
|
+
|
1091
|
+
def reset(
|
1092
|
+
self,
|
1093
|
+
base=0,
|
1094
|
+
item=0,
|
1095
|
+
leng=None,
|
1096
|
+
refs=None,
|
1097
|
+
both=True,
|
1098
|
+
kind=None,
|
1099
|
+
type=None,
|
1100
|
+
vari=_Not_vari,
|
1101
|
+
xtyp=False,
|
1102
|
+
**extra,
|
1103
|
+
):
|
1104
|
+
"""Reset all specified typedef attributes."""
|
1105
|
+
v = vari or _Not_vari
|
1106
|
+
if v != str(v): # attr name
|
1107
|
+
e = dict(vari=v)
|
1108
|
+
elif base < 0:
|
1109
|
+
e = dict(base=base)
|
1110
|
+
elif both not in (False, True):
|
1111
|
+
e = dict(both=both)
|
1112
|
+
elif item < 0:
|
1113
|
+
e = dict(item=item)
|
1114
|
+
elif kind not in _all_kinds:
|
1115
|
+
e = dict(kind=kind)
|
1116
|
+
elif leng not in _all_lens: # XXX or not callable(leng)
|
1117
|
+
e = dict(leng=leng)
|
1118
|
+
elif refs not in _all_refs: # XXX or not callable(refs)
|
1119
|
+
e = dict(refs=refs)
|
1120
|
+
elif xtyp not in (False, True):
|
1121
|
+
e = dict(xtyp=xtyp)
|
1122
|
+
elif extra:
|
1123
|
+
e = {}
|
1124
|
+
else:
|
1125
|
+
self.base = base
|
1126
|
+
self.both = both
|
1127
|
+
self.item = item
|
1128
|
+
self.kind = kind
|
1129
|
+
self.leng = leng
|
1130
|
+
self.refs = refs
|
1131
|
+
self.type = type # unchecked, as-is
|
1132
|
+
self.vari = v
|
1133
|
+
self.xtyp = xtyp
|
1134
|
+
return
|
1135
|
+
e.update(extra)
|
1136
|
+
raise _OptionError(self.reset, **e)
|
1137
|
+
|
1138
|
+
def save(self, t, base=0, heap=False):
|
1139
|
+
"""Save this typedef plus its class typedef."""
|
1140
|
+
c, k = _key2tuple(t)
|
1141
|
+
if k and k not in _typedefs: # instance key
|
1142
|
+
_typedefs[k] = self
|
1143
|
+
if c and c not in _typedefs: # class key
|
1144
|
+
b = _basicsize(type(t), base=base, heap=heap)
|
1145
|
+
k = _kind_ignored if _isignored(t) else self.kind
|
1146
|
+
_typedefs[c] = _Typedef(
|
1147
|
+
base=b, both=False, kind=k, type=t, refs=_type_refs
|
1148
|
+
)
|
1149
|
+
elif t not in _typedefs:
|
1150
|
+
if not _isbuiltin2(t): # array, range, xrange in Python 2.x
|
1151
|
+
s = " ".join((self.vari, _moduleof(t), _nameof(t)))
|
1152
|
+
s = "%r %s %s" % ((c, k), self.both, s.strip())
|
1153
|
+
raise KeyError("typedef %r bad: %s" % (self, s))
|
1154
|
+
|
1155
|
+
_typedefs[t] = _Typedef(
|
1156
|
+
base=_basicsize(t, base=base), both=False, kind=_kind_ignored, type=t
|
1157
|
+
)
|
1158
|
+
|
1159
|
+
def set(self, safe_len=False, **kwds):
|
1160
|
+
"""Set one or more attributes."""
|
1161
|
+
if kwds: # double check
|
1162
|
+
d = self.kwds()
|
1163
|
+
d.update(kwds)
|
1164
|
+
self.reset(**d)
|
1165
|
+
if safe_len and self.item:
|
1166
|
+
self.leng = _len
|
1167
|
+
|
1168
|
+
|
1169
|
+
_typedefs = {} # type: Dict[type, _Typedef]
|
1170
|
+
|
1171
|
+
|
1172
|
+
def _typedef_both(
|
1173
|
+
t,
|
1174
|
+
base=0,
|
1175
|
+
item=0,
|
1176
|
+
leng=None,
|
1177
|
+
refs=None,
|
1178
|
+
kind=_kind_static,
|
1179
|
+
heap=False,
|
1180
|
+
vari=_Not_vari,
|
1181
|
+
):
|
1182
|
+
"""Add new typedef for both data and code."""
|
1183
|
+
v = _Typedef(
|
1184
|
+
base=_basicsize(t, base=base),
|
1185
|
+
item=_itemsize(t, item),
|
1186
|
+
refs=refs,
|
1187
|
+
leng=leng,
|
1188
|
+
both=True,
|
1189
|
+
kind=kind,
|
1190
|
+
type=t,
|
1191
|
+
vari=vari,
|
1192
|
+
)
|
1193
|
+
v.save(t, base=base, heap=heap)
|
1194
|
+
return v # for _dict_typedef
|
1195
|
+
|
1196
|
+
|
1197
|
+
def _typedef_code(t, base=0, refs=None, kind=_kind_static, heap=False):
|
1198
|
+
"""Add new typedef for code only."""
|
1199
|
+
v = _Typedef(
|
1200
|
+
base=_basicsize(t, base=base), refs=refs, both=False, kind=kind, type=t
|
1201
|
+
)
|
1202
|
+
v.save(t, base=base, heap=heap)
|
1203
|
+
return v # for _dict_typedef
|
1204
|
+
|
1205
|
+
|
1206
|
+
# Static typedefs for data and code types
|
1207
|
+
_typedef_both(complex)
|
1208
|
+
_typedef_both(float)
|
1209
|
+
_typedef_both(int, leng=_len_int) # see _len_int
|
1210
|
+
_typedef_both(
|
1211
|
+
list, refs=_seq_refs, leng=_len_list, item=_sizeof_Cvoidp
|
1212
|
+
) # sizeof(PyObject*)
|
1213
|
+
_typedef_both(
|
1214
|
+
tuple, refs=_seq_refs, leng=_len, item=_sizeof_Cvoidp
|
1215
|
+
) # sizeof(PyObject*)
|
1216
|
+
_typedef_both(property, refs=_prop_refs)
|
1217
|
+
_typedef_both(type(Ellipsis))
|
1218
|
+
_typedef_both(type(None))
|
1219
|
+
|
1220
|
+
# _Slots are "tuple-like", REMOVED see _Slots.__doc__
|
1221
|
+
# _typedef_both(_Slots, item=_sizeof_Cvoidp,
|
1222
|
+
# leng=_len_slots, # length less one
|
1223
|
+
# refs=None, # but no referents
|
1224
|
+
# heap=True) # plus head
|
1225
|
+
|
1226
|
+
# dict, dictproxy, dict_proxy and other dict-like types
|
1227
|
+
_dict_typedef = _typedef_both(
|
1228
|
+
dict, item=_sizeof_CPyDictEntry, leng=_len_dict, refs=_dict_refs
|
1229
|
+
)
|
1230
|
+
# XXX any class __dict__ is <type dict_proxy> in Python 3+?
|
1231
|
+
_typedef_both(
|
1232
|
+
type(_Typedef.__dict__), item=_sizeof_CPyDictEntry, leng=_len_dict, refs=_dict_refs
|
1233
|
+
)
|
1234
|
+
# other dict-like classes and types may be derived or inferred,
|
1235
|
+
# provided the module and class name is listed here (see functions
|
1236
|
+
# _isdictype and _infer_dict for further details)
|
1237
|
+
_dict_types = dict(
|
1238
|
+
UserDict=("IterableUserDict", "UserDict"),
|
1239
|
+
weakref=("WeakKeyDictionary", "WeakValueDictionary"),
|
1240
|
+
)
|
1241
|
+
try: # <type module> is essentially a dict
|
1242
|
+
_typedef_both(
|
1243
|
+
Types.ModuleType,
|
1244
|
+
base=_dict_typedef.base,
|
1245
|
+
item=_dict_typedef.item + _sizeof_CPyModuleObject,
|
1246
|
+
leng=_len_module,
|
1247
|
+
refs=_module_refs,
|
1248
|
+
)
|
1249
|
+
except AttributeError: # missing
|
1250
|
+
pass
|
1251
|
+
|
1252
|
+
|
1253
|
+
# Newer or obsolete types
|
1254
|
+
from array import array as _array # array type
|
1255
|
+
|
1256
|
+
|
1257
|
+
def _len_array(obj):
|
1258
|
+
"""Array length (in bytes!)."""
|
1259
|
+
return len(obj) * obj.itemsize
|
1260
|
+
|
1261
|
+
|
1262
|
+
def _array_kwds(obj):
|
1263
|
+
# since item size varies by the array data type, set
|
1264
|
+
# itemsize to 1 byte and use _len_array in bytes;
|
1265
|
+
# _getsizeof(array) returns array plus base size
|
1266
|
+
b = max(56, _getsizeof(obj, 0) - _len_array(obj))
|
1267
|
+
return dict(
|
1268
|
+
base=b,
|
1269
|
+
leng=_len_array,
|
1270
|
+
item=_sizeof_Cbyte,
|
1271
|
+
vari="itemsize", # array.itemsize
|
1272
|
+
xtyp=True,
|
1273
|
+
) # never _getsizeof'd
|
1274
|
+
|
1275
|
+
|
1276
|
+
_all_lens.add(_len_array) # type: ignore
|
1277
|
+
|
1278
|
+
try: # bool has non-zero __itemsize__ in 3.0
|
1279
|
+
_typedef_both(bool)
|
1280
|
+
except NameError: # missing
|
1281
|
+
pass
|
1282
|
+
|
1283
|
+
try:
|
1284
|
+
_typedef_both(bytearray, item=_sizeof_Cbyte, leng=_len_bytearray)
|
1285
|
+
except NameError: # bytearray new in 2.6, 3.0
|
1286
|
+
pass
|
1287
|
+
try:
|
1288
|
+
if type(bytes) is not type(str): # bytes is str in 2.6, bytes new in 2.6, 3.0
|
1289
|
+
_typedef_both(bytes, item=_sizeof_Cbyte, leng=_len) # bytes new in 2.6, 3.0
|
1290
|
+
except NameError: # missing
|
1291
|
+
pass
|
1292
|
+
# try: # XXX like bytes
|
1293
|
+
# _typedef_both(str8, item=_sizeof_Cbyte, leng=_len) # str8 new in 2.6, 3.0
|
1294
|
+
# except NameError: # missing
|
1295
|
+
# pass
|
1296
|
+
|
1297
|
+
try:
|
1298
|
+
_typedef_both(enumerate, refs=_enum_refs)
|
1299
|
+
except NameError: # missing
|
1300
|
+
pass
|
1301
|
+
|
1302
|
+
try: # Exception is type in Python 3+
|
1303
|
+
_typedef_both(Exception, refs=_exc_refs)
|
1304
|
+
except Exception: # missing
|
1305
|
+
pass
|
1306
|
+
|
1307
|
+
try:
|
1308
|
+
_typedef_both(frozenset, item=_sizeof_Csetentry, leng=_len_set, refs=_seq_refs)
|
1309
|
+
except NameError: # missing
|
1310
|
+
pass
|
1311
|
+
try:
|
1312
|
+
_typedef_both(set, item=_sizeof_Csetentry, leng=_len_set, refs=_seq_refs)
|
1313
|
+
except NameError: # missing
|
1314
|
+
pass
|
1315
|
+
|
1316
|
+
try: # not callable()
|
1317
|
+
_typedef_both(Types.GetSetDescriptorType)
|
1318
|
+
except AttributeError: # missing
|
1319
|
+
pass
|
1320
|
+
|
1321
|
+
try: # not callable()
|
1322
|
+
_typedef_both(Types.MemberDescriptorType)
|
1323
|
+
except AttributeError: # missing
|
1324
|
+
pass
|
1325
|
+
|
1326
|
+
try:
|
1327
|
+
_typedef_both(type(NotImplemented)) # == Types.NotImplementedType
|
1328
|
+
except NameError: # missing
|
1329
|
+
pass
|
1330
|
+
|
1331
|
+
try: # MCCABE 19
|
1332
|
+
import numpy as _numpy # NumPy array, matrix, etc.
|
1333
|
+
|
1334
|
+
try:
|
1335
|
+
_numpy_memmap = _numpy.memmap
|
1336
|
+
except AttributeError:
|
1337
|
+
_numpy_memmap = None
|
1338
|
+
try:
|
1339
|
+
from mmap import PAGESIZE as _PAGESIZE
|
1340
|
+
|
1341
|
+
if _PAGESIZE < 1024:
|
1342
|
+
raise ImportError
|
1343
|
+
except ImportError:
|
1344
|
+
_PAGESIZE = 4096 # 4 KiB, typical
|
1345
|
+
|
1346
|
+
def _isnumpy(obj):
|
1347
|
+
"""Return True for a NumPy arange, array, matrix, memmap, ndarray, etc. instance."""
|
1348
|
+
# not every numpy obj hasattr(obj, 'base')
|
1349
|
+
if (
|
1350
|
+
hasattr(obj, "dtype")
|
1351
|
+
and hasattr(obj, "itemsize")
|
1352
|
+
and hasattr(obj, "nbytes")
|
1353
|
+
):
|
1354
|
+
try:
|
1355
|
+
return _moduleof(_classof(obj)).startswith("numpy") or _moduleof(
|
1356
|
+
type(obj)
|
1357
|
+
).startswith("numpy")
|
1358
|
+
except (AttributeError, OSError, ValueError): # on iOS/Pythonista
|
1359
|
+
pass
|
1360
|
+
return False
|
1361
|
+
|
1362
|
+
def _len_numpy(obj):
|
1363
|
+
"""NumPy array, matrix, etc. length (in bytes!)."""
|
1364
|
+
return obj.nbytes # == obj.size * obj.itemsize
|
1365
|
+
|
1366
|
+
def _len_numpy_memmap(obj):
|
1367
|
+
"""Approximate NumPy memmap in-memory size (in bytes!)."""
|
1368
|
+
nb = int(obj.nbytes * _amapped)
|
1369
|
+
# round up to multiple of virtual memory page size
|
1370
|
+
return ((nb + _PAGESIZE - 1) // _PAGESIZE) * _PAGESIZE
|
1371
|
+
|
1372
|
+
def _numpy_kwds(obj):
|
1373
|
+
t = type(obj)
|
1374
|
+
# .nbytes is included in sys.sizeof size for most numpy
|
1375
|
+
# objects except for numpy.memmap (and for the latter it
|
1376
|
+
# is the length of the file to be memory-mapped which by
|
1377
|
+
# default is the file size less the offset specified)
|
1378
|
+
if t is _numpy_memmap: # isinstance(obj, _numpy_memmap)
|
1379
|
+
b, _len_, nb = 144, _len_numpy_memmap, 0
|
1380
|
+
else: # XXX 96, 128, 144 typical?
|
1381
|
+
b, _len_, nb = 96, _len_numpy, obj.nbytes
|
1382
|
+
# since item size depends on the nympy data type, set
|
1383
|
+
# itemsize to 1 byte and use _len_numpy in bytes; note,
|
1384
|
+
# function itemsize returns the actual size in bytes,
|
1385
|
+
# function alen returns the length in number of items
|
1386
|
+
return dict(
|
1387
|
+
base=_getsizeof(obj, b) - nb,
|
1388
|
+
item=_sizeof_Cbyte, # not obj.itemsize!
|
1389
|
+
leng=_len_,
|
1390
|
+
refs=_numpy_refs,
|
1391
|
+
vari="itemsize", # numpy.itemsize
|
1392
|
+
xtyp=True,
|
1393
|
+
) # never _getsizeof'd
|
1394
|
+
|
1395
|
+
def _numpy_refs(obj, named):
|
1396
|
+
"""Return the .base object for NumPy slices, views, etc."""
|
1397
|
+
return _refs(obj, named, "base")
|
1398
|
+
|
1399
|
+
_all_lens.add(_len_numpy) # type: ignore
|
1400
|
+
_all_lens.add(_len_numpy_memmap) # type: ignore
|
1401
|
+
_all_refs.add(_numpy_refs) # type: ignore
|
1402
|
+
|
1403
|
+
except ImportError: # no NumPy
|
1404
|
+
_numpy = _numpy_kwds = None # type: ignore # see function _typedef below
|
1405
|
+
|
1406
|
+
def _isnumpy(unused): # PYCHOK expected
|
1407
|
+
"""Not applicable, no NumPy."""
|
1408
|
+
return False
|
1409
|
+
|
1410
|
+
|
1411
|
+
try:
|
1412
|
+
_typedef_both(range)
|
1413
|
+
except NameError: # missing
|
1414
|
+
pass
|
1415
|
+
|
1416
|
+
try:
|
1417
|
+
_typedef_both(reversed, refs=_enum_refs)
|
1418
|
+
except NameError: # missing
|
1419
|
+
pass
|
1420
|
+
|
1421
|
+
try:
|
1422
|
+
_typedef_both(
|
1423
|
+
slice, item=_sizeof_Cvoidp, leng=_len_slice
|
1424
|
+
) # XXX worst-case itemsize?
|
1425
|
+
except NameError: # missing
|
1426
|
+
pass
|
1427
|
+
|
1428
|
+
try:
|
1429
|
+
from os import stat
|
1430
|
+
|
1431
|
+
_typedef_both(type(stat(curdir)), refs=_stat_refs) # stat_result
|
1432
|
+
except ImportError: # missing
|
1433
|
+
pass
|
1434
|
+
|
1435
|
+
try:
|
1436
|
+
from os import statvfs
|
1437
|
+
|
1438
|
+
_typedef_both(
|
1439
|
+
type(statvfs(curdir)),
|
1440
|
+
refs=_statvfs_refs, # statvfs_result
|
1441
|
+
item=_sizeof_Cvoidp,
|
1442
|
+
leng=_len,
|
1443
|
+
)
|
1444
|
+
except ImportError: # missing
|
1445
|
+
pass
|
1446
|
+
|
1447
|
+
try:
|
1448
|
+
from struct import Struct # only in Python 2.5 and 3.0
|
1449
|
+
|
1450
|
+
_typedef_both(Struct, item=_sizeof_Cbyte, leng=_len_struct) # len in bytes
|
1451
|
+
except ImportError: # missing
|
1452
|
+
pass
|
1453
|
+
|
1454
|
+
try:
|
1455
|
+
_typedef_both(Types.TracebackType, refs=_tb_refs)
|
1456
|
+
except AttributeError: # missing
|
1457
|
+
pass
|
1458
|
+
|
1459
|
+
_typedef_both(str, leng=_len_unicode, item=_sizeof_Cunicode)
|
1460
|
+
|
1461
|
+
try: # <type 'KeyedRef'>
|
1462
|
+
_typedef_both(Weakref.KeyedRef, refs=_weak_refs, heap=True) # plus head
|
1463
|
+
except AttributeError: # missing
|
1464
|
+
pass
|
1465
|
+
|
1466
|
+
try: # <type 'weakproxy'>
|
1467
|
+
_typedef_both(Weakref.ProxyType)
|
1468
|
+
except AttributeError: # missing
|
1469
|
+
pass
|
1470
|
+
|
1471
|
+
try: # <type 'weakref'>
|
1472
|
+
_typedef_both(Weakref.ReferenceType, refs=_weak_refs)
|
1473
|
+
except AttributeError: # missing
|
1474
|
+
pass
|
1475
|
+
|
1476
|
+
# some other, callable types
|
1477
|
+
_typedef_code(object, kind=_kind_ignored)
|
1478
|
+
_typedef_code(super, kind=_kind_ignored)
|
1479
|
+
_typedef_code(_Type_type, kind=_kind_ignored)
|
1480
|
+
|
1481
|
+
try:
|
1482
|
+
_typedef_code(classmethod, refs=_im_refs)
|
1483
|
+
except NameError:
|
1484
|
+
pass
|
1485
|
+
try:
|
1486
|
+
_typedef_code(staticmethod, refs=_im_refs)
|
1487
|
+
except NameError:
|
1488
|
+
pass
|
1489
|
+
try:
|
1490
|
+
_typedef_code(Types.MethodType, refs=_im_refs)
|
1491
|
+
except NameError:
|
1492
|
+
pass
|
1493
|
+
|
1494
|
+
try: # generator (expression), no itemsize, no len(), not callable()
|
1495
|
+
_typedef_both(Types.GeneratorType, refs=_gen_refs)
|
1496
|
+
except AttributeError: # missing
|
1497
|
+
pass
|
1498
|
+
|
1499
|
+
try: # <type 'weakcallableproxy'>
|
1500
|
+
_typedef_code(Weakref.CallableProxyType, refs=_weak_refs)
|
1501
|
+
except AttributeError: # missing
|
1502
|
+
pass
|
1503
|
+
|
1504
|
+
# any type-specific iterators
|
1505
|
+
s = [_items({}), _keys({}), _values({})]
|
1506
|
+
try: # reversed list and tuples iterators
|
1507
|
+
s.extend([reversed([]), reversed(())])
|
1508
|
+
except NameError: # missing
|
1509
|
+
pass
|
1510
|
+
|
1511
|
+
try: # callable-iterator
|
1512
|
+
from re import finditer
|
1513
|
+
|
1514
|
+
s.append(finditer(_NN, _NN))
|
1515
|
+
del finditer
|
1516
|
+
except ImportError: # missing
|
1517
|
+
pass
|
1518
|
+
|
1519
|
+
for t in _values(_typedefs):
|
1520
|
+
if t.type and t.leng:
|
1521
|
+
try: # create an (empty) instance
|
1522
|
+
s.append(t.type())
|
1523
|
+
except TypeError:
|
1524
|
+
pass
|
1525
|
+
for t in s:
|
1526
|
+
try:
|
1527
|
+
i = iter(t)
|
1528
|
+
_typedef_both(type(i), leng=_len_iter, refs=_iter_refs, item=0) # no itemsize!
|
1529
|
+
except (KeyError, TypeError): # ignore non-iterables, duplicates, etc.
|
1530
|
+
pass
|
1531
|
+
del i, s, t
|
1532
|
+
|
1533
|
+
|
1534
|
+
def _typedef(obj, derive=False, frames=False, infer=False): # MCCABE 25
|
1535
|
+
"""Create a new typedef for an object."""
|
1536
|
+
t = type(obj)
|
1537
|
+
v = _Typedef(base=_basicsize(t, obj=obj), kind=_kind_dynamic, type=t)
|
1538
|
+
# _printf('new %r %r/%r %s', t, _basicsize(t), _itemsize(t), _repr(dir(obj)))
|
1539
|
+
if ismodule(obj): # handle module like dict
|
1540
|
+
v.dup(
|
1541
|
+
item=_dict_typedef.item + _sizeof_CPyModuleObject,
|
1542
|
+
leng=_len_module,
|
1543
|
+
refs=_module_refs,
|
1544
|
+
)
|
1545
|
+
elif _isframe(obj):
|
1546
|
+
v.set(
|
1547
|
+
base=_basicsize(t, base=_sizeof_CPyFrameObject, obj=obj),
|
1548
|
+
item=_itemsize(t),
|
1549
|
+
leng=_len_frame,
|
1550
|
+
refs=_frame_refs,
|
1551
|
+
)
|
1552
|
+
if not frames: # ignore frames
|
1553
|
+
v.set(kind=_kind_ignored)
|
1554
|
+
elif iscode(obj):
|
1555
|
+
v.set(
|
1556
|
+
base=_basicsize(t, base=_sizeof_CPyCodeObject, obj=obj),
|
1557
|
+
item=_sizeof_Cvoidp,
|
1558
|
+
leng=_len_code,
|
1559
|
+
refs=_co_refs,
|
1560
|
+
both=False,
|
1561
|
+
) # code only
|
1562
|
+
elif callable(obj):
|
1563
|
+
if isclass(obj): # class or type
|
1564
|
+
v.set(refs=_class_refs, both=False) # code only
|
1565
|
+
if _isignored(obj):
|
1566
|
+
v.set(kind=_kind_ignored)
|
1567
|
+
elif isbuiltin(obj): # function or method
|
1568
|
+
v.set(both=False, kind=_kind_ignored) # code only
|
1569
|
+
elif isfunction(obj):
|
1570
|
+
v.set(refs=_func_refs, both=False) # code only
|
1571
|
+
elif ismethod(obj):
|
1572
|
+
v.set(refs=_im_refs, both=False) # code only
|
1573
|
+
elif isclass(t): # callable instance, e.g. SCons,
|
1574
|
+
# handle like any other instance further below
|
1575
|
+
v.set(item=_itemsize(t), safe_len=True, refs=_inst_refs) # not code only!
|
1576
|
+
else:
|
1577
|
+
v.set(both=False) # code only
|
1578
|
+
elif _issubclass(t, dict):
|
1579
|
+
v.dup(kind=_kind_derived)
|
1580
|
+
elif _isdictype(obj) or (infer and _infer_dict(obj)):
|
1581
|
+
v.dup(kind=_kind_inferred)
|
1582
|
+
elif _iscell(obj):
|
1583
|
+
v.set(item=_itemsize(t), refs=_cell_refs)
|
1584
|
+
elif _isnamedtuple(obj):
|
1585
|
+
v.set(refs=_namedtuple_refs)
|
1586
|
+
elif _numpy and _isnumpy(obj):
|
1587
|
+
v.set(**_numpy_kwds(obj))
|
1588
|
+
elif isinstance(obj, _array):
|
1589
|
+
v.set(**_array_kwds(obj))
|
1590
|
+
elif _isignored(obj):
|
1591
|
+
v.set(kind=_kind_ignored)
|
1592
|
+
else: # assume an instance of some class
|
1593
|
+
if derive:
|
1594
|
+
p = _derive_typedef(t)
|
1595
|
+
if p: # duplicate parent
|
1596
|
+
v.dup(other=p, kind=_kind_derived)
|
1597
|
+
return v
|
1598
|
+
if _issubclass(t, Exception):
|
1599
|
+
v.set(item=_itemsize(t), safe_len=True, refs=_exc_refs, kind=_kind_derived)
|
1600
|
+
elif isinstance(obj, Exception):
|
1601
|
+
v.set(item=_itemsize(t), safe_len=True, refs=_exc_refs)
|
1602
|
+
else:
|
1603
|
+
v.set(item=_itemsize(t), safe_len=True, refs=_inst_refs)
|
1604
|
+
return v
|
1605
|
+
|
1606
|
+
|
1607
|
+
class _Prof(object):
|
1608
|
+
"""Internal type profile class."""
|
1609
|
+
|
1610
|
+
high = 0 # largest size
|
1611
|
+
number = 0 # number of (unique) objects
|
1612
|
+
objref = None # largest obj (weakref)
|
1613
|
+
total = 0 # total size
|
1614
|
+
weak = False # objref is weakref(obj)
|
1615
|
+
|
1616
|
+
def __cmp__(self, other):
|
1617
|
+
if self.total < other.total:
|
1618
|
+
return -1
|
1619
|
+
elif self.total > other.total:
|
1620
|
+
return +1
|
1621
|
+
elif self.number < other.number:
|
1622
|
+
return -1
|
1623
|
+
elif self.number > other.number:
|
1624
|
+
return +1
|
1625
|
+
return 0
|
1626
|
+
|
1627
|
+
def __lt__(self, other): # for Python 3+
|
1628
|
+
return self.__cmp__(other) < 0
|
1629
|
+
|
1630
|
+
def format(self, clip=0, grand=None):
|
1631
|
+
"""Return format dict."""
|
1632
|
+
if self.number > 1: # avg., plural
|
1633
|
+
a, p = int(self.total / self.number), "s"
|
1634
|
+
else:
|
1635
|
+
a, p = self.total, _NN
|
1636
|
+
o = self.objref
|
1637
|
+
if self.weak:
|
1638
|
+
o = o()
|
1639
|
+
t = _SI2(self.total)
|
1640
|
+
if grand:
|
1641
|
+
t += " (%s)" % _p100(self.total, grand, prec=0)
|
1642
|
+
return dict(
|
1643
|
+
avg=_SI2(a),
|
1644
|
+
high=_SI2(self.high),
|
1645
|
+
lengstr=_lengstr(o),
|
1646
|
+
obj=_repr(o, clip=clip),
|
1647
|
+
plural=p,
|
1648
|
+
total=t,
|
1649
|
+
)
|
1650
|
+
|
1651
|
+
def update(self, obj, size):
|
1652
|
+
"""Update this profile."""
|
1653
|
+
self.number += 1
|
1654
|
+
self.total += size
|
1655
|
+
if self.high < size: # largest
|
1656
|
+
self.high = size
|
1657
|
+
try: # prefer using weak ref
|
1658
|
+
self.objref, self.weak = Weakref.ref(obj), True
|
1659
|
+
except TypeError:
|
1660
|
+
self.objref, self.weak = obj, False
|
1661
|
+
|
1662
|
+
|
1663
|
+
class _Rank(object):
|
1664
|
+
"""Internal largest object class."""
|
1665
|
+
|
1666
|
+
deep = 0 # recursion depth
|
1667
|
+
id = 0 # id(obj)
|
1668
|
+
key = None # Typedef
|
1669
|
+
objref = None # obj or Weakref.ref(obj)
|
1670
|
+
pid = 0 # id(parent obj)
|
1671
|
+
size = 0 # size in bytes
|
1672
|
+
weak = False # objref is Weakref.ref
|
1673
|
+
|
1674
|
+
def __init__(self, key, obj, size, deep, pid):
|
1675
|
+
self.deep = deep
|
1676
|
+
self.id = id(obj)
|
1677
|
+
self.key = key
|
1678
|
+
try: # prefer using weak ref
|
1679
|
+
self.objref, self.weak = Weakref.ref(obj), True
|
1680
|
+
except TypeError:
|
1681
|
+
self.objref, self.weak = obj, False
|
1682
|
+
self.pid = pid
|
1683
|
+
self.size = size
|
1684
|
+
|
1685
|
+
def format(self, clip=0, id2x={}):
|
1686
|
+
"""Return this *rank* as string."""
|
1687
|
+
|
1688
|
+
def _ix(_id): # id or parent_id
|
1689
|
+
return id2x.get(_id, "?")
|
1690
|
+
|
1691
|
+
o = self.objref() if self.weak else self.objref
|
1692
|
+
d = (" (at %s)" % (self.deep,)) if self.deep > 0 else _NN
|
1693
|
+
p = (", pix %s" % (_ix(self.pid),)) if self.pid else _NN
|
1694
|
+
return "%s: %s%s, ix %s%s%s" % (
|
1695
|
+
_prepr(self.key, clip=clip),
|
1696
|
+
_repr(o, clip=clip),
|
1697
|
+
_lengstr(o),
|
1698
|
+
_ix(self.id),
|
1699
|
+
d,
|
1700
|
+
p,
|
1701
|
+
)
|
1702
|
+
|
1703
|
+
|
1704
|
+
class _Seen(dict):
|
1705
|
+
"""Internal obj visits counter."""
|
1706
|
+
|
1707
|
+
def again(self, key):
|
1708
|
+
try:
|
1709
|
+
s = self[key] + 1
|
1710
|
+
except KeyError:
|
1711
|
+
s = 1
|
1712
|
+
if s > 0:
|
1713
|
+
self[key] = s
|
1714
|
+
|
1715
|
+
|
1716
|
+
# Public classes
|
1717
|
+
|
1718
|
+
|
1719
|
+
class Asized(object):
|
1720
|
+
"""Stores the results of an **asized** object in the following
|
1721
|
+
4 attributes:
|
1722
|
+
|
1723
|
+
*size* -- total size of the object (including referents)
|
1724
|
+
|
1725
|
+
*flat* -- flat size of the object (in bytes)
|
1726
|
+
|
1727
|
+
*name* -- name or ``repr`` of the object
|
1728
|
+
|
1729
|
+
*refs* -- tuple containing an **Asized** instance for each referent
|
1730
|
+
"""
|
1731
|
+
|
1732
|
+
__slots__ = ("flat", "name", "refs", "size")
|
1733
|
+
|
1734
|
+
def __init__(self, size, flat, refs=(), name=None):
|
1735
|
+
self.size = size # total size
|
1736
|
+
self.flat = flat # flat size
|
1737
|
+
self.name = name # name, repr or None
|
1738
|
+
self.refs = tuple(refs)
|
1739
|
+
|
1740
|
+
def __str__(self):
|
1741
|
+
return "size %r, flat %r, refs[%d], name %r" % (
|
1742
|
+
self.size,
|
1743
|
+
self.flat,
|
1744
|
+
len(self.refs),
|
1745
|
+
self.name,
|
1746
|
+
)
|
1747
|
+
|
1748
|
+
def format(
|
1749
|
+
self,
|
1750
|
+
format="%(name)s size=%(size)d flat=%(flat)d",
|
1751
|
+
depth=-1,
|
1752
|
+
order_by="size",
|
1753
|
+
indent=_NN,
|
1754
|
+
):
|
1755
|
+
"""Format the size information of the object and of all
|
1756
|
+
sized referents as a string.
|
1757
|
+
|
1758
|
+
*format* -- Specifies the format per instance (with 'name',
|
1759
|
+
'size' and 'flat' as interpolation parameters)
|
1760
|
+
|
1761
|
+
*depth* -- Recursion level up to which the referents are
|
1762
|
+
printed (use -1 for unlimited)
|
1763
|
+
|
1764
|
+
*order_by* -- Control sort order of referents, valid choices
|
1765
|
+
are 'name', 'size' and 'flat'
|
1766
|
+
|
1767
|
+
*indent* -- Optional indentation (default '')
|
1768
|
+
"""
|
1769
|
+
t = indent + (format % dict(size=self.size, flat=self.flat, name=self.name))
|
1770
|
+
if depth and self.refs:
|
1771
|
+
rs = sorted(
|
1772
|
+
self.refs,
|
1773
|
+
key=lambda x: getattr(x, order_by),
|
1774
|
+
reverse=order_by in ("size", "flat"),
|
1775
|
+
)
|
1776
|
+
rs = [
|
1777
|
+
r.format(
|
1778
|
+
format=format,
|
1779
|
+
depth=depth - 1,
|
1780
|
+
order_by=order_by,
|
1781
|
+
indent=indent + " ",
|
1782
|
+
)
|
1783
|
+
for r in rs
|
1784
|
+
]
|
1785
|
+
t = "\n".join([t] + rs)
|
1786
|
+
return t
|
1787
|
+
|
1788
|
+
def get(self, name, dflt=None):
|
1789
|
+
"""Return the named referent (or *dflt* if not found)."""
|
1790
|
+
for ref in self.refs:
|
1791
|
+
if name == ref.name:
|
1792
|
+
return ref
|
1793
|
+
return dflt
|
1794
|
+
|
1795
|
+
|
1796
|
+
class Asizer(object):
|
1797
|
+
"""Sizer state and options to accumulate sizes."""
|
1798
|
+
|
1799
|
+
_above_ = 1024 # rank only objs of size 1K+
|
1800
|
+
_align_ = 8 # alignment, power-of-2
|
1801
|
+
_clip_ = 80
|
1802
|
+
_code_ = False
|
1803
|
+
_cutoff_ = 0 # in percent
|
1804
|
+
_derive_ = False
|
1805
|
+
_detail_ = 0 # for Asized only
|
1806
|
+
_frames_ = False
|
1807
|
+
_infer_ = False
|
1808
|
+
_limit_ = 100
|
1809
|
+
_stats_ = 0
|
1810
|
+
|
1811
|
+
_depth = 0 # deepest recursion
|
1812
|
+
_excl_d = None # {}
|
1813
|
+
_ign_d = _kind_ignored
|
1814
|
+
_incl = _NN # or ' (incl. code)'
|
1815
|
+
_mask = 7 # see _align_
|
1816
|
+
_missed = 0 # due to errors
|
1817
|
+
_profile = False # no profiling
|
1818
|
+
_profs = None # {}
|
1819
|
+
_ranked = 0
|
1820
|
+
_ranks = [] # type: List[_Rank] # sorted by decreasing size
|
1821
|
+
_seen = None # {}
|
1822
|
+
_stream = None # I/O stream for printing
|
1823
|
+
_total = 0 # total size
|
1824
|
+
|
1825
|
+
def __init__(self, **opts):
|
1826
|
+
"""New **Asizer** accumulator.
|
1827
|
+
|
1828
|
+
See this module documentation for more details.
|
1829
|
+
See method **reset** for all available options and defaults.
|
1830
|
+
"""
|
1831
|
+
self._excl_d = {}
|
1832
|
+
self.reset(**opts)
|
1833
|
+
|
1834
|
+
def _c100(self, stats):
|
1835
|
+
"""Cutoff as percentage (for backward compatibility)"""
|
1836
|
+
s = int(stats)
|
1837
|
+
c = int((stats - s) * 100.0 + 0.5) or self.cutoff
|
1838
|
+
return s, c
|
1839
|
+
|
1840
|
+
def _clear(self):
|
1841
|
+
"""Clear state."""
|
1842
|
+
self._depth = 0 # recursion depth reached
|
1843
|
+
self._incl = _NN # or ' (incl. code)'
|
1844
|
+
self._missed = 0 # due to errors
|
1845
|
+
self._profile = False
|
1846
|
+
self._profs = {}
|
1847
|
+
self._ranked = 0
|
1848
|
+
self._ranks = []
|
1849
|
+
self._seen = _Seen()
|
1850
|
+
self._total = 0 # total size
|
1851
|
+
for k in _keys(self._excl_d):
|
1852
|
+
self._excl_d[k] = 0
|
1853
|
+
# don't size, profile or rank private, possibly large objs
|
1854
|
+
m = sys.modules[__name__]
|
1855
|
+
self.exclude_objs(
|
1856
|
+
self,
|
1857
|
+
self._excl_d,
|
1858
|
+
self._profs,
|
1859
|
+
self._ranks,
|
1860
|
+
self._seen,
|
1861
|
+
m,
|
1862
|
+
m.__dict__,
|
1863
|
+
m.__doc__,
|
1864
|
+
_typedefs,
|
1865
|
+
)
|
1866
|
+
|
1867
|
+
def _nameof(self, obj):
|
1868
|
+
"""Return the object's name."""
|
1869
|
+
return _nameof(obj, _NN) or self._repr(obj)
|
1870
|
+
|
1871
|
+
def _prepr(self, obj):
|
1872
|
+
"""Like **prepr()**."""
|
1873
|
+
return _prepr(obj, clip=self._clip_)
|
1874
|
+
|
1875
|
+
def _printf(self, fmt, *args, **print3options):
|
1876
|
+
"""Print to sys.stdout or the configured stream if any is
|
1877
|
+
specified and if the file keyword argument is not already
|
1878
|
+
set in the **print3options** for this specific call.
|
1879
|
+
"""
|
1880
|
+
if self._stream and not print3options.get("file", None):
|
1881
|
+
if args:
|
1882
|
+
fmt = fmt % args
|
1883
|
+
_printf(fmt, file=self._stream, **print3options)
|
1884
|
+
else:
|
1885
|
+
_printf(fmt, *args, **print3options)
|
1886
|
+
|
1887
|
+
def _prof(self, key):
|
1888
|
+
"""Get _Prof object."""
|
1889
|
+
p = self._profs.get(key, None)
|
1890
|
+
if not p:
|
1891
|
+
self._profs[key] = p = _Prof()
|
1892
|
+
self.exclude_objs(p) # XXX superfluous?
|
1893
|
+
return p
|
1894
|
+
|
1895
|
+
def _rank(self, key, obj, size, deep, pid):
|
1896
|
+
"""Rank 100 largest objects by size."""
|
1897
|
+
rs = self._ranks
|
1898
|
+
# bisect, see <http://GitHub.com/python/cpython/blob/master/Lib/bisect.py>
|
1899
|
+
i, j = 0, len(rs)
|
1900
|
+
while i < j:
|
1901
|
+
m = (i + j) // 2
|
1902
|
+
if size < rs[m].size:
|
1903
|
+
i = m + 1
|
1904
|
+
else:
|
1905
|
+
j = m
|
1906
|
+
if i < 100:
|
1907
|
+
r = _Rank(key, obj, size, deep, pid)
|
1908
|
+
rs.insert(i, r)
|
1909
|
+
self.exclude_objs(r) # XXX superfluous?
|
1910
|
+
while len(rs) > 100:
|
1911
|
+
rs.pop()
|
1912
|
+
# self._ranks[:] = rs[:100]
|
1913
|
+
self._ranked += 1
|
1914
|
+
|
1915
|
+
def _repr(self, obj):
|
1916
|
+
"""Like ``repr()``."""
|
1917
|
+
return _repr(obj, clip=self._clip_)
|
1918
|
+
|
1919
|
+
def _sizer(self, obj, pid, deep, sized): # MCCABE 19
|
1920
|
+
"""Size an object, recursively."""
|
1921
|
+
s, f, i = 0, 0, id(obj)
|
1922
|
+
if i not in self._seen:
|
1923
|
+
self._seen[i] = 1
|
1924
|
+
elif deep or self._seen[i]:
|
1925
|
+
# skip obj if seen before
|
1926
|
+
# or if ref of a given obj
|
1927
|
+
self._seen.again(i)
|
1928
|
+
if sized:
|
1929
|
+
s = sized(s, f, name=self._nameof(obj))
|
1930
|
+
self.exclude_objs(s)
|
1931
|
+
return s # zero
|
1932
|
+
else: # deep == seen[i] == 0
|
1933
|
+
self._seen.again(i)
|
1934
|
+
try:
|
1935
|
+
k, rs = _objkey(obj), []
|
1936
|
+
if k in self._excl_d:
|
1937
|
+
self._excl_d[k] += 1
|
1938
|
+
else:
|
1939
|
+
v = _typedefs.get(k, None)
|
1940
|
+
if not v: # new typedef
|
1941
|
+
_typedefs[k] = v = _typedef(
|
1942
|
+
obj,
|
1943
|
+
derive=self._derive_,
|
1944
|
+
frames=self._frames_,
|
1945
|
+
infer=self._infer_,
|
1946
|
+
)
|
1947
|
+
if (v.both or self._code_) and v.kind is not self._ign_d:
|
1948
|
+
s = f = v.flat(obj, self._mask) # flat size
|
1949
|
+
if self._profile:
|
1950
|
+
# profile based on *flat* size
|
1951
|
+
self._prof(k).update(obj, s)
|
1952
|
+
# recurse, but not for nested modules
|
1953
|
+
if v.refs and deep < self._limit_ and not (deep and ismodule(obj)):
|
1954
|
+
# add sizes of referents
|
1955
|
+
z, d = self._sizer, deep + 1
|
1956
|
+
if sized and deep < self._detail_:
|
1957
|
+
# use named referents
|
1958
|
+
self.exclude_objs(rs)
|
1959
|
+
for o in v.refs(obj, True):
|
1960
|
+
if isinstance(o, _NamedRef):
|
1961
|
+
r = z(o.ref, i, d, sized)
|
1962
|
+
r.name = o.name
|
1963
|
+
else:
|
1964
|
+
r = z(o, i, d, sized)
|
1965
|
+
r.name = self._nameof(o)
|
1966
|
+
rs.append(r)
|
1967
|
+
s += r.size
|
1968
|
+
else: # just size and accumulate
|
1969
|
+
for o in v.refs(obj, False):
|
1970
|
+
s += z(o, i, d, None)
|
1971
|
+
# deepest recursion reached
|
1972
|
+
if self._depth < d:
|
1973
|
+
self._depth = d
|
1974
|
+
if self._stats_ and s > self._above_ > 0:
|
1975
|
+
# rank based on *total* size
|
1976
|
+
self._rank(k, obj, s, deep, pid)
|
1977
|
+
except RuntimeError: # XXX RecursionLimitExceeded:
|
1978
|
+
self._missed += 1
|
1979
|
+
if not deep:
|
1980
|
+
self._total += s # accumulate
|
1981
|
+
if sized:
|
1982
|
+
s = sized(s, f, name=self._nameof(obj), refs=rs)
|
1983
|
+
self.exclude_objs(s)
|
1984
|
+
return s
|
1985
|
+
|
1986
|
+
def _sizes(self, objs, sized=None):
|
1987
|
+
"""Return the size or an **Asized** instance for each
|
1988
|
+
given object plus the total size. The total includes
|
1989
|
+
the size of duplicates only once.
|
1990
|
+
"""
|
1991
|
+
self.exclude_refs(*objs) # skip refs to objs
|
1992
|
+
s, t = {}, []
|
1993
|
+
self.exclude_objs(s, t)
|
1994
|
+
for o in objs:
|
1995
|
+
i = id(o)
|
1996
|
+
if i in s: # duplicate
|
1997
|
+
self._seen.again(i)
|
1998
|
+
else:
|
1999
|
+
s[i] = self._sizer(o, 0, 0, sized)
|
2000
|
+
t.append(s[i])
|
2001
|
+
return tuple(t)
|
2002
|
+
|
2003
|
+
@property
|
2004
|
+
def above(self):
|
2005
|
+
"""Get the large object size threshold (int)."""
|
2006
|
+
return self._above_
|
2007
|
+
|
2008
|
+
@property
|
2009
|
+
def align(self):
|
2010
|
+
"""Get the size alignment (int)."""
|
2011
|
+
return self._align_
|
2012
|
+
|
2013
|
+
def asized(self, *objs, **opts):
|
2014
|
+
"""Size each object and return an **Asized** instance with
|
2015
|
+
size information and referents up to the given detail
|
2016
|
+
level (and with modified options, see method **set**).
|
2017
|
+
|
2018
|
+
If only one object is given, the return value is the
|
2019
|
+
**Asized** instance for that object. The **Asized** size
|
2020
|
+
of duplicate and ignored objects will be zero.
|
2021
|
+
"""
|
2022
|
+
if opts:
|
2023
|
+
self.set(**opts)
|
2024
|
+
t = self._sizes(objs, Asized)
|
2025
|
+
return t[0] if len(t) == 1 else t
|
2026
|
+
|
2027
|
+
def asizeof(self, *objs, **opts):
|
2028
|
+
"""Return the combined size of the given objects
|
2029
|
+
(with modified options, see method **set**).
|
2030
|
+
"""
|
2031
|
+
if opts:
|
2032
|
+
self.set(**opts)
|
2033
|
+
self.exclude_refs(*objs) # skip refs to objs
|
2034
|
+
return sum(self._sizer(o, 0, 0, None) for o in objs)
|
2035
|
+
|
2036
|
+
def asizesof(self, *objs, **opts):
|
2037
|
+
"""Return the individual sizes of the given objects
|
2038
|
+
(with modified options, see method **set**).
|
2039
|
+
|
2040
|
+
The size of duplicate and ignored objects will be zero.
|
2041
|
+
"""
|
2042
|
+
if opts:
|
2043
|
+
self.set(**opts)
|
2044
|
+
return self._sizes(objs, None)
|
2045
|
+
|
2046
|
+
@property
|
2047
|
+
def clip(self):
|
2048
|
+
"""Get the clipped string length (int)."""
|
2049
|
+
return self._clip_
|
2050
|
+
|
2051
|
+
@property
|
2052
|
+
def code(self):
|
2053
|
+
"""Size (byte) code (bool)."""
|
2054
|
+
return self._code_
|
2055
|
+
|
2056
|
+
@property
|
2057
|
+
def cutoff(self):
|
2058
|
+
"""Stats cutoff (int)."""
|
2059
|
+
return self._cutoff_
|
2060
|
+
|
2061
|
+
@property
|
2062
|
+
def derive(self):
|
2063
|
+
"""Derive types (bool)."""
|
2064
|
+
return self._derive_
|
2065
|
+
|
2066
|
+
@property
|
2067
|
+
def detail(self):
|
2068
|
+
"""Get the detail level for **Asized** refs (int)."""
|
2069
|
+
return self._detail_
|
2070
|
+
|
2071
|
+
@property
|
2072
|
+
def duplicate(self):
|
2073
|
+
"""Get the number of duplicate objects seen so far (int)."""
|
2074
|
+
return sum(1 for v in _values(self._seen) if v > 1) # == len
|
2075
|
+
|
2076
|
+
def exclude_objs(self, *objs):
|
2077
|
+
"""Exclude the specified objects from sizing, profiling and ranking."""
|
2078
|
+
for o in objs:
|
2079
|
+
self._seen.setdefault(id(o), -1)
|
2080
|
+
|
2081
|
+
def exclude_refs(self, *objs):
|
2082
|
+
"""Exclude any references to the specified objects from sizing.
|
2083
|
+
|
2084
|
+
While any references to the given objects are excluded, the
|
2085
|
+
objects will be sized if specified as positional arguments
|
2086
|
+
in subsequent calls to methods **asizeof** and **asizesof**.
|
2087
|
+
"""
|
2088
|
+
for o in objs:
|
2089
|
+
self._seen.setdefault(id(o), 0)
|
2090
|
+
|
2091
|
+
def exclude_types(self, *objs):
|
2092
|
+
"""Exclude the specified object instances and types from sizing.
|
2093
|
+
|
2094
|
+
All instances and types of the given objects are excluded,
|
2095
|
+
even objects specified as positional arguments in subsequent
|
2096
|
+
calls to methods **asizeof** and **asizesof**.
|
2097
|
+
"""
|
2098
|
+
for o in objs:
|
2099
|
+
for t in _key2tuple(o):
|
2100
|
+
if t and t not in self._excl_d:
|
2101
|
+
self._excl_d[t] = 0
|
2102
|
+
|
2103
|
+
@property
|
2104
|
+
def excluded(self):
|
2105
|
+
"""Get the types being excluded (tuple)."""
|
2106
|
+
return tuple(_keys(self._excl_d))
|
2107
|
+
|
2108
|
+
@property
|
2109
|
+
def frames(self):
|
2110
|
+
"""Ignore stack frames (bool)."""
|
2111
|
+
return self._frames_
|
2112
|
+
|
2113
|
+
@property
|
2114
|
+
def ignored(self):
|
2115
|
+
"""Ignore certain types (bool)."""
|
2116
|
+
return True if self._ign_d else False
|
2117
|
+
|
2118
|
+
@property
|
2119
|
+
def infer(self):
|
2120
|
+
"""Infer types (bool)."""
|
2121
|
+
return self._infer_
|
2122
|
+
|
2123
|
+
@property
|
2124
|
+
def limit(self):
|
2125
|
+
"""Get the recursion limit (int)."""
|
2126
|
+
return self._limit_
|
2127
|
+
|
2128
|
+
@property
|
2129
|
+
def missed(self):
|
2130
|
+
"""Get the number of objects missed due to errors (int)."""
|
2131
|
+
return self._missed
|
2132
|
+
|
2133
|
+
def print_largest(self, w=0, cutoff=0, **print3options):
|
2134
|
+
"""Print the largest objects.
|
2135
|
+
|
2136
|
+
The available options and defaults are:
|
2137
|
+
|
2138
|
+
*w=0* -- indentation for each line
|
2139
|
+
|
2140
|
+
*cutoff=100* -- number of largest objects to print
|
2141
|
+
|
2142
|
+
*print3options* -- some keyword arguments, like Python 3+ print
|
2143
|
+
"""
|
2144
|
+
c = int(cutoff) if cutoff else self._cutoff_
|
2145
|
+
n = min(len(self._ranks), max(c, 0))
|
2146
|
+
s = self._above_
|
2147
|
+
if n > 0 and s > 0:
|
2148
|
+
self._printf(
|
2149
|
+
"%s%*d largest object%s (of %d over %d bytes%s)",
|
2150
|
+
linesep,
|
2151
|
+
w,
|
2152
|
+
n,
|
2153
|
+
_plural(n),
|
2154
|
+
self._ranked,
|
2155
|
+
s,
|
2156
|
+
_SI(s),
|
2157
|
+
**print3options,
|
2158
|
+
)
|
2159
|
+
id2x = dict((r.id, i) for i, r in enumerate(self._ranks))
|
2160
|
+
for r in self._ranks[:n]:
|
2161
|
+
s, t = r.size, r.format(self._clip_, id2x)
|
2162
|
+
self._printf("%*d bytes%s: %s", w, s, _SI(s), t, **print3options)
|
2163
|
+
|
2164
|
+
def print_profiles(self, w=0, cutoff=0, **print3options):
|
2165
|
+
"""Print the profiles above *cutoff* percentage.
|
2166
|
+
|
2167
|
+
The available options and defaults are:
|
2168
|
+
|
2169
|
+
*w=0* -- indentation for each line
|
2170
|
+
|
2171
|
+
*cutoff=0* -- minimum percentage printed
|
2172
|
+
|
2173
|
+
*print3options* -- some keyword arguments, like Python 3+ print
|
2174
|
+
"""
|
2175
|
+
# get the profiles with non-zero size or count
|
2176
|
+
t = [(v, k) for k, v in _items(self._profs) if v.total > 0 or v.number > 1]
|
2177
|
+
if (len(self._profs) - len(t)) < 9: # just show all
|
2178
|
+
t = [(v, k) for k, v in _items(self._profs)]
|
2179
|
+
if t:
|
2180
|
+
s = _NN
|
2181
|
+
if self._total:
|
2182
|
+
s = " (% of grand total)"
|
2183
|
+
c = int(cutoff) if cutoff else self._cutoff_
|
2184
|
+
C = int(c * 0.01 * self._total)
|
2185
|
+
else:
|
2186
|
+
C = c = 0
|
2187
|
+
self._printf(
|
2188
|
+
"%s%*d profile%s: total%s, average, and largest flat size%s: largest object",
|
2189
|
+
linesep,
|
2190
|
+
w,
|
2191
|
+
len(t),
|
2192
|
+
_plural(len(t)),
|
2193
|
+
s,
|
2194
|
+
self._incl,
|
2195
|
+
**print3options,
|
2196
|
+
)
|
2197
|
+
r = len(t)
|
2198
|
+
t = [
|
2199
|
+
(v, self._prepr(k)) for v, k in t
|
2200
|
+
] # replace types with str for Python 3.11+
|
2201
|
+
for v, k in sorted(t, reverse=True):
|
2202
|
+
s = (
|
2203
|
+
"object%(plural)s: %(total)s, %(avg)s, %(high)s: %(obj)s%(lengstr)s"
|
2204
|
+
% v.format(self._clip_, self._total)
|
2205
|
+
)
|
2206
|
+
self._printf("%*d %s %s", w, v.number, k, s, **print3options)
|
2207
|
+
r -= 1
|
2208
|
+
if r > 1 and v.total < C:
|
2209
|
+
self._printf("%+*d profiles below cutoff (%.0f%%)", w, r, c)
|
2210
|
+
break
|
2211
|
+
z = len(self._profs) - len(t)
|
2212
|
+
if z > 0:
|
2213
|
+
self._printf(
|
2214
|
+
"%+*d %r object%s", w, z, "zero", _plural(z), **print3options
|
2215
|
+
)
|
2216
|
+
|
2217
|
+
def print_stats(
|
2218
|
+
self, objs=(), opts={}, sized=(), sizes=(), stats=3, **print3options
|
2219
|
+
):
|
2220
|
+
"""Prints the statistics.
|
2221
|
+
|
2222
|
+
The available options and defaults are:
|
2223
|
+
|
2224
|
+
*w=0* -- indentation for each line
|
2225
|
+
|
2226
|
+
*objs=()* -- optional, list of objects
|
2227
|
+
|
2228
|
+
*opts={}* -- optional, dict of options used
|
2229
|
+
|
2230
|
+
*sized=()* -- optional, tuple of **Asized** instances returned
|
2231
|
+
|
2232
|
+
*sizes=()* -- optional, tuple of sizes returned
|
2233
|
+
|
2234
|
+
*stats=3* -- print stats, see function **asizeof**
|
2235
|
+
|
2236
|
+
*print3options* -- some keyword arguments, like Python 3+ print
|
2237
|
+
"""
|
2238
|
+
s = min(opts.get("stats", stats) or 0, self.stats)
|
2239
|
+
if s > 0: # print stats
|
2240
|
+
w = len(str(self.missed + self.seen + self.total)) + 1
|
2241
|
+
t = c = _NN
|
2242
|
+
o = _kwdstr(**opts)
|
2243
|
+
if o and objs:
|
2244
|
+
c = ", "
|
2245
|
+
# print header line(s)
|
2246
|
+
if sized and objs:
|
2247
|
+
n = len(objs)
|
2248
|
+
if n > 1:
|
2249
|
+
self._printf(
|
2250
|
+
"%sasized(...%s%s) ...", linesep, c, o, **print3options
|
2251
|
+
)
|
2252
|
+
for i in range(n): # no enumerate in Python 2.2.3
|
2253
|
+
self._printf("%*d: %s", w - 1, i, sized[i], **print3options)
|
2254
|
+
else:
|
2255
|
+
self._printf("%sasized(%s): %s", linesep, o, sized, **print3options)
|
2256
|
+
elif sizes and objs:
|
2257
|
+
self._printf("%sasizesof(...%s%s) ...", linesep, c, o, **print3options)
|
2258
|
+
for z, o in zip(sizes, objs):
|
2259
|
+
self._printf(
|
2260
|
+
"%*d bytes%s%s: %s",
|
2261
|
+
w,
|
2262
|
+
z,
|
2263
|
+
_SI(z),
|
2264
|
+
self._incl,
|
2265
|
+
self._repr(o),
|
2266
|
+
**print3options,
|
2267
|
+
)
|
2268
|
+
else:
|
2269
|
+
if objs:
|
2270
|
+
t = self._repr(objs)
|
2271
|
+
self._printf("%sasizeof(%s%s%s) ...", linesep, t, c, o, **print3options)
|
2272
|
+
# print summary
|
2273
|
+
self.print_summary(w=w, objs=objs, **print3options)
|
2274
|
+
# for backward compatibility, cutoff from fractional stats
|
2275
|
+
s, c = self._c100(s)
|
2276
|
+
self.print_largest(w=w, cutoff=c if s < 2 else 10, **print3options)
|
2277
|
+
if s > 1: # print profile
|
2278
|
+
self.print_profiles(w=w, cutoff=c, **print3options)
|
2279
|
+
if s > 2: # print typedefs
|
2280
|
+
self.print_typedefs(w=w, **print3options) # PYCHOK .print_largest?
|
2281
|
+
|
2282
|
+
def print_summary(self, w=0, objs=(), **print3options):
|
2283
|
+
"""Print the summary statistics.
|
2284
|
+
|
2285
|
+
The available options and defaults are:
|
2286
|
+
|
2287
|
+
*w=0* -- indentation for each line
|
2288
|
+
|
2289
|
+
*objs=()* -- optional, list of objects
|
2290
|
+
|
2291
|
+
*print3options* -- some keyword arguments, like Python 3+ print
|
2292
|
+
"""
|
2293
|
+
self._printf(
|
2294
|
+
"%*d bytes%s%s",
|
2295
|
+
w,
|
2296
|
+
self._total,
|
2297
|
+
_SI(self._total),
|
2298
|
+
self._incl,
|
2299
|
+
**print3options,
|
2300
|
+
)
|
2301
|
+
if self._mask:
|
2302
|
+
self._printf("%*d byte aligned", w, self._mask + 1, **print3options)
|
2303
|
+
self._printf("%*d byte sizeof(void*)", w, _sizeof_Cvoidp, **print3options)
|
2304
|
+
n = len(objs or ())
|
2305
|
+
self._printf("%*d object%s %s", w, n, _plural(n), "given", **print3options)
|
2306
|
+
n = self.sized
|
2307
|
+
self._printf("%*d object%s %s", w, n, _plural(n), "sized", **print3options)
|
2308
|
+
if self._excl_d:
|
2309
|
+
n = sum(_values(self._excl_d))
|
2310
|
+
self._printf(
|
2311
|
+
"%*d object%s %s", w, n, _plural(n), "excluded", **print3options
|
2312
|
+
)
|
2313
|
+
n = self.seen
|
2314
|
+
self._printf("%*d object%s %s", w, n, _plural(n), "seen", **print3options)
|
2315
|
+
n = self.ranked
|
2316
|
+
if n > 0:
|
2317
|
+
self._printf("%*d object%s %s", w, n, _plural(n), "ranked", **print3options)
|
2318
|
+
n = self.missed
|
2319
|
+
self._printf("%*d object%s %s", w, n, _plural(n), "missed", **print3options)
|
2320
|
+
n = self.duplicate
|
2321
|
+
self._printf("%*d duplicate%s", w, n, _plural(n), **print3options)
|
2322
|
+
if self._depth > 0:
|
2323
|
+
self._printf("%*d deepest recursion", w, self._depth, **print3options)
|
2324
|
+
|
2325
|
+
def print_typedefs(self, w=0, **print3options):
|
2326
|
+
"""Print the types and dict tables.
|
2327
|
+
|
2328
|
+
The available options and defaults are:
|
2329
|
+
|
2330
|
+
*w=0* -- indentation for each line
|
2331
|
+
|
2332
|
+
*print3options* -- some keyword arguments, like Python 3+ print
|
2333
|
+
"""
|
2334
|
+
for k in _all_kinds:
|
2335
|
+
# XXX Python 3+ doesn't sort type objects
|
2336
|
+
t = [
|
2337
|
+
(self._prepr(a), v)
|
2338
|
+
for a, v in _items(_typedefs)
|
2339
|
+
if v.kind == k and (v.both or self._code_)
|
2340
|
+
]
|
2341
|
+
if t:
|
2342
|
+
self._printf(
|
2343
|
+
"%s%*d %s type%s: basicsize, itemsize, _len_(), _refs()",
|
2344
|
+
linesep,
|
2345
|
+
w,
|
2346
|
+
len(t),
|
2347
|
+
k,
|
2348
|
+
_plural(len(t)),
|
2349
|
+
**print3options,
|
2350
|
+
)
|
2351
|
+
for a, v in sorted(t):
|
2352
|
+
self._printf("%*s %s: %s", w, _NN, a, v, **print3options)
|
2353
|
+
# dict and dict-like classes
|
2354
|
+
t = sum(len(v) for v in _values(_dict_types))
|
2355
|
+
if t:
|
2356
|
+
self._printf("%s%*d dict/-like classes:", linesep, w, t, **print3options)
|
2357
|
+
for m, v in _items(_dict_types):
|
2358
|
+
self._printf("%*s %s: %s", w, _NN, m, self._prepr(v), **print3options)
|
2359
|
+
|
2360
|
+
@property
|
2361
|
+
def ranked(self):
|
2362
|
+
"""Get the number objects ranked by size so far (int)."""
|
2363
|
+
return self._ranked
|
2364
|
+
|
2365
|
+
def reset(
|
2366
|
+
self,
|
2367
|
+
above=1024,
|
2368
|
+
align=8,
|
2369
|
+
clip=80,
|
2370
|
+
code=False, # PYCHOK too many args
|
2371
|
+
cutoff=10,
|
2372
|
+
derive=False,
|
2373
|
+
detail=0,
|
2374
|
+
frames=False,
|
2375
|
+
ignored=True,
|
2376
|
+
infer=False,
|
2377
|
+
limit=100,
|
2378
|
+
stats=0,
|
2379
|
+
stream=None,
|
2380
|
+
**extra,
|
2381
|
+
):
|
2382
|
+
"""Reset sizing options, state, etc. to defaults.
|
2383
|
+
|
2384
|
+
The available options and default values are:
|
2385
|
+
|
2386
|
+
*above=0* -- threshold for largest objects stats
|
2387
|
+
|
2388
|
+
*align=8* -- size alignment
|
2389
|
+
|
2390
|
+
*code=False* -- incl. (byte)code size
|
2391
|
+
|
2392
|
+
*cutoff=10* -- limit large objects or profiles stats
|
2393
|
+
|
2394
|
+
*derive=False* -- derive from super type
|
2395
|
+
|
2396
|
+
*detail=0* -- **Asized** refs level
|
2397
|
+
|
2398
|
+
*frames=False* -- ignore frame objects
|
2399
|
+
|
2400
|
+
*ignored=True* -- ignore certain types
|
2401
|
+
|
2402
|
+
*infer=False* -- try to infer types
|
2403
|
+
|
2404
|
+
*limit=100* -- recursion limit
|
2405
|
+
|
2406
|
+
*stats=0* -- print statistics, see function **asizeof**
|
2407
|
+
|
2408
|
+
*stream=None* -- output stream for printing
|
2409
|
+
|
2410
|
+
See function **asizeof** for a description of the options.
|
2411
|
+
"""
|
2412
|
+
if extra:
|
2413
|
+
raise _OptionError(self.reset, Error=KeyError, **extra)
|
2414
|
+
# options
|
2415
|
+
self._above_ = above
|
2416
|
+
self._align_ = align
|
2417
|
+
self._clip_ = clip
|
2418
|
+
self._code_ = code
|
2419
|
+
self._cutoff_ = cutoff
|
2420
|
+
self._derive_ = derive
|
2421
|
+
self._detail_ = detail # for Asized only
|
2422
|
+
self._frames_ = frames
|
2423
|
+
self._infer_ = infer
|
2424
|
+
self._limit_ = limit
|
2425
|
+
self._stats_ = stats
|
2426
|
+
self._stream = stream
|
2427
|
+
if ignored:
|
2428
|
+
self._ign_d = _kind_ignored
|
2429
|
+
else:
|
2430
|
+
self._ign_d = None
|
2431
|
+
# clear state
|
2432
|
+
self._clear()
|
2433
|
+
self.set(align=align, code=code, cutoff=cutoff, stats=stats)
|
2434
|
+
|
2435
|
+
@property
|
2436
|
+
def seen(self):
|
2437
|
+
"""Get the number objects seen so far (int)."""
|
2438
|
+
return sum(v for v in _values(self._seen) if v > 0)
|
2439
|
+
|
2440
|
+
def set(
|
2441
|
+
self,
|
2442
|
+
above=None,
|
2443
|
+
align=None,
|
2444
|
+
code=None,
|
2445
|
+
cutoff=None,
|
2446
|
+
frames=None,
|
2447
|
+
detail=None,
|
2448
|
+
limit=None,
|
2449
|
+
stats=None,
|
2450
|
+
):
|
2451
|
+
"""Set some sizing options. See also **reset**.
|
2452
|
+
|
2453
|
+
The available options are:
|
2454
|
+
|
2455
|
+
*above* -- threshold for largest objects stats
|
2456
|
+
|
2457
|
+
*align* -- size alignment
|
2458
|
+
|
2459
|
+
*code* -- incl. (byte)code size
|
2460
|
+
|
2461
|
+
*cutoff* -- limit large objects or profiles stats
|
2462
|
+
|
2463
|
+
*detail* -- **Asized** refs level
|
2464
|
+
|
2465
|
+
*frames* -- size or ignore frame objects
|
2466
|
+
|
2467
|
+
*limit* -- recursion limit
|
2468
|
+
|
2469
|
+
*stats* -- print statistics, see function **asizeof**
|
2470
|
+
|
2471
|
+
Any options not set remain unchanged from the previous setting.
|
2472
|
+
"""
|
2473
|
+
# adjust
|
2474
|
+
if above is not None:
|
2475
|
+
self._above_ = int(above)
|
2476
|
+
if align is not None:
|
2477
|
+
if align > 1:
|
2478
|
+
m = align - 1
|
2479
|
+
if m & align:
|
2480
|
+
raise _OptionError(self.set, align=align)
|
2481
|
+
else:
|
2482
|
+
m = 0
|
2483
|
+
self._align_ = align
|
2484
|
+
self._mask = m
|
2485
|
+
if code is not None:
|
2486
|
+
self._code_ = code
|
2487
|
+
if code: # incl. (byte)code
|
2488
|
+
self._incl = " (incl. code)"
|
2489
|
+
if detail is not None:
|
2490
|
+
self._detail_ = detail
|
2491
|
+
if frames is not None:
|
2492
|
+
self._frames_ = frames
|
2493
|
+
if limit is not None:
|
2494
|
+
self._limit_ = limit
|
2495
|
+
if stats is not None:
|
2496
|
+
if stats < 0:
|
2497
|
+
raise _OptionError(self.set, stats=stats)
|
2498
|
+
# for backward compatibility, cutoff from fractional stats
|
2499
|
+
s, c = self._c100(stats)
|
2500
|
+
self._cutoff_ = int(cutoff) if cutoff else c
|
2501
|
+
self._stats_ = s
|
2502
|
+
self._profile = s > 1 # profile types
|
2503
|
+
|
2504
|
+
@property
|
2505
|
+
def sized(self):
|
2506
|
+
"""Get the number objects sized so far (int)."""
|
2507
|
+
return sum(1 for v in _values(self._seen) if v > 0)
|
2508
|
+
|
2509
|
+
@property
|
2510
|
+
def stats(self):
|
2511
|
+
"""Get the stats and cutoff setting (float)."""
|
2512
|
+
return self._stats_ # + (self._cutoff_ * 0.01)
|
2513
|
+
|
2514
|
+
@property
|
2515
|
+
def total(self):
|
2516
|
+
"""Get the total size (in bytes) accumulated so far."""
|
2517
|
+
return self._total
|
2518
|
+
|
2519
|
+
|
2520
|
+
def amapped(percentage=None):
|
2521
|
+
"""Set/get approximate mapped memory usage as a percentage
|
2522
|
+
of the mapped file size.
|
2523
|
+
|
2524
|
+
Sets the new percentage if not None and returns the
|
2525
|
+
previously set percentage.
|
2526
|
+
|
2527
|
+
Applies only to *numpy.memmap* objects.
|
2528
|
+
"""
|
2529
|
+
global _amapped
|
2530
|
+
p = _amapped * 100.0
|
2531
|
+
if percentage is not None:
|
2532
|
+
_amapped = max(0, min(1, percentage * 0.01))
|
2533
|
+
return p
|
2534
|
+
|
2535
|
+
|
2536
|
+
_amapped = 0.01 # 0 <= percentage <= 1.0
|
2537
|
+
_asizer = Asizer()
|
2538
|
+
|
2539
|
+
|
2540
|
+
def asized(*objs, **opts):
|
2541
|
+
"""Return a tuple containing an **Asized** instance for each
|
2542
|
+
object passed as positional argument.
|
2543
|
+
|
2544
|
+
The available options and defaults are:
|
2545
|
+
|
2546
|
+
*above=0* -- threshold for largest objects stats
|
2547
|
+
|
2548
|
+
*align=8* -- size alignment
|
2549
|
+
|
2550
|
+
*code=False* -- incl. (byte)code size
|
2551
|
+
|
2552
|
+
*cutoff=10* -- limit large objects or profiles stats
|
2553
|
+
|
2554
|
+
*derive=False* -- derive from super type
|
2555
|
+
|
2556
|
+
*detail=0* -- Asized refs level
|
2557
|
+
|
2558
|
+
*frames=False* -- ignore stack frame objects
|
2559
|
+
|
2560
|
+
*ignored=True* -- ignore certain types
|
2561
|
+
|
2562
|
+
*infer=False* -- try to infer types
|
2563
|
+
|
2564
|
+
*limit=100* -- recursion limit
|
2565
|
+
|
2566
|
+
*stats=0* -- print statistics
|
2567
|
+
|
2568
|
+
If only one object is given, the return value is the **Asized**
|
2569
|
+
instance for that object. Otherwise, the length of the returned
|
2570
|
+
tuple matches the number of given objects.
|
2571
|
+
|
2572
|
+
The **Asized** size of duplicate and ignored objects will be zero.
|
2573
|
+
|
2574
|
+
Set *detail* to the desired referents level and *limit* to the
|
2575
|
+
maximum recursion depth.
|
2576
|
+
|
2577
|
+
See function **asizeof** for descriptions of the other options.
|
2578
|
+
"""
|
2579
|
+
_asizer.reset(**opts)
|
2580
|
+
if objs:
|
2581
|
+
t = _asizer.asized(*objs)
|
2582
|
+
_asizer.print_stats(objs, opts=opts, sized=t) # show opts as _kwdstr
|
2583
|
+
_asizer._clear()
|
2584
|
+
else:
|
2585
|
+
t = ()
|
2586
|
+
return t
|
2587
|
+
|
2588
|
+
|
2589
|
+
def asizeof(*objs, **opts):
|
2590
|
+
"""Return the combined size (in bytes) of all objects passed
|
2591
|
+
as positional arguments.
|
2592
|
+
|
2593
|
+
The available options and defaults are:
|
2594
|
+
|
2595
|
+
*above=0* -- threshold for largest objects stats
|
2596
|
+
|
2597
|
+
*align=8* -- size alignment
|
2598
|
+
|
2599
|
+
*clip=80* -- clip ``repr()`` strings
|
2600
|
+
|
2601
|
+
*code=False* -- incl. (byte)code size
|
2602
|
+
|
2603
|
+
*cutoff=10* -- limit large objects or profiles stats
|
2604
|
+
|
2605
|
+
*derive=False* -- derive from super type
|
2606
|
+
|
2607
|
+
*frames=False* -- ignore stack frame objects
|
2608
|
+
|
2609
|
+
*ignored=True* -- ignore certain types
|
2610
|
+
|
2611
|
+
*infer=False* -- try to infer types
|
2612
|
+
|
2613
|
+
*limit=100* -- recursion limit
|
2614
|
+
|
2615
|
+
*stats=0* -- print statistics
|
2616
|
+
|
2617
|
+
Set *align* to a power of 2 to align sizes. Any value less
|
2618
|
+
than 2 avoids size alignment.
|
2619
|
+
|
2620
|
+
If *all* is True and if no positional arguments are supplied.
|
2621
|
+
size all current gc objects, including module, global and stack
|
2622
|
+
frame objects.
|
2623
|
+
|
2624
|
+
A positive *clip* value truncates all repr() strings to at
|
2625
|
+
most *clip* characters.
|
2626
|
+
|
2627
|
+
The (byte)code size of callable objects like functions,
|
2628
|
+
methods, classes, etc. is included only if *code* is True.
|
2629
|
+
|
2630
|
+
If *derive* is True, new types are handled like an existing
|
2631
|
+
(super) type provided there is one and only of those.
|
2632
|
+
|
2633
|
+
By default certain base types like object, super, etc. are
|
2634
|
+
ignored. Set *ignored* to False to include those.
|
2635
|
+
|
2636
|
+
If *infer* is True, new types are inferred from attributes
|
2637
|
+
(only implemented for dict types on callable attributes
|
2638
|
+
as get, has_key, items, keys and values).
|
2639
|
+
|
2640
|
+
Set *limit* to a positive value to accumulate the sizes of
|
2641
|
+
the referents of each object, recursively up to the limit.
|
2642
|
+
Using *limit=0* returns the sum of the flat sizes of the
|
2643
|
+
given objects. High *limit* values may cause runtime errors
|
2644
|
+
and miss objects for sizing.
|
2645
|
+
|
2646
|
+
A positive value for *stats* prints up to 9 statistics, (1)
|
2647
|
+
a summary of the number of objects sized and seen and a list
|
2648
|
+
of the largests objects with size over *above* bytes, (2) a
|
2649
|
+
simple profile of the sized objects by type and (3+) up to 6
|
2650
|
+
tables showing the static, dynamic, derived, ignored, inferred
|
2651
|
+
and dict types used, found respectively installed.
|
2652
|
+
The fractional part of the *stats* value (x 100) is the number
|
2653
|
+
of largest objects shown for (*stats*1.+) or the cutoff
|
2654
|
+
percentage for simple profiles for (*stats*=2.+). For example,
|
2655
|
+
*stats=1.10* shows the summary and the 10 largest objects,
|
2656
|
+
also the default.
|
2657
|
+
|
2658
|
+
See this module documentation for the definition of flat size.
|
2659
|
+
"""
|
2660
|
+
t, p, x = _objs_opts_x(asizeof, objs, **opts)
|
2661
|
+
_asizer.reset(**p)
|
2662
|
+
if t:
|
2663
|
+
if x: # don't size, profile or rank _getobjects tuple
|
2664
|
+
_asizer.exclude_objs(t)
|
2665
|
+
s = _asizer.asizeof(*t)
|
2666
|
+
_asizer.print_stats(objs=t, opts=opts) # show opts as _kwdstr
|
2667
|
+
_asizer._clear()
|
2668
|
+
else:
|
2669
|
+
s = 0
|
2670
|
+
return s
|
2671
|
+
|
2672
|
+
|
2673
|
+
def asizesof(*objs, **opts):
|
2674
|
+
"""Return a tuple containing the size (in bytes) of all objects
|
2675
|
+
passed as positional arguments.
|
2676
|
+
|
2677
|
+
The available options and defaults are:
|
2678
|
+
|
2679
|
+
*above=1024* -- threshold for largest objects stats
|
2680
|
+
|
2681
|
+
*align=8* -- size alignment
|
2682
|
+
|
2683
|
+
*clip=80* -- clip ``repr()`` strings
|
2684
|
+
|
2685
|
+
*code=False* -- incl. (byte)code size
|
2686
|
+
|
2687
|
+
*cutoff=10* -- limit large objects or profiles stats
|
2688
|
+
|
2689
|
+
*derive=False* -- derive from super type
|
2690
|
+
|
2691
|
+
*frames=False* -- ignore stack frame objects
|
2692
|
+
|
2693
|
+
*ignored=True* -- ignore certain types
|
2694
|
+
|
2695
|
+
*infer=False* -- try to infer types
|
2696
|
+
|
2697
|
+
*limit=100* -- recursion limit
|
2698
|
+
|
2699
|
+
*stats=0* -- print statistics
|
2700
|
+
|
2701
|
+
See function **asizeof** for a description of the options.
|
2702
|
+
|
2703
|
+
The length of the returned tuple equals the number of given
|
2704
|
+
objects.
|
2705
|
+
|
2706
|
+
The size of duplicate and ignored objects will be zero.
|
2707
|
+
"""
|
2708
|
+
_asizer.reset(**opts)
|
2709
|
+
if objs:
|
2710
|
+
t = _asizer.asizesof(*objs)
|
2711
|
+
_asizer.print_stats(objs, opts=opts, sizes=t) # show opts as _kwdstr
|
2712
|
+
_asizer._clear()
|
2713
|
+
else:
|
2714
|
+
t = ()
|
2715
|
+
return t
|
2716
|
+
|
2717
|
+
|
2718
|
+
def _typedefof(obj, save=False, **opts):
|
2719
|
+
"""Get the typedef for an object."""
|
2720
|
+
k = _objkey(obj)
|
2721
|
+
v = _typedefs.get(k, None)
|
2722
|
+
if not v: # new typedef
|
2723
|
+
v = _typedef(obj, **opts)
|
2724
|
+
if save:
|
2725
|
+
_typedefs[k] = v
|
2726
|
+
return v
|
2727
|
+
|
2728
|
+
|
2729
|
+
def basicsize(obj, **opts):
|
2730
|
+
"""Return the basic size of an object (in bytes).
|
2731
|
+
|
2732
|
+
The available options and defaults are:
|
2733
|
+
|
2734
|
+
*derive=False* -- derive type from super type
|
2735
|
+
|
2736
|
+
*infer=False* -- try to infer types
|
2737
|
+
|
2738
|
+
*save=False* -- save the object's type definition if new
|
2739
|
+
|
2740
|
+
See this module documentation for the definition of *basic size*.
|
2741
|
+
"""
|
2742
|
+
b = t = _typedefof(obj, **opts)
|
2743
|
+
if t:
|
2744
|
+
b = t.base
|
2745
|
+
return b
|
2746
|
+
|
2747
|
+
|
2748
|
+
def flatsize(obj, align=0, **opts):
|
2749
|
+
"""Return the flat size of an object (in bytes), optionally aligned
|
2750
|
+
to the given power-of-2.
|
2751
|
+
|
2752
|
+
See function **basicsize** for a description of other available options.
|
2753
|
+
|
2754
|
+
See this module documentation for the definition of *flat size*.
|
2755
|
+
"""
|
2756
|
+
f = t = _typedefof(obj, **opts)
|
2757
|
+
if t:
|
2758
|
+
if align > 1:
|
2759
|
+
m = align - 1
|
2760
|
+
if m & align:
|
2761
|
+
raise _OptionError(flatsize, align=align)
|
2762
|
+
else:
|
2763
|
+
m = 0
|
2764
|
+
f = t.flat(obj, mask=m)
|
2765
|
+
return f
|
2766
|
+
|
2767
|
+
|
2768
|
+
def itemsize(obj, **opts):
|
2769
|
+
"""Return the item size of an object (in bytes).
|
2770
|
+
|
2771
|
+
See function **basicsize** for a description of the available options.
|
2772
|
+
|
2773
|
+
See this module documentation for the definition of *item size*.
|
2774
|
+
"""
|
2775
|
+
i = t = _typedefof(obj, **opts)
|
2776
|
+
if t:
|
2777
|
+
i, v = t.item, t.vari
|
2778
|
+
if v and i == _sizeof_Cbyte:
|
2779
|
+
i = getattr(obj, v, i)
|
2780
|
+
return i
|
2781
|
+
|
2782
|
+
|
2783
|
+
def leng(obj, **opts):
|
2784
|
+
"""Return the length of an object, in number of *items*.
|
2785
|
+
|
2786
|
+
See function **basicsize** for a description of the available options.
|
2787
|
+
"""
|
2788
|
+
n = t = _typedefof(obj, **opts)
|
2789
|
+
if t:
|
2790
|
+
n = t.leng
|
2791
|
+
if n and callable(n):
|
2792
|
+
i, v, n = t.item, t.vari, n(obj)
|
2793
|
+
if v and i == _sizeof_Cbyte:
|
2794
|
+
i = getattr(obj, v, i)
|
2795
|
+
if i > _sizeof_Cbyte:
|
2796
|
+
n = n // i
|
2797
|
+
return n
|
2798
|
+
|
2799
|
+
|
2800
|
+
def named_refs(obj, **opts):
|
2801
|
+
"""Return all named **referents** of an object (re-using
|
2802
|
+
functionality from **asizeof**).
|
2803
|
+
|
2804
|
+
Does not return un-named *referents*, e.g. objects in a list.
|
2805
|
+
|
2806
|
+
See function **basicsize** for a description of the available options.
|
2807
|
+
"""
|
2808
|
+
rs = []
|
2809
|
+
v = _typedefof(obj, **opts)
|
2810
|
+
if v:
|
2811
|
+
v = v.refs
|
2812
|
+
if v and callable(v):
|
2813
|
+
for r in v(obj, True):
|
2814
|
+
try:
|
2815
|
+
rs.append((r.name, r.ref))
|
2816
|
+
except AttributeError:
|
2817
|
+
pass
|
2818
|
+
return rs
|
2819
|
+
|
2820
|
+
|
2821
|
+
def refs(obj, **opts):
|
2822
|
+
"""Return (a generator for) specific *referents* of an object.
|
2823
|
+
|
2824
|
+
See function **basicsize** for a description of the available options.
|
2825
|
+
"""
|
2826
|
+
v = _typedefof(obj, **opts)
|
2827
|
+
if v:
|
2828
|
+
v = v.refs
|
2829
|
+
if v and callable(v):
|
2830
|
+
v = v(obj, False)
|
2831
|
+
return v
|
2832
|
+
|
2833
|
+
|
2834
|
+
# License from the initial version of this source file follows:
|
2835
|
+
|
2836
|
+
# --------------------------------------------------------------------
|
2837
|
+
# Copyright (c) 2002-2022 -- ProphICy Semiconductor, Inc.
|
2838
|
+
# All rights reserved.
|
2839
|
+
#
|
2840
|
+
# Redistribution and use in source and binary forms, with or without
|
2841
|
+
# modification, are permitted provided that the following conditions
|
2842
|
+
# are met:
|
2843
|
+
#
|
2844
|
+
# - Redistributions of source code must retain the above copyright
|
2845
|
+
# notice, this list of conditions and the following disclaimer.
|
2846
|
+
#
|
2847
|
+
# - Redistributions in binary form must reproduce the above copyright
|
2848
|
+
# notice, this list of conditions and the following disclaimer in
|
2849
|
+
# the documentation and/or other materials provided with the
|
2850
|
+
# distribution.
|
2851
|
+
#
|
2852
|
+
# - Neither the name of ProphICy Semiconductor, Inc. nor the names
|
2853
|
+
# of its contributors may be used to endorse or promote products
|
2854
|
+
# derived from this software without specific prior written
|
2855
|
+
# permission.
|
2856
|
+
#
|
2857
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
2858
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
2859
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
2860
|
+
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
2861
|
+
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
2862
|
+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
2863
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
2864
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
2865
|
+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
2866
|
+
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
2867
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
2868
|
+
# OF THE POSSIBILITY OF SUCH DAMAGE.
|
2869
|
+
# --------------------------------------------------------------------
|