45
45
import static com .oracle .graal .python .builtins .PythonBuiltinClassType .TypeError ;
46
46
import static com .oracle .graal .python .builtins .PythonBuiltinClassType .ValueError ;
47
47
import static com .oracle .graal .python .builtins .modules .SSLModuleBuiltins .LOGGER ;
48
- import static com .oracle .graal .python .nodes .BuiltinNames .T_NT ;
49
- import static com .oracle .graal .python .nodes .BuiltinNames .T_POSIX ;
50
48
import static com .oracle .graal .python .nodes .ErrorMessages .S ;
51
49
import static com .oracle .graal .python .util .PythonUtils .toTruffleStringUncached ;
52
50
import static com .oracle .graal .python .util .PythonUtils .tsLiteral ;
89
87
import com .oracle .graal .python .builtins .CoreFunctions ;
90
88
import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
91
89
import com .oracle .graal .python .builtins .PythonBuiltins ;
92
- import com .oracle .graal .python .builtins .PythonOS ;
93
90
import com .oracle .graal .python .builtins .modules .SSLModuleBuiltins ;
94
91
import com .oracle .graal .python .builtins .objects .PNone ;
95
92
import com .oracle .graal .python .builtins .objects .buffer .PythonBufferAccessLibrary ;
96
93
import com .oracle .graal .python .builtins .objects .bytes .PBytes ;
97
94
import com .oracle .graal .python .builtins .objects .bytes .PBytesLike ;
98
- import com .oracle .graal .python .builtins .objects .common .HashingStorage ;
99
- import com .oracle .graal .python .builtins .objects .common .HashingStorageNodes .HashingStorageGetItem ;
100
95
import com .oracle .graal .python .builtins .objects .common .SequenceStorageNodes .ToByteArrayNode ;
101
96
import com .oracle .graal .python .builtins .objects .dict .PDict ;
102
97
import com .oracle .graal .python .builtins .objects .exception .OSErrorEnum ;
103
98
import com .oracle .graal .python .builtins .objects .function .PKeyword ;
104
99
import com .oracle .graal .python .builtins .objects .list .PList ;
105
- import com .oracle .graal .python .builtins .objects .module .PythonModule ;
106
100
import com .oracle .graal .python .builtins .objects .socket .PSocket ;
107
101
import com .oracle .graal .python .builtins .objects .ssl .CertUtils .NeedsPasswordException ;
108
102
import com .oracle .graal .python .builtins .objects .ssl .CertUtils .NoCertificateFoundException ;
109
103
import com .oracle .graal .python .builtins .objects .str .StringNodes ;
110
104
import com .oracle .graal .python .builtins .objects .type .TpSlots ;
111
105
import com .oracle .graal .python .builtins .objects .type .TypeNodes ;
106
+ import com .oracle .graal .python .lib .OsEnvironGetNode ;
112
107
import com .oracle .graal .python .lib .PyCallableCheckNode ;
113
108
import com .oracle .graal .python .lib .PyNumberAsSizeNode ;
114
109
import com .oracle .graal .python .lib .PyNumberIndexNode ;
119
114
import com .oracle .graal .python .nodes .PGuards ;
120
115
import com .oracle .graal .python .nodes .PNodeWithContext ;
121
116
import com .oracle .graal .python .nodes .PRaiseNode ;
122
- import com .oracle .graal .python .nodes .attributes .GetAttributeNode ;
123
117
import com .oracle .graal .python .nodes .call .CallNode ;
124
118
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
125
119
import com .oracle .graal .python .nodes .function .builtins .PythonBinaryBuiltinNode ;
145
139
import com .oracle .truffle .api .dsl .Cached .Shared ;
146
140
import com .oracle .truffle .api .dsl .Fallback ;
147
141
import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
148
- import com .oracle .truffle .api .dsl .NeverDefault ;
149
142
import com .oracle .truffle .api .dsl .NodeFactory ;
150
143
import com .oracle .truffle .api .dsl .Specialization ;
151
144
import com .oracle .truffle .api .frame .VirtualFrame ;
156
149
@ CoreFunctions (extendClasses = PythonBuiltinClassType .PSSLContext )
157
150
public final class SSLContextBuiltins extends PythonBuiltins {
158
151
159
- private static final TruffleString T_ENVIRON = tsLiteral ("environ" );
160
-
161
152
public static final TpSlots SLOTS = SSLContextBuiltinsSlotsGen .SLOTS ;
162
153
163
154
@ Override
@@ -618,27 +609,15 @@ static Object pha(@SuppressWarnings("unused") PSSLContext self) {
618
609
@ Builtin (name = "set_default_verify_paths" , minNumOfPositionalArgs = 1 )
619
610
@ GenerateNodeFactory
620
611
abstract static class SetDefaultVerifyPathsNode extends PythonUnaryBuiltinNode {
612
+ static final TruffleString T_SSL_CERT_FILE = tsLiteral ("SSL_CERT_FILE" );
613
+ static final TruffleString T_SSL_CERT_DIR = tsLiteral ("SSL_CERT_DIR" );
614
+
621
615
@ Specialization
622
616
Object set (VirtualFrame frame , PSSLContext self ,
623
617
@ Bind ("this" ) Node inliningTarget ,
624
- @ Cached PyUnicodeFSDecoderNode asPath ,
625
- @ Cached ("createEnvironLookup()" ) GetAttributeNode getAttribute ,
626
- @ Cached HashingStorageGetItem getItem ,
627
- @ Cached ("createCertFileKey()" ) PBytes certFileKey ,
628
- @ Cached ("createCertDirKey()" ) PBytes certDirKey ,
629
- @ Cached TruffleString .ToJavaStringNode toJavaStringNode ) {
630
-
631
- PythonModule posix ;
632
- if (PythonOS .getPythonOS () == PythonOS .PLATFORM_WIN32 ) {
633
- posix = getContext ().lookupBuiltinModule (T_NT );
634
- } else {
635
- posix = getContext ().lookupBuiltinModule (T_POSIX );
636
- }
637
- PDict environ = (PDict ) getAttribute .executeObject (frame , posix );
638
- HashingStorage storage = environ .getDictStorage ();
639
-
640
- TruffleFile file = toTruffleFile (frame , asPath , getItem .execute (frame , inliningTarget , storage , certFileKey ), toJavaStringNode );
641
- TruffleFile path = toTruffleFile (frame , asPath , getItem .execute (frame , inliningTarget , storage , certDirKey ), toJavaStringNode );
618
+ @ Cached PyUnicodeFSDecoderNode asPath ) {
619
+ TruffleFile file = toTruffleFile (frame , asPath , OsEnvironGetNode .executeUncached (T_SSL_CERT_FILE ));
620
+ TruffleFile path = toTruffleFile (frame , asPath , OsEnvironGetNode .executeUncached (T_SSL_CERT_DIR ));
642
621
if (file != null || path != null ) {
643
622
LOGGER .fine (() -> String .format ("set_default_verify_paths file: %s. path: %s" , file != null ? file .getPath () : "None" , path != null ? path .getPath () : "None" ));
644
623
try {
@@ -653,30 +632,13 @@ Object set(VirtualFrame frame, PSSLContext self,
653
632
return PNone .NONE ;
654
633
}
655
634
656
- @ NeverDefault
657
- @ TruffleBoundary
658
- protected PBytes createCertFileKey () {
659
- return PFactory .createBytes (PythonLanguage .get (null ), "SSL_CERT_FILE" .getBytes ());
660
- }
661
-
662
- @ NeverDefault
663
- @ TruffleBoundary
664
- protected PBytes createCertDirKey () {
665
- return PFactory .createBytes (PythonLanguage .get (null ), "SSL_CERT_DIR" .getBytes ());
666
- }
667
-
668
- @ NeverDefault
669
- protected static GetAttributeNode createEnvironLookup () {
670
- return GetAttributeNode .create (T_ENVIRON );
671
- }
672
-
673
- private TruffleFile toTruffleFile (VirtualFrame frame , PyUnicodeFSDecoderNode asPath , Object path , TruffleString .ToJavaStringNode toJavaStringNode ) throws PException {
635
+ private TruffleFile toTruffleFile (VirtualFrame frame , PyUnicodeFSDecoderNode asPath , TruffleString path ) throws PException {
674
636
if (path == null ) {
675
637
return null ;
676
638
}
677
639
TruffleFile file ;
678
640
try {
679
- file = getContext ().getEnv ().getPublicTruffleFile (toJavaStringNode . execute ( asPath .execute (frame , path )));
641
+ file = getContext ().getEnv ().getPublicTruffleFile (asPath .execute (frame , path ). toJavaStringUncached ( ));
680
642
if (!file .exists ()) {
681
643
return null ;
682
644
}
0 commit comments