4545import static com .oracle .graal .python .builtins .PythonBuiltinClassType .TypeError ;
4646import static com .oracle .graal .python .builtins .PythonBuiltinClassType .ValueError ;
4747import 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 ;
5048import static com .oracle .graal .python .nodes .ErrorMessages .S ;
5149import static com .oracle .graal .python .util .PythonUtils .toTruffleStringUncached ;
5250import static com .oracle .graal .python .util .PythonUtils .tsLiteral ;
8987import com .oracle .graal .python .builtins .CoreFunctions ;
9088import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
9189import com .oracle .graal .python .builtins .PythonBuiltins ;
92- import com .oracle .graal .python .builtins .PythonOS ;
9390import com .oracle .graal .python .builtins .modules .SSLModuleBuiltins ;
9491import com .oracle .graal .python .builtins .objects .PNone ;
9592import com .oracle .graal .python .builtins .objects .buffer .PythonBufferAccessLibrary ;
9693import com .oracle .graal .python .builtins .objects .bytes .PBytes ;
9794import 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 ;
10095import com .oracle .graal .python .builtins .objects .common .SequenceStorageNodes .ToByteArrayNode ;
10196import com .oracle .graal .python .builtins .objects .dict .PDict ;
10297import com .oracle .graal .python .builtins .objects .exception .OSErrorEnum ;
10398import com .oracle .graal .python .builtins .objects .function .PKeyword ;
10499import com .oracle .graal .python .builtins .objects .list .PList ;
105- import com .oracle .graal .python .builtins .objects .module .PythonModule ;
106100import com .oracle .graal .python .builtins .objects .socket .PSocket ;
107101import com .oracle .graal .python .builtins .objects .ssl .CertUtils .NeedsPasswordException ;
108102import com .oracle .graal .python .builtins .objects .ssl .CertUtils .NoCertificateFoundException ;
109103import com .oracle .graal .python .builtins .objects .str .StringNodes ;
110104import com .oracle .graal .python .builtins .objects .type .TpSlots ;
111105import com .oracle .graal .python .builtins .objects .type .TypeNodes ;
106+ import com .oracle .graal .python .lib .OsEnvironGetNode ;
112107import com .oracle .graal .python .lib .PyCallableCheckNode ;
113108import com .oracle .graal .python .lib .PyNumberAsSizeNode ;
114109import com .oracle .graal .python .lib .PyNumberIndexNode ;
119114import com .oracle .graal .python .nodes .PGuards ;
120115import com .oracle .graal .python .nodes .PNodeWithContext ;
121116import com .oracle .graal .python .nodes .PRaiseNode ;
122- import com .oracle .graal .python .nodes .attributes .GetAttributeNode ;
123117import com .oracle .graal .python .nodes .call .CallNode ;
124118import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
125119import com .oracle .graal .python .nodes .function .builtins .PythonBinaryBuiltinNode ;
145139import com .oracle .truffle .api .dsl .Cached .Shared ;
146140import com .oracle .truffle .api .dsl .Fallback ;
147141import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
148- import com .oracle .truffle .api .dsl .NeverDefault ;
149142import com .oracle .truffle .api .dsl .NodeFactory ;
150143import com .oracle .truffle .api .dsl .Specialization ;
151144import com .oracle .truffle .api .frame .VirtualFrame ;
156149@ CoreFunctions (extendClasses = PythonBuiltinClassType .PSSLContext )
157150public final class SSLContextBuiltins extends PythonBuiltins {
158151
159- private static final TruffleString T_ENVIRON = tsLiteral ("environ" );
160-
161152 public static final TpSlots SLOTS = SSLContextBuiltinsSlotsGen .SLOTS ;
162153
163154 @ Override
@@ -618,27 +609,15 @@ static Object pha(@SuppressWarnings("unused") PSSLContext self) {
618609 @ Builtin (name = "set_default_verify_paths" , minNumOfPositionalArgs = 1 )
619610 @ GenerateNodeFactory
620611 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+
621615 @ Specialization
622616 Object set (VirtualFrame frame , PSSLContext self ,
623617 @ 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 ));
642621 if (file != null || path != null ) {
643622 LOGGER .fine (() -> String .format ("set_default_verify_paths file: %s. path: %s" , file != null ? file .getPath () : "None" , path != null ? path .getPath () : "None" ));
644623 try {
@@ -653,30 +632,13 @@ Object set(VirtualFrame frame, PSSLContext self,
653632 return PNone .NONE ;
654633 }
655634
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 {
674636 if (path == null ) {
675637 return null ;
676638 }
677639 TruffleFile file ;
678640 try {
679- file = getContext ().getEnv ().getPublicTruffleFile (toJavaStringNode . execute ( asPath .execute (frame , path )));
641+ file = getContext ().getEnv ().getPublicTruffleFile (asPath .execute (frame , path ). toJavaStringUncached ( ));
680642 if (!file .exists ()) {
681643 return null ;
682644 }
0 commit comments