text
stringlengths 0
267k
|
---|
def graph6_to_data(string): |
"""Convert graph6 character sequence to 6-bit integers.""" |
v = [ord(c)-63 for c in string] |
if len(v) > 0 and (min(v) < 0 or max(v) > 63): |
return None |
return v |
def data_to_graph6(data): |
"""Convert 6-bit integer sequence to graph6 character sequence.""" |
if len(data) > 0 and (min(data) < 0 or max(data) > 63): |
raise NetworkXError("graph6 data units must be within 0..63") |
return ''.join([chr(d+63) for d in data]) |
def data_to_n(data): |
"""Read initial one-, four- or eight-unit value from graph6 |
integer sequence. |
Return (value, rest of seq.)""" |
if data[0] <= 62: |
return data[0], data[1:] |
if data[1] <= 62: |
return (data[1]<<12) + (data[2]<<6) + data[3], data[4:] |
return ((data[2]<<30) + (data[3]<<24) + (data[4]<<18) + |
(data[5]<<12) + (data[6]<<6) + data[7], data[8:]) |
def n_to_data(n): |
"""Convert an integer to one-, four- or eight-unit graph6 sequence.""" |
if n < 0: |
raise NetworkXError("Numbers in graph6 format must be non-negative.") |
if n <= 62: |
return [n] |
if n <= 258047: |
return [63, (n>>12) & 0x3f, (n>>6) & 0x3f, n & 0x3f] |
if n <= 68719476735: |
return [63, 63, |
(n>>30) & 0x3f, (n>>24) & 0x3f, (n>>18) & 0x3f, |
(n>>12) & 0x3f, (n>>6) & 0x3f, n & 0x3f] |
raise NetworkXError("Numbers above 68719476735 are not supported by graph6") |
def teardown_module(module): |
import os |
if os.path.isfile('test.g6'): |
os.unlink('test.g6') |
#!/usr/bin/env python |
# Copyright (c) 2012 The Chromium Authors. All rights reserved. |
# Use of this source code is governed by a BSD-style license that can be |
# found in the LICENSE file. |
""" Lexer for PPAPI IDL """ |
# |
# IDL Lexer |
# |
# The lexer is uses the PLY lex library to build a tokenizer which understands |
# WebIDL tokens. |
# |
# WebIDL, and WebIDL regular expressions can be found at: |
# http://dev.w3.org/2006/webapi/WebIDL/ |
# PLY can be found at: |
# http://www.dabeaz.com/ply/ |
import os.path |
import re |
import sys |
# |
# Try to load the ply module, if not, then assume it is in the third_party |
# directory, relative to ppapi |
# |
try: |
from ply import lex |
except: |
module_path, module_name = os.path.split(__file__) |
third_party = os.path.join(module_path, '..', '..', 'third_party') |
sys.path.append(third_party) |
from ply import lex |
from idl_option import GetOption, Option, ParseOptions |
Option('output', 'Generate output.') |
# |
# IDL Lexer |
# |
class IDLLexer(object): |
# 'tokens' is a value required by lex which specifies the complete list |
# of valid token types. |
tokens = [ |
# Symbol and keywords types |
'COMMENT', |
'DESCRIBE', |
'ENUM', |
'LABEL', |
'SYMBOL', |
'INLINE', |
'INTERFACE', |