@@ -3813,6 +3813,8 @@ class FileHash(Builtin):
38133813 <dt>'FileHash[$file$, $type$]'
38143814 <dd>returns an integer hash of the specified $type$ for the given $file$.</dd>
38153815 <dd>The types supported are "MD5", "Adler32", "CRC32", "SHA", "SHA224", "SHA256", "SHA384", and "SHA512".</dd>
3816+ <dt>'FileHash[$file$, $type$, $format$]'
3817+ <dd>gives a hash code in the specified format.</dd>
38163818 </dl>
38173819
38183820 >> FileHash["ExampleData/sunflowers.jpg"]
@@ -3841,19 +3843,20 @@ class FileHash(Builtin):
38413843 #> FileHash["ExampleData/sunflowers.jpg", xyzsymbol]
38423844 = FileHash[ExampleData/sunflowers.jpg, xyzsymbol]
38433845 #> FileHash["ExampleData/sunflowers.jpg", "xyzstr"]
3844- = FileHash[ExampleData/sunflowers.jpg, xyzstr]
3846+ = FileHash[ExampleData/sunflowers.jpg, xyzstr, Integer ]
38453847 #> FileHash[xyzsymbol]
38463848 = FileHash[xyzsymbol]
38473849 """
38483850
38493851 rules = {
3850- "FileHash[filename_String]" : 'FileHash[filename, "MD5"]' ,
3852+ "FileHash[filename_String]" : 'FileHash[filename, "MD5", "Integer"]' ,
3853+ "FileHash[filename_String, hashtype_String]" : 'FileHash[filename, hashtype, "Integer"]' ,
38513854 }
38523855
38533856 attributes = ("Protected" , "ReadProtected" )
38543857
3855- def apply (self , filename , hashtype , evaluation ):
3856- "FileHash[filename_String, hashtype_String]"
3858+ def apply (self , filename , hashtype , format , evaluation ):
3859+ "FileHash[filename_String, hashtype_String, format_String ]"
38573860 py_filename = filename .get_string_value ()
38583861
38593862 try :
@@ -3866,7 +3869,7 @@ def apply(self, filename, hashtype, evaluation):
38663869 e .message (evaluation )
38673870 return
38683871
3869- return Hash .compute (lambda update : update (dump ), hashtype .get_string_value ())
3872+ return Hash .compute (lambda update : update (dump ), hashtype .get_string_value (), format . get_string_value () )
38703873
38713874
38723875class FileDate (Builtin ):
@@ -4802,6 +4805,7 @@ def apply(self, pathname, evaluation):
48024805 return SymbolTrue
48034806 return SymbolFalse
48044807
4808+
48054809class Needs (Builtin ):
48064810 """
48074811 <dl>
@@ -4921,7 +4925,6 @@ def apply(self, context, evaluation):
49214925 curr_ctxt = evaluation .definitions .get_current_context ()
49224926 contextstr = curr_ctxt + contextstr [1 :]
49234927 context = String (contextstr )
4924-
49254928 if not valid_context_name (contextstr ):
49264929 evaluation .message ('Needs' , 'ctx' , Expression (
49274930 'Needs' , context ), 1 , '`' )
@@ -4931,19 +4934,11 @@ def apply(self, context, evaluation):
49314934 if test_loaded .is_true ():
49324935 # Already loaded
49334936 return SymbolNull
4934-
4935- # TODO: Figure out why this raises the message:
4936- # "Select::normal: Nonatomic expression expected."
4937- already_loaded = Expression ('MemberQ' ,
4938- Symbol ('System`$Packages' ), context )
4939- already_loaded = already_loaded .evaluate (evaluation ).is_true ()
4940- if already_loaded :
4941- return SymbolNull
4942-
49434937 result = Expression ('Get' , context ).evaluate (evaluation )
49444938
49454939 if result == SymbolFailed :
49464940 evaluation .message ("Needs" , "nocont" , context )
49474941 return SymbolFailed
49484942
49494943 return SymbolNull
4944+
0 commit comments