Convert schema to a prototype object.
| 168 | |
| 169 | |
| 170 | class _SchemaToStruct(object): |
| 171 | """Convert schema to a prototype object.""" |
| 172 | |
| 173 | @util.positional(3) |
| 174 | def __init__(self, schema, seen, dent=0): |
| 175 | """Constructor. |
| 176 | |
| 177 | Args: |
| 178 | schema: object, Parsed JSON schema. |
| 179 | seen: list, List of names of schema already seen while parsing. Used to |
| 180 | handle recursive definitions. |
| 181 | dent: int, Initial indentation depth. |
| 182 | """ |
| 183 | # The result of this parsing kept as list of strings. |
| 184 | self.value = [] |
| 185 | |
| 186 | # The final value of the parsing. |
| 187 | self.string = None |
| 188 | |
| 189 | # The parsed JSON schema. |
| 190 | self.schema = schema |
| 191 | |
| 192 | # Indentation level. |
| 193 | self.dent = dent |
| 194 | |
| 195 | # Method that when called returns a prototype object for the schema with |
| 196 | # the given name. |
| 197 | self.from_cache = None |
| 198 | |
| 199 | # List of names of schema already seen while parsing. |
| 200 | self.seen = seen |
| 201 | |
| 202 | def emit(self, text): |
| 203 | """Add text as a line to the output. |
| 204 | |
| 205 | Args: |
| 206 | text: string, Text to output. |
| 207 | """ |
| 208 | self.value.extend([" " * self.dent, text, "\n"]) |
| 209 | |
| 210 | def emitBegin(self, text): |
| 211 | """Add text to the output, but with no line terminator. |
| 212 | |
| 213 | Args: |
| 214 | text: string, Text to output. |
| 215 | """ |
| 216 | self.value.extend([" " * self.dent, text]) |
| 217 | |
| 218 | def emitEnd(self, text, comment): |
| 219 | """Add text and comment to the output with line terminator. |
| 220 | |
| 221 | Args: |
| 222 | text: string, Text to output. |
| 223 | comment: string, Python comment. |
| 224 | """ |
| 225 | if comment: |
| 226 | divider = "\n" + " " * (self.dent + 2) + "# " |
| 227 | lines = comment.splitlines() |
no outgoing calls
no test coverage detected
searching dependent graphs…