text:
package pruning

import (
	"bytes"
	"reflect"
	"testing"

	structuralschema "k8s.io/apiextensions-apiserver/pkg/apiserver/schema"
	"k8s.io/apimachinery/pkg/runtime"
	"k8s.io/apimachinery/pkg/util/diff"
	"k8s.io/apimachinery/pkg/util/json"
)

func TestPrune(t *testing.T) {
	tests := []struct {
		name           string
		json           string
		isResourceRoot bool
		schema         *structuralschema.Structural
		expected       string
	}{
		{name: "empty", json: "null", expected: "null"},
		{name: "scalar", json: "4", schema: &structuralschema.Structural{}, expected: "4"},
		{name: "scalar array", json: "[1,2]", schema: &structuralschema.Structural{
			Items: &structuralschema.Structural{},
		}, expected: "[1,2]"},
		{name: "object array", json: `[{"a":1},{"b":1},{"a":1,"b":2,"c":3}]`, schema: &structuralschema.Structural{
			Items: &structuralschema.Structural{
				Properties: map[string]structuralschema.Structural{
					"a": {},
					"c": {},
				},
			},
		}, expected: `[{"a":1},{},{"a":1,"c":3}]`},
		{name: "object array with nil schema", json: `[{"a":1},{"b":1},{"a":1,"b":2,"c":3}]`, expected: `[{},{},{}]`},
		{name: "object array object", json: `{"array":[{"a":1},{"b":1},{"a":1,"b":2,"c":3}],"unspecified":{"a":1},"specified":{"a":1,"b":2,"c":3}}`, schema: &structuralschema.Structural{
			Properties: map[string]structuralschema.Structural{
				"array": {
					Items: &structuralschema.Structural{
						Properties: map[string]structuralschema.Structural{
							"a": {},
							"c": {},
						},
					},
				},
				"specified": {
					Properties: map[string]structuralschema.Structural{
						"a": {},
						"c": {},
					},
				},
			},
		}, expected: `{"array":[{"a":1},{},{"a":1,"c":3}],"specified":{"a":1,"c":3}}`},
		{name: "nested x-kubernetes-preserve-unknown-fields", json: `
{
  "unspecified":"bar",
  "alpha": "abc",
  "beta": 42.0,
  "unspecifiedObject": {"unspecified": "bar"},
  "pruning": {
     "unspecified": "bar",
     "unspecifiedObject": {"unspecified": "bar"},
     "pruning": {"unspecified": "bar"},
     "preserving": {"unspecified": "bar"}
  },
  "preserving": {
     "unspecified": "bar",
     "unspecifiedObject": {"unspecified": "bar"},
     "pruning": {"unspecified": "bar"},
     "preserving": {"unspecified": "bar"}
  },
  "preservingAdditionalPropertiesNotInheritingXPreserveUnknownFields": {
     "foo": {
        "specified": {"unspecified":"bar"},
        "unspecified": "bar"
     }
  },
  "preservingAdditionalPropertiesKeyPruneValues": {
     "foo": {
        "specified": {"unspecified":"bar"},
        "unspecified": "bar"
     }
  }
}
`, schema: &structuralschema.Structural{
			Generic:    structuralschema.Generic{Type: "object"},
			Extensions: structuralschema.Extensions{XPreserveUnknownFields: true},
			Properties: map[string]structuralschema.Structural{
				"alpha": {Generic: structuralschema.Generic{Type: "string"}},
				"beta":  {Generic: structuralschema.Generic{Type: "number"}},
				"pruning": {
					Generic: structuralschema.Generic{Type: "object"},
					Properties: map[string]structuralschema.Structural{
						"preserving": {
							Generic:    structuralschema.Generic{Type: "object"},
							Extensions: structuralschema.Extensions{XPreserveUnknownFields: true},
						},
						"pruning": {
							Generic: structuralschema.Generic{Type: "object"},
						},
					},
				},
				"preserving": {
					Generic:    structuralschema.Generic{Type: "object"},
					Extensions: structuralschema.Extensions{XPreserveUnknownFields: true},
					Properties: map[string]structuralschema.Structural{
						"preserving": {
							Generic:    structuralschema.Generic{Type: "object"},
							Extensions: structuralschema.Extensions{XPreserveUnknownFields: true},
						},
						"pruning": {
							Generic: structuralschema.Generic{Type: "object"},
						},
					},
				},
				"preservingAdditionalPropertiesNotInheritingXPreserveUnknownFields": {
					// this x-kubernetes-preserve-unknown-fields is not inherited by the schema inside of additionalProperties
					Extensions: structuralschema.Extensions{XPreserveUnknownFields: true},
					Generic: structuralschema.Generic{
						Type: "object",
						AdditionalProperties: &structuralschema.StructuralOrBool{
							Structural: &structuralschema.Structural{
								Generic: structuralschema.Generic{Type: "object"},
								Properties: map[string]structuralschema.Structural{
									"specified": {Generic: structuralschema.Generic{Type: "object"}},
								},
							},
						},
					},
				},
				"preservingAdditionalPropertiesKeyPruneValues": {
					Generic: structuralschema.Generic{
						Type: "object",
						AdditionalProperties: &structuralschema.StructuralOrBool{
							Structural: &structuralschema.Structural{
								Generic: structuralschema.Generic{Type: "object"},
								Properties: map[string]structuralschema.Structural{
									"specified": {Generic: structuralschema.Generic{Type: "object"}},
								},
							},
						},
					},
				},
			},
		}, expected: `
{
  "unspecified":"bar",
  "alpha": "abc",
  "beta": 42.0,
  "unspecifiedObject": {"unspecified": "bar"},
  "pruning": {
     "pruning": {},
     "preserving": {"unspecified": "bar"}
  },
  "preserving": {
     "unspecified": "bar",
     "unspecifiedObject": {"unspecified": "bar"},
     "pruning": {},
     "preserving": {"unspecified": "bar"}
  },
  "preservingAdditionalPropertiesNotInheritingXPreserveUnknownFields": {
     "foo": {
        "specified": {}
     }
  },
  "preservingAdditionalPropertiesKeyPruneValues": {
     "foo": {
        "specified": {}
     }
  }
}
`},
		{name: "additionalProperties with schema", json: `{"a":1,"b":1,"c":{"a":1,"b":2,"c":{"a":1}}}`, schema: &structuralschema.Structural{
			Properties: map[string]structuralschema.Structural{
				"a": {},
				"c": {
					Generic: structuralschema.Generic{
						AdditionalProperties: &structuralschema.StructuralOrBool{
							Structural: &structuralschema.Structural{
								Generic: structuralschema.Generic{
									Type: "integer",
								},
							},
						},
					},
				},
			},
		}, expected: `{"a":1,"c":{"a":1,"b":2,"c":{}}}`},
		{name: "additionalProperties with bool", json: `{"a":1,"b":1,"c":{"a":1,"b":2,"c":{"a":1}}}`, schema: &structuralschema.Structural{
			Properties: map[string]structuralschema.Structural{
				"a": {},
				"c": {
					Generic: structuralschema.Generic{
						AdditionalProperties: &structuralschema.StructuralOrBool{
							Bool: false,
						},
					},
				},
			},
		}, expected: `{"a":1,"c":{"a":1,"b":2,"c":{}}}`},
		{name: "x-kubernetes-embedded-resource", json: `
{
  "apiVersion": "foo/v1",
  "kind": "Foo",
  "metadata": {
    "name": "instance",
    "unspecified": "bar"
  },
  "unspecified":"bar",
  "pruned": {
    "apiVersion": "foo/v1",
    "kind": "Foo",
    "unspecified": "bar",
    "metadata": {
      "name": "instance",
      "unspecified": "bar"
    },
    "spec": {
      "unspecified": "bar"
    }
  },
  "preserving": {
    "apiVersion": "foo/v1",
    "kind": "Foo",
    "unspecified": "bar",
    "metadata": {
      "name": "instance",
      "unspecified": "bar"
    },
    "spec": {
      "unspecified": "bar"
    }
  },
  "nested": {
    "apiVersion": "foo/v1",
    "kind": "Foo",
    "unspecified": "bar",
    "metadata": {
      "name": "instance",
      "unspecified": "bar"
    },
    "spec": {
      "unspecified": "bar",
      "embedded": {
        "apiVersion": "foo/v1",
        "kind": "Foo",
        "unspecified": "bar",
        "metadata": {
          "name": "instance",
          "unspecified": "bar"
        },
        "spec": {
          "unspecified": "bar"
        }
      }
    }
  }
}
`, schema: &structuralschema.Structural{
			Generic: structuralschema.Generic{Type: "object"},
			Properties: map[string]structuralschema.Structural{
				"pruned": {
					Generic: structuralschema.Generic{Type: "object"},
					Extensions: structuralschema.Extensions{
						XEmbeddedResource: true,
					},
					Properties: map[string]structuralschema.Structural{
						"spec": {
							Generic: structuralschema.Generic{Type: "object"},
						},
					},
				},
				"preserving": {
					Generic: structuralschema.Generic{Type: "object"},
					Extensions: structuralschema.Extensions{
						XEmbeddedResource:      true,
						XPreserveUnknownFields: true,
					},
				},
				"nested": {
					Generic: structuralschema.Generic{Type: "object"},
					Extensions: structuralschema.Extensions{
						XEmbeddedResource: true,
					},
					Properties: map[string]structuralschema.Structural{
						"spec": {
							Generic: structuralschema.Generic{Type: "object"},
							Properties: map[string]structuralschema.Structural{
								"embedded": {
									Generic: structuralschema.Generic{Type: "object"},
									Extensions: structuralschema.Extensions{
										XEmbeddedResource: true,
									},
									Properties: map[string]structuralschema.Structural{
										"spec": {
											Generic: structuralschema.Generic{Type: "object"},
										},
									},
								},
							},
						},
					},
				},
			},
		}, expected: `
{
  "pruned": {
    "apiVersion": "foo/v1",
    "kind": "Foo",
    "metadata": {
      "name": "instance",
      "unspecified": "bar"
    },
    "spec": {
    }
  },
  "preserving": {
    "apiVersion": "foo/v1",
    "kind": "Foo",
    "unspecified": "bar",
    "metadata": {
      "name": "instance",
      "unspecified": "bar"
    },
    "spec": {
      "unspecified": "bar"
    }
  },
  "nested": {
    "apiVersion": "foo/v1",
    "kind": "Foo",
    "metadata": {
      "name": "instance",
      "unspecified": "bar"
    },
    "spec": {
      "embedded": {
        "apiVersion": "foo/v1",
        "kind": "Foo",
        "metadata": {
          "name": "instance",
          "unspecified": "bar"
        },
        "spec": {
        }
      }
    }
  }
}
`},
		{name: "x-kubernetes-embedded-resource, with root=true", json: `
{
  "apiVersion": "foo/v1",
  "kind": "Foo",
  "metadata": {
    "name": "instance",
    "unspecified": "bar"
  },
  "unspecified":"bar",
  "pruned": {
    "apiVersion": "foo/v1",
    "kind": "Foo",
    "unspecified": "bar",
    "metadata": {
      "name": "instance",
      "unspecified": "bar"
    },
    "spec": {
      "unspecified": "bar"
    }
  },
  "preserving": {
    "apiVersion": "foo/v1",
    "kind": "Foo",
    "unspecified": "bar",
    "metadata": {
      "name": "instance",
      "unspecified": "bar"
    },
    "spec": {
      "unspecified": "bar"
    }
  },
  "nested": {
    "apiVersion": "foo/v1",
    "kind": "Foo",
    "unspecified": "bar",
    "metadata": {
      "name": "instance",
      "unspecified": "bar"
    },
    "spec": {
      "unspecified": "bar",
      "embedded": {
        "apiVersion": "foo/v1",
        "kind": "Foo",
        "unspecified": "bar",
        "metadata": {
          "name": "instance",
          "unspecified": "bar"
        },
        "spec": {
          "unspecified": "bar"
        }
      }
    }
  }
}
`, isResourceRoot: true, schema: &structuralschema.Structural{
			Generic: structuralschema.Generic{Type: "object"},
			Properties: map[string]structuralschema.Structural{
				"pruned": {
					Generic: structuralschema.Generic{Type: "object"},
					Extensions: structuralschema.Extensions{
						XEmbeddedResource: true,
					},
					Properties: map[string]structuralschema.Structural{
						"spec": {
							Generic: structuralschema.Generic{Type: "object"},
						},
					},
				},
				"preserving": {
					Generic: structuralschema.Generic{Type: "object"},
					Extensions: structuralschema.Extensions{
						XEmbeddedResource:      true,
						XPreserveUnknownFields: true,
					},
				},
				"nested": {
					Generic: structuralschema.Generic{Type: "object"},
					Extensions: structuralschema.Extensions{
						XEmbeddedResource: true,
					},
					Properties: map[string]structuralschema.Structural{
						"spec": {
							Generic: structuralschema.Generic{Type: "object"},
							Properties: map[string]structuralschema.Structural{
								"embedded": {
									Generic: structuralschema.Generic{Type: "object"},
									Extensions: structuralschema.Extensions{
										XEmbeddedResource: true,
									},
									Properties: map[string]structuralschema.Structural{
										"spec": {
											Generic: structuralschema.Generic{Type: "object"},
										},
									},
								},
							},
						},
					},
				},
			},
		}, expected: `
{
  "apiVersion": "foo/v1",
  "kind": "Foo",
  "metadata": {
    "name": "instance",
    "unspecified": "bar"
  },
  "pruned": {
    "apiVersion": "foo/v1",
    "kind": "Foo",
    "metadata": {
      "name": "instance",
      "unspecified": "bar"
    },
    "spec": {
    }
  },
  "preserving": {
    "apiVersion": "foo/v1",
    "kind": "Foo",
    "unspecified": "bar",
    "metadata": {
      "name": "instance",
      "unspecified": "bar"
    },
    "spec": {
      "unspecified": "bar"
    }
  },
  "nested": {
    "apiVersion": "foo/v1",
    "kind": "Foo",
    "metadata": {
      "name": "instance",
      "unspecified": "bar"
    },
    "spec": {
      "embedded": {
        "apiVersion": "foo/v1",
        "kind": "Foo",
        "metadata": {
          "name": "instance",
          "unspecified": "bar"
        },
        "spec": {
        }
      }
    }
  }
}
`},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			var in interface{}
			if err := json.Unmarshal([]byte(tt.json), &in); err != nil {
				t.Fatal(err)
			}

			var expected interface{}
			if err := json.Unmarshal([]byte(tt.expected), &expected); err != nil {
				t.Fatal(err)
			}

			Prune(in, tt.schema, tt.isResourceRoot)
			if !reflect.DeepEqual(in, expected) {
				var buf bytes.Buffer
				enc := json.NewEncoder(&buf)
				enc.SetIndent("", "  ")
				err := enc.Encode(in)
				if err != nil {
					t.Fatalf("unexpected result mashalling error: %v", err)
				}
				t.Errorf("expected: %s\ngot: %s\ndiff: %s", tt.expected, buf.String(), diff.ObjectDiff(expected, in))
			}
		})
	}
}

const smallInstance = `
{
  "unspecified":"bar",
  "alpha": "abc",
  "beta": 42.0,
  "unspecifiedObject": {"unspecified": "bar"},
  "pruning": {
     "pruning": {},
     "preserving": {"unspecified": "bar"}
  },
  "preserving": {
     "unspecified": "bar",
     "unspecifiedObject": {"unspecified": "bar"},
     "pruning": {},
     "preserving": {"unspecified": "bar"}
  }
}
`

func BenchmarkPrune(b *testing.B) {
	b.StopTimer()
	b.ReportAllocs()

	schema := &structuralschema.Structural{
		Generic:    structuralschema.Generic{Type: "object"},
		Extensions: structuralschema.Extensions{XPreserveUnknownFields: true},
		Properties: map[string]structuralschema.Structural{
			"alpha": {Generic: structuralschema.Generic{Type: "string"}},
			"beta":  {Generic: structuralschema.Generic{Type: "number"}},
			"pruning": {
				Generic: structuralschema.Generic{Type: "object"},
				Properties: map[string]structuralschema.Structural{
					"preserving": {
						Generic:    structuralschema.Generic{Type: "object"},
						Extensions: structuralschema.Extensions{XPreserveUnknownFields: true},
					},
					"pruning": {
						Generic: structuralschema.Generic{Type: "object"},
					},
				},
			},
			"preserving": {
				Generic:    structuralschema.Generic{Type: "object"},
				Extensions: structuralschema.Extensions{XPreserveUnknownFields: true},
				Properties: map[string]structuralschema.Structural{
					"preserving": {
						Generic:    structuralschema.Generic{Type: "object"},
						Extensions: structuralschema.Extensions{XPreserveUnknownFields: true},
					},
					"pruning": {
						Generic: structuralschema.Generic{Type: "object"},
					},
				},
			},
		},
	}

	var obj map[string]interface{}
	err := json.Unmarshal([]byte(smallInstance), &obj)
	if err != nil {
		b.Fatal(err)
	}

	instances := make([]map[string]interface{}, 0, b.N)
	for i := 0; i < b.N; i++ {
		instances = append(instances, runtime.DeepCopyJSON(obj))
	}

	b.StartTimer()
	for i := 0; i < b.N; i++ {
		Prune(instances[i], schema, true)
	}
}

func BenchmarkDeepCopy(b *testing.B) {
	b.StopTimer()
	b.ReportAllocs()

	var obj map[string]interface{}
	err := json.Unmarshal([]byte(smallInstance), &obj)
	if err != nil {
		b.Fatal(err)
	}

	instances := make([]map[string]interface{}, 0, b.N)

	b.StartTimer()
	for i := 0; i < b.N; i++ {
		//lint:ignore SA4010 the result of append is never used, it's acceptable since in benchmark testing.
		instances = append(instances, runtime.DeepCopyJSON(obj))
	}
}

func BenchmarkUnmarshal(b *testing.B) {
	b.StopTimer()
	b.ReportAllocs()

	instances := make([]map[string]interface{}, b.N)

	b.StartTimer()
	for i := 0; i < b.N; i++ {
		err := json.Unmarshal([]byte(smallInstance), &instances[i])
		if err != nil {
			b.Fatal(err)
		}
	}
}


text:
<?php
/**
 * Created by Khang Nguyen.
 * Email: khang.nguyen@banvien.com
 * Date: 10/3/2017
 * Time: 9:33 AM
 */
?>
<!DOCTYPE html>

	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>Tin Đất Đai | Quản lý bài đăng</title>
	<?php $this->load->view('/admin/common/header-js') ?>
	<link rel="stylesheet" href="<?=base_url('/admin/css/bootstrap-datepicker.min.css')?>">

	<?php $this->load->view('/admin/common/admin-header')?>

	<?php $this->load->view('/admin/common/left-menu') ?>

				Quản lý bài đăng <?=isset($user) ? 'của: '.$user->FullName.' - '.$user->Phone.'': ''?>

 Trang chủ

Quản lý bài đăng

		<?php
		$attributes = array("id" => "frmPost");
		echo form_open("admin/product/list", $attributes);
		?>

			<?php if(!empty($message_response)){
				echo '
';
				echo '×';
				echo $message_response;
				echo '
';
			}?>

Danh sách bài đăng

								Tiêu đề

									<input type="text" name="searchFor" placeholder="Tìm tiêu đề" class="form-control" id="searchKey">

								Số điện thoại

									<input type="text" name="phoneNumber" class="form-control" id="phoneNumber">

								Từ ngày

									<input type="text" name="postFromDate" class="form-control datepicker" id="fromDate">

								Đến ngày

									<input type="text" name="postToDate" class="form-control datepicker" id="toDate">

								Mã tin(ID)

									<input type="text" name="code" class="form-control" id="code">

								Loại tin

									<input id="chb-0" checked="checked" type="radio" name="hasAuthor" value="-1"> Tất cả
									<input id="chb-2" type="radio" name="hasAuthor" value="1"> Chính chủ
									<input id="chb-1" type="radio" name="hasAuthor" value="0"> Crawler

								Tình trạng

									<input id="st_0" checked="checked" type="radio" name="status" value="-1"> Tất cả
									<input id="st-1" type="radio" name="status" value="1"> Hoạt động
									<input id="st-0" type="radio" name="status" value="0"> Tạm dừng
									<input id="st-2" type="radio" name="status" value="2"> Chờ thanh toán

							Tìm kiếm

						Xóa Nhiều

									<input name="checkAll" value="1" type="checkbox" >
									Tiêu đề
									Status
									Loại tin
									Lượt xem
									Ngày đăng
									Hết hạn
									Cập nhật
									Người đăng
									Ip Address

							<?php
							$counter = 1;
							foreach ($products as $product) {
								?>

									<input name="checkList[]" type="checkbox" value="<?=$product->ProductID?>">
									<a class="vip<?=$product->Vip?>" data-toggle="tooltip" title="<?=$product->Title?>" href="<?=base_url(seo_url($product->Title).'-p').$product->ProductID.'.html'?>"><?=substr_at_middle($product->Title, 60)?>

										<?php
											if($product->Status == ACTIVE){
												echo 'Show';
											}else if($product->Status == PAYMENT_DELAY){
												echo 'Payment';
											} else{
												echo 'Hide';
											}
										?>

										<select onchange="updateVip('<?=$product->ProductID?>', this.value);">
											<option value="0" <?=$product->Vip == 0 ? ' selected' : ''?>>Vip 0</option>
											<option value="1" <?=$product->Vip == 1 ? ' selected' : ''?>>Vip 1</option>
											<option value="2" <?=$product->Vip == 2 ? ' selected' : ''?>>Vip 2</option>
											<option value="3" <?=$product->Vip == 3 ? ' selected' : ''?>>Vip 3</option>
											<option value="5" <?=$product->Vip == 5 ? ' selected' : ''?>>Thường</option>
										</select>

										<?php
										if(isset($product->FullName)) {
											?>
											<input class="txtView" id="pr-<?=$product->ProductID?>" type="text" value="<?= $product->View?>"
												   onchange="updateView('<?=$product->ProductID?>', this.value);"/>
											<?php
										}else{
											echo $product->View;
										}
										?>

									<?=date('d/m/Y H:i', strtotime($product->PostDate))?>
									<?=date('d/m/Y', strtotime($product->ExpireDate))?>
									<td id="modifiedDate_<?=$product->ProductID?>"><?=date('d/m/Y H:i', strtotime($product->ModifiedDate))?>
									<a href="<?=base_url('/admin/product/list.html?createdById='.$product->CreatedByID)?>"><?=$product->FullName?>
									<?=$product->IpAddress?>

										<a href="<?=base_url('/admin/product/edit.html?postId='.$product->ProductID)?>" data-toggle="tooltip" title="Chỉnh sửa"> |
										<a onclick="pushPostUp('<?=$product->ProductID?>');" data-toggle="tooltip" title="Làm mới tin"> |
										<a class="remove-post" data-post="<?=$product->ProductID?>" data-toggle="tooltip" title="Xóa tin đăng">

								<?php
							}
							?>

							<?php echo $pagination; ?>

		<input type="hidden" id="crudaction" name="crudaction">
		<input type="hidden" id="productId" name="productId">
		<?php echo form_close(); ?>

	<?php $this->load->view('/admin/common/admin-footer')?>

redpajama_set_name: RedPajamaGithub


text:
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/hwpf/hwp/slave_sbe/slave_sbe.C $                      */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2012,2015                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
/**
 *  @file slave_sbe.C
 *
 *  Support file for IStep: slave_sbe
 *   Slave SBE
 *
 *  HWP_IGNORE_VERSION_CHECK
 */

/******************************************************************************/
// Includes
/******************************************************************************/
#include <stdint.h>
#include <trace/interface.H>
#include <initservice/taskargs.H>
#include <errl/errlentry.H>
#include <initservice/isteps_trace.H>
#include <initservice/initserviceif.H>
#include <initservice/initsvcreasoncodes.H>
#include <sys/time.h>
#include <devicefw/userif.H>
#include <i2c/i2cif.H>

//  targeting support
#include <targeting/common/commontargeting.H>
#include <targeting/common/utilFilter.H>
#include <targeting/namedtarget.H>
#include <targeting/attrsync.H>

#include <hwpisteperror.H>
#include <errl/errludtarget.H>

//  fapi support
#include <fapi.H>
#include <fapiPlatHwpInvoker.H>

#include "proc_cen_ref_clk_enable.H"
#include "slave_sbe.H"
#include "proc_revert_sbe_mcs_setup.H"
#include "proc_check_slave_sbe_seeprom_complete.H"
#include "proc_getecid.H"
#include "proc_spless_sbe_startWA.H"
#include <sbe/sbeif.H>
#include <freqVoltageSvc.H>

const uint64_t MS_TO_WAIT_FIRST = 2500; //(2.5 s)
const uint64_t MS_TO_WAIT_OTHERS= 100; //(100 ms)

using namespace ISTEP;
using namespace ISTEP_ERROR;
using namespace ERRORLOG;
using namespace TARGETING;

namespace SLAVE_SBE
{

uint8_t getMembufsAttachedBitMask( TARGETING::Target * i_procChipHandle  );
void fenceAttachedMembufs( TARGETING::Target * i_procChipHandle  );

//******************************************************************************
// call_proc_revert_sbe_mcs_setup function
//******************************************************************************
void* call_proc_revert_sbe_mcs_setup(void *io_pArgs)
{
    errlHndl_t  l_errl = NULL;
    IStepError  l_stepError;

    TRACDCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
               "call_proc_revert_sbe_mcs_setup entry" );

    // Note: Even though Cronus trace shows this HWP runs on all proc,
    // this should be done only for Master chip per Dean.

    TARGETING::Target* l_pProcTarget = NULL;
    TARGETING::targetService().masterProcChipTargetHandle(l_pProcTarget);

    fapi::Target l_fapiProcTarget(fapi::TARGET_TYPE_PROC_CHIP, l_pProcTarget);

    // Invoke the HWP
    FAPI_INVOKE_HWP(l_errl, proc_revert_sbe_mcs_setup, l_fapiProcTarget);

    if (l_errl)
    {
        TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                  "ERROR : failed executing proc_revert_sbe_mcs_setup "
                  "returning error");

        // capture the target data in the elog
        ErrlUserDetailsTarget(l_pProcTarget).addToLog( l_errl );

        // Create IStep error log and cross reference error that occurred
        l_stepError.addErrorDetails( l_errl );

        errlCommit( l_errl, HWPF_COMP_ID );
    }
    else
    {
        TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                  "SUCCESS : proc_revert_sbe_mcs_setup completed ok");
    }

    TRACDCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
              "call_proc_revert_sbe_mcs_setup exit");

    // end task, returning any errorlogs to IStepDisp
    return l_stepError.getErrorHandle();
}

//******************************************************************************
// call_host_slave_sbe function
//******************************************************************************
void* call_host_slave_sbe_config(void *io_pArgs)
{
    errlHndl_t l_errl = NULL;
    IStepError  l_stepError;
    TRACDCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
               "call_host_slave_sbe_config entry" );

    // execute proc_read_nest_freq.C
    // execute proc_setup_sbe_config.C

#ifdef CONFIG_HTMGT
    // Set system frequency attributes
    l_errl = FREQVOLTSVC::setSysFreq();
    if (l_errl )
    {
        // Create IStep error log and cross reference error that occurred
        l_stepError.addErrorDetails( l_errl );

        // Commit Error
        errlCommit( l_errl, HWPF_COMP_ID );
    }
#endif // CONFIG_HTMGT

    // If there is no FSP, set ATTR_PROC_BOOT_VOLTAGE_VID

    if (!INITSERVICE::spBaseServicesEnabled())
    {
        l_errl = set_proc_boot_voltage_vid();
        if( l_errl )
        {
            TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                        "Error setting PROC_BOOT_VOLTAGE_VID: "
                        "slave_sbe.C::call_host_slave_sbe_config()");
            // Create IStep error log
            l_stepError.addErrorDetails( l_errl );

            // Commit Error
            errlCommit( l_errl, HWPF_COMP_ID );

        }

        // Enable SBE interrupt for OP systems
        TARGETING::Target* l_sys = NULL;
        targetService().getTopLevelTarget(l_sys);
        assert( l_sys != NULL );
        TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace, "Enabling SBE interrupt for OP systems");
        l_sys->setAttr<ATTR_FORCE_SKIP_SBE_MASTER_INTR_SERVICE>(0);
    }

    // Resolve the side characteristics of the Processor SBE Seeproms
    errlHndl_t err = SBE::resolveProcessorSbeSeeproms();
    if ( err )
    {
        // Create IStep error log and cross reference error that occurred
        l_stepError.addErrorDetails( err );

        // Commit Error
        errlCommit( err, HWPF_COMP_ID );
    }

    TRACDCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
               "call_host_slave_sbe_config exit" );

    // end task, returning any errorlogs to IStepDisp
    return l_stepError.getErrorHandle();

}

//******************************************************************************
// set_proc_boot_voltage_vid
//******************************************************************************
errlHndl_t set_proc_boot_voltage_vid()
{
    errlHndl_t l_errl = NULL;
    IStepError l_stepError;
    TRACDCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
            "ENTER set_proc_boot_voltage_vid()");
    do
    {
        // Get the top level target/system target
        Target* l_pTopLevelTarget = NULL;
        targetService().getTopLevelTarget(l_pTopLevelTarget);

        // If there is no top level target, terminate
        assert(l_pTopLevelTarget, "ERROR: Top level "
                   "target not found - slave_sbe.C::set_proc_boot_voltage_vid");

        // Get all Procs
        PredicateCTM l_proc(CLASS_CHIP, TYPE_PROC);
        PredicateIsFunctional l_functional;
        PredicatePostfixExpr l_procs;

        l_procs.push(&l_proc).push(&l_functional).And();

        TargetRangeFilter l_filter( targetService().begin(),
                                    targetService().end(),
                                    &l_procs);

        ATTR_BOOT_FREQ_MHZ_type l_boot_freq_mhz =
                   l_pTopLevelTarget->getAttr<ATTR_BOOT_FREQ_MHZ>();
        for(; l_filter; ++l_filter)
        {

            l_errl = FREQVOLTSVC::runProcGetVoltage(*l_filter,
                                                    l_boot_freq_mhz);
            if( l_errl )
            {
                TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                            "ERROR: calling runProcGetVoltage for Proc "
                            "Target HUID[0x%08X]",
                            l_filter->getAttr<ATTR_HUID>());

                // Deconfig the processor
                l_errl->addHwCallout(*l_filter,
                        HWAS::SRCI_PRIORITY_LOW,
                        HWAS::DECONFIG,
                        HWAS::GARD_NULL);

                // Commit error log
                errlCommit( l_errl, HWPF_COMP_ID );
            }
        }

    }while( 0 );
    return l_errl;
}

//******************************************************************************
// call_host_sbe_start function
//******************************************************************************
void* call_host_sbe_start( void *io_pArgs )
{
    errlHndl_t  l_errl = NULL;
    IStepError  l_stepError;
    bool        l_sbeSeepromSelect = false;

    TRACDCOMP( ISTEPS_TRACE::g_trac_isteps_trace, "call_host_sbe_start entry" );

    do
    {
        //
        //  get the master Proc target, we want to IGNORE this one.
        //
        TARGETING::Target* l_pMasterProcTarget = NULL;
        TARGETING::targetService().masterProcChipTargetHandle(
                                                 l_pMasterProcTarget);

        //
        //  get a list of all the procs in the system
        //
        TARGETING::TargetHandleList l_procTargetList;
        getAllChips(l_procTargetList, TYPE_PROC);

        TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
            "host_sbe_start: %d procs in the system.",
            l_procTargetList.size() );

        //
        //  get the SBE Image side that master Proc booted from
        //  if hostboot needs to start SBE on slave processors
        //
        if ( (l_procTargetList.size() > 0) &&
             !INITSERVICE::spBaseServicesEnabled() )
        {
            uint64_t scomData = 0x0;
            size_t op_size = sizeof(scomData);
            l_errl = deviceRead(l_pMasterProcTarget,
                                &scomData,
                                op_size,
                                DEVICE_SCOM_ADDRESS(PORE_SBE_VITAL_0x0005001C));

            if(l_errl)
            {
                TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                           ERR_MRK"call_host_sbe_start: Error reading SBE "
                           "VITAL REG (0x%.8X) from Target HUID=0x%.8X",
                           PORE_SBE_VITAL_0x0005001C,
                           TARGETING::get_huid(l_pMasterProcTarget));

                // capture the target data in the elog
                ErrlUserDetailsTarget(l_pMasterProcTarget).addToLog( l_errl );

                l_errl->setSev(ERRL_SEV_INFORMATIONAL);

                // Create IStep error log and cross reference error
                // that occurred
                l_stepError.addErrorDetails( l_errl );

                // Commit error log
                errlCommit( l_errl, HWPF_COMP_ID );

                // Don't break - attempt to continue
            }

            // Bit 8 in VITAL REG is SBE_IMAGE_SELECT bit:
            // - if 0 then first image otherwise 2nd image
            else if( scomData & 0x0080000000000000 )
            {
                l_sbeSeepromSelect = 1;
                TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                           "call_host_sbe_start: Master Proc booted from "
                           "2nd SBE Image. SBE_VITAL_REG(0x%X) data = 0x%.16X",
                           PORE_SBE_VITAL_0x0005001C, scomData);
            }
        }

        // loop thru all the cpu's
        for (TargetHandleList::const_iterator
                l_proc_iter = l_procTargetList.begin();
                l_proc_iter != l_procTargetList.end();
                ++l_proc_iter)
        {
            //  make a local copy of the Processor target
            TARGETING::Target* l_pProcTarget = *l_proc_iter;

            fapi::Target l_fapiProcTarget( fapi::TARGET_TYPE_PROC_CHIP,
                                           l_pProcTarget    );

            if (l_pProcTarget  ==  l_pMasterProcTarget )
            {
                // we are just checking the Slave SBE's, skip the master
               TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                        "target HUID %.8X --> skipping proc_spless_sbe_startWA",
                        TARGETING::get_huid(l_pProcTarget));

                continue;
            }
            else if (!INITSERVICE::spBaseServicesEnabled())
            {
                TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                          "target HUID %.8X --> "
                          "calling proc_spless_sbe_startWA",
                          TARGETING::get_huid(l_pProcTarget));

                //Need to issue SBE start workaround on all slave chips
                // Invoke the HWP
                FAPI_INVOKE_HWP(l_errl,
                                proc_spless_sbe_startWA,
                                l_fapiProcTarget,
                                l_sbeSeepromSelect);
            }
            else
            {
                //Eventually for secureboot will need to kick off
                //SBE here (different HWP), but for now not needed
                //so do nothing
            }

            if (l_errl)
            {
                TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                          "ERROR : sbe_start (proc_spless_sbe_startWA) "
                          "failed, returning errorlog" );

                // capture the target data in the elog
                ErrlUserDetailsTarget(l_pProcTarget).addToLog( l_errl );

                // Create IStep error log and cross reference error
                // that occurred
                l_stepError.addErrorDetails( l_errl );

                // Commit error log
                errlCommit( l_errl, HWPF_COMP_ID );
            }
            else
            {
                TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                          "SUCCESS : sbe_start (proc_spless_sbe_startWA) "
                          "completed ok");

            }
            TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                      "target HUID %.8X --> after proc_spless_sbe_startWA",
                      TARGETING::get_huid(l_pProcTarget));

        }   // endfor

    }while( 0 );

    TRACDCOMP( ISTEPS_TRACE::g_trac_isteps_trace, "call_host_sbe_start exit" );

    // end task, returning any errorlogs to IStepDisp
    return l_stepError.getErrorHandle();
}

//******************************************************************************
// call_proc_check_slave_sbe_seeprom_complete function
//******************************************************************************
void* call_proc_check_slave_sbe_seeprom_complete( void *io_pArgs )
{
    errlHndl_t  l_errl = NULL;
    IStepError  l_stepError;
    void* sbeImgPtr = NULL;
    size_t sbeImgSize = 0;
    size_t l_wait_time = MS_TO_WAIT_OTHERS;

    TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
               "call_proc_check_slave_sbe_seeprom_complete entry" );

    //If in FSPless environment -- give time for SBE to complete on first chip
    if (!INITSERVICE::spBaseServicesEnabled())
    {
        l_wait_time = MS_TO_WAIT_FIRST;
    }

    //
    //  get the master Proc target, we want to IGNORE this one.
    //
    TARGETING::Target* l_pMasterProcTarget = NULL;
    TARGETING::targetService().masterProcChipTargetHandle(l_pMasterProcTarget);

    //
    //  get a list of all the procs in the system
    //
    TARGETING::TargetHandleList l_procTargetList;
    getAllChips(l_procTargetList, TYPE_PROC);

    TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
        "proc_check_slave_sbe_seeprom_complete: %d procs in the system.",
        l_procTargetList.size() );

    // loop thru all the cpu's
    for (TargetHandleList::const_iterator
            l_proc_iter = l_procTargetList.begin();
            l_proc_iter != l_procTargetList.end();
            ++l_proc_iter)
    {
        //  make a local copy of the Processor target
        TARGETING::Target* l_pProcTarget = *l_proc_iter;

        TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                "target HUID %.8X",
                TARGETING::get_huid(l_pProcTarget));

        if ( l_pProcTarget  ==  l_pMasterProcTarget )
        {
            // we are just checking the Slave SBE's, skip the master
            continue;
        }

        l_errl = SBE::findSBEInPnor(l_pProcTarget,sbeImgPtr,sbeImgSize);

        if (l_errl)
        {
            TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                  "ERROR : proc_check_slave_sbe_seeprom_complete "
                  "Can't find SBE image in pnor");
        }

        fapi::Target l_fapiProcTarget( fapi::TARGET_TYPE_PROC_CHIP,
                                       l_pProcTarget    );

        // Invoke the HWP
        fapi::ReturnCode rc_fapi = fapi::FAPI_RC_SUCCESS;
        FAPI_EXEC_HWP(rc_fapi,
                      proc_check_slave_sbe_seeprom_complete,
                      l_fapiProcTarget,
                      sbeImgPtr,
                      l_wait_time);

        // check for re ipl request
        if(static_cast<uint32_t>(rc_fapi) ==
           fapi::RC_PROC_EXTRACT_SBE_RC_ENGINE_RETRY)
        {
            l_errl = fapi::fapiRcToErrl(rc_fapi);

            // capture the target data in the elog
            ErrlUserDetailsTarget(l_pProcTarget).addToLog( l_errl );

            l_errl->setSev(ERRL_SEV_INFORMATIONAL);

            errlCommit( l_errl, HWPF_COMP_ID );

            TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                      "ERROR : proc_extract_sbe_rc requesting reIPL:"
                      " Calling INITSERVICE::doShutdown() with "
                      "SBE_EXTRACT_RC_REQUEST_REIPL = 0x%x",
                      INITSERVICE::SBE_EXTRACT_RC_REQUEST_REIPL);

            INITSERVICE::doShutdown
                ( INITSERVICE::SBE_EXTRACT_RC_REQUEST_REIPL);
            // doShutdown does not return
        }
        else
        {
            l_errl = fapi::fapiRcToErrl(rc_fapi);
        }

        if (l_errl)
        {
            TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                      "ERROR : proc_check_slave_sbe_seeprom_complete",
                      "failed, returning errorlog" );

            // capture the target data in the elog
            ErrlUserDetailsTarget(l_pProcTarget).addToLog( l_errl );

            // Create IStep error log and cross reference to error that occurred
            l_stepError.addErrorDetails( l_errl );

            // Commit error log
            errlCommit( l_errl, HWPF_COMP_ID );
        }
        else
        {
            TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                      "SUCCESS : proc_check_slave_sbe_seeprom_complete",
                      "completed ok");

        }

        //after first one default to quick check time
        l_wait_time = MS_TO_WAIT_OTHERS;
    }   // endfor

    //  Once the sbe's are up correctly, fetch all the proc ECIDs and
    //  store them in an attribute.
    for (TargetHandleList::const_iterator
            l_proc_iter = l_procTargetList.begin();
            l_proc_iter != l_procTargetList.end();
            ++l_proc_iter)
    {
        //  make a local copy of the Processor target
        TARGETING::Target* l_pProcTarget = *l_proc_iter;

        TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                "target HUID %.8X --> calling proc_getecid",
                TARGETING::get_huid(l_pProcTarget));

        fapi::Target l_fapiProcTarget( fapi::TARGET_TYPE_PROC_CHIP,
                                       l_pProcTarget    );

        //  proc_getecid should set the fuse string to 112 bits long.
        ecmdDataBufferBase  l_fuseString;

        // Invoke the HWP
        FAPI_INVOKE_HWP(l_errl,
                        proc_getecid,
                        l_fapiProcTarget,
                        l_fuseString  );

        if (l_errl)
        {
            TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                      "ERROR : proc_getecid",
                      " failed, returning errorlog" );

            // capture the target data in the elog
            ErrlUserDetailsTarget(l_pProcTarget).addToLog( l_errl );

            // Create IStep error log and cross reference error that occurred
            l_stepError.addErrorDetails( l_errl );

            // Commit error log
            errlCommit( l_errl, HWPF_COMP_ID );
        }
        else
        {
            TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                      "SUCCESS : proc_getecid",
                      " completed ok");

        }
        TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                  "target HUID %.8X --> after proc_getecid",
                  TARGETING::get_huid(l_pProcTarget));

    }   // endfor

    TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
              "call_proc_check_slave_sbe_seeprom_complete exit");

    // end task, returning any errorlogs to IStepDisp
    return l_stepError.getErrorHandle();
}

//******************************************************************************
// call_proc_xmit_sbe
//******************************************************************************
void* call_proc_xmit_sbe(void *io_pArgs )
{
    IStepError  l_stepError;

    TRACDCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
               "call_proc_xmit_sbe entry" );

    // call proc_xmit_sbe.C

    TRACDCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
               "call_proc_xmit_sbe exit" );

    // end task, returning any errorlogs to IStepDisp
    return l_stepError.getErrorHandle();
}

//******************************************************************************
// call_proc_cen_ref_clock_enable
//******************************************************************************
void* call_proc_cen_ref_clk_enable(void *io_pArgs )
{
    errlHndl_t  l_errl = NULL;

    IStepError  l_stepError;

    TRACDCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
               "call_proc_cen_ref_clock_enable enter" );

    TARGETING::TargetHandleList functionalProcChipList;

    getAllChips(functionalProcChipList, TYPE_PROC, true);

    // loop thru the list of processors
    for (TargetHandleList::const_iterator
            l_proc_iter = functionalProcChipList.begin();
            l_proc_iter != functionalProcChipList.end();
            ++l_proc_iter)
    {
        TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                "target HUID %.8X",
                TARGETING::get_huid( *l_proc_iter ));

        uint8_t l_membufsAttached = 0;
        // get a bit mask of present/functional dimms assocated with
        // this processor
        l_membufsAttached = getMembufsAttachedBitMask( *l_proc_iter );

        //Perform a workaround for GA1 to raise fences on centaurs
        //to prevent FSP from analyzing if HB TIs for recoverable
        //errors
        //RTC 106276
        fenceAttachedMembufs( *l_proc_iter );

        TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                "passing target HUID %.8X and 0x%x mask",
                TARGETING::get_huid( *l_proc_iter ), l_membufsAttached );

        if( l_membufsAttached )
        {

            fapi::Target l_fapiProcTarget( fapi::TARGET_TYPE_PROC_CHIP,
                                       *l_proc_iter );

            // Invoke the HWP passing in the proc target and
            // a bit mask indicating connected centaurs
            FAPI_INVOKE_HWP(l_errl,
                    proc_cen_ref_clk_enable,
                    l_fapiProcTarget, l_membufsAttached );

            if (l_errl)
            {
                TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                        "ERROR : proc_cen_ref_clk_enable",
                        "failed, returning errorlog" );

                // capture the target data in the elog
                ErrlUserDetailsTarget( *l_proc_iter ).addToLog( l_errl );

                // Create IStep error log and cross ref error that occurred
                l_stepError.addErrorDetails( l_errl );

                // Commit error log
                errlCommit( l_errl, HWPF_COMP_ID );
            }
            else
            {
                TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                        "SUCCESS : proc_cen_ref_clk_enable",
                        "completed ok");
            }
        }
    }   // endfor

    TRACDCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
               "call_proc_cen_ref_clock_enable exit" );

    // end task, returning any errorlogs to IStepDisp
    return l_stepError.getErrorHandle();
}

//******************************************************************************
// getMembufsAttachedBitMask - helper function for hwp proc_cen_ref_clk_enable
//******************************************************************************
uint8_t getMembufsAttachedBitMask( TARGETING::Target * i_procTarget  )
{
    const uint8_t MCS_WITH_ATTACHED_CENTAUR_MASK = 0x80;

    TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
            "Finding functional membuf chips downstream from "
            "proc chip with HUID of 0x%08X",
            i_procTarget->getAttr<TARGETING::ATTR_HUID>());

    uint8_t l_attachedMembufs = 0;

    // Get list of functional membuf chips downstream from the given
    // proc chip
    TARGETING::TargetHandleList functionalMembufChipList;

    getChildAffinityTargets( functionalMembufChipList,
                      const_cast<TARGETING::Target*>(i_procTarget ),
                      TARGETING::CLASS_CHIP,
                      TARGETING::TYPE_MEMBUF,
                      true);

    // loop through the functional membufs
    for(TARGETING::TargetHandleList::const_iterator pTargetItr
                            = functionalMembufChipList.begin();
                            pTargetItr != functionalMembufChipList.end();
                            pTargetItr++)
    {
        // Find each functional membuf chip's upstream functional MCS
        // unit, if any, and accumulate it into the attached membuf
        // chips mask
        TARGETING::TargetHandleList functionalMcsUnitList;

        getParentAffinityTargets( functionalMcsUnitList, *pTargetItr,
                                  TARGETING::CLASS_UNIT, TARGETING::TYPE_MCS,
                                  true );

        if(functionalMcsUnitList.empty())
        {
            TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                    "Functional membuf chip with HUID of 0x%08X "
                    "is not attached to an upstream functional MCS",
                    (*pTargetItr)->getAttr<
                    TARGETING::ATTR_HUID>());
            continue;
        }

        TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                "Found functional MCS unit with HUID of 0x%08X "
                "upstream from functional membuf chip with HUID of 0x%08X",
                ((*functionalMcsUnitList.begin())->getAttr<
                 TARGETING::ATTR_CHIP_UNIT>()),
                (*pTargetItr)->getAttr<
                TARGETING::ATTR_HUID>());
        l_attachedMembufs |=
            ((MCS_WITH_ATTACHED_CENTAUR_MASK) >>
             ((*functionalMcsUnitList.begin())->getAttr<
              TARGETING::ATTR_CHIP_UNIT>()));
    }

    TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
            "Proc chip with HUID of 0x%08X has attached membuf "
            "mask (l_attachedMembufs) of 0x%02X",
            i_procTarget->getAttr<TARGETING::ATTR_HUID>(),
            l_attachedMembufs);

    // return the bitmask
    return l_attachedMembufs;

}

//******************************************************************************
// fenceAttachedMembufs - helper function for hwp proc_cen_ref_clk_enable
//******************************************************************************
void fenceAttachedMembufs( TARGETING::Target * i_procTarget  )
{
     errlHndl_t  l_errl = NULL;

    TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
            "Fencing attached (present) membuf chips downstream from "
            "proc chip with HUID of 0x%08X",
            i_procTarget->getAttr<TARGETING::ATTR_HUID>());

    // Get list of membuf chips downstream from the given proc chip
    TARGETING::TargetHandleList MembufChipList;

    getChildAffinityTargetsByState( MembufChipList,
                      const_cast<TARGETING::Target*>(i_procTarget ),
                      TARGETING::CLASS_CHIP,
                      TARGETING::TYPE_MEMBUF,
                      TARGETING::UTIL_FILTER_PRESENT);

    // loop through the membufs
    for(TARGETING::TargetHandleList::const_iterator pTargetItr
                            = MembufChipList.begin();
                            pTargetItr != MembufChipList.end();
                            pTargetItr++)
    {
        //Get CFAM "1012" -- FSI GP3 and set bits 23-27 (various fence bits)
        //Note 1012 is ecmd addressing, real address is 0x1048 (byte)
        uint64_t l_addr = 0x1048;
        const uint32_t l_fence_bits= 0x000001F0;
        uint32_t l_data = 0;
        size_t l_size = sizeof(uint32_t);
        l_errl = deviceRead(*pTargetItr,
                         &l_data,
                         l_size,
                         DEVICE_FSI_ADDRESS(l_addr));
        if (l_errl)
        {
            TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
             "Failed getcfam 1012 to HUID 0x%08X, ignoring, skipping",
             (*pTargetItr)->getAttr<TARGETING::ATTR_HUID>());
            delete l_errl;
            l_errl = NULL;
            continue;
        }

        l_data |= l_fence_bits;

        l_errl = deviceWrite(*pTargetItr,
                         &l_data,
                         l_size,
                         DEVICE_FSI_ADDRESS(l_addr));
        if (l_errl)
        {
            TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                      "Failed putcfam 1012 to HUID 0x%08X, ignoring, skipping",
                      (*pTargetItr)->getAttr<TARGETING::ATTR_HUID>());
            delete l_errl;
            l_errl = NULL;
            continue;
        }
    }

}

}


text:
package org.jrivets.mq;

import org.jrivets.util.OverflowException;

public interface MessageQueue {

    <T> void put(T value) throws OverflowException;

    Object get(long timeoutMs);

    /**
     * Terminates the queue content and release all resources borrowed for the
     * queue purposes
     */
    void terminate();
}


text:
module Azure::Compute::Mgmt::V2020_09_30_preview
  module Models
    #
    # Specifies information about the gallery image definition that you want to
    # update.
    #
    class GalleryImageUpdate < UpdateResourceDefinition

      include MsRestAzure

      # @return [String] The description of this gallery image definition
      # resource. This property is updatable.
      attr_accessor :description

      # @return [String] The Eula agreement for the gallery image definition.
      attr_accessor :eula

      # @return [String] The privacy statement uri.
      attr_accessor :privacy_statement_uri

      # @return [String] The release note uri.
      attr_accessor :release_note_uri

      # @return [OperatingSystemTypes] This property allows you to specify the
      # type of the OS that is included in the disk when creating a VM from a
      # managed image.

 Possible values are:

 **Windows**
      #

 **Linux**. Possible values include: 'Windows', 'Linux'
      attr_accessor :os_type

      # @return [OperatingSystemStateTypes] This property allows the user to
      # specify whether the virtual machines created under this image are
      # 'Generalized' or 'Specialized'. Possible values include: 'Generalized',
      # 'Specialized'
      attr_accessor :os_state

      # @return [HyperVGeneration] The hypervisor generation of the Virtual
      # Machine. Applicable to OS disks only. Possible values include: 'V1',
      # 'V2'
      attr_accessor :hyper_vgeneration

      # @return [Array<GalleryImageFeature>] A list of gallery image features.
      attr_accessor :features

      # @return [DateTime] The end of life date of the gallery image
      # definition. This property can be used for decommissioning purposes.
      # This property is updatable.
      attr_accessor :end_of_life_date

      # @return [GalleryImageIdentifier]
      attr_accessor :identifier

      # @return [RecommendedMachineConfiguration]
      attr_accessor :recommended

      # @return [Disallowed]
      attr_accessor :disallowed

      # @return [ImagePurchasePlan]
      attr_accessor :purchase_plan

      # @return [Enum] The current state of the gallery image definition. The
      # provisioning state, which only appears in the response. Possible values
      # include: 'Creating', 'Updating', 'Failed', 'Succeeded', 'Deleting',
      # 'Migrating'
      attr_accessor :provisioning_state

      #
      # Mapper for GalleryImageUpdate class as Ruby Hash.
      # This will be used for serialization/deserialization.
      #
      def self.mapper()
        {
          client_side_validation: true,
          required: false,
          serialized_name: 'GalleryImageUpdate',
          type: {
            name: 'Composite',
            class_name: 'GalleryImageUpdate',
            model_properties: {
              id: {
                client_side_validation: true,
                required: false,
                read_only: true,
                serialized_name: 'id',
                type: {
                  name: 'String'
                }
              },
              name: {
                client_side_validation: true,
                required: false,
                read_only: true,
                serialized_name: 'name',
                type: {
                  name: 'String'
                }
              },
              type: {
                client_side_validation: true,
                required: false,
                read_only: true,
                serialized_name: 'type',
                type: {
                  name: 'String'
                }
              },
              tags: {
                client_side_validation: true,
                required: false,
                serialized_name: 'tags',
                type: {
                  name: 'Dictionary',
                  value: {
                      client_side_validation: true,
                      required: false,
                      serialized_name: 'StringElementType',
                      type: {
                        name: 'String'
                      }
                  }
                }
              },
              description: {
                client_side_validation: true,
                required: false,
                serialized_name: 'properties.description',
                type: {
                  name: 'String'
                }
              },
              eula: {
                client_side_validation: true,
                required: false,
                serialized_name: 'properties.eula',
                type: {
                  name: 'String'
                }
              },
              privacy_statement_uri: {
                client_side_validation: true,
                required: false,
                serialized_name: 'properties.privacyStatementUri',
                type: {
                  name: 'String'
                }
              },
              release_note_uri: {
                client_side_validation: true,
                required: false,
                serialized_name: 'properties.releaseNoteUri',
                type: {
                  name: 'String'
                }
              },
              os_type: {
                client_side_validation: true,
                required: true,
                serialized_name: 'properties.osType',
                type: {
                  name: 'Enum',
                  module: 'OperatingSystemTypes'
                }
              },
              os_state: {
                client_side_validation: true,
                required: true,
                serialized_name: 'properties.osState',
                type: {
                  name: 'Enum',
                  module: 'OperatingSystemStateTypes'
                }
              },
              hyper_vgeneration: {
                client_side_validation: true,
                required: false,
                serialized_name: 'properties.hyperVGeneration',
                type: {
                  name: 'String'
                }
              },
              features: {
                client_side_validation: true,
                required: false,
                serialized_name: 'properties.features',
                type: {
                  name: 'Sequence',
                  element: {
                      client_side_validation: true,
                      required: false,
                      serialized_name: 'GalleryImageFeatureElementType',
                      type: {
                        name: 'Composite',
                        class_name: 'GalleryImageFeature'
                      }
                  }
                }
              },
              end_of_life_date: {
                client_side_validation: true,
                required: false,
                serialized_name: 'properties.endOfLifeDate',
                type: {
                  name: 'DateTime'
                }
              },
              identifier: {
                client_side_validation: true,
                required: true,
                serialized_name: 'properties.identifier',
                type: {
                  name: 'Composite',
                  class_name: 'GalleryImageIdentifier'
                }
              },
              recommended: {
                client_side_validation: true,
                required: false,
                serialized_name: 'properties.recommended',
                type: {
                  name: 'Composite',
                  class_name: 'RecommendedMachineConfiguration'
                }
              },
              disallowed: {
                client_side_validation: true,
                required: false,
                serialized_name: 'properties.disallowed',
                type: {
                  name: 'Composite',
                  class_name: 'Disallowed'
                }
              },
              purchase_plan: {
                client_side_validation: true,
                required: false,
                serialized_name: 'properties.purchasePlan',
                type: {
                  name: 'Composite',
                  class_name: 'ImagePurchasePlan'
                }
              },
              provisioning_state: {
                client_side_validation: true,
                required: false,
                read_only: true,
                serialized_name: 'properties.provisioningState',
                type: {
                  name: 'String'
                }
              }
            }
          }
        }
      end
    end
  end
end


text:
[![Nyan Cat result printer for PHPUnit](https://github.com/whatthejeff/nyancat-phpunit-resultprinter/raw/master/nyan.gif)](https://github.com/whatthejeff/nyancat-phpunit-resultprinter/raw/master/nyan.gif)

## Requirements

The Nyan Cat result printer for PHPUnit works with PHP 5.3.3 or later.

## Installation

The recommended way to install the Nyan Cat result printer for PHPUnit is
[through composer](http://getcomposer.org). Just create a `composer.json` file
and run the `php composer.phar install` command to install it:

~~~json
{
    "require-dev": {
        "whatthejeff/nyancat-phpunit-resultprinter": "~1.2"
    }
}
~~~

Once installed, add the following attributes to the `<phpunit>` element in your
`phpunit.xml` file:

    printerFile="vendor/whatthejeff/nyancat-phpunit-resultprinter/src/NyanCat/PHPUnit/ResultPrinter.php"
    printerClass="NyanCat\PHPUnit\ResultPrinter"

## Tests

[![Build Status](https://travis-ci.org/whatthejeff/nyancat-phpunit-resultprinter.png?branch=master)](https://travis-ci.org/whatthejeff/nyancat-phpunit-resultprinter)

To run the test suite, you need [composer](http://getcomposer.org).

    $ php composer.phar install
    $ vendor/bin/phpunit

## Acknowledgements

The Nyan Cat result printer for PHPUnit was __heavily__ inspired by the
glorious [mocha/nyan.js](https://github.com/visionmedia/mocha/blob/master/lib/reporters/nyan.js).

## License

The Nyan Cat result printer for PHPUnit is licensed under the [MIT license](LICENSE).


text:
package org.adeptnet.prtg.config;

import javax.xml.bind.JAXBException;
import org.adeptnet.prtg.config.xml.Config;

/**
 *
 * @author Francois Steyn - Adept Internet (PTY) LTD (francois.s@adept.co.za)
 */
public interface ConfigInterface {

    Config getConfig() throws JAXBException;

    String getJmxInitialContext();
}


text:
import os
import models
from lib.helpers import signals

try:
    from dblogging import add_log
except ImportError:
    def add_log(*args, **kvargs): pass

@signals.post_save(sender=models.Attachment)
def attachment_saved(sender, instance, created, **kvargs):
    if created:
        instance.mime_type = instance.detect_mime()
        instance.make_checksum()
        instance.make_check_av()
        instance.save()

        # deduplication step
        dupfirst = models.Attachment.objects.filter(checksum=instance.checksum).order_by('id')[0]
        if dupfirst.id < instance.id:
            path=instance.file.path
            try:
                os.unlink(path)
                os.link(dupfirst.file.path, path)
                add_log('DEDUPLICATION',
                        item_id=instance.id,
                        first_id=dupfirst.id)
            except IOError, e:
                add_log('DEDUPLICATION_ERROR',
                        exception=e,
                        item_id=instance.id)
                with open(path, 'w') as fd:
                    fd.write(dupfirst.file.read())


text:
{% comment %}

   Copyright 2010 Micah Altman, Michael McDonald

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

   This file is part of The Public Mapping Project
   https://github.com/PublicMapping/

   Purpose:
       This template is a wrapper for report panels.

       This template contains the HTML required to take a
       set of report panels and display them in the report panel
       placeholder, or a page of its own.

   Author:
       Andrew Jennings, David Zwarg, Kenny Shepard

{% endcomment %}

{% load redistricting_extras %}
{% load i18n %}
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <link rel="stylesheet" type="text/css" href="/static-media/css/reports.css"/>
  </head>

  <body>
    {% autoescape off %}
    {{ report_panels }}
    {% endautoescape %}
  </body>
</html>


text:
<!doctype html>

		<meta charset="utf-8">

		<title>reveal.js - The HTML Presentation Framework</title>

		<meta name="description" content="A framework for easily creating beautiful presentations using HTML">
		<meta name="author" content="Hakim El Hattab">

		<meta name="apple-mobile-web-app-capable" content="yes" />
		<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />

		<link href='http://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic' rel='stylesheet' type='text/css'>

		<link rel="stylesheet" href="css/main.css">
		<link rel="stylesheet" href="css/theme/default.css" id="theme">

		<link rel="stylesheet" href="lib/css/zenburn.css">

Reveal.js

HTML Presentations Made Easy

Heads Up

						reveal.js is a framework for easily creating beautiful presentations using HTML. You'll need a browser with
						support for CSS 3D transforms to see it in its full glory.

						- Hakim El Hattab / @hakimel

						Oh hey, these are some notes. They'll be hidden in your presentation, but you can see them if you run the speaker notes server.

Vertical Slides

							Slides can be nested inside of other slides,
							try pressing down.

Basement Level 1

Press down or up to navigate.

Basement Level 2

Cornify

Basement Level 3

That's it, time to go back up.

Holistic Overview

						Press ESC to enter the slide overview!

rvl.io

						If you don't like writing slides in HTML you can use the online editor rvl.io.

Works in Mobile Safari

						Try it out! You can swipe through the slides pinch your way to the overview.

Marvelous Unordered List

No order here

Or here

Or here

Or here

Fantastic Ordered List

One is smaller than...

Two is smaller than...

Three!

					## Markdown support

					For those of you who like that sort of thing. Instructions and a bit more info available [here](https://github.com/hakimel/reveal.js#markdown).

<section data-markdown>
  ## Markdown support

  For those of you who like that sort of thing.
  Instructions and a bit more info available [here](https://github.com/hakimel/reveal.js#markdown).
</section>

Transition Styles

						You can select from different transitions, like:

						Cube -
						Page -
						Concave -
						Linear

Themes

						Reveal.js comes with a few themes built in:

						Sky -
						Beige -
						Simple -
						Default

							* Theme demos are loaded after the presentation which leads to flicker. In production you should load your theme in the <head> using a <link>.

Global State

							Set data-state="something" on a slide and "something"
							will be added as a class to the document element when the slide is open. This lets you
							apply broader style changes, like switching the background.

"blackout"

"soothe"

Custom Events

						Additionally custom events can be triggered on a per slide basis by binding to the data-state name.

Reveal.addEventListener( 'customevent', function() {
	console.log( '"customevent" has fired' );
} );

Clever Quotes

						These guys come in two forms, inline: <q cite="http://searchservervirtualization.techtarget.com/definition/Our-Favorite-Technology-Quotations">
						The nice thing about standards is that there are so many to choose from</q> and block:

						For years there has been a theory that millions of monkeys typing at random on millions of typewriters would
						reproduce the entire works of Shakespeare. The Internet has proven this theory to be untrue.

Pretty Code

function linkify( selector ) {
  if( supports3DTransforms ) {

    var nodes = document.querySelectorAll( selector );

    for( var i = 0, len = nodes.length; i < len; i++ ) {
      var node = nodes[i];

      if( !node.className ) ) {
        node.className += ' roll';
      }
    };
  }
}

Courtesy of highlight.js.

Intergalactic Interconnections

						You can link between slides internally,
						like this.

Fragmented Views

Hit the next arrow...

... to step through ...

any type

of view

fragments

Spectacular image!

Export to PDF

Presentations can be exported to PDF, below is an example that's been uploaded to SlideShare.

Stellar Links

Source code on GitHub

Leave feedback on my site

Follow me on Twitter

THE END

BY Hakim El Hattab / hakim.se

				◄
				►
				▲
				▼


text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _06.Strings_And_Objects
{
    class Program
    {
        static void Main(string[] args)
        {
            string word1 = "Hello";
            string word2 = "World";

            object words = word1 + " " + word2;

            string concatenated = (string)words;

            Console.WriteLine(concatenated);
        }
    }
}


text:
'''
---------------------------------------------------------------------------------------------------
PART 1 - NAIVE BAYES
---------------------------------------------------------------------------------------------------
(Apart form the below description, the files bayesmodel.py and filereader.py in modules folder contain additional comments which can help in your understanding)
1. Problem Formulation
    The formulation of the Naive Bayes Model is pretty simple. It assumes that every word is independent of the other given the topic. We proceed with this assumption.
    A topic-wise dictionary is kept which contains all the word frequencies for words occurring in documents of that topic. This two level dictionary structure helps to
    quickly do the lookups when calculating the posterior probabilities.
2. How the program works?
    The program builds this dictionary structure along with other counts which help to speed up the calculation of posterior probabilities for a test document.
    Topic with this highest probability is the label assigned to the test document.
3. Design decision
    As mentioned before we use a dictionary of dictionaries to speed up our lookups.
4. Performance

    Here are the confusion matrices
    Binary Features (Accuracy = 98.2%)
             notspam  spam
    notspam     1360     9
    spam          37  1148

    Continuous Features (Accuracy = 98.79%)
             notspam  spam
    notspam     1359    10
    spam          21  1164

    Accuracy is not significantly different when dealing with binary or continuous features. However we did observe that the top 10 word printed were very good
    for the continuous features case. Here they are for your reference:

    --------------------------------------------------
    Top 10 words associated with spam
    --------------------------------------------------
    content-type - 1076
    0100 - 1005
    1.0 - 1001
    mime-version - 998
    8.11.6/8.11.6 - 914
    smtp - 855
    127.0.0.1 - 832
    content-transfer-encoding - 827
    localhost - 825
    postfix - 807

    --------------------------------------------------
    Top 10 words associated with notspam
    --------------------------------------------------
    8.11.6/8.11.6 - 1353
    0100 - 1347
    dogma.slashnull.org - 1342
    127.0.0.1 - 1292
    localhost - 1290
    postfix - 1289
    delivered-to - 1283
    imap - 1278
    ist - 1275
    fetchmail-5.9.0 - 1275

---------------------------------------------------------------------------------------------------
PART 2 - DECISION TREE
---------------------------------------------------------------------------------------------------
(1) a description of how you formulated the problem, including precisely defining the abstractions.
Here we have the problem of learning a decision tree.
We have the words found in the document as the features for the decision tree.
For each word we then calculate the "Avg. Disorder." or the "Entropy"
This can be done using two ways either by checking the presence of the word or the count of the word.
Once we find the feature or the word which splits the dataset giving the least entropy.
We then make a recursive call on the split up datasets to further split them based on the word with the least entropy.
This uses the ID3 algorithm for the binary feature type.
We use binning for the continuous type where we calculate the frequency/total ratio of the counts of the words in a document.

(2) a brief description of how your program works.

In the training mode we read the all the documents in the given training dataset.
It is stored in a dictionary which has two keys 'spam' and 'notspam'.
These keys have another dictionary as its values having the file name in the dataset as the keys.
This dictionary will have a defaultdict of type float as its value.
This defaultdict contains "word":count as its value.
We assume that words which are not there in the defaultdict have value 0.

The class 'Tree' is used to store the nodes of the Decision Tree.
This is the data structure for the decision tree nodes.
data contains the word or will contain boolean True/False for leaf nodes.
True indicates a spam Document and False indicates a non-spam document.

The generateDecisionTree method is called recursively to split the dataset based on the word with the least frequency.
The words found here are then stored in the objects of the Tree type.
The tree structure generated is then stored to the model file using pickle.

In the testing mode we then read the tree structure using pickle.
This rootnode is used to classify the documents from the test set by doing a walk/traversal of the tree.

(3) a discussion of any problems, assumptions, simplications, and/or design decisions you made.
We have kept a word count which stores the count of the number of spam/notspam documents the word is found in.
So we don't have to calculate the no of documents the word is present in for each feature/word.
We have kept an additional parameter at the end 'b' or 'c' which will choose the binary feature or continuous feature.

(4) answers to any questions asked below in the assignment.
The binary feature gave better result as compared to the continuous feature for the decision tree as the model tries to overfit.
Thus the binary feature was better for the decision tree.
Here we found that based purely on the accuracy the bayes model with continuous feature gives us the best result.

---------------------------------------------------------------------------------------------------
Results:
---------------------------------------------------------------------------------------------------
1)Decision Tree with binary feature
The top 4 levels of Decision Tree are as follows:
                                x-spam-status:

                        False                           in-reply-to:

                                        False                   zzzz@localhost.netnoteinc.com

                                                        False                           reserved.
Percentage Accuracy: 98.6296006265 %
Confusion Matrix:
_______________________________________________________
|                | Predicted Spam | Predicted Not-Spam|
|Actual Spam     | 1173           | 12                |
|Actual Not-Spam | 23             | 1346              |

**********
In this representation the root node is "x-spam-status:"
"x-spam-status:" has left node as "False" and right node as "in-reply-to:"
"in-reply-to:" has left node as "False" and right node as "zzzz@localhost.netnoteinc.com"
"zzzz@localhost.netnoteinc.com" has left node as "False" and right node as "reserved."
More nodes further down the tree are not shown here
Similar representation is used below.
**********

2)Decision Tree with continuous feature
The top 4 levels of Decision Tree are as follows:
                                x-spam-status:(0.01)

                        False(None)                             zzzz@localhost.netnoteinc.com(0.01)

                                        False(None)                     in-reply-to:(0.01)

                                                        False(None)                             reserved.(0.01)
Percentage Accuracy: 97.9639780736 %
Confusion Matrix:
_______________________________________________________
|                | Predicted Spam | Predicted Not-Spam|
|Actual Spam     | 1142           | 43                |
|Actual Not-Spam | 9             | 1360               |
'''
import sys

if len(sys.argv) < 5:
    print "Too few arguments"
    print "The program expects arguments in this fashion"
    print "python spam.py [mode] [technique] [dataset-directory] [model-file]"
    print "[mode] - ""train"" or ""test"""
    print "[model-file] - filename to save model to, or load model from"
    print "[technique] - can be ""dt"" decision tree or ""bayes"" naive bayes model"
else:
    # mode can be 'train' or 'test'
    mode = str(sys.argv[1])
    # technique can be 'bayes' or 'dt'
    technique = str(sys.argv[2])
    # dataset_directory is of the form 'test' or 'train' or 'part1/train' or 'part1/test'
    dataset_directory = str(sys.argv[3])
    # model_file can be named anything as long as it is same for train and test and the feature used
    model_file =  str(sys.argv[4])
    # feature can be 'b' for binary or 'c' for continuous feature
    try:
        feature =  str(sys.argv[5])
    except IndexError:
        feature = None

    if technique == "dt":
        if feature == 'b' or feature == None:
            from modules.spam_dt_binary import *
        elif feature == 'c':
            from modules.spam_dt_cont import *
        if mode == "train":
            print "Started reading data"
            (trained_data,wordslist,wordscount) = readData(dataset_directory)
            print "Finished reading data"
            print "\nStarted learning decision tree"
            rootnode = generateDecisionTree(trained_data,wordslist,wordscount)
            print "Finished learning decision tree"
            print_tree3(rootnode)
            with open(model_file, 'wb') as output:
                pickle.dump(rootnode, output, pickle.HIGHEST_PROTOCOL)
            print "Finished writing learned decision tree to model file"
        if mode == "test":
            print "Started reading data"
            (trained_data,wordslist,wordscount) = readData(dataset_directory)
            print "Finished reading data"
            print "Started reading decision tree from model file"
            with open(model_file, 'rb') as input:
                rootnode = pickle.load(input)
            print_tree3(rootnode)
            print "Finished reading decision tree from model file"
            print "Started classification"
            classifyDocs(trained_data, rootnode)

    elif technique == "bayes":
        import modules.filereader as fr
        import modules.bayesmodel as bm
        import os
        import pickle

        stopwords_dict = fr.stopwords()
        if mode == "train":
            if os.path.exists(model_file):
                os.remove(model_file)

            data = fr.readdata(dataset_directory, stopwords_dict)

            # change the featuretype variable for changing the representation ["binary" or "frequency"]
            featuretype = "binary" if feature == 'b' else "frequency"
            trained_model = bm.train(data, featuretype=featuretype, part="part1")
            pickle.dump(trained_model, open(model_file, "wb"))
            print "Model written to", model_file
            print "Use the same filename for running on test set"

        elif mode == "test":
            if os.path.exists(model_file):
                trained_model = pickle.load(open(model_file, "rb"))
                bm.test(trained_model, dataset_directory, stopwords_dict)
            else:
                print "Model file", model_file, "does not exist"


text:
import os
from setuptools import setup

README = open(os.path.join(os.path.dirname(__file__), 'README.md')).read()

# allow setup.py to be run from any path
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))

setup(
    name='django-contextlayers',
    version='0.1',
    packages=['contextlayers'],
    include_package_data=True,
    license='BSD License',
    description='Slather your templates with contextual data.',
    long_description=README,
    url='https://github.com/natural/django-contextlayers',
    author='Troy Melhase',
    author_email='troy@troy.io',
    classifiers=[
        'Environment :: Web Environment',
        'Framework :: Django',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: BSD License',
        'Operating System :: OS Independent',
        'Programming Language :: Python',
        'Programming Language :: Python :: 2.6',
        'Programming Language :: Python :: 2.7',
        'Topic :: Internet :: WWW/HTTP',
        'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
    ],
)


text:
    <a class="logo navbar-btn pull-left" href="<?php echo URI::base(); ?>" title="Inicio">

    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
    Toggle navigation

    </button>

<a href="<?php echo URI::base(); ?>" title="" class="active">Inicio

<a href="<?php echo URI::base().'seccion/municipio' ?>">Municipio

<a href="<?php echo URI::base().'seccion/HCD' ?>">HCD

<a href="<?php echo URI::base().'seccion/novedades' ?>" title="">Novedades

<a href="<?php echo URI::base().'seccion/contacto' ?>">Contacto

      <?php echo Asset::img('themeoriginal/facebook.png', array('id' => 'fede')) ?>

      <?php echo Asset::img('themeoriginal/twitter.png'); ?>

      <?php echo Asset::img('themeoriginal/youtube.png'); ?>