Pulling numbers from ASCII filename not working

2006-01-24 Thread IamIan
I searched the archives but couldn't find anyone else with this
problem. Basically I'm grabbing all ASCII files in a directory and
doing geoprocessing on them. I need to calculate a z-factor based on
the latitude of the ASCII file being worked on, which is in the
filename. If I type in the code manually it works and reads the
latitude value from the ASCII filename, but when run within ArcGIS it
crashes when it gets to int(LatString). Isnumber() returned false for
Latitude as well. Is there something different about reading values
from an ASCII filename?

import sys, os, win32com.client, string, gc

# Get a list of ASCII files in the workspace for ASCII To Raster
conversion
filenames = os.listdir(gp.workspace)
filenames = [filename.lower()
for filename in filenames
if (filename[-4:].lower() == ".asc" and filename[0] != "-" )]
for filename in filenames:

# For each ASCII file, create Hillshade.
# account for latitude by computing Z units using radians
Latitude = filename[1:3]
LatString = str(Latitude)
LatInt = int(LatString)
radians = LatInt * 0.0174532925
zFactor = 1/(113200 * (cos(radians)))

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


Re: Pulling numbers from ASCII filename not working

2006-01-24 Thread IamIan
The exception I get is "TypeError: Cannot add value 'int' to string." I
have looked at LatString, and it is the string representation of
latitude ('17' etc.). What's odd is that the exception is raised not
when I include LatInt = int(LatString), but when I try to print
LatInt's value or multiply it by another number.

Filenames are along the lines of "N16W110.asc" - is there another way
to get LatString into a number for multiplication purposes?

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


Re: Pulling numbers from ASCII filename not working

2006-01-25 Thread IamIan
Thank you for the replies, I'm new to Python and appreciate your
patience. I'm using Python 2.1.

To reiterate, the ASCII files in the workspace are being read correctly
and their latitude values (coming from the filenames) are successfully
being converted to string. Even doing LatInt = int(LatString) works,
however the second I try to print LatInt's value or use it in
mathematical operations, the code chokes in ArcGIS.

My full code:

# Import system modules
import sys, os, win32com.client

# Create the geoprocessor object
gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")
print gp.usage("Hillshade_sa")
print gp.usage("RasterToOtherFormat_conversion")
print gp.usage("DefineProjection_management")

# Check license availability
gp.AddMessage ("ArcInfo license is " + str(gp.CheckProduct("ArcInfo")))
gp.SetProduct("ArcInfo")
gp.CheckOutExtension("Spatial")

# Set workspace
workspace = "E:\\GISTest"
gp.workspace = workspace
gp.AddMessage("Workspace = " + gp.workspace)

filenames = os.listdir(gp.workspace)
filenames = [filename.lower()
for filename in filenames
if (filename[-4:].lower() == ".asc" and filename[0] != "-" )]
for filename in filenames:

   # For each ASCII file, create Hillshade.
   # account for latitude by computing Z units using radians
   Latitude = filename[1:3]
   LatString = str(Latitude)
   LatInt = int(LatString)
   gp.AddMessage("LatInt is " + LatInt)
   radians = LatInt * 0.0174532925
   zFactor = 1/(113200 * (cos(radians)))

The complete traceback:

Traceback (most recent call last):
  File "e:\python21\pythonwin\pywin\framework\scriptutils.py", line
310, in RunScript
exec codeObject in __main__.__dict__
  File "E:\Documents and
Settings\Administrator\Desktop\Ian\GIS\Python\zOnly.py", line 32, in ?
gp.AddMessage("LatInt is " + LatInt)
TypeError: cannot add type "int" to string


I tried print repr(filename) and it returned the actual filename:
'n16w099.asc' , 'n17w062.asc' , etc.

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


Re: Pulling numbers from ASCII filename not working

2006-01-25 Thread IamIan
>Dude. You're trying to add a string to an int. What did you think would
>happen?

Dude. I thought it would concatenate the value for LatInt with the rest
of the sentence; I wasn't literally trying to add them. Apparently you
can only concatenate strings like this in Python.

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


Re: Pulling numbers from ASCII filename not working

2006-02-01 Thread IamIan
Thanks for the help everyone (especially those that gave more answers
than attitude). It's working perfectly!

Ian

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


Help with os.spawnv

2006-02-09 Thread IamIan
I've had to migrate back to Python 2.1 and am now trying to use
os.spawnv to get around a memory leak (either in Python or ArcGIS or
both) in a geoprocessing script.

This script (Second Script) gets each Ascii file in the workspace,
converts it to a raster, sets the spatial reference, and hillshades it.
The script works on its own. In the Main Script I can successfully pass
parameters in a list, but no geoprocessing is ever initiated when using
os.spawnv. No errors are being thrown so I don't have a traceback to
post. Help getting this straightened out would be EXTREMELY
appreciated!


Main Script

# Import subprocess module
import os, sys

# Define arguments for subprocess
pyPath = "E:\\Python242\\python.exe"
pyScript = "E:\\Documents and
Settings\\Administrator\\Desktop\\Ian\\GIS\\Python\\subProcess2.py"
workspace = "E:\\GISTest"

# Get a list of ASCII files in the workspace for ASCII To Raster
conversion
filenames = os.listdir(workspace)
filenames = [filename.lower()
for filename in filenames
if (filename[-4:].lower() == ".asc" and filename[0] != "-" )]
for filename in filenames:
# Define Img filename, truncating .asc from inAscii filename
inAscii = workspace + "\\" + filename
outImg = workspace + "\\" + filename[:-4] + ".img"

# Create parameter list
parameterList = []
# First parameter is the name of the Python executable
parameterList.append('python.exe')
# Second parameter is the full path of the Python script
parameterList.append(pyScript)
# The following parameters are the arguments for the Batch script
parameterList.append(filename)
parameterList.append(inAscii)
parameterList.append(outImg)
parameterList.append(outHill)
print parameterList
# Run subprocess
os.spawnv(os.P_WAIT, pyPath, parameterList)
print parameterList

Second Script

I can't post this verbatim for work reasons, but basically it goes:

import sys, os, win32com.client, string
gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")
gp.SetProduct("ArcInfo")
gp.CheckOutExtension("Spatial")

# For each ASCII file, convert into IMG format
filename = sys.argv[1]
inAscii = sys.argv[2]
outImg = sys.argv[3]
outHill = sys.argv[4]

Do Ascii to raster conversion using inAscii, creating outImg

Set spatial reference

Hillshade using outImg, creating outHill

Convert each hillshade to IMG format, using outHill

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


Exiting os.spawnv's subroutine

2006-02-17 Thread IamIan
I am using os.spawnv in Python 2.1 to do some geoprocessing in a
subroutine/process. Everything works great, except when the processing
is done the subroutine just waits for a couple minutes before closing
itself and returning to the main script. I have tried using sys.exit()
and exit() but these aren't doing anything.

What is the proper way to terminate this subroutine upon completion,
rather than waiting? Thank you.

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


Re: Exiting os.spawnv's subroutine

2006-02-21 Thread IamIan
My code is below. As a single script there is no pause at the end of
the processing as there is with using os.spawnv... I am using the
P_WAIT value, and wonder if it is responsible for the extra time at the
end of each iteration. Could it take longer for the processing to be
"successful" when run under os.spawnv? Is there a way to manually send
a "success" exit code back to os.spawnv, rather than waiting for it?
Thanks.

Main script:
# Import subprocess modules
import os, sys, win32com.client

# Define arguments for subprocess
pyPath = "C:\\Python21\\python.exe"
contourScript = "C:\\Ian\\Python scripts\\subProcess2.py"
workspace = "D:\\GIS\\Test"

# Get a list of IMG files in the workspace for Contouring
filenames = os.listdir(workspace)
filenames = [filename.lower()
for filename in filenames
if (filename[-4:].lower() == ".img" and filename[0:2] != "h_" )]
for filename in filenames:

# Define filenames
print "Filename is " + filename
inImg = workspace + "\\" + filename
outContour50 = workspace + "\\contour50_" + filename[:-4] + ".shp"
outContour100 = workspace + "\\contour100_" + filename[:-4] +
".shp"
outContour200 = workspace + "\\contour200_" + filename[:-4] +
".shp"
outContour500 = workspace + "\\contour500_" + filename[:-4] +
".shp"

# Create parameter list
parameterList = []

# First parameter is the name of the Python executable
parameterList.append('python.exe')

# Second parameter is the full path of the Python script
parameterList.append(contourScript)

# The following parameters are the arguments for the Batch script
parameterList.append(inImg)
parameterList.append(outContour50)
parameterList.append(outContour100)
parameterList.append(outContour200)
parameterList.append(outContour500)

# Run subprocess
os.spawnv(os.P_WAIT, pyPath, parameterList)

print "All done!"


Secondary script:
# Import system modules
import sys, win32com.client

# Create the geoprocessor object
gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")

# Confirm license availability
print "ArcInfo license is " + str(gp.CheckProduct("ArcInfo"))
gp.SetProduct("ArcInfo")
gp.CheckOutExtension("Spatial")

# Set arguments to be passed to main script
inImg = sys.argv[1]
outContour50 = sys.argv[2]
outContour100 = sys.argv[3]
outContour200 = sys.argv[4]
outContour500 = sys.argv[5]

badImgList = []

try:
# For each IMG file, contour at 50, 100, and 200 meter intervals
gp.Contour_sa(inImg, outContour50, "50", "0", "1")
print "Successfully contoured at 50 meter interval!"

gp.Contour_sa(inImg, outContour100, "100", "0", "1")
print "Successfully contoured at 100 meter interval!"

gp.Contour_sa(inImg, outContour200, "200", "0", "1")
print "Successfully contoured at 200 meter interval!"

gp.Contour_sa(inImg, outContour500, "500", "0", "1")
print "Successfully contoured at 500 meter interval!"
except:
badImgList.append(filename)
print filename + " is no good! It's been added to the list!"

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


Re: Exiting os.spawnv's subroutine

2006-02-22 Thread IamIan
Strange but removing the try/except part of the second script (leaving
only the processing) removed the 2 minute lag at the end of each
subroutine.

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


Splitting SAX results

2007-06-06 Thread IamIan
Hi list,

I have a very simple SAX script from which I get results like
'Title1:Description','Title2:Description'. I want to split each result
on the colon, using the two resulting elements as key/value pairs in a
dictionary. I've tried a couple different approaches with lists etc,
but I keep getting an 'IndexError: list index out of range' when I go
to split the results. Probably an easy fix but it's my first hack at
SAX/XML. Thank you!

from xml.sax import make_parser
from xml.sax.handler import ContentHandler

class reportHandler(ContentHandler):
  def __init__(self):
self.isReport = 0

  def startElement(self, name, attrs):
if name == 'title':
  self.isReport = 1
  self.reportText = ''

  def characters(self, ch):
if self.isReport:
  self.reportText += ch

  def endElement(self, name):
if name == 'title':
  self.isReport = 0
  print self.reportText

parser = make_parser()
parser.setContentHandler(reportHandler())
parser.parse('http://www.some.com/rss/')

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


Re: Splitting SAX results

2007-06-08 Thread IamIan
Well SAX isn't the problem... maybe I should repost this with a
different title. The SAX part works just as I want, but the results I
get back need to be manipulated. No matter what I try I can't split a
result like 'Title 1:Description' on the colon without getting an
IndexError. Ideas anyone?

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


Re: Splitting SAX results

2007-06-12 Thread IamIan
I do know how split works, but thank you for the response. The end
result that I want is a dictionary made up of the title results coming
through SAX, looking like {'Title1: Description',
'Title2:Description'}.

The XML data looks like:

Title1:Description
Link
Desc
Author
Date


Title2:Description
Link
Desc
Author
Date


I've tried different approaches, a couple of which I've added to the
code below (only running one option at a time):

from xml.sax import make_parser
from xml.sax.handler import ContentHandler

tracker = [] # Option 1
tracker = {} # Option 2

class reportHandler(ContentHandler):

  def __init__(self):
self.isReport = 0

  def startElement(self, name, attrs):
if name == 'title':
  self.isReport = 1
  self.reportText = ''

  def characters(self, ch):
if self.isReport:
  self.reportText += ch
  tracker.append(ch) # Option 1
  key, value = ch.split (':') # Option 2
  tracker[key] = value

  def endElement(self, name):
if name == 'title':
  self.isReport = 0
  print self.reportText

parser = make_parser()
parser.setContentHandler(reportHandler())
parser.parse('http://www.some.com/rss/')

print tracker


Option 1 returns a list with the markup included, looking like:
[u'Title1:", u'\n', u'Description ', u'\n', u'\t\t\t', u'Title2:',
u'\n', u'Description ', u'\n', u'\t\t\t', etc]

Option 2 fails with the traceback:
File "C:\test.py", line 21, in characters
key, value = ch.split(':')
ValueError: need more than 1 value to unpack

Thank you for the help!

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


XML / Unicode / SAX question

2007-07-03 Thread IamIan
I am using SAX to parse XML that has numeric html entities I need to
convert and feed to JavaScript as part of a CGI. I can get the
characters to print correctly, but not without being surrounded by
linebreaks:

from xml.sax import make_parser
from xml.sax.handler import ContentHandler
import htmlentitydefs, re

def unescape_charref(ref):
name = ref[2:-1]
base = 10
if name.startswith("x"):
name = name[1:]
base = 16
return unichr(int(name, base))

def replace_entities(match):
ent = match.group()
if ent[1] == "#":
return unescape_charref(ent)

repl = htmlentitydefs.name2codepoint.get(ent[1:-1])
if repl is not None:
repl = unichr(repl)
else:
repl = ent
return repl

def unescape(data):
return re.sub(r"&#?[A-Za-z0-9]+?;", replace_entities, data)

class newsHandler(ContentHandler):
  def __init__(self):
self.isNews = 0

  def startElement(self, name, attrs):
if name == 'title':
  self.isNews = 1

  def characters(self, ch):
if self.isNews:
  ch = unescape(ch)
  print ch

  def endElement(self, name):
if name == 'title':
  self.isNews = 0

parser = make_parser()
parser.setContentHandler(newsHandler())
parser.parse('http://www.some.com/rss/rss.xml')

For a line like 'Mark à Capbreton'
my results print as:
'Mark
à
Capbreton'

Is this another SAX quirk? I've already had to hack my way around SAX
not being able to split results on a colon. No matter if I try strip,
etc the results are always the same: newlines surrounding the html
entities. I'm using version 2.3.5 and need to stick to the standard
libraries. Thanks.

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


Re: Nested dictionaries trouble

2007-04-19 Thread IamIan
Thank you again for the great suggestions. I have one final question
about creating a httpMonths dictionary like {'Jan':'01' , 'Feb':'02' ,
etc} with a minimal amount of typing. My code follows (using Python
2.3.4):

import calendar

# Create years list, formatting as strings
years = map(str, xrange(1990,2051))

# Create months list with three letter abbreviations
months = list(calendar.month_abbr)

# Create monthTotals dictionary with default value of zero
monthTotals = dict.fromkeys(months[1:],0)

# Create yearTotals dictionary with years for keys
# and copies of the monthTotals dictionary for values
yearTotals = dict([(year, monthTotals.copy()) for year in years])

# Create httpMonths dictionary to map month abbreviations
# to Apache numeric month representations
httpMonths =
{"Jan":"01","Feb":"02","Mar":"03","Apr":"04","May":"05","Jun":"06","Jul":"07","Aug":"08","Sep":"09","Oct":"10","Nov":"11","Dec":"12"}

It is this last step I'm referring to. I got close with:
httpMonths = {}
for month in months[1:]:
  httpMonths[month] = str(len(httpMonths)+1)

but the month numbers are missing the leading zero for 01-09. Thanks!

Ian

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


Simple elementtree question

2007-08-30 Thread IamIan
This is in Python 2.3.5. I've had success with elementtree and other
RSS feeds, but I can't get it to work with this format:

http://www.w3.org/1999/02/22-rdf-syntax-ns#";
 xmlns:dc="http://purl.org/dc/elements/1.1/";
 xmlns:fr="http://ASPRSS.com/fr.html";
 xmlns:pa="http://ASPRSS.com/pa.html";
 xmlns="http://purl.org/rss/1.0/";>
http://www.sample.com";>
Example feed
http://www.sample.com
Sample News Agency - News Feed
http://www.sample.com/img/new.gif"; />


http://www.sample.com/news/2/news.htm"; />
http://www.sample.com/news/20001/news.htm"; />


http://www.sample.com/img/about.gif";>
Our News Feed
http://www.sample.com/img/title.gif
http://www.sample.com

http://www.sample.com/news/2/
news.htm">First story
30 August, 2007 : - - First description including unicode
characters
http://www.sample.com/news/2/news.htm

http://www.sample.com/news/20001/
news.htm">Second story
30 August, 2007 : - - Second description including
unicode characters
http://www.sample.com/news/20001/news.htm



What I want to extract is the text in the title and link tags for each
item (eg. First story and http://www.sample.com/
news/2/news.htm). Starting with the title, my test script
is:

import sys
from urllib import urlopen

sys.path.append("/home/me/lib/python")
import elementtree.ElementTree as ET

news = urlopen("http://www.sample.com/rss/rss.xml";)
nTree = ET.parse(news)
for item in nTree.getiterator("title"):
  print item.text

Whether I try this for title or link, nothing is printed. There are
also unicode characters in the  tags, I'm not sure if that
could affect the output like this. In case it did I passed an encoding
argument to ET.parse (which I'd seen in other posts) but it said
encoding was an unexpected argument...

Printing all subelements does work:
print nTree.getiterator()

[http://www.w3.org/1999/02/22-rdf-syntax-ns#}RDF at
40436d2c>,
http://purl.org/rss/1.0/}channel at 40436b2c>,
http://purl.org/rss/ 1.0/}title at 40436dcc>,
http://purl.org/rss/1.0/}link at 40436d6c>,
< Element {http://purl.org/rss/1.0/}description at 40436e0c>,
http://pur l.org/rss/1.0/}image at 40436e6c>,
http://purl.org/rss/1.0/}items at 4 0436f2c>, http://www.w3.org/1999/02/22-rdf-syntax-ns#}Seq at 40436f6c> ,
http://www.w3.org/1999/02/22-rdf-syntax-ns#}li at
40436f0c>,
http://www.w3.org/1999/02/22-rdf-syntax-ns#}li at
40436fec>,
http://purl.org/rss /1.0/}item at 4044624c>,
http://purl.org/rss/1.0/}title at 4044626c>,
http://purl.org/rss/1.0/}description at 4044614c>,
http://purl.org/rss/1.0/}link at 4044630c>,
http://purl.org/rss/1.0/}item at 40 4463ac>,
http://purl.org/rss/1.0/}title at 404463cc>,
,
http://purl.org/rss/1.0/} link at 4044640c>]

Any ideas are greatly appreciated.

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


Re: Simple elementtree question

2007-08-30 Thread IamIan
Thank you very much! That did it.

In the source XML  tags have rdf:about attributes with the link
to the story, and it was here I planned on grabbing the link and
matching it up with the  child text. After seeing the output of
elmenttree's getiterator() though, it now looks like each item, title,
description, and link is a separate element...

I could use a dictionary or lists to match the first title to the
first link, but is there a more elegant way in elementtree (or
otherwise) to do this?

Thanks again,

Ian

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


08 and 09 in sequence create "invalid token" error?!

2007-04-06 Thread IamIan
Hello all,

I am confused as to why including 08 or 09 in a sequence (list or
tuple) causes this error. All other numbers with a leading zero work.

[01,02,03,04,05,06,07]  is fine
[01,02,03,04,05,06,07,10]  is fine

[01,02,03,04,05,06,08]  produces "SyntaxError: invalid token", as
does: [01,02,03,04,05,06,09]

I have tried this both in a script and in the interactive interpreter.
Using Python 2.3.4

Thanks!

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


Re: 08 and 09 in sequence create "invalid token" error?!

2007-04-06 Thread IamIan
Thank you!

Ian

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


Nested dictionaries trouble

2007-04-11 Thread IamIan
Hello,

I'm writing a simple FTP log parser that sums file sizes as it runs. I
have a yearTotals dictionary with year keys and the monthTotals
dictionary as its values. The monthTotals dictionary has month keys
and file size values. The script works except the results are written
for all years, rather than just one year. I'm thinking there's an
error in the way I set my dictionaries up or reference them...

import glob, traceback

years = ["2005", "2006", "2007"]
months = ["01","02","03","04","05","06","07","08","09","10","11","12"]
# Create months dictionary to convert log values
logMonths =
{"Jan":"01","Feb":"02","Mar":"03","Apr":"04","May":"05","Jun":"06","Jul":"07","Aug":"08","Sep":"09","Oct":"10","Nov":"11","Dec":"12"}
# Create monthTotals dictionary with default 0 value
monthTotals = dict.fromkeys(months, 0)
# Nest monthTotals dictionary in yearTotals dictionary
yearTotals = {}
for year in years:
  yearTotals.setdefault(year, monthTotals)

currentLogs = glob.glob("/logs/ftp/*")

try:
  for currentLog in currentLogs:
readLog = open(currentLog,"r")
for line in readLog.readlines():
  if not line: continue
  if len(line) < 50: continue
  logLine = line.split()

  # The 2nd element is month, 5th is year, 8th is filesize
  # Counting from zero:

  # Lookup year/month pair value
  logMonth = logMonths[logLine[1]]
  currentYearMonth = yearTotals[logLine[4]][logMonth]

  # Update year/month value
  currentYearMonth += int(logLine[7])
  yearTotals[logLine[4]][logMonth] = currentYearMonth
except:
  print "Failed on: " + currentLog
  traceback.print_exc()

# Print dictionaries
for x in yearTotals.keys():
  print "KEY",'\t',"VALUE"
  print x,'\t',yearTotals[x]
  #print "  key",'\t',"value"
  for y in yearTotals[x].keys():
print "  ",y,'\t',yearTotals[x][y]


Thank you,
Ian

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


Re: Nested dictionaries trouble

2007-04-11 Thread IamIan
Thank you everyone for the helpful replies. Some of the solutions were
new to me, but the script now runs successfully. I'm still learning to
ride the snake but I love this language!

Ian

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


Re: Nested dictionaries trouble

2007-04-18 Thread IamIan
I am using the suggested approach to make a years list:

years = ["199%s" % x for x in range(0,10)]
years += ["200%s" % x for x in range(0,10)]

I haven't had any luck doing this in one line though. Is it possible?

Thanks.

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


CGI and external JavaScript nightmare

2007-10-10 Thread IamIan
My website is built from a Python CGI and works great. I'm now
including Google Ads, which requires two pieces of JavaScript; the
first contains the display settings for the ads, and the second piece
is a very lengthy garbled js file at 
http://pagead2.googlesyndication.com/pagead/show_ads.js

The first piece of JavaScript works fine and the ads display
correctly, however the second file throws an "unterminated string
literal" js error. Looking at it you can see a healthy amount of both
single and double quotes, which is where my problem lies.

What is the best way to get the second js file into a nice printable/
usable format? cgi.escape? xml.sax.saxutils.quoteattr? String
substitution? I could use some guidance.

Thank you!

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


Re: CGI and external JavaScript nightmare

2007-10-11 Thread IamIan
bump

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


Re: CGI and external JavaScript nightmare

2007-10-17 Thread IamIan
Thank you for the replies. After a lot of research I tracked down the
issue. I was using the CGI to build all of the pages for the site,
then filling in content with .innerHTML= as users clicked on tabs.
Since I wanted to place the Google Ads in different parts of each
page, the Google Ads JavaScript was in each page chunk being
dynamically placed with .innerHTML.

It turns out that JavaScript isn't executed when it is placed in a
page via .innerHTML. I tried some tricks to execute it after it was
added to the page (eval, appendChild) but it still didn't work. The
Google Ads JavaScript is very touchy and their agreement is very
strict; it wasn't even clear that what I was doing was in line with
it, so I broke the site up into multiple CGI pages and now it works
fine.

One CGI question - since all of my CGIs are spitting out HTML is their
source code safe? wget and linking to the source deliver the output
HTML. Are there any other methods of trying to steal the source CGI I
need to protect against?

Thank you.

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


Re: CGI and external JavaScript nightmare

2007-10-17 Thread IamIan
Thank you for the replies. After a lot of research I tracked down the
issue. I was using the CGI to build all of the pages for the site,
then filling in content with .innerHTML= as users clicked on tabs.
Since I wanted to place the Google Ads in different parts of each
page, the Google Ads JavaScript was in each page chunk being
dynamically placed with .innerHTML.

It turns out that JavaScript isn't executed when it is placed in a
page via .innerHTML. I tried some tricks to execute it after it was
added to the page (eval, appendChild) but it still didn't work. The
Google Ads JavaScript is very touchy and their agreement is very
strict; it wasn't even clear that what I was doing was in line with
it, so I broke the site up into multiple CGI pages and now it works
fine.

One CGI question - since all of my CGIs are spitting out HTML is their
source code safe? wget and linking to the source deliver the output
HTML. Are there any other methods of trying to steal the source CGI I
need to protect against?

Thank you.

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


Re: CGI and external JavaScript nightmare

2007-10-17 Thread IamIan
Thank you for the replies. After a lot of research I tracked down the
issue. I was using the CGI to build all of the pages for the site,
then filling in content with .innerHTML= as users clicked on tabs.
Since I wanted to place the Google Ads in different parts of each
page, the Google Ads JavaScript was in each page chunk being
dynamically placed with .innerHTML.

It turns out that JavaScript isn't executed when it is placed in a
page via .innerHTML, it is inserted as text hence the unterminated
string literal error. I tried some tricks to execute it after it was
added to the page (eval, appendChild) but it still didn't work. The
Google Ads JavaScript is very touchy and their agreement is very
strict; it wasn't even clear that what I was doing was in line with
it, so I broke the site up into multiple CGI pages and now it works
fine.

One CGI question - since all of my CGIs are spitting out HTML is their
source code safe? wget and linking to the source deliver the output
HTML. Are there any other methods of trying to steal the source CGI I
need to protect against?

Thank you.

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


Re: CGI and external JavaScript nightmare

2007-10-17 Thread IamIan
Thank you for the replies. After a lot of research I tracked down the
issue. I was using the CGI to build all of the pages for the site,
then filling in content with .innerHTML= as users clicked on tabs.
Since I wanted to place the Google Ads in different parts of each
page, the Google Ads JavaScript was in each page chunk being
dynamically placed with .innerHTML.

It turns out that JavaScript isn't executed when it is placed in a
page via .innerHTML. I tried some tricks to execute it after it was
added to the page (eval, appendChild) but it still didn't work. The
Google Ads JavaScript is very touchy and their agreement is very
strict; it wasn't even clear that what I was doing was in line with
it, so I broke the site up into multiple CGI pages and now it works
fine.

One CGI question - since all of my CGIs are spitting out HTML is their
source code safe? wget and linking to the source deliver the output
HTML. Are there any other methods of trying to steal the source CGI I
need to protect against?

Thank you.

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


Re: CGI and external JavaScript nightmare

2007-10-17 Thread IamIan
Thank you for the replies. After a lot of research I tracked down the
issue. I was using the CGI to build all of the pages for the site,
then filling in content with .innerHTML= as users clicked on tabs.
Since I wanted to place the Google Ads in different parts of each
page, the Google Ads JavaScript was in each page chunk being
dynamically placed with .innerHTML.

It turns out that JavaScript isn't executed when it is placed in a
page via .innerHTML. I tried some tricks to execute it after it was
added to the page (eval, appendChild) but it still didn't work. The
Google Ads JavaScript is very touchy and their agreement is very
strict; it wasn't even clear that what I was doing was in line with
it, so I broke the site up into multiple CGI pages and now it works
fine.

One CGI question - since all of my CGIs are spitting out HTML is their
source code safe? wget and linking to the source deliver the output
HTML. Are there any other methods of trying to steal the source CGI I
need to protect against?

Thank you.

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


Re: CGI and external JavaScript nightmare

2007-10-18 Thread IamIan
> > The OP's problem is that he suffers from the delusion that people want
> > to steal the source code for hisCGIscript.

Why is assuming someone may try to get my source CGI delusional?

I'm on a shared server (Dreamhost). The CGI itself has 755 permissions
to execute, but what about folder permissions, etc? If you could
expand on "access to the server, and so on" that would be great.

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


Regexp not performing the same in FTP versus Python

2007-02-08 Thread IamIan
Hello all,

I'm trying to use a regular expression in an FTP script to list
certain files. When run in a standard FTP session the command:

dir .??[oOdDnNmM]*

returns 48 files. When I use the following Python script it prints
roughly 12 files (a subset of the 48), ending with 'None':


import ftplib, traceback

ftp = ftplib.FTP('host')
ftp.login(user='user', passwd='pass')

try:
  admFiles =  ftp.dir('.??[oOdDnNmM]*')
  print admFiles
except:
  traceback.print_exc

ftp.quit()


Is my Python syntax off?

Thank you.

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


Re: Regexp not performing the same in FTP versus Python

2007-02-08 Thread IamIan
It's strange but since more files have been added to this directory
the regexp appears to be working correctly. Sorry to bother the list
and thanks for your time.

Ian

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