Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-08-2012, 11:21 PM   PM User | #1
Mayankode
New Coder

 
Join Date: May 2011
Posts: 27
Thanks: 4
Thanked 0 Times in 0 Posts
Mayankode is an unknown quantity at this point
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.
Mayankode is offline   Reply With Quote
Old 12-09-2012, 12:14 PM   PM User | #2
Mayankode
New Coder

 
Join Date: May 2011
Posts: 27
Thanks: 4
Thanked 0 Times in 0 Posts
Mayankode is an unknown quantity at this point
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.
Mayankode is offline   Reply With Quote
Old 12-09-2012, 01:26 PM   PM User | #3
007julien
Regular Coder

 
Join Date: May 2012
Location: France
Posts: 121
Thanks: 0
Thanked 18 Times in 16 Posts
007julien is an unknown quantity at this point
Try
Code:
   url: .*(?!subdir_a)
But I do not know if this lookahead negative assertion are autorized in this language which is not javascript !
007julien is online now   Reply With Quote
Old 12-09-2012, 03:32 PM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,100
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Old 12-09-2012, 04:09 PM   PM User | #5
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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
AndrewGSW is offline   Reply With Quote
Old 12-09-2012, 04:12 PM   PM User | #6
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
@Mayancode
Sorry, mis-information deleted!
__________________
"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

Last edited by AndrewGSW; 12-09-2012 at 04:20 PM..
AndrewGSW is offline   Reply With Quote
Old 12-09-2012, 05:09 PM   PM User | #7
Mayankode
New Coder

 
Join Date: May 2011
Posts: 27
Thanks: 4
Thanked 0 Times in 0 Posts
Mayankode is an unknown quantity at this point
@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
Mayankode is offline   Reply With Quote
Old 12-09-2012, 06:16 PM   PM User | #8
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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.
__________________
"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

Last edited by AndrewGSW; 12-09-2012 at 06:27 PM..
AndrewGSW is offline   Reply With Quote
Users who have thanked AndrewGSW for this post:
Mayankode (12-10-2012)
Old 12-09-2012, 11:54 PM   PM User | #9
Mayankode
New Coder

 
Join Date: May 2011
Posts: 27
Thanks: 4
Thanked 0 Times in 0 Posts
Mayankode is an unknown quantity at this point
@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
Mayankode is offline   Reply With Quote
Old 12-10-2012, 12:19 AM   PM User | #10
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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
AndrewGSW is offline   Reply With Quote
Old 12-10-2012, 12:28 AM   PM User | #11
Mayankode
New Coder

 
Join Date: May 2011
Posts: 27
Thanks: 4
Thanked 0 Times in 0 Posts
Mayankode is an unknown quantity at this point
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 ?
Mayankode is offline   Reply With Quote
Old 12-10-2012, 12:42 AM   PM User | #12
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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
__________________
"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

Last edited by AndrewGSW; 12-10-2012 at 12:50 AM..
AndrewGSW is offline   Reply With Quote
Old 12-10-2012, 12:53 AM   PM User | #13
Mayankode
New Coder

 
Join Date: May 2011
Posts: 27
Thanks: 4
Thanked 0 Times in 0 Posts
Mayankode is an unknown quantity at this point
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...
Mayankode is offline   Reply With Quote
Old 12-10-2012, 01:14 AM   PM User | #14
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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 ]
__________________
"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

Last edited by AndrewGSW; 12-10-2012 at 01:18 AM..
AndrewGSW is offline   Reply With Quote
Old 12-10-2012, 01:45 AM   PM User | #15
Mayankode
New Coder

 
Join Date: May 2011
Posts: 27
Thanks: 4
Thanked 0 Times in 0 Posts
Mayankode is an unknown quantity at this point
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 ()
Mayankode is offline   Reply With Quote
Reply

Bookmarks

Tags
regular expressions

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:18 PM.


Advertisement
Log in to turn off these ads.