All Samples(29193) | Call(21107) | Derive(373) | Import(7713)
class StringIO([buffer]) When a StringIO object is created, it can be initialized to an existing string by passing the string to the constructor. If no string is given, the StringIO will start empty. The StringIO object can accept either Unicode or 8-bit strings, but mixing the two may take some care. If both are used, 8-bit strings that cannot be interpreted as 7-bit ASCII (that use the 8th bit) will cause a UnicodeError to be raised when getvalue() is called.
src/b/r/braintree_python_examples-HEAD/tr_checkout_app_engine/web/browser.py braintree_python_examples(Download)
import httplib, urllib, urllib2 import copy from StringIO import StringIO DEBUG = False
def get_response(self):
"""Returns a copy of the current response."""
return urllib.addinfourl(StringIO(self.data), self._response.info(), self._response.geturl())
def get_soup(self):
"""Returns beautiful soup of the current document."""
import BeautifulSoup
def _make_response(self, result, url):
data = "\r\n".join(["%s: %s" % (k, v) for k, v in result.header_items])
headers = httplib.HTTPMessage(StringIO(data))
response = urllib.addinfourl(StringIO(result.data), headers, url)
code, msg = result.status.split(None, 1)
response.code, response.msg = int(code), msg
return response
src/n/i/NiPy-OLD-HEAD/examples/fiac/fiac_util.py NiPy-OLD(Download)
# Stdlib import os from StringIO import StringIO from os import makedirs, listdir from os.path import exists, abspath, isdir, join as pjoin
X, cons = design.stack_designs((X_exper, cons_exper),
(X_initial, {}))
Xf = np.loadtxt(StringIO(FIACdesigns.designs[dtype]))
for i in range(X.shape[1]):
yield nitest.assert_true, (matchcol(X[:,i], Xf.T)[1] > 0.999)
# more in the form of a 2-way ANOVA
eventdict = {1:'SSt_SSp', 2:'SSt_DSp', 3:'DSt_SSp', 4:'DSt_DSp'}
s = StringIO()
w = csv.writer(s)
w.writerow(['time', 'sentence', 'speaker'])
src/n/i/nipy-HEAD/examples/fiac/fiac_util.py nipy(Download)
# Stdlib import os from StringIO import StringIO from os import makedirs, listdir from os.path import exists, abspath, isdir, join as pjoin
X, cons = design.stack_designs((X_exper, cons_exper),
(X_initial, {}))
Xf = np.loadtxt(StringIO(FIACdesigns.designs[dtype]))
for i in range(X.shape[1]):
yield nitest.assert_true, (matchcol(X[:,i], Xf.T)[1] > 0.999)
# more in the form of a 2-way ANOVA
eventdict = {1:'SSt_SSp', 2:'SSt_DSp', 3:'DSt_SSp', 4:'DSt_DSp'}
s = StringIO()
w = csv.writer(s)
w.writerow(['time', 'sentence', 'speaker'])
src/l/a/Langtangen-HEAD/src/py/examples/simviz/inputfile_wunits.py Langtangen(Download)
def _test():
from StringIO import StringIO
ifile = StringIO("""\
set gridfile = somefile.grid
set add boundary indicator nodes = n=1 b4=[0,1]x[-2,-2]
set time step = 0.5 h ! [s]
set heat heatflux 1 = 0.01 ! [K/m]
ok ! return back to previous level
ok
ok
""")
parsed_lines, dummy = parse_input_file(ifile.readlines())
import pprint
print 'parsed_lines:\n', pprint.pformat(parsed_lines)
src/p/y/pyaeso-0.5/examples/marketgraphs.py pyaeso(Download)
import os import os.path import math from StringIO import StringIO # Plotting libraries NUMPY = 'numpy'
def download_and_create_figure_data(start_date, end_date):
'''Download raw csv files, process them, and return data necessary
for drawing the figure.'''
# Download data from website and buffer it
f = StringIO()
ets.dump_pool_price(f, start_date, end_date)
# calling dump_pool_price each time.
# Create data necessary for drawing
f = StringIO(csvdata)
data = create_figure_data(f)
f.close()
src/p/y/python-cookbook-HEAD/cb2_examples/cb2_2_10_exm_1.py python-cookbook(Download)
import zipfile
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
class ZipString(ZipFile):
def __init__(self, datastring):
ZipFile.__init__(self, StringIO(datastring))
src/p/o/pony-build-HEAD/examples/push-cgi-notifier/feedparser.py pony-build(Download)
try:
from cStringIO import StringIO as _StringIO
except:
from StringIO import StringIO as _StringIO
# ---------- optional modules (feedparser will work without these, but with reduced functionality) ----------
pass
# treat url_file_stream_or_string as string
return _StringIO(str(url_file_stream_or_string))
_date_handlers = []
def registerDateHandler(func):
saxparser.setContentHandler(feedparser)
saxparser.setErrorHandler(feedparser)
source = xml.sax.xmlreader.InputSource()
source.setByteStream(_StringIO(data))
if hasattr(saxparser, '_ns_stack'):
# work around bug in built-in SAX parser (doesn't recognize xml: namespace)
# PyXML doesn't have this problem, and it doesn't have _ns_stack either
src/n/o/notmm-0.4.1/examples/lib/product/forms.py notmm(Download)
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
from decimal import Decimal
from django import forms
if include_images:
filedir = settings.MEDIA_ROOT
buf = StringIO()
zf = zipfile.ZipFile(buf, 'a', zipfile.ZIP_STORED)
export_file = 'products.%s' % format
errors.append(_('Could not parse format from filename: %s') % filename)
if format == 'zip':
zf = zipfile.ZipFile(StringIO(raw), 'r')
files = zf.namelist()
image_dir = config_value('PRODUCT', 'IMAGE_DIR')
other_image_dir = None
errors.append(_('Missing VARS in import zipfile.'))
else:
raw = StringIO(str(raw))
if not format in serializers.get_serializer_formats():
errors.append(_('Unknown file format: %s') % format)
src/p/y/pyaggregator-0.3/examples/links.py pyaggregator(Download)
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
from elixir import *
class Outgoing(Entity):
def process_entry_outgoing(self, post, feed, entry, posts, parsed_data):
content = StringIO('<div>' +
genshi.HTML(post.content).render('xhtml') +
'</div>')
finder = OutgoingFind(content)
self.clearOutgoingForPost(post)
for link, description in finder.get_outgoing():
src/w/s/WsgiDAV-0.4.0b2/wsgidav/samples/virtual_dav_provider.py WsgiDAV(Download)
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO #@UnusedImport
from wsgidav.dav_provider import DAVProvider, DAVResource
from wsgidav.dav_error import DAVError, HTTP_FORBIDDEN, HTTP_INTERNAL_ERROR,\
PRECONDITION_CODE_ProtectedProperty
html = self._data["description"]
else:
raise DAVError(HTTP_INTERNAL_ERROR, "Invalid artifact '%s'" % self._name)
return StringIO(html)
class VirtualResFile(_VirtualResource):
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Next