Python __builtin__.set() Examples
The following are 10
code examples of __builtin__.set().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
__builtin__
, or try the search function
.
Example #1
Source File: fypp.py From fypp with BSD 2-Clause "Simplified" License | 6 votes |
def openscope(self, customlocals=None): '''Opens a new (embedded) scope. Args: customlocals (dict): By default, the locals of the embedding scope are visible in the new one. When this is not the desired behaviour a dictionary of customized locals can be passed, and those locals will become the only visible ones. ''' self._locals_stack.append(self._locals) self._globalrefs_stack.append(self._globalrefs) if customlocals is not None: self._locals = customlocals.copy() elif self._locals is not None: self._locals = self._locals.copy() else: self._locals = {} self._globalrefs = set() self._scope = self._globals.copy() self._scope.update(self._locals)
Example #2
Source File: fypp.py From fypp with BSD 2-Clause "Simplified" License | 5 votes |
def handle_set(self, span, name, expr): '''Called when parser encounters a set directive. It is a dummy method and should be overridden for actual use. Args: span (tuple of int): Start and end line of the directive. name (str): Name of the variable. expr (str): String representation of the expression to be assigned to the variable. ''' self._log_event('set', span, name=name, expression=expr)
Example #3
Source File: fypp.py From fypp with BSD 2-Clause "Simplified" License | 5 votes |
def handle_set(self, span, name, expr): '''Should be called to signalize a set directive. Args: span (tuple of int): Start and end line of the directive. name (str): Name of the variable. expr (str): String representation of the expression to be assigned to the variable. ''' self._curnode.append(('set', self._curfile, span, name, expr))
Example #4
Source File: compat.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 5 votes |
def setenv(name, value): """ Accepts unicode string and set it as environment variable 'name' containing value 'value'. """ os.environ[name] = value
Example #5
Source File: compat.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 5 votes |
def unsetenv(name): """ Delete the environment variable 'name'. """ # Some platforms (e.g. AIX) do not support `os.unsetenv()` and # thus `del os.environ[name]` has no effect onto the real # environment. For this case we set the value to the empty string. os.environ[name] = "" del os.environ[name] # Exec commands in subprocesses.
Example #6
Source File: http.py From nightmare with GNU General Public License v2.0 | 4 votes |
def modified(date=None, etag=None): """ Checks to see if the page has been modified since the version in the requester's cache. When you publish pages, you can include `Last-Modified` and `ETag` with the date the page was last modified and an opaque token for the particular version, respectively. When readers reload the page, the browser sends along the modification date and etag value for the version it has in its cache. If the page hasn't changed, the server can just return `304 Not Modified` and not have to send the whole page again. This function takes the last-modified date `date` and the ETag `etag` and checks the headers to see if they match. If they do, it returns `True`, or otherwise it raises NotModified error. It also sets `Last-Modified` and `ETag` output headers. """ try: from __builtin__ import set except ImportError: # for python 2.3 from sets import Set as set n = set([x.strip('" ') for x in web.ctx.env.get('HTTP_IF_NONE_MATCH', '').split(',')]) m = net.parsehttpdate(web.ctx.env.get('HTTP_IF_MODIFIED_SINCE', '').split(';')[0]) validate = False if etag: if '*' in n or etag in n: validate = True if date and m: # we subtract a second because # HTTP dates don't have sub-second precision if date-datetime.timedelta(seconds=1) <= m: validate = True if date: lastmodified(date) if etag: web.header('ETag', '"' + etag + '"') if validate: raise web.notmodified() else: return True
Example #7
Source File: http.py From Hatkey with GNU General Public License v3.0 | 4 votes |
def modified(date=None, etag=None): """ Checks to see if the page has been modified since the version in the requester's cache. When you publish pages, you can include `Last-Modified` and `ETag` with the date the page was last modified and an opaque token for the particular version, respectively. When readers reload the page, the browser sends along the modification date and etag value for the version it has in its cache. If the page hasn't changed, the server can just return `304 Not Modified` and not have to send the whole page again. This function takes the last-modified date `date` and the ETag `etag` and checks the headers to see if they match. If they do, it returns `True`, or otherwise it raises NotModified error. It also sets `Last-Modified` and `ETag` output headers. """ try: from __builtin__ import set except ImportError: # for python 2.3 from sets import Set as set n = set([x.strip('" ') for x in web.ctx.env.get('HTTP_IF_NONE_MATCH', '').split(',')]) m = net.parsehttpdate(web.ctx.env.get('HTTP_IF_MODIFIED_SINCE', '').split(';')[0]) validate = False if etag: if '*' in n or etag in n: validate = True if date and m: # we subtract a second because # HTTP dates don't have sub-second precision if date-datetime.timedelta(seconds=1) <= m: validate = True if date: lastmodified(date) if etag: web.header('ETag', '"' + etag + '"') if validate: raise web.notmodified() else: return True
Example #8
Source File: fypp.py From fypp with BSD 2-Clause "Simplified" License | 4 votes |
def _render(self, tree): output = [] eval_inds = [] eval_pos = [] for node in tree: cmd = node[0] if cmd == 'txt': output.append(node[3]) elif cmd == 'if': out, ieval, peval = self._get_conditional_content(*node[1:5]) eval_inds += _shiftinds(ieval, len(output)) eval_pos += peval output += out elif cmd == 'eval': out, ieval, peval = self._get_eval(*node[1:4]) eval_inds += _shiftinds(ieval, len(output)) eval_pos += peval output += out elif cmd == 'def': result = self._define_macro(*node[1:6]) output.append(result) elif cmd == 'set': result = self._define_variable(*node[1:5]) output.append(result) elif cmd == 'del': self._delete_variable(*node[1:4]) elif cmd == 'for': out, ieval, peval = self._get_iterated_content(*node[1:6]) eval_inds += _shiftinds(ieval, len(output)) eval_pos += peval output += out elif cmd == 'call' or cmd == 'block': out, ieval, peval = self._get_called_content(*node[1:7]) eval_inds += _shiftinds(ieval, len(output)) eval_pos += peval output += out elif cmd == 'include': out, ieval, peval = self._get_included_content(*node[1:5]) eval_inds += _shiftinds(ieval, len(output)) eval_pos += peval output += out elif cmd == 'comment': output.append(self._get_comment(*node[1:3])) elif cmd == 'mute': output.append(self._get_muted_content(*node[1:4])) elif cmd == 'stop': self._handle_stop(*node[1:4]) elif cmd == 'assert': result = self._handle_assert(*node[1:4]) output.append(result) elif cmd == 'global': self._add_global(*node[1:4]) else: msg = "internal error: unknown command '{0}'".format(cmd) raise FyppFatalError(msg) return output, eval_inds, eval_pos
Example #9
Source File: http.py From bokken with GNU General Public License v2.0 | 4 votes |
def modified(date=None, etag=None): """ Checks to see if the page has been modified since the version in the requester's cache. When you publish pages, you can include `Last-Modified` and `ETag` with the date the page was last modified and an opaque token for the particular version, respectively. When readers reload the page, the browser sends along the modification date and etag value for the version it has in its cache. If the page hasn't changed, the server can just return `304 Not Modified` and not have to send the whole page again. This function takes the last-modified date `date` and the ETag `etag` and checks the headers to see if they match. If they do, it returns `True`, or otherwise it raises NotModified error. It also sets `Last-Modified` and `ETag` output headers. """ try: from __builtin__ import set except ImportError: # for python 2.3 from sets import Set as set n = set([x.strip('" ') for x in web.ctx.env.get('HTTP_IF_NONE_MATCH', '').split(',')]) m = net.parsehttpdate(web.ctx.env.get('HTTP_IF_MODIFIED_SINCE', '').split(';')[0]) validate = False if etag: if '*' in n or etag in n: validate = True if date and m: # we subtract a second because # HTTP dates don't have sub-second precision if date-datetime.timedelta(seconds=1) <= m: validate = True if date: lastmodified(date) if etag: web.header('ETag', '"' + etag + '"') if validate: raise web.notmodified() else: return True
Example #10
Source File: http.py From cosa-nostra with GNU General Public License v3.0 | 4 votes |
def modified(date=None, etag=None): """ Checks to see if the page has been modified since the version in the requester's cache. When you publish pages, you can include `Last-Modified` and `ETag` with the date the page was last modified and an opaque token for the particular version, respectively. When readers reload the page, the browser sends along the modification date and etag value for the version it has in its cache. If the page hasn't changed, the server can just return `304 Not Modified` and not have to send the whole page again. This function takes the last-modified date `date` and the ETag `etag` and checks the headers to see if they match. If they do, it returns `True`, or otherwise it raises NotModified error. It also sets `Last-Modified` and `ETag` output headers. """ try: from __builtin__ import set except ImportError: # for python 2.3 from sets import Set as set n = set([x.strip('" ') for x in web.ctx.env.get('HTTP_IF_NONE_MATCH', '').split(',')]) m = net.parsehttpdate(web.ctx.env.get('HTTP_IF_MODIFIED_SINCE', '').split(';')[0]) validate = False if etag: if '*' in n or etag in n: validate = True if date and m: # we subtract a second because # HTTP dates don't have sub-second precision if date-datetime.timedelta(seconds=1) <= m: validate = True if date: lastmodified(date) if etag: web.header('ETag', '"' + etag + '"') if validate: raise web.notmodified() else: return True