Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    New Coder
    Join Date
    May 2011
    Posts
    27
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question Reg Expression to Exclude the contents of a Single folder

    How can I exclude the contents of a folder using regular expressions.

    Here is the code of the appspot app.yaml code.
    Code:
    handlers:
    - url: /(.*\.(gif|png|jpg|ico|js|css))
      static_files: \1
      upload: (.*\.(gif|png|jpg|ico|js|css))
    
    - url: /robots.txt
      static_files: robots.txt
      upload: robots.txt 
    
    - url: /favicon.ico
      static_files: favicon.ico
      upload: favicon.ico
      
    - url: .*
      script: main.py
      
    
    error_handlers:
    - file: default_error.html
    
    - error_code: over_quota
      file: over_quota.html
    I want any "file not found" 404 error arising in the folder /Codebox to be applied by error_handlers at the bottom of the code. Since the code is read from top and all handlers have to come above the error_handlers, I want to modify the code of the handlers so that they exclude the contents of the folder /Codebox and so that any error arising from this folder will be taken care by the error_handlers.

    Please suggest a regexpression to exclude the contents of a single named folder. Thank you.

  • #2
    New Coder
    Join Date
    May 2011
    Posts
    27
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Lightbulb

    In other words Here is the directory list


    Webroot
    -dir_1
    -dir_2
    --subdir_a
    --subdir_b
    --subdir_c
    ...


    What will be the regex for all files and folders including those in the webroot but except the contents of subdir_a

    Please suggest.

  • #3
    Regular Coder
    Join Date
    May 2012
    Location
    France
    Posts
    224
    Thanks
    0
    Thanked 32 Times in 30 Posts
    Try
    Code:
       url: .*(?!subdir_a)
    But I do not know if this lookahead negative assertion are autorized in this language which is not javascript !

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,984
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Is this code Java? This is the JavaScript forum. Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Rather like Austria and Australia! Ask a mod to move this thread to the right forum.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Quote Originally Posted by Philip M View Post
    Is this code Java? This is the JavaScript forum. Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Rather like Austria and Australia! Ask a mod to move this thread to the right forum.
    Java?! It's actually YAML; but this is, more specifically, a (Python) server-configuration file.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #6
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    @Mayancode
    Sorry, mis-information deleted!
    Last edited by AndrewGSW; 12-09-2012 at 04:20 PM.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #7
    New Coder
    Join Date
    May 2011
    Posts
    27
    Thanks
    4
    Thanked 0 Times in 0 Posts
    @julien that is not working and you are right since it is not javascript regex.

    @Phillip Thanks, I am aware of the old saying "as car is to carpet, java is to javascript". I just could not find a forum matching its language...

    @Andy You are right, this is a python server configuration file... I was wrong in thinking the regex would be similar to javascript.. I have found the documentation here http://docs.python.org/2/library/re.html but I am still not able to make out a code which will let the errors arising in a specific folder to be handled by error_hander... All I want the code to be is to exclude folder /Codebox and its contents in the expressions used in the top part of the code which are handled by handlers

  • #8
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Code:
    - url: /dir_2/subdir_a
      script: yourscript.py
    # or perhaps
    Code:
    - url: /dir_2/subdir_a/.*
      script: yourscript.py
    would redirect (as I understand..) requests to this subfolder to a Python script named yourscript.py, which you would need to create. Reference I'm looking at.
    Code:
    error_handlers:
    - file: default_error.html
    .. would redirect any 404 (or other) errors to the page default_error.html. You might redirect to a .py or .php (but I assume Python is your server-side language?). The page that is redirected to could contain a script to provide different content according to the page requested.

    But this is the extent of my understanding.. and I may be wrong

    Added If you are looking to exclude a folder then 007julien has provided an example using a negative lookahead assertion. That is to say, "does not have this text". I do not know either, whether such a construct is acceptable within your configuration file.
    Last edited by AndrewGSW; 12-09-2012 at 06:27 PM.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • Users who have thanked AndrewGSW for this post:

    Mayankode (12-10-2012)

  • #9
    New Coder
    Join Date
    May 2011
    Posts
    27
    Thanks
    4
    Thanked 0 Times in 0 Posts
    @Andy the script you suggested would work if I were having a python script (ex: errorhandling.py ) But I am not having any knowledge of python and so I would give up to adopt any alternative.

    If only I could make sure non of the regex in the handlers referred to the particular folder /Codebox then I could assign error_handlers:
    - file: default_error.html
    as suggested here https://developers.google.com/appeng...rror_Responses

  • #10
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    What do you want it to do when someone visits /Codebox ?
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #11
    New Coder
    Join Date
    May 2011
    Posts
    27
    Thanks
    4
    Thanked 0 Times in 0 Posts
    If someone goes to /Codebox/xyz.html then it should show them the page but ANY other address combination inside the Codebox directory such as /Codebox/superman.html should take him to a predefined 404.html page in located in the root directory. Do you think it is possible in the configuration file ?

  • #12
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Until you find a proper solution you could perhaps add this code to your default 404 page so that it redirects to your alternative 404:

    Code:
    if (document.referrer.indexOf('Codebox') + 1) {
        location.href = "/someother404.html";
    }
    I do not know if your requirement is possible in the configuration file - never seen it before today
    Last edited by AndrewGSW; 12-10-2012 at 12:50 AM.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #13
    New Coder
    Join Date
    May 2011
    Posts
    27
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I dont have the default 404page with me either... the 404 error is just a system generated cluttered python data ! I dont know editing the main.py file either... May be we should consider for an alternative...

  • #14
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Quote Originally Posted by Mayankode View Post
    I dont have the default 404page with me either... the 404 error is just a system generated cluttered python data ! I dont know editing the main.py file either... May be we should consider for an alternative...
    Can you not create your own 404 page? That is the whole idea after all..

    I wouldn't know if main.py is a general page over which you have no control, or whether you are allowed to create or modify your own version of this (it may not even exist!?).

    If you are able to track down your copy of this file (on your server's domain somewhere I assume) then I could have a gander at it. But I suspect that creating your own 404 page is the way to go.

    [I thought "lookahead negative assertion" was quite witty, in a reciprocal way?! Maybe its just me ]
    Last edited by AndrewGSW; 12-10-2012 at 01:18 AM.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #15
    New Coder
    Join Date
    May 2011
    Posts
    27
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Here is the code of main.py

    and it sits in the root and is editable very well.. Please take a look, I am sure this is the key to our solution...

    the filestructure is
    Webroot
    -index.html (my static homepage)
    -gate.html (the static pop up )
    -app.yaml
    -index.yaml
    -main.py
    -...
    -Codebox
    --xyz.html (refered to as treasure)


    The main.py code
    Code:
    import os
    from google.appengine.ext import webapp
    from google.appengine.ext.webapp import util
    from google.appengine.ext.webapp import template
    
    class MainHandler(webapp.RequestHandler):
      def get (self, q):
        if q is None:
          q = 'index.html'
    
        path = os.path.join (os.path.dirname (__file__), q)
        self.response.headers ['Content-Type'] = 'text/html'
        self.response.out.write (template.render (path, {}))
    
    def main ():
      application = webapp.WSGIApplication ([('/(.*html)?', MainHandler)], debug=True)
      util.run_wsgi_app (application)
    
    if __name__ == '__main__':
      main ()


  •  
    Page 1 of 2 12 LastLast

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •