
    .Ph6                        d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZdZ	  ej                    j        ZdZn# e$ r dZej        ZY nw xY w e ed                    dd                                         Z ej        d	          d
k    Z eedd          dk    ZdZ	 ddlZn# e$ r dZY nw xY w	 ddlZej        Zn# e$ r dZY nw xY w	 ddlZ	 ej        Zn# e$ r dZY nw xY wn# e$ r dZY nw xY w	 ddl Z  e!e j"                  Z#n# e$ r dZ#Y nw xY w	 ddl$Z$e$j%        Z%n# e$ r dZ%Y nw xY w	 ddl&m'Z' e'j(        Z(n# e$ r dZ(Y nw xY w	 ddl)m*Z*  e*            Z+n# e$ r dZ+Y nw xY w	 ddl,Z,dZ-n# e$ r dZ-Y nw xY w	 ej.        Z/n# e$ r dZ/Y nw xY w	 ddl0m1Z1m2Z2  e1e2          \  Z3Z4n# e$ r d\  Z3Z4Y nw xY w e!e
j
        5                    e
j6        j7                            ej6         dz  dZ8d Z9d Z:d Z;d dZ<d Z=d!dZ> ej?        d          j@        ZAd"dZBd"dZCeDdk    r
 e=             dS )#a  As a programming ecosystem grows, so do the chances of runtime
variability.

Python boasts one of the widest deployments for a high-level
programming environment, making it a viable target for all manner of
application. But with breadth comes variance, so it's important to
know what you're working with.

Some basic variations that are common among development machines:

* **Executable runtime**: CPython, PyPy, Jython, etc., plus build date and compiler
* **Language version**: 2.7 through 3.12
* **Host operating system**: Windows, OS X, Ubuntu, Debian, CentOS, RHEL, etc.
* **Features**: 64-bit, IPv6, Unicode character support (UCS-2/UCS-4)
* **Built-in library support**: OpenSSL, threading, SQLite, zlib
* **User environment**: umask, ulimit, working directory path
* **Machine info**: CPU count, hostname, filesystem encoding

See the full example profile below for more.

ecoutils was created to quantify that variability. ecoutils quickly
produces an information-dense description of critical runtime factors,
with minimal side effects. In short, ecoutils is like browser and user
agent analytics, but for Python environments.

Transmission and collection
---------------------------

The data is all JSON serializable, and is suitable for sending to a
central analytics server. An HTTP-backed service for this can be found
at: https://github.com/mahmoud/espymetrics/

Notable omissions
-----------------

Due to space constraints (and possibly latency constraints), the
following information is deemed not dense enough, and thus omitted:

* :data:`sys.path`
* full :mod:`sysconfig`
* environment variables (:data:`os.environ`)

Compatibility
-------------

So far ecoutils has has been tested on Python 3.7+ and PyPy3. 
Various versions have been tested on Ubuntu, Debian,
RHEL, OS X, FreeBSD, and Windows 7.

.. note:: 

   ``boltons.ecoutils`` historically supported back to Python 2.4, but in 2024, 
    due to increasing testing burden, ecoutils support tracks the same 
    versions of Python as the rest of the boltons package. 
    For older Pythons, see `this version`_ from boltons 23.0.0.

.. _this version: https://github.com/mahmoud/boltons/blob/4b1d728f31a8378b193be9c966c853be0a57527d/boltons/ecoutils.py

Profile generation
------------------

Profiles are generated by :func:`ecoutils.get_profile`.

When run as a module, ecoutils will call :func:`~ecoutils.get_profile`
and print a profile in JSON format::

    $ python -m boltons.ecoutils
    {
      "_eco_version": "1.0.0",
      "cpu_count": 4,
      "cwd": "/home/mahmoud/projects/boltons",
      "fs_encoding": "UTF-8",
      "guid": "6b139e7bbf5ad4ed8d4063bf6235b4d2",
      "hostfqdn": "mahmoud-host",
      "hostname": "mahmoud-host",
      "linux_dist_name": "Ubuntu",
      "linux_dist_version": "14.04",
      "python": {
        "argv": "boltons/ecoutils.py",
        "bin": "/usr/bin/python",
        "build_date": "Jun 22 2015 17:58:13",
        "compiler": "GCC 4.8.2",
        "features": {
          "64bit": true,
          "expat": "expat_2.1.0",
          "ipv6": true,
          "openssl": "OpenSSL 1.0.1f 6 Jan 2014",
          "readline": true,
          "sqlite": "3.8.2",
          "threading": true,
          "tkinter": "8.6",
          "unicode_wide": true,
          "zlib": "1.2.8"
        },
        "version": "2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2]",
        "version_info": [
          2,
          7,
          6,
          "final",
          0
        ]
      },
      "time_utc": "2016-05-24 07:59:40.473140",
      "time_utc_offset": -8.0,
      "ulimit_hard": 4096,
      "ulimit_soft": 1024,
      "umask": "002",
      "uname": {
        "machine": "x86_64",
        "node": "mahmoud-host",
        "processor": "x86_64",
        "release": "3.13.0-85-generic",
        "system": "Linux",
        "version": "#129-Ubuntu SMP Thu Mar 17 20:50:15 UTC 2016"
      },
      "username": "mahmoud"
    }

``pip install boltons`` and try it yourself!

    Nz1.1.0TF      P   
maxunicodei    zOpenSSL >0.8.0)expat)	cpu_count)	getrlimitRLIMIT_NOFILE)r   r   g      @)time_utctime_utc_offsetc                     i } t          t          j                  | d<   t          j        | d<   d                    t          j                                                  | d<   t          j                    | d<   t          j	                    d         | d<   t          t          j                  | d<   t          t          t          t          t           t"          t$          t&          t(          t*          t,          d	| d
<   | S )Nargvbin versioncompiler   
build_dateversion_info)opensslr
   sqlitetkinterzlibunicode_widereadline64bitipv6	threadingurandomfeatures)_escape_shell_argssysr   
executablejoinr   splitplatformpython_compilerpython_buildlistr   OPENSSL_VERSIONEXPAT_VERSIONSQLITE_VERSIONTKINTER_VERSIONZLIB_VERSION	HAVE_UCS4HAVE_READLINEIS_64BIT	HAVE_IPV6HAVE_THREADINGHAVE_URANDOM)rets    P/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/boltons/ecoutils.pyget_python_infor:     s    
C$SX..CKCJ
 XXck//1122C	N.00C
O -//2Cs/00C"1 -!/"1+'0#0 (($2".
0 
0C
O J    c                  b   |                      dd          }| r$t          d|                                           i }	 t          j                    |d<   n# t
          $ r d|d<   Y nw xY wt          t                    |d<   t          j	                    |d<   t          j
                    |d<   t          j                    }|d	         |d
         |d         |d         |d         |d         d|d<   	 t          j                    }n# t
          $ r d}Y nw xY w|d	         |d<   |d
         |d<   t          |d<   t          j                    |d<   t"          |d<   t$          |d<   t'          j                    |d<   t+          t'          j        t'          j        d                                                  dd          |d<   t1                      |d<   |                    t4                     t6          |d<   |r5d|d<   d|d<   d|d<   d|d         d<   d|d         d<   d|d         d <   d|d<   |S )!a  The main entrypoint to ecoutils. Calling this will return a
    JSON-serializable dictionary of information about the current
    process.

    It is very unlikely that the information returned will change
    during the lifetime of the process, and in most cases the majority
    of the information stays the same between runs as well.

    :func:`get_profile` takes one optional keyword argument, *scrub*,
    a :class:`bool` that, if True, blanks out identifiable
    information. This includes current working directory, hostname,
    Python executable path, command-line arguments, and
    username. Values are replaced with '-', but for compatibility keys
    remain in place.

    scrubFzunexpected keyword arguments: usernamer	   guidhostnamehostfqdnr   r   r      r      )systemnodereleaser   machine	processoruname)r	   r	   r	   linux_dist_namelinux_dist_versionr   fs_encodingulimit_softulimit_hardcwd0umaskpython_eco_version-r   r   rE   )pop	TypeErrorkeysgetpassgetuser	ExceptionstrINSTANCE_IDsocketgethostnamegetfqdnr)   rI   linux_distribution	CPU_COUNTr%   getfilesystemencodingRLIMIT_FDS_SOFTRLIMIT_FDS_HARDosgetcwdoctrQ   rjustr:   updateSTART_TIME_INFOECO_VERSION)kwargsr=   r8   rI   
linux_dists        r9   get_profilern   "  sO   " JJw&&E LJJJKKK
C!/++J   Jk""CK(**C
On&&C
ONE#Ah!!H$Qx$Qx$Qx!&q+ +CL"022

 " " "!


"']C *1C C244C(C(CCJrx,,--33As;;CL#%%CMJJ%C E
JJ"He #Hf"GVJJs$    A A)(A)3D DDc                 `    |rt          j        | d|          S t          j        | d          S )NT)	sort_keysindent)rp   )jsondumps)valrq   s     r9   rs   rs   e  s6     >z#f====:cT****r;   c                 L    | rd} nd} t                      }t          ||           S )Nr   r   )rn   rs   )rq   	data_dicts     r9   get_profile_jsonrw   k  s/     IF###r;   c                  @    t          t          d                     d S )NT)rq   )printrw    r;   r9   mainr{   u  s"    	
$
'
'
'(((((r;   r   c                     |st           j        dk    rd}nd}|dk    rt          | |          S |dk    rt          | |          S t	          d|z            )Nwin32cmdsh)sepz+style expected one of 'cmd' or 'sh', not %r)r%   r)   _args2sh	_args2cmd
ValueError)argsr   styles      r9   r$   r$   }  so     <7""EEE}}#&&&&	%3''''
BUJ
K
KKr;   z[^a-zA-Z0-9_@%+=:,./-]c                    g }| D ]n}|s|                     d           t          |          |                     |           ?|                     d|                    dd          z   dz              od                    |          S )Nz'''z'"'"'r   )append_find_sh_unsafereplacer'   )r   r   ret_listargs       r9   r   r     s    H 	A 	A 	OOD!!!3'OOC    	ckk#y999C?@@@@88Hr;   c                 h   g }d}| D ]}g }|r|                     d           d|v pd|v p| }|r|                     d           |D ]}|dk    r|                     |           |dk    r@|                     dt          |          z  dz             g }|                     d           d|r|                    |           g }|                     |           |r|                    |           |r*|                    |           |                     d           d                    |          S )	NFr   	"\r   z\"r	   )r   lenextendr'   )r   r   result	needquoter   bs_bufcs          r9   r   r     sp   FI ! !  	MM#CZ<TS[<W	 	MM# 	! 	!ADyya    cdS[[02333e$$$$   MM&)))Fa      	"MM&!!! 	MM&!!!MM#776??r;   __main__)F)r   N)r   )E__doc__rere   r%   rr   timerandomr]   structrX   datetimer)   rk   SystemRandomgetrandbitsr7   rZ   hexlowerr\   calcsizer4   getattrr2   r3   r   sqlite3sqlite_versionr/   sslr-   AttributeErrorr   r[   	TkVersionr0   r   r1   xml.parsersr
   r.   multiprocessingr   ra   r!   r6   has_ipv6r5   resourcer   r   rc   rd   nowtimezoneutcrj   r:   rn   rs   rw   r{   r$   compilesearchr   r   r   __name__rz   r;   r9   <module>r      s  >y yv 
			 				 



        %%&%''3KLL % % %L$KKK% c++c""##AbD)//116?3!#GCq))E1	OOOO   MMMNNN+NN   NNN

JJJ+- + + + ++    OOONNNc'+,,OO   OOOKKK$LL   LLL!!!!!!'MM   MMM))))))	II   IIINN   NNNII   III,11111111'0y'?'?$O__ , , ,'+$O___,  #s8#4#8#89J9N#O#OPP'+}nv&=? ?  :@ @ @F+ + +$ $ $ $) ) )L L L L "*677>   $' ' ' '\ zDFFF s   A	 	AA3B8 8CCC CC C; %C- ,C; -C74C; 6C77C; ;DD	D D('D(,D8 8EEE EE"E3 3E=<E=F FFF F('F(,G 
GG