Re: Wrong website loaded when other requested

2013-06-13 Thread Νικόλαος Κούρας
Τη Πέμπτη, 13 Ιουνίου 2013 7:52:27 μ.μ. UTC+3, ο χρήστης Νικόλαος Κούρας έγραψε:
> On 13/6/2013 6:35 μμ, Joel Goldstick wrote:
> 
> > [Tue Jun 11 21:59:31 2013] [error] [client 79.103.41.173]
> 
> > FileNotFoundError: [Errno 2] \\u0394\\u03b5\\u03bd
> 
> > \\u03c5\\u03c0\\u03ac\\u03c1\\
> 
> >
> 
> > u03c7\\u03b5\\u03b9 \\u03c4\\u03ad\\u03c4\\u03bf\\u03b9\\u03bf
> 
> > \\u03b1\\u03c1\\u03c7\\u03b5\\u03af\\u03bf \\u03ae
> 
> > \\u03ba\\u03b1\\u03c4\\u03ac\\u03bb\\u03bf\\u03b3\\u03bf\\u03c2:
> 
> > '/home/nikos/public_html//home/dauwin/public_html/index.html',
> 
> > referer: http://superhost.gr/
> 
> > [/code]
> 
> >
> 
> > DO YOU SEE THIS PART:
> 
> >   '/home/nikos/public_html//home/dauwin/public_html/index.html',
> 
> > referer: http://superhost.gr/
> 
> >
> 
> > Do you see that it prepends your nikos path the your dauwin path and
> 
> > file name.  It isn't replacing one with the other.  Somewhere in your
> 
> > SFBI mess of code you perhaps have set the nikos path as the start of a
> 
> > filename.  Check that out
> 
> 
> 
> yes i saw your post Joel,
> 
> 
> 
> After research i am under the impression that i'am in need for UserDir 
> 
> directive as it essentially allows you to use User Home directories as 
> 
> web directories...
> 
> 
> 
> So after reading this: 
> 
> http://centosforge.com/node/how-get-userdir-user-specific-publichtml-working-apache-centos-6
> 
> i did this:
> 
> 
> 
> 
> 
> 
> 
> UserDir public_html
> 
> 
> 
> 
> 
> #UserDir disabled
> 
> UserDir "enabled *"
> 
> UserDir "disabled root"
> 
> 
> 
> 
> 
> 
> 
> 
> 
> root@nikos [~]# chmod 711 /home
> 
> root@nikos [~]# chmod 711 /home/nikos
> 
> root@nikos [~]# chmod 755 /home/nikos/public_html/
> 
> root@nikos [~]# chmod o+r /home/nikos/public_html/index.html
> 
> root@nikos [~]# chmod 711 /home/dauwin
> 
> root@nikos [~]# chmod 755 /home/dauwin/public_html/
> 
> root@nikos [~]# chmod o+r /home/dauwin/public_html/index.html
> 
> root@nikos [~]#
> 
> 
> 
> setsebool -P httpd_enable_homedirs true
> 
> chcon -R -t httpd_sys_content_t /home/testuser/public_html
> 
> (the last one one failed though)
> 
> 
> 
> the i restarted Apache but the problem is still there.
> 
> 
> 
> ===
> 
> ni...@superhost.gr [~]# [Thu Jun 13 19:50:57 2013] [error] [client 
> 
> 79.103.41.173] Error in sys.excepthook:
> 
> [Thu Jun 13 19:50:57 2013] [error] [client 79.103.41.173] ValueError: 
> 
> underlying buffer has been detached
> 
> [Thu Jun 13 19:50:57 2013] [error] [client 79.103.41.173]
> 
> [Thu Jun 13 19:50:57 2013] [error] [client 79.103.41.173] Original 
> 
> exception was:
> 
> [Thu Jun 13 19:50:57 2013] [error] [client 79.103.41.173] Traceback 
> 
> (most recent call last):
> 
> [Thu Jun 13 19:50:57 2013] [error] [client 79.103.41.173]   File 
> 
> "/home/nikos/public_html/cgi-bin/metrites.py", line 213, in 
> 
> [Thu Jun 13 19:50:57 2013] [error] [client 79.103.41.173] with open( 
> 
> '/home/nikos/public_html/' + page, encoding='utf-8' ) as f:
> 
> [Thu Jun 13 19:50:57 2013] [error] [client 79.103.41.173] 
> 
> FileNotFoundError: [Errno 2] \\u0394\\u03b5\\u03bd 
> 
> \\u03c5\\u03c0\\u03ac\\u03c1\\u03c7\\u03b5\\u03b9 
> 
> \\u03c4\\u03ad\\u03c4\\u03bf\\u03b9\\u03bf 
> 
> \\u03b1\\u03c1\\u03c7\\u03b5\\u03af\\u03bf \\u03ae 
> 
> \\u03ba\\u03b1\\u03c4\\u03ac\\u03bb\\u03bf\\u03b3\\u03bf\\u03c2: 
> 
> '/home/nikos/public_html//home/dauwin/public_html/index.html'
> 
> 

please take an overall look at my httpd.conf at http://pastebin.com/Pb3VbNC9 in 
case you want to examine somehting else. 

Thank you very much.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Turnign greek-iso filenames => utf-8 iso

2013-06-13 Thread Νικόλαος Κούρας

On 13/6/2013 8:27 μμ, Zero Piraeus wrote:

:


But iam not offering Steven full root access, but restricted user level
access. Are you implying that for example one could elevate his privileges
to root level access form within a normal restricted user account?


I am implying that your demonstrated lack of ability means that *you
don't know* what Steven or anyone else could do with user-level
access. Elsewhere on this list, you've been shown that you're
publishing database passwords to the whole world in plaintext. Who
knows what other mistakes you've made? Who knows how
$STRANGER_YOU_TRUST_THIS_WEEK could exploit your (proven to be
insecure) setup if they had a mind to?


I trust him.


You are right, but i still believe Stevn would not act maliciously in 
the server.  He proved himself very helpfull already.




Also there is no other way of me solving this, so i have no other
alternative and i *must* solve this its over 15 days i'am trying with this
encoding issues, let alone years of trouble in various other scripts.


Then you need to contract with paid, professional support to solve
your problems.


Or receive some free help, to solve this single detail i'am missing.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Wrong website loaded when other requested

2013-06-13 Thread Νικόλαος Κούρας

On 13/6/2013 7:28 μμ, Chris Angelico wrote:

On Fri, Jun 14, 2013 at 2:23 AM,  ��  wrote:

Oh my God, i'll find an httpd.conf directive ot .htaccess directive that
prohibits display of source code of cgi scripts

please tell me if you know of such a directive.


Yes. This will majorly improve your security. It goes in your
httpd.conf or equivalent.

Listen 127.0.0.1:80

ChrisA


liek iam gonna fall for that!!!

127.0.0.1 is listening only to itself :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: A certainl part of an if() structure never gets executed.

2013-06-13 Thread Νικόλαος Κούρας

if '-' not in name + month + year:
			cur.execute( '''SELECT * FROM works WHERE clientsID = (SELECT id FROM 
clients WHERE name = %s) and MONTH(lastvisit) = %s and YEAR(lastvisit) = 
%s ORDER BY lastvisit ASC''', (name, month, year) )

elif '-' not in name + year:
			cur.execute( '''SELECT * FROM works WHERE clientsID = (SELECT id FROM 
clients WHERE name = %s) and YEAR(lastvisit) = %s ORDER BY lastvisit 
ASC''', (name, year) )

elif '-' not in month + year:
			cur.execute( '''SELECT * FROM works WHERE MONTH(lastvisit) = %s and 
YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', (month, year) )

elif '-' not in year:
			cur.execute( '''SELECT * FROM works WHERE YEAR(lastvisit) = %s ORDER 
BY lastvisit ASC''', year )



This finally worked!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Wrong website loaded when other requested

2013-06-13 Thread Νικόλαος Κούρας

On 13/6/2013 6:35 μμ, Joel Goldstick wrote:

[Tue Jun 11 21:59:31 2013] [error] [client 79.103.41.173]
FileNotFoundError: [Errno 2] \\u0394\\u03b5\\u03bd
\\u03c5\\u03c0\\u03ac\\u03c1\\

u03c7\\u03b5\\u03b9 \\u03c4\\u03ad\\u03c4\\u03bf\\u03b9\\u03bf
\\u03b1\\u03c1\\u03c7\\u03b5\\u03af\\u03bf \\u03ae
\\u03ba\\u03b1\\u03c4\\u03ac\\u03bb\\u03bf\\u03b3\\u03bf\\u03c2:
'/home/nikos/public_html//home/dauwin/public_html/index.html',
referer: http://superhost.gr/
[/code]

DO YOU SEE THIS PART:
  '/home/nikos/public_html//home/dauwin/public_html/index.html',
referer: http://superhost.gr/

Do you see that it prepends your nikos path the your dauwin path and
file name.  It isn't replacing one with the other.  Somewhere in your
SFBI mess of code you perhaps have set the nikos path as the start of a
filename.  Check that out


yes i saw your post Joel,

After research i am under the impression that i'am in need for UserDir 
directive as it essentially allows you to use User Home directories as 
web directories...


So after reading this: 
http://centosforge.com/node/how-get-userdir-user-specific-publichtml-working-apache-centos-6

i did this:



UserDir public_html


#UserDir disabled
UserDir "enabled *"
UserDir "disabled root"




root@nikos [~]# chmod 711 /home
root@nikos [~]# chmod 711 /home/nikos
root@nikos [~]# chmod 755 /home/nikos/public_html/
root@nikos [~]# chmod o+r /home/nikos/public_html/index.html
root@nikos [~]# chmod 711 /home/dauwin
root@nikos [~]# chmod 755 /home/dauwin/public_html/
root@nikos [~]# chmod o+r /home/dauwin/public_html/index.html
root@nikos [~]#

setsebool -P httpd_enable_homedirs true
chcon -R -t httpd_sys_content_t /home/testuser/public_html
(the last one one failed though)

the i restarted Apache but the problem is still there.

===
ni...@superhost.gr [~]# [Thu Jun 13 19:50:57 2013] [error] [client 
79.103.41.173] Error in sys.excepthook:
[Thu Jun 13 19:50:57 2013] [error] [client 79.103.41.173] ValueError: 
underlying buffer has been detached

[Thu Jun 13 19:50:57 2013] [error] [client 79.103.41.173]
[Thu Jun 13 19:50:57 2013] [error] [client 79.103.41.173] Original 
exception was:
[Thu Jun 13 19:50:57 2013] [error] [client 79.103.41.173] Traceback 
(most recent call last):
[Thu Jun 13 19:50:57 2013] [error] [client 79.103.41.173]   File 
"/home/nikos/public_html/cgi-bin/metrites.py", line 213, in 
[Thu Jun 13 19:50:57 2013] [error] [client 79.103.41.173] with open( 
'/home/nikos/public_html/' + page, encoding='utf-8' ) as f:
[Thu Jun 13 19:50:57 2013] [error] [client 79.103.41.173] 
FileNotFoundError: [Errno 2] \\u0394\\u03b5\\u03bd 
\\u03c5\\u03c0\\u03ac\\u03c1\\u03c7\\u03b5\\u03b9 
\\u03c4\\u03ad\\u03c4\\u03bf\\u03b9\\u03bf 
\\u03b1\\u03c1\\u03c7\\u03b5\\u03af\\u03bf \\u03ae 
\\u03ba\\u03b1\\u03c4\\u03ac\\u03bb\\u03bf\\u03b3\\u03bf\\u03c2: 
'/home/nikos/public_html//home/dauwin/public_html/index.html'



--
http://mail.python.org/mailman/listinfo/python-list


Re: Wrong website loaded when other requested

2013-06-13 Thread Νικόλαος Κούρας

On 13/6/2013 6:11 μμ, Chris Angelico wrote:

On Fri, Jun 14, 2013 at 12:54 AM, Andreas Perstinger
 wrote:

On 13.06.2013 16:23,  �� wrote:


Please suggest something of why this happnes.



That's not a Python problem.

BTW both scripts at
http://superhost.gr/~dauwin/metrites.py
and at
http://superhost.gr/~dauwin/cgi-bin/metrites.py
show the world the passwords to your databases in plain text.


See, that's the kind of thing that means you can't give out even
read-only access to your server. Does this mean anything to you Nikos?

ChrisA


Yes it does iam researchign a solution to this as we speak.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Wrong website loaded when other requested

2013-06-13 Thread Νικόλαος Κούρας

On 13/6/2013 5:54 μμ, Andreas Perstinger wrote:


That's not a Python problem.

BTW both scripts at
http://superhost.gr/~dauwin/metrites.py
and at
http://superhost.gr/~dauwin/cgi-bin/metrites.py
show the world the passwords to your databases in plain text.


Oh my God, i'll find an httpd.conf directive ot .htaccess directive that 
prohibits display of source code of cgi scripts


please tell me if you know of such a directive.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Turnign greek-iso filenames => utf-8 iso

2013-06-13 Thread Νικόλαος Κούρας

On 13/6/2013 5:16 μμ, Zero Piraeus wrote:

:


Steven, i can create a normal user account for you and copy files.py into
your home folder if you want to take a look from within.


Nikos, please, DO NOT DO THIS.

It must be clear to you that Steven is *much* more experienced than
you. Your presumptions about what he can and can't do with the access
you give him are therefore not much more than uninformed guesswork.


But iam not offering Steven full root access, but restricted user level 
access. Are you implying that for example one could elevate his 
privileges to root level access form within a normal restricted user 
account?



You have already been give a lesson about trusting the care of your
(and by extension your clients) resources to people you don't know,
and Chris, who gave you that lesson, is telling you that the course of
action you propose is unwise.

Steven has given every impression, over a long period, of being one of
the good guys, but *you don't know him*, and *you don't have any kind
of legal agreement with him* that would protect you should he turn out
to be malicious[1].


He is the only one helping me so far, to my hundreds of questiosn and in 
detail. He also the only one that didn't made fun of me because being 
inexperienced by making funny jokes at my expense.


I trust him.

Also there is no other way of me solving this, so i have no other 
alternative and i *must* solve this its over 15 days i'am trying with 
this encoding issues, let alone years of trouble in various other scripts.



--
http://mail.python.org/mailman/listinfo/python-list


Re: A certainl part of an if() structure never gets executed.

2013-06-13 Thread Νικόλαος Κούρας

On 13/6/2013 12:16 πμ, Sibylle Koczian wrote:

Am 12.06.2013 22:00, schrieb Νικόλαος Κούρας:

On 12/6/2013 10:48 μμ, Sibylle Koczian wrote:

if '=' not in ( name and month and year ):
i understand: if '=' not in name AND '=' not in month AND '=' not in
year


Wrong. The "'=' not in (...)" first evaluates the expression in
parentheses, that's what parentheses are for. And then it looks for '='
in the result. And that result is just one of the three values, MRAB
told you which one.


okey first the expression eval:

( name and month and year ) = ( name=True and month=True and year=True )


No. Read MRABs post, he explains it. Or work through the tutorial. This
would be right in another language, but not in Python.

If this expression would really evaluate to True or False, you
definitely couldn't search for any character in the result.

As it is, it evaluates to a string or to None, but searching for '=' in
that string doesn't give the result you think it does.


(name and month and year) is a Boolean expression, correct?

It will return True if all three are True and False otherwise. I cannot 
use it the way i desire regardless of how logical i think it looks.


Basically its just like i'am saying:


if "-" in True:
or
if "-" in False:

Obviously when i write it this way you can see it makes no sense.

==
But (name or month or year) is also a Boolean expression.

It will return the first of the three depending which value comes first 
as truthy.

it will return False if none of the three are False.

So how am i going to write it that?

if '-' not in name and '-' not in month and '-' not in year:  ??


--
http://mail.python.org/mailman/listinfo/python-list


Re: A certainl part of an if() structure never gets executed.

2013-06-13 Thread Νικόλαος Κούρας

On 13/6/2013 3:22 μμ, Sibylle Koczian wrote:

Am 13.06.2013 09:11, schrieb Νικόλαος Κούρας:

On 13/6/2013 4:55 πμ, Steven D'Aprano wrote:


The "and" operator works in a similar fashion. Experiment with it and
see
how it works for yourself.


I read yours psots many times,all of them, tryign to understand them.



But you didn't do what he recommended, did you? And it's really the best
or possibly the only way to understanding.

Try it out in the interactive Shell, using Stevens examples connected
with 'and' instead of 'or'.


I try and try to work it out but i can't understand it even in theory.

==

if '-' not in ( name and month and year ):
cur.execute( '''SELECT * FROM works WHERE clientsID = 
(SELECT id FROM clients WHERE name = %s) and MONTH(lastvisit) = %s and 
YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', (name, month, year) )

elif '-' not in ( name and year ):
cur.execute( '''SELECT * FROM works WHERE clientsID = 
(SELECT id FROM clients WHERE name = %s) and YEAR(lastvisit) = %s ORDER 
BY lastvisit ASC''', (name, year) )

elif '-' not in ( month and year ):
cur.execute( '''SELECT * FROM works WHERE MONTH(lastvisit) 
= %s and YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', (month, year) )

elif '-' not in year:
cur.execute( '''SELECT * FROM works WHERE YEAR(lastvisit) = 
%s ORDER BY lastvisit ASC''', year )


==

i just want 4 cases to examine so correct execute to be run:

i'm reading and reading and reading this all over:

if '-' not in ( name and month and year ):

and i cant comprehend it.

While it seems so beautiful saying:

if character '-' ain't contained in string name , neither in string 
month neither in string year.


But it just doesn't work like this.

Since  ( name and month and year ) are all truthy values, what is 
returned by this expression to be checked if it cotnains '=' within it?




--
http://mail.python.org/mailman/listinfo/python-list


Re: Turnign greek-iso filenames => utf-8 iso

2013-06-13 Thread Νικόλαος Κούρας

On 13/6/2013 9:49 πμ, Νικόλαος Κούρας wrote:

On 12/6/2013 1:40 μμ, Νικόλαος Κούρας wrote:

Thanks Steven , i made some alternations to the variables names and at
the end of the way that i check a database filename against and hdd
filename. Here is the code:

#
=


# 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 )
=

Now 'http://superhost.gr/?page=files.py' is not erring out at all but
also it doesn't display the big filename table for users to download.

Here is how i try to print the filenames with button for the users:

=


#Display ALL files, each with its own download button#
=


print('''
  
  
''')

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('''
 
 

%s 
%s 
%s 
 
 
 ''' % (filename, hits, host, lastvisit) )
 print( '''''' )
except pymysql.ProgrammingError as e:
 print( repr(e) )


Steven, i can create a normal user account for you and copy files.py
into your home folder if you want to take a look from within.

Since the code seems correct, cause its not erring out and you 've
helped me write it, then i dont knwo what else to try.

Those files inside 'apps' dir ought to be printed in an html table fter
their utf-8 conversion.

They still insist not to...



Can you accept please? or suggest something i should try so for the 
files to be correctly viewed by my visitors?

--
http://mail.python.org/mailman/listinfo/python-list


Re: Wrong website loaded when other requested

2013-06-13 Thread Νικόλαος Κούρας

On 13/6/2013 9:41 πμ, Νικόλαος Κούρας wrote:

On 12/6/2013 11:35 μμ, Joel Goldstick wrote:




On Wed, Jun 12, 2013 at 1:33 PM, Νικόλαος Κούρας mailto:supp...@superhost.gr>> wrote:

==
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^/?(.+\.html)
/cgi-bin/metrites.py?file=%{__REQUEST_FILENAME} [L,PT,QSA]
==

[code]
file = form.getvalue('file')
page = form.getvalue('page')

if not page and os.path.exists( file ):
 # it is an html template
 page = file.replace( '/home/dauwin/public_html/', '' )
elif page or form.getvalue('show'):
 # it is a python script
 page = page..replace(
'/home/dauwin/public_html/cgi-__bin/', '' )
else:
 #when everything else fails fallback
 page = "index.html"




 if page.endswith('.html'):
 with open( '/home/dauwin/public_html/' + page,
encoding='utf-8' ) as f:
 htmlpage = f.read()
 htmlpage = htmlpage % (quote, music)
 template = htmlpage + counter
 elif page.endswith('.py'):
 pypage = subprocess.check_output(
'/home/dauwin/public_html/cgi-__bin/' + page )
 pypage = pypage.decode('utf-8').__replace(
'Content-type: text/html; charset=utf-8', '' )
 template = pypage + counter

 print( template )
[/code]

Everything as you see point to 'dauwin' username, yet the error
still says:

[code]
[Tue Jun 11 21:59:31 2013] [error] [client 79.103.41.173]   File
"/home/nikos/public_html/cgi-__bin/metrites.py", line 219, in
, referer: http://superhost.gr/
[Tue Jun 11 21:59:31 2013] [error] [client 79.103.41.173] with
open( '/home/nikos/public_html/' + page, encoding='utf-8' ) as f:,
referer: http://superhost.gr/
[Tue Jun 11 21:59:31 2013] [error] [client 79.103.41.173]
FileNotFoundError: [Errno 2] \\u0394\\u03b5\\u03bd
\\u03c5\\u03c0\\u03ac\\u03c1\\__u03c7\\u03b5\\u03b9
\\u03c4\\u03ad\\u03c4\\u03bf\\__u03b9\\u03bf
\\u03b1\\u03c1\\u03c7\\u03b5\\__u03af\\u03bf \\u03ae
\\u03ba\\u03b1\\u03c4\\u03ac\\__u03bb\\u03bf\\u03b3\\u03bf\\__u03c2:
'/home/nikos/public_html//__home/dauwin/public_html/index.__html',
referer: http://superhost.gr/
[/code]


Notice that you have the file path you want concatenated to your
/home/nikos/... stuff in the line above.  Look in your code to find out
why. Fix that.  Lather, rinse, repeat


In my source code as seen above i mention nowhere for '/home/nikos/' but
instead for '/home/dauwin/'

That error message makes me come to conclusion that metrites.py script
is running from user's nikos' cgi-bin:

/home/nikos/public_html/cgi-bin/metrites.py

instead of:

/home/dauwin/public_html/cgi-bin/metrites.py

I wonder why.
I mean iam sayign it clearly

with open( '/home/dauwin/public_html/' + page,

and the error says:

[Tue Jun 11 21:59:31 2013] [error] [client 79.103.41.173] with
 > open( '/home/nikos/public_html/' + page, encoding='utf-8' ) as f:,
 > referer: http://superhost.gr/

What happens when i give http://superhost.gr/~dauwin

Why home/nikos/public_html/cgi-bin/metrites.py seems to be the scritp
that always run?

That should have run when i browser: 'http://superhost.gr' and not when
i browse 'http://superhost.gr/~dauwin'

Please help. A client wanst to utilize my metrites.py script because he
lieks the way that has a seperate counter for each html page and the way
the log is presented in an html table like form.
Of course i will give it it to him for free.



Please suggest something of why this happnes.
--
http://mail.python.org/mailman/listinfo/python-list


Re: A few questiosn about encoding

2013-06-13 Thread Νικόλαος Κούρας

On 13/6/2013 2:49 μμ, Steven D'Aprano wrote:

Please confirm these are true statement:

A code-point and the code-point's ordinal value are associated into a 
Unicode charset. They have the so called 1:1 mapping.


So, i was under the impression that by encoding the code-point into 
utf-8 was the same as encoding the code-point's ordinal value into utf-8.


So, now i believe they are two different things.
The code-point *is what actually* needs to be encoded and *not* its 
ordinal value.



> The leading 0b is just syntax to tell you "this is base 2, not base 8
> (0o) or base 10 or base 16 (0x)". Also, leading zero bits are dropped.

But byte objects are represented as '\x' instead of the aforementioned 
'0x'. Why is that?



ints always display in decimal. The only way to display in another base
is to build a string showing what the int would look like in a different
base:

py> hex(16474)
'0x405a'

Notice that the return value of bin, oct and hex are all strings. If they
were ints, then they would display in decimal, defeating the purpose!


Thank you didn't knew that! indeed it working like this.

To encode a number we have to turn it into a string first.

"16474".encode('utf-8')
b'16474'

That 'b' stand for bytes.
How can i view this byte's object representation as hex() or as bin()?


Also:
>>> len('0b10001011010')
17

You said this string consists of 17 chars.
Why the leading syntax of '0b' counts as bits as well? Shouldn't be 15 
bits instead of 17?




--
http://mail.python.org/mailman/listinfo/python-list


Re: Turnign greek-iso filenames => utf-8 iso

2013-06-13 Thread Νικόλαος Κούρας

On 13/6/2013 12:25 μμ, Chris Angelico wrote:

On Thu, Jun 13, 2013 at 6:15 PM,  ��  wrote:

I host no "e-shop" websites, hence into my system there is no credit card
info stored, no id photos, no SSN, nothing.

Now i checked and most are Joomla files or sites made by DreamWeaver.
and they are 755, that would mean group and word readable, *not* writable,
so no harm can possibly come out of this.


You really want to bet everything that not one of your clients has a
single bit of private information? Have you really learned nothing?


Yes i can take that bet. All of clients ar also good friends and i know 
their websites and what they are storing, nothing else that each website 
representation, nothing personal.


--
http://mail.python.org/mailman/listinfo/python-list


Re: A few questiosn about encoding

2013-06-13 Thread Νικόλαος Κούρας

On 13/6/2013 11:20 πμ, Chris Angelico wrote:

On Thu, Jun 13, 2013 at 6:08 PM, Νικόλαος Κούρας  wrote:

On 13/6/2013 10:58 πμ, Chris Angelico wrote:


On Thu, Jun 13, 2013 at 5:42 PM,  �� 
wrote:


On 13/6/2013 10:11 ��, Steven D'Aprano wrote:


No! That creates a string from 16474 in base two:
'0b10001011010'



I disagree here.
16474 is a number in base 10. Doing bin(16474) we get the binary
representation of number 16474 and not a string.
Why you say we receive a string while python presents a binary number?



You can disagree all you like. Steven cited a simple point of fact,
one which can be verified in any Python interpreter. Nikos, you are
flat wrong here; bin(16474) creates a string.



Indeed python embraced it in single quoting '0b10001011010' and not as
0b10001011010 which in fact makes it a string.

But since bin(16474) seems to create a string rather than an expected
number(at leat into my mind) then how do we get the binary representation of
the number 16474 as a number?


In Python 2:

16474
typing 16474 in interactive session both in python 2 and 3 gives back 
the number 16474


while we want the the binary representation of the number 16474


--
http://mail.python.org/mailman/listinfo/python-list


Re: Turnign greek-iso filenames => utf-8 iso

2013-06-13 Thread Νικόλαος Κούρας

On 13/6/2013 10:54 πμ, Chris Angelico wrote:

On Thu, Jun 13, 2013 at 4:49 PM,  ��  wrote:

Steven, i can create a normal user account for you and copy files.py into
your home folder if you want to take a look from within.


At least you're not offering root access any more. But are you aware
that most of your users' files are world-readable? And are you aware
of what that means?


I host no "e-shop" websites, hence into my system there is no credit 
card info stored, no id photos, no SSN, nothing.


Now i checked and most are Joomla files or sites made by DreamWeaver.
and they are 755, that would mean group and word readable, *not* 
writable, so no harm can possibly come out of this.


And even if something could happen, i strongly believe Steven would not 
do it as he is almost(there are others too bu not so frequent and 
detailed helpers) the only one that in fact helps me with my questions 
and i'm seriously considering of paying him to turn my cgi scripts to 
python web frameworks(perhaps 'webpy'), since Django must  be an 
overkill for my case, wouldn't do any harm.

--
http://mail.python.org/mailman/listinfo/python-list


Re: A few questiosn about encoding

2013-06-13 Thread Νικόλαος Κούρας

On 13/6/2013 10:58 πμ, Chris Angelico wrote:

On Thu, Jun 13, 2013 at 5:42 PM,  ��  wrote:

On 13/6/2013 10:11 ��, Steven D'Aprano wrote:

No! That creates a string from 16474 in base two:
'0b10001011010'


I disagree here.
16474 is a number in base 10. Doing bin(16474) we get the binary
representation of number 16474 and not a string.
Why you say we receive a string while python presents a binary number?


You can disagree all you like. Steven cited a simple point of fact,
one which can be verified in any Python interpreter. Nikos, you are
flat wrong here; bin(16474) creates a string.


Indeed python embraced it in single quoting '0b10001011010' and not 
as 0b10001011010 which in fact makes it a string.


But since bin(16474) seems to create a string rather than an expected 
number(at leat into my mind) then how do we get the binary 
representation of the number 16474 as a number?

--
http://mail.python.org/mailman/listinfo/python-list


Re: A few questiosn about encoding

2013-06-13 Thread Νικόλαος Κούρας

On 13/6/2013 10:11 πμ, Steven D'Aprano wrote:


  >>> chr(16474)
'䁚'

Some Chinese symbol.
So code-point '䁚' has a Unicode ordinal value of 16474, correct?


Correct.



where in after encoding this glyph's ordinal value to binary gives us
the following bytes:

  >>> bin(16474).encode('utf-8')
b'0b10001011010'


An observations here that you please confirm as valid.

1. A code-point and the code-point's ordinal value are associated into a 
Unicode charset. They have the so called 1:1 mapping.


So, i was under the impression that by encoding the code-point into 
utf-8 was the same as encoding the code-point's ordinal value into utf-8.


That is why i tried to:
bin(16474).encode('utf-8') instead of chr(16474).encode('utf-8')

So, now i believe they are two different things.
The code-point *is what actually* needs to be encoded and *not* its 
ordinal value.




The leading 0b is just syntax to tell you "this is base 2, not base 8
(0o) or base 10 or base 16 (0x)". Also, leading zero bits are dropped.


But byte objects are represented as '\x' instead of the aforementioned 
'0x'. Why is that?



> No! That creates a string from 16474 in base two:
> '0b10001011010'

I disagree here.
16474 is a number in base 10. Doing bin(16474) we get the binary 
representation of number 16474 and not a string.

Why you say we receive a string while python presents a binary number?



Then you encode the string '0b10001011010' into UTF-8. There are 17
characters in this string, and they are all ASCII characters to they take
up 1 byte each, giving you bytes b'0b10001011010' (in ASCII form).


0b10001011010 stands for a number in base 2 for me not as a string.
Have i understood something wrong?


--
http://mail.python.org/mailman/listinfo/python-list


Re: A certainl part of an if() structure never gets executed.

2013-06-13 Thread Νικόλαος Κούρας

On 13/6/2013 4:55 πμ, Steven D'Aprano wrote:

On Wed, 12 Jun 2013 14:17:32 +0300, Νικόλαος Κούρας wrote:


doesn't that mean?

if '=' not in ( name and month and year ):

if '=' does not exists as a char inside the name and month and year
variables?

i think it does, but why it fails then?


No. Python is very close to "English-like", but not exactly, and this is
one of the easiest places to trip.

In English:

"the cat is in the box or the cupboard or the kitchen"

means:

"the cat is in the box, or the cat is in the cupboard, or the cat is in
the kitchen".


But that is not how Python works. In Python, you have to say:

cat in box or cat in cupboard or cat in kitchen


Although this will work as well:

any(cat in place for place in (box, cupboard, kitchen))


In Python, an expression like this:

cat in (box or cupboard or kitchen)


has a completely different meaning. First, the expression in the round
brackets is evaluated:

(box or cupboard or kitchen)


and then the test is performed:

cat in (result of the above)


The expression (box or cupboard or kitchen) means "return the first one
of box, cupboard, kitchen that is a truthy value, otherwise the last
value". Truthy values are those which are considered to be "like True":

truthy values:

- True
- object()
- numbers apart from zero
- non-empty strings
- non-empty lists
- non-empty sets
- non-empty dicts
- etc.

falsey:

- False
- None
- zero (0, 0.0, Decimal(0), Fraction(0), etc.)
- empty string
- empty list
- empty set
- empty dict
- etc.

(Can you see the pattern?)


So you can experiment with this yourself:

42 or 23 or "foo"
=> the first object is truthy, so it is returned

0 or 23 or "foo"
=> the first object is falsey, and the second object is truthy,
so it is returned

0 or [] or "foo"
=> the first two objects are falsey, so the third is returned


The "and" operator works in a similar fashion. Experiment with it and see
how it works for yourself.


I read yours psots many times,all of them, tryign to understand them.


if '-' not in ( name and month and year ):
			cur.execute( '''SELECT * FROM works WHERE clientsID = (SELECT id FROM 
clients WHERE name = %s) and MONTH(lastvisit) = %s and YEAR(lastvisit) = 
%s ORDER BY lastvisit ASC''', (name, month, year) )

elif '-' not in ( name and year ):
			cur.execute( '''SELECT * FROM works WHERE clientsID = (SELECT id FROM 
clients WHERE name = %s) and YEAR(lastvisit) = %s ORDER BY lastvisit 
ASC''', (name, year) )

elif '-' not in ( month and year ):
			cur.execute( '''SELECT * FROM works WHERE MONTH(lastvisit) = %s and 
YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', (month, year) )

elif '-' not in year:
			cur.execute( '''SELECT * FROM works WHERE YEAR(lastvisit) = %s ORDER 
BY lastvisit ASC''', year )


==

i just want 4 cases to examine so correct execute to be run:

i'm reading and reading and reading this all over:

if '-' not in ( name and month and year ):

and i cant comprehend it.

While it seems so beutifull saying:

if character '-' aint contained in string name , neither in string month 
neither in string year.


But it just doesn't work like this.

Since  ( name and month and year ) are all truthy values, what is 
returned by this expression to be checked if it cotnains '=' within it?



--
http://mail.python.org/mailman/listinfo/python-list


Re: Turnign greek-iso filenames => utf-8 iso

2013-06-12 Thread Νικόλαος Κούρας

On 12/6/2013 1:40 μμ, Νικόλαος Κούρας wrote:

Thanks Steven , i made some alternations to the variables names and at
the end of the way that i check a database filename against and hdd
filename. Here is the code:

#
=

# 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 )
=

Now 'http://superhost.gr/?page=files.py' is not erring out at all but
also it doesn't display the big filename table for users to download.

Here is how i try to print the filenames with button for the users:

=

#Display ALL files, each with its own download button#
=

print('''
  
  
''')

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('''
 
 

%s 
%s 
%s 
 
 
 ''' % (filename, hits, host, lastvisit) )
 print( '''''' )
except pymysql.ProgrammingError as e:
 print( repr(e) )


Steven, i can create a normal user account for you and copy files.py 
into your home folder if you want to take a look from within.


Since the code seems correct, cause its not erring out and you 've 
helped me write it, then i dont knwo what else to try.


Those files inside 'apps' dir ought to be printed in an html table fter 
their utf-8 conversion.


They still insist not to...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Wrong website loaded when other requested

2013-06-12 Thread Νικόλαος Κούρας

On 12/6/2013 11:35 μμ, Joel Goldstick wrote:




On Wed, Jun 12, 2013 at 1:33 PM, Νικόλαος Κούρας mailto:supp...@superhost.gr>> wrote:

==
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^/?(.+\.html)
/cgi-bin/metrites.py?file=%{__REQUEST_FILENAME} [L,PT,QSA]
==

[code]
file = form.getvalue('file')
page = form.getvalue('page')

if not page and os.path.exists( file ):
 # it is an html template
 page = file.replace( '/home/dauwin/public_html/', '' )
elif page or form.getvalue('show'):
 # it is a python script
 page = page..replace(
'/home/dauwin/public_html/cgi-__bin/', '' )
else:
 #when everything else fails fallback
 page = "index.html"




 if page.endswith('.html'):
 with open( '/home/dauwin/public_html/' + page,
encoding='utf-8' ) as f:
 htmlpage = f.read()
 htmlpage = htmlpage % (quote, music)
 template = htmlpage + counter
 elif page.endswith('.py'):
 pypage = subprocess.check_output(
'/home/dauwin/public_html/cgi-__bin/' + page )
 pypage = pypage.decode('utf-8').__replace(
'Content-type: text/html; charset=utf-8', '' )
 template = pypage + counter

 print( template )
[/code]

Everything as you see point to 'dauwin' username, yet the error
still says:

[code]
[Tue Jun 11 21:59:31 2013] [error] [client 79.103.41.173]   File
"/home/nikos/public_html/cgi-__bin/metrites.py", line 219, in
, referer: http://superhost.gr/
[Tue Jun 11 21:59:31 2013] [error] [client 79.103.41.173] with
open( '/home/nikos/public_html/' + page, encoding='utf-8' ) as f:,
referer: http://superhost.gr/
[Tue Jun 11 21:59:31 2013] [error] [client 79.103.41.173]
FileNotFoundError: [Errno 2] \\u0394\\u03b5\\u03bd
\\u03c5\\u03c0\\u03ac\\u03c1\\__u03c7\\u03b5\\u03b9
\\u03c4\\u03ad\\u03c4\\u03bf\\__u03b9\\u03bf
\\u03b1\\u03c1\\u03c7\\u03b5\\__u03af\\u03bf \\u03ae
\\u03ba\\u03b1\\u03c4\\u03ac\\__u03bb\\u03bf\\u03b3\\u03bf\\__u03c2:
'/home/nikos/public_html//__home/dauwin/public_html/index.__html',
referer: http://superhost.gr/
[/code]


Notice that you have the file path you want concatenated to your
/home/nikos/... stuff in the line above.  Look in your code to find out
why. Fix that.  Lather, rinse, repeat


In my source code as seen above i mention nowhere for '/home/nikos/' but 
instead for '/home/dauwin/'


That error message makes me come to conclusion that metrites.py script 
is running from user's nikos' cgi-bin:


/home/nikos/public_html/cgi-bin/metrites.py

instead of:

/home/dauwin/public_html/cgi-bin/metrites.py

I wonder why.
I mean iam sayign it clearly

with open( '/home/dauwin/public_html/' + page,

and the error says:

[Tue Jun 11 21:59:31 2013] [error] [client 79.103.41.173] with
> open( '/home/nikos/public_html/' + page, encoding='utf-8' ) as f:,
> referer: http://superhost.gr/

What happens when i give http://superhost.gr/~dauwin

Why home/nikos/public_html/cgi-bin/metrites.py seems to be the scritp 
that always run?


That should have run when i browser: 'http://superhost.gr' and not when 
i browse 'http://superhost.gr/~dauwin'


Please help. A client wanst to utilize my metrites.py script because he 
lieks the way that has a seperate counter for each html page and the way 
the log is presented in an html table like form.

Of course i will give it it to him for free.
--
http://mail.python.org/mailman/listinfo/python-list


Re: A few questiosn about encoding

2013-06-12 Thread Νικόλαος Κούρας

On 12/6/2013 11:30 μμ, Nobody wrote:

On Wed, 12 Jun 2013 14:23:49 +0300, Νικόλαος Κούρας wrote:


So, how many bytes does UTF-8 stored for codepoints > 127 ?


U+..U+007F  1 byte
U+0080..U+07FF  2 bytes
U+0800..U+  3 bytes

=U+1   4 bytes


'U' stands for Unicode code-point which means a character right?

How can you be able to tell up to what character utf-8 needs 1 byte or 2 
bytes or 3?



And some of the bytes' bits are used to tell where a code-points 
representations stops, right?  i mean if we have a code-point that needs 
2 bytes to be stored that the high bit must be set to 1 to signify that 
this character's encoding stops at 2 bytes.


I just know that 2^8 = 256, that's by first look 265 places, which mean 
256 positions to hold a code-point which in turn means a character.


We take the high bit out and then we have 2^7 which is enough positions 
for 0-127 standard ASCII. High bit is set to '0' to signify that char is 
encoded in 1 byte.


Please tell me that i understood correct so far.

But how about for 2 or 3 or 4 bytes?

Am i saying ti correct ?



--
http://mail.python.org/mailman/listinfo/python-list


Re: A few questiosn about encoding

2013-06-12 Thread Νικόλαος Κούρας

On 13/6/2013 3:13 πμ, Steven D'Aprano wrote:

On Wed, 12 Jun 2013 14:23:49 +0300, Νικόλαος Κούρας wrote:


So, how many bytes does UTF-8 stored for codepoints > 127 ?


Two, three or four, depending on the codepoint.


The amount of bytes needed by UTF-8 to store a code-point(character), 
depends on the ordinal value of the code-point in the Unicode charset, 
correct?


If this is correct then the higher the ordinal value(which is an decimal 
integer) in the Unicode charset the more bytes needed for storage.


Its like the bigger a decimal integer is the bigger binary number it 
produces.


Is this correct?



example for codepoint 256, 1345, 16474 ?


You can do this yourself. I have already given you enough information in
previous emails to answer this question on your own, but here it is again:

Open an interactive Python session, and run this code:

c = ord(16474)
len(c.encode('utf-8'))


That will tell you how many bytes are used for that example.

This si actually wrong.

ord()'s arguments must be a character for which we expect its ordinal value.

>>> chr(16474)
'䁚'

Some Chinese symbol.
So code-point '䁚' has a Unicode ordinal value of 16474, correct?

where in after encoding this glyph's ordinal value to binary gives us 
the following bytes:


>>> bin(16474).encode('utf-8')
b'0b10001011010'

Now, we take tow symbols out:

'b' symbolism which is there to tell us that we are looking a bytes 
object as well as the
'0b' symbolism which is there to tell us that we are looking a binary 
representation of a bytes object


Thus, there we count 15 bits left.
So it says 15 bits, which is 1-bit less that 2 bytes.
Is the above statements correct please?


but thinking this through more and more:

>>> chr(16474).encode('utf-8')
b'\xe4\x81\x9a'
>>> len(b'\xe4\x81\x9a')
3

it seems that the bytestring the encode process produces is of length 3.

So i take it is 3 bytes?

but there is a mismatch of what >>> bin(16474).encode('utf-8') and >>> 
chr(16474).encode('utf-8') is telling us here.


Care to explain that too please ?






--
http://mail.python.org/mailman/listinfo/python-list


Re: A certainl part of an if() structure never gets executed.

2013-06-12 Thread Νικόλαος Κούρας

On 13/6/2013 4:55 πμ, Steven D'Aprano wrote:

On Wed, 12 Jun 2013 14:17:32 +0300, Νικόλαος Κούρας wrote:


doesn't that mean?

if '=' not in ( name and month and year ):

if '=' does not exists as a char inside the name and month and year
variables?

i think it does, but why it fails then?


No. Python is very close to "English-like", but not exactly, and this is
one of the easiest places to trip.

In English:

"the cat is in the box or the cupboard or the kitchen"

means:

"the cat is in the box, or the cat is in the cupboard, or the cat is in
the kitchen".


But that is not how Python works. In Python, you have to say:

cat in box or cat in cupboard or cat in kitchen


Although this will work as well:

any(cat in place for place in (box, cupboard, kitchen))


In Python, an expression like this:

cat in (box or cupboard or kitchen)


has a completely different meaning. First, the expression in the round
brackets is evaluated:

(box or cupboard or kitchen)


and then the test is performed:

cat in (result of the above)


The expression (box or cupboard or kitchen) means "return the first one
of box, cupboard, kitchen that is a truthy value, otherwise the last
value". Truthy values are those which are considered to be "like True":

truthy values:

- True
- object()
- numbers apart from zero
- non-empty strings
- non-empty lists
- non-empty sets
- non-empty dicts
- etc.

falsey:

- False
- None
- zero (0, 0.0, Decimal(0), Fraction(0), etc.)
- empty string
- empty list
- empty set
- empty dict
- etc.

(Can you see the pattern?)


So you can experiment with this yourself:

42 or 23 or "foo"
=> the first object is truthy, so it is returned

0 or 23 or "foo"
=> the first object is falsey, and the second object is truthy,
so it is returned

0 or [] or "foo"
=> the first two objects are falsey, so the third is returned


The "and" operator works in a similar fashion. Experiment with it and see
how it works for yourself.


First i wan tot thank you for taking the time to explain to me (the 
languages examples to explai encode-decode was really great as well)



So, baring in ming your explanation:

if '=' not in ( name or month or year )

first eval the expr. The expr will result to return the first object 
that has a truthy values.


in this particular example all 3 strings are truthies because they all 
contain characters inside them, the one user submitted when hitting the 
submit button


so that would turn to if '=' not in ( name ).
Allright, but what i wanted to check is if the char '=' ain't contained 
in both 3 strings not for the 1st string(name) which will always be true.


So i guess having it like this "if '=' not in ( name or month or year )" 
 is wrong?



b) Also what "if '=' not in ( name and month and year )" returns in the 
round brackets since in my case all the strings have values therefore 
they are true, which string get returned?


--
http://mail.python.org/mailman/listinfo/python-list


Re: Wrong website loaded when other requested

2013-06-12 Thread Νικόλαος Κούρας

What i mean is the the python.cgi script supposed to be executed was

"/home/dauwin/public_html/cgi-bin/metrites.py"

but instead for this to load for some reason

File "/home/nikos/public_html/cgi-bin/metrites.py"


But this is crazy.
I hit to the browser 'http://superhost.gr/~dauwin' and not 
'http://superhost.gr'


dauwin and nikos are 2 different usernames belonging to 2 different 
cPanel accounts.

--
http://mail.python.org/mailman/listinfo/python-list


Re: A certainl part of an if() structure never gets executed.

2013-06-12 Thread Νικόλαος Κούρας

On 12/6/2013 10:48 μμ, Sibylle Koczian wrote:

if '=' not in ( name and month and year ):
i understand: if '=' not in name AND '=' not in month AND '=' not in year


Wrong. The "'=' not in (...)" first evaluates the expression in
parentheses, that's what parentheses are for. And then it looks for '='
in the result. And that result is just one of the three values, MRAB
told you which one.


okey first the expression eval:

( name and month and year ) = ( name=True and month=True and year=True )

then if '=' not in (name = True and month = True and year = True)

I still do not follow how this works. it just doesn't make any sense to 
me at all.



if '=' not in ( name and month and year ):
if '=' not in ( name or month or year ):

I try to read both of them them as an English sentence but i cannot.
how can you be able to understand this?


--
http://mail.python.org/mailman/listinfo/python-list


Re: Turnign greek-iso filenames => utf-8 iso

2013-06-12 Thread Νικόλαος Κούρας

On 12/6/2013 8:27 μμ, Νικόλαος Κούρας wrote:

On 12/6/2013 3:42 μμ, Νικόλαος Κούρας wrote:


=

# 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('''
  
  
''')

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('''
 
 

%s 
%s 
%s 
 
 
 ''' % (filename, hits, host, lastvisit) )
 print( '''''' )
except pymysql.ProgrammingError as e:
 print( repr(e) )

sys.exit(0)

==


Please help, the script does not erring out, bu neither print the files
along with download button for the users to download.

What else do i need to try to find out, where the logical error(it it is
one) might be?

After correcting this issue, this gonna be my last question, every other
script is fixed, its just this issues now almost 15 days.


Any ideas please on how to check this?
--
http://mail.python.org/mailman/listinfo/python-list


Re: A certainl part of an if() structure never gets executed.

2013-06-12 Thread Νικόλαος Κούρας

On 12/6/2013 8:53 μμ, MRAB wrote:


and then what this is doing?

if '=' not in ( name or month or year ):


In English, the result of:

 x or y

is basically:

 if bool(x) is true then the result is x, otherwise the result is y

For example:

 >>> bool("")
False
 >>> "" or "world"
'world'
 >>> bool("Hello")
True
 >>> "Hello" or "world"
'Hello'

These can be strung together, so that:

 x and y and z

is equivalent to:

 (x and y) and z

and:

 x or y or z

is equivalent to:

 (x or y) or z

and so on, however many times you wish to do it.


Never before i used not in with soe many variables in parenthesi, up
until now i was specified it as not in var 1 and not in var 2 and not in
var 2 and so on


Keep it simple:

 if '=' not in name and '=' not in month and '=' not in year:

There may be a shorter way, but you seem confused enough as it is.



Whn i see:

if( x and y ):
i understand: if x expression = True AND ALSO y expression = True then 
execute



if( x or y ):
i understand: if x expression = True OR y expression = True then execute


if '=' not in ( name and month and year ):
i understand: if '=' not in name AND '=' not in month AND '=' not in year


if '=' not in ( name or month or year ):
i understand: if '=' not in name OR '=' not in month OR '=' not in year


but i know it does not work like this, but tis is how i understand it. 
its like reading an English sentence



--
http://mail.python.org/mailman/listinfo/python-list


Wrong website loaded when other requested

2013-06-12 Thread Νικόλαος Κούρας

==
RewriteEngine Off
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^/?(.+\.html) /cgi-bin/metrites.py?file=%{REQUEST_FILENAME} 
[L,PT,QSA]

==

[code]
file = form.getvalue('file')
page = form.getvalue('page')

if not page and os.path.exists( file ):
# it is an html template
page = file.replace( '/home/dauwin/public_html/', '' )
elif page or form.getvalue('show'):
# it is a python script
page = page..replace( '/home/dauwin/public_html/cgi-bin/', '' )
else:
#when everything else fails fallback
page = "index.html"




if page.endswith('.html'):
with open( '/home/dauwin/public_html/' + page, encoding='utf-8' 
) as f:
htmlpage = f.read()
htmlpage = htmlpage % (quote, music)
template = htmlpage + counter
elif page.endswith('.py'):
		pypage = subprocess.check_output( '/home/dauwin/public_html/cgi-bin/' 
+ page )
		pypage = pypage.decode('utf-8').replace( 'Content-type: text/html; 
charset=utf-8', '' )

template = pypage + counter

print( template )
[/code]

Everything as you see point to 'dauwin' username, yet the error still says:

[code]
[Tue Jun 11 21:59:31 2013] [error] [client 79.103.41.173]   File 
"/home/nikos/public_html/cgi-bin/metrites.py", line 219, in , 
referer: http://superhost.gr/
[Tue Jun 11 21:59:31 2013] [error] [client 79.103.41.173] with open( 
'/home/nikos/public_html/' + page, encoding='utf-8' ) as f:, referer: 
http://superhost.gr/
[Tue Jun 11 21:59:31 2013] [error] [client 79.103.41.173] 
FileNotFoundError: [Errno 2] \\u0394\\u03b5\\u03bd 
\\u03c5\\u03c0\\u03ac\\u03c1\\u03c7\\u03b5\\u03b9 
\\u03c4\\u03ad\\u03c4\\u03bf\\u03b9\\u03bf 
\\u03b1\\u03c1\\u03c7\\u03b5\\u03af\\u03bf \\u03ae 
\\u03ba\\u03b1\\u03c4\\u03ac\\u03bb\\u03bf\\u03b3\\u03bf\\u03c2: 
'/home/nikos/public_html//home/dauwin/public_html/index.html', referer: 
http://superhost.gr/

[/code]


Why is pointing to /home/nikos isntead of /home/dauwin ?

this is what a smash my head to the wall to understand.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Turnign greek-iso filenames => utf-8 iso

2013-06-12 Thread Νικόλαος Κούρας

On 12/6/2013 8:14 μμ, Νικόλαος Κούρας wrote:

On 12/6/2013 5:42 μμ, Mark Lawrence wrote:

On 12/06/2013 13:42, Νικόλαος Κούρας wrote:


Something you want me to try?


I'd suggest suicide but that would no doubt start another stream of
questions along the lines of "How do I do it?".


Okey that was indeed very finny, i even laughed at my own expense :)



Hahahahahhahahahha, damn life, there is a how-to for everything in this 
world, even when it comes to leave it to go to afterlife :)

--
http://mail.python.org/mailman/listinfo/python-list


Re: Turnign greek-iso filenames => utf-8 iso

2013-06-12 Thread Νικόλαος Κούρας

On 12/6/2013 3:42 μμ, Νικόλαος Κούρας wrote:


=
# 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('''
  
  
''')

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('''
 
 

%s 
%s 
%s 
 
 
 ''' % (filename, hits, host, lastvisit) )
 print( '''''' )
except pymysql.ProgrammingError as e:
 print( repr(e) )

sys.exit(0)

==


Please help, the script does not erring out, bu neither print the files 
along with download button for the users to download.


What else do i need to try to find out, where the logical error(it it is 
one) might be?


After correcting this issue, this gonna be my last question, every other 
script is fixed, its just this issues now almost 15 days.

--
http://mail.python.org/mailman/listinfo/python-list


Re: Turnign greek-iso filenames => utf-8 iso

2013-06-12 Thread Νικόλαος Κούρας

On 12/6/2013 7:18 μμ, Neil Cerutti wrote:

On 2013-06-12, Mark Lawrence  wrote:

On 12/06/2013 13:42,   wrote:


Something you want me to try?


I'd suggest suicide but that would no doubt start another
stream of questions along the lines of "How do I do it?".


hi. I loopet rope aroung and jumped, but bruise happen and erron
do the death.

Pls heelp!

Nikos


lool :-)

Guys i'am really not trolling here, i just learn along the way as error 
appear. this is my last questiosn for my webiste to work, any other 
scripts i ahve is properrly working , its just this files.py error that 
needs fixing anf then i'll stop ask, at least for a while :)

--
http://mail.python.org/mailman/listinfo/python-list


Re: Turnign greek-iso filenames => utf-8 iso

2013-06-12 Thread Νικόλαος Κούρας

On 12/6/2013 5:42 μμ, Mark Lawrence wrote:

On 12/06/2013 13:42, Νικόλαος Κούρας wrote:


Something you want me to try?


I'd suggest suicide but that would no doubt start another stream of
questions along the lines of "How do I do it?".


Okey that was indeed very finny, i even laughed at my own expense :)

--
http://mail.python.org/mailman/listinfo/python-list


Re: A certainl part of an if() structure never gets executed.

2013-06-12 Thread Νικόλαος Κούρας

On 12/6/2013 7:40 μμ, MRAB wrote:

On 12/06/2013 12:17, Νικόλαος Κούρας wrote:



As with most of your problems you are barking up the wrong tree.
Why not use the actual value you get from the form to check whether you
have a valid month?
Do you understand why "0" is submitted instead of "=="?

Bye, Andreas


I have corrected the enumerate loop but it seems thet now the year works
and the selected name nad month fail:

if '=' not in ( name and month and year ):
cur.execute( '''SELECT * FROM works WHERE clientsID =
(SELECT id FROM
clients WHERE name = %s) and MONTH(lastvisit) = %s and YEAR(lastvisit) =
%s ORDER BY lastvisit ASC''', (name, month, year) )
elif '=' not in ( month and year ):
cur.execute( '''SELECT * FROM works WHERE MONTH(lastvisit)
= %s and
YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', (month, year) )
elif '=' not in year:
cur.execute( '''SELECT * FROM works WHERE YEAR(lastvisit)
= %s ORDER
BY lastvisit ASC''', year )
else:
print( 'Πώς να γίνει αναζήτηση αφού
δεν επέλεξες
ούτε πελάτη ούτε μήνα ή τουλάχιστον το έτος?' )
print( '' )
sys.exit(0)


i tried in , not in and all possible combinations. but somehow it
confuses me.

doesn't that mean?

if '=' not in ( name and month and year ):

if '=' does not exists as a char inside the name and month and year
variables?

i think it does, but why it fails then?


You think it does, but you're wrong.


How would you telll in english word what this is doing?

if '=' not in ( name and month and year ):


and then what this is doing?

if '=' not in ( name or month or year ):

Never before i used not in with soe many variables in parenthesi, up 
until now i was specified it as not in var 1 and not in var 2 and not in 
var 2 and so on


--
http://mail.python.org/mailman/listinfo/python-list


Re: Turnign greek-iso filenames => utf-8 iso

2013-06-12 Thread Νικόλαος Κούρας

On 12/6/2013 2:32 μμ, Νικόλαος Κούρας wrote:

On 12/6/2013 12:37 μμ, Steven D'Aprano wrote:

On Wed, 12 Jun 2013 12:24:24 +0300, Νικόλαος Κούρας wrote:




[1] Correction. While I was typing this, it came good, for about 20
seconds, and displayed a hideously ugly background pattern and a cute
smiling face waving, and then broke again.



Ah sorry Steven i made the change of:

host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or 'UnResolved'

to metrites.py isntead of files.py

now i have made both chnages.

you can see the webpage now, eys the one with the cure smile face.

behidn that we should beeen seeing all the files in a table like format
for uses to downlaod, instead not a single file is being displayed.

here is the print process., actually here is what i have up until now
after modifications for you to take an overall look.

#
=

# 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('''
  
  
''')

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('''
 
 

%s 
%s 
%s 
 
 
 ''' % (filename, hits, host, lastvisit) )
 print( '''''' )
except pymysql.ProgrammingError as e:
 print( repr(e) )

sys.exit(0)

==
ima happy that at elaST IT DOES NOT ERRIGN OUT!



Can you shed some ligth please as to what might the problem be and its 
not displayign the filenames sicn ethey are utf8 encoded correctly?


Something you want me to try?
--
http://mail.python.org/mailman/listinfo/python-list


Re: A certainl part of an if() structure never gets executed.

2013-06-12 Thread Νικόλαος Κούρας

On 12/6/2013 2:49 μμ, F�bio Santos wrote:


On 12 Jun 2013 12:08, " ��" mailto:supp...@superhost.gr>> wrote:
 >
 > Oh my God!
 >
 > i just need to do this:
 >
 >
 > for i, month in enumerate( months ):
 > � � � � print(' %s ' % (month, month) )

Usually what goes in  is an ID of something. You
should keep using (i, month) and then do months[id] to get the month string.

Also, tuples aren't traditionally used for this. Normally you'd use a list.



You were right, i counter needed to signify the value: I just made it 
work as i wanted to!



print('')
for i, month in enumerate( months ):
print(' %s ' % (i, month) )
if month == '0':
month = '=='






# 
=

# find & display requested info based on name/month/year criteria
# 
=

if( seek ): 
try:
if '=' not in ( name or month or year ):
			cur.execute( '''SELECT * FROM works WHERE clientsID = (SELECT id FROM 
clients WHERE name = %s) and MONTH(lastvisit) = %s and YEAR(lastvisit) = 
%s ORDER BY lastvisit ASC''', (name, month, year) )

elif '=' not in ( month or year ):
			cur.execute( '''SELECT * FROM works WHERE MONTH(lastvisit) = %s and 
YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', (month, year) )

elif '=' not in year:
			cur.execute( '''SELECT * FROM works WHERE YEAR(lastvisit) = %s ORDER 
BY lastvisit ASC''', year )


--
http://mail.python.org/mailman/listinfo/python-list


Re: Turnign greek-iso filenames => utf-8 iso

2013-06-12 Thread Νικόλαος Κούρας

On 12/6/2013 12:37 μμ, Steven D'Aprano wrote:

On Wed, 12 Jun 2013 12:24:24 +0300, Νικόλαος Κούρας wrote:




[1] Correction. While I was typing this, it came good, for about 20
seconds, and displayed a hideously ugly background pattern and a cute
smiling face waving, and then broke again.



Ah sorry Steven i made the change of:

host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or 'UnResolved'

to metrites.py isntead of files.py

now i have made both chnages.

you can see the webpage now, eys the one with the cure smile face.

behidn that we should beeen seeing all the files in a table like format 
for uses to downlaod, instead not a single file is being displayed.


here is the print process., actually here is what i have up until now 
after modifications for you to take an overall look.


# 
=

# 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('''
 
 
''')

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('''


   
   %s 

   %s 

   %s 



''' % (filename, hits, host, lastvisit) )
print( '''''' )
except pymysql.ProgrammingError as e:
print( repr(e) )

sys.exit(0)

==
ima happy that at elaST IT DOES NOT ERRIGN OUT!
--
http://mail.python.org/mailman/listinfo/python-list


Re: A few questiosn about encoding

2013-06-12 Thread Νικόλαος Κούρας

On 12/6/2013 12:24 μμ, Steven D'Aprano wrote:

On Wed, 12 Jun 2013 09:09:05 +0000, Νικόλαος Κούρας wrote:


Isn't 14 bits way to many to store a character ?


No.

There are 1114111 possible characters in Unicode. (And in Japan, they
sometimes use TRON instead of Unicode, which has even more.)

If you list out all the combinations of 14 bits:

   00
   01
   10
   11
[...]
   10
   11

you will see that there are only 32767 (2**15-1) such values. You can't
fit 1114111 characters with just 32767 values.




Thanks Steven,
So, how many bytes does UTF-8 stored for codepoints > 127 ?

example for codepoint 256, 1345, 16474 ?
--
http://mail.python.org/mailman/listinfo/python-list


Re: A certainl part of an if() structure never gets executed.

2013-06-12 Thread Νικόλαος Κούρας



As with most of your problems you are barking up the wrong tree.
Why not use the actual value you get from the form to check whether you
have a valid month?
Do you understand why "0" is submitted instead of "=="?

Bye, Andreas


I have corrected the enumerate loop but it seems thet now the year works 
and the selected name nad month fail:


if '=' not in ( name and month and year ):
			cur.execute( '''SELECT * FROM works WHERE clientsID = (SELECT id FROM 
clients WHERE name = %s) and MONTH(lastvisit) = %s and YEAR(lastvisit) = 
%s ORDER BY lastvisit ASC''', (name, month, year) )

elif '=' not in ( month and year ):
			cur.execute( '''SELECT * FROM works WHERE MONTH(lastvisit) = %s and 
YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', (month, year) )

elif '=' not in year:
			cur.execute( '''SELECT * FROM works WHERE YEAR(lastvisit) = %s ORDER 
BY lastvisit ASC''', year )

else:
			print( 'Πώς να γίνει αναζήτηση αφού δεν επέλεξες 
ούτε πελάτη ούτε μήνα ή τουλάχιστον το έτος?' )
			print( 'content="5;/cgi-bin/pelatologio.py">' )

sys.exit(0)


i tried in , not in and all possible combinations. but somehow it 
confuses me.


doesn't that mean?

if '=' not in ( name and month and year ):

if '=' does not exists as a char inside the name and month and year 
variables?


i think it does, but why it fails then?
--
http://mail.python.org/mailman/listinfo/python-list


Re: A certainl part of an if() structure never gets executed.

2013-06-12 Thread Νικόλαος Κούρας

Oh my God!

i just need to do this:

for i, month in enumerate( months ):
print(' %s ' % (month, month) )
--
http://mail.python.org/mailman/listinfo/python-list


Re: A certainl part of an if() structure never gets executed.

2013-06-12 Thread Νικόλαος Κούρας

On 12/6/2013 1:07 μμ, Andreas Perstinger wrote:


So, i must tell:

for i, month in enumerate(months):
  print(' %s ' % (i, month) )

to somehow return '==' instead of 0 but don't know how.


As with most of your problems you are barking up the wrong tree.
Why not use the actual value you get from the form to check whether you
have a valid month?
Do you understand why "0" is submitted instead of "=="?


No, this is exactly what i do not understand.

months = ( '==', 'Ιανουάριος', 'Φεβρουάριος', 'Μάρτιος', 
'Απρίλιος', 'Μάϊος', 'Ιούνιος',
   'Ιούλιος', 'Αύγουστος', 'Σεπτέμβριος', 'Οκτώβριος', 
'Νοέμβριος', 'Δεκέμβριος' )


This is a tuple containign months. Then we have this:

for i, month in enumerate(months):
  print(' %s ' % (i, month) )

i is assiciated to month in similar fashion as a dic's key to it's value

i = the increasing counter after each iteration in the loop
month = just the displayed month.

when iteration happens we get this:

value 0 for month '=='
value 1 for month 'Ιανουάριος'
.
.
value 12 for month 'Δεκέμβριος'

So when '==' is being selected as month from the user value 0 is 
beign returned, but what i need is the string '==' itself, not 
the value.


the year var have no prblem, is the month that always fails the if() 
condition branch.

--
http://mail.python.org/mailman/listinfo/python-list


Re: A certainl part of an if() structure never gets executed.

2013-06-12 Thread Νικόλαος Κούρας



 Original Message 
Subject: Re: A certainl part of an if() structure never gets executed.
Date: Wed, 12 Jun 2013 10:07:39 +0100
From: Fábio Santos 
To: Νικόλαος Κούρας 
CC: python-list@python.org 
Newsgroups: comp.lang.python
References: <2bc90d3b-09c2-4315-9357-ff7f03946...@googlegroups.com> 
 


On Wed, Jun 12, 2013 at 9:54 AM, Νικόλαος Κούρας  
wrote:

> but if enumerate yields 0 instead of '==' then elif '=' not in
> year of course fails.
>
> So, i must tell:
>
> for i, month in enumerate(months):
> print(' %s ' % (i, month) )
>
> to somehow return '==' instead of 0 but don't know how.
> --
> http://mail.python.org/mailman/listinfo/python-list

Well, you could try this:

> for i, month in enumerate(months):
> if i == 0:
> month = ('=' * 10)
> print(' %s ' % (i, month) )

No?

You can see if for yourself if you go to:
http://superhost.gr/?page=pelatologio.py

bottom down where the form drop down menus are:

search will work but f the suer just gives out the year it will never 
make it to the specific if() branch.




--
http://mail.python.org/mailman/listinfo/python-list


Re: Turnign greek-iso filenames => utf-8 iso

2013-06-12 Thread Νικόλαος Κούρας
Thanks Steven , i made some alternations to the variables names and at 
the end of the way that i check a database filename against and hdd 
filename. Here is the code:


# 
=

# 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 )
=

Now 'http://superhost.gr/?page=files.py' is not erring out at all but 
also it doesn't display the big filename table for users to download.


Here is how i try to print the filenames with button for the users:

=
#Display ALL files, each with its own download button# 
=

print('''
 
 
''')

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('''


   
   %s 

   %s 

   %s 



''' % (filename, hits, host, lastvisit) )
print( '' )
except pymysql.ProgrammingError as e:
print( repr(e) )
--
http://mail.python.org/mailman/listinfo/python-list


Re: Turnign greek-iso filenames => utf-8 iso

2013-06-12 Thread Νικόλαος Κούρας

On 12/6/2013 12:17 μμ, Steven D'Aprano wrote:

On Wed, 12 Jun 2013 12:00:38 +0300, Νικόλαος Κούρας wrote:


On 12/6/2013 11:31 πμ, Steven D'Aprano wrote:

On Wed, 12 Jun 2013 08:02:24 +, Νικόλαος Κούρας wrote:



and the output is just Pacman.exe as seen in

http://superhost.gr/?page=files.py


Wrong. The output is:

Internal Server Error


print( filenames )
sys.exit(0)


No it dosnt not, it loads properly and if you visit it again you will
see all the files being displayed since now i:


Wrong again. It still gives Internal Error. I have just revisited the
page three times now, and every time it still fails.

I am not lying, I am not making this up. Here is the text:



Internal Server Error

The server encountered an internal error or misconfiguration and was
unable to complete your request.

Please contact the server administrator, supp...@superhost.gr and inform
them of the time the error occurred, and anything you might have done
that may have caused the error.

More information about this error may be available in the server error
log.

Additionally, a 404 Not Found error was encountered while trying to use
an ErrorDocument to handle the request.
Apache/2.2.24 (Unix) mod_ssl/2.2.24 OpenSSL/1.0.0-fips
mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Server at
superhost.gr Port 80


I know that you do not lie and also i think i know why *you* 
specifically can load my webiste.



i think your ip address does not have a PTR entry (reverse DNS entry)

and when you try to laod superhost.gr this lines fail for you and hece 
it errs out an internal server error.


host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]


i just switched the above line to to avoid missing PTRs

host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or 'UnResolved'

Try now please.
--
http://mail.python.org/mailman/listinfo/python-list


Re: A certainl part of an if() structure never gets executed.

2013-06-12 Thread Νικόλαος Κούρας

On 12/6/2013 12:07 μμ, F�bio Santos wrote:

On Wed, Jun 12, 2013 at 9:54 AM, Νικόλαος Κούρας  wrote:

but if enumerate yields 0 instead of '==' then elif '=' not in
year of course fails.

So, i must tell:

for i, month in enumerate(months):
 print(' %s ' % (i, month) )

to somehow return '==' instead of 0 but don't know how.
--
http://mail.python.org/mailman/listinfo/python-list


Well, you could try this:


for i, month in enumerate(months):
 if i == 0:
 month = ('=' * 10)
 print(' %s ' % (i, month) )


No?


I'am afraid not Fabio, i just tried byt sumbitting only the year, not 
name not month


after printign the valeus to see what went wrong, the values look like:

== 0 2010

instead of:

== ==  2010

== is the value of the month when its not selected by the user, 
but even with your suggestions it reurns t0 intead of the equal signs.


--
http://mail.python.org/mailman/listinfo/python-list


Re: A few questiosn about encoding

2013-06-12 Thread Νικόλαος Κούρας
>> (*) infact UTF8 also indicates the end of each character

> Up to a point.  The initial byte encodes the length and the top few
> bits, but the subsequent octets aren’t distinguishable as final in
> isolation.  0x80-0xBF can all be either medial or final.


So, the first high-bits are a directive that UTF-8 uses to know how many 
bytes each character is being represented as.

0-127 codepoints(characters) use 1 bit to signify they need 1 bit for 
storage and the rest 7 bits to actually store the character ?

while

128-256 codepoints(characters) use 2 bit to signify they need 2 bits for 
storage and the rest 14 bits to actually store the character ?

Isn't 14 bits way to many to store a character ? 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Turnign greek-iso filenames => utf-8 iso

2013-06-12 Thread Νικόλαος Κούρας

root@nikos [/home/nikos/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
root@nikos [/home/nikos/www/data/apps]#

--
http://mail.python.org/mailman/listinfo/python-list


Re: Turnign greek-iso filenames => utf-8 iso

2013-06-12 Thread Νικόλαος Κούρας

On 12/6/2013 11:31 πμ, Steven D'Aprano wrote:

On Wed, 12 Jun 2013 08:02:24 +0000, Νικόλαος Κούρας wrote:


i tried to insert
print( filename )
sys.exit(0)


That's not very useful. That will just print ONE file name, then stop.
You have how many files in there? Two? Twenty? What if the problem does
not lie with the first one?


just before the execute
and the output is just Pacman.exe as seen in

http://superhost.gr/?page=files.py


Wrong. The output is:

Internal Server Error


print( filenames )
sys.exit(0)


No it dosnt not, it loads properly and if you visit it again you will 
see all the files being displayed since now i:


print( filenames )
sys.exit(0)

Thne grek ones ar displayed as 
'\udcce\udc95\udccf\udc85\udccf\udc87\udcce\udcae 
\udccf\udc84\udcce\udcbf\udccf\udc85 
\udcce\udc99\udcce\udcb7\udccf\udc83\udcce\udcbf\udccf\udc8d.mp3' in Chrome


dont know why since the above procedure supposed to turned them into utf-8

ls -l apps though via putty display all filesnames correctly.

===
# Collect filenames of the path dir as strings
filenames = os.listdir( '/home/nikos/public_html/data/apps/' )

# Build a set of 'path/to/filename' based on the objects of path dir
filepaths = set()
for filename in filenames:
filepaths.add( filename )

# Load'em
for filename in filenames:
try:
		# Check the presence of a file against the database and insert if it 
doesn't exist

print( filenames )
sys.exit(0)
cur.execute('''SELECT url FROM files WHERE url = %s''', 
filename )
data = cur.fetchone()
===

Into the database only 2 english have been inserted pacman.exe and one 
other english filenames before filename breaks into the execute statemnt.


--
http://mail.python.org/mailman/listinfo/python-list


Re: A certainl part of an if() structure never gets executed.

2013-06-12 Thread Νικόλαος Κούρας

On 12/6/2013 11:27 πμ, Denis McMahon wrote:

On Tue, 11 Jun 2013 13:20:52 -0700, Νικόλαος Κούρας wrote:


The above if structure works correctly *only* if the user sumbits by
form:

name, month, year or month, year

If, he just enter a year in the form and sumbit then, i get no error,
but no results displayed back.

Any ideas as to why this might happen?


Yes, I know exactly why this is happening.

It is for one of two reasons. You may determine which one using the
following secret code which I stole from the illuminati in 1836:

import random

reason = { 1: "Input data is not as expected by coder", 2: "Flow control
logic not performing as coder expects", 3: "Badger Badger Badger Badger
Badger Badger Badger Badger Mushroom", 4: "Please try again", 5:
"Snake", 6: "Grumpy cat says fix your own damn code", 7: "I'll be
back" }

print reason[ random.choice( reason.keys() ) ]

Note - this only has a small chance of actually doing what you want (ie
giving a possibly accurate answer), but it sounds as if that's a level of
precision you're used to working with anyway.

On a slightly more serious note, if you can't apply yourself to debugging
a case of "the program logic isn't doing what I expect" for some value of
program logic that you coded, that may be a hint that:

a) you don't actually understand what the program logic is doing

b) you shouldn't be writing logic so complex that you can't see how to
debug it

c) your logic is overly convoluted and complex

d) all of the above

So perhaps you need to scrub the logic altogether, and start again taking
smaller steps.

You could also perhaps do with a lesson in De Morgan's theorem:

not a and not b and not c = not ( a or b or c )

not a or not b or not c = not ( a and b and c )

and sometimes the alternative form is easier to understand

Now, looking at your code here are two important questions:

(1) What is the initial values of name, month and year?
(2) Which block is actually being executed?

Bear in mind that if a branch other than one you expect to be executed is
executing, the fail condition might not be what you think it is.
Specifically, is it possible that the code is executing the wrong branch
and tripping up when it tries to generate or perhaps execute the sql
statement empty strings, or just not getting any result from the sql
because of the empty strings?

Hint - take the code from the current file, apply a liberal smattering of
print statements, and test it for various values of month, year and name.

def test(name, month, year):
 print "name, month, year ::", name, month, year
if not re.search( '=', name ) and not re.search( '=', month ) and
not re.search( '=', year ):
print "branch 1"
elif not re.search( '=', month ) and not re.search( '=', year ):
print "branch 2"
elif not re.search( '=', year ):
print "branch 3"
else:
print "branch 4"

# testing logic for 8 possible input conditions

test("=", "=", "=")
test("=", "=", "x")
test("=", "x", "=")
test("=", "x", "x")
test("x", "=", "=")
test("x", "=", "x")
test("x", "x", "=")
test("x", "x", "x")



Thank you but i already foudn out what the problem was, i just don't 
known how to fix it. Here is is again:



Here is the defines of those variables. as you can see are all tuples

# populate names, months, years
names.add( '==' )
months = ( '==', 'Ιανουάριος', 'Φεβρουάριος', 'Μάρτιος',
'Απρίλιος', 'Μάϊος', 'Ιούνιος',
   'Ιούλιος', 'Αύγουστος', 'Σεπτέμβριος', 'Οκτώβριος',
'Νοέμβριος',
'Δεκέμβριος' )
years = ( '==', 2010, 2011, 2012, 2013 )




i used print( name, month, year ) and noticed that all values 
returned as expected when selected fro drop-down menus and submitted.


But when it comes to select '==' from month instead of
'==' to be submitted a zero gets submitted and i think the 
problem is the way i'm filling up months into the drop down menu which is:



for i, month in enumerate(months):
print(' %s ' % (i, month) )


the if case does not execute because of the way it checks for None entry
which is: elif '=' not in year:

but if enumerate yields 0 instead of '==' then elif '=' not in
year of course fails.

So, i must tell:

for i, month in enumerate(months):
print(' %s ' % (i, month) )

to somehow return '==' instead of 0 but don't know how.
--
http://mail.python.org/mailman/listinfo/python-list


Turnign greek-iso filenames => utf-8 iso

2013-06-12 Thread Νικόλαος Κούρας
#
# Collect directory and its filenames as bytes
path = b'/home/nikos/public_html/data/apps/'
files = os.listdir( path )

for filename in files:
# Compute 'path/to/filename'
filepath_bytes = path + filename

for encoding in ('utf-8', 'iso-8859-7', 'latin-1'):
try: 
filepath = filepath_bytes.decode( encoding )
except UnicodeDecodeError:
continue

# Rename to something valid in UTF-8 
if encoding != 'utf-8': 
os.rename( filepath_bytes, filepath.encode('utf-8') 
)

assert os.path.exists( filepath.encode('utf-8') )
break 
else: 
# This only runs if we never reached the break
raise ValueError( 'unable to clean filename %r' % 
filepath_bytes ) 


# Collect filenames of the path dir as strings
filenames = os.listdir( '/home/nikos/public_html/data/apps/' )

# Build a set of 'path/to/filename' based on the objects of path dir
filepaths = set()
for filename in filenames:
filepaths.add( filename )

==
# Load'em
for filename in filenames:
try:
# Check the presence of a file against the database and 
insert if it doesn't exist
cur.execute('''SELECT url FROM files WHERE url = %s''', 
filename )
data = cur.fetchone()


[Wed Jun 12 10:56:56 2013] [error] [client 79.103.41.173] Traceback (most 
recent call last):, referer: http://superhost.gr/
[Wed Jun 12 10:56:56 2013] [error] [client 79.103.41.173]   File "/home/
nikos/public_html/cgi-bin/files.py", line 102, in , referer: 
http://superhost.gr/
[Wed Jun 12 10:56:56 2013] [error] [client 79.103.41.173] print
( filename ), referer: http://superhost.gr/
[Wed Jun 12 10:56:56 2013] [error] [client 79.103.41.173]   File "/usr/
local/lib/python3.3/codecs.py", line 355, in write, referer: http://
superhost.gr/
[Wed Jun 12 10:56:56 2013] [error] [client 79.103.41.173] data, 
consumed = self.encode(object, self.errors), referer: http://superhost.gr/
[Wed Jun 12 10:56:56 2013] [error] [client 79.103.41.173] 
UnicodeEncodeError: 'utf-8' codec can't encode character '\\udcce' in 
position 0: surrogates not allowed, referer: http://superhost.gr/
=

i tried to insert
print( filename )
sys.exit(0)

just before the execute
and the output is just Pacman.exe as seen in 

http://superhost.gr/?page=files.py

Seens the encoding precedure successfully turned all the filenames from 
greek-iso to utf-8 without failing, why woul it still be encoding issues 
when it comes to execute?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A certainl part of an if() structure never gets executed.

2013-06-12 Thread Νικόλαος Κούρας
On Tue, 11 Jun 2013 22:49:05 -0600, Michael Torrie wrote:

> What do each of these functions return?  When you print out
> re.search('=', name) what happens?

First of all i have changed the code to the following because using a 
regex 
to detect a single char was an overkill.

if '=' not in name and '=' not in month and '=' not in year:
cur.execute( '''SELECT * FROM works WHERE clientsID = (SELECT id 
FROM clients WHERE name = %s) and MONTH(lastvisit) = %s and YEAR
(lastvisit) 
= %s ORDER BY lastvisit ASC''', (name, month, year) )
elif '=' not in month and '=' not in year:
cur.execute( '''SELECT * FROM works WHERE MONTH(lastvisit) = %s 
and YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', (month, year) )
elif '=' not in year:
cur.execute( '''SELECT * FROM works WHERE YEAR(lastvisit) = %s 
ORDER BY lastvisit ASC''', year )
else:
print( 'Πώς να γίνει αναζήτηση αφού δεν 
επέλεξες ούτε πελάτη ούτε μήνα ή τουλάχιστον το έτος?' )
print( '' )
sys.exit(0)


Here is the definements of those varibles. as you can see are all tuples

# populate names, months, years
names.add( '==' )
months = ( '==', 'Ιανουάριος', 'Φεβρουάριος', 'Μάρτιος', 
'Απρίλιος', 'Μάϊος', 'Ιούνιος',
   'Ιούλιος', 'Αύγουστος', 'Σεπτέμβριος', 'Οκτώβριος', 
'Νοέμβριος', 
'Δεκέμβριος' )
years = ( '==', 2010, 2011, 2012, 2013 )




i used  print( name, month, year ) and noticed that all values returned as 
expected when selected fro drop-down menus and submitted.

But when it comes to select '==' form month instead of 
'==' to be submitted a zero gets submitted and i think the problem 
is the way i'm filling up months into the drop down menu which is:


for i, month in enumerate(months):
print(' %s ' % (i, month) )


the if case does not execute because of the way it checks for None entry 
which is: elif '=' not in year:

but if enumerate yields 0 instead of '==' then elif '=' not in 
year of course fails.

So, i must tell:

for i, month in enumerate(months):
print(' %s ' % (i, month) )

to somehow return '==' instead of 0 but dont know how.



-- 
http://mail.python.org/mailman/listinfo/python-list


A certainl part of an if() structure never gets executed.

2013-06-11 Thread Νικόλαος Κούρας
[code]
if not re.search( '=', name ) and not re.search( '=', month ) 
and not re.search( '=', year ):
cur.execute( '''SELECT * FROM works WHERE clientsID = 
(SELECT id FROM clients WHERE name = %s) and MONTH(lastvisit) = %s and 
YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', (name, month, year) )
elif not re.search( '=', month ) and not re.search( '=', year ):
cur.execute( '''SELECT * FROM works WHERE 
MONTH(lastvisit) = %s and YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', 
(month, year) )
elif not re.search( '=', year ):
cur.execute( '''SELECT * FROM works WHERE 
YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', year )
else:
print('''Πώς να γίνει αναζήτηση αφού δεν επέλεξες 
ούτε πελάτη ούτε μήνα ή τουλάχιστον το έτος?''')
print( '' )
sys.exit(0)

data = cur.fetchall()

hits = money = 0

for row in data:
hits += 1
money = money + row[2]

..
..
selects based on either name, month, year or all of them
[/code]


The above if structure works correctly *only* if the user sumbits by form:

name, month, year
or
month, year

If, he just enter a year in the form and sumbit then, i get no error, but no 
results displayed back.

Any ideas as to why this might happen?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: e-mail reply to old/archived message (was Re: Encoding questions (continuation))

2013-06-11 Thread Νικόλαος Κούρας
Τη Τρίτη, 11 Ιουνίου 2013 2:21:50 μ.μ. UTC+3, ο χρήστης Andreas Perstinger 
έγραψε:

> > sending the mail to python-list@python.org will just open anew
> > subject intead of replyign to an opened thread.

> You would need to find out the Message-Id of the post you want to reply 
> to and then add manually the In-Reply-To and References headers to your 
> e-mail using that Id.

You mean by viewing for example your post as 'view original source', finding 
In-Reply-To: <71d585e6-bb98-47b7-9a45-7cde1ba0c...@googlegroups.com>

and then compose a new mail as:

to: Andreas Perstinger 
cc: In-Reply-To: <71d585e6-bb98-47b7-9a45-7cde1ba0c...@googlegroups.com>

is this the way Andrea?

but what the diif between rplyt-to and message-id ?
Message-ID: 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Receing a form variable as a list instead of as a string

2013-06-11 Thread Νικόλαος Κούρας
But if i write it as:

if not page and os.path.exists( file ): 
# it is an html template 
page = file.replace( '/home/nikos/public_html/', '' ) 
elif page or form.getvalue('show') == 'log': 
# it is a python script 
page = page 
elif page or form.getvalue('show') == 'stats': 
page = file.replace( '/home/nikos/public_html/', '' )
==

I get the error that i cannot use 'replac'e to a 'list'.
How can i avoid that?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encoding questions (continuation)

2013-06-11 Thread Νικόλαος Κούρας
Τη Τρίτη, 11 Ιουνίου 2013 10:52:02 π.μ. UTC+3, ο χρήστης Larry Hudson έγραψε:
> On 06/10/2013 06:56 AM, Νικόλαος Κούρας wrote:
> 
> 
> 
> >>> ps. i tried to post a reply to the thread i opend via thunderbird mail
> 
> >>> client, but not as a reply to somne other reply but as  new mail send to
> 
> >>> python list.
> 
> >>> because of that a new thread will be opened. How can i tell thunderbird
> 
> >>> to reply to the original thread and not start a new one?
> 
> >> By replying to an email in that thread.
> 
> >
> 
> > Yes thats obvious.
> 
> > What is not obvious is how you reply back to a thread by giving extra info 
> > when you are not replying to a mail formt tha thread or when you ahve 
> > deleted the reply for a member
> 
> >
> 
> > sending the mail to python-list@python.org will just open anew subject 
> > intead of replyign to an opened thread.
> 
> >
> 
> In Thunderbird, click on "Followup" not "Reply".

Lets say i want to anser to your question by mail and not by using spamming 
'\n' google groups, how will i be ble to do it by follow up?

i think your suggestions works only if you have a mail handy in TB and you hit 
follow-up what if you dont have the mail handy?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encoding questions (continuation)

2013-06-11 Thread Νικόλαος Κούρας
Τη Τρίτη, 11 Ιουνίου 2013 1:19:25 π.μ. UTC+3, ο χρήστης Lele Gaifax έγραψε:

> Maybe he just want to prove we are smart enough... 
> Or maybe his encoding algorithm needs some refinement 
> :-)

I already knwo you are smart enough, the latter is what needs some more 
refinement work :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Receing a form variable as a list instead of as a string

2013-06-11 Thread Νικόλαος Κούρας
Τη Τρίτη, 11 Ιουνίου 2013 2:51:04 μ.μ. UTC+3, ο χρήστης Ulrich Eckhardt έγραψε:

> 
> For that, you'd have to adjust the code that you received it from. If 
> that's not possible, convert it to a string yourself. But didn't you 
> want a "form variable"?

i manages to work around it by using this:
Indeed as Andreas said i was overusing the form variable 'page'

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

if not page and os.path.exists( file ):
# it is an html template
page = file.replace( '/home/nikos/public_html/', '' )
elif page or form.getvalue('show'):
# it is a python script
page = page
else:
#when everything else fails default
page = page

-- 
http://mail.python.org/mailman/listinfo/python-list


Receing a form variable as a list instead of as a string

2013-06-11 Thread Νικόλαος Κούρας
page = form.getvalue('page')

if form.getvalue('show') == 'log' or page:
# it is a python script
page = page.replace( '/home/nikos/public_html/cgi-bin/', '' )
elif os.path.exists( page ):
# it is an html template
page = page.replace( '/home/nikos/public_html/', '' )



[Tue Jun 11 13:35:30 2013] [error] [client 79.103.41.173]   File 
"/home/nikos/public_html/cgi-bin/metrites.py", line 28, in , referer: 
http://superhost.gr/
[Tue Jun 11 13:35:30 2013] [error] [client 79.103.41.173] page = 
page.replace( '/home/nikos/public_html/', '' ), referer: http://superhost.gr/
[Tue Jun 11 13:35:30 2013] [error] [client 79.103.41.173] AttributeError: 
'list' object has no attribute 'replace', referer: http://superhost.gr
=

but page is a form variable coming from a previous sumbitted form
why the error says 'page' is a list?

How to receive that form variable as a string?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reply to post 'Tryign to add a valkue to a set'

2013-06-10 Thread Νικόλαος Κούρας
Since dict.keys() return a list of the keys in the dict and the keys are 
associated with the dict's values why doesnt it work the other way around too?

I'm talking about this:
[code]
for key in sorted( months.keys() ): 
 print(''' 
  %s  
 ''' % (months[key], key) ) 

[/code]

I could have uses ordered by kees but that orders key alphabetically, and 
montha re not displayed in the usual row. ordering by values though it would be 
a perfect fit.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-10 Thread Νικόλαος Κούρας
Τη Δευτέρα, 10 Ιουνίου 2013 2:59:03 μ.μ. UTC+3, ο χρήστης Steven D'Aprano 
έγραψε:
> On Mon, 10 Jun 2013 00:10:38 -0700, nagia.retsina wrote:
> 
> 
> 
> > Τη Κυριακή, 9 Ιουνίου 2013 3:31:44 μ.μ. UTC+3, ο χρήστης Steven D'Aprano
> 
> > έγραψε:
> 
> > 
> 
> >> py> c = 'α'
> 
> >> py> ord(c)
> 
> >> 945
> 
> > 
> 
> > The number 945 is the characters 'α' ordinal value in the unicode
> 
> > charset correct?
> 
> 
> 
> Correct.
> 
> 
> 
> 
> 
> > The command in the python interactive session to show me how many bytes
> 
> > this character will take upon encoding to utf-8 is:
> 
> > 
> 
>  s = 'α'
> 
>  s.encode('utf-8')
> 
> > b'\xce\xb1'
> 
> > 
> 
> > I see that the encoding of this char takes 2 bytes. But why two exactly?
> 
> 
> 
> Because that's how UTF-8 works. If it was a different encoding, it might 
> 
> be 4 bytes, or 2, or 1, or 101, or 7, or 3. But it is UTF-8, so it takes 
> 
> 2 bytes. If you want to understand how UTF-8 works, look it up on 
> 
> Wikipedia. 
> 
> 
> 
> 
> 
> > How do i calculate how many bits are needed to store this char into
> 
> > bytes?
> 
> 
> 
> Every byte is made of 8 bits. There are two bytes. So multiply 8 by 2.
> 
> 
> 
> 
> 
> > Trying to to the same here but it gave me no bytes back.
> 
> > 
> 
>  s = 'a'
> 
>  s.encode('utf-8')
> 
> > b'a'
> 
> 
> 
> There is a byte there. The byte is printed by Python as b'a', which in my  
> opinion is a design mistake. That makes it look like a string, but it is  
> not a string, and would be better printed as b'\x61'. But regardless of 
> the display, it is still a single byte.


Perhaps, up to 127 ASCII chars python thinks its better for human to read the 
character representaion of the stored byte, instead of hex's. Just a guess.

> Just like 0o1234 uses octal, "o" for Octal.
> And 0x123EF uses hexadecimal. "x" for heXadecimal.

Why the leadin zero before octal's 'o' and hex's 'x'  and binary's 'b' ?


Iam not goin to tired you any more, because ia hve exhaust myself tlo days now 
tryign to get my head around this.

Please confirm i ahve understood correctly:

I did but docs confuse me even more. Can you pleas ebut it simple.

Unicode as i understand it was created out of need for a bigger character set 
compared to ASCII which could hold up to 127 chars(and extended versions of it 
up to 256), that could be able to hold all worlds symbols.

ASCII and Unicode are character sets.

Everything else sees to be an encoding system that work upon those characters 
sets.

If what i said is true the last thing that still confuses me is that

iso-8859-7(256 chars) seems like charactet set and an encoding method too.
Can it be both or it is iso-8859-7 encoding method of Unicode character set 
similar as uTF8 is also Unicode's encoding method?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reply to post 'Tryign to add a valkue to a set'

2013-06-10 Thread Νικόλαος Κούρας
Τη Δευτέρα, 10 Ιουνίου 2013 4:14:33 μ.μ. UTC+3, ο χρήστης Ulrich Eckhardt 
έγραψε:
> Am 10.06.2013 12:57, schrieb Νικόλαος Κούρας:
> 
> >  >Τη Δευτέρα, 10 Ιουνίου 2013 12:40:01 μ.μ. UTC+3, ο χρήστης Ulrich
> 
> > Eckhardt έγραψε:
> 
> >
> 
> > for key in sorted( months.keys() ):
> 
> >  print('''
> 
> >   %s 
> 
> >  ''' % (months[key], key) )
> 
> >
> 
> > this in fact works, it sorts the dict by its keys()
> 
> 
> 
> No, it does not sort the dict. Please slow down, relax and take a look 
> 
> at the documentation of sorted(). You are jumping to conclusions based 
> 
> on flawed expectations and assumptions, which can only yield garbage in 
> 
> the end.
> 
> 
> 
> Uli

It soerts it just fine by keys() alpabeticall but this isnt what i want, i need 
sorting by values()

for key in sorted( months.values() ): 
 print(''' 
  %s  
 ''' % (key, what should_we put here_to get the actual months 
name? ) 

the value is a vale form  the values in order, but how do i specify the 
correspondign key to that value?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encoding questions (continuation)

2013-06-10 Thread Νικόλαος Κούρας
Τη Δευτέρα, 10 Ιουνίου 2013 2:41:07 μ.μ. UTC+3, ο χρήστης Steven D'Aprano 
έγραψε:
> On Mon, 10 Jun 2013 14:13:00 +0300, Νικόλαος Κούρας wrote:
> 
> 
> 
> > Τη Δευτέρα, 10 Ιουνίου 2013 1:42:25 μ.μ. UTC+3, ο χρήστης Andreas
> 
> > Perstinger έγραψε:
> 
> > 
> 
> >  >  >>> s = b'\xce\xb1'
> 
> >  >
> 
> >  >  >>> s[0]
> 
> >  >
> 
> >  > 206
> 
> > 
> 
> > 's' is a byte object, how can you treat it as a string asking to present
> 
> > you its first character?
> 
> 
> 
> That is not treating it as a string, and it does not present the first 
> 
> character. It presents the first byte, which is a number between 0 and 
> 
> 255, not a character.
> 
> 
> 
> py> alist = [0xce, 0xb1]
> 
> py> alist[0]
> 
> 206


To my mind alist[0] should yield '0xce'

> Is that treating alist as a string? No, of course not. Strings are not 
> 
> the only object that have indexing object[position].

Yes actually it does.

s string is a series of characters.

a list is a series of objects, which can be chars, strings, integers, other 
data structures.

So doing a_list[0] is similar of doing a_string[00


> >  > A byte object is a sequence of bytes (= integer values) and support 
> > indexing


Isn't a byte a series of zeros and ones, like 01010101 ?
So why you say bytes are integers since its numbers into a binary system?
perhsp you mean a represantaion of a bye to a decimal value?

> I am not saying this to insult you, or to be rude. But you are obviously  
> struggling with the most basic concepts, like what a byte is. You need to  
> go back to basics and learn the simple things, and perhaps if it is 
> explained to you in your native language, you will understand it better.
> 

> I have already provided an example. Many other people have provided 
> 
> examples. Please read them.

i do read everythign being posted back to me.

> > ps. i tried to post a reply to the thread i opend via thunderbird mail
> > client, but not as a reply to somne other reply but as  new mail send to
> > python list.
> > because of that a new thread will be opened. How can i tell thunderbird
> > to reply to the original thread and not start a new one?
> By replying to an email in that thread.

Yes thats obvious.
What is not obvious is how you reply back to a thread by giving extra info when 
you are not replying to a mail formt tha thread or when you ahve deleted the 
reply for a member

sending the mail to python-list@python.org will just open anew subject intead 
of replyign to an opened thread.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reply to post 'Tryign to add a valkue to a set'

2013-06-10 Thread Νικόλαος Κούρας
Τη Δευτέρα, 10 Ιουνίου 2013 4:14:33 μ.μ. UTC+3, ο χρήστης Ulrich Eckhardt 
έγραψε:
> Am 10.06.2013 12:57, schrieb Νικόλαος Κούρας:
> 
> >  >Τη Δευτέρα, 10 Ιουνίου 2013 12:40:01 μ.μ. UTC+3, ο χρήστης Ulrich
> 
> > Eckhardt έγραψε:
> 
> >
> 
> > for key in sorted( months.keys() ):
> 
> >  print('''
> 
> >   %s 
> 
> >  ''' % (months[key], key) )
> 
> >
> 
> > this in fact works, it sorts the dict by its keys()
> 
> 
> 
> No, it does not sort the dict. Please slow down, relax and take a look 
> 
> at the documentation of sorted(). You are jumping to conclusions based 
> 
> on flawed expectations and assumptions, which can only yield garbage in 
> 
> the end.

it doe ssort the dict at least for keys() why not for values() too?



for key in sorted( months.keys() ): 
 print(''' 
  %s  
 ''' % (months[key], key) ) 

this in fact works, it sorts the dict by its keys() was mistaken before 
but the sorting aint correct because its done alphabetically and not by 
integer value. 
We need value
-- 
http://mail.python.org/mailman/listinfo/python-list


Encoding questions (continuation)

2013-06-10 Thread Νικόλαος Κούρας
Τη Δευτέρα, 10 Ιουνίου 2013 1:42:25 μ.μ. UTC+3, ο χρήστης Andreas 
Perstinger έγραψε:


>  >>> s = b'\xce\xb1'
>
>  >>> s[0]
>
> 206

's' is a byte object, how can you treat it as a string asking to present 
you its first character?


>
>  >>> s[1]
>
> 177

's' is a byte object, how can you treat it as a string asking to present 
you its first character?


> A byte object is a sequence of bytes (= integer values) and support  
indexing


A sequeence of bystes is a a sequence of bits which is zeros and one's 
not integers.



> Because your method doesn't work.
> If you use all possible 256 bit-combinations to represent a valid
> character, how do you decide where to stop in a sequence of bytes?

How you mean? please provice an example so i can understand this.

> > EBCDIC and ASCII and Unicode are charactet sets, correct?

> > iso-8859-1, iso-8859-7, utf-8, utf-16, utf-32 and so on are 
encoding methods, right?


> Look at http://www.unicode.org/glossary/ for an explanation of all 
the terms


I did but docs confuse me even more. Can you pleas ebut it simple.

Unicode as i udnerstand it was created out of need for a big character 
set that could be able to hold all worlds symboles, whiel ascii could 
only store first 127 and extended 246.


ascii and unicode are character sets.

everything else sees to be an encoding system that work upne the 
characters set(never deen them though act on the scii charset)


but iso-8859-7 is both a charset and an encoding system?



ps. i tried to post a reply to the thread i opend via thunderbird mail 
client, but not as a reply to somne other reply but as  new mail send to 
python list.

because of that a new thread will be opened.
How can i tell thunderbird to reply to the original thread and not start 
a new one?
Sorry for that but i can' even post via google groups any more. it says 
that an error occured.
Sorry for this. please xplain hpw to reply properly to correct hread via 
mail.

thank you.
--
Webhost && Weblog 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reply to post 'Tryign to add a valkue to a set'

2013-06-10 Thread Νικόλαος Κούρας
>Τη Δευτέρα, 10 Ιουνίου 2013 12:40:01 μ.μ. UTC+3, ο χρήστης Ulrich 
Eckhardt έγραψε:


for key in sorted( months.keys() ):
print('''
 %s 
''' % (months[key], key) )

this in fact works, it sorts the dict by its keys() was mistaken before 
but the sorting aint correct because its done alphabetically and not by 
integer value.

We need values.


for key in sorted( months.values() ):
print('''
 %s 
''' % (key, what should_we put here_to get the actual months 
name? )

--
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting a set works, sorting a dictionary fails ?

2013-06-10 Thread Νικόλαος Κούρας
Τη Δευτέρα, 10 Ιουνίου 2013 12:40:01 μ.μ. UTC+3, ο χρήστης Ulrich Eckhardt 
έγραψε:
> Am 10.06.2013 10:29, schrieb Νικόλαος Κούρας:
> 
> > for key in sorted( months.values() ):
> 
>^^^   ^^
> 
> 
> 
> > KeyError 1 ??!! All i did was to tell python to sort the dictionary values, 
> > which are just integers.
> 
> 
> 
> ...and which you then proceed to use as key, which is obviously wrong.

How hsould have i written it then?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-10 Thread Νικόλαος Κούρας
>  s = 'α' 
>  s.encode('utf-8') 
> > b'\xce\xb1' 

'b' stands for binary right? 
 b'\xce\xb1' = we are looking at a byte in a hexadecimal format? 
if yes how could we see it in binary and decimal represenation? 
  
> > I see that the encoding of this char takes 2 bytes. But why two exactly? 
> > How do i calculate how many bits are needed to store this char into bytes? 
  
> Because utf-8 takes 1 to 4 bytes to encode characters 

Since 2^8 = 256, utf-8 should store the first 256 chars of unicode charset 
using 1 byte. 

Also Since 2^16 = 65535, utf-8 should store the first 65535 chars of unicode 
charset using 2 bytes and so on. 

But i know that this is not the case. 
But i dont understand why. 


>  s = 'a' 
>  s.encode('utf-8') 
> > b'a' 
> utf-8 takes ASCII as it is, as 1 byte. They are the same 

EBCDIC and ASCII and Unicode are charactet sets, correct? 

iso-8859-1, iso-8859-7, utf-8, utf-16, utf-32 and so on are encoding methods, 
right?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting a set works, sorting a dictionary fails ?

2013-06-10 Thread Νικόλαος Κούρας
After many tried this did the job:

for key in sorted(months.items(),key=lambda num : num[1]):
print('''
 %s 
''' % (key[1], key[0]) )


but its really frustrating not being able to:

for key in sorted( months.values() ): 
print(''' 
 %s  
''' % (months[key], key) ) 

Which seemed to be an abivous way to do it.
names set() was able to order like this why not the dictionary too?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-10 Thread Νικόλαος Κούρας
Τη Δευτέρα, 10 Ιουνίου 2013 11:15:38 π.μ. UTC+3, ο χρήστης Andreas Perstinger 
έγραψε:

What is the difference between len('nikos') and len(b'nikos')
First beeing the length of string nikos in characters while the second being 
the length of an ???


> The python interpreter will represent all values below 256 as ASCII 
> characters if they are printable:

>  >>> ord(b'a')
> 97
>  >>> hex(97)
> '0x61'
>  >>> b'\x61' == b'a'
> True
> The Python designers have decided to use b'a' instead of b'\x61'.

b'a' and b'\x61' are the bytestrings of char 'a' after utf-8 encoding?

This ord(b'a' )should give an error in my opinion:

ord('a') should return the ordinal value of char 'a', not ord(b'a')
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting a set works, sorting a dictionary fails ?

2013-06-10 Thread Νικόλαος Κούρας
Trying this:

months = { 'Ιανουάριος':1, 'Φεβρουάριος':2, 'Μάρτιος':3, 'Απρίλιος':4, 
'Μάϊος':5, 'Ιούνιος':6, \
   'Ιούλιος':7, 'Αύγουστος':8, 'Σεπτέμβριος':9, 'Οκτώβριος':10, 
'Νοέμβριος':11, 'Δεκέμβριος':12 }

for key in sorted( months.values() ):
print('''
 %s 
''' % (months[key], key) )


output this:

[Mon Jun 10 11:25:11 2013] [error] [client 79.103.41.173]   File 
"/home/nikos/public_html/cgi-bin/pelatologio.py", line 310, in , 
referer: http://superhost.gr/
[Mon Jun 10 11:25:11 2013] [error] [client 79.103.41.173] ''' % 
(months[key], key) ), referer: http://superhost.gr/
[Mon Jun 10 11:25:11 2013] [error] [client 79.103.41.173] KeyError: 1, referer: 
http://superhost.gr/

KeyError 1 ??!! All i did was to tell python to sort the dictionary values, 
which are just integers.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting a set works, sorting a dictionary fails ?

2013-06-10 Thread Νικόλαος Κούρας
Τη Δευτέρα, 10 Ιουνίου 2013 11:16:37 π.μ. UTC+3, ο χρήστης Νικόλαος Κούρας 
έγραψε:
> What if i wanted to sort it out if alphabetically and not by the values?
> 
> 
> 
> Thsi worked:
> 
> 
> 
> for item in sorted(months.items(),key=lambda num : num[1]):
> 
> 
> 
> but this failed:
> 
> 
> 
> for item in sorted(months.items()):
> 
> 
> 
> why?

sorry what i was tryign to say was why not as: for item in 
sorted(months.values()):

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting a set works, sorting a dictionary fails ?

2013-06-10 Thread Νικόλαος Κούρας
What if i wanted to sort it out if alphabetically and not by the values?

Thsi worked:

for item in sorted(months.items(),key=lambda num : num[1]):

but this failed:

for item in sorted(months.items()):

why?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-10 Thread Νικόλαος Κούρας
Τη Δευτέρα, 10 Ιουνίου 2013 10:51:34 π.μ. UTC+3, ο χρήστης Larry Hudson έγραψε:

> > I mean utf-8 could use 1 byte for storing the 1st 256 characters. I meant 
> > up to 256, not above 256.

> 0 - 127, yes.
> 128 - 255 -> one byte of a multibyte code.

you mean that in utf-8 for 1 character to be stored, we need 2 bytes?
I still havign troubl e understanding this.

Since 2^8 = 256, utf-8 would need 1 byte to store the 1st 256 characters but 
instead its using 1 byte up to the first 127 value and then 2 bytes for 
anyhtign above.  Why?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-09 Thread Νικόλαος Κούρας
Please and tell me that this actually can be solved.
Iam willing to try anything for 'files.py' to load propelry.
Every thign works as expected in my webiste, have manages to correct 
pelatologio.poy and koukos.py.

This is the last thing the webiste needs, that is files.py to load so users can 
grab importan files in greek format.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Errin when executing a cgi script that sets a cookie in the browser

2013-06-09 Thread Νικόλαος Κούρας
Τη Κυριακή, 9 Ιουνίου 2013 8:27:53 π.μ. UTC+3, ο χρήστης nagia@gmail.com 
έγραψε:
> Trying 
> 
> 
> 
> yum install dos2unix
> 
> 
> 
> and 
> 
> 
> 
> root@nikos [/home/nikos/www/cgi-bin]# dos2unix koukos.py
> 
> dos2unix: converting file koukos.py to UNIX format ...
> 
> 
> 
> 
> 
> Then browsed to the page again in Chrome it worked as expected :-)

So how from  python koukos.py script was interpreting correctly and from 
browser it failed?
-- 
http://mail.python.org/mailman/listinfo/python-list


A few questiosn about encoding

2013-06-09 Thread Νικόλαος Κούρας
A few questiosn about encoding please:

>> Since 1 byte can hold up to 256 chars, why not utf-8 use 1-byte for 
>> values up to 256? 

>Because then how do you tell when you need one byte, and when you need 
>two? If you read two bytes, and see 0x4C 0xFA, does that mean two 
>characters, with ordinal values 0x4C and 0xFA, or one character with 
>ordinal value 0x4CFA? 

I mean utf-8 could use 1 byte for storing the 1st 256 characters. I meant up to 
256, not above 256. 


>> UTF-8 and UTF-16 and UTF-32 
>> I though the number beside of UTF- was to declare how many bits the 
>> character set was using to store a character into the hdd, no? 

>Not exactly, but close. UTF-32 is completely 32-bit (4 byte) values. 
>UTF-16 mostly uses 16-bit values, but sometimes it combines two 16-bit 
>values to make a surrogate pair. 

A surrogate pair is like itting for example Ctrl-A, which means is a 
combination character that consists of 2 different characters? 
Is this what a surrogate is? a pari of 2 chars? 


>UTF-8 uses 8-bit values, but sometimes 
>it combines two, three or four of them to represent a single code-point. 

'a' to be utf8 encoded needs 1 byte to be stored ? (since ordinal = 65) 
'α΄' to be utf8 encoded needs 2 bytes to be stored ? (since ordinal is > 127 ) 
'a chinese ideogramm' to be utf8 encoded needs 4 byte to be stored ? (since 
ordinal >  65000 ) 

The amount of bytes needed to store a character solely depends on the 
character's ordinal value in the Unicode table?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-09 Thread Νικόλαος Κούρας
I k nwo i have been a pain in the ass these days but this is the lats 
explanation i want from you, just to understand it completely.

>> Since 1 byte can hold up to 256 chars, why not utf-8 use 1-byte for 
>> values up to 256? 

>Because then how do you tell when you need one byte, and when you need 
>two? If you read two bytes, and see 0x4C 0xFA, does that mean two 
>characters, with ordinal values 0x4C and 0xFA, or one character with 
>ordinal value 0x4CFA? 

I mean utf-8 could use 1 byte for storing the 1st 256 characters. I meant up to 
256, not above 256.


>> UTF-8 and UTF-16 and UTF-32 
>> I though the number beside of UTF- was to declare how many bits the 
>> character set was using to store a character into the hdd, no? 

>Not exactly, but close. UTF-32 is completely 32-bit (4 byte) values. 
>UTF-16 mostly uses 16-bit values, but sometimes it combines two 16-bit 
>values to make a surrogate pair.

A surrogate pair is like itting for example Ctrl-A, which means is a 
combination character that consists of 2 different characters?
Is this what a surrogate is? a pari of 2 chars?


>UTF-8 uses 8-bit values, but sometimes 
>it combines two, three or four of them to represent a single code-point.

'a' to be utf8 encoded needs 1 byte to be stored ? (since ordinal = 65)
'α΄' to be utf8 encoded needs 2 bytes to be stored ? (since ordinal is > 127 )
'a chinese ideogramm' to be utf8 encoded needs 4 byte to be stored ? (since 
ordinal >  65000 )

The amount of bytes needed to store a character solely depends on the 
character's ordinal value in the Unicode table?


>UTF-8 solves this problem by reserving some values to mean "this byte, on 
>its own", and others to mean "this byte, plus the next byte, together", 
>and so forth, up to four bytes.

Some of the utf-8 bits that are used to represent a character's ordinal value 
are actually been also used to seperate or join the ordinal values themselves?
Can you give an example please? How there are beign seperated?


>Computers are digital and work with numbers.


So character 'A' <-> 65 (in decimal uses in charset's table)  <-> 01011100 (as 
binary stored in disk) <-> 0xEF (as hex, when we open the file with a hex 
editor)

Is this how the thing works? (above values are fictional)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-09 Thread Νικόλαος Κούρας
Τη Κυριακή, 9 Ιουνίου 2013 12:14:12 μ.μ. UTC+3, ο χρήστης Νικόλαος Κούρας 
έγραψε:
> Τη Κυριακή, 9 Ιουνίου 2013 11:15:07 π.μ. UTC+3, ο χρήστης Steven D'Aprano 
> έγραψε:
> 
> 
> 
> > Please try this: log into the Linux server, and then start up a Python 
> 
> 
> 
> > import os, sys 
> 
> > print(sys.version)
> 
> > s = ('\N{GREEK SMALL LETTER ALPHA}\N{GREEK SMALL LETTER BETA}' 
> 
> >  '\N{GREEK SMALL LETTER GAMMA}\N{GREEK SMALL LETTER DELTA}' 
> 
> >  '\N{GREEK SMALL LETTER EPSILON}')
> 
> > print(s)
> 
> > filename = '/tmp/' + s
> 
> > open(filename, 'w')
> 
> > os.path.exists(filename)
> 
> 
> 
> > Copy and paste the results back here please.
> 
> 
> 
> Of course: here it is:
> 
> 
> 
> root@nikos [/home/nikos/www/cgi-bin]# python
> 
> Python 3.3.2 (default, Jun  3 2013, 16:18:05)
> 
> [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux
> 
> Type "help", "copyright", "credits" or "license" for more information.
> 
> >>> import os, sys
> 
> >>> print(sys.version)
> 
> 3.3.2 (default, Jun  3 2013, 16:18:05)
> 
> [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)]
> 
> >>> s = ('\N{GREEK SMALL LETTER ALPHA}\N{GREEK SMALL LETTER BETA}'
> 
> ...  '\N{GREEK SMALL LETTER GAMMA}\N{GREEK SMALL LETTER DELTA}'
> 
> ...  '\N{GREEK SMALL LETTER EPSILON}')
> 
> print(s)
> 
> >>> αβγδε
> 
> >>> filename = '/tmp/' + s
> 
> >>> open(filename, 'w')
> 
> <_io.TextIOWrapper name='/tmp/αβγδε' mode='w' encoding='UTF-8'>
> 
> >>> os.path.exists(filename)
> 
> True
> 
> >>>

I dont much but it lloks correct to me, but then agian why this error?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-09 Thread Νικόλαος Κούρας
Τη Κυριακή, 9 Ιουνίου 2013 12:20:58 μ.μ. UTC+3, ο χρήστης Lele Gaifax έγραψε:

> > How about a string i wonder? 
> > s = "νίκος" 
> > what_are these_bytes = s.encode('iso-8869-7').encode(utf-8')

> Ignoring the usual syntax error, this is just a variant of the code I 
> posted: "s.encode('iso-8869-7')" produces a bytes instance which
> *cannot* be "re-encoded" again in whatever encoding.

s = 'a'
s = s.encode('iso-8859-7').decode('utf-8')
print( s )

a (we got the original character back)

s = 'α'
s = s.encode('iso-8859-7').decode('utf-8')
print( s )

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe1 in position 0: 
unexpected end of data

Why this error? because 'a' ordinal value > 127 ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-09 Thread Νικόλαος Κούρας
Τη Κυριακή, 9 Ιουνίου 2013 12:12:36 μ.μ. UTC+3, ο χρήστης Cameron Simpson 
έγραψε:
> On 09Jun2013 02:00, =?utf-8?B?zp3Or866zr/PgiDOk866z4EzM866?= 
>  wrote:
> 
> | Steven wrote:
> 
> | >> Since 1 byte can hold up to 256 chars, why not utf-8 use 1-byte for 
> 
> | >> values up to 256? 
> 
> | 
> 
> | >Because then how do you tell when you need one byte, and when you need 
> 
> | >two? If you read two bytes, and see 0x4C 0xFA, does that mean two 
> 
> | >characters, with ordinal values 0x4C and 0xFA, or one character with 
> 
> | >ordinal value 0x4CFA? 
> 
> | 
> 
> | I mean utf-8 could use 1 byte for storing the 1st 256 characters. I meant 
> up to 256, not above 256.
> 
> 
> 
> Then it would not be UTF-8. UTF-8 will encode an Unicode codepoint. Your 
> >suggestion will not.

I dont follow.

> | >> UTF-8 and UTF-16 and UTF-32 
> 
> | >> I though the number beside of UTF- was to declare how many bits the 
> 
> | >> character set was using to store a character into the hdd, no? 
> 
> | 
> 
> | >Not exactly, but close. UTF-32 is completely 32-bit (4 byte) values. 
> 
> | >UTF-16 mostly uses 16-bit values, but sometimes it combines two 16-bit 
> 
> | >values to make a surrogate pair.
> 
> | 
> 
> | A surrogate pair is like itting for example Ctrl-A, which means is a 
> combination character that consists of 2 different characters?
> 
> | Is this what a surrogate is? a pari of 2 chars?
> 
> 
> 
> Essentially. The combination represents a code point.
> 
> 
> 
> | >UTF-8 uses 8-bit values, but sometimes 
> 
> | >it combines two, three or four of them to represent a single code-point.
> 
> | 
> 
> | 'a' to be utf8 encoded needs 1 byte to be stored ? (since ordinal = 65)
> 
> | 'α΄' to be utf8 encoded needs 2 bytes to be stored ? (since ordinal is > 
> 127 )
> 
> | 'a chinese ideogramm' to be utf8 encoded needs 4 byte to be stored ? (since 
> ordinal >  65000 )
> 
> | 
> 
> | The amount of bytes needed to store a character solely depends on the 
> character's ordinal value in the Unicode table?
> 
> 
> 
> Essentially. You can read up on the exact process in Wikipedia or the Unicode 
> Standard.



When you say essentially means you agree with my statements?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-09 Thread Νικόλαος Κούρας
Τη Κυριακή, 9 Ιουνίου 2013 11:15:07 π.μ. UTC+3, ο χρήστης Steven D'Aprano 
έγραψε:

> Please try this: log into the Linux server, and then start up a Python 

> import os, sys 
> print(sys.version)
> s = ('\N{GREEK SMALL LETTER ALPHA}\N{GREEK SMALL LETTER BETA}' 
>  '\N{GREEK SMALL LETTER GAMMA}\N{GREEK SMALL LETTER DELTA}' 
>  '\N{GREEK SMALL LETTER EPSILON}')
> print(s)
> filename = '/tmp/' + s
> open(filename, 'w')
> os.path.exists(filename)

> Copy and paste the results back here please.

Of course: here it is:

root@nikos [/home/nikos/www/cgi-bin]# python
Python 3.3.2 (default, Jun  3 2013, 16:18:05)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, sys
>>> print(sys.version)
3.3.2 (default, Jun  3 2013, 16:18:05)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)]
>>> s = ('\N{GREEK SMALL LETTER ALPHA}\N{GREEK SMALL LETTER BETA}'
...  '\N{GREEK SMALL LETTER GAMMA}\N{GREEK SMALL LETTER DELTA}'
...  '\N{GREEK SMALL LETTER EPSILON}')
print(s)
>>> αβγδε
>>> filename = '/tmp/' + s
>>> open(filename, 'w')
<_io.TextIOWrapper name='/tmp/αβγδε' mode='w' encoding='UTF-8'>
>>> os.path.exists(filename)
True
>>>

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-09 Thread Νικόλαος Κούρας
Τη Κυριακή, 9 Ιουνίου 2013 11:55:43 π.μ. UTC+3, ο χρήστης Lele Gaifax έγραψε:
> Steven D'Aprano  writes:
> 
> 
> 
> > On Sat, 08 Jun 2013 22:09:57 -0700, nagia.retsina wrote:
> 
> >
> 
> >> chr('A') would give me the mapping of this char, the number 65 while
> 
> >> ord(65) would output the char 'A' likewise.
> 
> >
> 
> > Correct. Python uses Unicode, where code-point 65 ("ordinal value 65") 
> 
> > means letter "A".
> 
> 
> 
> Actually, that's the other way around:
> 
> 
> 
> >>> chr(65)
> 
> 'A'
> 
> >>> ord('A')
> 
> 65
> 
> 
> 
> >> What would happen if we we try to re-encode bytes on the disk? like
> 
> >> trying:
> 
> >> 
> 
> >> s = "νίκος"
> 
> >> utf8_bytes = s.encode('utf-8')
> 
> >> greek_bytes = utf_bytes.encode('iso-8869-7')
> 
> >> 
> 
> >> Can we re-encode twice or as many times we want and then decode back
> 
> >> respectively lke?
> 
> >
> 
> > Of course. Bytes have no memory of where they came from, or what they are 
> 
> > used for. All you are doing is flipping bits on a memory chip, or on a 
> 
> > hard drive. So long as *you* remember which encoding is the right one, 
> 
> > there is no problem. If you forget, and start using the wrong one, you 
> 
> > will get garbage characters, mojibake, or errors.
> 
> 
> 
> Uhm, no: "encode" transforms a Unicode string into an array of bytes,
> 
> "decode" does the opposite transformation. You cannot do the former on
> 
> an "arbitrary" array of bytes:
> 
> 
> 
> >>> s = "νίκος"
> 
> >>> utf8_bytes = s.encode('utf-8')
> 
> >>> greek_bytes = utf8_bytes.encode('iso-8869-7')
> 
> Traceback (most recent call last):
> 
>   File "", line 1, in 
> 
> AttributeError: 'bytes' object has no attribute 'encode'

So something encoded into bytes cannot be re-encoded to some other bytes.

How about a string i wonder?
s = "νίκος"
what_are these_bytes = s.encode('iso-8869-7').encode(utf-8')
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-09 Thread Νικόλαος Κούρας
Τη Κυριακή, 9 Ιουνίου 2013 11:02:48 π.μ. UTC+3, ο χρήστης Cameron Simpson 
έγραψε:

> In this scenario, really it is the Terminal program (eg Putty) which
> cares about text (what you type, and what gets displayed). It is
> because of mismatches between your Terminal local settings and the
> encoding that was chosen for the filenames that you get garbage
> listings, one way or another.

Ca n you give an example please that shows a string being greek-iso encoded and 
then being utf8 decoded and presented back as:

1. properly
2. garbage ( means trash but dont what a garbage char is)
3. error
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-09 Thread Νικόλαος Κούρας
Steven wrote:
>> Since 1 byte can hold up to 256 chars, why not utf-8 use 1-byte for 
>> values up to 256? 

>Because then how do you tell when you need one byte, and when you need 
>two? If you read two bytes, and see 0x4C 0xFA, does that mean two 
>characters, with ordinal values 0x4C and 0xFA, or one character with 
>ordinal value 0x4CFA? 

I mean utf-8 could use 1 byte for storing the 1st 256 characters. I meant up to 
256, not above 256.


>> UTF-8 and UTF-16 and UTF-32 
>> I though the number beside of UTF- was to declare how many bits the 
>> character set was using to store a character into the hdd, no? 

>Not exactly, but close. UTF-32 is completely 32-bit (4 byte) values. 
>UTF-16 mostly uses 16-bit values, but sometimes it combines two 16-bit 
>values to make a surrogate pair.

A surrogate pair is like itting for example Ctrl-A, which means is a 
combination character that consists of 2 different characters?
Is this what a surrogate is? a pari of 2 chars?


>UTF-8 uses 8-bit values, but sometimes 
>it combines two, three or four of them to represent a single code-point.

'a' to be utf8 encoded needs 1 byte to be stored ? (since ordinal = 65)
'α΄' to be utf8 encoded needs 2 bytes to be stored ? (since ordinal is > 127 )
'a chinese ideogramm' to be utf8 encoded needs 4 byte to be stored ? (since 
ordinal >  65000 )

The amount of bytes needed to store a character solely depends on the 
character's ordinal value in the Unicode table?


>UTF-8 solves this problem by reserving some values to mean "this byte, on 
>its own", and others to mean "this byte, plus the next byte, together", 
>and so forth, up to four bytes.

Some of the utf-8 bits that are used to represent a character's ordinal value 
are actually been also used to seperate or join the ordinal values themselves?
Can you give an example please? How there are beign seperated?


>Computers are digital and work with numbers.


So character 'A' <-> 65 (in decimal uses in charset's table)  <-> 01011100 (as 
binary stored in disk) <-> 0xEF (as hex, when we open the file with a hex 
editor)

Is this how the thing works? (above values are fictional)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-09 Thread Νικόλαος Κούρας
I'm sorry posted by mistake unnessary code: here is the correct one that 
prodiuced the above error:


#
# Collect directory and its filenames as bytes
path = b'/home/nikos/public_html/data/apps/'
files = os.listdir( path )

for filename in files:
# Compute 'path/to/filename'
filepath_bytes = path + filename
for encoding in ('utf-8', 'iso-8859-7', 'latin-1'):
try: 
filepath = filepath_bytes.decode( encoding )
except UnicodeDecodeError:
continue

# Rename to something valid in UTF-8 
if encoding != 'utf-8': 
os.rename( filepath_bytes, filepath.encode('utf-8') )

assert os.path.exists( filepath )
break 
else: 
# This only runs if we never reached the break
raise ValueError( 'unable to clean filename %r' % 
filepath_bytes ) 


#
# Collect filenames of the path dir as strings
filenames = os.listdir( '/home/nikos/public_html/data/apps/' )

# Load'em
for filename in filenames:
try:
# Check the presence of a file against the database and insert 
if it doesn't exist
cur.execute('''SELECT url FROM files WHERE url = %s''', 
(filename,) )
data = cur.fetchone()

if not data:
# First time for file; primary key is automatic, hit is 
defaulted
print( "iam here", filename + '\n' )
cur.execute('''INSERT INTO files (url, host, lastvisit) 
VALUES (%s, %s, %s)''', (filename, host, lastvisit) )
except pymysql.ProgrammingError as e:
print( repr(e) )


#
# Collect filenames of the path dir as strings
filenames = os.listdir( '/home/nikos/public_html/data/apps/' )
filepaths = set()

# Build a set of 'path/to/filename' based on the objects of path dir
for filename in filenames:
filepaths.add( filename )

# Delete spurious 
cur.execute('''SELECT url FROM files''')
data = cur.fetchall()

# Check database's filenames against path's filenames
for rec in data:
if rec not in filepaths:
cur.execute('''DELETE FROM files WHERE url = %s''', rec )
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-08 Thread Νικόλαος Κούρας

On 9/6/2013 1:32 πμ, Cameron Simpson wrote:

On 08Jun2013 14:14, =?utf-8?B?zp3Or866zr/PgiDOk866z4EzM866?= 
 wrote:
| Τη Σάββατο, 8 Ιουνίου 2013 10:01:57 μ.μ. UTC+3, ο χρήστης Steven D'Aprano 
έγραψε:
| > ASCII actually needs 7 bits to store a character. Since computers are
| > optimized to work with bytes, not bits, normally ASCII characters are
| > stored in a single byte, with one bit wasted.
|
| So ASCII and Unicode are 2 Encoding Systems currently in use.
| How should i imagine them, visualize them?
| Like tables 'A' = 65, 'B' = 66 and so on?

Yes, that works.

| But if i do then that would be the visualization of a 'charset' not of an 
encoding system.
| What the diffrence of an encoding system and of a charset?

And encoding system is the method or transcribing these values to bytes and 
back again.

So we have:

( 'A' mapped to the value of '65' ) => encoding process(i.e. uf-8) => bytes
bytes => decoding process(i.e. utf-8) =>  ( '65' mapped to character 'A' )

Why does every character in a character set needs to be associated with 
a numeric value?
I mean couldn't we just have characters sets that wouldn't have numeric 
associations like:


'A'  => encoding process(i.e. uf-8) => bytes
bytes => decoding process(i.e. utf-8) =>  character 'A'




EBCDIC and ASCII and Unicode and Greek-ISO (iso-8859-7) are all character sets.
(1:1 mappings of characters to numbers/ordinals).

And encoding is a way of writing these values to bytes.
Decoding reads bytes and emits character values.

Because all of EBCDIC, ASCII and the iso-8859-x characters sets fit in the 
range 0-255,
they are usually transcribed (encoded) directly, one byte per ordinal.

Unicode is much larger. It cannot be transcribed (encoded) as one bytes to one 
value.
There are several ways of transcribing Unicode. UTF-8 is a popular and usually 
compact form,
using one byte for values below 128 and and multiple bytes for higher values.

An ordinal = ordered numbers like 7,8,910 and so on?

Since 1 byte can hold up to 256 chars, why not utf-8 use 1-byte for 
values up to 256?


UTF-8 and UTF-16 and UTF-32
I though the number beside of UTF- was to declare how many bits the 
character set was using to store a character into the hdd, no?


"Narrow" Unicode uses two bytes per character. Since two bytes is only
enough for about 65,000 characters, not 1,000,000+, the rest of the
characters are stored as pairs of two-byte "surrogates".

Can you please explain this line "the rest of thecharacters are stored 
as pairs of two-byte "surrogates"" more easily for me to understand it?

I'm still having troubl understanding what a surrogate is.

Again, thank you very much for explaining the encodings to me, they were 
giving me trouble for years in all of my scripts.



And one last thing.
When locale to linux system is set to utf-8 that would mean that the 
linux applications, should try to encode string into hdd by using 
system's default encoding to utf-8 nad read them back from bytes by also 
using utf-8. Is that correct?

--
Webhost && Weblog 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Errin when executing a cgi script that sets a cookie in the browser

2013-06-08 Thread Νικόλαος Κούρας
Τη Κυριακή, 9 Ιουνίου 2013 12:17:16 π.μ. UTC+3, ο χρήστης Michael Torrie έγραψε:

> > What does this error means anyway?

> It means that Apache is unable to find your cgi script.  It's turning 
> the url into a file path, but it can't find the file path.  Sometimes 
> Apache is configured to not follow symlinks.

Why every other python cgi script of mine that i run via browser  doesnt 
produce this kind of error and only 'koukos.py' does?

> It's confusing too because you have two apaches installed.  The system 
> default one and the one that comes with cPanel.

Hi Michael, indeed they are too.
I wonder why cPanel deosnt use the default apache that came with the system and 
isntead complied its own.

anyway httpd.conf seems correct
==
root@nikos [~]# cat /usr/local/apache/conf/httpd.conf | grep 'www'
#   system refer to the documentation at: 
http://www.cpanel.net/support/docs/ea/ea3/customdirectives.html   #
#   system refer to the documentation at: 
http://www.cpanel.net/support/docs/ea/ea3/customdirectives.html   #
ServerAlias www.varsa.gr
ServerAlias www.parking-byzantio.gr
ServerAlias www.cafebar-idea.gr
ServerAlias www.dauwin.gr
ServerAlias www.leonidasgkelos.com
ServerAlias www.mythosweb.gr
ServerAlias www.superhost.gr
ServerAlias www.panostech.gr
ServerAlias www.pdimou.gr
ServerAlias www.radio-klepsydra.com
ServerAlias www.cravendot.gr
ServerAlias www.ypsilandio.gr
ServerAlias www.oliveoils.mythosweb.gr
ServerAlias www.zimotirio.pdimou.gr

root@nikos [~]# cat /usr/local/apache/conf/httpd.conf | grep 'public_html'
UserDir public_html
DocumentRoot /home/akis/public_html
ScriptAlias /cgi-bin/ /home/akis/public_html/cgi-bin/
DocumentRoot /home/byzantio/public_html
ScriptAlias /cgi-bin/ /home/byzantio/public_html/cgi-bin/
DocumentRoot /home/cafebar/public_html
ScriptAlias /cgi-bin/ /home/cafebar/public_html/cgi-bin/
DocumentRoot /home/dauwin/public_html
ScriptAlias /cgi-bin/ /home/dauwin/public_html/cgi-bin/
DocumentRoot /home/gkelos/public_html
ScriptAlias /cgi-bin/ /home/gkelos/public_html/cgi-bin/
DocumentRoot /home/mythos/public_html
ScriptAlias /cgi-bin/ /home/mythos/public_html/cgi-bin/
DocumentRoot /home/nikos/public_html
ScriptAlias /cgi-bin/ /home/nikos/public_html/cgi-bin/
DocumentRoot /home/panos/public_html
ScriptAlias /cgi-bin/ /home/panos/public_html/cgi-bin/
DocumentRoot /home/pdimou/public_html
ScriptAlias /cgi-bin/ /home/pdimou/public_html/cgi-bin/
DocumentRoot /home/radio/public_html
ScriptAlias /cgi-bin/ /home/radio/public_html/cgi-bin/
DocumentRoot /home/tasos/public_html
ScriptAlias /cgi-bin/ /home/tasos/public_html/cgi-bin/
DocumentRoot /home/ypsiland/public_html
ScriptAlias /cgi-bin/ /home/ypsiland/public_html/cgi-bin/
DocumentRoot /home/mythos/public_html/oliveoils
ScriptAlias /cgi-bin/ /home/mythos/public_html/oliveoils/cgi-bin/
DocumentRoot /home/pdimou/public_html/zimotirio
ScriptAlias /cgi-bin/ /home/pdimou/public_html/zimotirio/cgi-bin/
root@nikos [~]#
===

Why every other python cgi script of mines doesnt prodice this error
and only 'koukos.py' does?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-08 Thread Νικόλαος Κούρας
Sorry for displaying my code so many times, i know i ahve exhaust you but hti 
is the last thinkg i am gonna ask from you in this thread. We are very close to 
have this working.


#
# Collect directory and its filenames as bytes
path = b'/home/nikos/public_html/data/apps/'
files = os.listdir( path )

for filename in files:
# Compute 'path/to/filename'
filepath_bytes = path + filename
for encoding in ('utf-8', 'iso-8859-7', 'latin-1'):
try: 
filepath = filepath_bytes.decode( encoding )
except UnicodeDecodeError:
continue

# Rename to something valid in UTF-8 
if encoding != 'utf-8': 
os.rename( filepath_bytes, filepath.encode('utf-8') )

assert os.path.exists( filepath )
break 
else: 
# This only runs if we never reached the break
raise ValueError( 'unable to clean filename %r' % 
filepath_bytes ) 


#
# Collect filenames of the path dir as strings
filenames = os.listdir( '/home/nikos/public_html/data/apps/' )

# Load'em
for filename in filenames:
try:
# Check the presence of a file against the database and insert 
if it doesn't exist
cur.execute('''SELECT url FROM files WHERE url = %s''', 
(filename,) )
data = cur.fetchone()

if not data:
# First time for file; primary key is automatic, hit is 
defaulted
print( "iam here", filename + '\n' )
cur.execute('''INSERT INTO files (url, host, lastvisit) 
VALUES (%s, %s, %s)''', (filename, host, lastvisit) )
except pymysql.ProgrammingError as e:
print( repr(e) )


#
# Collect filenames of the path dir as strings
filenames = os.listdir( '/home/nikos/public_html/data/apps/' )
filepaths = ()

# Build a set of 'path/to/filename' based on the objects of path dir
for filename in filenames:
filepaths.add( filename )

# Delete spurious 
cur.execute('''SELECT url FROM files''')
data = cur.fetchall()

# Check database's filenames against path's filenames
for rec in data:
if rec not in filepaths:
cur.execute('''DELETE FROM files WHERE url = %s''', rec )





=
[Sun Jun 09 00:16:14 2013] [error] [client 79.103.41.173] Original exception 
was:
[Sun Jun 09 00:16:14 2013] [error] [client 79.103.41.173] Traceback (most 
recent call last):
[Sun Jun 09 00:16:14 2013] [error] [client 79.103.41.173]   File 
"/home/nikos/public_html/cgi-bin/files.py", line 78, in 
[Sun Jun 09 00:16:14 2013] [error] [client 79.103.41.173] assert 
os.path.exists( filepath )
[Sun Jun 09 00:16:14 2013] [error] [client 79.103.41.173]   File 
"/usr/local/lib/python3.3/genericpath.py", line 18, in exists
[Sun Jun 09 00:16:14 2013] [error] [client 79.103.41.173] os.stat(path)
[Sun Jun 09 00:16:14 2013] [error] [client 79.103.41.173] UnicodeEncodeError: 
'ascii' codec can't encode characters in position 34-37: ordinal not in 
range(128)
==

Asserts what to make sure the the path/to/file afetr the rename exists but why 
are we still get those unicodeencodeerrors?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-08 Thread Νικόλαος Κούρας
Τη Σάββατο, 8 Ιουνίου 2013 10:01:57 μ.μ. UTC+3, ο χρήστης Steven D'Aprano 
έγραψε:

> ASCII actually needs 7 bits to store a character. Since computers are  
> optimized to work with bytes, not bits, normally ASCII characters are
> stored in a single byte, with one bit wasted.

So ASCII and Unicode are 2 Encoding Systems currently in use.
How should i imagine them, visualize them?
Like tables 'A' = 65, 'B' = 66 and so on?

But if i do then that would be the visualization of a 'charset' not of an 
encoding system.
What the diffrence of an encoding system and of a charset?

ebcdic - ascii - unicode = al of them are encoding systems

greek-iso - latin-iso - utf8 - utf16 = all of them are charsets.

What are these differences? i cant imagine them all, i can only imagine 
charsets not encodign systems.

Why python interprets by default all given strings as unicode and not ascii? 
because the former supports many positions while ascii only 127 positions , 
hence can interpet only 127 different characters? 


> "Narrow" Unicode uses two bytes per character. Since two bytes is only 
> enough for about 65,000 characters, not 1,000,000+, the rest of the 
> characters are stored as pairs of two-byte "surrogates".

surrogates literal means a replacemnt?


> Latin-1 is similar, except there are 256 positions. Greek ISO-8859-7 is 
> also similar, also 256 positions, but the characters are different. And 
> so on, with dozens of charsets. 

Latin has to display english chars(capital, small) + numbers + symbols. that 
would be 127 why 256?

greek = all of the above plus greek chars, no?

> And then there is Unicode, which includes *every* character is all of 
> those dozens of charsets. It has 1114111 positions (most are currently  
> unfilled).

Shouldt the positions that Unicode has to use equal to the summary of all 
available characters of all the languages of the worlds plus numbers and 
special chars? why 1.000.000+ why the need for so many positions? Narrow 
Unicode format (2 byted) can cover all ofmthe worlds symbols.

> An encoding is simply a program that takes a character and returns a 
> byte, or visa versa. For instance, the ASCII encoding will take character 
> 'A'. That is found at position 65, which is 0x41 in hexadecimal, so the 
> ASCII encoding turns character 'A' into byte 0x41, and visa versa.

Why you say ASCII turn a character into HEX format and not as in binary format?
Isnt the latter the way bytes are stored into hdd, like 01010010101 etc?
Are they stored as hex instead or you just said so to avoid printing 0s and 1s?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-08 Thread Νικόλαος Κούρας

On 8/6/2013 5:49 πμ, Cameron Simpson wrote:

On 07Jun2013 04:53, =?utf-8?B?zp3Or866zr/PgiDOk866z4EzM866?= 
 wrote:
| Τη Παρασκευή, 7 Ιουνίου 2013 11:53:04 π.μ. UTC+3, ο χρήστης Cameron Simpson 
έγραψε:
| > | >| errors='replace' mean dont break in case or error?
| >
| > | >Yes. The result will be correct for correct iso-8859-7 and slightly 
mangled
| > | >for something that would not decode smoothly.
| >
| > | How can it be correct? We have encoded out string in utf-8 and then
| > | we tried to decode it as greek-iso? How can this possibly be
| > | correct?
|
| > If it is a valid iso-8859-7 sequence (which might cover everything,
| > since I expect it is an 8-bit 1:1 mapping from bytes values to a
| > set of codepoints, just like iso-8859-1) then it may decode to the
| > "wrong" characters, but the reverse process (characters encoded as
| > bytes) should produce the original bytes.  With a mapping like this,
| > errors='replace' may mean nothing; there will be no errors because
| > the only Unicode characters in play are all from iso-8859-7 to start
| > with. Of course another string may not be safe.
|
| > Visually, the names will be garbage. And if you go:
| >   mv '999-EΟΟΞ�-ΟΞΏΟ-ΞΞ·ΟΞΏΟ.mp3' '999-Eυχή-του-Ιησού.mp3'
| > while using the iso-8859-7 locale, the wrong thing will occur
| > (assuming it even works, though I think it should because all these
| > characters are represented in iso-8859-7, yes?)
|
| All the rest you i understood only the above quotes its still unclear to me.
| I cant see to understand it.
|
| Do you mean that utf-8, latin-iso, greek-iso and ASCII have the 1st 0-127 
codepoints similar?

Yes. It is certainly true for utf-8 and latin-iso and ASCII.
I expect it to be so for greek-iso, but have not checked.

They're all essentially the ASCII set plus a range of other character
codepoints for the upper values.  The 8-bit sets iso-8859-1 (which
I take you to mean by "latin-iso") and iso-8859-7 (which I take you
to mean by "greek-iso") are single byte mapping with the top half
mapped to characters commonly used in a particular region.

Unicode has a much greater range, but the UTF-8 encoding of Unicode
deliberately has the bottom 0-127 identical to ASCII, and higher
values represented by multibyte sequences commences with at least
the first byte in the 128-255 range. In this way pure ASCII files
are already in UTF-8 (and, in fact, work just fine for the iso-8859-x
encodings as well).


Hold on!

In the beginning there was ASCII with 0-127 values and then there was 
Unicode with 0-127 of ASCII's + i dont know how much many more?


Now ASCIII needs 1 byte to store a single character while Unicode needs 
2 bytes to store a character and that is because it has > 256 characters 
to store > 2^8bits ?


Is this correct?

Now UTF-8, latin-iso, greek-iso e.t.c are WAYS of storing characters 
into the hard drive?


Because in some post i have read that 'UTF-8 encoding of Unicode'.
Can you please explain to me whats the difference of ASCII-Unicode 
themselves aand then of them compared to 'Charsets' . I'm still confused 
about this.


Is it like we said in C++:
' int a', a variable with name 'a' of type integer.
'char a',   a variable with name 'a' of type char

So taken form above example(the closest i could think of), the way i 
understand them is:


A 'string' can be of (unicode's or ascii's) type and that type needs a 
way (thats a charset) to store this string into the hdd as a sequense of 
bytes?







--
Webhost && Weblog 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-08 Thread Νικόλαος Κούρας
Okey after reading also Steven post, i was relived form the previous suck 
position i was, so with an alternation of a few variable names here is the code 
now:


#
# Collect directory and its filenames as bytes
path = b'/home/nikos/public_html/data/apps/'
files = os.listdir( path )

for filename in files:
# Compute 'path/to/filename'
filepath_bytes = path + filename
for encoding in ('utf-8', 'iso-8859-7', 'latin-1'):
try: 
filepath = filepath_bytes.decode( encoding )
except UnicodeDecodeError:
continue

# Rename to something valid in UTF-8 
if encoding != 'utf-8': 
os.rename( filepath_bytes, filepath.encode('utf-8') )

assert os.path.exists( filepath )
break 
else: 
# This only runs if we never reached the break
raise ValueError( 'unable to clean filename %r' % 
filepath_bytes ) 

=

I dont know why it is still failing when it tried to decode stuff since it 
tries 3 ways of decoding. Here is the exact error.


ni...@superhost.gr [~/www/cgi-bin]# [Sat Jun 08 20:32:44 2013] [error] [client 
79.103.41.173] Error in sys.excepthook:
[Sat Jun 08 20:32:44 2013] [error] [client 79.103.41.173] ValueError: 
underlying buffer has been detached
[Sat Jun 08 20:32:44 2013] [error] [client 79.103.41.173]
[Sat Jun 08 20:32:44 2013] [error] [client 79.103.41.173] Original exception 
was:
[Sat Jun 08 20:32:44 2013] [error] [client 79.103.41.173] Traceback (most 
recent call last):
[Sat Jun 08 20:32:44 2013] [error] [client 79.103.41.173]   File 
"/home/nikos/public_html/cgi-bin/files.py", line 78, in 
[Sat Jun 08 20:32:44 2013] [error] [client 79.103.41.173] assert 
os.path.exists( filepath )
[Sat Jun 08 20:32:44 2013] [error] [client 79.103.41.173]   File 
"/usr/local/lib/python3.3/genericpath.py", line 18, in exists
[Sat Jun 08 20:32:44 2013] [error] [client 79.103.41.173] os.stat(path)
[Sat Jun 08 20:32:44 2013] [error] [client 79.103.41.173] UnicodeEncodeError: 
'ascii' codec can't encode characters in position 34-37: ordinal not in 
range(128)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Errin when executing a cgi script that sets a cookie in the browser

2013-06-08 Thread Νικόλαος Κούρας
Τη Σάββατο, 8 Ιουνίου 2013 7:03:57 μ.μ. UTC+3, ο χρήστης Chris Angelico έγραψε:
> On Sun, Jun 9, 2013 at 1:36 AM, Νικόλαος Κούρας  wrote:

> > Well, www as symlink to public_html is always a symlink to any system i
> > have used so its something defaulted.

> It's most certainly not the default, it's definitely not universal 
> and that has nothing to do with what I said. Use the exact same path,
> it reduces confusion. Also, I think it's time to mention again: Get
> yourself off Google Groups, or start trimming out the stupid double
> spacing! It's getting extremely annoying.


its very tedious to always triming everything for me and i know it is for you 
to ead it assuc. Damn google groups, why is it behaving as such?
Dont the programmers know about it?

Also everytime i post it always display to me different addresses to get 
responses back.

Any way what did you say and i havent understand you correctly?
What path do you want me to show to you?

What does this error means anyway?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-08 Thread Νικόλαος Κούρας
Sorry for th delay guys, was busy with other thigns today and i am still 
reading your resposes, still ahvent rewad them all just Cameron's:

Here is what i have now following Cameron's advices:


#
# Collect filenames of the path directory as bytes
path = b'/home/nikos/public_html/data/apps/'
filenames_bytes = os.listdir( path )

for filename_bytes in filenames_bytes:
try:
filename = filename_bytes.decode('utf-8)
except UnicodeDecodeError:
# Since its not a utf8 bytestring then its for sure a greek 
bytestring

# Prepare arguments for rename to happen
utf8_filename = filename_bytes.encode('utf-8')
greek_filename = filename_bytes.encode('iso-8859-7')

utf8_path = path + utf8_filename
greek_path = path + greek_filename

# Rename current filename from greek bytes --> utf8 bytes
os.rename( greek_path, utf8_path )
==

I know this is wrong though.
Since filename_bytes is the current filename encoded as utf8 or greek-iso
then i cannot just *encode* what is already encoded by doing this:

utf8_filename = filename_bytes.encode('utf-8')
greek_filename = filename_bytes.encode('iso-8859-7')
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Errin when executing a cgi script that sets a cookie in the browser

2013-06-08 Thread Νικόλαος Κούρας
Τη Σάββατο, 8 Ιουνίου 2013 10:01:51 π.μ. UTC+3, ο χρήστης Chris Angelico έγραψε:
> On Sat, Jun 8, 2013 at 4:53 PM, Νικόλαος Κούρας  wrote:
> 
> > Τη Παρασκευή, 7 Ιουνίου 2013 11:47:58 μ.μ. UTC+3, ο χρήστης MRAB έγραψε:
> 
> >> On 07/06/2013 19:24, Νικόλαος Κούρας wrote:
> 
> \>> > Τη Παρασκευή, 7 Ιουνίου 2013 5:32:09 μ.μ. UTC+3, ο χρήστης MRAB έγραψε:
> 
> >> >> It's looking for '/home/nikos/public_html/cgi-bin/koukos.py'.
> 
> >> >> Have a look in '/home/nikos/public_html/cgi-bin'. Is 'koukos.py' in
> 
> >> >> there?
> 
> >> > Yes it is.
> 
> >> > ni...@superhost.gr [~/www/cgi-bin]# ls -l
> 
> >> > -rwxr-xr-x 1 nikos nikos   1160 Jun  6 06:27 koukos.py*
> 
> >> The prompt says "~/www/cgi-bin".
> 
> >> Is that the same as "/home/nikos/public_html/cgi-bin"?
> 
> > Good day MRAB, yes '~/www' its a symlink to '~/public_html'
> 
> 
> 
> More basics. When someone asks you to check something, check exactly
> 
> that. It really does not help to check something unrelated. If you'd
> 
> shown in your prompt ~/public_html/cgi-bin rather than your symlink of
> 
> www, there would have been less confusion; putting the full path in as
> 
> a parameter would eliminate all trouble. By using the symlink, you
> 
> demand that we understand or assume something about your system, and
> 
> that's unnecessary.

Well, www as symlink to public_html is always a symlink to any system i have 
used so its something defaulted.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Errin when executing a cgi script that sets a cookie in the browser

2013-06-07 Thread Νικόλαος Κούρας
Τη Παρασκευή, 7 Ιουνίου 2013 11:47:58 μ.μ. UTC+3, ο χρήστης MRAB έγραψε:
> On 07/06/2013 19:24, Νικόλαος Κούρας wrote:
> 
> > Τη Παρασκευή, 7 Ιουνίου 2013 5:32:09 μ.μ. UTC+3, ο χρήστης MRAB έγραψε:
> 
> >>>Can find what? koukos.py is there inside the cg-bin dir with 755 perms.
> 
> >
> 
> >> It's looking for '/home/nikos/public_html/cgi-bin/koukos.py'.
> 
> >
> 
> > Its looking for its self?!?!
> 
> >
> 
> >> Have a look in '/home/nikos/public_html/cgi-bin'. Is 'koukos.py' in
> 
> >> there?
> 
> > Yes it is.
> 
> >
> 
> >
> 
> > ni...@superhost.gr [~/www/cgi-bin]# ls -l
> 
> > total 56
> 
> > drwxr-xr-x 2 nikos nikos   4096 Jun  6 20:29 ./
> 
> > drwxr-x--- 4 nikos nobody  4096 Jun  5 11:32 ../
> 
> > -rwxr-xr-x 1 nikos nikos   1199 Apr 25 15:33 convert.py*
> 
> > -rwxr-xr-x 1 nikos nikos   5434 Jun  7 14:51 files.py*
> 
> > -rw-r--r-- 1 nikos nikos170 May 30 15:18 .htaccess
> 
> > -rwxr-xr-x 1 nikos nikos   1160 Jun  6 06:27 koukos.py*
> 
> > -rwxr-xr-x 1 nikos nikos   9356 Jun  6 09:13 metrites.py*
> 
> > -rwxr-xr-x 1 nikos nikos  13512 Jun  6 09:13 pelatologio.py*
> 
> > ni...@superhost.gr [~/www/cgi-bin]#
> 
> >
> 
> The prompt says "~/www/cgi-bin".
> 
> 
> 
> Is that the same as "/home/nikos/public_html/cgi-bin"?
> 
> 
> 
> Try:
> 
> 
> 
> ls -l /home/nikos/public_html/cgi-bin

Good day MRAB, yes '~/www' its a symlink to '~/public_html'

ni...@superhost.gr [~/www/data/apps]# ls -ld /home/nikos/www/
drwxr-x--- 4 nikos nobody 4096 Jun  5 11:32 /home/nikos/www//
ni...@superhost.gr [~/www/data/apps]# ls -ld /home/nikos/public_html/
drwxr-x--- 4 nikos nobody 4096 Jun  5 11:32 /home/nikos/public_html//
ni...@superhost.gr [~/www/data/apps]# ls -l /home/nikos/public_html/cgi-bin
total 56
drwxr-xr-x 2 nikos nikos   4096 Jun  6 20:29 ./
drwxr-x--- 4 nikos nobody  4096 Jun  5 11:32 ../
-rwxr-xr-x 1 nikos nikos   1199 Apr 25 15:33 convert.py*
-rwxr-xr-x 1 nikos nikos   5793 Jun  8 09:39 files.py*
-rw-r--r-- 1 nikos nikos170 May 30 15:18 .htaccess
-rwxr-xr-x 1 nikos nikos   1160 Jun  6 06:27 koukos.py*
-rwxr-xr-x 1 nikos nikos   9356 Jun  6 09:13 metrites.py*
-rwxr-xr-x 1 nikos nikos  13512 Jun  6 09:13 pelatologio.py*
ni...@superhost.gr [~/www/data/apps]# ls -l /home/nikos/www/cgi-bin/
total 56
drwxr-xr-x 2 nikos nikos   4096 Jun  6 20:29 ./
drwxr-x--- 4 nikos nobody  4096 Jun  5 11:32 ../
-rwxr-xr-x 1 nikos nikos   1199 Apr 25 15:33 convert.py*
-rwxr-xr-x 1 nikos nikos   5793 Jun  8 09:39 files.py*
-rw-r--r-- 1 nikos nikos170 May 30 15:18 .htaccess
-rwxr-xr-x 1 nikos nikos   1160 Jun  6 06:27 koukos.py*
-rwxr-xr-x 1 nikos nikos   9356 Jun  6 09:13 metrites.py*
-rwxr-xr-x 1 nikos nikos  13512 Jun  6 09:13 pelatologio.py*
ni...@superhost.gr [~/www/data/apps]#
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-07 Thread Νικόλαος Κούρας
Τη Σάββατο, 8 Ιουνίου 2013 5:52:22 π.μ. UTC+3, ο χρήστης Cameron Simpson έγραψε:
> On 07Jun2013 11:52, =?utf-8?B?zp3Or866zr/PgiDOk866z4EzM866?= 
>  wrote:
> 
> | ni...@superhost.gr [~/www/cgi-bin]# [Fri Jun 07 21:49:33 2013] [error] 
> [client 79.103.41.173]   File "/home/nikos/public_html/cgi-bin/files.py", 
> line 81
> 
> | [Fri Jun 07 21:49:33 2013] [error] [client 79.103.41.173] if( flag == 
> 'greek' )
> 
> | [Fri Jun 07 21:49:33 2013] [error] [client 79.103.41.173]   
>   ^
> 
> | [Fri Jun 07 21:49:33 2013] [error] [client 79.103.41.173] SyntaxError: 
> invalid syntax
> 
> | [Fri Jun 07 21:49:33 2013] [error] [client 79.103.41.173] Premature end of 
> script headers: files.py
> 
> | ---
> 
> | i dont know why that if statement errors.
> 
> 
> 
> Python statements that continue (if, while, try etc) end in a colon, so:

Oh iam very sorry.
Oh my God i cant beleive i missed a colon *again*:

I have corrected this:

#
# Collect filenames of the path dir as bytes
filename_bytes = os.listdir( b'/home/nikos/public_html/data/apps/' )

for filename in filename_bytes:
# Compute 'path/to/filename' into bytes
filepath_bytes = b'/home/nikos/public_html/data/apps/' + b'filename'
flag = False

try:
# Assume current file is utf8 encoded
filepath = filepath_bytes.decode('utf-8')
flag = 'utf8' 
except UnicodeDecodeError:
try:
# Since current filename is not utf8 encoded then it 
has to be greek-iso encoded
filepath = filepath_bytes.decode('iso-8859-7')
flag = 'greek'
except UnicodeDecodeError:
print( '''I give up! File name is unreadable!''' )

if flag == 'greek':
# Rename filename from greek bytes --> utf-8 bytes
os.rename( filepath_bytes, filepath.encode('utf-8') )
==

Now everythitng were supposed to work but instead iam getting this surrogate 
error once more. 
What is this surrogate thing?

Since i make use of error cathcing and handling like 'except 
UnicodeDecodeError:'

then it utf8's decode fails for some reason, it should leave that file alone 
and try the next file?
try:
# Assume current file is utf8 encoded
filepath = filepath_bytes.decode('utf-8')
flag = 'utf8' 
except UnicodeDecodeError:

This is what it supposed to do, correct?

==
[Sat Jun 08 09:39:34 2013] [error] [client 79.103.41.173]   File 
"/home/nikos/public_html/cgi-bin/files.py", line 94, in 
[Sat Jun 08 09:39:34 2013] [error] [client 79.103.41.173] 
cur.execute('''SELECT url FROM files WHERE url = %s''', (filename,) )
[Sat Jun 08 09:39:34 2013] [error] [client 79.103.41.173]   File 
"/usr/local/lib/python3.3/site-packages/PyMySQL3-0.5-py3.3.egg/pymysql/cursors.py",
 line 108, in execute
[Sat Jun 08 09:39:34 2013] [error] [client 79.103.41.173] query = 
query.encode(charset)
[Sat Jun 08 09:39:34 2013] [error] [client 79.103.41.173] UnicodeEncodeError: 
'utf-8' codec can't encode character '\\udcce' in position 35: surrogates not 
allowed
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-07 Thread Νικόλαος Κούρας
Τη Παρασκευή, 7 Ιουνίου 2013 5:29:25 μ.μ. UTC+3, ο χρήστης MRAB έγραψε:

> This is a worse way of doing it because the ISO-8859-7 encoding has 1
> byte per codepoint, meaning that it's more 'tolerant' (if that's the 
> word) of errors. A sequence of bytes that is actually UTF-8 can be
> decoded as ISO-8859-7, giving gibberish.

> UTF-8 is less tolerant, and it's the encoding that ideally you should 
> be using everywhere, so it's better to assume UTF-8 and, if it fails,  
> try ISO-8859-7 and then rename so that any names that were ISO-8859-7
> will be converted to UTF-8.

Indeed iw asnt aware of that, at that time, i was under the impression that if 
a string was encoded to bytes using soem charset can only be switched back with 
the use of that and only that charset. Since this is the case here is my 
fixning:


#
# Collect filenames of the path dir as bytes
filename_bytes = os.listdir( b'/home/nikos/public_html/data/apps/' )

for filename in filename_bytes:
# Compute 'path/to/filename' into bytes
filepath_bytes = b'/home/nikos/public_html/data/apps/' + b'filename'
flag = False

try:
# Assume current file is utf8 encoded
filepath = filepath_bytes.decode('utf-8')
flag = 'utf8' 
except UnicodeDecodeError:
try:
# Since current filename is not utf8 encoded then it 
has to be greek-iso encoded
filepath = filepath_bytes.decode('iso-8859-7')
flag = 'greek'
except UnicodeDecodeError:
print( '''I give up! File name is unreadable!''' )

if( flag = 'greek' )
# Rename filename from greek bytes --> utf-8 bytes
os.rename( filepath_bytes, filepath.encode('utf-8') )


#
filenames = os.listdir( '/home/nikos/public_html/data/apps/' )

# Load'em
for filename in filenames:
try:
# Check the presence of a file against the database and insert 
if it doesn't exist
cur.execute('''SELECT url FROM files WHERE url = %s''', 
filename )
data = cur.fetchone()

if not data:
# First time for file; primary key is automatic, hit is 
defaulted 
cur.execute('''INSERT INTO files (url, host, lastvisit) 
VALUES (%s, %s, %s)''', (filename, host, lastvisit) )
except pymysql.ProgrammingError as e:
print( repr(e) )


#
filenames = os.listdir( '/home/nikos/public_html/data/apps/' )
filepaths = ()

# Build a set of 'path/to/filename' based on the objects of path dir
for filename in filenames:
filepaths.add( filename )

# Delete spurious 
cur.execute('''SELECT url FROM files''')
data = cur.fetchall()

# Check database's filenames against path's filenames
for rec in data:
if rec not in filepaths:
cur.execute('''DELETE FROM files WHERE url = %s''', rec )

=
ni...@superhost.gr [~/www/cgi-bin]# [Fri Jun 07 21:49:33 2013] [error] [client 
79.103.41.173]   File "/home/nikos/public_html/cgi-bin/files.py", line 81
[Fri Jun 07 21:49:33 2013] [error] [client 79.103.41.173] if( flag == 
'greek' )
[Fri Jun 07 21:49:33 2013] [error] [client 79.103.41.173]   
  ^
[Fri Jun 07 21:49:33 2013] [error] [client 79.103.41.173] SyntaxError: invalid 
syntax
[Fri Jun 07 21:49:33 2013] [error] [client 79.103.41.173] Premature end of 
script headers: files.py
---
i dont know why that if statement errors.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Errin when executing a cgi script that sets a cookie in the browser

2013-06-07 Thread Νικόλαος Κούρας
Τη Παρασκευή, 7 Ιουνίου 2013 5:32:09 μ.μ. UTC+3, ο χρήστης MRAB έγραψε:
>>Can find what? koukos.py is there inside the cg-bin dir with 755 perms.

> It's looking for '/home/nikos/public_html/cgi-bin/koukos.py'.

Its looking for its self?!?!

> Have a look in '/home/nikos/public_html/cgi-bin'. Is 'koukos.py' in
> there?
Yes it is.


ni...@superhost.gr [~/www/cgi-bin]# ls -l
total 56
drwxr-xr-x 2 nikos nikos   4096 Jun  6 20:29 ./
drwxr-x--- 4 nikos nobody  4096 Jun  5 11:32 ../
-rwxr-xr-x 1 nikos nikos   1199 Apr 25 15:33 convert.py*
-rwxr-xr-x 1 nikos nikos   5434 Jun  7 14:51 files.py*
-rw-r--r-- 1 nikos nikos170 May 30 15:18 .htaccess
-rwxr-xr-x 1 nikos nikos   1160 Jun  6 06:27 koukos.py*
-rwxr-xr-x 1 nikos nikos   9356 Jun  6 09:13 metrites.py*
-rwxr-xr-x 1 nikos nikos  13512 Jun  6 09:13 pelatologio.py*
ni...@superhost.gr [~/www/cgi-bin]#


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-07 Thread Νικόλαος Κούρας
Τη Παρασκευή, 7 Ιουνίου 2013 11:53:04 π.μ. UTC+3, ο χρήστης Cameron Simpson 
έγραψε:
> On 07Jun2013 09:56, =?utf-8?B?zp3Or866zr/PgiDOk866z4EzM866?= 
>  wrote:
> 
> | On 7/6/2013 4:01 πμ, Cameron Simpson wrote:
> 
> | >On 06Jun2013 11:46, =?utf-8?B?zp3Or866zr/PgiDOk866z4EzM866?= 
>  wrote:
> 
> | >| Τη Πέμπτη, 6 Ιουνίου 2013 3:44:52 μ.μ. UTC+3, ο χρήστης Steven D'Aprano 
> έγραψε:
> 
> | >| > py> s = '999-Eυχή-του-Ιησού'
> 
> | >| > py> bytes_as_utf8 = s.encode('utf-8')
> 
> | >| > py> t = bytes_as_utf8.decode('iso-8859-7', errors='replace')
> 
> | >| > py> print(t)
> 
> | >| > 999-EΟΟΞ�-ΟΞΏΟ-ΞΞ·ΟΞΏΟ
> 
> | >|
> 
> | >| errors='replace' mean dont break in case or error?
> 
> | >
> 
> | >Yes. The result will be correct for correct iso-8859-7 and slightly mangled
> 
> | >for something that would not decode smoothly.
> 
> |
> 
> | How can it be correct? We have encoded out string in utf-8 and then
> 
> | we tried to decode it as greek-iso? How can this possibly be
> 
> | correct?

> If it is a valid iso-8859-7 sequence (which might cover everything, 
> since I expect it is an 8-bit 1:1 mapping from bytes values to a 
> set of codepoints, just like iso-8859-1) then it may decode to the 
> "wrong" characters, but the reverse process (characters encoded as
> bytes) should produce the original bytes.  With a mapping like this, 
> errors='replace' may mean nothing; there will be no errors because
> the only Unicode characters in play are all from iso-8859-7 to start
> with. Of course another string may not be safe. 

> Visually, the names will be garbage. And if you go:
>   mv '999-EΟΟΞ�-ΟΞΏΟ-ΞΞ·ΟΞΏΟ.mp3' '999-Eυχή-του-Ιησού.mp3'
> while using the iso-8859-7 locale, the wrong thing will occur
> (assuming it even works, though I think it should because all these
> characters are represented in iso-8859-7, yes?)

All the rest you i understood only the above quotes its still unclear to me.
I cant see to understand it.

Do you mean that utf-8, latin-iso, greek-iso and ASCII have the 1st 0-127 
codepoints similar?

For example char 'a' has the value of '65' for all of those character sets?
Is hat what you mean?

s = 'a'  (This is unicode right?  Why when we assign a string to a variable 
that string's type is always unicode and does not automatically become utf-8 
which includes all available world-wide characters? Unicode is something 
different that a character set? )

utf8_byte = s.encode('utf-8')

Now if we are to decode this back to utf8 we will receive the char 'a'.
I beleive same thing will happen with latin, greek, ascii isos. Correct?

utf8_a = utf8_byte.decode('iso-8859-7')
latin_a = utf8_byte.decode('iso-8859-1')
ascii_a = utf8_byte.decode('ascii')
utf8_a = utf8_byte.decode('iso-8859-7')

Is this correct? 
All of those decodes will work even if the encoded bytestring was of utf8 type?

The characters that will not decode correctly are those that their codepoints 
are greater that > 127 ?

for example if s = 'α' (greek character equivalent to english 'a')

Is this what you mean?


Now back to my almost ready files.py script please:


#
# Collect filenames of the path dir as bytes
greek_filenames = os.listdir( b'/home/nikos/public_html/data/apps/' )

for filename in greek_filenames:
# Compute 'path/to/filename' in bytes
greek_path = b'/home/nikos/public_html/data/apps/' + b'filename'
try:
filepath = greek_path.decode('iso-8859-7')

# Rename current filename from greek bytes --> utf-8 bytes
os.rename( greek_path, filepath.encode('utf-8') )
except UnicodeDecodeError:
# Since its not a greek bytestring then its a proper utf8 
bytestring
filepath = greek_path.decode('utf-8')


#
filenames = os.listdir( '/home/nikos/public_html/data/apps/' )

# Load'em
for filename in filenames:
try:
# Check the presence of a file against the database and insert 
if it doesn't exist
cur.execute('''SELECT url FROM files WHERE url = %s''', 
filename )
data = cur.fetchone()

if not data:
# First time for file; primary key is automatic, hit is 
defaulted 
cur.execute('''INSERT INTO files (url, host, lastvisit) 
VALUES (%s, %s, %s)''', (filename, host, lastvisit) )
except pymysql.ProgrammingError as e:
print( repr(e) )


#
filenames = os.listdir( '/home/nikos/public_html/data/apps/' )
filepaths = ()

# Build a set of 'path/to/filename' based on the objects of path dir
for filename in filenames:
filepaths.add( filename )

# Delete spurious 
cur.execute('''SELECT url FROM files''')
data = cur.fetchall()

# Check database's filenames against path's filen

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-07 Thread Νικόλαος Κούρας

On 7/6/2013 10:42 πμ, Michael Weylandt wrote:


os.rename( filepath_bytes filepath.encode('utf-8')
Missing comma, which is, after all, just a matter of syntax so it can't matter, 
right?


I doubted that os.rename arguments must be comma seperated.
But ater reading the docs.

s.rename(/src/,/dst/)

   Rename the file or directory/src/to/dst/. If/dst/is a
   directory,OSError
   will
   be raised. On Unix, if/dst/exists and is a file, it will be replaced
   silently if the user has permission. The operation may fail on some
   Unix flavors if/src/and/dst/are on different filesystems. If
   successful, the renaming will be an atomic operation (this is a
   POSIX requirement). On Windows, if/dst/already exists,OSError
   will
   be raised even if it is a file; there may be no way to implement an
   atomic rename when/dst/names an existing file.

   Availability: Unix, Windows.

Indeed it has to be:

os.rename( filepath_bytes, filepath.encode('utf-8')

'mv source target' didn't require commas so i though it was safe to assume that 
os.rename did not either.


I'am happy to announce that after correcting many idiotic error like commas, 
missing colons and declaring of variables, this surrogate erro si the last i 
get.
I still dont understand what surrogate means. In english means replacement.
Here is the code:


#
# Collect filenames of the path dir as bytes
filename_bytes = os.listdir( b'/home/nikos/public_html/data/apps/' )

# Iterate over all filenames in the path dir
for filename in filename_bytes:
# Compute 'path/to/filename' in bytes
filepath_bytes = b'/home/nikos/public_html/data/apps/' + b'filename'
try:
filepath = filepath_bytes.decode('utf-8')
except UnicodeDecodeError:
try:
filepath = filepath_bytes.decode('iso-8859-7')

# Rename current filename from greek bytes => utf-8 
bytes
os.rename( filepath_bytes, filepath.encode('utf-8') )
except UnicodeDecodeError:
print( '''I give up! This filename is unreadable! ''')


#
# Get filenames of the apps directory as unicode
filenames = os.listdir( '/home/nikos/public_html/data/apps/' )

# Load'em
for filename in filenames:
try:
# Check the presence of a file against the database and insert 
if it doesn't exist
cur.execute('''SELECT url FROM files WHERE url = %s''', 
(filename,) )
data = cur.fetchone()#filename is unique, so should 
only be one

if not data:
# First time for file; primary key is automatic, hit is 
defaulted
cur.execute('''INSERT INTO files (url, host, lastvisit) 
VALUES (%s, %s, %s)''', (filename, host, lastvisit) )
except pymysql.ProgrammingError as e:
print( repr(e) )


#
filenames = os.listdir( '/home/nikos/public_html/data/apps/' )
filenames = ()

# Build a set of 'path/to/filename' based on the objects of path dir
for filename in filenames:
filenames.add( filename )

# Delete spurious
cur.execute('''SELECT url FROM files''')
data = cur.fetchall()

# Check database's filenames against path's filenames
for filename in data:
if filename not in filenames:
cur.execute('''DELETE FROM files WHERE url = %s''', (filename,) 
)



=

[Fri Jun 07 11:08:17 2013] [error] [client 79.103.41.173]   File 
"/home/nikos/public_html/cgi-bin/files.py", line 88, in 
[Fri Jun 07 11:08:17 2013] [error] [client 79.103.41.173] 
cur.execute('''SELECT url FROM files WHERE url = %s''', filename )
[Fri Jun 07 11:08:17 2013] [error] [client 79.103.41.173]   File 
"/usr/local/lib/python3.3/site-packages/PyMySQL3-0.5-py3.3.egg/pymysql/cursors.py",
 line 108, in execute
[Fri Jun 07 11:08:17 2013] [error] [client 79.103.41.173] query = 
query.encode(charset)
[Fri Jun 07 11:08:17 2013] [error] [client 79.103.41.173] UnicodeEncodeError: 
'utf-8' codec can't encode character '\\udcce' in position 35: surrogates not 
allowed



--
Webhost && Weblog 
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   4   >