Esempio n. 1
0
    def htmlEncode(s):
        """HTML encode special characters.
        Alias for `WebUtils.Funcs.htmlEncode`, quotes the special characters
        &, <, >, and \"

        """
        return Funcs.htmlEncode(s)
Esempio n. 2
0
    def htmlDecode(s):
        """HTML decode special characters.

        Alias for `WebUtils.Funcs.htmlDecode`. Decodes HTML entities.

        """
        return Funcs.htmlDecode(s)
Esempio n. 3
0
    def urlEncode(s):
        """Quotes special characters using the % substitutions.

        This method does the same as the `urllib.quote_plus()` function.

        """
        return Funcs.urlEncode(s) # we could also use urllib.quote
Esempio n. 4
0
    def urlDecode(s):
        """Turn special % characters into actual characters.

        This method does the same as the `urllib.unquote_plus()` function.

        """
        return Funcs.urlDecode(s)
Esempio n. 5
0
	def urlDecode(self, s):
		"""Alias for `WebUtils.Funcs.urlDecode`.

		Turns special % characters into actual characters.

		"""
		return Funcs.urlDecode(s)
    def handleRequest(self):
        verbose = self._server._verbose
        self._startTime = time.time()
        if verbose:
            print '%5i  %s ' % (self._requestID, timestamp()['pretty']),

        data = []
        dict = self.receiveDict()
        if dict and verbose and dict.has_key('environ'):
            requestURI = Funcs.requestURI(dict['environ'])
            print requestURI
        else:
            requestURI = None

        dict['input'] = self.makeInput()
        streamOut = TASASStreamOut(self._sock)
        transaction = self._server._app.dispatchRawRequest(dict, streamOut)
        streamOut.close()

        try:
            self._sock.shutdown(1)
            self._sock.close()
        except:
            pass

        if self._server._verbose:
            duration = '%0.2f secs' % (time.time() - self._startTime)
            duration = string.ljust(duration, 19)
            print '%5i  %s  %s' % (self._requestID, duration, requestURI)
            print

        transaction._application = None
        transaction.die()
        del transaction
Esempio n. 7
0
	def urlEncode(self, s):
		"""Alias for `WebUtils.Funcs.urlEncode`.

		Quotes special characters using the % substitutions.

		"""
		# @@: urllib.quote, or
		return Funcs.urlEncode(s)
Esempio n. 8
0
 def writeStyleSheet(self):
     """
     Writes stylesheet (CSS) information -- you should probably
     override styleSheetHref() or styleSheet() instead.
     """
     href = self.styleSheetHref()
     if href:
         self.write('<link rel="stylesheet" href="%s" type="text/css">\n' %
                    Funcs.htmlEncode(href))
     styles = self.styleSheet()
     if styles:
         self.write('<style type="text/css"><!--\n%s\n--></style>\n' %
                    styles)
Esempio n. 9
0
 def writeBody(self):
     """
     Writes the <body> portion of the page by writing the
     <body>...</body> (making use of self.htBodyArgs()) and invoking
     self.writeBodyParts() in between.
     """
     wr = self.writeln
     bodyArgs = self.htBodyArgs()
     if type(bodyArgs) is DictionaryType:
         bodyArgs = ' '.join(
             map(lambda x: '%s="%s"' % (x[0], Funcs.htmlEncode(x[1])),
                 bodyArgs.items()))
     if bodyArgs:
         wr('<body %s>' % bodyArgs)
     else:
         wr('<body>')
     self.writeBodyContent()
     wr('</body>')
Esempio n. 10
0
	def writeContent(self):
		self.write("""
		<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>Upload Test</title>
  </head>

  <body>
    <h1>Upload Test</h1>
	<p>%s
	<p>

<form action="FileUpload.py" method=POST enctype="multipart/form-data">
<input type="FILE" name="filename">
<p>
<input type="SUBMIT" name="_action_" value="fileupload">
</form>
  </body>
</html>

		""" % (Funcs.htmlEncode(self.__doc__)))
Esempio n. 11
0
    def urlEncode(s):
        """Quotes special characters using the % substitutions.

        This method does the same as the `urllib.quote_plus()` function.
        """
        return Funcs.urlEncode(s)  # we could also use urllib.quote
Esempio n. 12
0
 def testUrlRoundTrip(self):
     t = '<test>\n\t"50% = 50,50?"\n</test>'
     self.assertEqual(Funcs.urlDecode(Funcs.urlEncode(t)), t)
Esempio n. 13
0
 def writeTitle(self):
     self.write('<title>%s</title>\n' % Funcs.htmlEncode(self.title()))
Esempio n. 14
0
    def htmlDecode(s):
        """HTML decode special characters.

        Alias for ``WebUtils.Funcs.htmlDecode``. Decodes HTML entities.
        """
        return Funcs.htmlDecode(s)
Esempio n. 15
0
 def urlEncode(self, s):
     return Funcs.urlEncode(s)
Esempio n. 16
0
	def fileupload(self, trans):

		f = self.request().field('filename')

		contents = f.file.read()

		self.write("""<html><head></head><body bgcolor='#DDDDEE'>
		Here's the file you submitted:
		<hr>
		name:%s<p>
		type:%s<p>
		type_options:%s<p>
		disposition:%s<p>
		disposition_options:%s<p>
		headers:%s<p>
		size: %s<p>
		contents:<hr>%s </body>
		""" % (f.filename, f.type, f.type_options, f.disposition, f.disposition_options, f.headers, len(contents), Funcs.htmlEncode(contents) ) )
Esempio n. 17
0
 def htmlEncode(self, s):
     return Funcs.htmlEncode(s)
Esempio n. 18
0
 def testHtmlRoundTrip(self):
     t = '<test>\n\t"1 < 2 & 2 > 1"\n</test>'
     self.assertEqual(Funcs.htmlDecode(Funcs.htmlEncode(t)), t)
Esempio n. 19
0
	def writeContent(self):
		self.heading('AppServer')
		self.writeln(Funcs.htmlForDict(self.application().server().config()))

		self.heading('Application')
		self.writeln(Funcs.htmlForDict(self.application().config()))
Esempio n. 20
0
	def writeContent(self):
		self.heading('AppServer')
		self.writeln(Funcs.htmlForDict(self.application().server().config()))

		self.heading('Application')
		self.writeln(Funcs.htmlForDict(self.application().config()))
Esempio n. 21
0
 def urlDecode(self, s):
     return Funcs.urlDecode(s)
Esempio n. 22
0
    def urlDecode(s):
        """Turn special % characters into actual characters.

        This method does the same as the `urllib.unquote_plus()` function.
        """
        return Funcs.urlDecode(s)
Esempio n. 23
0
 def htmlEncode(s):
     """HTML encode special characters.
     Alias for ``WebUtils.Funcs.htmlEncode``, quotes the special characters
     &, <, >, and \"
     """
     return Funcs.htmlEncode(s)
Esempio n. 24
0
 def testHtmlRoundTrip(self):
     t = '<test>\n\t"1 < 2 & 2 > 1"\n</test>'
     self.assertEqual(Funcs.htmlDecode(Funcs.htmlEncode(t)), t)
Esempio n. 25
0
 def htmlDecode(self, s):
     return Funcs.htmlDecode(s)
    def handleRequest(self):

        verbose = self.server._verbose

        startTime = time.time()
        if verbose:
            print '%5i  %s ' % (self._number, timestamp()['pretty']),

        conn = self.sock

        # @@ 2001-05-30 ce: Ack! Look at this hard coding.
        BUFSIZE = 8 * 1024

        data = []

        chunk = ''
        missing = int_length
        while missing > 0:
            block = conn.recv(missing)
            if not block:
                conn.close()
                if len(chunk) == 0:
                    # We probably awakened due to awakeSelect being called.
                    return 0
                else:
                    # We got a partial request -- something went wrong.
                    raise NotEnoughDataError, 'received only %d out of %d bytes when receiving dict_length' % (
                        len(chunk), int_length)
            chunk = chunk + block
            missing = int_length - len(chunk)
        dict_length = loads(chunk)
        if type(dict_length) != type(1):
            conn.close()
            print
            print "Error: Invalid AppServer protocol"
            return 0

        chunk = ''
        missing = dict_length
        while missing > 0:
            block = conn.recv(missing)
            if not block:
                conn.close()
                raise NotEnoughDataError, 'received only %d out of %d bytes when receiving dict' % (
                    len(chunk), dict_length)
            chunk = chunk + block
            missing = dict_length - len(chunk)

        dict = loads(chunk)
        #if verbose: print "Comm Delay=%s" % (time.time() - dict['time'])

        if dict:
            if verbose:
                if dict.has_key('environ'):
                    requestURI = Funcs.requestURI(dict['environ'])
                else:
                    requestURI = None
                print requestURI

        dict['input'] = conn.makefile("rb", 8012)

        strmOut = TASASStreamOut(self.sock)
        transaction = self.server._app.dispatchRawRequest(dict, strmOut)
        strmOut.close()

        try:
            conn.shutdown(1)
            conn.close()
        except:
            pass

        if verbose:
            duration = '%0.2f secs' % (time.time() - startTime)
            duration = string.ljust(duration, 19)
            print '%5i  %s  %s' % (self._number, duration, requestURI)
            print

        transaction._application = None
        transaction.die()
        del transaction
Esempio n. 27
0
 def testUrlRoundTrip(self):
     t = '<test>\n\t"50% = 50,50?"\n</test>'
     self.assertEqual(Funcs.urlDecode(Funcs.urlEncode(t)), t)