Python parser problem

2012-12-12 Thread RCU

  Hello.
I would like to report a parser bug manifesting on Python 2.5, 2.7 (but not on 2.2) 
and 3.3.

Please see the attached script.
Basically this bug appeared after applying PythonTidy on a valid script.

More exactly, when running:
python -c "import iCam_GIT5_5"
  I get:
Traceback (most recent call last):
  File "", line 1, in 
  File "iCam_GIT5_5.py", line 60

^
SyntaxError: invalid syntax

Actually, the error reported by Python is a bug, as far as I see: the line 60 
reported in the script does not actually contain the text reported in the error, and this 
makes quite difficult locating the so-called error.
In fact the error is at script line 30: we should have all the code on one line, like 
this
	playlistToUse = youtubeClient.AddPlaylist(playlistTitle, playlistTitle, 
playlist_private=False).
The "\" used in the script to break the line in 2 is a reminiscence of running 
PythonTidy-1.22.python (so fixing this bug would be directly relevant when using PythonTidy).


With this occasion I would like to ask also what are the limits of the Python 2.x and 
3.x parser. Where can I find what are the limits on the size/lines of the parsed script?


  Best regards,
Alex
CURRENT_RELEASE_TIME = '2012_12_10_13_00_00'

NEW_BT_FORMAT_TO_ALLOW_PLAYING_FILE_EVEN_IN_INBOX = True

def SendAlarmMessageToYouTubePlaylist(message):

global youtubeClient, youtubeClientAlreadyConnected

global YOUTUBE_TEST_CLIENT_ID, googleUsername, youtubeDeveloperKey

global uploadMediaToYouTube

global deviceId

if MY_DEBUG_STDOUT:

print 'Entered SendAlarmMessageToYouTubePlaylist() at %s.' % 
GetCurrentDateTimeStringWithMilliseconds()

sys.stdout.flush()

if uploadMediaToYouTube == 0:

uploadMediaToYouTube = 1

if youtubeClientAlreadyConnected == False:

if gdataModulesImported == False:

ImportGdataModules()

connResult = ConnectToYouTubeGData()

try:

playlistTitle = 'iCam_alarm_' + deviceId

if False:

playlistDescription = playlistTitle

playlistToUse = None

feed = youtubeClient.GetYouTubePlaylistFeed()

for myEntry in feed.entry:

myEntryTitle = myEntry.title.text

myEntryIdStr = myEntry.id.text.split('/')[-1]

if playlistTitle == myEntryTitle:

playlistToUse = myEntry

break

if playlistToUse is None:

playlistToUse = \

youtubeClient.AddPlaylist(playlistTitle, playlistTitle, 
playlist_private=False)

playlistDescription = ''

newPlaylistDescription = 'Alarm... motion degree... audio degree... 
%s.' % message

playlistToUse = None

feed = youtubeClient.GetYouTubePlaylistFeed()

for myEntry in feed.entry:

myEntryTitle = myEntry.title.text

myEntryIdStr = myEntry.id.text.split('/')[-1]

if myEntryTitle == playlistTitle:

if MY_DEBUG_STDOUT:

print 'SendAlarmMessageToYouTubePlaylist(): Feed matched 
myEntry =', myEntry

print 'SendAlarmMessageToYouTubePlaylist(): myEntry.content 
=', myEntry.content

print 'SendAlarmMessageToYouTubePlaylist(): 
myEntry.description = %s' % str(myEntry.description)

sys.stdout.flush()

playlistDescription = 
str(myEntry.description).split('>')[-2].split('-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python parser problem

2012-12-13 Thread RCU

  Dave,
Thanks for the reply.
The script was originally edited on Windows with proper \r\n endings, but the 
PythonTidy script somehow does the doubling (I guess it assumes UNIX format only), i.e., 
\r\r\n . So indeed, that's kind of messy (and the Python Lang Reference specifies clearly 
it interprets \r as a newline, as well) and I didn't realize it with my editor. After 
running dos2unix (twice) on the script I cleaned all \r and it went OK.


I guess Python is complaining at line 30 and not at the previous lines, because of 
the line-breaking backslash.


  Best regards,
Alex

On 12/12/2012 9:59 PM, Dave Angel wrote:

On 12/12/2012 02:10 PM, RCU wrote:

   Hello.
 I would like to report a parser bug manifesting on Python 2.5, 2.7
(but not on 2.2) and 3.3.
 Please see the attached script.
 Basically this bug appeared after applying PythonTidy on a valid
script.

 More exactly, when running:
 python -c "import iCam_GIT5_5"
   I get:
 Traceback (most recent call last):
   File "", line 1, in
   File "iCam_GIT5_5.py", line 60

 ^
 SyntaxError: invalid syntax

 Actually, the error reported by Python is a bug, as far as I see:
the line 60 reported in the script does not actually contain the text
reported in the error, and this makes quite difficult locating the
so-called error.


No, the error is on line 60.  You have blank line between each line, but
your editor apparently doesn't show you that.

Your line-endings are messed up.  Here's a dump of the first two lines.
(using hexdump -C)

  43 55 52 52 45 4e 54 5f  52 45 4c 45 41 53 45 5f
|CURRENT_RELEASE_|
0010  54 49 4d 45 20 3d 20 27  32 30 31 32 5f 31 32 5f  |TIME =
'2012_12_|
0020  31 30 5f 31 33 5f 30 30  5f 30 30 27 0d 0d 0a 4e
|10_13_00_00'...N|

Notice that the line ends with 0d0d0a, or \r\r\n.  That's not valid.
Apparently python's logic considers that as a line ending with \r,
followed by a blank line ending with\r\n.



 In fact the error is at script line 30: we should have all the
code on one line, like this
 playlistToUse = youtubeClient.AddPlaylist(playlistTitle,
playlistTitle, playlist_private=False).
 The "\" used in the script to break the line in 2 is a
reminiscence of running PythonTidy-1.22.python (so fixing this bug
would be directly relevant when using PythonTidy).


Nothing wrong with ending with a backslash for continuation.  Backslash
continues the line onto the next one, which is blank.  Remove the extra
\r there and it'll be fine.



 With this occasion I would like to ask also what are the limits of
the Python 2.x and 3.x parser. Where can I find what are the limits on
the size/lines of the parsed script?


Can't help there.





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