zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
U
Þ=®dHIã@s´UddlmZddlZddlZddlZddlZddlZddlZddlZddl    Z    ddl
Z ddl Z ddl mZddlmZddlmZddlmZddlmZddlmZd    d
lmZd    d lmZd    d lmZd    d lmZd    dl m!Z!d    dl"m#Z#d    dl$m%Z%ddl&m'Z'ddl(m)Z)ddl(m*Z*ddl(m+Z+e j,rVddl-m.Z.ddl-m/Z/ddl-m0Z0dZ1dddœdd„Z2da3de4d<dd œd!d"„Z5Gd#d$„d$ƒZ6d%d&d'œd(d)„Z7Gd*d+„d+ƒZ8dS),é)Ú annotationsN)Ú    ExitStack)ÚBytesIO)Úchain)Úbasename)Újoin)Úadler32é)Ú_log)ÚNotFound)Ú parse_cookie)Úgen_salt)Ú    send_file)ÚRequest)ÚResponseé)ÚConsole)ÚDebugFrameSummary)ÚDebugTraceback)Úrender_console_html)Ú StartResponse)ÚWSGIApplication)ÚWSGIEnvironmenti€:    Ústr)ÚpinÚreturncCs$t |›d dd¡¡ ¡dd…S)Nz  added saltúutf-8Úreplaceé )ÚhashlibÚsha1ÚencodeÚ    hexdigest)r©r#úNd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\werkzeug/debug/__init__.pyÚhash_pin)sr%ústr | bytes | NoneÚ _machine_id©rcCs$tdk    r tSddœdd„}|ƒatS)Nr&r(c
Ss¼d}dD]T}z&t|dƒ}| ¡ ¡}W5QRXWntk
rJYqYnX|r||7}q^qz4tddƒ }|| ¡ ¡ d¡d7}W5QRXWntk
r¦YnX|r°|SzTddlm}m}|d    d
d d d g|d ¡d}t     
d|¡}|dk    r|  d¡WSWntt fk
rYnXt jdkr¸ddl}zl| |jdd|j|jB¡H}    | |    d¡\}
} | |jkr†|
 d¡W5QR£WS|
W5QR£WSQRXWntk
r¶YnXdS)Nó)z/etc/machine-idz/proc/sys/kernel/random/boot_idÚrbz/proc/self/cgroupó/r    r)ÚPopenÚPIPEZioregz-cZIOPlatformExpertDevicez-dÚ2)Ústdouts"serial-number" = <([^>]+)rÚwin32zSOFTWARE\Microsoft\CryptographyZ MachineGuidr)ÚopenÚreadlineÚstripÚOSErrorÚ
rpartitionÚ
subprocessr,r-Ú communicateÚreÚsearchÚgroupÚ ImportErrorÚsysÚplatformÚwinregÚOpenKeyÚHKEY_LOCAL_MACHINEÚKEY_READÚKEY_WOW64_64KEYÚ QueryValueExÚREG_SZr!) ÚlinuxÚfilenameÚfÚvaluer,r-ÚdumpÚmatchr>ZrkZguidZ    guid_typer#r#r$Ú    _generate6s^ 
 ( ÿþ 
 
ü z!get_machine_id.<locals>._generate)r')rKr#r#r$Úget_machine_id0s
CrLc@s.eZdZdZddœdd„Zdddœd    d
„Zd S) Ú _ConsoleFramez]Helper class so that we can reuse the frame console code for the
    standalone console.
    zdict[str, t.Any])Ú    namespacecCst|ƒ|_d|_dS)Nr)rÚconsoleÚid)ÚselfrNr#r#r$Ú__init__‚s
z_ConsoleFrame.__init__rzt.Any)ÚcodercCs |j |¡S©N)rOÚeval)rQrSr#r#r$rU†sz_ConsoleFrame.evalN)Ú__name__Ú
__module__Ú __qualname__Ú__doc__rRrUr#r#r#r$rM}srMrz%tuple[str, str] | tuple[(None, None)])Úapprc     s¶tj d¡}d}d‰|dkr dS|dk    rJ| dd¡ ¡rJd|krF|}n|‰t|dt t|¡j    j
ƒ}z t   ¡}Wnt tfk
rŠd}YnXtj |¡}||t|dt|ƒjƒt|d    dƒg}tt ¡ƒtƒg}t ¡}t||ƒD](}    |    sèqÞt|    tƒrü|     d
¡}    | |    ¡qÞ| d ¡d | ¡dd …›}
ˆdkrV| d¡t| ¡dƒd›dd…‰|dkr®dD]D‰tˆƒˆdkrdd  ‡‡fdd„t!dtˆƒˆƒDƒ¡}q®qdˆ}||
fS)aQGiven an application object this returns a semi-stable 9 digit pin
    code and a random key.  The hope is that this is stable between
    restarts to not make debugging particularly frustrating.  If the pin
    was forcefully disabled this returns `None`.
 
    Second item in the resulting tuple is the cookie name for remembering.
    ZWERKZEUG_DEBUG_PINNÚoff)NNú-ÚrWrVÚ__file__rs
cookiesaltZ__wzdéspinsaltéZ09dé    )ééérc3s&|]}ˆ||ˆ… ˆd¡VqdS)Ú0N)Úrjust)Ú.0Úx©Z
group_sizeÚnumr#r$Ú    <genexpr>Õsÿz*get_pin_and_cookie_name.<locals>.<genexpr>)"ÚosÚenvironÚgetrÚ    isdecimalÚgetattrÚtÚcastÚobjectÚ    __class__rWÚgetpassÚgetuserr;ÚKeyErrorr<ÚmodulesÚtyperVrÚuuidÚgetnoderLrr rÚ
isinstancer!Úupdater"ÚintÚlenrÚrange) rZrÚrvÚmodnameÚusernameÚmodZprobably_public_bitsZ private_bitsÚhÚbitZ cookie_namer#rir$Úget_pin_and_cookie_nameŠsT
 
 
ü
 
 
 
 
 
 
þ
r‡c @seZdZUdZded<ded<d8d
d ddd d d d d dœ    dd„Zeddœdd„ƒZejdd dœdd„ƒZeddœdd„ƒZ    ddddœdd„Z
ddd d!d"œd#d$„Z dd!d%œd&d'„Z ddd!d(œd)d*„Z dd+d,œd-d.„Zd dœd/d0„Zdd!d%œd1d2„Zd!dœd3d4„Zddd5dœd6d7„ZdS)9ÚDebuggedApplicationa4Enables debugging support for a given application::
 
        from werkzeug.debug import DebuggedApplication
        from myapp import app
        app = DebuggedApplication(app, evalex=True)
 
    The ``evalex`` argument allows evaluating expressions in any frame
    of a traceback. This works by preserving each frame with its local
    state. Some state, such as context globals, cannot be restored with
    the frame by default. When ``evalex`` is enabled,
    ``environ["werkzeug.debug.preserve_context"]`` will be a callable
    that takes a context manager, and can be called multiple times.
    Each context manager will be entered before evaluating code in the
    frame, then exited again, so they can perform setup and cleanup for
    each call.
 
    :param app: the WSGI application to run debugged.
    :param evalex: enable exception evaluation feature (interactive
                   debugging).  This requires a non-forking server.
    :param request_key: The key that points to the request object in this
                        environment.  This parameter is ignored in current
                        versions.
    :param console_path: the URL for a general purpose console.
    :param console_init_func: the function that is executed before starting
                              the general purpose console.  The return value
                              is used as initial namespace.
    :param show_hidden_frames: by default hidden traceback frames are skipped.
                               You can show them by setting this parameter
                               to `True`.
    :param pin_security: can be used to disable the pin based security system.
    :param pin_logging: enables the logging of the pin system.
 
    .. versionchanged:: 2.2
        Added the ``werkzeug.debug.preserve_context`` environ key.
    rÚ_pinÚ _pin_cookieFúwerkzeug.requestú/consoleNTrÚboolz't.Callable[[], dict[str, t.Any]] | NoneÚNone)    rZÚevalexÚ request_keyÚ console_pathÚconsole_init_funcÚshow_hidden_framesÚ pin_securityÚ pin_loggingrc        Cs |sd}||_||_i|_i|_||_||_||_||_tdƒ|_    d|_
||_ |r–t j  d¡dkrœ|rœtddƒ|jdkr†tddƒqœtdd    |jƒnd|_dS)
Nr_rZWERKZEUG_RUN_MAINÚtrueÚwarningz * Debugger is active!z- * Debugger PIN disabled. DEBUGGER UNSECURED!Úinfoz * Debugger PIN: %s)rZrÚframesÚframe_contextsrr‘r’r“r ÚsecretÚ_failed_pin_authr•rlrmrnr
r)    rQrZrrr‘r’r“r”r•r#r#r$rRs( 
 
 
 zDebuggedApplication.__init__z
str | Noner(cCs&t|dƒs t|jƒ}|\|_|_|jS)Nr‰©Úhasattrr‡rZr‰rŠ©rQZ
pin_cookier#r#r$r,s
 
 zDebuggedApplication.pin)rHrcCs
||_dSrT)r‰)rQrHr#r#r$r3scCs&t|dƒs t|jƒ}|\|_|_|jS)zThe name of the pin cookie.rŠrrŸr#r#r$Úpin_cookie_name7s
 
 z#DebuggedApplication.pin_cookie_namerrzt.Iterator[bytes])rmÚstart_responserc cs<g}|jr|j|d<d}z,| ||¡}|EdHt|dƒrB| ¡Wnòtk
r6}zÒt|dƒrj| ¡t|d|j d}|jD] }||j    t
|ƒ<||j t
|ƒ<q‚t |  |¡ƒ}|j|j|j|d}    t|    ddd    }
z|
||ƒEdHWn$tk
r |d
 d ¡YnX|d
 d  | ¡¡¡W5d}~XYnXdS) z6Run the application and conserve the traceback frames.zwerkzeug.debug.preserve_contextNÚcloser)ÚskipZhide)rr›Úevalex_trustediôú    text/html)ÚstatusÚmimetypez wsgi.errorszpDebugging middleware caught exception in streamed response at a point where response headers were already sent.
r])rÚappendrZržr¢Ú    Exceptionrr“Z
all_framesr™rPršrÚcheck_pin_trustZrender_debugger_htmlr›rÚwriterZrender_traceback_text) rQrmr¡ÚcontextsZapp_iterÚeÚtbÚframeÚ
is_trustedÚhtmlÚresponser#r#r$Údebug_application?s<
 
 
 
 
ýÿ
z%DebuggedApplication.debug_applicationrz!DebugFrameSummary | _ConsoleFramer)ÚrequestÚcommandr¯rc
CsV|j t|ƒg¡}tƒ4}|D]}| |¡qt| |¡ddW5QR£SQRXdS)zExecute a command in a console.r¥©r§N)ršrnrPrÚ enter_contextrrU)rQr´rµr¯r¬Z
exit_stackÚcmr#r#r$Úexecute_commandos
 z#DebuggedApplication.execute_command)r´rcCshd|jkrB|jdkri}n t| ¡ƒ}| d|j¡t|ƒ|jd<t| |j¡ƒ}t    t
|j |dddS)zDisplay a standalone shell.rNrZ)r›r¤r¥r¶) r™r’ÚdictÚ
setdefaultrZrMrrªrmrrr›)rQr´Únsr°r#r#r$Údisplay_console~s
 
  þz#DebuggedApplication.display_console)r´rFrcCsrtdt|ƒƒ}zt t|¡}Wntk
r8tƒYSX|dkrHtƒStt|ƒd@ƒ}t    t
|ƒ|j ||dSdS)z0Return a static resource from the shared folder.ZsharedNlÿÿ)Z download_nameÚetag) rrÚpkgutilÚget_dataÚ __package__r4r rrrrrm)rQr´rFÚpathÚdatar¾r#r#r$Ú get_resources ÿz DebuggedApplication.get_resourcez bool | None)rmrcCs„|jdkrdSt|ƒ |j¡}|r*d|kr.dS| dd¡\}}z t|ƒ}Wntk
r`YdSX|t|jƒkrtdSt ¡t    |kS)a!Checks if the request passed the pin test.  This returns `True` if the
        request is trusted on a pin/cookie basis and returns `False` if not.
        Additionally if the cookie's stored pin hash is wrong it will return
        `None` so that appropriate action can be taken.
        NTú|Fr)
rr rnr Úsplitr~Ú
ValueErrorr%ÚtimeÚPIN_TIME)rQrmÚvalZts_strZpin_hashÚtsr#r#r$rªžs
  z#DebuggedApplication.check_pin_trustcCs*t |jdkrdnd¡|jd7_dS)Nrbg@gà?r)rÈÚsleeprœ©rQr#r#r$Ú_fail_pin_auth´sz"DebuggedApplication._fail_pin_authc    Csðd}d}| |j¡}t t|j¡}d}|dkr<| ¡d}nT|rFd}nJ|jdkrVd}n:|jd}|     ¡ 
dd¡| 
dd¡krˆd|_d}n| ¡t t   ||d    œ¡d
d }|rÜ|j|jtt ¡ƒ›d t|ƒ›dd |jdn|rì| |j¡|S)zAuthenticates with the pin.FNTé
rr\r]r)ÚauthÚ    exhaustedzapplication/jsonr¶rÅZStrict)ÚhttponlyÚsamesiteÚsecure)rªrmrqrrrrrÎrœÚargsr3rrÚjsonÚdumpsÚ
set_cookier r~rÈr%Z    is_secureZ delete_cookie)    rQr´rÑrÐÚtrustrÚ
bad_cookieZ entered_pinrr#r#r$Úpin_auth¸s@ 
 
þû zDebuggedApplication.pin_authcCs0|jr(|jdk    r(tddƒtdd|jƒtdƒS)zLog the pin if needed.Nr˜z= * To enable the debugger you need to enter the security pin:z * Debugger pin code: %sr])r•rr
rrÍr#r#r$Úlog_pin_requestësÿz#DebuggedApplication.log_pin_requestzt.Iterable[bytes]c    Cst|ƒ}|j}|j d¡dkrè|j d¡}|j d¡}|j d¡}|j |jjdtd¡}|dkrt|rt| ||¡}nr|d    kr’||jkr’| |¡}nT|d
kr®||jkr®|     ¡}n8|j
ræ|d k    ræ|d k    ræ|j|kræ|  |¡ræ|  |||¡}n,|j
r|j d k    r|j|j kr| |¡}|||ƒS) zDispatch the requests.Z __debugger__ÚyesÚcmdrGÚsÚfrm)ryÚresourceZpinauthZprintpinN)rr³rÕrnr™r~rÄr›rÛrÜrrªr¹r‘rÂr½)    rQrmr¡r´r²rÞÚargr›r¯r#r#r$Ú__call__ôs@     
ÿþýüûÿþ
ý
zDebuggedApplication.__call__)Fr‹rŒNFTT)rVrWrXrYÚ__annotations__rRÚpropertyrÚsetterr r³r¹r½rÄrªrÎrÛrÜrãr#r#r#r$rˆàs4
$÷ $03    rˆ)9Ú
__future__rrurrÖrlr¿r8r<rÈÚtypingrqrzÚ
contextlibrÚiorÚ    itertoolsrÚos.pathrrÚzlibrÚ    _internalr
Ú
exceptionsr Úhttpr Úsecurityr ÚutilsrZwrappers.requestrZwrappers.responserrOrZtbtoolsrrrÚ TYPE_CHECKINGZ_typeshed.wsgirrrrÉr%r'rärLrMr‡rˆr#r#r#r$Ú<module>sN                      M V