text stringlengths 0 828 |
|---|
if name is not None: |
pathr = self / name |
else: |
pathr = self |
for m in 'war+': |
mode = mode.replace(m, '') |
# Build options |
common_kwargs = {} |
readable_kwargs = {} |
writable_kwargs = {} |
for key, value in kwargs.items(): |
if key.startswith('read_'): |
readable_kwargs[key[5:]] = value |
elif key.startswith('write_'): |
writable_kwargs[key[6:]] = value |
else: |
common_kwargs[key] = value |
readable_kwargs = dict_union(common_kwargs, readable_kwargs) |
writable_kwargs = dict_union(common_kwargs, writable_kwargs) |
with pathr.open('r' + mode, **readable_kwargs) as readable: |
if temp is not None: |
pathw = Path(temp) |
else: |
pathw = pathr + tempext |
try: |
pathw.remove() |
except OSError: |
pass |
writable = pathw.open('w' + mode, **writable_kwargs) |
try: |
yield readable, writable |
except Exception: |
# Problem, delete writable |
writable.close() |
pathw.remove() |
raise |
else: |
writable.close() |
# Alright, replace |
pathr.copymode(pathw) |
pathr.remove() |
pathw.rename(pathr)" |
4128,"def matches(self, path): |
""""""Tests if the given path matches the pattern. |
Note that the unicode translation of the patch is matched, so |
replacement characters might have been added. |
"""""" |
path = self._prepare_path(path) |
return self.full_regex.search(path) is not None" |
4129,"def may_contain_matches(self, path): |
""""""Tests whether it's possible for paths under the given one to match. |
If this method returns None, no path under the given one will match the |
pattern. |
"""""" |
path = self._prepare_path(path) |
return self.int_regex.search(path) is not None" |
4130,"def _fetch(url,): |
"""""" |
*Retrieve an HTML document or file from the web at a given URL* |
**Key Arguments:** |
- ``url`` -- the URL of the document or file |
**Return:** |
- ``url`` -- the URL of the document or file, or None if an error occured |
- ``body`` -- the text content of the HTML document. |
"""""" |
import logging as log |
import socket |
from eventlet import Timeout |
from eventlet.green import urllib2 |
import sys |
# TRY AND DOWNLOAD X TIMES BEFORE QUITING |
tries = 10 |
count = 1 |
downloaded = False |
while count < tries and downloaded == False: |
try: |
log.debug('downloading ' + url.get_full_url()) |
body = urllib2.urlopen(url).read() |
downloaded = True |
except socket.timeout, e: |
print ""timeout on URL, trying again"" |
count += 1 |
except Exception, e: |
if ""[Errno 60]"" in str(e): |
log.warning('timeout on URL, trying again' % locals()) |
count += 1 |
if ""Error 502"" in str(e): |
log.warning('proxy error on URL, trying again' % locals()) |
count += 1 |
else: |
log.warning( |
""could not download "" + url.get_full_url() + "" : "" + str(e) + ""\n"") |
url = None |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.