equal
deleted
inserted
replaced
72 import google |
72 import google |
73 from google.pyglib import gexcept |
73 from google.pyglib import gexcept |
74 |
74 |
75 from google.appengine.api import apiproxy_stub_map |
75 from google.appengine.api import apiproxy_stub_map |
76 from google.appengine.api import appinfo |
76 from google.appengine.api import appinfo |
|
77 from google.appengine.api import croninfo |
77 from google.appengine.api import datastore_admin |
78 from google.appengine.api import datastore_admin |
78 from google.appengine.api import datastore_file_stub |
79 from google.appengine.api import datastore_file_stub |
79 from google.appengine.api import mail_stub |
80 from google.appengine.api import mail_stub |
80 from google.appengine.api import urlfetch_stub |
81 from google.appengine.api import urlfetch_stub |
81 from google.appengine.api import user_service_stub |
82 from google.appengine.api import user_service_stub |
775 _root_path = None |
776 _root_path = None |
776 _application_paths = None |
777 _application_paths = None |
777 _skip_files = None |
778 _skip_files = None |
778 _static_file_config_matcher = None |
779 _static_file_config_matcher = None |
779 |
780 |
|
781 _allow_skipped_files = True |
|
782 |
780 _availability_cache = {} |
783 _availability_cache = {} |
781 |
784 |
782 @staticmethod |
785 @staticmethod |
783 def SetAllowedPaths(root_path, application_paths): |
786 def SetAllowedPaths(root_path, application_paths): |
784 """Configures which paths are allowed to be accessed. |
787 """Configures which paths are allowed to be accessed. |
798 for path in application_paths)) |
801 for path in application_paths)) |
799 FakeFile._application_paths.add(root_path) |
802 FakeFile._application_paths.add(root_path) |
800 |
803 |
801 FakeFile._root_path = os.path.join(root_path, '') |
804 FakeFile._root_path = os.path.join(root_path, '') |
802 |
805 |
|
806 FakeFile._availability_cache = {} |
|
807 |
|
808 @staticmethod |
|
809 def SetAllowSkippedFiles(allow_skipped_files): |
|
810 """Configures access to files matching FakeFile._skip_files |
|
811 |
|
812 Args: |
|
813 allow_skipped_files: Boolean whether to allow access to skipped files |
|
814 """ |
|
815 FakeFile._allow_skipped_files = allow_skipped_files |
803 FakeFile._availability_cache = {} |
816 FakeFile._availability_cache = {} |
804 |
817 |
805 @staticmethod |
818 @staticmethod |
806 def SetSkippedFiles(skip_files): |
819 def SetSkippedFiles(skip_files): |
807 """Sets which files in the application directory are to be ignored. |
820 """Sets which files in the application directory are to be ignored. |
875 """ |
888 """ |
876 if IsPathInSubdirectories(logical_filename, [FakeFile._root_path], |
889 if IsPathInSubdirectories(logical_filename, [FakeFile._root_path], |
877 normcase=normcase): |
890 normcase=normcase): |
878 relative_filename = logical_filename[len(FakeFile._root_path):] |
891 relative_filename = logical_filename[len(FakeFile._root_path):] |
879 |
892 |
880 if FakeFile._skip_files.match(relative_filename): |
893 if (not FakeFile._allow_skipped_files and |
|
894 FakeFile._skip_files.match(relative_filename)): |
881 logging.warning('Blocking access to skipped file "%s"', |
895 logging.warning('Blocking access to skipped file "%s"', |
882 logical_filename) |
896 logical_filename) |
883 return False |
897 return False |
884 |
898 |
885 if FakeFile._static_file_config_matcher.IsStaticFile(relative_filename): |
899 if FakeFile._static_file_config_matcher.IsStaticFile(relative_filename): |
2787 URLMap instances, this function will raise an InvalidAppConfigError |
2801 URLMap instances, this function will raise an InvalidAppConfigError |
2788 exception. |
2802 exception. |
2789 """ |
2803 """ |
2790 try: |
2804 try: |
2791 appinfo_file = file(appinfo_path, 'r') |
2805 appinfo_file = file(appinfo_path, 'r') |
2792 try: |
|
2793 return parse_app_config(appinfo_file) |
|
2794 finally: |
|
2795 appinfo_file.close() |
|
2796 except IOError, e: |
2806 except IOError, e: |
2797 raise InvalidAppConfigError( |
2807 raise InvalidAppConfigError( |
2798 'Application configuration could not be read from "%s"' % appinfo_path) |
2808 'Application configuration could not be read from "%s"' % appinfo_path) |
|
2809 try: |
|
2810 return parse_app_config(appinfo_file) |
|
2811 finally: |
|
2812 appinfo_file.close() |
2799 |
2813 |
2800 |
2814 |
2801 def CreateURLMatcherFromMaps(root_path, |
2815 def CreateURLMatcherFromMaps(root_path, |
2802 url_map_list, |
2816 url_map_list, |
2803 module_dict, |
2817 module_dict, |
2954 pass |
2968 pass |
2955 |
2969 |
2956 raise AppConfigNotFoundError |
2970 raise AppConfigNotFoundError |
2957 |
2971 |
2958 |
2972 |
|
2973 def ReadCronConfig(croninfo_path, parse_cron_config=croninfo.LoadSingleCron): |
|
2974 """Reads cron.yaml file and returns a list of CronEntry instances. |
|
2975 |
|
2976 Args: |
|
2977 croninfo_path: String containing the path to the cron.yaml file. |
|
2978 parse_cron_config: Used for dependency injection. |
|
2979 |
|
2980 Returns: |
|
2981 A CronInfoExternal object. |
|
2982 |
|
2983 Raises: |
|
2984 If the config file is unreadable, empty or invalid, this function will |
|
2985 raise an InvalidAppConfigError or a MalformedCronConfiguration exception. |
|
2986 """ |
|
2987 try: |
|
2988 croninfo_file = file(croninfo_path, 'r') |
|
2989 except IOError, e: |
|
2990 raise InvalidAppConfigError( |
|
2991 'Cron configuration could not be read from "%s"' % croninfo_path) |
|
2992 try: |
|
2993 return parse_cron_config(croninfo_file) |
|
2994 finally: |
|
2995 croninfo_file.close() |
|
2996 |
|
2997 |
2959 def SetupStubs(app_id, **config): |
2998 def SetupStubs(app_id, **config): |
2960 """Sets up testing stubs of APIs. |
2999 """Sets up testing stubs of APIs. |
2961 |
3000 |
2962 Args: |
3001 Args: |
2963 app_id: Application ID being served. |
3002 app_id: Application ID being served. |
3122 login_url, |
3161 login_url, |
3123 port, |
3162 port, |
3124 template_dir, |
3163 template_dir, |
3125 serve_address='', |
3164 serve_address='', |
3126 require_indexes=False, |
3165 require_indexes=False, |
|
3166 allow_skipped_files=False, |
3127 static_caching=True, |
3167 static_caching=True, |
3128 python_path_list=sys.path, |
3168 python_path_list=sys.path, |
3129 sdk_dir=os.path.dirname(os.path.dirname(google.__file__))): |
3169 sdk_dir=os.path.dirname(os.path.dirname(google.__file__))): |
3130 """Creates an new HTTPServer for an application. |
3170 """Creates an new HTTPServer for an application. |
3131 |
3171 |
3154 |
3194 |
3155 SetupTemplates(template_dir) |
3195 SetupTemplates(template_dir) |
3156 FakeFile.SetAllowedPaths(absolute_root_path, |
3196 FakeFile.SetAllowedPaths(absolute_root_path, |
3157 [sdk_dir, |
3197 [sdk_dir, |
3158 template_dir]) |
3198 template_dir]) |
|
3199 FakeFile.SetAllowSkippedFiles(allow_skipped_files) |
3159 |
3200 |
3160 handler_class = CreateRequestHandler(absolute_root_path, |
3201 handler_class = CreateRequestHandler(absolute_root_path, |
3161 login_url, |
3202 login_url, |
3162 require_indexes, |
3203 require_indexes, |
3163 static_caching) |
3204 static_caching) |