I'm sorry. The reason of error was in "display_name" property of "User" 
class (it is written in Unicode). So to see error log I have to logout.

Also 3 lines are required:

from paste.urlparser import StaticURLParser
from tg import config
import os

And of course we need a line inside RootController:

private = PrivateStatics()

But in the end I have 404 error...

Sorry for interruption...

четверг, 4 июля 2013 г., 16:51:41 UTC+4 пользователь Maxim Oganesyan 
написал:
>
> I found solution after "googling". After that I removed post (well, I can 
> remove post, but I can't stop email :) )
>
> My code is now:
>
> *from tg.controllers.tgcontroller import TGController                    
> from tg.controllers import WSGIAppController                            
>                                                                         
> class PrivateStatics(TGController):                                     
>     @expose()                                                           
>     def lookup(self, *args):                                            
>         site_dir = os.path.join(config.get('here'), '/myapp/private')
>         return WSGIAppController(StaticURLParser(site_dir)), args       
>                                                                         
>     _lookup = lookup                                                    *
>
> But when I try to get files using path "
> http://www.mysite.com/private/img.png"; I have another error:
>
> Traceback (most recent call last):
> File 
> "/www/tg2env/local/lib/python2.7/site-packages/Paste-1.7.5.1-py2.7.egg/paste/httpserver.py",
>  
> line 1068, in process_request_in_thread
> self.finish_request(request, client_address)
> File "/usr/lib/python2.7/SocketServer.py", line 323, in finish_request
> self.RequestHandlerClass(request, client_address, self)
> File "/usr/lib/python2.7/SocketServer.py", line 638, in __init__
> self.handle()
> File 
> "/www/tg2env/local/lib/python2.7/site-packages/Paste-1.7.5.1-py2.7.egg/paste/httpserver.py",
>  
> line 442, in handle
> BaseHTTPRequestHandler.handle(self)
> File "/usr/lib/python2.7/BaseHTTPServer.py", line 340, in handle
> self.handle_one_request()
> File 
> "/www/tg2env/local/lib/python2.7/site-packages/Paste-1.7.5.1-py2.7.egg/paste/httpserver.py",
>  
> line 437, in handle_one_request
> self.wsgi_execute()
> File 
> "/www/tg2env/local/lib/python2.7/site-packages/Paste-1.7.5.1-py2.7.egg/paste/httpserver.py",
>  
> line 287, in wsgi_execute
> self.wsgi_start_response)
> File 
> "/www/tg2env/local/lib/python2.7/site-packages/Paste-1.7.5.1-py2.7.egg/paste/cascade.py",
>  
> line 130, in __call__
> return self.apps[-1](environ, start_response)
> File 
> "/www/tg2env/local/lib/python2.7/site-packages/Paste-1.7.5.1-py2.7.egg/paste/registry.py",
>  
> line 379, in __call__ app_iter = self.application(environ, start_response)
> File 
> "/www/tg2env/local/lib/python2.7/site-packages/Pylons-1.0-py2.7.egg/pylons/middleware.py",
>  
> line 150, in __call__
> self.app, environ, catch_exc_info=True)
> File 
> "/www/tg2env/local/lib/python2.7/site-packages/Pylons-1.0-py2.7.egg/pylons/util.py",
>  
> line 48, in call_wsgi_application
> app_iter = application(environ, start_response)
> File 
> "/www/tg2env/local/lib/python2.7/site-packages/WebError-0.10.3-py2.7.egg/weberror/evalexception.py",
>  
> line 235, in __call__
> return self.respond(environ, start_response)
> File 
> "/www/tg2env/local/lib/python2.7/site-packages/WebError-0.10.3-py2.7.egg/weberror/evalexception.py",
>  
> line 483, in respond
> return debug_info.content()
> File 
> "/www/tg2env/local/lib/python2.7/site-packages/WebError-0.10.3-py2.7.egg/weberror/evalexception.py",
>  
> line 539, in content
> self.base_path, self.counter, self.libraries)
> File 
> "/www/tg2env/local/lib/python2.7/site-packages/WebError-0.10.3-py2.7.egg/weberror/evalexception.py",
>  
> line 657, in format_eval_html
> short_er, extra_data = short_formatter.format_collected_data(exc_data)
> File 
> "/www/tg2env/local/lib/python2.7/site-packages/WebError-0.10.3-py2.7.egg/weberror/formatter.py",
>  
> line 73, in format_collected_data
> importance, title, value)
> File 
> "/www/tg2env/local/lib/python2.7/site-packages/WebError-0.10.3-py2.7.egg/weberror/formatter.py",
>  
> line 345, in format_extra_data
> return self.zebra_table(title, value)
> File 
> "/www/tg2env/local/lib/python2.7/site-packages/WebError-0.10.3-py2.7.egg/weberror/formatter.py",
>  
> line 390, in zebra_table
> % make_wrappable(self.quote(truncate(value))))
> File 
> "/www/tg2env/local/lib/python2.7/site-packages/WebError-0.10.3-py2.7.egg/weberror/formatter.py",
>  
> line 295, in quote
> s = s.encode('latin1', 'htmlentityreplace')
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 279: 
> ordinal not in range(128)
>
> The same error was when I wrote Your part of code without importing 
> TGController and WSGIAppController.
> Looks like I missed something... :(
>
> четверг, 4 июля 2013 г., 16:16:14 UTC+4 пользователь Alessandro Molina 
> написал:
>>
>> Hi
>> Which version of turbogears? My solution is explicitly only for 
>> turbogears2. That might be the reason TGController is not available
>> Il giorno 04/lug/2013 12:59, "Maxim Oganesyan" <[email protected]> ha 
>> scritto:
>>
>>> Hi, Alessandro!
>>> I'm trying to use Your solution.
>>>
>>> I've got a question:
>>> from *????* import TGController 
>>>
>>> import TGController does not work...
>>>
>>> Best regards.
>>> Maxim.
>>>
>>> вторник, 19 июня 2012 г., 0:28:58 UTC+4 пользователь Alessandro Molina 
>>> написал:
>>>>
>>>> Static files are served by a middleware in the WSGI chain, 
>>>> this runs before the authentication layer got in, so it doesn't have 
>>>> any knowledge of users. 
>>>>
>>>> You can roll your own statics serving controller which checks users 
>>>> and so on, a minima solution can be: 
>>>>
>>>> class StaticsController(**TGController): 
>>>>     @expose() 
>>>>     def _lookup(self, *args): 
>>>>         return WSGIAppController(**StaticURLParser(statics_path))**, 
>>>> args 
>>>>
>>>> On Mon, Jun 18, 2012 at 2:39 PM, abc_coder <[email protected]> 
>>>> wrote: 
>>>> > Hi all 
>>>> > 
>>>> > I searched a lot but haven't found any solution. How can I in 
>>>> turgobears 2 
>>>> > restrict access to static files only for logged users? 
>>>> > I want add some protection from unlogged users and web robots. 
>>>> > 
>>>> > Please help. 
>>>> > 
>>>> > -- 
>>>> > You received this message because you are subscribed to the Google 
>>>> Groups 
>>>> > "TurboGears" group. 
>>>> > To view this discussion on the web visit 
>>>> > https://groups.google.com/d/**msg/turbogears/-/a6oOER4Ps3cJ<https://groups.google.com/d/msg/turbogears/-/a6oOER4Ps3cJ>.
>>>> >  
>>>>
>>>> > To post to this group, send email to [email protected]. 
>>>> > To unsubscribe from this group, send email to 
>>>> > turbogears+...@**googlegroups.com. 
>>>> > For more options, visit this group at 
>>>> > http://groups.google.com/**group/turbogears?hl=en<http://groups.google.com/group/turbogears?hl=en>.
>>>> >  
>>>>
>>>>
>>>  -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "TurboGears" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to [email protected].
>>> To post to this group, send email to [email protected].
>>> Visit this group at http://groups.google.com/group/turbogears.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>  
>>>  
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to