Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #48354 > unrolled thread

Why 'files.py' does not print the filenames into a table format?

Started byNick the Gr33k <support@superhost.gr>
First post2013-06-15 22:38 +0300
Last post2013-06-16 05:57 -0700
Articles 17 on this page of 37 — 15 participants

Back to article view | Back to comp.lang.python


Contents

  Why 'files.py' does not print the filenames into a table format? Nick the Gr33k <support@superhost.gr> - 2013-06-15 22:38 +0300
    Re: Why 'files.py' does not print the filenames into a table format? Jarrod Henry <jarrodhenry@gmail.com> - 2013-06-15 14:46 -0500
      Re: Why 'files.py' does not print the filenames into a table format? Nick the Gr33k <support@superhost.gr> - 2013-06-15 22:51 +0300
        Re: Why 'files.py' does not print the filenames into a table format? Benjamin Schollnick <benjamin@schollnick.net> - 2013-06-15 16:29 -0400
        Re: Why 'files.py' does not print the filenames into a table format? Joshua Landau <joshua.landau.ws@gmail.com> - 2013-06-15 21:37 +0100
          Re: Why 'files.py' does not print the filenames into a table format? Νίκος <support@superhost.gr> - 2013-06-17 08:58 +0300
            Re: Why 'files.py' does not print the filenames into a table format? Νίκος <support@superhost.gr> - 2013-06-17 09:11 +0300
              Re: Why 'files.py' does not print the filenames into a table format? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-17 07:00 +0000
                Re: Why 'files.py' does not print the filenames into a table format? Simpleton <support@superhost.gr> - 2013-06-17 12:07 +0300
                  Re: Why 'files.py' does not print the filenames into a table format? Simpleton <support@superhost.gr> - 2013-06-17 12:18 +0300
                  Re: Why 'files.py' does not print the filenames into a table format? Simpleton <support@superhost.gr> - 2013-06-17 13:26 +0300
        Re: Why 'files.py' does not print the filenames into a table format? Chris Angelico <rosuav@gmail.com> - 2013-06-16 08:51 +1000
          Re: Why 'files.py' does not print the filenames into a table format? Nick the Gr33k <support@superhost.gr> - 2013-06-16 04:07 +0300
            Python Greek mailing list [was Re: Why 'files.py' does not print the filenames into a table format?] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-16 05:06 +0000
              Re: Python Greek mailing list [was Re: Why 'files.py' does not print the filenames into a table format?] Nick the Gr33k <support@superhost.gr> - 2013-06-16 11:28 +0300
                Re: Python Greek mailing list [was Re: Why 'files.py' does not print the filenames into a table format?] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-16 10:33 +0000
                  Re: Python Greek mailing list [was Re: Why 'files.py' does not print the filenames into a table format?] Ferrous Cranus <support@superhost.gr> - 2013-06-16 13:57 +0300
                    Re: Python Greek mailing list [was Re: Why 'files.py' does not print the filenames into a table format?] Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-06-16 12:09 +0100
                      Re: Python Greek mailing list [was Re: Why 'files.py' does not print the filenames into a table format?] Ferrous Cranus <support@superhost.gr> - 2013-06-16 14:12 +0300
                    Re: Python Greek mailing list [was Re: Why 'files.py' does not print the filenames into a table format?] Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2013-06-16 13:19 +0200
                  Re: Python Greek mailing list [was Re: Why 'files.py' does not print the filenames into a table format?] Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2013-06-16 13:03 +0200
            Re: Why 'files.py' does not print the filenames into a table format? Ferrous Cranus <support@superhost.gr> - 2013-06-16 16:57 +0300
          Re: Why 'files.py' does not print the filenames into a table format? Nick the Gr33k <support@superhost.gr> - 2013-06-16 04:10 +0300
          Re: Why 'files.py' does not print the filenames into a table format? Nick the Gr33k <support@superhost.gr> - 2013-06-16 04:24 +0300
        Re: Why 'files.py' does not print the filenames into a table format? Grant Edwards <invalid@invalid.invalid> - 2013-06-17 14:50 +0000
    Re: Why 'files.py' does not print the filenames into a table format? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-06-15 22:29 +0100
      Re: Why 'files.py' does not print the filenames into a table format? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-16 00:10 +0000
        Re: Why 'files.py' does not print the filenames into a table format? alex23 <wuwei23@gmail.com> - 2013-06-16 17:04 -0700
          Re: Why 'files.py' does not print the filenames into a table format? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-06-17 01:31 +0100
      Re: Why 'files.py' does not print the filenames into a table format? Nick the Gr33k <support@superhost.gr> - 2013-06-16 04:03 +0300
        Re: Why 'files.py' does not print the filenames into a table format? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-06-16 02:10 +0100
          Re: Why 'files.py' does not print the filenames into a table format? Nick the Gr33k <support@superhost.gr> - 2013-06-16 04:28 +0300
    Re: Why 'files.py' does not print the filenames into a table format? Denis McMahon <denismfmcmahon@gmail.com> - 2013-06-16 07:23 +0000
      Re: Why 'files.py' does not print the filenames into a table format? Nick the Gr33k <support@superhost.gr> - 2013-06-16 11:35 +0300
        Re: Why 'files.py' does not print the filenames into a table format? Denis McMahon <denismfmcmahon@gmail.com> - 2013-06-16 08:55 +0000
        Re: Why 'files.py' does not print the filenames into a table format? Ferrous Cranus <support@superhost.gr> - 2013-06-16 16:59 +0300
    Re: Why 'files.py' does not print the filenames into a table format? jmfauth <wxjmfauth@gmail.com> - 2013-06-16 05:57 -0700

Page 2 of 2 — ← Prev page 1 [2]


#48434 — Re: Python Greek mailing list [was Re: Why 'files.py' does not print the filenames into a table format?]

FromChris “Kwpolska” Warrick <kwpolska@gmail.com>
Date2013-06-16 13:03 +0200
SubjectRe: Python Greek mailing list [was Re: Why 'files.py' does not print the filenames into a table format?]
Message-ID<mailman.3435.1371380660.3114.python-list@python.org>
In reply to#48428
On Sun, Jun 16, 2013 at 12:33 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
>
> On Sun, 16 Jun 2013 11:28:00 +0300, Nick the Gr33k wrote:
>
> > On 16/6/2013 8:06 πμ, Steven D'Aprano wrote:
> >> Nikos,
> >>
> >> Have you considered subscribing to this?
> >>
> >> http://mail.python.org/mailman/listinfo/python-greece
>
> [...]
> > I prefer staying here but i can also subscribe there as well if you teel
> > me what the groups name.
>
> Nikos, this is exactly the sort of thing that makes it painful to try to
> help you. I've given you the URL. The name of the list is in the URL, and
> even if it isn't, you can just click on it and see for yourself.
>
> Let me repeat the URL in case you cannot see it above:
>
> http://mail.python.org/mailman/listinfo/python-greece

Nikos wants Usenet:

> Thank you Steven i don't want to enter there as mail but wish to find it as a newsgroups, which i tried to subscribe but TB couldn't find it.

--
Kwpolska <http://kwpolska.tk> | GPG KEY: 5EAAEA16
stop html mail                | always bottom-post
http://asciiribbon.org        | http://caliburn.nl/topposting.html

[toc] | [prev] | [next] | [standalone]


#48454

FromFerrous Cranus <support@superhost.gr>
Date2013-06-16 16:57 +0300
Message-ID<kpkg94$1bva$1@news.ntua.gr>
In reply to#48393
On 16/6/2013 4:07 πμ, Nick the Gr33k wrote:
> On 16/6/2013 1:51 πμ, Chris Angelico wrote:
>> On Sun, Jun 16, 2013 at 6:29 AM, Benjamin Schollnick
>> <benjamin@schollnick.net> wrote:
>>> cur.execute('''SELECT ID FROM counters WHERE url = %s''', page )
>>> cur.execute('''INSERT INTO counters (url) VALUES (%s)''', page )
>>>
>>> Sure, whoever wrote that code is a fool.
>>>
>>> http://xkcd.com/327/
>>>
>>> They didn't sanitize your database inputs.
>>
>> I assume you're talking about the above two lines of code? They're not
>> SQL injection targets.
>
> Then how those page entries found in the database Chris?
>
>> The clue is that the %s isn't in quotes.
>
> What happens if i write it like this?
>
> cur.execute('''SELECT ID FROM counters WHERE url = "%s"''', page )
>
> How quoting of %s helps here?
>
>> This is an out-of-band argument passing method (actually, since he's
>> using
>> MySQL (IIRC), it's probably just going to escape it and pass it on
>> through, but it comes to the same thing), so it's safe.
>
> Yes iam using a comma and not a substitute operator, so input is mysql
> validates.
>
> Please explain what is an "out-of-band argument passing method"
>
> What your idea of those entries made it to the counters database table?
>
>

Chris? Care to explain please?

-- 
What is now proved was at first only imagined!

[toc] | [prev] | [next] | [standalone]


#48394

FromNick the Gr33k <support@superhost.gr>
Date2013-06-16 04:10 +0300
Message-ID<kpj3a8$1j17$5@news.ntua.gr>
In reply to#48381
On 16/6/2013 1:51 πμ, Chris Angelico wrote:
> On Sun, Jun 16, 2013 at 6:29 AM, Benjamin Schollnick
> <benjamin@schollnick.net> wrote:
>> cur.execute('''SELECT ID FROM counters WHERE url = %s''', page )
>> cur.execute('''INSERT INTO counters (url) VALUES (%s)''', page )
>>
>> Sure, whoever wrote that code is a fool.
>>
>> http://xkcd.com/327/
>>
>> They didn't sanitize your database inputs.
>
> I assume you're talking about the above two lines of code? They're not
> SQL injection targets. The clue is that the %s isn't in quotes. This
> is an out-of-band argument passing method (actually, since he's using
> MySQL (IIRC), it's probably just going to escape it and pass it on
> through, but it comes to the same thing), so it's safe.
>
> ChrisA
>

Chris or someone else please explain a bit whats happening here because 
that list is getting bigger and bigger as we speak.

look: http://superhost.gr/?show=stats

At least i have secured 'pelatologio.py' form prying eyes.

-- 
What is now proved was at first only imagined!

[toc] | [prev] | [next] | [standalone]


#48395

FromNick the Gr33k <support@superhost.gr>
Date2013-06-16 04:24 +0300
Message-ID<kpj449$1j17$6@news.ntua.gr>
In reply to#48381
On 16/6/2013 1:51 πμ, Chris Angelico wrote:
> On Sun, Jun 16, 2013 at 6:29 AM, Benjamin Schollnick
> <benjamin@schollnick.net> wrote:
>> cur.execute('''SELECT ID FROM counters WHERE url = %s''', page )
>> cur.execute('''INSERT INTO counters (url) VALUES (%s)''', page )
>>
>> Sure, whoever wrote that code is a fool.
>>
>> http://xkcd.com/327/
>>
>> They didn't sanitize your database inputs.
>
> I assume you're talking about the above two lines of code? They're not
> SQL injection targets. The clue is that the %s isn't in quotes. This
> is an out-of-band argument passing method (actually, since he's using
> MySQL (IIRC), it's probably just going to escape it and pass it on
> through, but it comes to the same thing), so it's safe.
>
> ChrisA
>

Here is how i think i have dealt with it:

=================
path = '/home/nikos/public_html/'
cgi_path = '/home/nikos/public_html/cgi-bin/'

file = form.getvalue('file')	# this comes from .htaccess
page = form.getvalue('page')	# this comes form index.html or metrites.py

if not page and os.path.exists( file ):
	# it is an html template
	page = file.replace( path, '' )

.....
.....

#find the needed counter for the page URL
if os.path.exists( path + page ) or os.path.exists( cgi_path + page ):
	cur.execute('''SELECT ID FROM counters WHERE url = %s''', page )
	data = cur.fetchone()		#URL is unique

==================

Do you think i'am sfae now from those kind of attacks?
Do you see some other way, better, to write the above?
-- 
What is now proved was at first only imagined!

[toc] | [prev] | [next] | [standalone]


#48521

FromGrant Edwards <invalid@invalid.invalid>
Date2013-06-17 14:50 +0000
Message-ID<kpn7o8$qha$2@reader1.panix.com>
In reply to#48357
On 2013-06-15, Nick the Gr33k <support@superhost.gr> wrote:
> On 15/6/2013 10:46 ??, Jarrod Henry wrote:
>> Nick, at this point, you need to hire someone to do your work for you.
>
> The code is completely ready.

OK.  Good-bye then.

-- 
Grant Edwards               grant.b.edwards        Yow! Th' MIND is the Pizza
                                  at               Palace of th' SOUL
                              gmail.com            

[toc] | [prev] | [next] | [standalone]


#48373

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2013-06-15 22:29 +0100
Message-ID<mailman.3412.1371331806.3114.python-list@python.org>
In reply to#48354
On 15/06/2013 20:38, Nick the Gr33k wrote:
>
> Thank you and please whoever does not feel like helping, please at least
> not spam the thread.
>

Your arrogance clearly has no bounds.  This is a public forum and people 
can say what they like.  You've wasted enough time as it is, so why 
don't you simply bugger off.

-- 
"Steve is going for the pink ball - and for those of you who are 
watching in black and white, the pink is next to the green." Snooker 
commentator 'Whispering' Ted Lowe.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#48389

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2013-06-16 00:10 +0000
Message-ID<51bd0273$0$29997$c3e8da3$5496439d@news.astraweb.com>
In reply to#48373
On Sat, 15 Jun 2013 22:29:29 +0100, Mark Lawrence wrote:

> Your arrogance clearly has no bounds.  This is a public forum and people
> can say what they like.  You've wasted enough time as it is, so why
> don't you simply bugger off.

Congratulation. You have just entered an extremely exclusive club. See 
you in a month.


*plonk*


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#48486

Fromalex23 <wuwei23@gmail.com>
Date2013-06-16 17:04 -0700
Message-ID<58b6d6f3-a57b-4b46-9f94-4aa5fce3375e@mq5g2000pbb.googlegroups.com>
In reply to#48389
On Jun 16, 10:10 am, Steven D'Aprano <steve
+comp.lang.pyt...@pearwood.info> wrote:
> Congratulation. You have just entered an extremely exclusive club. See
> you in a month.
>
> *plonk*

So yours are the only pissy one-liner responses that shouldn't be
taken off-list?

[toc] | [prev] | [next] | [standalone]


#48487

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2013-06-17 01:31 +0100
Message-ID<mailman.3464.1371429308.3114.python-list@python.org>
In reply to#48486
On 17/06/2013 01:04, alex23 wrote:
> On Jun 16, 10:10 am, Steven D'Aprano <steve
> +comp.lang.pyt...@pearwood.info> wrote:
>> Congratulation. You have just entered an extremely exclusive club. See
>> you in a month.
>>
>> *plonk*
>
> So yours are the only pissy one-liner responses that shouldn't be
> taken off-list?
>

I suggest caution, Big Brother is watching *YOU* :)

-- 
"Steve is going for the pink ball - and for those of you who are 
watching in black and white, the pink is next to the green." Snooker 
commentator 'Whispering' Ted Lowe.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#48392

FromNick the Gr33k <support@superhost.gr>
Date2013-06-16 04:03 +0300
Message-ID<kpj2sp$1j17$3@news.ntua.gr>
In reply to#48373
On 16/6/2013 12:29 πμ, Mark Lawrence wrote:
> On 15/06/2013 20:38, Nick the Gr33k wrote:
>>
>> Thank you and please whoever does not feel like helping, please at least
>> not spam the thread.
>>

> Your arrogance clearly has no bounds.

Your spamming to my threads in an unproductive and yet bitching way has 
no bounds either.

>This is a public forum

Yes it is.

>and people can say what they like.

Only if its relative to the OP's question, otherwise its trolling to an 
other's person thread.

> You've wasted enough time as it is, so why don't you simply bugger off.

The only time i'm wasting is that of folk's trying to respond to my 
questions.

You are the one that wants to waste his time if you take the time and 
read my posts and also take more time to bitch-respond.

I said to you and others before. Kill-file me, or mute my threads or 
ignore me if you do not like me and my questions.



-- 
What is now proved was at first only imagined!

[toc] | [prev] | [next] | [standalone]


#48396

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2013-06-16 02:10 +0100
Message-ID<mailman.3421.1371345071.3114.python-list@python.org>
In reply to#48392
On 16/06/2013 02:03, Nick the Gr33k wrote:
> On 16/6/2013 12:29 πμ, Mark Lawrence wrote:
>> On 15/06/2013 20:38, Nick the Gr33k wrote:
>>>
>>> Thank you and please whoever does not feel like helping, please at least
>>> not spam the thread.
>>>
>
>> Your arrogance clearly has no bounds.
>
> Your spamming to my threads in an unproductive and yet bitching way has
> no bounds either.
>
>> This is a public forum
>
> Yes it is.
>
>> and people can say what they like.
>
> Only if its relative to the OP's question, otherwise its trolling to an
> other's person thread.
>
>> You've wasted enough time as it is, so why don't you simply bugger off.
>
> The only time i'm wasting is that of folk's trying to respond to my
> questions.
>
> You are the one that wants to waste his time if you take the time and
> read my posts and also take more time to bitch-respond.
>
> I said to you and others before. Kill-file me, or mute my threads or
> ignore me if you do not like me and my questions.
>

I have no intention of kill-filing you, muting your threads or ignoring 
you.  I do intend hounding you until with any luck you crawl off into a 
hole somewhere and leave this group in peace.

-- 
"Steve is going for the pink ball - and for those of you who are 
watching in black and white, the pink is next to the green." Snooker 
commentator 'Whispering' Ted Lowe.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#48397

FromNick the Gr33k <support@superhost.gr>
Date2013-06-16 04:28 +0300
Message-ID<kpj4cd$1j17$7@news.ntua.gr>
In reply to#48396
On 16/6/2013 4:10 πμ, Mark Lawrence wrote:
> I have no intention of kill-filing you, muting your threads or ignoring
> you.  I do intend hounding you until with any luck you crawl off into a
> hole somewhere and leave this group in peace.

No such luck i'm afraid for you.
And it seems to me that you are the one that doesn't leave this group in 
piece, not me.


ps to other members: Is there any way in ThunderBird that i kill file 
Mark? Never have to used kill-filing before but i'll start now.

-- 
What is now proved was at first only imagined!

[toc] | [prev] | [next] | [standalone]


#48417

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2013-06-16 07:23 +0000
Message-ID<kpjp52$4rb$2@dont-email.me>
In reply to#48354
On Sat, 15 Jun 2013 22:38:38 +0300, Nick the Gr33k wrote:

> PLEASE take a look, its not a huge code

First, you need to start writing your code to less than 80 columns if 
you're going to keep posting it to usenet. I'm sure I'm not the only 
person who can't be bothered to unwrap it.

Secondly, the code you posted only tells part of the story - it's 
obviously missing either relevant imports or defined functions or 
possibly both.

Third, it would help to see examples of (a) what you expect it to 
generate, and (b) what it actually generates. You obviously have a web 
server available to you - you could put both code (just append .txt to 
the filename) and screenshots from your browser there with no difficulty 
at all and just include links.

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#48421

FromNick the Gr33k <support@superhost.gr>
Date2013-06-16 11:35 +0300
Message-ID<kpjtc0$hmp$4@news.ntua.gr>
In reply to#48417
On 16/6/2013 10:23 πμ, Denis McMahon wrote:
> On Sat, 15 Jun 2013 22:38:38 +0300, Nick the Gr33k wrote:
>
>> PLEASE take a look, its not a huge code
>
> First, you need to start writing your code to less than 80 columns if
> you're going to keep posting it to usenet. I'm sure I'm not the only
> person who can't be bothered to unwrap it.

TB behaves for me the same way. Any line > 80 chars gets a newline.
Why this is happening? Why not post up to 256 chars in a single line?

> Secondly, the code you posted only tells part of the story - it's
> obviously missing either relevant imports or defined functions or
> possibly both.
>
> Third, it would help to see examples of (a) what you expect it to
> generate, and (b) what it actually generates. You obviously have a web
> server available to you - you could put both code (just append .txt to
> the filename) and screenshots from your browser there with no difficulty
> at all and just include links.
>
Actually i twas a short story since i have asked this already in 2 
previous threads of mine,  but here it is the whole thing pasted in 
pastebin. Its not so biug and with your talent you could understand it 
in aprox. 5 mins.

http://pastebin.com/XgWKuXUC
-- 
What is now proved was at first only imagined!

[toc] | [prev] | [next] | [standalone]


#48422

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2013-06-16 08:55 +0000
Message-ID<kpjuhh$4rb$5@dont-email.me>
In reply to#48421
On Sun, 16 Jun 2013 11:35:12 +0300, Nick the Gr33k wrote:

> TB behaves for me the same way. Any line > 80 chars gets a newline. Why
> this is happening? Why not post up to 256 chars in a single line?

Because this is usenet. Read the RFCs if you must know!

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#48455

FromFerrous Cranus <support@superhost.gr>
Date2013-06-16 16:59 +0300
Message-ID<kpkgbq$1bva$2@news.ntua.gr>
In reply to#48421
On 16/6/2013 11:35 πμ, Nick the Gr33k wrote:
> On 16/6/2013 10:23 πμ, Denis McMahon wrote:
>> On Sat, 15 Jun 2013 22:38:38 +0300, Nick the Gr33k wrote:
>>
>>> PLEASE take a look, its not a huge code
>>
>> First, you need to start writing your code to less than 80 columns if
>> you're going to keep posting it to usenet. I'm sure I'm not the only
>> person who can't be bothered to unwrap it.
>
> TB behaves for me the same way. Any line > 80 chars gets a newline.
> Why this is happening? Why not post up to 256 chars in a single line?
>
>> Secondly, the code you posted only tells part of the story - it's
>> obviously missing either relevant imports or defined functions or
>> possibly both.
>>
>> Third, it would help to see examples of (a) what you expect it to
>> generate, and (b) what it actually generates. You obviously have a web
>> server available to you - you could put both code (just append .txt to
>> the filename) and screenshots from your browser there with no difficulty
>> at all and just include links.
>>
> Actually i twas a short story since i have asked this already in 2
> previous threads of mine,  but here it is the whole thing pasted in
> pastebin. Its not so biug and with your talent you could understand it
> in aprox. 5 mins.
>
> http://pastebin.com/XgWKuXUC

Someone saw something that will help explain why the utf-8 converted 
filenames refuse to appear?

-- 
What is now proved was at first only imagined!

[toc] | [prev] | [next] | [standalone]


#48447

Fromjmfauth <wxjmfauth@gmail.com>
Date2013-06-16 05:57 -0700
Message-ID<f711cf6b-5899-4772-ac43-1efe987e18d0@q8g2000vbl.googlegroups.com>
In reply to#48354
On 15 juin, 21:38, Nick the Gr33k <supp...@superhost.gr> wrote:
> Hello,
>
> Trying to browsehttp://superhost.gr/?page=files.pywith tailing -F of
> the error_log i noticed that error log outputs no error!
>
> So that means that the script is correct.
>
> here are the directory app's files.
>
> ni...@superhost.gr [~/www/data/apps]# ls -l
> total 412788
> drwxr-xr-x 2 nikos nikos     4096 Jun 12 12:03 ./
> drwxr-xr-x 6 nikos nikos     4096 May 26 21:13 ../
> -rwxr-xr-x 1 nikos nikos 13157283 Mar 17 12:57 100\ Mythoi\ tou\
> Aiswpou.pdf*
> -rwxr-xr-x 1 nikos nikos 29524686 Mar 11 18:17 Anekdotologio.exe*
> -rw-r--r-- 1 nikos nikos 42413964 Jun  2 20:29 Battleship.exe
> -rw-r--r-- 1 nikos nikos 51819750 Jun  2 20:04 Luxor\ Evolved.exe
> -rw-r--r-- 1 nikos nikos 60571648 Jun  2 14:59 Monopoly.exe
> -rwxr-xr-x 1 nikos nikos  1788164 Mar 14 11:31 Online\ Movie\ Player.zip*
> -rw-r--r-- 1 nikos nikos  5277287 Jun  1 18:35 O\ Nomos\ tou\ Merfy\
> v1-2-3.zip
> -rwxr-xr-x 1 nikos nikos 16383001 Jun 22  2010 Orthodoxo\ Imerologio.exe*
> -rw-r--r-- 1 nikos nikos  6084806 Jun  1 18:22 Pac-Man.exe
> -rw-r--r-- 1 nikos nikos 45297713 Jun 10 12:38 Raptor\ Chess.exe
> -rw-r--r-- 1 nikos nikos 25476584 Jun  2 19:50 Scrabble.exe
> -rwxr-xr-x 1 nikos nikos 49141166 Mar 17 12:48 To\ 1o\ mou\ vivlio\ gia\
> to\ skaki.pdf*
> -rwxr-xr-x 1 nikos nikos  3298310 Mar 17 12:45 Vivlos\ gia\ Atheofovous.pdf*
> -rw-r--r-- 1 nikos nikos  1764864 May 29 21:50 V-Radio\ v2.4.msi
> -rw-r--r-- 1 nikos nikos  3511233 Jun  4 14:11 Ευχή\ του\ Ιησού.mp3
> -rwxr-xr-x 1 nikos nikos 66896732 Mar 17 13:13 Κοσμάς\ Αιτωλός\ -\
> Προφητείες.pdf*
> -rw-r--r-- 1 nikos nikos   236032 Jun  4 14:10 Σκέψου\ έναν\ αριθμό.exe
>
> The code is as follows:
>
> #
> =================================================================================================================
> # Convert wrongly encoded filenames to utf-8
> #
> =================================================================================================================
> path = b'/home/nikos/public_html/data/apps/'
> filenames = os.listdir( path )
>
> utf8_filenames = []
>
> for filename in filenames:
>         # Compute 'path/to/filename'
>         filename_bytes = path + filename
>         encoding = guess_encoding( filename_bytes )
>
>         if encoding == 'utf-8':
>                 # File name is valid UTF-8, so we can skip to the next file.
>                 utf8_filenames.append( filename_bytes )
>                 continue
>         elif encoding is None:
>                 # No idea what the encoding is. Hit it with a hammer until it stops
> moving.
>                 filename = filename_bytes.decode( 'utf-8', 'xmlcharrefreplace' )
>         else:
>                 filename = filename_bytes.decode( encoding )
>
>         # Rename the file to something which ought to be UTF-8 clean.
>         newname_bytes = filename.encode('utf-8')
>         os.rename( filename_bytes, newname_bytes )
>         utf8_filenames.append( newname_bytes )
>
>         # Once we get here, the file ought to be UTF-8 clean and the Unicode
> name ought to exist:
>         assert os.path.exists( newname_bytes.decode('utf-8') )
>
> # Switch filenames from utf8 bytestrings => unicode strings
> filenames = []
>
> for utf8_filename in utf8_filenames:
>         filenames.append( utf8_filename.decode('utf-8') )
>
> # Check the presence of a database file against the dir files and delete
> record if it doesn't exist
> cur.execute('''SELECT url FROM files''')
> data = cur.fetchall()
>
> for url in data:
>         if url not in filenames:
>                 # Delete spurious
>                 cur.execute('''DELETE FROM files WHERE url = %s''', url )
>
> #
> =================================================================================================================
> # Display ALL files, each with its own download button
> #
> =================================================================================================================
> print('''<body background='/data/images/star.jpg'>
>                  <center><img src='/data/images/download.gif'><br><br>
>                  <table border=5 cellpadding=5 bgcolor=green>
> ''')
>
> try:
>         cur.execute( '''SELECT * FROM files ORDER BY lastvisit DESC''' )
>         data = cur.fetchall()
>
>         for row in data:
>                 (filename, hits, host, lastvisit) = row
>                 lastvisit = lastvisit.strftime('%A %e %b, %H:%M')
>
>                 print('''
>                 <form method="get" action="/cgi-bin/files.py">
>                         <tr>
>                                 <td> <center> <input type="submit" name="filename" value="%s"> </td>
>                                 <td> <center> <font color=yellow size=5> %s </td>
>                                 <td> <center> <font color=orange size=4> %s </td>
>                                 <td> <center> <font color=silver size=4> %s </td>
>                         </tr>
>                 </form>
>                 ''' % (filename, hits, host, lastvisit) )
>         print( '''</table><br><br>''' )
> except pymysql.ProgrammingError as e:
>         print( repr(e) )
>
> ===========================================
> PLEASE take a look, its not a huge code, the encoding was of Steven
> idea's, so from another thread is a bit more or less already known to
> the most of you.
>
> I just want to know why it doesn't print anything.
>
> Thank you and please whoever does not feel like helping, please at least
> not spam the thread.
>
> --
> What is now proved was at first only imagined!

-----


If my understanding is correct, you are writing something
like a "web application, server + html page display" (not
my cup of tea).

I suggest you simply drop Python and use something else,
eg the Go language.

From a Unicode point of view, it is rock solid. Far away
from Python and its hobbyism in that field (worse release
after release).

jmf


[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.python


csiph-web